| View previous topic :: View next topic |
| Author |
Message |
Hissatsu How do I cheat?
Reputation: 0
Joined: 11 May 2012 Posts: 2
|
Posted: Fri May 11, 2012 4:45 pm Post subject: Looking for byte [] in process memory |
|
|
Greetings!
I need to make a program that enhances game abilities, adding new hotkeys and automating certain actions, etc. For that, i need to read from and write to program memory (like, user preses a hotkey and i write some value that stores the slider position that was previoulsly only controllable by mouse).
I'm programming in .Net C#.
I have studied the game memory with Cheat Engine and found out that values i need are stored as plain floats, but their position changes each time program is ran.
I have learnt how to read and write memory with kernel32.dll's readprocessmemory and writeprocessmemory. However, i have encountered a problem.
What my program basically does is it runs the game process, and then repeatedly scans its memory for a key sequence of bytes. This sequence is read from a file on disk, so i always know what to look for. When user presses "new game" for the first time, this sequence is read. Thats when my program whould detect this sequence in the game memory and find all the offsets for the values i need to be able to change when user presses custom hotkeys.
Now, problem is, this only works correctly 90% of a time. 10% of a time, my program will get locked out of the game's memory. ReadProcessMemory will read zero bytes EXACTLY for the location where the target byte sequence is stored (i checked that with Cheat Engine). This sometimes clears on its own after a while (like, after some minutes, my program can finally read that part of game memory) but sometimes it doesnt.
Cheat Engine never has problems with reading the game memory. I can always open memory and find the sequence of bytes i need there.
I tried downloading sources but i dont seem to find the Delphi Project file to open - there are only project files for the tutorial and speedhack, and no project files for the CE itself.
If someone who knows how CE works could tell me how does CE open the program memory and how does it scan it, i'd be very grateful! Or maybe you have any insight why is my program getting blocked out from the game's memory, while cheat engine isnt?
Thanks in advance!
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25833 Location: The netherlands
|
Posted: Fri May 11, 2012 5:20 pm Post subject: |
|
|
Perhaps the block you are reading is too big. If it's too big readprocessmemory will fail (The actualread parameter is unreliable)
Try smaller chunks
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri May 11, 2012 7:14 pm Post subject: |
|
|
| Dark Byte wrote: | Perhaps the block you are reading is too big. If it's too big readprocessmemory will fail (The actualread parameter is unreliable)
Try smaller chunks |
Along with this, check the return from ReadProcessMemory. If it fails, call GetLastError to see if it failed due to the block size. If it is, you can use the ActualRead param as a start to know how much wasn't read based on the original size you tried to get.
_________________
- Retired. |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25833 Location: The netherlands
|
Posted: Fri May 11, 2012 7:25 pm Post subject: |
|
|
Weird thing about the actualread parameter is that it sometimes stays 0 even if the start address is readable (I noticed that with CE's stacksave feature in win7)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Hissatsu How do I cheat?
Reputation: 0
Joined: 11 May 2012 Posts: 2
|
Posted: Sat May 12, 2012 10:50 am Post subject: |
|
|
| Actual problem seemed to be that i didnt check if the memory was readable or not. Using VirtualQueryEx helped - now first i map the program's memory, then read only mapped regions. Thanks!
|
|
| Back to top |
|
 |
|