Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #define SLEEP_TIME 100000
- HANDLE GetProcessByName(char* name) {
- DWORD pid = 0;
- // Create toolhelp snapshot.
- HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- PROCESSENTRY32 process;
- ZeroMemory(&process, sizeof(process));
- process.dwSize = sizeof(process);
- // Walkthrough all processes.
- if (Process32First(snapshot, &process)) {
- do {
- // Compare process.szExeFile based on format of name, i.e., trim file path
- // trim .exe if necessary, etc.
- if (!strcmp(process.szExeFile, name)) {
- pid = process.th32ProcessID;
- break;
- }
- } while (Process32Next(snapshot, &process));
- }
- CloseHandle(snapshot);
- if (pid != 0) {
- return OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
- }
- return NULL;
- }
- int _tmain(int argc, _TCHAR* argv[]) {
- printf("[ GTA V switchable graphics fix - AcidShout @ reddit ]\n\n");
- if (!IsUserAnAdmin()) {
- printf("[!] Not running as admin, patch may fail.\n");
- }
- printf("[>] Waiting for GTA V...\n");
- FILE* tmp;
- int err;
- char tmpnambuf[L_tmpnam_s];
- if ((err = tmpnam_s(tmpnambuf)) != 0) {
- printf("[#TFE] Error: %d\n", err);
- Sleep(SLEEP_TIME);
- return 0;
- }
- tmp = fopen(tmpnambuf, "w+");
- fwrite(VEH_DLL, 1, sizeof(VEH_DLL), tmp);
- HANDLE old_gtav = NULL;
- while (true) {
- HANDLE gtav;
- if ((gtav = GetProcessByName("GTA5.exe")) != NULL && gtav != old_gtav) {
- printf("Found GTA5.exe! Patching...\n");
- int pathlength = strlen(tmpnambuf);
- void* mem = VirtualAllocEx(gtav, NULL, pathlength, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- if (!mem) {
- printf("[#UAM] Error: %d\n", GetLastError());
- Sleep(SLEEP_TIME);
- return 0;
- }
- if (!WriteProcessMemory(gtav, mem, tmpnambuf, pathlength, NULL)) {
- printf("[#WPM] Cannot write process memory! (%d)\n", GetLastError());
- Sleep(SLEEP_TIME);
- return 0;
- }
- HANDLE remoteThread = CreateRemoteThread(
- gtav,
- NULL,
- 0,
- (LPTHREAD_START_ROUTINE) GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA"),
- mem,
- 0,
- NULL
- );
- if (!remoteThread) {
- printf("[#CRT] Cannot create remote thread! (%d)\n", GetLastError());
- Sleep(SLEEP_TIME);
- return 0;
- }
- WaitForSingleObject(remoteThread, INFINITE);
- DWORD tec; // thread exit code
- GetExitCodeThread(remoteThread, &tec);
- CloseHandle(remoteThread);
- VirtualFreeEx(gtav, mem, pathlength, MEM_RELEASE);
- if (tec) {
- printf("[ERR] Something went wrong. Not sure if GTA V is patched properly.\nError code: %d\n", GetLastError());
- Sleep(SLEEP_TIME);
- return 0;
- } else {
- printf("\n\n==============\nGTA V patched!\n==============\nNow you can play, have fun, fellow gamer!\n\n- AcidShout\n");
- Sleep(100000);
- return 0;
- }
- }
- Sleep(500);
- }
- fclose(tmp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment