Skip to content

Commit

Permalink
ChaosMod: Re-patch shop_controller if thread id changes
Browse files Browse the repository at this point in the history
Fixes #3551
  • Loading branch information
pongo1231 committed Aug 24, 2023
1 parent da9a779 commit d3ef55b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 7 additions & 2 deletions ChaosMod/Lib/scrThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,20 @@ namespace rage
virtual __int64 Kill() = 0;

public:
const char *GetName() const
DWORD GetThreadId() const
{
return getGameVersion() < eGameVersion::VER_1_0_2699_0_STEAM ? pad_2699 : m_Name;
return m_ThreadId;
}

DWORD GetHash() const
{
return m_ScriptHash;
}

const char *GetName() const
{
return getGameVersion() < eGameVersion::VER_1_0_2699_0_STEAM ? pad_2699 : m_Name;
}
};
}

Expand Down
16 changes: 10 additions & 6 deletions ChaosMod/Memory/Hooks/ScriptThreadRunHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

#include <scripthookv/inc/main.h>

static bool ms_EnabledHook = false;
static bool ms_EnabledHook = false;

static bool ms_RanOnlineVehicleDespawnPatch = false;
static DWORD64 ms_OnlineVehicleDespawnPatchAddr = 0;
static DWORD ms_OnlineVehicleDespawnScriptThreadId = 0;
static DWORD64 ms_OnlineVehicleDespawnPatchAddr = 0;
static std::array<BYTE, 3> ms_OnlineVehicleDespawnPatchOrigBytes;

__int64 (*OG_rage__scrThread__Run)(rage::scrThread *);
Expand All @@ -28,11 +28,15 @@ __int64 HK_rage__scrThread__Run(rage::scrThread *thread)

if (!strcmp(thread->GetName(), "shop_controller"))
{
if (!ms_RanOnlineVehicleDespawnPatch)
auto threadId = thread->GetThreadId();
if (ms_OnlineVehicleDespawnScriptThreadId != threadId)
{
ms_RanOnlineVehicleDespawnPatch = true;
LOG("New shop_controller script instance with thread ID " << threadId << "!");

auto program = Memory::ScriptThreadToProgram(thread);
ms_OnlineVehicleDespawnScriptThreadId = threadId;
ms_OnlineVehicleDespawnPatchAddr = 0;

auto program = Memory::ScriptThreadToProgram(thread);
if (program->m_CodeBlocks)
{
// Thanks to rainbomizer
Expand Down

0 comments on commit d3ef55b

Please sign in to comment.