1
0

script protection on spells against reuse of the lua state between proc / other spell processes

This commit is contained in:
Emagi 2025-01-18 18:54:10 -05:00
parent dad7873dc5
commit e9936f1c80
3 changed files with 14 additions and 0 deletions

View File

@ -1740,6 +1740,9 @@ bool Entity::CastProc(Proc* proc, int8 type, Spawn* target) {
if(item_proc) {
mutex = lua_interface->GetItemScriptMutex(proc->item->GetItemScript());
}
else if(proc->spell) {
proc->spell->MScriptMutex.writelock(__FUNCTION__, __LINE__);
}
if(mutex)
mutex->readlock(__FUNCTION__, __LINE__);
@ -1804,6 +1807,9 @@ bool Entity::CastProc(Proc* proc, int8 type, Spawn* target) {
mutex->releasereadlock(__FUNCTION__, __LINE__);
if(item_proc)
lua_interface->UseItemScript(proc->item->GetItemScript(), state, false);
else if(proc->spell) {
proc->spell->MScriptMutex.releasewritelock(__FUNCTION__, __LINE__);
}
return false;
}
}
@ -1815,6 +1821,9 @@ bool Entity::CastProc(Proc* proc, int8 type, Spawn* target) {
mutex->releasereadlock(__FUNCTION__);
if(item_proc)
lua_interface->UseItemScript(proc->item->GetItemScript(), state, false);
else if(proc->spell) {
proc->spell->MScriptMutex.releasewritelock(__FUNCTION__, __LINE__);
}
return true;
}

View File

@ -100,6 +100,7 @@ struct LuaSpell{
bool had_triggers;
bool had_dmg_remaining;
Mutex MSpellTargets;
Mutex MScriptMutex;
int32 effect_bitmask;
bool restored; // restored spell cross zone
std::atomic<bool> has_proc;

View File

@ -551,6 +551,8 @@ bool SpellProcess::DeleteCasterSpell(LuaSpell* spell, string reason, bool removi
bool SpellProcess::ProcessSpell(LuaSpell* spell, bool first_cast, const char* function, SpellScriptTimer* timer, bool all_targets) {
bool ret = false;
spell->MScriptMutex.writelock(__FUNCTION__, __LINE__);
if(!spell->state)
{
LogWrite(SPELL__ERROR, 0, "Spell", "Error: State is NULL! SpellProcess::ProcessSpell for Spell '%s'", (spell->spell != nullptr) ? spell->spell->GetName() : "Unknown");
@ -574,6 +576,7 @@ bool SpellProcess::ProcessSpell(LuaSpell* spell, bool first_cast, const char* fu
}
}
}
spell->MScriptMutex.releasewritelock(__FUNCTION__, __LINE__);
return true;
}
std::string functionCall = ApplyLuaFunction(spell, first_cast, function, timer);
@ -584,6 +587,7 @@ bool SpellProcess::ProcessSpell(LuaSpell* spell, bool first_cast, const char* fu
else
ret = lua_interface->CallSpellProcess(spell, 2 + spell->spell->GetLUAData()->size(), functionCall);
}
spell->MScriptMutex.releasewritelock(__FUNCTION__, __LINE__);
return ret;
}