Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

C++ Hooking?


ClassicGTAManiac
 Share

Recommended Posts

ClassicGTAManiac

Hey,

 

I am currently learning C++, and am interested in working with the Grand Theft Auto series (with mods such as Multi Theft Auto), but I was wondering if anybody could lend a hand and give me some brief guidelines? Basically, I just need to know an overview of how C++ hooking works, what libraries/functions I should look into, any documentation on doing so (I've looked around and not found anything relatively good). Any examples (even if extremely basic) would be fantastic.

 

Thanks,

Callum

Link to comment
Share on other sites

To make ASI mods, have the ASI loader installed and create a DLL Project and set the output destination to the GTASA dir with .asi extension.

 

Example (VC++), forum messed up the indention or something:

 

 

#include "StdAfx.h"BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID lpReserved){if(reason==DLL_PROCESS_ATTACH){ // Hack away!  patch(0x476154, &func_089D, 4);   // what I use in VJ to replace a dummy opcode}return TRUE;}// use this function to write protected memory...void _patch(void *pAddress, DWORD data, DWORD iSize){unsigned long dwProtect[2];VirtualProtect(pAddress, iSize, PAGE_EXECUTE_READWRITE, &dwProtect[0]);switch(iSize){ case 1: *(BYTE*)pAddress = (BYTE)data; break; case 2: *(WORD*)pAddress = (WORD)data; break; case 4: *(DWORD*)pAddress = (DWORD)data; break; default: memset(pAddress, data, iSize); break;}VirtualProtect(pAddress, iSize, dwProtect[0], &dwProtect[1]);}

 

 

Good luck smile.gif

Link to comment
Share on other sites

ClassicGTAManiac

Thanks, I'll look into this when I get home, but I was hoping to find out more about hooking into GTA from a seperate process (obviously programmed in C++).

Link to comment
Share on other sites

You are probably looking for an injector.

Here:

 

#include <windows.h> #include <tlhelp32.h> #include <shlwapi.h> #include <conio.h> #include <stdio.h> #define WIN32_LEAN_AND_MEAN #define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ) BOOL Inject(DWORD pID, const char * DLL_NAME); DWORD GetTargetThreadIDFromProcName(const char * ProcName); int main(int argc, char * argv[]) {   // Retrieve process ID   DWORD pID = GetTargetThreadIDFromProcName("cmd.exe");      // Get the dll's full path name   char buf[MAX_PATH] = {0};   GetFullPathName("injected.dll", MAX_PATH, buf, NULL);   printf(buf);   printf("\n");      // Inject our main dll   if(!Inject(pID, buf))   {        printf("DLL Not Loaded!");    }else{        printf("DLL Loaded!");    }    _getch();   return 0; } BOOL Inject(DWORD pID, const char * DLL_NAME) {   HANDLE Proc;   HMODULE hLib;   char buf[50] = {0};   LPVOID RemoteString, LoadLibAddy;   if(!pID)      return false;   Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);   if(!Proc)   {      sprintf(buf, "OpenProcess() failed: %d", GetLastError());      //MessageBox(NULL, buf, "Loader", MB_OK);      printf(buf);      return false;   }      LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");   // Allocate space in the process for our DLL   RemoteString = (LPVOID)VirtualAllocEx(Proc, NULL, strlen(DLL_NAME), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);   // Write the string name of our DLL in the memory allocated   WriteProcessMemory(Proc, (LPVOID)RemoteString, DLL_NAME, strlen(DLL_NAME), NULL);   // Load our DLL   CreateRemoteThread(Proc, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL);   CloseHandle(Proc);   return true; } DWORD GetTargetThreadIDFromProcName(const char * ProcName) {   PROCESSENTRY32 pe;   HANDLE thSnapShot;   BOOL retval, ProcFound = false;   thSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);   if(thSnapShot == INVALID_HANDLE_VALUE)   {      //MessageBox(NULL, "Error: Unable to create toolhelp snapshot!", "2MLoader", MB_OK);      printf("Error: Unable to create toolhelp snapshot!");      return false;   }   pe.dwSize = sizeof(PROCESSENTRY32);      retval = Process32First(thSnapShot, &pe);   while(retval)   {      if(StrStrI(pe.szExeFile, ProcName))      {         return pe.th32ProcessID;      }      retval = Process32Next(thSnapShot, &pe);   }   return 0; }

 

 

It simply loads a dll file into a process. Rename the process and dll file according to your needs and compile it as an exe.

EDIT: BTW its not mine but I found this somewhere and found it reliable.

Link to comment
Share on other sites

@Up

We have already ASI loader @[email protected]

Link to comment
Share on other sites

ClassicGTAManiac

Swoorup, thanks for the help, really appreciate it.

 

However, when I try and compile the code you supplied, I get;

 

 

main.obj : error LNK2019: unresolved external symbol [email protected] referenced in function "unsigned long __cdecl GetTargetThreadIDFromProcName(char const *)" ([email protected]@[email protected])
Link to comment
Share on other sites

I am not sure if Visual C++ compiler can compile it because it throws a lot of errors.

If you have ming gw compiler throw this in the command line.

 

 

g++ dll_injector.cpp -o injector.exe

OR

gcc dll_injector.cpp -o injector.exe

 

Also note that this is a C program not C++.

 

 

@Up

We have already ASI loader @[email protected]

 

Yes, of course. But I don't asi loader can load dll from a seperate process.

This is just an injector. It can load into a process from anywhere, anytime rolleyes.gif

Edited by Swoorup
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.