| View previous topic :: View next topic |
| Author |
Message |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Sun Apr 17, 2016 2:32 am Post subject: Random number generator crashes the game. |
|
|
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 |
|
 |
++METHOS I post too much
Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Sun Apr 17, 2016 2:39 am Post subject: |
|
|
| You should paste your script in its entirety. Also, you should pop in reverse order.
|
|
| Back to top |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Sun Apr 17, 2016 8:30 am Post subject: |
|
|
| ++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".
Update:
The game does not crash if I removed "call rand", but why?
Last edited by Dr.Disrespect on Sun Apr 17, 2016 8:49 am; edited 1 time in total |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25816 Location: The netherlands
|
Posted: Sun Apr 17, 2016 8:44 am Post subject: |
|
|
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 |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Sun Apr 17, 2016 8:50 am Post subject: |
|
|
| Dark Byte wrote: | | You're popping the registers in the wrong order |
I reversed the popping order, but it still crashes the game...
It's the line "div ecx" that causes the crash...
|
|
| Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4711
|
Posted: Sun Apr 17, 2016 10:25 am Post subject: |
|
|
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 |
|
 |
Dr.Disrespect Grandmaster Cheater
Reputation: 3
Joined: 17 Feb 2016 Posts: 526
|
Posted: Sun Apr 17, 2016 3:14 pm Post subject: |
|
|
| 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.
|
|
| Back to top |
|
 |
|