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 


Random number generator crashes the game.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sun Apr 17, 2016 2:32 am    Post subject: Random number generator crashes the game. Reply with quote

Please take a look at the following code, which I uses to get a random number between 1-5:
Code:

push eax
push ebx
push ecx
push edx
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor edx,edx
//-------------
call rand
mov ebx,1
mov ecx,5
cmp ecx,ebx
cmovl ecx,ebx
inc ecx
sub ecx,ebx
div ecx   <--------------------------this line causes the crash, same result with "idiv"
add edx,ebx
mov [myRandomNumber],edx
//-------------
pop edx
pop ecx
pop ebx
pop eax (I changed the popping order but it still crashes)


The code above crashes the game, I mark the line that causes the crash. Is there a way to fix it?
Thanks in advance.


Last edited by Dr.Disrespect on Sun Apr 17, 2016 8:51 am; edited 1 time in total
Back to top
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Sun Apr 17, 2016 2:39 am    Post subject: Reply with quote

You should paste your script in its entirety. Also, you should pop in reverse order.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sun Apr 17, 2016 8:30 am    Post subject: Reply with quote

++METHOS wrote:
You should paste your script in its entirety. Also, you should pop in reverse order.


Sorry for the late reply. Actually that's pretty much it about the code, I just injected the code by using the "code injection" template, and when I checked it step by step, the game crashes when it executed "div ecx". Sad

Update:
The game does not crash if I removed "call rand", but why? Sad


Last edited by Dr.Disrespect on Sun Apr 17, 2016 8:49 am; 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: 25817
Location: The netherlands

PostPosted: Sun Apr 17, 2016 8:44 am    Post subject: Reply with quote

You're popping the registers in the wrong order
_________________
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
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sun Apr 17, 2016 8:50 am    Post subject: Reply with quote

Dark Byte wrote:
You're popping the registers in the wrong order

I reversed the popping order, but it still crashes the game... Sad
It's the line "div ecx" that causes the crash...
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 152

Joined: 06 Jul 2014
Posts: 4711

PostPosted: Sun Apr 17, 2016 10:25 am    Post subject: Reply with quote

edx isn't guaranteed to be preserved across a call. xor it after your call to rand. It probably signaled a divide error exception causing the program to crash.

Setting eax, ecx, and ebx to 0 does nothing. Especially for eax and ecx since they'll be destroyed across that call.

_________________
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
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sun Apr 17, 2016 3:14 pm    Post subject: Reply with quote

ParkourPenguin wrote:
edx isn't guaranteed to be preserved across a call. xor it after your call to rand. It probably signaled a divide error exception causing the program to crash.

Setting eax, ecx, and ebx to 0 does nothing. Especially for eax and ecx since they'll be destroyed across that call.


Thank you Penguin, i will give it a try. Smile
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