Results 1 to 4 of 4

Threaded View

  1. #1
    Kai13shadow's Avatar
    Join Date
    Jun 2011
    Gender
    male
    Posts
    57
    Reputation
    10
    Thanks
    2,934

    C++ Script Help - Garry's Mod - Forcing r_drawothermodels 2

    Okay, so what I'm attempting to do is change the value stored at client.dll+005C58D8 (r_drawothermodels) to 2.
    I have completely no idea what I am doing wrong...
    I'm a bit of a newbie to C++, so please try to go easy on me and explain as much as you can about what I've done wrong!
    Code:
    #include <Windows.h>
    #include <iostream>
    #include <string.h>
    
    using namespace std;
    
    int main() {
    	HWND hwnd;
    	HANDLE handle;
    	DWORD process_ID;
    
    	hwnd = FindWindow(NULL, "Garry's Mod");
    	GetWindowThreadProcessId(hwnd, &process_ID);
    	handle = OpenProcess(PROCESS_ALL_ACCESS, false, process_ID);
    
    	system("cls");
    	system("title Garry's Mod Wallhack");
    	system("color 0a");
    
    	int newVar = 2;
    	DWORD* baseAddress = (DWORD*)GetModuleHandle("client.dll");
    	DWORD* Address = baseAddress + 0x5C58D8;
    	if(WriteProcessMemory(handle, (DWORD*)Address, &newVar, sizeof(newVar), NULL)) {
    		cout << "Hacked Successfully!" << endl;
    		cout << "Press ENTER to end this program...";
    		cin.get();
    	}
    	else {
    		cout << "Failed to hack..." << endl;
    		cout << "Press ENTER to end this program...";
    		cin.get();
    	}
    
    	CloseHandle(handle);
    	return 1;
    }
    I think maybe the error might lie around the code below, but i'm not 100% sure.
    Code:
    	DWORD* baseAddress = (DWORD*)GetModuleHandle("client.dll");
    	DWORD* Address = baseAddress + 0x5C58D8;
    	if(WriteProcessMemory(handle, (DWORD*)Address, &newVar, sizeof(newVar), NULL))
    This part of it is my attempt to join the address at client.dll with the 0x5C58D8 (i think 0x5C58D8 is the offset)

    I don't actually get an error really, just the output from my console window is always "Failed to hack..." (The output if the value was unable to be changed)

    Also I know that I have a high chance of being vac banned and blah blah blah or something like that because this 'hack' is literally just forcing one of the game's variables. I don't really care about this, this is just a little 'test' to help me get started with 'hacking' using C++.

    I know that the answer is probably really really obvious, but like i said, I'm still a newbie to this stuff :S

    ---------- Post added at 01:47 AM ---------- Previous post was at 01:00 AM ----------

    Okay guys, don't worry about it. I managed to find and fix the errors myself. It turns out i was on the right track, just not doing it right.
    I needed to change the way i was trying to find the base address of "client.dll"

    The second function (DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName) ) is not mine. Yes, i leeched it :S
    But hey, at least i got it done. After all, I'm still new to this and learning!

    Code:
    #include <Windows.h>
    #include <iostream>
    #include <string.h>
    #include <tlhelp32.h>
    #include <tchar.h>
    
    using namespace std;
    DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName);
    
    int main() {
    	HWND hwnd;
    	HANDLE handle;
    	DWORD process_ID;
    
    	hwnd = FindWindow(NULL, "Garry's Mod");
    	GetWindowThreadProcessId(hwnd, &process_ID);
    	handle = OpenProcess(PROCESS_ALL_ACCESS, false, process_ID);
    
    	system("cls");
    	system("title Garry's Mod Wallhack");
    	system("color 0a");
    
    	int newVar = 2;
    	DWORD baseAddress = dwGetModuleBaseAddress(process_ID, _T("client.dll"));
    	DWORD newAddress = baseAddress + 0x5C58D8;
    	if(WriteProcessMemory(handle, (DWORD*)newAddress, &newVar, sizeof(newVar), NULL)) {
    		cout << "Hacked Successfully!" << endl;
    		cout << "Press ENTER to end this program...";
    		cin.get();
    	}
    	else {
    		cout << "Failed to hack..." << endl;
    		cout << "Press ENTER to end this program...";
    		cin.get();
    	}
    
    	CloseHandle(handle);
    	return 1;
    }
    
    //Find the base address [Not My Code]
    DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcessIdentifier, TCHAR *szModuleName)
    {
       DWORD_PTR dwModuleBaseAddress = 0;
       HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcessIdentifier); 
       if (hSnapshot != INVALID_HANDLE_VALUE)
       {
          MODULEENTRY32 ModuleEntry32;
          ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
          if (Module32First(hSnapshot, &ModuleEntry32))
          {
             do
             {
                if (_tcscmp(ModuleEntry32.szModule, szModuleName) == 0)
                {
                   dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
                   break;
                }
             }
             while (Module32Next(hSnapshot, &ModuleEntry32));
          }
          CloseHandle(hSnapshot);
       }
       return dwModuleBaseAddress;
    }
    Last edited by Kai13shadow; 10-11-2012 at 11:01 AM.

Similar Threads

  1. Replies: 2
    Last Post: 01-06-2016, 12:38 AM
  2. [Help Request] JetBot script help (Two boss maps).
    By Z4ck in forum Vindictus Help
    Replies: 0
    Last Post: 02-20-2012, 08:19 AM
  3. [Help Request] I need help with my mod please:)
    By LawlFaceXD in forum Combat Arms Mod Help
    Replies: 0
    Last Post: 08-09-2011, 08:36 PM
  4. [Help Request] Can anyone help me .rez Mod?
    By Albus Dumbledore in forum Combat Arms Mod Help
    Replies: 1
    Last Post: 07-01-2011, 11:22 AM
  5. [Help Request] Help With Making Mod
    By mastalol in forum Combat Arms Mod Help
    Replies: 7
    Last Post: 06-10-2011, 02:29 AM

Tags for this Thread