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 


Arrays and allocations

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Seneekikaant
Advanced Cheater
Reputation: 0

Joined: 04 May 2016
Posts: 52

PostPosted: Thu Nov 10, 2016 2:32 am    Post subject: Arrays and allocations Reply with quote

I did a search on google and had a quick browse and didn't find an answer to what I'm wondering, so please forgive me if this has been covered.

What I would like to to is an injection copy with some allocated memory to get the base address of an item in game, however this particular game doesn't have every item put nicely in one base address where I can just change the offset to get to each item. It seems to just put each item in its own random address and I haven't been able to find a pattern with that either, but I did find a particular offset value that only items share as a way to filter out undesired addresses.

So when I try an injection copy using the usual methods, I only get one address (expected behaviour) but I noticed when I look at what addresses are accessed by the code, each time I trigger the event, the code gets run 8 times (I only have 8 items currently) and that gave me a great idea to switch over to Lua and have each address put into an array and then use a for loop to put each address into its own allocated place in memory so these addresses can be found (this is a very touchy game, it crashes if you modify the wrong value, or even put a value that's too high).

I'm just wondering if that's even possible, and if so, how do I implement something like that into CE? Would it be best to make the script entirely out of Lua or switch between ASM and Lua?

_________________
Insanity Prawn Boy wrote:

Hitler loves cat bottoms!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4300

PostPosted: Thu Nov 10, 2016 8:33 am    Post subject: Reply with quote

Did you check for a sequence of pointers to your items? I'm willing to bet the array you're trying to make is already stored in the game somewhere.

Seneekikaant wrote:
I only get one address (expected behaviour) but I noticed when I look at what addresses are accessed by the code, each time I trigger the event, the code gets run 8 times (I only have 8 items currently)...

You only get one address from what? Does that instruction access multiple addresses or the same address for each of those 8 times it's executed?

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Cake-san
Grandmaster Cheater
Reputation: 8

Joined: 18 Dec 2014
Posts: 541
Location: Semenanjung

PostPosted: Thu Nov 10, 2016 8:57 am    Post subject: Reply with quote

you can also make some loops out of asm Rolling Eyes
_________________
...
Back to top
View user's profile Send private message
Seneekikaant
Advanced Cheater
Reputation: 0

Joined: 04 May 2016
Posts: 52

PostPosted: Fri Nov 11, 2016 9:47 am    Post subject: Reply with quote

ParkourPenguin wrote:
Did you check for a sequence of pointers to your items? I'm willing to bet the array you're trying to make is already stored in the game somewhere.

Seneekikaant wrote:
I only get one address (expected behaviour) but I noticed when I look at what addresses are accessed by the code, each time I trigger the event, the code gets run 8 times (I only have 8 items currently)...

You only get one address from what? Does that instruction access multiple addresses or the same address for each of those 8 times it's executed?


The one address is the allocated memory I'm storing the address to, it gets executed one time per item and always ends up being the last address that's accessed each time the menu is opened. (I put the debugger on my code, mov [cutomPtr],ecx )


Where would I begin checking for a sequence of pointers? Every time I load the game, as expected, the addresses are different, but there is no real pattern to the difference bettwen each item, like sometimes the difference between the first and second item will be +B437 and then next time it's +2368 and sometimes even -2587, which leads me to believe they're loaded individually with no relation to each other at all. The code that accesses them is always using the same offset, where most games I usually find the offset changes but the base address is always the same, which is why I thought an array might be the way to go, but if it's already there somewhere like you say, that would be a much easier route to go down.


Cake-san wrote:
you can also make some loops out of asm Rolling Eyes


oh really? I wasn't aware of that. Like, I figured there had to be a way somehow. I'll go look that one up, this could be interesting. Thanks for the tip

_________________
Insanity Prawn Boy wrote:

Hitler loves cat bottoms!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4300

PostPosted: Fri Nov 11, 2016 11:02 am    Post subject: Reply with quote

I believe I understand what you meant now. That instruction accesses the addresses of all your items, but with your current code, it's copying all of them into the same address. This leaves the last item accessed the only usable address.

I wrote some code for a similar problem in another topic here. The Lua code may not apply to whatever you want to do and you may need to change some of the registers in the AA script, but the AA script isn't a bad reference to see how to add values to a buffer. Note that if items can be removed from your inventory, you'll need to remove them from the buffer as well.


There is a difference between a pointer to an item and the item itself. I'm not surprised the items are loaded at different spots in memory, since that's certainly not uncommon. What I'm referring to is a sequence of pointers, or addresses whose values are other addresses, to the items. If you haven't worked with pointers before, complete the CE tutorial: it contains useful information I'm sure you'll find helpful now and in future endeavors.

Find the probable base addresses of the item structures (probably ecx based on your code). Search for those addresses using a grouped value scan. The values should be 4-byte and out of order. If you find something, great- it's probably used by the game to manage your items. If not... well, there's probably something somewhere, but finding it like that isn't a very good option.

Personally, it would be easier and faster to look at how the game is deriving a reference to the items (i.e. backtracing), but that requires knowledge of assembly. The code immediately leading up to the instruction which accesses the items might contain useful information. If you're at a complete loss, post a screenshot of that so others can analyze it and you might get lucky.


Depending on what you intend to do with the items, the pointer scanner is also an option.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Seneekikaant
Advanced Cheater
Reputation: 0

Joined: 04 May 2016
Posts: 52

PostPosted: Sat Nov 12, 2016 12:05 pm    Post subject: Reply with quote

Yeah, that's what I was getting at. Each item has its own structure by the looks, because normally you'll see something like mov eax,[eax+ecx*4] and ecx will determine the offset, however in this case it's always mov eax,[ecx+30] with no definite gap between base addresses. I even went as far as getting pointers for each one (just scanning the base address and saving the green addresses worked as they're only 1 level deep) and there's no pattern that I can find to determine between them to try figuring out where to go from there.

I did manage to get a loop going, but ecx stayed the same value throughout the entire loop, so I obviously messed that up somewhere, but backtracing back as far as I could (I went all the way back to where the register first gets assigned the right address, and then back to where the instruction that sets that gets the info from etc 3 levels deep) and still no luck, but that's what made me think a for loop in Lua might help, with some way of putting the base addresses in an array and then somehow accessing it as one base address and each position in the array being accessed as an offset.

The main thing I'd like to do with the items is (because they seem to have their own place in the inventory, if you remove an item and then add it back, it goes to the same place, if you remove the item before it, everything moves back one place) just have them mapped out so you can add them at will. But the more I think about it, the more I think it would be easier for me to continue through the game, get at least one of each item, save each pointer for each new item and once I have a full inventory I may be able to find a pattern. I only have 8 items so far with room for about 32 so maybe I'll put this project on hold for a while until I can get more solid info.

Thanks for your help and your link definitely helped a bit, learning new ways to do things is always a benefit.

_________________
Insanity Prawn Boy wrote:

Hitler loves cat bottoms!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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