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 


Reading AA Registered Symbols in Lua

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
godsblight
Grandmaster Cheater
Reputation: 0

Joined: 02 Jul 2007
Posts: 805

PostPosted: Sun Dec 20, 2020 9:48 am    Post subject: Reading AA Registered Symbols in Lua Reply with quote

I looked around and read some stuff and everything I can think of me doing is correct, so at this point I'm stumped.

Situation: I have a registered symbol in AA called ConsumablesBase along with an allocation of the same name. The symbol's value is an address, so ConsumablesBase is essentially a pointer. I am attempting to read that pointer or extract the value and then get the value of that address with offset 10F. My issue is that Lua is returning completely wrong addresses and values.

Lua is returning these values (I tried with different formatting just incase):
ConsumeablesBase Address formatted with string format: 7ff652670016
ConsumeablesBase Address formatted with DEC_HEX function: 7FF652670016
ConsumeablesBase Address not formatted, output in integer: 140695921164310 <= this one in hex is the same as the two above.
ConsumeablesBase's Value formatted to Hex: 7BB7F807598

Cheat engine when putting these ConsumeablesBase as an address into the table:

Address: 7FF652660013
Value: 000007BB7FB486D8

Thanks in advance for any helpful insight on what might be happening.

Here is my code

Code:

[enable]
{$lua}
function DEC_HEX(IN)
    local B,K,OUT,I,D=16,"0123456789ABCDEF","",0
    while IN>0 do
        I=I+1
        IN,D=math.floor(IN/B),math.mod(IN,B)+1
        OUT=string.sub(K,D,D)..OUT
    end
    return OUT
end
local HpAddress
HpAddressStringFormat = string.format( '%x', GetAddress("ConsumeablesBase") )
HpAddressDEC_HEX = DEC_HEX( GetAddress("ConsumeablesBase") )
HpAddressDecRaw = GetAddress("ConsumeablesBase")
HpAddressValue = DEC_HEX( readQword("ConsumeablesBase") )
[/code]
_________________
Name: Player One
Occupation: Gamer

The Players are a particularly violent group of gamers. They solve all of their problems via bloody bouts with each other, and they live happier lives for it.

Player One is blue, and a bit of an asshole.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Sun Dec 20, 2020 11:00 am    Post subject: Reply with quote

It would be helpful if you had the AA script that initializes the symbol. I'm assuming it goes something like this:
Code:
newmem:
  // original code:
  mov [edi+10F],eax
  // your code:
  mov [ConsumablesBase],edi
  jmp return

godsblight wrote:
The symbol's value is an address, so ConsumablesBase is essentially a pointer. I am attempting to read that pointer or extract the value and then get the value of that address with offset 10F.
...

Cheat engine when putting these ConsumeablesBase as an address into the table:

Address: 7FF652660013
Value: 000007BB7FB486D8
You recognize it's a pointer and it has one offset of 10F. Treat it like it's a pointer with an offset of 10F.
When you click on "add address", click the "pointer" checkbox, put "ConsumablesBase" for the base address, and put "10F" for the offset.
Lua equivalent:
Code:
print(getAddressSafe'[ConsumablesBase]+10F')
print(readInteger'[ConsumablesBase]+10F')

-- more explicit:
print(readInteger(readPointer'ConsumablesBase'+0x10F))


Also:
Code:
function DEC_HEX(IN)
    return ('%X'):format(IN)
end
Lua has operators for integer division ("//") and modulus ("%") too.
_________________
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
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Dec 20, 2020 11:06 am    Post subject: Reply with quote

keep in mind that lua executes before the AA script, so if you do the registering of the symbol in the SAME script, you're not going to get the current address
_________________
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
godsblight
Grandmaster Cheater
Reputation: 0

Joined: 02 Jul 2007
Posts: 805

PostPosted: Mon Dec 21, 2020 2:38 am    Post subject: Reply with quote

Thanks for all the help. I must have been super tired when I was trying to do this, because I was looking at the wrong base address. Embarassed

@ParkourPenguin - thanks for the advice and letting me know about the string operators.

@Dark Byte - I had read that somewhere before, so I made sure that the LUA script is a child entry of the ASM script so the symbols get registered before hand, otherwise I know to use the AutoAssemble[[code here]] block in LUA. Don't know if there is a better way or other way besides doing that or putting the ASM in a code block beforehand and calling the AutoAssemble method in LUA

_________________
Name: Player One
Occupation: Gamer

The Players are a particularly violent group of gamers. They solve all of their problems via bloody bouts with each other, and they live happier lives for it.

Player One is blue, and a bit of an asshole.
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