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 


onMemRecPostExecute execution order bug?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
thebmxbandit11
Newbie cheater
Reputation: 0

Joined: 03 Jul 2014
Posts: 15

PostPosted: Thu Jul 13, 2017 2:35 am    Post subject: onMemRecPostExecute execution order bug? Reply with quote

In the below code blocks I'm trying to get the sub entry worldFlags to properly activate and run the line of code that prints "do something"

This code doesn't work

Code:
   
--a table has a main open AA script that populates the table entries
openAddr = getAddressList().getMemoryRecordByID(21)
openAddr.Active = true

function onMemRecPostExecute(memrec, newState, succeeded)

  print(memrec.ID, tostring(newState), tostring(succeeded))

  if memrec.ID == 21 and succeeded then --this is if the table is open
    --this is an entry that appears on the table when openAddr is set to active
    worldFlags = al.getMemoryRecordByID(12567)
    worldFlags.Active = true
    print("done with opening table?")

  elseif memrec.ID == 12567 and succeeded then
    print("do something")
  end

end

--[[output:
21 true true
12567 true false      ------ <<<< The problem
done with opening table?
--]]



This really gross code does work, but I'd love to know if there is a better way to do this.


Code:

--a table has a main open AA script that populates the table entries
openAddr = getAddressList().getMemoryRecordByID(21)
openAddr.Active = true

function onMemRecPostExecute(memrec, newState, succeeded)

  print(memrec.ID, tostring(newState), tostring(succeeded))

  if memrec.ID == 21 and succeeded then --this is if the table is open
    t2=createTimer(nil)
    timer_setInterval(t2,100)
    timer_onTimer(t2,openSubEntry)
    print("done with opening table?")

  elseif memrec.ID == 12567 and succeeded then
    print("do something")
  end

end

testTimer = 0

function openSubEntry()
  testTimer = testTimer + 1

  if testTimer == 10 then
    --activating last hit script for mod
    lastHitAddr = al.getMemoryRecordByID(12246)
    lastHitAddr.Active = true
  end
end

--[[output:
21 true true
done with opening table?
12567 true true
do something
--]]


The "problem" is I want to activate sub-entries of a table after the master AA script has finished, but using the function seen in the first example it attempts to activate the memory record before (I think) the actual end of execution, where end of execution is defined as the AA script finished and the table is now updated with clickable entries. The second example is just a cheap trick that waits 1 second or 10 cycles of a timer function before activating the memory record (not sure if u have to wait 10 cycles or just one will do), but this feels like horrible practice and I'd really like to know if this is intended or a glitch. Also if it is not a glitch then is there any other function that is like onMemoryRecordFinishActivation that waits until the AA script is completely done and the table is populated?

I pretty much understand the glitch, which is basically the initial onMemRecPostExecute is called then inside of it we try to activate a sub entry on the table, which runs the AA script immediately and then calls onMemRecPostExecute again before the first call has returned. The problem i am guessing is that onMemRecPostExecute is called before the table updates, but after the AA script finishes, so I need to call the sub entry activation after the first onMemRecPostExecute is completely finished, but there really isn't anyway to do that because adding a function call at the end or something needs an artificial non-sleep delay or else it will just execute before the end anyway (i think).

Thanks!
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Jul 13, 2017 2:52 am    Post subject: Reply with quote

onMemRecPostExecute (and memrec.OnActivate/memrec.OnDeactivate) executes after the AA code has been executed

do you have any conflicting options like activating children on parent activation?
Is it an async record ?

Does memrec 12567 do something with an initialized pointer? Perhaps the game hasn't had time to run the AA code yet.

(Also, your second script has a mistake, you activate 12246 but 12567 gets activated)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Jul 13, 2017 2:58 am    Post subject: Reply with quote

Also, this table:
Code:

<?xml version="1.0" encoding="utf-8"?>
<CheatTable>
  <CheatEntries>
    <CheatEntry>
      <ID>0</ID>
      <Description>"Auto Assemble script"</Description>
      <LastState Activated="1"/>
      <VariableType>Auto Assembler Script</VariableType>
      <AssemblerScript>[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat

00400500:
nop
 
 
[DISABLE]
//code from here till the end of the code will be used to disable the cheat
</AssemblerScript>
      <CheatEntries>
        <CheatEntry>
          <ID>1</ID>
          <Description>"Auto Assemble script"</Description>
          <LastState Activated="1"/>
          <VariableType>Auto Assembler Script</VariableType>
          <AssemblerScript>[ENABLE]
//code from here to '[DISABLE]' will be used to enable the cheat

00400600:
nop
 
 
[DISABLE]
//code from here till the end of the code will be used to disable the cheat
</AssemblerScript>
        </CheatEntry>
      </CheatEntries>
    </CheatEntry>
  </CheatEntries>
</CheatTable>


with this script:
Code:

function onMemRecPostExecute(memrec, newState, succeeded)

  print(memrec.ID, tostring(newState), tostring(succeeded))

  if memrec.ID == 0 and succeeded then --this is if the table is open
    --this is an entry that appears on the table when openAddr is set to active
    worldFlags = al.getMemoryRecordByID(1)
    worldFlags.Active = true
    print("done with opening table?")

  elseif memrec.ID == 1 and succeeded then
    print("do something")
  end

end

al=getAddressList()
openAddr = getAddressList().getMemoryRecordByID(0)
openAddr.Active = true




works as intended
Code:

0 true true
1 true true
do something
done with opening table?


Oh, one thing that I expect went wrong is that during your tests you put the definition of the function AFTER activating the memory record, causing you to execute the OLD version of onMemRecPostExecute, which will lead to unexpected results

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
thebmxbandit11
Newbie cheater
Reputation: 0

Joined: 03 Jul 2014
Posts: 15

PostPosted: Thu Jul 13, 2017 3:30 am    Post subject: Reply with quote

Oh yea you're right about the ID typo, my actual code is correct on my table, but when writing the example for this post I just typoed it. I wasn't aware about an async option or something like it for a memoryRecord, how do i check that? The main open toggle is a script that just does some AOB scans, and the other sub-entry is just an AA script that doesn't use anything from the open AA script as far as I can tell. I'll try to do more tests because I'm not sure how your example works, but mine doesn't.

edit: tried moving the onMemRecPostExecute to the top and it changed nothing, I think its just that the game hasn't had time to run the assembly, but I guess there is no set way to check if that has happened or is there? I guess I could write something and wait for its effect, but the waiting portion would just be another timer which brings me back to the same issue I had before. If the open script does do things the sub entries need to function, is there anyway to determine when the events have happened? Also my cheat table has all childen of the open hidden until it's active, but toggling that didn't seem to change anything.

also 1 more thing, the first toggle of Active which should set of a chain event of toggles is in onProcessOpen(), not sure if that matters
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Jul 13, 2017 7:51 am    Post subject: Reply with quote

onOpenProcess may be too soon to do things.
it's recommended to only create timers in onOpenProcess

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
thebmxbandit11
Newbie cheater
Reputation: 0

Joined: 03 Jul 2014
Posts: 15

PostPosted: Thu Jul 13, 2017 2:39 pm    Post subject: Reply with quote

Okay, where should I put the first activate then if I need it to run once the trainer has successful attached to the process? Also the activate that is in the onOpenProcess does return true for success, it's just the activates inside the onMemRecPostExecute that fail.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Thu Jul 13, 2017 3:05 pm    Post subject: Reply with quote

don't forget the case where the user runs the trainer before they run the game.

It's likely that the game hasn't loaded all files into memory at the time cheat engine attaches, which will cause some scripts to fail

As for other fails, get dbgview from wininternals and check the output.
When a memoryrecord fails to activate an assembler script, it writes the output to a debug log that dbgview can view as well

https://technet.microsoft.com/en-us/sysinternals/debugview.aspx

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message 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