diff --git a/Source/Contents/Effects/EffectLists.cpp b/Source/Contents/Effects/EffectLists.cpp index 2262e18b5..e94919fc9 100644 --- a/Source/Contents/Effects/EffectLists.cpp +++ b/Source/Contents/Effects/EffectLists.cpp @@ -79,6 +79,7 @@ #include "Contents/Effects/Particle.h" #include "Script/LuaScript.h" +#include #include #include #include @@ -275,14 +276,15 @@ CEffect* EffectLists::At(int id, unsigned index) const { void EffectLists::Add(int actor, CEffect* effect) { this->active[actor].push_back(effect); - switch (effect->id) { + const int id = effect->id; + switch (id) { case EF_EMITTER: case EF_MAGIC_FLOOR: case EF_EVILS_PAW: case EF_ANIMATED_EMITTER: case EF_NEW_RANGEDATTACK: case EF_UNK_2343: - this->indexed[effect->id].push_back(effect); + this->indexed[id].push_back(effect); break; } } @@ -496,7 +498,7 @@ bool CreateEffectMgr() { return false; } - EffectLists* mgr = new (std::nothrow) EffectLists(); + EffectLists* mgr = new (std::nothrow) EffectLists; if (mgr) { mgr->initialized = false; if (mgr->RegisterAllocators()) { @@ -1783,7 +1785,7 @@ bool EffectLists::RegisterAllocators() { return false; } - std::list hatEffects = g_session.m_hotkeyScript->TableKeys("hatEffectTable", 14); + std::list hatEffects = g_session.m_hotkeyScript->TableKeys("hatEffectTable"); for (int hatEffect : hatEffects) { if (!this->RegisterAllocator(hatEffect + 2485, new (std::nothrow) CEffectAllocator)) { return false; @@ -5205,19 +5207,20 @@ bool EffectLists::RegisterAllocators() { // OFFSET: 0x00B3A430 // FUNCTION: fn_18787 bool EffectLists::RegisterAllocator(int id, CAllocator* allocator) { - return this->allocators.try_emplace(id, allocator).second; + return this->allocators.insert(std::make_pair(id, allocator)).second; } // OFFSET: 0x00B3AF30 // FUNCTION: fn_18793 void EffectLists::Update() { - for (auto& entry : this->active) { + std::for_each(this->active.begin(), this->active.end(), [](std::pair>& entry) { + const int actor = entry.first; std::list& effects = entry.second; effects.remove_if([](CEffect* effect) { return effect->RetireIfInactive(); }); for (CEffect* effect : effects) { - effect->Update(entry.first); + effect->Update(actor); } - } + }); } // OFFSET: 0x00B3A9C0 diff --git a/Source/Script/LuaScript.cpp b/Source/Script/LuaScript.cpp index c81c92685..1fca4a5cd 100644 --- a/Source/Script/LuaScript.cpp +++ b/Source/Script/LuaScript.cpp @@ -1229,14 +1229,14 @@ bool LuaScript::HasTable(const char* name) { // OFFSET: 0x00AFD4D0 // FUNCTION: fn_18332 -std::list LuaScript::TableKeys(const char* name, int) { +std::list LuaScript::TableKeys(std::string_view name) { std::list keys; if (!this->m_state) { return keys; } - lua_getglobal(this->m_state, name); + lua_getglobal(this->m_state, name.data()); if (lua_type(this->m_state, -1) == LUA_TTABLE) { lua_pushnil(this->m_state); diff --git a/Source/Script/LuaScript.h b/Source/Script/LuaScript.h index bce5b0676..529046303 100644 --- a/Source/Script/LuaScript.h +++ b/Source/Script/LuaScript.h @@ -7,6 +7,7 @@ #include #include #include +#include #include struct lua_State; @@ -23,7 +24,7 @@ public: int GlobalInteger(const char* name); std::string GlobalString(const char* name); bool HasTable(const char* name); - std::list TableKeys(const char* name, int unused); + std::list TableKeys(std::string_view name); int TableInteger(std::string table, int keyType, std::intptr_t key); void Close(); void Register(std::string name, int (*function)(lua_State*));