Do not call lua functions that do not exist for spells, causes crashes
This commit is contained in:
parent
34b588c370
commit
c98a2997d7
2 changed files with 16 additions and 6 deletions
|
@ -569,6 +569,16 @@ std::string LuaInterface::AddSpawnPointers(LuaSpell* spell, bool first_cast, boo
|
|||
functionCalled = "tick";
|
||||
lua_getglobal(spell->state, "tick");
|
||||
}
|
||||
|
||||
LogWrite(SPELL__DEBUG, 0, "Spell", "LuaInterface::AddSpawnPointers spell %s (%u) function %s, caster %s.", spell->spell ? spell->spell->GetName() : "UnknownUnset", spell->spell ? spell->spell->GetSpellID() : 0, functionCalled.c_str(), spell->caster ? spell->caster->GetName() : "Unknown");
|
||||
|
||||
if (!lua_isfunction(spell->state, lua_gettop(spell->state))){
|
||||
lua_pop(spell->state, 1);
|
||||
return string("");
|
||||
}
|
||||
else {
|
||||
lua_getglobal(spell->state, functionCalled.c_str());
|
||||
}
|
||||
|
||||
if(passLuaSpell)
|
||||
SetSpellValue(spell->state, spell);
|
||||
|
|
|
@ -653,8 +653,8 @@ bool SpellProcess::CastInstant(Spell* spell, Entity* caster, Entity* target, boo
|
|||
Spell* tmpSpell = lua_spell->spell;
|
||||
lua_spell->spell = new Spell(lua_spell->spell);
|
||||
lua_interface->AddCustomSpell(lua_spell);
|
||||
lua_interface->AddSpawnPointers(lua_spell, false, false, "customspell",0,true);
|
||||
if (lua_pcall(lua_spell->state, 3, 3, 0) != 0) {
|
||||
std::string outCall = lua_interface->AddSpawnPointers(lua_spell, false, false, "customspell",0,true);
|
||||
if (outCall.length() > 0 && lua_pcall(lua_spell->state, 3, 3, 0) != 0) {
|
||||
lua_interface->RemoveCustomSpell(lua_spell->spell->GetSpellID());
|
||||
lua_interface->ResetFunctionStack(lua_spell->state);
|
||||
safe_delete(lua_spell->spell);
|
||||
|
@ -1097,8 +1097,8 @@ void SpellProcess::ProcessSpell(ZoneServer* zone, Spell* spell, Entity* caster,
|
|||
Spell* tmpSpell = lua_spell->spell;
|
||||
lua_spell->spell = new Spell(lua_spell->spell);
|
||||
lua_interface->AddCustomSpell(lua_spell);
|
||||
lua_interface->AddSpawnPointers(lua_spell, false, false, "customspell", 0, true);
|
||||
if (lua_pcall(lua_spell->state, 3, 3, 0) != 0) {
|
||||
std::string outCall = lua_interface->AddSpawnPointers(lua_spell, false, false, "customspell", 0, true);
|
||||
if (outCall.length() > 0 && lua_pcall(lua_spell->state, 3, 3, 0) != 0) {
|
||||
lua_interface->RemoveCustomSpell(lua_spell->spell->GetSpellID());
|
||||
lua_interface->ResetFunctionStack(lua_spell->state);
|
||||
safe_delete(lua_spell->spell);
|
||||
|
@ -1533,8 +1533,8 @@ void SpellProcess::ProcessSpell(ZoneServer* zone, Spell* spell, Entity* caster,
|
|||
// Precast in lua
|
||||
if (lua_interface) {
|
||||
bool result = false;
|
||||
lua_interface->AddSpawnPointers(lua_spell, false, true);
|
||||
if (lua_pcall(lua_spell->state, 2, 2, 0) == 0) {
|
||||
std::string outCall = lua_interface->AddSpawnPointers(lua_spell, false, true);
|
||||
if (outCall.length() > 0 && lua_pcall(lua_spell->state, 2, 2, 0) == 0) {
|
||||
result = lua_interface->GetBooleanValue(lua_spell->state, 1);
|
||||
int8 error = lua_interface->GetInt8Value(lua_spell->state, 2) == 0 ? SPELL_ERROR_CANNOT_PREPARE : lua_interface->GetInt8Value(lua_spell->state, 2);
|
||||
lua_interface->ResetFunctionStack(lua_spell->state);
|
||||
|
|
Loading…
Reference in a new issue