Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map/set stuff also skip in layer #323

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs/game_data/spel2.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions docs/src/includes/_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,15 @@ int | [health](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=health)
int | [bombs](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=bombs) |
int | [ropes](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=ropes) |

### ItemOwnerDetails

Used in [RoomOwnersInfo](#RoomOwnersInfo)

Type | Name | Description
---- | ---- | -----------
[ENT_TYPE](#ENT_TYPE) | [owner_type](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owner_type) |
int | [owner_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owner_uid) |

### Letter


Expand Down Expand Up @@ -799,6 +808,25 @@ nil | [clear_virtual(CallbackId callback_id)](https://github.com/spelunky-fyi/ov
[CallbackId](#Aliases) | [set_pre_render(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_pre_render) | Hooks before the virtual function.<br/>The callback signature is `bool render(RenderInfo self, float float, VanillaRenderContext vanilla_render_context)`
[CallbackId](#Aliases) | [set_post_render(function fun)](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=set_post_render) | Hooks after the virtual function.<br/>The callback signature is `nil render(RenderInfo self, float float, VanillaRenderContext vanilla_render_context)`

### RoomOwnerDetails

Used in [RoomOwnersInfo](#RoomOwnersInfo)

Type | Name | Description
---- | ---- | -----------
int | [layer](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=layer) |
int | [room_index](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=room_index) |
int | [owner_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owner_uid) |

### RoomOwnersInfo

Used in [StateMemory](#StateMemory)

Type | Name | Description
---- | ---- | -----------
custom_map&lt;int, [ItemOwnerDetails](#ItemOwnerDetails)&gt; | [owned_items](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owned_items) | key/index is the uid of an item
array&lt;[RoomOwnerDetails](#RoomOwnerDetails)&gt; | [owned_rooms](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=owned_rooms) |

### ShortTileCodeDef

Used in [get_short_tile_code](#get_short_tile_code), [get_short_tile_code_definition](#get_short_tile_code_definition) and [PostRoomGenerationContext](#PostRoomGenerationContext)
Expand Down Expand Up @@ -2630,6 +2658,7 @@ array&lt;int, 9&gt; | [journal_progress_theme_slots](https://github.com/spelunky
[LogicList](#LogicList) | [logic](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=logic) | Level logic like dice game and cutscenes
[LiquidPhysics](#LiquidPhysics) | [liquid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=liquid) |
int | [next_entity_uid](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=next_entity_uid) | Next entity spawned will have this uid
[RoomOwnersInfo](#RoomOwnersInfo) | [room_owners](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=room_owners) | Holds info about owned rooms and items (shops, challenge rooms, vault etc.)

## Texture types

Expand Down
4 changes: 3 additions & 1 deletion src/game_api/entities_fx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ class FxSpringtrapRing : public Movable
class FxWitchdoctorHint : public Movable
{
public:
std::set<int32_t> unknown; // uid of the witchdoctor, why the map/set?
/// There can be only one Hint above the player, so it has list of witchdoctors
/// in case there are more then one attacking you the same time
std::set<int32_t> witchdoctor;
};

class FxNecromancerANKH : public Movable
Expand Down
2 changes: 1 addition & 1 deletion src/game_api/entities_monsters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class Yang : public RoomOwner
{
public:
/// Table of uid's of the turkeys, goes only up to 3, is nil when yang is angry
std::set<int32_t> turkeys_in_den; // probably a Map, but the second value is just 1 or 0, not really useful
std::set<int32_t> turkeys_in_den;
uint8_t unknown4;
uint8_t unknown5;
/// I'm looking for turkeys, wanna help?
Expand Down
27 changes: 20 additions & 7 deletions src/game_api/layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <functional> // for less
#include <map> // for map
#include <new> // for operator new
#include <set> //
#include <utility> // for find, pair
#include <vector> // for allocator, vector

Expand Down Expand Up @@ -117,6 +118,15 @@ struct EntityList
}
};

struct EntityRegions
{
EntityList** entity_lists;
// pointers to entities from entities_by_region array

uint8_t size;
uint8_t cap;
};

struct Layer
{
bool is_back_layer;
Expand All @@ -125,14 +135,17 @@ struct Layer
EntityList all_entities;
// char + fx + mons + item + logical + mount + activefloor + BG (excluding BG_SHOP, BG_LEVEL_*)
EntityList unknown_entities1;
size_t unknown1;
// key is the mask
std::map<uint32_t, EntityList> entities_by_mask;
EntityRegions* unknown1; // players in motion?

std::map<uint32_t, EntityList> entities_by_mask; // key is the mask

EntityList entities_by_unknown[647]; // could be more, not sure what for, each holds like 1 entity for split second
char stuff0[0xB778]; // unknown, maybe more of the array above?
// 4x4 block areas (the edge ones extend to infinity?), each probably contains diffrent mask entities
EntityList entities_by_region1[31][21];
EntityList entities_by_region2[31][21]; // Active floors ?
EntityList entities_by_region3[31][21];
EntityList entities_by_region4[31][21];

std::map<int32_t, size_t> unknown_map; // some movable and liquids and something else maybe?, key is uid
std::map<int32_t, EntityRegions> entity_regions; // key is uid, all entities except FX, FLOOR, DECORATION, BG, SHADOW and LOGICAL

Entity* grid_entities[g_level_max_y][g_level_max_x];
EntityList entities_overlaping_grid[g_level_max_y][g_level_max_x]; // static entities (like midbg, decorations) that overlap this grid position
Expand All @@ -142,7 +155,7 @@ struct Layer
EntityList unknown_entities3; // debris, explosions, laserbeams etc. ?
EntityList unknown_entities4; // explosions, laserbeams, BG_LEVEL_*_SOOT ? only for short time while there are spawned?
std::vector<Entity*> unknown_vector; // add_to_layer uses this
size_t unknown6; // MysteryLayerPointer1 in plugin
std::set<float>* unknown6; // triggered by floor entity destruction? needs more testing
// List of items that were destroyed and are waiting to have the dtor called
// and then be returned to the entity pool
EntityList expired_entities;
Expand Down
18 changes: 2 additions & 16 deletions src/game_api/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1675,13 +1675,6 @@ void move_grid_entity(int32_t uid, float x, float y, LAYER layer)

void add_item_to_shop(int32_t item_uid, int32_t shop_owner_uid)
{
struct dummy // dummy struct
{
std::set<ShopRestrictedItem>::iterator __omg;
int __wow;
};
using AddRestrictedItemFun = size_t(std::set<ShopRestrictedItem>*, dummy, ShopRestrictedItem);

Movable* item = get_entity_ptr(item_uid)->as<Movable>();
Entity* owner = get_entity_ptr(shop_owner_uid);
if (item && owner && item->is_movable())
Expand All @@ -1699,21 +1692,14 @@ void add_item_to_shop(int32_t item_uid, int32_t shop_owner_uid)
{
if (owner->type->id == it) // TODO: check what happens if it's not room owner/shopkeeper
{
static auto add_to_items_set = (AddRestrictedItemFun*)get_address("add_shopitem");
auto state = State::get();
item->flags = setflag(item->flags, 23); // shop item
item->flags = setflag(item->flags, 20); // Enable button prompt (flag is problably: show dialogs and other fx)
state.layer_local(item->layer)->spawn_entity_over(to_id("ENT_TYPE_FX_SALEICON"), item, 0, 0);
state.layer_local(item->layer)->spawn_entity_over(to_id("ENT_TYPE_FX_SALEDIALOG_CONTAINER"), item, 0, 0.5);

// This function actually only takes iterator and value as argument, but for some reason they need to be passed thru stack
// This is probably some standard `insert` function, but the items is a strange one, i would guess it's a map (item uid as a key and array/struct as a value)
// but standard function, no matter if i set it to map or set, also adds something at the end of a bucket (key hash?), so it's either very similar container or some special setup for set/map
const auto bucket = add_to_items_set(&state.ptr()->shops.items, {state.ptr()->shops.items.end(), 0}, {item_uid, 0, 0});

auto the_struct = (ShopRestrictedItem*)(bucket + 0x1C); // 0x1C - is just the internal map/set stuff
the_struct->owner_uid = shop_owner_uid;
the_struct->owner_type = owner->type->id;
ItemOwnerDetails iod{shop_owner_uid, owner->type->id};
state.ptr()->room_owners.owned_items.insert({item->uid, iod});
return;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/game_api/script/usertypes/state_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ void register_usertypes(sol::state& lua)
statememory_type["logic"] = &StateMemory::logic;
statememory_type["liquid"] = &StateMemory::liquid_physics;
statememory_type["next_entity_uid"] = &StateMemory::next_entity_uid;
statememory_type["room_owners"] = &StateMemory::room_owners;

lua.create_named_table("QUEST_FLAG", "RESET", 1, "DARK_LEVEL_SPAWNED", 2, "VAULT_SPAWNED", 3, "SPAWN_OUTPOST", 4, "SHOP_SPAWNED", 5, "SHORTCUT_USED", 6, "SEEDED", 7, "DAILY", 8, "CAVEMAN_SHOPPIE_AGGROED", 9, "WADDLER_AGGROED", 10, "SHOP_BOUGHT_OUT", 11, "EGGPLANT_CROWN_PICKED_UP", 12, "UDJAT_EYE_SPAWNED", 17, "BLACK_MARKET_SPAWNED", 18, "DRILL_SPAWNED", 19, "MOON_CHALLENGE_SPAWNED", 25, "STAR_CHALLENGE_SPAWNED", 26, "SUN_CHALLENGE_SPAWNED", 27);

Expand Down Expand Up @@ -554,6 +555,15 @@ void register_usertypes(sol::state& lua)
logicdiceshop_type["won_prizes_count"] = &LogicDiceShop::won_prizes_count;
logicdiceshop_type["balance"] = &LogicDiceShop::balance;

/// Used in StateMemory
lua.new_usertype<RoomOwnersInfo>("RoomOwnersInfo", "owned_items", &RoomOwnersInfo::owned_items, "owned_rooms", &RoomOwnersInfo::owned_rooms);

/// Used in RoomOwnersInfo
lua.new_usertype<ItemOwnerDetails>("ItemOwnerDetails", "owner_type", &ItemOwnerDetails::owner_type, "owner_uid", &ItemOwnerDetails::owner_uid);

/// Used in RoomOwnersInfo
lua.new_usertype<RoomOwnerDetails>("RoomOwnerDetails", "layer", &RoomOwnerDetails::layer, "room_index", &RoomOwnerDetails::room_index, "owner_uid", &RoomOwnerDetails::owner_uid);

lua.create_named_table("CAUSE_OF_DEATH", "DEATH", 0, "ENTITY", 1, "LONG_FALL", 2, "STILL_FALLING", 3, "MISSED", 4, "POISONED", 5);

lua["toast_visible"] = []() -> bool
Expand Down
9 changes: 0 additions & 9 deletions src/game_api/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1727,15 +1727,6 @@ std::unordered_map<std::string_view, AddressRule> g_address_rules{
.find_after_inst("\x41\x0F\xB6\x87\x17\x01\x00\x00\x83\xF8"sv)
.at_exe(),
},
{
// Set write bp on State->shops->restricted_item_count, this structure is quite common so i chosen pattern before the call
"add_shopitem"sv,
PatternCommandBuffer{}
.find_after_inst("\x4C\x8D\x84\x24\xD0\x00\x00\x00\xE8"sv)
.offset(-0x1)
.decode_call()
.at_exe(),
},
{
// Find a string "Basic systems initialized", right after it's usage (found via XREFS)
// stuff gets emplaced to a map, it is this map
Expand Down
3 changes: 2 additions & 1 deletion src/game_api/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ struct StateMemory
uint8_t unknown31a; // padding probably
uint8_t unknown31b;
uint8_t unknown31c;
ShopsInfo shops;
/// Holds info about owned rooms and items (shops, challenge rooms, vault etc.)
RoomOwnersInfo room_owners;
/// Number of frames since the game was launched
uint32_t time_startup;
uint32_t special_visibility_flags;
Expand Down
31 changes: 16 additions & 15 deletions src/game_api/state_structs.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include "aliases.hpp"
#include "containers/custom_map.hpp"
#include "containers/custom_vector.hpp"
#include "layer.hpp"
#include "render_api.hpp"
#include <array>
#include <cstdint>
#include <set>
#include <map>

class Entity;

Expand Down Expand Up @@ -841,13 +842,13 @@ struct LiquidPhysics
LiquidTileSpawnData stagnant_lava_tile_spawn_data;
};
};
std::list<uint32_t>* floors; // pointer to map/list that contains all floor uids that the liquid interact with
std::list<uint32_t>* push_blocks; // pointer to map/list that contains all activefloor uids that the liquid interact with
custom_vector<LiquidLake> impostor_lakes; //
uint32_t total_liquid_spawned; // Total number of spawned liquid entities, all types.
uint32_t unknown8; // padding probably
uint8_t* unknown9; // array byte* ? game allocates 0x2F9E8 bytes for it, (0x2F9E8 / g_level_max_x * g_level_max_y = 18) which is weird, but i still think it's position based index, maybe it's 16 and accounts for more rows (grater level height)
// always allocates after the LiquidPhysics
std::map<std::pair<uint8_t, uint8_t>, size_t*>* floors; // key is a grid position, the struct seams to be the same as in push_blocks
std::map<uint32_t, size_t*>* push_blocks; // key is uid, not sure about the struct it points to (it's also possible that the value is 2 pointers)
custom_vector<LiquidLake> impostor_lakes; //
uint32_t total_liquid_spawned; // Total number of spawned liquid entities, all types.
uint32_t unknown8; // padding probably
uint8_t* unknown9; // array byte* ? game allocates 0x2F9E8 bytes for it, (0x2F9E8 / g_level_max_x * g_level_max_y = 18) which is weird, but i still think it's position based index, maybe it's 16 and accounts for more rows (grater level height)
// always allocates after the LiquidPhysics

uint32_t total_liquid_spawned2; // Same as total_liquid_spawned?
bool unknown12;
Expand Down Expand Up @@ -972,27 +973,27 @@ struct Dialogue
uint32_t unknown18;
};

struct ShopRestrictedItem
struct ItemOwnerDetails
{
int32_t item_uid;
int32_t owner_uid;
ENT_TYPE owner_type;
};

struct ShopOwnerDetails
struct RoomOwnerDetails
{
uint8_t layer;
uint8_t padding1;
uint8_t padding2;
uint8_t padding3;
uint32_t room_index;
uint32_t shop_owner_uid;
int32_t owner_uid;
};

struct ShopsInfo
struct RoomOwnersInfo
{
std::set<ShopRestrictedItem> items; // could also be a map
std::vector<ShopOwnerDetails> shop_owners;
/// key/index is the uid of an item
custom_map<int32_t, ItemOwnerDetails> owned_items;
std::vector<RoomOwnerDetails> owned_rooms;
};

struct MultiLineTextRendering
Expand Down
Loading