|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
KryziK Expert Cheater Reputation: 3
Joined: 16 Aug 2009 Posts: 199
|
Posted: Thu Sep 01, 2011 1:46 pm Post subject: |
|
|
iMockBa wrote: | Hi.. i want ask how can i read memory by using this script .
i tryed it for writing values & its work perfectly ...but as new on c# i cant find out how to tranceform that script for reading memory .
and other litl question .. in section
int iValue_To_Write = (1000); //Value that we want to write (Step2 requires that you change the value to 1000)
walue to write is inside of script ....& i would like to make that posible to write that value by user inside of TextBox ..... so how can i tranceform String on Int ? if change the cod on
int iValue_To_Write = (TextBox.Text);
i m getting error .
Previously Thanks for any help. |
I have included code to read from memory in that snippet.
You would use it by doing:
Code: | int bytesRead; //This will hold the number of bytes that were successfully read
byte[] ThisIs4Bytes = Read(address, 4, out int bytesRead); //Reads 4 bytes to a byte array
int ReadValue = Bitconverter.ToInt32(ThisIs4Bytes); //Converts the byte array to a single integer
|
You can look here for different types to convert to, such as float, double, etc.
and for the textbox:
Code: | int iValue_To_Write = Int32.Parse(TextBox.Text); // Or Int32.TryParse(...)
|
However, you may want to take a look at my C# Memory Library which contains newer code and functions, making it easier to use. I'm still in the process of updating it as stated on the page, even though it has almost been a year!
|
|
Back to top |
|
|
iMockBa How do I cheat? Reputation: 0
Joined: 01 Sep 2011 Posts: 3
|
Posted: Thu Sep 01, 2011 3:23 pm Post subject: |
|
|
Thanks ...string converting example helped .
But im still trying to understend how work ReadProcessMemory. i m using your code & trying ...but unfortunately. ( Im realy new on C#)
the code i have now is : Code: | {
Process[] aProcesses = Process.GetProcessesByName("Requiem");
if (aProcesses.Length != 0)
LogBox.Text = LogBox.Text + ((" Process " + "Requiem" + " found "));
else
LogBox.Text = LogBox.Text + ((" Process " + "Requiem" + " not found "));
oMemory.ReadProcess = aProcesses[0];
oMemory.Open(); //Open Process
int Current_HP = Addr.ToDec("00a42358 "); //The static address of the pointer
int[] Current_HP_Offsets = { 0x3dc, 0xa4}; //Offsets from bottom to top
uint iValue_To_Read= oMemory.Read((0x00a42358 + 0x3dc) + 0xa4);
byte[] bValue_To_Read = BitConverter.GetBytes(iValue_To_Read); //
LogBox.Text = LogBox.Text + bValue_To_Read;
oMemory.CloseHandle(); //Close Memory Handle
} |
could you please help me to find out where im wrong ?
Previously thanks.
|
|
Back to top |
|
|
KryziK Expert Cheater Reputation: 3
Joined: 16 Aug 2009 Posts: 199
|
Posted: Thu Sep 01, 2011 3:35 pm Post subject: |
|
|
iMockBa wrote: | Thanks ...string converting example helped .
But im still trying to understend how work ReadProcessMemory. i m using your code & trying ...but unfortunately. ( Im realy new on C#)
the code i have now is : Code: | {
Process[] aProcesses = Process.GetProcessesByName("Requiem");
if (aProcesses.Length != 0)
LogBox.Text = LogBox.Text + ((" Process " + "Requiem" + " found "));
else
LogBox.Text = LogBox.Text + ((" Process " + "Requiem" + " not found "));
oMemory.ReadProcess = aProcesses[0];
oMemory.Open(); //Open Process
int Current_HP = Addr.ToDec("00a42358"); //The static address of the pointer
int[] Current_HP_Offsets = { 0x3dc, 0xa4}; //Offsets from bottom to top
uint iValue_To_Read= oMemory.Read((0x00a42358 + 0x3dc) + 0xa4);
byte[] bValue_To_Read = BitConverter.GetBytes(iValue_To_Read); //
LogBox.Text = LogBox.Text + bValue_To_Read;
oMemory.CloseHandle(); //Close Memory Handle
} |
could you please help me to find out where im wrong ?
Previously thanks. |
It looks like you're trying to read from a pointer.
You should instead use
Code: | {
Process[] aProcesses = Process.GetProcessesByName("Requiem");
if (aProcesses.Length != 0)
LogBox.Text = LogBox.Text + ((" Process " + "Requiem" + " found "));
else
LogBox.Text = LogBox.Text + ((" Process " + "Requiem" + " not found "));
oMemory.ReadProcess = aProcesses[0];
oMemory.Open(); //Open Process
int Current_HP = Addr.ToDec("00a42358"); //The static address of the pointer
int[] Current_HP_Offsets = { 0x3dc, 0xa4}; //Offsets from bottom to top
byte[] bValue_To_Read= oMemory.PointerRead(Current_HP, 4, Current_HP_Offsets); //Read 4 bytes from Current_HP with the offsets above
int iValue_To_Read = BitConverter.ToInt32(bValue_To_Read); // Convert byte[] to int
LogBox.Text = LogBox.Text + iValue_To_Read; //Add the text to the log box
oMemory.CloseHandle(); //Close Memory Handle
} |
Unfortunately it's been so long since I've used this code that I'm not quite sure if I'm forgetting something or not. Hopefully that works. Remember: When reading you store as byte[], and then you have to convert it to what you want using such things as BitConverter.ToInt32(byte[] array), BitConverter.ToDouble(byte[] array), etc.
|
|
Back to top |
|
|
iMockBa How do I cheat? Reputation: 0
Joined: 01 Sep 2011 Posts: 3
|
Posted: Sun Sep 04, 2011 6:11 am Post subject: |
|
|
Looks like there s some error inside of class Memory.
im trying to read HP value wich have (1 static adress + Offset1)+Offset2
& always readed value is 0.
But whene i try to read somethink simple wich have only 1 offset im getting exact value .
|
|
Back to top |
|
|
z03dsk8 How do I cheat? Reputation: 0
Joined: 22 Jan 2010 Posts: 1 Location: Indonesia
|
Posted: Thu Sep 08, 2011 7:24 pm Post subject: |
|
|
iMockBa wrote: | Looks like there s some error inside of class Memory.
im trying to read HP value wich have (1 static adress + Offset1)+Offset2
& always readed value is 0.
But whene i try to read somethink simple wich have only 1 offset im getting exact value . |
try this
Code: |
Process[] anProcess = Process.GetProcessesByName("name ur process");
if (anProcess.Length != 0)
{
Process anProcesses = anProcess[0];
IntPtr readHandle = MemoryAPI.OpenProcess(0x10, 0, (uint)anProcesses.Id);
IntPtr Base = anProcess[0].MainModule.BaseAddress;
oMemory.ReadProcess = anProcess[0];
oMemory.Open();
byte[] buffer = new byte[16];
IntPtr ByteRead;
uint Offset_1 = 0x2E6224;
uint Offset_Nick = (uint)Base + Offset_1;
uint size_nick = 24;
uint size = 4;
MemoryAPI.ReadProcessMemory(readHandle, (IntPtr)Offset_Nick, buffer, size_nick, out ByteRead);
uint baseContent_1 = BitConverter.ToUInt32(buffer, 0);
uint baseAddress_1 = baseContent_1 += 0x1E0; //0x1E0 Offset 1
MemoryAPI.ReadProcessMemory(readHandle, (IntPtr)baseAddress_1, buffer, size_nick, out ByteRead);
uint baseContent_2 = BitConverter.ToUInt32(buffer, 0);
uint baseAddress_2 = baseContent_2 += 0x61C; //0x61C Offset 2
MemoryAPI.ReadProcessMemory(readHandle, (IntPtr)baseAddress_2, buffer, size_nick, out ByteRead);
string charName = Encoding.UTF8.GetString(buffer);//Final
lNick.Text = charName;
oMemory.CloseHandle();
}
|
|
|
Back to top |
|
|
Ryuuzaki_L How do I cheat? Reputation: 0
Joined: 25 Oct 2012 Posts: 3
|
Posted: Fri Oct 26, 2012 3:41 pm Post subject: |
|
|
Hello,
Thank you for the awesome tutorial. It has helped me make a trainer for FTL. However, I have one question.
I got this to work with Scrap and Fuel as they had static addresses. However, when I found the static pointer for fuel it is something like:
"FTLGame.exe"+002E79B8 with offsets of 138, 8c, 0, 1d4
Now I was wondering, what do I do with the "FTLGame.exe" part to make it work with the code?
|
|
Back to top |
|
|
KryziK Expert Cheater Reputation: 3
Joined: 16 Aug 2009 Posts: 199
|
Posted: Fri Oct 26, 2012 4:22 pm Post subject: |
|
|
Ryuuzaki_L wrote: | Hello,
Thank you for the awesome tutorial. It has helped me make a trainer for FTL. However, I have one question.
I got this to work with Scrap and Fuel as they had static addresses. However, when I found the static pointer for fuel it is something like:
"FTLGame.exe"+002E79B8 with offsets of 138, 8c, 0, 1d4
Now I was wondering, what do I do with the "FTLGame.exe" part to make it work with the code? |
Assuming you have a Process object open to FTLGame.exe, you would just do Process.MainModule.BaseAddress.ToInt32() to calculate the equivalent address of "FTLGame.exe".
|
|
Back to top |
|
|
Ryuuzaki_L How do I cheat? Reputation: 0
Joined: 25 Oct 2012 Posts: 3
|
Posted: Fri Oct 26, 2012 4:36 pm Post subject: |
|
|
KryziK wrote: | Ryuuzaki_L wrote: | Hello,
Thank you for the awesome tutorial. It has helped me make a trainer for FTL. However, I have one question.
I got this to work with Scrap and Fuel as they had static addresses. However, when I found the static pointer for fuel it is something like:
"FTLGame.exe"+002E79B8 with offsets of 138, 8c, 0, 1d4
Now I was wondering, what do I do with the "FTLGame.exe" part to make it work with the code? |
Assuming you have a Process object open to FTLGame.exe, you would just do Process.MainModule.BaseAddress.ToInt32() to calculate the equivalent address of "FTLGame.exe". |
Thank you, I was reading something about that.
I have Code: |
myProcess = Process.GetProcessesByName("FTLGame");
if (myProcess.Length != 0)
{
isGameAvailable = true;
label1.Text = "Status: Found FTL";
hProcModuleBA = myProcess[0].MainModule.BaseAddress;
}
|
hProcModuleBA is an IntPtr of course, and it holds the value of 4194304 in debugging.
Bear in mind with me, I am fairly new to all this myself so forgive my stupid questions. What would I do from here?
I have a base address of 4194304 and the + 002E79B8.
Also, I noticed I have an 8c in the offsets, what would I do with that?
Thank you for taking the time to help me out. I greatly appreciate it. I am learning a great deal. It's nice to see actual use for the programs I write =)
edit: Forgot to mention I was probably using a different memory API. I'll try re-writing with yours real quick. xD.
Although, if you could still answer my questions that would be awesome =).Always looking to learn more.
|
|
Back to top |
|
|
hitmetwice Advanced Cheater Reputation: 0
Joined: 20 Nov 2012 Posts: 63
|
Posted: Sat Mar 23, 2013 7:57 pm Post subject: |
|
|
@Kryzik I'm working with your code for a day now and although I just started with C# 3 days ago, it's helping me a lot . I mean, I have no idea how efficient, elegant or portable your code is, but I love working with it.
I upgraded it a little. Sothat I can use your code like that:
Code: |
if (CanOpenProcessMemory(string processName))
{
MemoryWrite(int address, new int[] { offsets }, int value);
MemoryWrite(int address, new int[] { offsets }, int value);
...
...
CloseProcessMemory();
}
|
I was easily able to do that because you commented your example so well. Google helped me to get familiar with the C# syntax.
The problem is, that I'm not able to do the same thing with memory read. This is because I dont understand how it works. How can I make my program automatically calculate the legth of the bytes etc?
Also I would really love to skype with someone who knows something about that.
Should I post my code here?
Last edited by hitmetwice on Sun Mar 24, 2013 5:13 am; edited 1 time in total |
|
Back to top |
|
|
KryziK Expert Cheater Reputation: 3
Joined: 16 Aug 2009 Posts: 199
|
Posted: Sat Mar 23, 2013 10:17 pm Post subject: |
|
|
Please post your code so we can see what you are asking. What do you mean read doesn't work?
|
|
Back to top |
|
|
hitmetwice Advanced Cheater Reputation: 0
Joined: 20 Nov 2012 Posts: 63
|
Posted: Sun Mar 24, 2013 5:33 am Post subject: |
|
|
My problem is, that I'm not able to set up a simple read function.
Here is my code
Code: |
private void hButton_Click_1(object sender, EventArgs e)
{
if (CanOpenProcessMemory("Tutorial-i386"))
{
MemoryWrite(00690320, new int[] { 0x464 }, 1000);
MemoryWrite(02B5821C, new int[] { 0xC4, 6F }, 1234);
//I want to read addresses with a function like that:
//MessageBox.Show(ToString(MemoryRead(00690320, new int[] { 0x464 })));
//
CloseProcessMemory();
}
else
{
MessageBox.Show("Unable to open the process memory of 'Tutorial-i386'!");
}
}
#region Open/Close Memory
public bool CanOpenProcessMemory(string processName)
{
Process[] aProcesses = Process.GetProcessesByName(processName);
if (aProcesses.Length != 0)
{
oMemory.ReadProcess = aProcesses[0];
oMemory.Open();
return true;
}
else
{
return false;
}
}
public void CloseProcessMemory()
{
oMemory.CloseHandle();
}
#endregion
#region MemoryWrite
public void MemoryWrite(int address, int[] offsets, int value)
{
int converted_address = Addr.ToDec(address.ToString());
int bytesWritten;
byte[] converted_value = BitConverter.GetBytes(value);
string sWritten_Address = oMemory.PointerWrite((IntPtr)converted_address, converted_value, offsets, out bytesWritten);
if (bytesWritten == converted_value.Length)
MessageBox.Show("Wrote " + value.ToString() + " to " + sWritten_Address + "!");
else
MessageBox.Show("There was an error writing " + value.ToString() + " to " + sWritten_Address + ".");
}
#endregion
|
This is all I can offer for the MemoryRead function:
Code: |
#region MemoryRead
public void MemoryRead(int address, int[] offsets)
{
//I need something that calculates the length of the bytes for me automatically
//and I guess I have to convert the address or something?
PointerRead(address, ????, offsets, out int bytesRead);
return bytesRead
}
#endregion
|
It is of course not working, but I hope it will make it easier to understand my problem.
I'm also wondering if it is neccessary to add a parameter "type" to the functions. Like float, double, 4bytes, Text?
|
|
Back to top |
|
|
KryziK Expert Cheater Reputation: 3
Joined: 16 Aug 2009 Posts: 199
|
Posted: Sun Mar 24, 2013 12:21 pm Post subject: |
|
|
I provide the code to read from memory in the first post. Check the parameters and what it returns. You might have to cast the return value to something you want (like an integer).
Edit: Also, feel free to check out another bit of code that I wrote:
http://forum.cheatengine.org/viewtopic.php?p=5447297#5447297
The code there is much better than this code, even if it does contain a few errors. You might find it a lot more useful!
|
|
Back to top |
|
|
hitmetwice Advanced Cheater Reputation: 0
Joined: 20 Nov 2012 Posts: 63
|
Posted: Sun Mar 24, 2013 4:17 pm Post subject: |
|
|
you are sooo awesome! Thank you so much
|
|
Back to top |
|
|
jackdaniels42 Cheater Reputation: 0
Joined: 15 Jan 2013 Posts: 26
|
Posted: Mon May 27, 2013 11:21 pm Post subject: hi |
|
|
hi,can you tell me how can i find the weapondamage in the game ??
|
|
Back to top |
|
|
Splamy How do I cheat? Reputation: 0
Joined: 30 Jul 2013 Posts: 1
|
Posted: Tue Jul 30, 2013 5:26 am Post subject: |
|
|
I know this Topic is pretty old, but I've seen a mistake an I'd like to correct it:
in the public static string Make(byte[] buffer) function you have to change the
if (Convert.ToInt16(buffer[i]) < 10)
to
if (Convert.ToInt16(buffer[i]) <= 0xF)
because in hex for example the number 15(0xF) is only 1 digit long
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|