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 


Wait for code execution to stop before disabling script?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Cheating'sHard
Newbie cheater
Reputation: 0

Joined: 15 Aug 2020
Posts: 12
Location: 16845 N 29th Ave Ste 1212, Phoenix, AZ 85053

PostPosted: Tue Feb 15, 2022 11:12 am    Post subject: Wait for code execution to stop before disabling script? Reply with quote

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?

_________________
Why not?
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4725

PostPosted: Tue Feb 15, 2022 12:02 pm    Post subject: Reply with quote

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.

Edit: this has come up several times before, so I wrote a guide about it:
https://forum.cheatengine.org/viewtopic.php?p=5776941#5776941

_________________
I don't know where I'm going, but I'll figure it out when I get there.


Last edited by ParkourPenguin on Tue Feb 15, 2022 4:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Tue Feb 15, 2022 12:56 pm    Post subject: Reply with quote

createthreadandwait can help
_________________
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 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