@@ -26,6 +26,8 @@ static bool g_d3dx11;
2626
2727static 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+
130212NTSTATUS 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
402487static 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+
404517FARPROC 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
0 commit comments