View previous topic :: View next topic |
Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Wed Apr 13, 2016 5:00 pm Post subject: Lua script: how to read a value from memory address? |
|
|
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.
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 |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Wed Apr 13, 2016 5:35 pm Post subject: |
|
|
You simply forgot the quotes.
4-bytes:
Code: | readInteger("game.exe+00000001") |
8-bytes:
Code: | readQword("game.exe+00000001") |
|
|
Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Wed Apr 13, 2016 5:39 pm Post subject: |
|
|
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 |
|
 |
Zanzer I post too much
Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Wed Apr 13, 2016 5:45 pm Post subject: |
|
|
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 |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Wed Apr 13, 2016 5:46 pm Post subject: |
|
|
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.
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 |
|
 |
|