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 


Checking whether a Pointer is working [solved]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
b0g_
How do I cheat?
Reputation: 0

Joined: 22 Jan 2022
Posts: 5

PostPosted: Sat Jan 22, 2022 7:57 am    Post subject: Checking whether a Pointer is working [solved] Reply with quote

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
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1053
Location: 0x90

PostPosted: Sat Jan 22, 2022 9:49 am    Post subject: Reply with quote

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
View user's profile Send private message
TheyCallMeTim13
Wiki Contributor
Reputation: 50

Joined: 24 Feb 2017
Posts: 976
Location: Pluto

PostPosted: Sat Jan 22, 2022 11:44 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Sat Jan 22, 2022 12:53 pm    Post subject: Reply with quote

^
or readPointer(address)

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Sat Jan 22, 2022 1:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
b0g_
How do I cheat?
Reputation: 0

Joined: 22 Jan 2022
Posts: 5

PostPosted: Sat Jan 22, 2022 3:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting 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