Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Looking for byte [] in process memory

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Hissatsu
How do I cheat?
Reputation: 0

Joined: 11 May 2012
Posts: 2

PostPosted: Fri May 11, 2012 4:45 pm    Post subject: Looking for byte [] in process memory Reply with quote

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
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25833
Location: The netherlands

PostPosted: Fri May 11, 2012 5:20 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri May 11, 2012 7:14 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25833
Location: The netherlands

PostPosted: Fri May 11, 2012 7:25 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Hissatsu
How do I cheat?
Reputation: 0

Joined: 11 May 2012
Posts: 2

PostPosted: Sat May 12, 2012 10:50 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites