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 


aob string in lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Tutorials -> LUA Tutorials
View previous topic :: View next topic  
Author Message
thenewcomer
Newbie cheater
Reputation: 0

Joined: 09 Mar 2013
Posts: 22
Location: Behind you

PostPosted: Sat Sep 27, 2014 2:21 pm    Post subject: aob string in lua Reply with quote

Hey guys, i've been starting to mess around with lua recently and couldn't figure this out, and thought perhaps you guys could help.

what i'm trying to do is take an AOBScan, and return the bytes (not the address) as a string so i can count how many bytes it is. this is part of a larger project so i have to keep the AOBScan in there Razz
so far this is what i have

function countBytes(search)
aob = AOBScan(search)
if(aob ~= nil) then
a = (aob) --set a to the aob
b = (string.len(a)-2) --set to offset
s = (DEC_HEX(b)/3) --go by bytes count
print (s) --output number of bytes
end
object_destroy(aob);
aob=nil
end

but this returns the address, and the string.len gives the error that its userData rather than a string. ive tried using readBytes(aob) but then it returns nil. any ideas?

_________________
-TNC
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 54

Joined: 01 Oct 2008
Posts: 941

PostPosted: Sat Sep 27, 2014 3:22 pm    Post subject: Reply with quote

If AOBScan failed, it return nil, otherwise it return a Stringlist object, which is of lua type userdata. By userdata, it normally cannot be manipulated by lua intrinsic function or statement, but by its own api. That's the 'userdata not string' error I guess.
[You can check Stringlists api from main.lua (a big comment as a document, you insert your own lua code so that they load wen ce start) at your ce install location.]

The Stringlist returned by AOBScan is a collection of strings which is the hexidecimal string representation of result address. For example, memory address 1000(dec) = 0x3e8 (hex) is a string '3e8' in the Stringlist.

Stringlist is subclass of Strings (also ce userdata).
To get how many string in the stringlists, aob.getCount()
To get the ith string, aob[i-1] or aob.getStrings(i-1)
Note aob is not table/array in itself, but aob.String is. but its index is base-0, lua use base-1, a base-0 array cannot get its lua array length by #array correctly, ie. #aob return error, #ab.String will return 0 (not as expected).

Most ce api, eg readBytes, accept the address parameter as string form or number form. So you can convert the string to a number and add a offset then use this resulted number of type 'number' as address parameter, eg offsetAddr = aob[0] + 123 ; readBytes(offsetAddr,100)

The address result is in string form to best interacte with the powerful autoAssemble function.

btw, Your readBytes need a second parameter of how many bytes to read
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

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

PostPosted: Sat Sep 27, 2014 3:32 pm    Post subject: Reply with quote

Try to specify exactly what you wish to do before doing it

AOBScan is not going to help you with counting the number of bytes in an AOB string as it only returns addresses. And address sizes go from the address they are in to 0xffffffffffffffff
and counting the size of an address returned by the aobscan stringlist is always at least 8

You probably want to count the number of bytes in the search string provided.
I recommend manually chopping up the string into pieces and parse that yourself
keep in mind that aobscan strings can be formatted as:
"10 11 12 ? 14 15"
"10 11 12 ?? 14 15"
"101123??1415"
"10 11 12 z 14 15"
"101112zz1415"

_________________
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
thenewcomer
Newbie cheater
Reputation: 0

Joined: 09 Mar 2013
Posts: 22
Location: Behind you

PostPosted: Sat Sep 27, 2014 5:12 pm    Post subject: Reply with quote

what i ended up doing was this
Code:

function countBytes(search, change)
   aob = AOBScan(search)
   if(aob ~= nil) then
      a = (search)                 --set a to the aob
      b = (string.len(a))         --get the length in decimal
      c = ((b-2)/3)                 --set to offset and count by bytes rather than characters
      s = DEC_HEX(c)            --convert to hex
      print (s)                        --output number as hex
   end
   object_destroy(aob);
   aob=nil
end

i realized i didnt need to use (aob) as the parameter since i already checked if it returned a result or not. duh! thanks for your help guys!
heres my final product

Code:

function countBytes(search)
   aob = AOBScan(search)
   if(aob ~= nil) then
      s = DEC_HEX(((string.len(search))-2)/3)   --do everything(is there enough parenthesis? lol)
      print (s)      --output number
   end
   object_destroy(aob);
   aob=nil
end

_________________
-TNC
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 Tutorials -> LUA Tutorials 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 cannot download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites