C# Basic Memory Hacking in SAMP

Lelz

Active member
Joined
Jan 5, 2015
Messages
76
Reaction score
1
How does one go about editing a specific SAMP value at a memory address in C#? I found the memory address of the value and I understand that the address will change once the game is restarted etc. What I want to do is write a program to find the memory address of the value I wish to modify, then modify it. From my understanding, you then have to grab the process and then grab the base address of the "samp.dll" module. I have done that, but there seems to be more to it that I'm missing. The difference between the samp.dll base address and the address of the value I wish to modify changes by varying degrees. What am I missing? Do I need to find a pointer to the address? If so, how would I go about that?

So for example, if I wanted to set a player's drunk level to 10000 (the SAMP related value, not directly the effect). I would...

-Get the GTA process
-Get the base address of the samp.dll module

Then...?
 

Kelsi235

Active member
Joined
Jun 2, 2019
Messages
53
Reaction score
4
WriteMemory(samp.dll + offset, byte[] buffer)

I coded something for samp in C# reply if u need help
 

Kelsi235

Active member
Joined
Jun 2, 2019
Messages
53
Reaction score
4
public IntPtr GetModuleAddress(string moduleName)
{
for (int i = 0; i < process.Modules.Count; i++)
if (process.Modules.ModuleName == moduleName)
return process.Modules.BaseAddress;
return IntPtr.Zero;
}
 

Kelsi235

Active member
Joined
Jun 2, 2019
Messages
53
Reaction score
4
public byte[] ReadMemory(IntPtr memoryAddress, uint bytesToRead)
{
byte[] buffer = new byte[bytesToRead];
ProccessManagerApi.ReadProcessMemory(handle, memoryAddress, buffer, bytesToRead, out IntPtr pBytesRead);
return buffer;
}


public void WriteMemory(IntPtr memoryAddress, byte[] buffer)
{
ProccessManagerApi.WriteProcessMemory(handle, memoryAddress, buffer, (uint)buffer.Length, out IntPtr pBytesWritten);
}

this is all you need
 

Lelz

Active member
Joined
Jan 5, 2015
Messages
76
Reaction score
1
Yeah but the offset from the samp.dll to the memory address seems to change? Is there something I'm missing?
 

Lelz

Active member
Joined
Jan 5, 2015
Messages
76
Reaction score
1
WriteMemory(samp.dll + offset, byte[] buffer)

So samp.dll in this case would be the base address of the module? And the offset should be a static value correct?

If so, that's not what I'm seeing. Here's the results I'm getting:

Game launch #1:
samp.dll base address: 64159744 (0x‭03D30000)‬
drunk value address: 63737417 (0x0‭3CC8E49‬)
difference (offset): 422327 (0x000‭671B7‬)


Game launch #2:
samp.dll base address: 62324736 (0x0‭3B70000‬)
drunk value address: ‭69176897‬ (0x041F8E41)
difference (offset): ‭6852161‬ (0x00‭688E41‬)

(found the drunk value addresses via cheat engine)
 

Parazitas

God
Joined
Jan 2, 2017
Messages
3,104
Solutions
5
Reaction score
882
Location
Lithuania
So samp.dll in this case would be the base address of the module? And the offset should be a static value correct?

If so, that's not what I'm seeing. Here's the results I'm getting:

Game launch #1:
samp.dll base address: 64159744 (0x‭03D30000)‬
drunk value address: 63737417 (0x0‭3CC8E49‬)
difference (offset): 422327 (0x000‭671B7‬)


Game launch #2:
samp.dll base address: 62324736 (0x0‭3B70000‬)
drunk value address: ‭69176897‬ (0x041F8E41)
difference (offset): ‭6852161‬ (0x00‭688E41‬)

(found the drunk value addresses via cheat engine)
You sure you get static pointer?
Post here full pointer with offsets
I check it later
 

Lelz

Active member
Joined
Jan 5, 2015
Messages
76
Reaction score
1
You sure you get static pointer?
Post here full pointer with offsets
I check it later

Static pointer for what? The samp.dll base address or the drunk level address?
 

Lelz

Active member
Joined
Jan 5, 2015
Messages
76
Reaction score
1
C#:
IntPtr dllBase;

Process process = Process.GetProcessesByName("gta_sa").ToList().FirstOrDefault();
if(process != null)
{
    mreader.ReadProcess = process;
    mreader.OpenProcess();

    dllBase = process.Modules[56].BaseAddress;
 

Lelz

Active member
Joined
Jan 5, 2015
Messages
76
Reaction score
1
Is there really no one on this forum that knows how to create a program in C# that grabs a specific samp value's memory address?
 

ShihabSoft

New member
Joined
Aug 27, 2018
Messages
4
Reaction score
1
Is there really no one on this forum that knows how to create a program in C# that grabs a specific samp value's memory address?

Use cheat engine to find the pointers which points towards the memory addresses, which inturn points towards the value you're looking for. For values like drunk level, we usually set it by getting the GTA base module address + the static memory address for drunk level which can be searched in google.

It's what we call ASLR, Address Space Layout Randomization, so the memory address change whenever you restart the program or restart your computer. So that's why we gotta grab the GTA SA's base address in the memory first then add the offset of the memory address you wanna change.
 
Joined
Feb 18, 2005
Messages
2,963
Reaction score
267
we gotta grab the GTA SA's base address in the memory

Maybe you mean samp module base address, since the GTA SA base address would always be 0x400000, the default for x86 procs.

And the offset should be a static value correct?

Game launch #1:
samp.dll base address: 64159744 (0x‭03D30000)‬
drunk value address: 63737417 (0x0‭3CC8E49‬)
difference (offset): 422327 (0x000‭671B7‬)


Game launch #2:
samp.dll base address: 62324736 (0x0‭3B70000‬)
drunk value address: ‭69176897‬ (0x041F8E41)
difference (offset): ‭6852161‬ (0x00‭688E41‬)

(found the drunk value addresses via cheat engine)

Then it's not a static offset relative to samp module, use CE to generate a pointer map for the address, and filter out bad results.
 
Top