Browse Source

spell target protections in wards and heroic op

Emagi 1 year ago
parent
commit
361fb06d21
2 changed files with 11 additions and 4 deletions
  1. 10 3
      EQ2/source/WorldServer/LuaFunctions.cpp
  2. 1 1
      EQ2/source/WorldServer/SpellProcess.cpp

+ 10 - 3
EQ2/source/WorldServer/LuaFunctions.cpp

@@ -6370,7 +6370,7 @@ int EQ2Emu_lua_AddToWard(lua_State* state) {
 	}
 	ZoneServer* zone = spell->caster->GetZone();
 	spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
-	if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
+	if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
 		Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
 		ward = target->GetWard(spell->spell->GetSpellID());
 		if (target && ward) {
@@ -6403,14 +6403,17 @@ int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
 		return 0;
 	}
 
-	if (spell->caster && spell->caster->GetZone() && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
+	spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
+	if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
 		Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
 		WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
 		if (ward) {
 			lua_interface->SetInt32Value(state, ward->DamageLeft);
+			spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
 			return 1;
 		}
 	}
+	spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
 	return 0;
 }
 
@@ -6429,7 +6432,8 @@ int EQ2Emu_lua_GetWardValue(lua_State* state) {
 
 	lua_interface->ResetFunctionStack(state);
 	
-	if (spell->caster && spell->caster->GetZone() && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
+	spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
+	if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
 
 		Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
 		WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
@@ -6458,9 +6462,12 @@ int EQ2Emu_lua_GetWardValue(lua_State* state) {
 				lua_interface->SetInt32Value(state, ward->MaxHitCount);
 			else
 				lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
+			
+			spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
 			return 1;
 		}
 	}
+	spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
 	return 0;
 }
 

+ 1 - 1
EQ2/source/WorldServer/SpellProcess.cpp

@@ -1856,7 +1856,7 @@ bool SpellProcess::CastProcessedSpell(LuaSpell* spell, bool passive, bool in_her
 				ho = groupItr->second;
 				int32 group_id = client->GetPlayer()->GetGroupMemberInfo()->group_id;
 				spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
-				if ((spell->targets.at(0) == ho->GetTarget() || spell->spell->GetSpellData()->friendly_spell)
+				if (((spell->targets.size() > 0 && spell->targets.at(0) == ho->GetTarget()) || spell->spell->GetSpellData()->friendly_spell)
 					&& ho->UpdateHeroicOP(spell->spell->GetSpellIconHeroicOp())) {
 					spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);