-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRAGEHelper.cpp
More file actions
57 lines (44 loc) · 1.88 KB
/
RAGEHelper.cpp
File metadata and controls
57 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <RAGEhelper.hpp>
#include "src/fivem/classes/classes.hpp"
DWORD64 dwRegistrationTablePtr = 0;
extern PBYTE location;
rage::pgPtrCollection<GtaThread>* GetGtaThreadCollection()
{
if (!fivem::dwThreadCollectionPtr) {
DWORD64 dwAddressOfThreadCollection = fivem::dwThreadCollectionPtr;// *(DWORD*)(dwThreadCollectionPtr + 3) + 7;
MODULEINFO g_MainModuleInfo = { 0 };
if (!GetModuleInformation(GetCurrentProcess(), GetModuleHandle(0), &g_MainModuleInfo, sizeof(g_MainModuleInfo))) {
}
if (!dwAddressOfThreadCollection ||
dwAddressOfThreadCollection < (DWORD64)g_MainModuleInfo.lpBaseOfDll ||
dwAddressOfThreadCollection >(DWORD64) g_MainModuleInfo.lpBaseOfDll + g_MainModuleInfo.SizeOfImage
) {
}
fivem::dwThreadCollectionPtr = dwAddressOfThreadCollection;
}
return (rage::pgPtrCollection<GtaThread>*) fivem::dwThreadCollectionPtr;
}
template<typename T = char*>
T get_tls()
{
static auto tlsIndex = ([]()
{
auto base = (char*)GetModuleHandleA(NULL);
auto moduleBase = (PIMAGE_DOS_HEADER)base;
auto ntBase = (PIMAGE_NT_HEADERS)(base + moduleBase->e_lfanew);
auto tlsBase = (PIMAGE_TLS_DIRECTORY)(base + ntBase->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress);
return reinterpret_cast<uint32_t*>(tlsBase->AddressOfIndex);
})();
auto tlsBase = (LPVOID*)__readgsqword(0x58);
return (T)tlsBase[*tlsIndex];
}
rage::scrThread* GetActiveThread()
{
char* moduleTls = *(char**)__readgsqword(0x58);
return *reinterpret_cast<rage::scrThread**>(get_tls() + fivem::activeThreadTlsOffset); //citizenMP sigs this offset. It's been the same for 3 versions. Not worth it.
}
//I won't even begin to claim that I know what the fuck is going on here. ~gir489
void SetActiveThread(rage::scrThread* thread)
{
*reinterpret_cast<rage::scrThread**>(get_tls() + fivem::activeThreadTlsOffset) = thread;
}