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 


How to set up custom events and it's event handler

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 75

PostPosted: Sun Jan 08, 2023 11:41 am    Post subject: How to set up custom events and it's event handler Reply with quote

I want to run a code whenever the value of a memory address has a value x. I don't want timer based solution (I think they are inefficient, please prove me wrong) . For now I am using hotkeys to do such things. But I don't want to constantly press a button for this use case(I have to press it too frequently) . But I recently found a static address let's say y. I want to do something like "when y has value x run this code". This can be done with code injection also but I don't want to use assembly. I am comfortable with lua not with asm. Maybe if someone can suggest me a way to inject lua function inside assembly that would help.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Sun Jan 08, 2023 12:34 pm    Post subject: Reply with quote

sgsgwv$6263 wrote:
For now I am using hotkeys to do such things. But I don't want to constantly press a button for this use case(I have to press it too frequently) .
Just use a timer. Increase the interval to however frequently you press the hotkey and it'll be the same.

If the value doesn't get written to that often, you could use a breakpoint.

Worst case, you could use code injection and {$luacode}. (I think {$luacode} would be about as bad as a breakpiont- use assembly to skip over the {$luacode} block if it isn't the right value)

_________________
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
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Sun Jan 08, 2023 2:14 pm    Post subject: Reply with quote

If you have fixed addresses (where x values are read and y values are read), you can compare them with the lua code and add something based on the result.
You can use this interchangeably with "{$lua}", "{$asm}" in asm.
And yes, it makes more sense to use a timer if the reading is not predictive or instantaneous.
You can handle this in a single script and with a hotkey assigned to it.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 75

PostPosted: Sun Jan 08, 2023 10:23 pm    Post subject: Reply with quote

Thanks for help both of you. But I have never used a script with {$lua} and {$asm} togather. I have used lua and asm togather before but somehow my lua code cannot access the register values if I inject the lua code between asm. Or even if I call print() , the call happens just when I activate the script and not when the the processor executes the asm code. I think it skips over the lua code(?).

Seeing something like this:
https://www.cheatengine.org/forum/viewtopic.php?t=577027&sid=9a8df847d55270ea27d2ef2756b7ca86

I think it's too much boilerplate code for calling a single function. Can you elaborate whats going on in DB's code in this link or provide a simple alternative solution like that.

Also, the value doesnot get written periodically. It depends on what happens in the game.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Sun Jan 08, 2023 10:36 pm    Post subject: Reply with quote

{$lua} is just for preprocessing stuff before the AA script actually gets run (a returned string gets put into the script). {$luacode} is for injecting Lua code that gets run from a code injection.

Again, I would highly recommend just using a timer. It's by far the simplest solution. If it's not fast enough, you're doing something wrong and it's very likely no other solution will be fast enough. Lua code is always run by CE: {$luacode} necessarily involves synchronous IPC. This is not fast.
If you insist on {$luacode}:
https://forum.cheatengine.org/viewtopic.php?t=618134

If you gave more details about whatever it is you're trying to do, you could get better help. Post the code you have so far.

_________________
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
sgsgwv$6263
Advanced Cheater
Reputation: 0

Joined: 05 Aug 2020
Posts: 75

PostPosted: Sun Jan 08, 2023 10:57 pm    Post subject: Reply with quote

Okay. Thanks. I think timers will be okay if {$luacode} is that bad.

But in luacode, will the registers be available for use like eax will be in EAX variable?

What I am trying to do: currently I have set a hotkey that sets a breakpoint at an asm code. On breakpoint,Based on certain condition writes something to eax register. Another hotkey is set for removing the breakpoint. The value that I am changing is not in any memory address, it's only in that eax register at the BP address.

But all this has to be done frequently. It's a code which is trying to set field positions for a baseball game. Game doesnot allow field positions other than the in built positions. I have to press this hotkey everytime the pitcher is ready to throw the ball so that before he throws the ball I can set the coordinates of the fielders with my script using these hotkeys.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon Jan 09, 2023 5:34 am    Post subject: Reply with quote

sgsgwv$6263 wrote:
Okay. . I have to press this hotkey everytime the pitcher is ready to throw the ball so that before he throws the ball I can set the coordinates of the fielders with my script using these hotkeys.


Let's assume the ready position is 1, and the non-ready value is 0.
If you can find an address that will give you this value, we can develop a good idea for your code.
The required address should give the following values:
It must give values indicating that the ball in the pitcher is pending (not ready) or ready.
If you find the address that says these values, we're done.

(A similar lua code has been rendered recently.)

https://forum.cheatengine.org/viewtopic.php?p=5780987#5780987

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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