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 


Lua script: how to read a value from memory address?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Wed Apr 13, 2016 5:00 pm    Post subject: Lua script: how to read a value from memory address? Reply with quote

In Lua script, how to read a value from a memory address and then show the value in decimal on my trainer?
For example:
1. The hexdecimal value is "64 01" at the memory address: 00000001.
2. I want to read that value and then show it on my trainer the decimal value: 356.

What lua functions should I use?
I have tried the follwing and it does not work(did not allow me to execute script):
Code:

function CEButton1Click(sender)
   readInteger(game.exe+00000001)
end

Thanks in advance. Smile

Update:
I figured it out. In case someone needs it:
Code:

function CEButton1Click(sender)
   local number = readBytes("game.exe+00000001",2)
   control_setCaption(CETrainer.CELabel1,tostring(number))
end

new question here: <--------------------------------
How to read 4 bytes? or 8 bytes? I changed the number "2" to "4" or "8", but it did not work, it still only read "64" insteadn of "64 01".
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Apr 13, 2016 5:35 pm    Post subject: Reply with quote

You simply forgot the quotes.
4-bytes:
Code:
readInteger("game.exe+00000001")

8-bytes:
Code:
readQword("game.exe+00000001")
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Wed Apr 13, 2016 5:39 pm    Post subject: Reply with quote

Zanzer wrote:
You simply forgot the quotes.
4-bytes:
Code:
readInteger("game.exe+00000001")

8-bytes:
Code:
readQword("game.exe+00000001")


Thanks for the reply.
But readInteger did not work properly.
The address looks like this:
"09 01 ff ff"

1. readBytes: the result is "9", which is correct.
2. readInteger: the result is "4294902025". However, "109" should be "265". What did I do wrong?

I just want to read "09 01".


Last edited by Dr.Disrespect on Wed Apr 13, 2016 5:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Wed Apr 13, 2016 5:45 pm    Post subject: Reply with quote

readInteger is for 4 bytes. There is no readShort for 2-byte values.
Code:
local b1,b2 = readBytes("address",2)
local value = b2 * 256 + b1
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Wed Apr 13, 2016 5:46 pm    Post subject: Reply with quote

Zanzer wrote:
readInteger is for 4 bytes. There is no readShort for 2-byte values.
Code:
local b1,b2 = readBytes("address",2)
local value = b2 * 256 + b1


Zaner, you saved me again. Thanks so much. Very Happy
One final question:
local b1,b2=readBytes("address",2)

What value are being assigned to b1 and b2 respectively? I am not very familiar with the syntax.
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 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