Quantcast

Jump to content

» «
Photo

Changing pointer offsets

5 replies to this topic
ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#1

Posted 26 March 2013 - 03:45 AM

Okay so I've got this C++ Console code for Vice City.

I'm trying to make my wanted level be 4 stars when I run this program.

Only problem is, I don't quite understand how to get to the 'Wanted counter' and increment it by 1200 (4 stars) - According to GTAmodding.

I tried manipulating the Gravity address and it worked since there was no offsets I had to go through to get to it.

Please forgive the utter mess you're about to see, I'm a beginner (The Title of this Topic probably doesn't even make sense suicidal.gif ):

CODE
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
DWORD address = 0x94A5F4; //Ped Pointer
BYTE offset1 = 0x345; //Wanted Pointer
BYTE offset2 = 0x0; //Wanted Counter
   BYTE newvalue[] = {1200}; //Four Wanted Stars
   HWND hwnd;
   HANDLE phandle;
   DWORD pid;
   hwnd = FindWindow(NULL, "GTA: Vice City");

   if (hwnd != 0) {
       GetWindowThreadProcessId(hwnd, &pid);
       phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
   }
else
{
       cout << "Could not find the window.";
       cin.get();
       return 0;
   }
   if (phandle != 0)
  {
       address = address + offset1 + offset2; //Thought adding them all up might do the trick but It didn't
       WriteProcessMemory(phandle, (LPVOID)address, (LPVOID) &newvalue, 4, 0);
       cout << "Memory wrote successfully.";
       cin.get();
   }
else
{
       cout << "Couldn't get a handle";
       cin.get();
   }
}


Any help would be greatly appreciated icon14.gif

K^2
  • K^2

    Vidi Vici Veni

  • Moderator
  • Joined: 14 Apr 2004
  • United-States

#2

Posted 26 March 2013 - 04:12 PM Edited by K^2, 26 March 2013 - 04:49 PM.

If I recall correctly, that 0x94A5F4 address isn't where the CPed structure is stored. It holds the pointer to that structure. In other words, that's where you should get the value for your address variable. Something along these lines should work.

CODE
ReadProcessMemory(phandle, (LPVOID)address, (LPVOID) &address, 4, 0);
address = address + offset1 + offset2;
WriteProcessMemory(phandle, (LPVOID)address, (LPVOID) &newvalue, 4, 0);


Basically, just adds one line of code to what you have already. I included the following two lines just for clarity. Try that, and call me in the morning.


Edit: Actually, wanted level is also an offset, you had wrong address values, and all of your BYTE values should be DWORD values. Here is the full working code.

CODE
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
DWORD address = 0x94AD28; //Ped Pointer
DWORD offset1 = 0x5F4; //Wanted Pointer
DWORD offset2 = 0x0; //Wanted Counter
DWORD newvalue[] = {1200}; //Four Wanted Stars
HWND hwnd;
HANDLE phandle;
DWORD pid;
hwnd = FindWindow(NULL, "GTA: Vice City");

if (hwnd != 0)
{
 GetWindowThreadProcessId(hwnd, &pid);
 phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
}
else
{
 cout << "Could not find the window.";
 cin.get();
 return 0;
}
if (phandle != 0)
{
 ReadProcessMemory(phandle, (LPVOID)address, (LPVOID) &address, 4, 0);
 cout << "New Address = " << address << "\n";
 address = address + offset1;
 ReadProcessMemory(phandle, (LPVOID)address, (LPVOID) &address, 4, 0);
 cout << "New Address = " << address << "\n";
 address = address + offset2;
 WriteProcessMemory(phandle, (LPVOID)address, (LPVOID) &newvalue, 4, 0);
 cout << "Memory wrote successfully.";
 cin.get();
}
else
{
 cout << "Couldn't get a handle";
 cin.get();
}
}

ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#3

Posted 26 March 2013 - 05:22 PM

Thanks K^2 , I can't explain how much this helped me out.

I know it's just a simple process for someone with your knowledge but I really needed this clarifying, the tutorials on the internet aren't very good.

Thanks again! icon14.gif cookie.gif cookie.gif cookie.gif

ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#4

Posted 14 June 2013 - 02:51 AM Edited by The_Sorrow, 14 June 2013 - 04:04 AM.

I changed this code to work inside a .asi file:

CODE
#include <windows.h>
#include <iostream>

int main()
{
DWORD address = 0x94AD28; //Ped Pointer
DWORD offset1 = 0x5F4; //Wanted Pointer
DWORD offset2 = 0x0; //Wanted Counter
DWORD newvalue[] = {1200}; //Four Wanted Stars
HWND hwnd;
HANDLE phandle = NULL;
DWORD pid;
hwnd = FindWindow(NULL, L"GTA: Vice City");

if (hwnd != 0)
{
 GetWindowThreadProcessId(hwnd, &pid);
 phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
}
else
{
}
if (phandle != 0)
{
 ReadProcessMemory(phandle, (LPVOID)address, (LPVOID) &address, 4, 0);
 address = address + offset1;
 ReadProcessMemory(phandle, (LPVOID)address, (LPVOID) &address, 4, 0);
 address = address + offset2;
 WriteProcessMemory(phandle, (LPVOID)address, (LPVOID) &newvalue, 4, 0);
}
else
{
}
}


The code compiled so I placed the .asi inside the Vice City folder, with no additional plugins since K^2 said asi's get loaded automatically with Vice City.

I started a new game but nothing happened.
All I've done is remove the console commands, the memory editing code is still there, still the same.

I did try to remove the window check since we know that Vice City will load it anyway but the memory code needs phandle.

EDIT: I also tried:

CODE
#include <windows.h>
#include <iostream>

int main()
{
DWORD address = 0x94AD28; //Ped Pointer
DWORD offset1 = 0x5F4; //Wanted Pointer
DWORD offset2 = 0x0; //Wanted Counter
DWORD newvalue[] = {1200}; //Four Wanted Stars
ReadProcessMemory(GetCurrentProcess(), (LPVOID)address, (LPVOID) &address, 4, 0);
address = address + offset1;
ReadProcessMemory(GetCurrentProcess(), (LPVOID)address, (LPVOID) &address, 4, 0);
address = address + offset2;
WriteProcessMemory(GetCurrentProcess(), (LPVOID)address, (LPVOID) &newvalue, 4, 0);
return 0;
}



Help appreciated, thanks icon14.gif
  • abccba123 likes this

Bad.boy!
  • Bad.boy!

    SA modder

  • Members
  • Joined: 20 Jun 2010

#5

Posted 14 June 2013 - 07:46 AM

An asi file is a renamed dll file. You're code is written like a separate application. You need to create an Dllmain function. This will make sure the dllmain function is execute on load and unload of the library. In the dllmain function you need to hook a game function somewhere, because you want to execute your code when the player is loaded. Then the code is executed automatically when the hooked function is called. Then you don't need to use "ReadProcessMemory" since you're code is executed in the process itself. So you'll have to force a new pointer on a certain memory address and then you can modify it.

Take a look at how Link2012 did this: http://www.gtaforums...howtopic=514465

ChopTheDog.
  • ChopTheDog.

    War. War never changes.

  • Members
  • Joined: 31 May 2010
  • None

#6

Posted 14 June 2013 - 01:48 PM

QUOTE (Bad.boy! @ Friday, Jun 14 2013, 08:46)
An asi file is a renamed dll file. You're code is written like a separate application. You need to create an Dllmain function. This will make sure the dllmain function is execute on load and unload of the library. In the dllmain function you need to hook a game function somewhere, because you want to execute your code when the player is loaded. Then the code is executed automatically when the hooked function is called. Then you don't need to use "ReadProcessMemory" since you're code is executed in the process itself. So you'll have to force a new pointer on a certain memory address and then you can modify it.

Take a look at how Link2012 did this: http://www.gtaforums...howtopic=514465

Duh I totally forgot, thanks bad.boy!
  • abccba123 likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users