Skip to content

Commit 15251aa

Browse files
committed
hello there, Bob
1 parent c814f80 commit 15251aa

174 files changed

Lines changed: 17028 additions & 387 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitlab-ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,33 @@ build_client:
3030
paths:
3131
- code/shared/citversion.h
3232
- code/build/
33+
except:
34+
- server-ci
35+
- portability-rdr3
36+
- tags
37+
38+
build_client_rdr3:
39+
<<: *build_windows
40+
tags:
41+
- vs2017
42+
- client
43+
variables:
44+
IS_FXSERVER: '0'
45+
IS_LAUNCHER: '0'
46+
IS_RDR3: '1'
47+
artifacts:
48+
paths:
49+
- caches/diff/
50+
- caches/caches.xml
51+
- caches/CitizenFX.exe.xz
52+
- caches/version.txt
53+
expire_in: 1 month
54+
cache:
55+
key: rdr3
56+
untracked: true
57+
paths:
58+
- code/shared/citversion.h
59+
- code/build/
3360
except:
3461
- server-ci
3562
- tags
@@ -58,6 +85,7 @@ build_launcher:
5885
- code/build/
5986
except:
6087
- server-ci
88+
- portability-rdr3
6189
- tags
6290

6391
build_server_windows:
@@ -75,6 +103,7 @@ build_server_windows:
75103
- tags
76104
#- master
77105
- feature/update-to-1365
106+
- portability-rdr3
78107
#- feature/update-to-1493
79108
cache:
80109
key: server
@@ -100,6 +129,7 @@ build_proot_linux:
100129
- feature/update-to-1604
101130
- feature/cloning-stuff-releng
102131
- feature/cloning-plus
132+
- portability-rdr3
103133
tags:
104134
- linux
105135

code/client/citicore/FileMapping.Win32.cpp

Lines changed: 183 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ static bool g_d3dx11;
2626

2727
static std::wstring MapRedirectedFilename(const wchar_t* origFileName)
2828
{
29+
//trace("map %s\n", ToNarrow(origFileName));
30+
2931
if (wcsstr(origFileName, L"autosignin.dat") != nullptr)
3032
{
3133
return MakeRelativeCitPath(L"cache\\game\\autosignin.dat");
@@ -56,6 +58,43 @@ static std::wstring MapRedirectedFilename(const wchar_t* origFileName)
5658
return MakeRelativeCitPath(L"nodontfuckingplaygtav.exe");
5759
}
5860

61+
if (wcsstr(origFileName, L"LauncherPatcher.exe") != nullptr)
62+
{
63+
return MakeRelativeCitPath(L"nodontfuckingplaygtav.exe");
64+
}
65+
66+
if (wcsstr(origFileName, L"Data\\Rockstar Games\\Launcher") != nullptr)
67+
{
68+
return MakeRelativeCitPath(L"cache\\game\\ros_launcher_data") + &wcsstr(origFileName, L"Games\\Launcher")[14];
69+
}
70+
71+
if (wcsstr(origFileName, L"Local\\Rockstar Games\\Launcher") != nullptr)
72+
{
73+
return MakeRelativeCitPath(L"cache\\game\\ros_launcher_appdata") + &wcsstr(origFileName, L"Games\\Launcher")[14];
74+
}
75+
76+
if (wcsstr(origFileName, L"Rockstar Games\\GTA5.exe") != nullptr)
77+
{
78+
return origFileName;
79+
}
80+
81+
if (wcsstr(origFileName, L"Rockstar Games\\RDR2.exe") != nullptr)
82+
{
83+
return origFileName;
84+
}
85+
86+
if (getenv("CitizenFX_ToolMode"))
87+
{
88+
if (wcsstr(origFileName, L"Rockstar Games\\Red Dead Redemption 2\\") != nullptr)
89+
{
90+
CreateDirectoryW(MakeRelativeCitPath(L"cache\\game\\ros_launcher_game").c_str(), NULL);
91+
92+
static std::wstring s;
93+
s = MakeRelativeCitPath(L"cache\\game\\ros_launcher_game") + &wcsstr(origFileName, L"d Redemption 2")[14];
94+
origFileName = s.c_str();
95+
}
96+
}
97+
5998
wchar_t* fileName = g_mappingFunction(origFileName, malloc);
6099

61100
std::wstring retval(fileName);
@@ -84,6 +123,22 @@ static bool IsMappedFilename(const std::wstring& fileName)
84123
{
85124
return true;
86125
}
126+
127+
if (fileName.find(L"Files\\Rockstar Games\\Launcher") != std::string::npos)
128+
{
129+
return true;
130+
}
131+
132+
if (fileName.find(L"Data\\Rockstar Games\\Launcher") != std::string::npos)
133+
{
134+
return true;
135+
}
136+
137+
// TODO: support redirected localappdata!!
138+
if (fileName.find(L"Data\\Local\\Rockstar Games\\Launcher") != std::string::npos)
139+
{
140+
return true;
141+
}
87142

88143
if (fileName.find(L"autosignin.dat") != std::string::npos)
89144
{
@@ -110,11 +165,29 @@ static bool IsMappedFilename(const std::wstring& fileName)
110165
return true;
111166
}
112167

113-
if (fileName.length() > 10 && fileName.compare(fileName.length() - 8, 8, L"GTA5.exe") == 0)
168+
if (wcsstr(fileName.c_str(), L"LauncherPatcher.exe") != nullptr)
114169
{
115170
return true;
116171
}
117172

173+
if (fileName.length() > 10 && fileName.compare(fileName.length() - 8, 8, L"GTA5.exe") == 0 && fileName.find(L"Rockstar Games\\GTA5.exe") == std::string::npos)
174+
{
175+
return true;
176+
}
177+
178+
if (fileName.length() > 10 && fileName.compare(fileName.length() - 8, 8, L"RDR2.exe") == 0 && fileName.find(L"Rockstar Games\\RDR2.exe") == std::string::npos)
179+
{
180+
return true;
181+
}
182+
183+
if (getenv("CitizenFX_ToolMode"))
184+
{
185+
if (wcsstr(fileName.c_str(), L"Rockstar Games\\Red Dead Redemption 2\\") != nullptr/* && wcsstr(fileName.c_str(), L"index.bin") == nullptr*/)
186+
{
187+
return true;
188+
}
189+
}
190+
118191
return false;
119192
}
120193

@@ -127,6 +200,15 @@ static HANDLE CreateFileWStub(_In_ LPCWSTR lpFileName, _In_ DWORD dwDesiredAcces
127200
return g_origCreateFileW(fileName.c_str(), dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
128201
}
129202

203+
static BOOL(*g_origGetFileAttributesExW)(_In_ LPCWSTR lpFileName, _In_ GET_FILEEX_INFO_LEVELS fInfoLevelId, _Out_writes_bytes_(sizeof(WIN32_FILE_ATTRIBUTE_DATA)) LPVOID lpFileInformation);
204+
205+
static BOOL GetFileAttributesExWStub(_In_ LPCWSTR lpFileName, _In_ GET_FILEEX_INFO_LEVELS fInfoLevelId, _Out_writes_bytes_(sizeof(WIN32_FILE_ATTRIBUTE_DATA)) LPVOID lpFileInformation)
206+
{
207+
std::wstring fileName = MapRedirectedFilename(lpFileName);
208+
209+
return g_origGetFileAttributesExW(fileName.c_str(), fInfoLevelId, lpFileInformation);
210+
}
211+
130212
NTSTATUS NTAPI LdrLoadDllStub(const wchar_t* fileName, uint32_t* flags, UNICODE_STRING* moduleName, HANDLE* handle)
131213
{
132214
UNICODE_STRING newString;
@@ -163,8 +245,11 @@ NTSTATUS NTAPI LdrLoadDllStub(const wchar_t* fileName, uint32_t* flags, UNICODE_
163245
moduleNameStr.find(L"PrxerDrv.dll") != std::string::npos ||
164246
// Ad Muncher, causes LoopbackTcpServer to crash
165247
moduleNameStr.find(L"am64-34121.dll") != std::string::npos ||
248+
#if !defined(IS_RDR3)
166249
// VulkanRT loader, we don't use Vulkan, CEF does (to 'collect info'), and this crashes a lot of Vulkan drivers
167-
moduleNameStr.find(L"vulkan-1.dll") != std::string::npos
250+
moduleNameStr.find(L"vulkan-1.dll") != std::string::npos ||
251+
#endif
252+
false
168253
)
169254
{
170255
return 0xC0000135;
@@ -401,12 +486,105 @@ static HRESULT WINAPI QueryDListForApplication1Stub(BOOL* pDefaultToDiscrete, HA
401486

402487
static FARPROC(WINAPI* g_origGetProcAddress)(HMODULE hModule, LPCSTR procName, void* caller);
403488

489+
NTSTATUS NTAPI NtCloseHook(IN HANDLE Handle);
490+
NTSTATUS NtQueryInformationProcessHook(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL);
491+
492+
extern "C" NTSTATUS NTAPI NtQueryVirtualMemory(
493+
HANDLE ProcessHandle,
494+
PVOID BaseAddress,
495+
INT MemoryInformationClass,
496+
PVOID MemoryInformation,
497+
SIZE_T MemoryInformationLength,
498+
PSIZE_T ReturnLength
499+
);
500+
501+
NTSTATUS NtQueryVirtualMemoryHook(
502+
HANDLE ProcessHandle,
503+
PVOID BaseAddress,
504+
INT MemoryInformationClass,
505+
PVOID MemoryInformation,
506+
SIZE_T MemoryInformationLength,
507+
PSIZE_T ReturnLength
508+
)
509+
{
510+
trace("qvm %016llx %d\n", (uintptr_t)BaseAddress, MemoryInformationClass);
511+
512+
return NtQueryVirtualMemory(ProcessHandle, BaseAddress, MemoryInformationClass, MemoryInformation, MemoryInformationLength, ReturnLength);
513+
}
514+
515+
#include <Hooking.h>
516+
404517
FARPROC WINAPI GetProcAddressStub(HMODULE hModule, LPCSTR lpProcName, void* caller)
405518
{
406519
static const DWORD bigOne = 1;
407520

408521
if (!IS_INTRESOURCE(lpProcName))
409522
{
523+
static thread_local bool in;
524+
525+
if (!in)
526+
{
527+
in = true;
528+
//trace("%s\n", lpProcName);
529+
in = false;
530+
}
531+
532+
if (!getenv("CitizenFX_ToolMode") || true)
533+
{
534+
if (hModule == GetModuleHandleW(L"ntdll.dll") && _stricmp(lpProcName, "NtQueryInformationProcess") == 0)
535+
{
536+
//auto lol = (char*)GetModuleHandleW(L"ntdll.dll") + 0x183000;
537+
auto lol = (char*)GetModuleHandleW(L"ntdll.dll") + 0x00118400 - 0x40;
538+
539+
static std::once_flag lold;
540+
541+
std::call_once(lold, [lol]
542+
{
543+
DWORD oldProtect;
544+
VirtualProtect(lol, 48, PAGE_EXECUTE_READWRITE, &oldProtect);
545+
546+
static struct : jitasm::Frontend
547+
{
548+
uintptr_t f;
549+
550+
void InternalMain() override
551+
{
552+
mov(rax, qword_ptr[rsp + 0x28]);
553+
sub(rsp, 0x38);
554+
mov(qword_ptr[rsp + 0x20], rax);
555+
mov(rax, f);
556+
call(rax);
557+
add(rsp, 0x38);
558+
ret();
559+
}
560+
} g;
561+
562+
g.f = (uint64_t)NtQueryInformationProcessHook;
563+
564+
auto c = g.GetCode();
565+
memcpy(lol, c, g.GetCodeSize());
566+
567+
VirtualProtect(lol, 48, PAGE_EXECUTE_READ, &oldProtect);
568+
});
569+
570+
return (FARPROC)lol;
571+
572+
//return (FARPROC)NtQueryInformationProcessHook;
573+
//return (FARPROC)NtQueryInformationProcess;
574+
}
575+
576+
if (hModule == GetModuleHandleW(L"ntdll.dll") && _stricmp(lpProcName, "NtQueryVirtualMemory") == 0)
577+
{
578+
return (FARPROC)NtQueryVirtualMemoryHook;
579+
//return (FARPROC)NtQueryInformationProcess;
580+
}
581+
582+
if (hModule == GetModuleHandleW(L"ntdll.dll") && _stricmp(lpProcName, "NtClose") == 0)
583+
{
584+
//return (FARPROC)NtCloseHook;
585+
}
586+
}
587+
410588
if (_stricmp(lpProcName, "NvOptimusEnablement") == 0 || _stricmp(lpProcName, "AmdPowerXpressRequestHighPerformance") == 0)
411589
{
412590
return (FARPROC)&bigOne;
@@ -538,21 +716,22 @@ extern "C" DLL_EXPORT void CoreSetMappingFunction(MappingFunctionType function)
538716
g_mappingFunction = function;
539717
g_tlsHandle = TlsAlloc();
540718

719+
LSP_InitializeHooks();
720+
541721
MH_CreateHookApi(L"ntdll.dll", "NtCreateFile", NtCreateFileStub, (void**)&g_origNtCreateFile);
542722
MH_CreateHookApi(L"ntdll.dll", "NtOpenFile", NtOpenFileStub, (void**)&g_origNtOpenFile);
543723
MH_CreateHookApi(L"ntdll.dll", "NtDeleteFile", NtDeleteFileStub, (void**)&g_origNtDeleteFile);
544724
MH_CreateHookApi(L"ntdll.dll", "NtQueryAttributesFile", NtQueryAttributesFileStub, (void**)&g_origNtQueryAttributesFile);
545725
MH_CreateHookApi(L"ntdll.dll", "LdrLoadDll", LdrLoadDllStub, (void**)&g_origLoadDll);
546726
MH_CreateHookApi(L"ntdll.dll", "LdrGetProcedureAddress", LdrGetProcedureAddressStub, (void**)&g_origGetProcedureAddress);
547727
MH_CreateHookApi(L"kernelbase.dll", "RegOpenKeyExW", RegOpenKeyExWStub, (void**)&g_origRegOpenKeyExW);
728+
MH_CreateHookApi(L"kernelbase.dll", "GetFileAttributesExW", GetFileAttributesExWStub, (void**)&g_origGetFileAttributesExW);
548729
MH_CreateHookApi(L"kernelbase.dll", "GetProcAddressForCaller", GetProcAddressStub, (void**)&g_origGetProcAddress);
549730
MH_EnableHook(MH_ALL_HOOKS);
550731

551732
static auto _LdrRegisterDllNotification = (decltype(&LdrRegisterDllNotification))GetProcAddress(GetModuleHandle(L"ntdll.dll"), "LdrRegisterDllNotification");
552733
_LdrRegisterDllNotification(0, LdrDllNotification, nullptr, &g_lastDllNotif);
553734

554-
LSP_InitializeHooks();
555-
556735
trace("Initialized system mapping!\n");
557736
}
558737

code/client/citicore/LSPHooks.Win32.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool IsModule(void* address)
8888

8989
typedef NTSTATUS(*NtQueryInformationProcessType)(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL);
9090

91-
static NTSTATUS NtQueryInformationProcessHook(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
91+
NTSTATUS NtQueryInformationProcessHook(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, OUT PULONG ReturnLength OPTIONAL)
9292
{
9393
NTSTATUS status = ((NtQueryInformationProcessType)origQIP)(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength, ReturnLength);
9494

@@ -157,13 +157,14 @@ void LSP_InitializeHooks()
157157

158158
MH_CreateHookApi(L"kernelbase.dll", "RegOpenKeyExA", ProcessLSPRegOpenKeyExA, (void**)&g_origRegOpenKeyExA);
159159

160-
if (CoreIsDebuggerPresent())
160+
//if (CoreIsDebuggerPresent())
161161
{
162-
MH_CreateHookApi(L"ntdll.dll", "NtQueryInformationProcess", NtQueryInformationProcessHook, (void**)&origQIP);
162+
//MH_CreateHookApi(L"ntdll.dll", "NtQueryInformationProcess", NtQueryInformationProcessHook, (void**)&origQIP);
163+
//MH_CreateHookApi(L"ntdll.dll", "NtClose", NtCloseHook, (void**)&origClose);
164+
origQIP = (decltype(origQIP))GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtQueryInformationProcess");
165+
origClose = (decltype(origClose))GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtClose");
163166
}
164167

165-
MH_CreateHookApi(L"ntdll.dll", "NtClose", NtCloseHook, (void**)&origClose);
166-
167168
MH_EnableHook(MH_ALL_HOOKS);
168169
}
169170
#endif

code/client/citicore/PatternCache.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77

88
#include "StdInc.h"
99

10-
#ifdef GTA_FIVE
10+
#if defined(GTA_FIVE) || defined(IS_RDR3)
1111
#include <Hooking.h>
1212

13+
#if defined(IS_RDR3)
14+
static uintptr_t g_currentStub = 0x148000000;
15+
#else
1316
static uintptr_t g_currentStub = 0x146000000;
17+
#endif
1418

1519
extern "C"
1620
{

code/client/citicore/SEHTableHandler.Win32.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,19 @@ static BOOLEAN(*g_origRtlDispatchException)(EXCEPTION_RECORD* record, CONTEXT* c
238238

239239
static BOOLEAN RtlDispatchExceptionStub(EXCEPTION_RECORD* record, CONTEXT* context)
240240
{
241+
// anti-anti-anti-anti-debug
242+
if (CoreIsDebuggerPresent() && (record->ExceptionCode == 0xc0000008/* || record->ExceptionCode == 0x80000003*/))
243+
{
244+
return TRUE;
245+
}
246+
241247
BOOLEAN success = g_origRtlDispatchException(record, context);
242248

249+
if (CoreIsDebuggerPresent())
250+
{
251+
return success;
252+
}
253+
243254
static bool inExceptionFallback;
244255

245256
if (!success)
@@ -270,7 +281,7 @@ extern "C" void DLL_EXPORT CoreSetExceptionOverride(LONG(*handler)(EXCEPTION_POI
270281
{
271282
if (CoreIsDebuggerPresent())
272283
{
273-
return;
284+
//return;
274285
}
275286

276287
g_exceptionHandler = handler;

0 commit comments

Comments
 (0)