Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (85,500 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

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

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption 2

    2. Red Dead Redemption

    3. Rockstar Games

    1. Off-Topic

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

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

    2. Site Suggestions

Sign in to follow this  
Node

C++ .asi help

Recommended Posts

Node
#include <windows.h>#include <detours.h>BOOL WINAPI DLLMain(	_In_  HINSTANCE hinstDLL,	_In_  DWORD nReason,	_In_  LPVOID lpvReserved	){	DWORD PlayerPointer = 0x94AD28;	DWORD WantedLevelPointer = 0x5F4;	DWORD WantedCounter = 0x0;	DWORD WantedLevel = {1200}; // 4 stars	HWND hWnd = FindWindow(NULL,L"GTA: Vice City");	HANDLE phandle = NULL;	DWORD pid;	//-----------------------------------------	//-----------------------------------------	switch (nReason)	{	case DLL_PROCESS_ATTACH:		if (hWnd != 0)		{			GetWindowThreadProcessId(hWnd, &pid);			phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);			if (phandle != 0)			{				ReadProcessMemory(phandle, (LPVOID)PlayerPointer, (LPVOID) &PlayerPointer, 4, 0);				PlayerPointer = PlayerPointer + WantedLevelPointer;				ReadProcessMemory(phandle, (LPVOID)PlayerPointer, (LPVOID) &PlayerPointer, 4, 0);				PlayerPointer = PlayerPointer + WantedCounter;				WriteProcessMemory(phandle, (LPVOID)PlayerPointer, (LPVOID) &WantedLevel, 4, 0);			}		}	case DLL_PROCESS_DETACH:		break;		    case DLL_THREAD_ATTACH:    case DLL_THREAD_DETACH:		break;	}	return TRUE;}

Okay, so this code is meant to be compiled to a .asi file and placed inside my Vice City directory and then it should give the player a wanted level as soon as he has spawned.

 

For some reason though it doesn't work and I can't put my finger on it.

 

I was also told that Vice City doesn't require an ASI loader so I don't have one.

 

Any help is appreciated.

Edited by ChopTheDog.

Share this post


Link to post
Share on other sites
Bad.boy!

I'll quote myself on this one:

It doesn't work because your code is executed when the game starts. You need to hook a (in)game function, so that your code will be executed when the game is loaded. And in your hooked function you should force a pointer on the address you want to modify, instead of using ReadProcessMemory and WriteProcessMemory.

 

I assume that you're trying to learn how to create your own game mods in a real programming language. But it doesn't look like you know the programming language well. You should try to master the language before writing mods in it. Also cleo scripts are a better and easier way to write mods, ASI plugins don't offer much advantages unless you're rewriting bits/parts of the engine.

 

 

Also, it would be better if you posted this in your other topic in III-era coding.

Share this post


Link to post
Share on other sites
K^2

At the time that the ASI file is loaded, which is when DLLMain is called, the player object doesn't exist yet. So you can't alter the wanted level at that time.

Share this post


Link to post
Share on other sites
Node

At the time that the ASI file is loaded, which is when DLLMain is called, the player object doesn't exist yet. So you can't alter the wanted level at that time.

 

I don't know which function I should be looking to hook though (using Microsoft's Detours).

 

Is using ReadProcessMemory and WriteProcessMemory the correct way of editing memory values through a .asi file?

 

I've read/seen loads of different snippets using different code to edit memory in C++.

Edited by ChopTheDog.

Share this post


Link to post
Share on other sites
K^2

I don't know which function I should be looking to hook though (using Microsoft's Detours).

What exactly are you trying to achieve? The easiest thing to hook into with Vice City is message processing, which is why most trainers have shortcut keys. It's easy to intercept key down messages. For pretty much anything else you either need to find a game's own function to hook or hook into the Direct 3D libraries. (E.g. if you want something done per-frame.)

 

 

Is using ReadProcessMemory and WriteProcessMemory the correct way of editing memory values through a .asi file?

Yeah. Your code for actually writing the value to the correct location looks good. You just need to figure out a good way to trigger it. Like I said, getting it to trigger on a key press is very easy. Getting it to trigger on other conditions is trickier.

Share this post


Link to post
Share on other sites
Node

 

I don't know which function I should be looking to hook though (using Microsoft's Detours).

What exactly are you trying to achieve? The easiest thing to hook into with Vice City is message processing, which is why most trainers have shortcut keys. It's easy to intercept key down messages. For pretty much anything else you either need to find a game's own function to hook or hook into the Direct 3D libraries. (E.g. if you want something done per-frame.)

 

Is using ReadProcessMemory and WriteProcessMemory the correct way of editing memory values through a .asi file?

Yeah. Your code for actually writing the value to the correct location looks good. You just need to figure out a good way to trigger it. Like I said, getting it to trigger on a key press is very easy. Getting it to trigger on other conditions is trickier.

 

 

Well, all I want to achieve at this moment is to develop a .asi file and get it to set the wanted level when the game is started.

 

I would think that checking for key presses could cause problems since the user can click the mouse or press the space bar at any time before getting to the Menu and selecting an option?

 

Sorry for these annoying newbie questions I'm still wrapping my head around this, although I do prefer to be thrown into the deep end because I actually learn, but that's just me.

Share this post


Link to post
Share on other sites
Bad.boy!

Yeah. Your code for actually writing the value to the correct location looks good.

It works, but it isn't efficient at all. The code is executed in the same virtual memory, so he won't have to use any api calls to alter memory (as you probably already know).

 

The most reliable way to execute your function on game load is to hook a function which is often used in-game. When the code is called you simply set the wanted level and remove the hook.

Edited by Bad.boy!

Share this post


Link to post
Share on other sites
K^2

Like Bad.boy! said, you need to hook into one of the functions. This is much easier to do if you understand a bit of x86 machine language, but you can find pretty good tutorials for GTA III era.

 

Depending on the order in which these things are called, hooking into CPed::Initialise might work. If you can hook it at the function exit, call your own code, check if the pointer to CPed matches pointer to player, and if so, modify wanted level, it should work flawlessly. Unless, of course, the init code is called before player pointer is set. But I doubt that's the case. I would guess that the game calls constructor, sets player pointer, and then calls the init code, making it the perfect place for the hook.

Share this post


Link to post
Share on other sites
WBaker

This made me wonder... would hooking int 8 (rtc) bog down the game too much?

Share this post


Link to post
Share on other sites
K^2

This made me wonder... would hooking int 8 (rtc) bog down the game too much?

This isn't DOS. Are you going to root the system just so you can hook an interrupt?

Share this post


Link to post
Share on other sites
WBaker

 

This made me wonder... would hooking int 8 (rtc) bog down the game too much?

This isn't DOS. Are you going to root the system just so you can hook an interrupt?

As a matter of fact, the last time I hooked an interrupt it was DOS.

 

Thanks for the answer.

Share this post


Link to post
Share on other sites
Node

Like Bad.boy! said, you need to hook into one of the functions. This is much easier to do if you understand a bit of x86 machine language, but you can find pretty good tutorials for GTA III era.

 

Depending on the order in which these things are called, hooking into CPed::Initialise might work. If you can hook it at the function exit, call your own code, check if the pointer to CPed matches pointer to player, and if so, modify wanted level, it should work flawlessly. Unless, of course, the init code is called before player pointer is set. But I doubt that's the case. I would guess that the game calls constructor, sets player pointer, and then calls the init code, making it the perfect place for the hook.

 

Here's the function I pulled from IDA starting at 0x50D9F0 (This is where CPed::Initialize starts)

 

bUbZ2P8.png

 

So I looked up a basic hooking tutorial and after editing I got this code:

 

#define StartOfCPED 0x50D9F0double (__cdecl* originalFunction) (double);

This should define and point to the original function, right?

 

So in the DLLmain I wrote (using Detours 1.5):

 

BOOL WINAPI DLLMAIN(HANDLE hHandle,DWORD nReason,LPVOID lpReserved ){switch (nReason){case DLL_PROCESS_ATTACH:originalFunction = (double(__cdecl*)(double))DetourFunction((PBYTE)(StartOfCPED), (PBYTE)Hook);break;case DLL_PROCESS_DETACH:break;}return TRUE;}

This calls (I think) my Hook function which is:

double Hook(double a){GetWindowThreadProcessId(hWnd, &pid);phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);ReadProcessMemory(phandle, (LPVOID)PlayerPointer, (LPVOID) &PlayerPointer, 4, 0);PlayerPointer = PlayerPointer + WantedLevelPointer;ReadProcessMemory(phandle, (LPVOID)PlayerPointer, (LPVOID) &PlayerPointer, 4, 0);PlayerPointer = PlayerPointer + WantedCounter;WriteProcessMemory(phandle, (LPVOID)PlayerPointer, (LPVOID) &WantedLevel, 4, 0);return originalFunction (a);}

The game loads without crashing (thankfully) but nothing happens.

 

Just for the record, I'm trying to hook VC and I am not using an ASI Loader.

 

You might look at this and laugh at how noobish it is. :sui:

 

EDIT: Unless, like K^2 stated, CPed::Initialize is called before the Player pointer

is set and my code is still behind it.

 

EDIT 2:

 

I also tried hooking on game load at 0x61A700 but again, I failed, it must be my Detours code or the pointer to the original function causing the problem.

 

qNv5YEK.png

Edited by ChopTheDog.

Share this post


Link to post
Share on other sites
sharpie_eastern

You could do it via SCM. I just tried it

010D: set_player $PLAYER_CHAR wanted_level_to 4

Share this post


Link to post
Share on other sites
Node

 

You could do it via SCM. I just tried it

 

010D: set_player $PLAYER_CHAR wanted_level_to 4

 

I already knew that bro.

 

I've been an SCM scripter for 3 years. :p

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

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