From 3aca9e64b34baee781f402c3f33ad7ee7991c232 Mon Sep 17 00:00:00 2001 From: jackpoz Date: Sun, 4 May 2014 13:41:07 +0200 Subject: Core/Misc: Fix exploit Fix exploit that allowed to learn spells from recipes without consuming them. --- src/server/game/Spells/Spell.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'src/server') diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 3a947b1b07f..3282ce880f9 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -6335,6 +6335,45 @@ bool Spell::UpdatePointers() // cast item not found, somehow the item is no longer where we expected if (!m_CastItem) return false; + + // check if the retrieved item can even cast the spell + ItemTemplate const* proto = m_CastItem->GetTemplate(); + bool spellFound = false; + for (int i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) + { + if (proto->Spells[i].SpellId == GetSpellInfo()->Id) + { + spellFound = true; + break; + } + } + + // check enchantment if the spell wasn't found in item proto + if (!spellFound) + { + for (uint8 e_slot = 0; e_slot < MAX_ENCHANTMENT_SLOT; ++e_slot) + { + uint32 enchant_id = m_CastItem->GetEnchantmentId(EnchantmentSlot(e_slot)); + SpellItemEnchantmentEntry const* pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchant_id); + if (!pEnchant) + continue; + + for (uint8 s = 0; s < MAX_ITEM_ENCHANTMENT_EFFECTS; ++s) + { + if (pEnchant->spellid[s] == GetSpellInfo()->Id) + { + spellFound = true; + break; + } + } + + if (spellFound) + break; + } + } + + if (!spellFound) + return false; } m_targets.Update(m_caster); -- cgit v1.2.3 From 1c0c163485a2ba1781abf5a1f72b168375199d40 Mon Sep 17 00:00:00 2001 From: jackpoz Date: Sun, 4 May 2014 14:03:42 +0200 Subject: Core/Misc: Fix warning --- src/server/game/Spells/Spell.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server') diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 3282ce880f9..2dc501d896f 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -6341,7 +6341,7 @@ bool Spell::UpdatePointers() bool spellFound = false; for (int i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) { - if (proto->Spells[i].SpellId == GetSpellInfo()->Id) + if (uint32(proto->Spells[i].SpellId) == GetSpellInfo()->Id) { spellFound = true; break; -- cgit v1.2.3 From 109495ac9b5120f302728887dcca9a4de0f921d9 Mon Sep 17 00:00:00 2001 From: Dehravor Date: Sun, 4 May 2014 20:30:19 +0200 Subject: Scripts/Ulduar: Fix crash when Algalon's Big Bang is casted by player --- .../scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server') diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp index bd446c60c90..67500382758 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/boss_algalon_the_observer.cpp @@ -1196,7 +1196,7 @@ class spell_algalon_big_bang : public SpellScriptLoader bool Load() override { _targetCount = 0; - return true; + return GetCaster()->GetTypeId() == TYPEID_UNIT && GetCaster()->IsAIEnabled; } void CountTargets(std::list& targets) -- cgit v1.2.3 From 24ef7dbdf4b76d312cb1df44958c6ccc79bf75f4 Mon Sep 17 00:00:00 2001 From: Gacko Date: Sun, 4 May 2014 22:15:11 +0200 Subject: Core/GameObject: Solve some TODOs related to traps in GameObject::Update and improve logic. Some more changes, TODO solutions and a fix for traps like those in #1359 or #6388 will follow. --- src/server/game/Entities/GameObject/GameObject.cpp | 99 ++++++++++++---------- src/server/game/Entities/GameObject/GameObject.h | 2 +- 2 files changed, 55 insertions(+), 46 deletions(-) (limited to 'src/server') diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 77f9ca59db4..a8b63eddb85 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -451,84 +451,83 @@ void GameObject::Update(uint32 diff) if (isSpawned()) { - // traps can have time and can not have GameObjectTemplate const* goInfo = GetGOInfo(); if (goInfo->type == GAMEOBJECT_TYPE_TRAP) { if (m_cooldownTime >= time(NULL)) - return; + break; - // Type 2 - Bomb (will go away after casting it's spell) + // Type 2 (bomb) does not need to be triggered by a unit and despawns after casting its spell. if (goInfo->trap.type == 2) { - if (goInfo->trap.spellId) - CastSpell(NULL, goInfo->trap.spellId); // FIXME: null target won't work for target type 1 - SetLootState(GO_JUST_DEACTIVATED); + SetLootState(GO_ACTIVATED); break; } - // Type 0 and 1 - trap (type 0 will not get removed after casting a spell) - Unit* owner = GetOwner(); - Unit* ok = NULL; // pointer to appropriate target if found any - bool IsBattlegroundTrap = false; - //FIXME: this is activation radius (in different casting radius that must be selected from spell data) - /// @todo move activated state code (cast itself) to GO_ACTIVATED, in this place only check activating and set state - float radius = (float)(goInfo->trap.radius)/3*2; /// @todo rename radius to diameter (goInfo->trap.radius) should be (goInfo->trap.diameter) - if (!radius) - { - if (goInfo->trap.cooldown != 3) // cast in other case (at some triggering/linked go/etc explicit call) - return; - else - { - if (m_respawnTime > 0) - break; + // Type 0 despawns after being triggered, type 1 does not. - radius = (float)goInfo->trap.cooldown; // battlegrounds gameobjects has data2 == 0 && data5 == 3 - IsBattlegroundTrap = true; + bool isBattlegroundTrap; - if (!radius) - return; - } + /// @todo This is activation radius. Casting radius must be selected from spell data. + /// @todo Move activated state code to GO_ACTIVATED, in this place just check for activation and set state. + float radius; + if (!goInfo->trap.diameter) + { + // Cast in other case (at some triggering/linked go/etc explicit call) + if (goInfo->trap.cooldown != 3 || m_respawnTime > 0) + break; + + // Battleground gameobjects have data2 == 0 && data5 == 3 + isBattlegroundTrap = true; + radius = 3.f; + } else { + isBattlegroundTrap = false; + radius = goInfo->trap.diameter / 2.f; } - // Note: this hack with search required until GO casting not implemented - // search unfriendly creature - if (owner) // hunter trap + Unit* owner = GetOwner(); + // Pointer to appropriate target if found any + Unit* target = NULL; + + /// @todo this hack with search required until GO casting not implemented + // Hunter trap: Search units which are unfriendly to the trap's owner + if (owner) { Trinity::AnyUnfriendlyNoTotemUnitInObjectRangeCheck checker(this, owner, radius); - Trinity::UnitSearcher searcher(this, ok, checker); + Trinity::UnitSearcher searcher(this, target, checker); VisitNearbyGridObject(radius, searcher); - if (!ok) VisitNearbyWorldObject(radius, searcher); + if (!target) + VisitNearbyWorldObject(radius, searcher); } - else // environmental trap + // Environmental trap: Any target + else { - // environmental damage spells already have around enemies targeting but this not help in case not existed GO casting support - // affect only players + // Environmental damage spells already have around enemies targeting but this does not help in case of not existing GO casting support + // Affect only players Player* player = NULL; Trinity::AnyPlayerInObjectRangeCheck checker(this, radius); Trinity::PlayerSearcher searcher(this, player, checker); VisitNearbyWorldObject(radius, searcher); - ok = player; + target = player; } - if (ok) + if (target) { - // some traps do not have spell but should be triggered + // Some traps do not have a spell but should be triggered if (goInfo->trap.spellId) - CastSpell(ok, goInfo->trap.spellId); + CastSpell(target, goInfo->trap.spellId); - m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)); // template or 4 seconds + // Template value or 4 seconds + m_cooldownTime = time(NULL) + (goInfo->trap.cooldown ? goInfo->trap.cooldown : uint32(4)); if (goInfo->trap.type == 1) SetLootState(GO_JUST_DEACTIVATED); - if (IsBattlegroundTrap && ok->GetTypeId() == TYPEID_PLAYER) - { - //Battleground gameobjects case - if (ok->ToPlayer()->InBattleground()) - if (Battleground* bg = ok->ToPlayer()->GetBattleground()) + // Battleground gameobjects case + if (isBattlegroundTrap) + if (Player* player = target->ToPlayer()) + if (Battleground* bg = player->GetBattleground()) bg->HandleTriggerBuff(GetGUID()); - } } } else if (uint32 max_charges = goInfo->GetCharges()) @@ -574,6 +573,16 @@ void GameObject::Update(uint32 diff) } else m_groupLootTimer -= diff; } + case GAMEOBJECT_TYPE_TRAP: + { + GameObjectTemplate const* goInfo = GetGOInfo(); + if (goInfo->trap.spellId) + /// @todo NULL target won't work for target type 1 + CastSpell(NULL, goInfo->trap.spellId); + + SetLootState(GO_JUST_DEACTIVATED); + break; + } default: break; } diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index e94bccc4835..511a04bb9af 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -123,7 +123,7 @@ struct GameObjectTemplate { uint32 lockId; //0 -> Lock.dbc uint32 level; //1 - uint32 radius; //2 radius for trap activation + uint32 diameter; //2 radius for trap activation uint32 spellId; //3 uint32 type; //4 0 trap with no despawn after cast. 1 trap despawns after cast. 2 bomb casts on spawn. uint32 cooldown; //5 time in secs -- cgit v1.2.3 From 99e04ddaf6b5c7a6634dcef21417ecf369bac081 Mon Sep 17 00:00:00 2001 From: Gacko Date: Sun, 4 May 2014 22:32:24 +0200 Subject: Fix indention from changes in previous commit. --- src/server/game/Entities/GameObject/GameObject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server') diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index 511a04bb9af..95d8933a1fa 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -123,7 +123,7 @@ struct GameObjectTemplate { uint32 lockId; //0 -> Lock.dbc uint32 level; //1 - uint32 diameter; //2 radius for trap activation + uint32 diameter; //2 radius for trap activation uint32 spellId; //3 uint32 type; //4 0 trap with no despawn after cast. 1 trap despawns after cast. 2 bomb casts on spawn. uint32 cooldown; //5 time in secs -- cgit v1.2.3 From b6bf83589c7000a9d327009a01d9a22ba4bc6df8 Mon Sep 17 00:00:00 2001 From: Vincent-Michael Date: Mon, 5 May 2014 10:06:44 +0200 Subject: Core/Gameobject: Added missing break in 24ef7dbdf4b76d312cb1df44958c6ccc79bf75f4 --- src/server/game/Entities/GameObject/GameObject.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/server') diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index a8b63eddb85..98cfb722e50 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -480,7 +480,9 @@ void GameObject::Update(uint32 diff) // Battleground gameobjects have data2 == 0 && data5 == 3 isBattlegroundTrap = true; radius = 3.f; - } else { + } + else + { isBattlegroundTrap = false; radius = goInfo->trap.diameter / 2.f; } @@ -573,6 +575,7 @@ void GameObject::Update(uint32 diff) } else m_groupLootTimer -= diff; } + break; case GAMEOBJECT_TYPE_TRAP: { GameObjectTemplate const* goInfo = GetGOInfo(); -- cgit v1.2.3