Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Tuners
      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. Red Dead Redemption 2

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

    1. Grand Theft Auto Series

      1. 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. Guides & Strategies
      2. Help & Support
    6. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
    7. GTA III

      1. Guides & Strategies
      2. 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. 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

      1. GTANet 20th Anniversary
    2. Support

    3. Suggestions

[REL|SRC] SA injector


JGuntherS@NL
 Share

Recommended Posts

I've made a program that injects itself into the SA-proces, making it possible to manipulate San Andreas from within. The special thing about this program is that the CRT is also usable inside the SA-proces, so that you can use trivial functions like malloc and sprintf. It's written in C++, but with some adaptions, it can be made suitable for C as well. I hope someone can use this.

 

I used op9080's injector's source code for inspiration and I used some functions like findGTASA. Credits to him!

 

If you want to use it in your own project, you have to take into account that some compiler and linker settings are abnormal. These are:

 

  • Compiler: Runtime Library: Multi-threaded Debug (/MTd)
  • Compiler: Create/Use Precompiled Header: Not Using Precompiled Headers
  • Linker: Additional Dependencies: wbemuuid.lib
  • Linker: Entry Point: EntryPoint
  • Linker: Base Address: 0x48320000
  • Linker: Fixed Base Address: Generate a relocation section (/FIXED:NO)

And the download link: http://jesse.thorbit.nl/sainject/sainjector.zip

 

NOTE: You can resume SA's main thread by calling ResumeThread(dwSAThreadID), it's suspended when your main-function gets called.

Link to comment
Share on other sites

I have some more notes;

 

Next to CurWorkingDir's definition is a comment saying that it always has a backslash appended at the end. In fact, I made mistake, it doesn't have a backslash appended

 

The gta_sa.exe process quits if your RealMain function returns.

 

In the first part of the application (the 'loader' part, mostly the code in ExeInject.cpp and the first part of SA Injector.cpp), you can use some CRT-functions, like strcat. Others, like malloc, won't work, because CRT hasn't yet been initialised.

 

Edit: I've still got some new notes:

 

If you want to use some function from a non-standard DLL (like d3dx9.dll, it's not loaded by an application by default, in contrast to for example kernel32.dll or user32.dll. Of course it's loaded by SA, but that's because gta_sa.exe was linked to d3dx9.lib), you have to retrieve the module handle first by using GetModuleHandle, and then you retrieve the function's address by using GetProcAddress. Or, of course, if you're using a DLL that isn't loaded by gta_sa.exe, you have to load it yourself (LoadLibrary). Example:

 

 

// this is the equivalent of a function prototype, but we have to use this method nowtypedef HRESULT (WINAPI *PD3DXCreateTextureFromFileInMemoryEx)(LPDIRECT3DDEVICE9, LPCVOID, UINT, UINT, UINT, UINT, DWORD, D3DFORMAT, D3DPOOL, DWORD, DWORD, D3DCOLOR, D3DXIMAGE_INFO *, PALETTEENTRY *, LPDIRECT3DTEXTURE9 *);void SomeFunc(){ // first, get a handle to some d3dx9.dll, one of these should be loaded, but we don't know which // (depends on the DX version you've got), so we check them all hD3DX9 = GetModuleHandle("d3dx9_24.dll"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("D3DX9_24.DLL"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("d3dx9_25.dll"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("D3DX9_25.DLL"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("d3dx9_26.dll"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("D3DX9_26.DLL"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("d3dx9_27.dll"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("D3DX9_27.DLL"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("d3dx9_28.dll"); if (!hD3DX9)   hD3DX9 = GetModuleHandle("D3DX9_28.DLL"); if (!hD3DX9)   // HELP HELP HELP!   return; pfunc = (PD3DXCreateTextureFromFileInMemoryEx) GetProcAddress(hD3DX9, "D3DXCreateTextureFromFileInMemoryEx"); HRESULT hr = pfunc(argument, argument, .........);}

 

Edited by [email protected]
Link to comment
Share on other sites

Congrats JGunther! smile.gif

 

Couple 'o questions:

 

1) Since it's based on the op9080 hook, does it use a DX SDK? If so which one?

 

2) I'm currently facing a problem trying to reload data because of the way it's injected. Example, I have this in my code:

 

 

void FileStuff(){pFile = fopen("AnimKeys.txt","r");fscanf (pFile, "%s %s", AnimIDA, AnimFileA);fscanf (pFile, "%s %s", AnimIDB, AnimFileB);fscanf (pFile, "%s %s", AnimIDC, AnimFileC);fscanf (pFile, "%s %s", AnimIDD, AnimFileD);fscanf (pFile, "%s %s", AnimIDE, AnimFileE);fscanf (pFile, "%s %s", AnimIDF, AnimFileF);fscanf (pFile, "%s %s", AnimIDG, AnimFileG);fscanf (pFile, "%s %s", AnimIDH, AnimFileH);fscanf (pFile, "%s %s", AnimIDI, AnimFileI);fscanf (pFile, "%s %s", AnimIDJ, AnimFileJ);fscanf (pFile, "%s %s", AnimIDK, AnimFileK);fscanf (pFile, "%s %s", AnimIDL, AnimFileL);fscanf (pFile, "%s %s", AnimIDM, AnimFileM);fscanf (pFile, "%s %s", AnimIDN, AnimFileN);fscanf (pFile, "%s %s", AnimIDO, AnimFileO);fscanf (pFile, "%s %s", AnimIDP, AnimFileP);fclose (pFile);

 

 

Which lets me use a text file to assign animations. The problem: I can't seem to reload anything without restarting the game; I suspect (though I am not nearly talented enough to confirm) that this is all "compiled" (for lack of a better term) at runtime - if I remove my text file, the game won't load at all. Any ideas how I might get around this without having to reload the game everytime?

 

 

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

1) It doesn't use a DX SDK, but you can implement it if you want (I've made a DXHook for it myself, so that does use a DX SDK)

 

2) I don't get your problem exactly. Do you mean it crashes if you call this function for the second time? (The first time you 'load', the second time you 'reload')

Link to comment
Share on other sites

 

2) I don't get your problem exactly. Do you mean it crashes if you call this function for the second time? (The first time you 'load', the second time you 'reload')

Yeah, without getting into real gory details, that function loads my text file at the start and assigns those animations to specific keys. Any attempts to "reload" inside the game causes a crash, which is why I suspect it's somewhat pre-compiled when I start the game from the desktop. The point is to allow users to ALT-TAB, change the text file, ALT-TAB back to the game a press a key to "reload" those animation names.

 

Sorry for derailing your thread; we can pick this up in PM if you like. smile.gif

I'm actually not against democracy though. I'm against things I think are f*cking stupid. I think this is f*cking stupid. - Sweets

Link to comment
Share on other sites

I don't get a crash when I call your function twice (or even more times). I've made the following little debug-like program, can you tell me if it works for you? (Copy it into the SA Injector, but I think you can figure out the exact way yourself wink.gif)

 

 

char AnimIDA[10], AnimIDB[10], AnimIDC[10], AnimIDD[10], AnimIDE[10], AnimIDF[10],AnimIDG[10], AnimIDH[10], AnimIDI[10], AnimIDJ[10], AnimIDK[10], AnimIDL[10],AnimIDM[10], AnimIDN[10], AnimIDO[10], AnimIDP[10];char AnimFileA[10], AnimFileB[10], AnimFileC[10], AnimFileD[10], AnimFileE[10], AnimFileF[10],AnimFileG[10], AnimFileH[10], AnimFileI[10], AnimFileJ[10], AnimFileK[10], AnimFileL[10],AnimFileM[10], AnimFileN[10], AnimFileO[10], AnimFileP[10];void FileStuff(){FILE *pFile = fopen("C:\\AnimKeys.txt","r");if (!pFile) return;Beep(1000,100);fscanf (pFile, "%s %s", AnimIDA, AnimFileA);fscanf (pFile, "%s %s", AnimIDB, AnimFileB);fscanf (pFile, "%s %s", AnimIDC, AnimFileC);fscanf (pFile, "%s %s", AnimIDD, AnimFileD);fscanf (pFile, "%s %s", AnimIDE, AnimFileE);fscanf (pFile, "%s %s", AnimIDF, AnimFileF);fscanf (pFile, "%s %s", AnimIDG, AnimFileG);fscanf (pFile, "%s %s", AnimIDH, AnimFileH);fscanf (pFile, "%s %s", AnimIDI, AnimFileI);fscanf (pFile, "%s %s", AnimIDJ, AnimFileJ);fscanf (pFile, "%s %s", AnimIDK, AnimFileK);fscanf (pFile, "%s %s", AnimIDL, AnimFileL);fscanf (pFile, "%s %s", AnimIDM, AnimFileM);fscanf (pFile, "%s %s", AnimIDN, AnimFileN);fscanf (pFile, "%s %s", AnimIDO, AnimFileO);fscanf (pFile, "%s %s", AnimIDP, AnimFileP);fclose (pFile);}int __stdcall RealMain(){ResumeThread(OpenThread(THREAD_ALL_ACCESS,FALSE,dwSAThreadID));for (;{ Sleep(10); if(GetAsyncKeyState('S')) { 	FileStuff(); 	MessageBox(NULL, AnimIDA, AnimFileA, MB_OK); }}return 0;}

 

 

This works best if you start it and then Alt-Tab the SA window away, so it won't bother you and then press the S key. If it all works, a MessageBox should pop up, telling you the first entry in your file. Then modify the file and press S again. It should then pop up with the modified entries.

 

 

Sorry for derailing your thread; we can pick this up in PM if you like. smile.gif

No problem, there might be other people out there with the same or a similar problem, they might find this discussion useful smile.gif.

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.