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 


Can't disable createthread script

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Wed Mar 29, 2017 8:49 pm    Post subject: Can't disable createthread script Reply with quote

I had an earlier issue of figuring out how to add a delay to a script and a friend suggested to use createthread + sleep Windows function, so I removed that post thanks to this solution basically doing what I needed. But I was probably too quick to do that since now I have a new issue,

Disabling this script does not stop the loop from being continued and shortly after the game also crashes, I've never used createthread outside of Lua before so am not sure how to "suspend" the thread or whatever it might be I need to do for it to stop.

Code:
[enable]
alloc(key1,128)
alloc(update,32)
label(loop)
 
createthread(loop)
 
key1:
mov esi,[00000000]
mov ecx,[esi+00]
push edx
push 00
call 00000000
ret
 
update:
mov edx, 002C0000
call key1
jmp loop
 
loop:
push 2000
call Kernel32.Sleep
jmp update
 
[disable]
dealloc(key1)
dealloc(update)


any help would be greatly appreciated, thank you in advance
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Wed Mar 29, 2017 10:11 pm    Post subject: Reply with quote

Deallocating memory a thread is actively using like you're doing will kill the program. To do it safely, let the thread deallocate its own memory.

x86 example:
Code:
[ENABLE]
alloc(newmem,2048)
label(shouldExit)
registersymbol(shouldExit)

createthread(newmem)

newmem:
  push #50
  call kernel32.Sleep
  cmp byte ptr[shouldExit],0
  je newmem
// free memory, return
  pop eax
  push 8000
  push 0
  push newmem
  push eax
  jmp kernel32.VirtualFree
shouldExit:
  db 0

[DISABLE]
shouldExit:
  db 1

unregistersymbol(shouldExit)


x64 example:
Code:
[ENABLE]
alloc(newmem,2048,kernel32.dll)
label(shouldExit)
registersymbol(shouldExit)

createthread(newmem)

newmem:
  push rbp
  mov rbp,rsp
  sub rsp,20
  and spl,F0
@@:
  mov ecx,#50
  call kernel32.Sleep
  cmp byte ptr[shouldExit],0
  je @b
// free memory, return
  mov rsp,rbp
  pop rbp
  mov rcx,newmem
  xor rdx,rdx
  mov r8d,8000
  jmp kernel32.VirtualFree
shouldExit:
  db 0

[DISABLE]
shouldExit:
  db 1

unregistersymbol(shouldExit)


(you could also just use globalalloc and not worry about deallocating the memory)

_________________
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
usernotfound
Expert Cheater
Reputation: 0

Joined: 21 Feb 2016
Posts: 115

PostPosted: Wed Mar 29, 2017 10:35 pm    Post subject: Reply with quote

Thank you so much, you're right the deallocs were indeed causing the crash

Sorry if this is a silly question, but is the difference between x86/x64 here meant to apply to my OS or if the game is 32 bit or not? I'm guessing the latter but just wanted to make sure
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 Mar 30, 2017 2:02 am    Post subject: Reply with quote

you can also use a {$LUA} section in which you write a value with writeInteger to signal it has to stop, and then wait till the thread has actually terminated before you continue. (Lua sections run before the AA script runs, so the dealloc will always be done last)

e.g
Code:

writeInteger('Terminate',1)
while readInteger('hasTerminated')==0 do
  sleep(100)
end
sleep(10) --just to be sure the last ret gets executed as well


and in your thread check for the state of Terminate, and if it's set exit the loop (and set hasTerminated to true)

_________________
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
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Thu Mar 30, 2017 8:11 am    Post subject: Reply with quote

usernotfound wrote:
is the difference between x86/x64 here meant to apply to my OS or if the game is 32 bit or not?

The game.

_________________
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
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