Skip to content

Commit 7fed8ed

Browse files
committed
Fix bug
1 parent ec5a337 commit 7fed8ed

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

Client/game_sa/CFireSA.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "CFireSA.h"
1515
#include "CGameSA.h"
1616
#include "CPoolsSA.h"
17+
#include <game/CTaskManager.h>
18+
#include <game/TaskTypes.h>
1719

1820
extern CGameSA* pGame;
1921

@@ -209,3 +211,46 @@ void CFireSA::SetNumGenerationsAllowed(char generations)
209211
{
210212
internalInterface->nNumGenerationsAllowed = generations;
211213
}
214+
215+
////////////////////////////////////////////////////////////////////////
216+
// CFire::Extinguish
217+
//
218+
// Fix GH #3249 (PLAYER_ON_FIRE task is not aborted after the fire is extinguished)
219+
////////////////////////////////////////////////////////////////////////
220+
static void AbortFireTask(CEntitySAInterface* entityOnFire)
221+
{
222+
if (!entityOnFire)
223+
return;
224+
225+
auto ped = pGame->GetPools()->GetPed(reinterpret_cast<DWORD*>(entityOnFire));
226+
if (!ped || !ped->pEntity)
227+
return;
228+
229+
CTaskManager* taskManager = ped->pEntity->GetPedIntelligence()->GetTaskManager();
230+
if (!taskManager)
231+
return;
232+
233+
taskManager->RemoveTaskSecondary(TASK_SECONDARY_PARTIAL_ANIM, TASK_SIMPLE_PLAYER_ON_FIRE);
234+
}
235+
236+
#define HOOKPOS_CFire_Extinguish 0x539429
237+
#define HOOKSIZE_CFire_Extinguish 6
238+
static constexpr std::uintptr_t CONTINUE_CFire_Extinguish = 0x53942F;
239+
static void _declspec(naked) HOOK_CFire_Extinguish()
240+
{
241+
_asm
242+
{
243+
mov [eax+730h], edi
244+
245+
push eax
246+
call AbortFireTask
247+
add esp, 4
248+
249+
jmp CONTINUE_CFire_Extinguish
250+
}
251+
}
252+
253+
void CFireSA::StaticSetHooks()
254+
{
255+
EZHookInstall(CFire_Extinguish);
256+
}

Client/game_sa/CFireSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ class CFireSA : public CFire
6464
void SetStrength(float fStrength);
6565
void SetNumGenerationsAllowed(char generations);
6666
CFireSAInterface* GetInterface() { return internalInterface; }
67+
68+
static void StaticSetHooks();
6769
};

Client/game_sa/CGameSA.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ CGameSA::CGameSA()
245245
CVehicleSA::StaticSetHooks();
246246
CCheckpointSA::StaticSetHooks();
247247
CHudSA::StaticSetHooks();
248+
CFireSA::StaticSetHooks();
248249
}
249250
catch (const std::bad_alloc& e)
250251
{

Client/game_sa/CPedSA.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ void CPedSA::SetBleeding(bool bBleeding)
854854
bool CPedSA::SetOnFire(bool onFire)
855855
{
856856
CPedSAInterface* pInterface = GetPedInterface();
857-
if (onFire && pInterface->pFireOnPed)
857+
if (onFire == !!pInterface->pFireOnPed)
858858
return false;
859859

860860
auto* fireManager = static_cast<CFireManagerSA*>(pGame->GetFireManager());
@@ -876,17 +876,11 @@ bool CPedSA::SetOnFire(bool onFire)
876876
}
877877
else
878878
{
879-
bool wasFire = false;
880-
881879
CFire* fire = fireManager->GetFire(static_cast<CFireSAInterface*>(pInterface->pFireOnPed));
882-
if (fire)
883-
{
884-
fire->Extinguish();
885-
wasFire = true;
886-
}
880+
if (!fire)
881+
return false;
887882

888-
CTaskManager* taskManager = m_pPedIntelligence->GetTaskManager();
889-
return wasFire || (taskManager && taskManager->RemoveTaskSecondary(TASK_SECONDARY_PARTIAL_ANIM, TASK_SIMPLE_PLAYER_ON_FIRE));
883+
fire->Extinguish();
890884
}
891885

892886
return true;

0 commit comments

Comments
 (0)