Joined: 15 Aug 2020 Posts: 12 Location: 16845 N 29th Ave Ste 1212, Phoenix, AZ 85053
Posted: Tue Feb 15, 2022 11:12 am Post subject: Wait for code execution to stop before disabling script?
I have a really large auto-assemble script. It's large enough that it has a tendency to crash the game when it's disabled, and I assume this is because the instruction pointer is still in the script, so when it deallocates all of the memory it crashes.
Is there a way to wait for the execution to stop before deallocating the memory so this doesn't happen? If not, is there another way to avoid this crashing behavior? _________________
Processors are fast. Unless you're running at least several hundred thousand instructions, script length isn't a problem. You should provide more information about what you're doing.
Calling sleep or using allocated memory for some sort of callback could be a problem if the memory is deallocated before execution finishes. In simple cases, the thread running the code can deallocate the memory itself with a tail call to VirtualFree:
https://www.cheatengine.org/forum/viewtopic.php?p=5744208#5744208
If you aren't using createthread yourself and are injecting code, you'll have to inject at the beginning of a function so that VirtualFree has shadow store available on the stack.
In general, I guess you could set a flag in assembly and create a timer in the disable section that reads this flag and acts when it is set. But at that point it might be easier to use globalalloc to only ever allocate memory once and forget about deallocating memory.
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