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 


Crash on sleep

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
SirCabby
Newbie cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 15

PostPosted: Sun Sep 13, 2020 5:26 pm    Post subject: Crash on sleep Reply with quote

I'm working on a game that needs longer freeze cycles for its internal game clock. I have this hardcoded for 10s sleeps, but sometimes I need an additional sleep time for the game to progress. I built this in by creating a registeredsymbol that the user can modify to tell my freeze thread to wait longer on this loop.

Code looks like this:
Code:
  push #8000
  call sleep
  cmp [extraSleepTime],0
  je short smwait
  push #5000 // this line
  call sleep // and this line
  mov [extraSleepTime],0


For some reason, if the second set of push and sleep lines are not commented out, the game crashes immediately. However I'm able to trigger the jump lines and the reset of my variable to 0 without issue if they are commented out. Any ideas?
Back to top
View user's profile Send private message
Csimbi
I post too much
Reputation: 97

Joined: 14 Jul 2007
Posts: 3329

PostPosted: Mon Sep 14, 2020 1:25 am    Post subject: Reply with quote

I think you might be screwing up some state but it's hard to tell from this snippet.
Back to top
View user's profile Send private message
blankTM
Cheater
Reputation: 1

Joined: 03 May 2020
Posts: 49

PostPosted: Mon Sep 14, 2020 2:08 am    Post subject: Re: Crash on sleep Reply with quote

Code:

mov ecx,#8000//64bit
push #8000//32bit
call Sleep
Back to top
View user's profile Send private message
SirCabby
Newbie cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 15

PostPosted: Mon Sep 14, 2020 8:24 am    Post subject: Reply with quote

Thanks for the replies.

The game is 32-bit, but since it's running in a thread, maybe it's 64-bit since it's attached to CE? Either way I have working 32-bit sleeps going on in other places. I've tested the 64-bit sleep variant as well with same result.

I also agree it sounds like state is mixed up somewhere. I'll post the whole script for review. What I'm trying to accomplish has a lot of context in the game, but happy to explain why it's structured the way it is if there's any questions. Thanks again for the help.

Code:

[ENABLE]
globalalloc(mycode,4096)
CREATETHREAD(mycode)

label(save wait smwait loop noerror clockStart mustend frozenTimeAt zero extraSleepTime)
registersymbol(mustend)
registersymbol(frozenTimeAt)
registersymbol(extraSleepTime)

mycode:
{$try}
  jmp loop
save:
  movsd xmm0,[edx+38]  // total time [[[["PapersPlease.exe"+0037DC18]+78]+7C]+A8]+38
  movsd [frozenTimeAt],xmm0
  jmp short smwait
wait:
  push #8000
  call sleep
  cmp [extraSleepTime],0
  je short smwait
  push #5000
  call sleep
  mov [extraSleepTime],0
smwait:
  push #2000
  call sleep
loop:
  mov eax,[mustend]
  test eax,eax
  jne short noerror
  mov ecx,["PapersPlease.exe"+0037DC18]
  mov ecx,[ecx+78]
  mov ecx,[ecx+7C]
  mov edx,ecx
  mov ecx,[ecx+80]
  mov ecx,[ecx+78]
  movsd xmm0,[ecx+68]  // clock [[[[["PapersPlease.exe"+0037DC18]+78]+7C]+80]+78]+68
  mov edx,[edx+A8]
  movsd xmm1,[clockStart] // If clock is at 6, save the timer
  comisd xmm0,xmm1     // clock,clockStart(6)
  je short save
  movsd xmm2,[frozenTimeAt]
  movsd xmm1,[zero]
  comisd xmm1,xmm2 // If our stored value is 0, we should save instead of load
  je short save
// load:
  movsd [edx+38],xmm2  /// total time
  jmp short wait

{$except}
  jmp short smwait

noerror:
  xor eax,eax
  ret

  align 8 CC
clockStart:
  dq (double)6
zero:
  dq (double)0
frozenTimeAt:
  dq (double)0
extraSleepTime:
  dd 0
mustend:
  dd 0

[DISABLE]
mustend:
  dd 1

unregistersymbol(mustend)
unregistersymbol(frozenTimeAt)
unregistersymbol(extraSleepTime)
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Mon Sep 14, 2020 10:14 am    Post subject: Reply with quote

Perhaps there's some other function sleep? Try replacing "call sleep" with "call kernel32.Sleep".

It could be that there are too many instructions to use the short form of jumps. Remove "short" in "jmp/jcc short label", particularly the ones near the bottom.

If that doesn't work, set a breakpoint somewhere and step over instructions until it crashes.

_________________
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
SirCabby
Newbie cheater
Reputation: 0

Joined: 31 Aug 2020
Posts: 15

PostPosted: Mon Sep 14, 2020 11:16 am    Post subject: Reply with quote

ParkourPenguin to my rescue yet again.

I did both of these suggestions, replacing the sleeps with kernel32.Sleep as well as removing shorts from my jumps, and my script immediately worked as expected. Your help is always spot on and appreciated.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking 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