Core/Scripts: Fix heap buffer overflow in BRD Tomb of seven event (#27920)

* Core/Scripts: Fix heap buffer overflow in BRD Tomb of seven event

* Core/Scripts: Remove magic numbers in brd script, adjust codestyle to tc preference

* missing )

Closes #27919

(cherry picked from commit 0d86727325)
This commit is contained in:
Riztazz
2022-04-22 12:59:08 +02:00
committed by Shauren
parent 312569970e
commit 5417285a11

View File

@@ -26,6 +26,7 @@
#define TIMER_TOMBOFTHESEVEN 15000
#define MAX_ENCOUNTER 6
constexpr uint8 TOMB_OF_SEVEN_BOSS_NUM = 7;
enum Creatures
{
@@ -124,7 +125,7 @@ public:
uint32 BarAleCount;
uint32 GhostKillCount;
ObjectGuid TombBossGUIDs[7];
ObjectGuid TombBossGUIDs[TOMB_OF_SEVEN_BOSS_NUM];
ObjectGuid TombEventStarterGUID;
uint32 TombTimer;
uint32 TombEventCounter;
@@ -170,7 +171,7 @@ public:
case GO_TOMB_ENTER: GoTombEnterGUID = go->GetGUID(); break;
case GO_TOMB_EXIT:
GoTombExitGUID = go->GetGUID();
if (GhostKillCount >= 7)
if (GhostKillCount >= TOMB_OF_SEVEN_BOSS_NUM)
HandleGameObject(ObjectGuid::Empty, true, go);
else
HandleGameObject(ObjectGuid::Empty, false, go);
@@ -234,7 +235,7 @@ public:
break;
}
if (data == DONE || GhostKillCount >= 7)
if (data == DONE || GhostKillCount >= TOMB_OF_SEVEN_BOSS_NUM)
{
OUT_SAVE_INST_DATA;
@@ -340,17 +341,17 @@ public:
for (uint8 i = 0; i < MAX_ENCOUNTER; ++i)
if (encounter[i] == IN_PROGRESS)
encounter[i] = NOT_STARTED;
if (GhostKillCount > 0 && GhostKillCount < 7)
if (GhostKillCount > 0 && GhostKillCount < TOMB_OF_SEVEN_BOSS_NUM)
GhostKillCount = 0;//reset tomb of seven event
if (GhostKillCount >= 7)
GhostKillCount = 7;
if (GhostKillCount >= TOMB_OF_SEVEN_BOSS_NUM)
GhostKillCount = TOMB_OF_SEVEN_BOSS_NUM;
OUT_LOAD_INST_DATA_COMPLETE;
}
void TombOfSevenEvent()
{
if (GhostKillCount < 7 && !TombBossGUIDs[TombEventCounter].IsEmpty())
if (GhostKillCount < TOMB_OF_SEVEN_BOSS_NUM && !TombBossGUIDs[TombEventCounter].IsEmpty())
{
if (Creature* boss = instance->GetCreature(TombBossGUIDs[TombEventCounter]))
{
@@ -366,7 +367,7 @@ public:
{
HandleGameObject(GoTombExitGUID, false);//event reseted, close exit door
HandleGameObject(GoTombEnterGUID, true);//event reseted, open entrance door
for (uint8 i = 0; i < 7; ++i)
for (uint8 i = 0; i < TOMB_OF_SEVEN_BOSS_NUM; ++i)
{
if (Creature* boss = instance->GetCreature(TombBossGUIDs[i]))
{
@@ -400,15 +401,19 @@ public:
}
void Update(uint32 diff) override
{
if (!TombEventStarterGUID.IsEmpty() && GhostKillCount < 7)
if (!TombEventStarterGUID.IsEmpty() && GhostKillCount < TOMB_OF_SEVEN_BOSS_NUM)
{
if (TombTimer <= diff)
{
TombTimer = TIMER_TOMBOFTHESEVEN;
++TombEventCounter;
TombOfSevenEvent();
if (TombEventCounter < TOMB_OF_SEVEN_BOSS_NUM)
{
TombOfSevenEvent();
++TombEventCounter;
}
// Check Killed bosses
for (uint8 i = 0; i < 7; ++i)
for (uint8 i = 0; i < TOMB_OF_SEVEN_BOSS_NUM; ++i)
{
if (Creature* boss = instance->GetCreature(TombBossGUIDs[i]))
{
@@ -420,7 +425,7 @@ public:
}
} else TombTimer -= diff;
}
if (GhostKillCount >= 7 && !TombEventStarterGUID.IsEmpty())
if (GhostKillCount >= TOMB_OF_SEVEN_BOSS_NUM && !TombEventStarterGUID.IsEmpty())
TombOfSevenEnd();
}
};