View previous topic :: View next topic |
Author |
Message |
b0g_ How do I cheat? Reputation: 0
Joined: 22 Jan 2022 Posts: 5
|
Posted: Sat Jan 22, 2022 7:57 am Post subject: Checking whether a Pointer is working [solved] |
|
|
First off I'm a newbie when it comes to Lua, I primarily have experience in java so this language is completely mind boggling for me..
I'm writing a simple cheat table and I'm using Lua scripts to change values without much/any hassle to the user.
currently I'm writing to pointers like this:
Code: | memrec.Child[0].Child[y].Value |
However some of the pointers I use don't point to the correct address in some parts of the game so the pointer looks something like this:
Code: | Address: P->????????
Value: ?? |
But once the cheat needs to modify the value it returns back to normal so no problems there. What I need to do here is not change the Value once that happens because it throws an error in the Lua console.
I've tried doing something like this:
Code: | value = memrec.Child[0].Child[y].Value
if not value == '??' then |
But that didn't work. I hope this explains my situation well, help is much appreciated!
Last edited by b0g_ on Tue Jan 25, 2022 9:42 am; edited 3 times in total |
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Sat Jan 22, 2022 9:49 am Post subject: |
|
|
You will want to read the value from the pointer directly and make any changes based on that for example (assuming it's just a single-level pointer):
Code: |
[ENABLE]
{$LUA}
local baseaddress = 0x1234567
local offset = 0xA
local pointer = getAddressSafe('[' .. baseaddress .. ']+' .. offset)
if pointer ~= nil then
readInteger(pointer)
end
{$ASM}
[DISABLE]
...
|
You didn't state which data type the value is so I've assumed it is an integer. This checks that the address actually exists and if it does then retrieve the integer value at said address.
|
|
Back to top |
|
|
TheyCallMeTim13 Wiki Contributor Reputation: 50
Joined: 24 Feb 2017 Posts: 976 Location: Pluto
|
Posted: Sat Jan 22, 2022 11:44 am Post subject: |
|
|
You can actually just try and write to the address with the CE lua functions. And if the address isn't valid, CE just won't do anything. You can execute this in the lua engine and CE won't throw any errors, if you want error handling you'll have to use "getAddressSafe" to check the address and throw an error based on it's return.
Code: | writeFloat('[DEADBEEF]+10', 100) |
https://wiki.cheatengine.org/index.php?title=Lua:writeFloat
Code: | writeInteger('[mySymbol]+10', 100) |
https://wiki.cheatengine.org/index.php?title=Lua:writeInteger
Code: | writeInteger('game.exe+10AC00', 100) |
Just know that this function and most others that take an address in CE, look at numbers in strings as hex by default. So base 10 numbers need to be passed as numbers or converted to a hex string.
_________________
|
|
Back to top |
|
|
Frouk Master Cheater Reputation: 5
Joined: 22 Jun 2021 Posts: 489 Location: mov dword ptr [Ukraine]
|
Posted: Sat Jan 22, 2022 12:53 pm Post subject: |
|
|
^
or readPointer(address)
_________________
void(__cdecl *Haxing)(HWND hGameWindow) |
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4289
|
Posted: Sat Jan 22, 2022 1:58 pm Post subject: |
|
|
b0g_ wrote: | What I need to do here is not change the Value once that happens because it throws an error in the Lua console. | I can't replicate this behaviour. Setting the value property of a memory record with an invalid address silently fails for me.
b0g_ wrote: | if not value == '??' then | not has higher precedence than ==. i.e. `not 1 == 2` evaluates to false, but `not (1 == 2)` evaluates to true.
You should be using ~= (not equal to operator) anyway. Comparing if the Value property isn't '??' should work most of the time, but there is a small race condition (unless you suspend the process, but that's ridiculous).
If you need to handle failure, read the CurrentAddress property of the memory record and pass that to one of the write* functions. Check the result of those functions to see if they succeeded or not.
Code: | if not writeInteger(AddressList[0].CurrentAddress, 1) then
print'failure'
else
print'success'
end |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
b0g_ How do I cheat? Reputation: 0
Joined: 22 Jan 2022 Posts: 5
|
Posted: Sat Jan 22, 2022 3:33 pm Post subject: |
|
|
wow! thanks for all the advice!!
The issue was solved by using ~= instead (like i said in the post im a newbie in lua). but i will for sure keep all the advice in mind for future trainers, this is my first one and it shows in the code
|
|
Back to top |
|
|
|