Skip to content

Commit

Permalink
Merge Better scrThread adjustment to support new TU (mr-641)
Browse files Browse the repository at this point in the history
4a02b90 - fix(five): better scrThread adjustment to support new TU
  • Loading branch information
prikolium-cfx committed Dec 24, 2024
2 parents 2070731 + 4a02b90 commit bc34246
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 35 deletions.
61 changes: 26 additions & 35 deletions code/components/rage-scripting-five/include/scrThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,30 +190,38 @@ struct scrThreadContext

static_assert(sizeof(scrThreadContext) == 168, "scrThreadContext has wrong size!");

class
class
#ifdef COMPILING_RAGE_SCRIPTING_FIVE
__declspec(dllexport)
__declspec(dllexport)
#endif
scrThread
scrThread
{
protected:
scrThreadContext m_Context;
void* m_pStack; // should be +176 including vtable
void* pad;
void* pad2;
scrThreadContext m_Context;
void* m_pStack; // should be +176 including vtable
void* pad;
void* pad2;

// should be +200
const char* m_pszExitMessage;
const char* m_pszExitMessage;

public:
virtual void __dummyMethod1() {}
virtual ~scrThread() {}
virtual eThreadState Reset(uint32_t scriptHash, void* pArgs, uint32_t argCount) = 0;
virtual eThreadState Run(uint32_t opsToExecute) = 0;
virtual eThreadState Tick(uint32_t opsToExecute) = 0;
virtual void Kill() = 0;

scrThreadContext* GetContext() { return &m_Context; }
virtual uint64_t proxyMethod1(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);
virtual uint64_t proxyMethod2(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);
virtual uint64_t proxyMethod3(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);
virtual uint64_t proxyMethod4(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);
virtual uint64_t proxyMethod5(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);
virtual uint64_t proxyMethod6(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4);

virtual eThreadState Reset(uint32_t scriptHash, void* pArgs, uint32_t argCount) = 0;
virtual eThreadState Run(uint32_t opsToExecute) = 0;
virtual eThreadState Tick(uint32_t opsToExecute) = 0;
virtual void Kill() = 0;

scrThreadContext* GetContext()
{
return &m_Context;
}
};
}

Expand Down Expand Up @@ -241,30 +249,13 @@ class
char pad_b2699[8];

public:
GtaThread()
{
if (!xbr::IsGameBuildOrGreater<3407>())
{
auto vtable = *(void***)this;
DWORD oldProtect;
VirtualProtect(vtable, 5 * 8, PAGE_EXECUTE_READWRITE, &oldProtect);

for (int i = 0; i < 5; i++)
{
vtable[i] = vtable[i + 1];
}

VirtualProtect(vtable, 5 * 8, oldProtect, &oldProtect);
}
}

virtual void DoRun() = 0;

virtual rage::eThreadState Reset(uint32_t scriptHash, void* pArgs, uint32_t argCount);
virtual rage::eThreadState Run(uint32_t opsToExecute);
virtual rage::eThreadState Tick(uint32_t opsToExecute);
virtual void Kill();

virtual void DoRun() = 0;

inline void SetScriptName(const char* name)
{
if (xbr::IsGameBuildOrGreater<2699>())
Expand Down
67 changes: 67 additions & 0 deletions code/components/rage-scripting-five/src/scrThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,70 @@ static hook::thiscall_stub<void(rage::scrNativeCallContext*)> setVectorResults([
{
return hook::pattern("83 79 18 00 48 8B D1 74 4A FF 4A 18").count(1).get(0).get<void>();
});

uint64_t rage::scrThread::proxyMethod1(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4)
{
return 0;
}

uint64_t rage::scrThread::proxyMethod2(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4)
{
if (xbr::IsGameBuildOrGreater<3407>())
{
return 0;
}
else
{
return Reset((uint32_t)a1, (void*)a2, (uint32_t)a3);
}
} // Reset or dtor

uint64_t rage::scrThread::proxyMethod3(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4)
{
if (xbr::IsGameBuildOrGreater<3407>())
{
return Reset((uint32_t)a1, (void*)a2, (uint32_t)a3);
}
else
{
return Run((uint32_t)a1);
}
} // Run or Reset

uint64_t rage::scrThread::proxyMethod4(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4)
{
if (xbr::IsGameBuildOrGreater<3407>())
{
return Run((uint32_t)a1);
}
else
{
return Tick((uint32_t)a1);
}
} // Run or Reset

uint64_t rage::scrThread::proxyMethod5(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4)
{
if (xbr::IsGameBuildOrGreater<3407>())
{
return Tick((uint32_t)a1);
}
else
{
Kill();
return 0;
}
} // Tick or Run

uint64_t rage::scrThread::proxyMethod6(uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4)
{
if (xbr::IsGameBuildOrGreater<3407>())
{
Kill();
return 0;
}
else
{
return 0;
}
} // Kill or Tick

0 comments on commit bc34246

Please sign in to comment.