Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setPedOnFire(ped, false) doesn't cancel TASK_SIMPLE_PLAYER_ON_FIRE #3930

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Client/game_sa/CFireSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "CFireSA.h"
#include "CGameSA.h"
#include "CPoolsSA.h"
#include <game/CTaskManager.h>
#include <game/TaskTypes.h>

extern CGameSA* pGame;

Expand Down Expand Up @@ -209,3 +211,43 @@ void CFireSA::SetNumGenerationsAllowed(char generations)
{
internalInterface->nNumGenerationsAllowed = generations;
}

////////////////////////////////////////////////////////////////////////
// CFire::Extinguish
//
// Fix GH #3249 (PLAYER_ON_FIRE task is not aborted after the fire is extinguished)
////////////////////////////////////////////////////////////////////////
static void AbortFireTask(CEntitySAInterface* entityOnFire)
{
auto ped = pGame->GetPools()->GetPed(reinterpret_cast<DWORD*>(entityOnFire));
if (!ped || !ped->pEntity)
return;

CTaskManager* taskManager = ped->pEntity->GetPedIntelligence()->GetTaskManager();
if (!taskManager)
return;

taskManager->RemoveTaskSecondary(TASK_SECONDARY_PARTIAL_ANIM, TASK_SIMPLE_PLAYER_ON_FIRE);
}

#define HOOKPOS_CFire_Extinguish 0x539429
#define HOOKSIZE_CFire_Extinguish 6
static constexpr std::uintptr_t CONTINUE_CFire_Extinguish = 0x53942F;
static void _declspec(naked) HOOK_CFire_Extinguish()
{
_asm
{
mov [eax+730h], edi

push eax
call AbortFireTask
add esp, 4

jmp CONTINUE_CFire_Extinguish
}
}

void CFireSA::StaticSetHooks()
{
EZHookInstall(CFire_Extinguish);
}
2 changes: 2 additions & 0 deletions Client/game_sa/CFireSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ class CFireSA : public CFire
void SetStrength(float fStrength);
void SetNumGenerationsAllowed(char generations);
CFireSAInterface* GetInterface() { return internalInterface; }

static void StaticSetHooks();
};
1 change: 1 addition & 0 deletions Client/game_sa/CGameSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ CGameSA::CGameSA()
CVehicleSA::StaticSetHooks();
CCheckpointSA::StaticSetHooks();
CHudSA::StaticSetHooks();
CFireSA::StaticSetHooks();
}
catch (const std::bad_alloc& e)
{
Expand Down
12 changes: 12 additions & 0 deletions Client/game_sa/CTaskManagerSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ void CTaskManagerSA::RemoveTaskSecondary(const int iTaskPriority)
SetTaskSecondary(NULL, iTaskPriority);
}

bool CTaskManagerSA::RemoveTaskSecondary(const int taskPriority, const int taskType)
{
CTask* task = GetTaskSecondary(taskPriority);
if (task && task->GetTaskType() == taskType)
{
RemoveTaskSecondary(taskPriority);
return true;
}

return false;
}

void CTaskManagerSA::SetTaskSecondary(CTaskSA* pTaskSecondary, const int iType)
{
DWORD dwFunc = FUNC_SetTaskSecondary;
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CTaskManagerSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CTaskManagerSA : public CTaskManager
CTask* FindActiveTaskByType(const int iTaskType);
CTask* FindTaskByType(const int iPriority, const int iTaskType);
void RemoveTaskSecondary(const int iTaskPriority);
bool RemoveTaskSecondary(const int taskPriority, const int taskType);
void SetTaskSecondary(CTaskSA* pTaskSecondary, const int iType);
CTask* GetTaskSecondary(const int iType); // code it
bool HasTaskSecondary(const CTask* pTaskSecondary); // code it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2594,7 +2594,7 @@ bool CStaticFunctionDefinitions::SetPedOnFire(CClientEntity& Entity, bool bOnFir
{
if (IS_PED(&Entity))
{
if (!Entity.IsLocalEntity())
if (!Entity.IsLocalEntity() && &Entity != GetLocalPlayer())
TheNormalnij marked this conversation as resolved.
Show resolved Hide resolved
return false;

CClientPed& Ped = static_cast<CClientPed&>(Entity);
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaElementDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,7 @@ bool CLuaElementDefs::SetLowLodElement(lua_State* luaVM, CClientEntity* pEntity,

bool CLuaElementDefs::SetElementOnFire(CClientEntity* entity, bool onFire) noexcept
{
if (!entity->IsLocalEntity())
if (!entity->IsLocalEntity() && entity != CStaticFunctionDefinitions::GetLocalPlayer())
TheNormalnij marked this conversation as resolved.
Show resolved Hide resolved
return false;

return entity->SetOnFire(onFire);
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CTaskManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class CTaskManager
virtual CTask* FindActiveTaskByType(const int iTaskType) = 0;
virtual CTask* FindTaskByType(const int iPriority, const int iTaskType) = 0;
virtual void RemoveTaskSecondary(const int iTaskPriority) = 0;
virtual bool RemoveTaskSecondary(const int taskPriority, const int taskType) = 0;
// virtual void SetTaskSecondary(CTask* pTaskSecondary, const int iType)=0;
virtual CTask* GetTaskSecondary(const int iType) = 0;
virtual bool HasTaskSecondary(const CTask* pTaskSecondary) = 0;
Expand Down
Loading