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 


Break on register and pass count

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Csimbi
I post too much
Reputation: 98

Joined: 14 Jul 2007
Posts: 3362

PostPosted: Wed Mar 04, 2026 5:37 pm    Post subject: Break on register and pass count Reply with quote

Hiya LUA masters,
I would like to come up with a scriptlet to a complex breakpoint condition.
This is what I am thinking about.
Code:
--the register values like EAX and EBX can be read here.
--Changing them has no effect though
--Note: Keep in mind hexadecimal values start with 0x
--return (conditon) --return a non-zero value if you want to break
local passcount=0
passcount=passcount+1
if RSI==0x1847E621C0 and RAX==0x250 and passcount==2 then return (1)
return (0)


Above code does not break.
I guess the problem is, if the code gets executed each time the breakpoint is hit, passcount will be always reset to zero and it never gets to 2.
Any ideas?

Additionally, does this work for break and trace?
If I change the breakpoint conditions manually where I set the trace.

Thank you!
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1556

PostPosted: Thu Mar 05, 2026 1:33 am    Post subject: Reply with quote

If you assign a "passcount" each time, your loop will only see 1.
Code:
local passcount = 0


Assign it if it doesn't exist, overwrite it if it does, add it:
Code:
if passcount == nil then passcount = 0 end

passcount = passcount + 1

print(passcount)

-----------------------------------------

The main gap here is when the loop is updated.

If you don't reset "passcount" after the current condition (2), the loop can never return to 2.

In this case, you have to check for multiples of two instead of "passcount==2":

Code:
if passcount % 2 == 0 then --> 2.. 4.. 6.. 8 ...


---------------------------------------------

However, I recommend adding a refresh condition and resetting the counter back to 0 at the expected time.

Also, it might be more appropriate to increment the counter only when the specified conditions are met (if RSI and RAX...).

The decision is yours, and here's an example with explanations:

Code:
-- Global persistence: If passcount doesn't exist yet, initialize it to 0.
-- Since we don't use 'local', this value stays in memory between hits.
if passcount == nil then passcount = 0 end

-- Logical Filter: Only increment the counter if our specific registers match.
-- This ensures we are counting the specific event, not just every time the code runs.
if RSI == 0x1847E621C0 and RAX == 0x250 then
    passcount = passcount + 1
   
    -- Hit Target: Check if this is the 2nd time the condition is met.
    if passcount == 2 then
        passcount = 0 -- Self-Reset: Prepare for the next cycle (2nd, 4th, 6th...)
        return 1      -- Trigger: Return non-zero to break the execution.
    end
end

-- Default: Return 0 so the debugger continues running without stopping.
return 0

_________________
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