AcidShout

GTA V Patch - Loader

Apr 15th, 2015
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.83 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #define SLEEP_TIME 100000
  4.  
  5. HANDLE GetProcessByName(char* name) {
  6.     DWORD pid = 0;
  7.  
  8.     // Create toolhelp snapshot.
  9.     HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  10.     PROCESSENTRY32 process;
  11.     ZeroMemory(&process, sizeof(process));
  12.     process.dwSize = sizeof(process);
  13.  
  14.     // Walkthrough all processes.
  15.     if (Process32First(snapshot, &process)) {
  16.         do {
  17.             // Compare process.szExeFile based on format of name, i.e., trim file path
  18.             // trim .exe if necessary, etc.
  19.             if (!strcmp(process.szExeFile, name)) {
  20.                 pid = process.th32ProcessID;
  21.                 break;
  22.             }
  23.         } while (Process32Next(snapshot, &process));
  24.     }
  25.  
  26.     CloseHandle(snapshot);
  27.  
  28.     if (pid != 0) {
  29.         return OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
  30.     }
  31.  
  32.     return NULL;
  33. }
  34.  
  35. int _tmain(int argc, _TCHAR* argv[]) {
  36.     printf("[ GTA V switchable graphics fix - AcidShout @ reddit ]\n\n");
  37.  
  38.     if (!IsUserAnAdmin()) {
  39.         printf("[!] Not running as admin, patch may fail.\n");
  40.     }
  41.  
  42.     printf("[>] Waiting for GTA V...\n");
  43.  
  44.     FILE* tmp;
  45.     int err;
  46.     char tmpnambuf[L_tmpnam_s];
  47.     if ((err = tmpnam_s(tmpnambuf)) != 0) {
  48.         printf("[#TFE] Error: %d\n", err);
  49.         Sleep(SLEEP_TIME);
  50.         return 0;
  51.     }
  52.  
  53.     tmp = fopen(tmpnambuf, "w+");
  54.     fwrite(VEH_DLL, 1, sizeof(VEH_DLL), tmp);
  55.  
  56.     HANDLE old_gtav = NULL;
  57.     while (true) {
  58.         HANDLE gtav;
  59.  
  60.         if ((gtav = GetProcessByName("GTA5.exe")) != NULL && gtav != old_gtav) {
  61.             printf("Found GTA5.exe! Patching...\n");
  62.  
  63.             int pathlength = strlen(tmpnambuf);
  64.             void* mem = VirtualAllocEx(gtav, NULL, pathlength, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  65.  
  66.             if (!mem) {
  67.                 printf("[#UAM] Error: %d\n", GetLastError());
  68.                 Sleep(SLEEP_TIME);
  69.                 return 0;
  70.             }
  71.  
  72.             if (!WriteProcessMemory(gtav, mem, tmpnambuf, pathlength, NULL)) {
  73.                 printf("[#WPM] Cannot write process memory! (%d)\n", GetLastError());
  74.                 Sleep(SLEEP_TIME);
  75.                 return 0;
  76.             }
  77.  
  78.             HANDLE remoteThread = CreateRemoteThread(
  79.                 gtav,
  80.                 NULL,
  81.                 0,
  82.                 (LPTHREAD_START_ROUTINE) GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA"),
  83.                 mem,
  84.                 0,
  85.                 NULL
  86.             );
  87.  
  88.             if (!remoteThread) {
  89.                 printf("[#CRT] Cannot create remote thread! (%d)\n", GetLastError());
  90.                 Sleep(SLEEP_TIME);
  91.                 return 0;
  92.             }
  93.  
  94.             WaitForSingleObject(remoteThread, INFINITE);
  95.  
  96.             DWORD tec; // thread exit code
  97.             GetExitCodeThread(remoteThread, &tec);
  98.  
  99.             CloseHandle(remoteThread);
  100.             VirtualFreeEx(gtav, mem, pathlength, MEM_RELEASE);
  101.  
  102.             if (tec) {
  103.                 printf("[ERR] Something went wrong. Not sure if GTA V is patched properly.\nError code: %d\n", GetLastError());
  104.                 Sleep(SLEEP_TIME);
  105.                 return 0;
  106.             } else {
  107.                 printf("\n\n==============\nGTA V patched!\n==============\nNow you can play, have fun, fellow gamer!\n\n- AcidShout\n");
  108.                 Sleep(100000);
  109.                 return 0;
  110.             }
  111.         }
  112.  
  113.         Sleep(500);
  114.     }
  115.  
  116.     fclose(tmp);
  117.  
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment