diff --git a/libzhl/functions/Room.zhl b/libzhl/functions/Room.zhl index 68f9f190a..0ee48d463 100644 --- a/libzhl/functions/Room.zhl +++ b/libzhl/functions/Room.zhl @@ -79,6 +79,15 @@ __thiscall void Room::SaveState(); "568b35????????578bf9833e0d": __thiscall uint32_t Room::GetBossVictoryJingle(); +"558bec83f905": +static cleanup bool Room::ShouldSaveEntity(unsigned int Type, unsigned int Variant, unsigned int SubType, unsigned int SpawnerType, bool Unk); + +"558bec6aff68????????64a1????????5083ec3056": +__thiscall bool Room::SaveEntity(Entity* ent, EntitySaveState* saveState, bool unk); + +"558bec83e4f883ec1c5356578b7d??8bf1": +__thiscall void Room::RestoreEntity(Entity* ent, EntitySaveState* saveState); + struct Room depends (EntityList, RoomDescriptor, TemporaryEffects, RailManager) { {{ inline Camera* GetCamera() { return *(Camera**)((char*)this + 0x11F8); } diff --git a/repentogon/LuaInterfaces/CustomCallbacks.cpp b/repentogon/LuaInterfaces/CustomCallbacks.cpp index ad4c575ad..77d53e8a3 100644 --- a/repentogon/LuaInterfaces/CustomCallbacks.cpp +++ b/repentogon/LuaInterfaces/CustomCallbacks.cpp @@ -3935,4 +3935,83 @@ HOOK_METHOD(Minimap, Render, () -> void) { lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key); lua::LuaCaller(L).push(postcallbackid).call(1); } +} + +HOOK_STATIC(Room, ShouldSaveEntity, (unsigned int Type, unsigned int Variant, unsigned int SubType, unsigned int SpawnerType, bool unk) -> bool) { + const int callbackid = 1481; + if (CallbackState.test(callbackid - 1000)) { + lua_State* L = g_LuaEngine->_state; + lua::LuaStackProtector protector(L); + + lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key); + + lua::LuaResults result = lua::LuaCaller(L).push(callbackid) + .pushnil() + .push(Type) + .push(Variant) + .push(SubType) + .push(SpawnerType) + .push(unk) + .call(1); + + if (!result) { + if (lua_isboolean(L, -1)) { + return lua_toboolean(L, -1); + } + } + } + super(Type, Variant, SubType, SpawnerType, unk); +} + +/*void ProcessSaveRestoreCallbacks(Entity* entity, EntitySaveState* state, const char* mode, bool isCleared) { + +} +*/ + +HOOK_METHOD(Room, SaveEntity, (Entity* entity, EntitySaveState* state, bool isCleared) -> bool) { + const int callbackid = 1482; + if (CallbackState.test(callbackid - 1000)) { + lua_State* L = g_LuaEngine->_state; + lua::LuaStackProtector protector(L); + + lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key); + + lua::LuaCaller caller(L); + + + + lua::LuaResults result = lua::LuaCaller(L).push(callbackid) + .push(entity->_type) + .push(entity, lua::Metatables::ENTITY) + .push(&state, lua::metatables::EntitySaveStateMT) + .push(isCleared) + .call(1); + + if (!result) { + if (lua_isboolean(L, -1)) { + return lua_toboolean(L, -1); + } + } + } + + return super(entity, state, isCleared); + +} + +HOOK_METHOD(Room, RestoreEntity, (Entity* entity, EntitySaveState* state) -> void) { + const int callbackid = 1483; + if (CallbackState.test(callbackid - 1000)) { + lua_State* L = g_LuaEngine->_state; + lua::LuaStackProtector protector(L); + + lua_rawgeti(L, LUA_REGISTRYINDEX, g_LuaEngine->runCallbackRegistry->key); + + lua::LuaCaller(L).push(callbackid) + .push(entity->_type) + .push(entity, lua::Metatables::ENTITY) + .push(state, lua::metatables::EntitySaveStateMT) + .call(1); + } + + super(entity, state); } \ No newline at end of file