 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
xcynic Cheater
Reputation: 0
Joined: 28 Aug 2010 Posts: 31
|
Posted: Sun Mar 24, 2013 4:17 pm Post subject: Problem with enable while key down. |
|
|
Hey. So I'm currently trying to make a script that deletes the gravity in a game when a certain key is pushed down.
I tried reading the tutorial on how to do so, but I think I might have messed up somewhere.
So basically, this is the code that kills the gravity for the game:
| Code: | [ENABLE]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)
newmem:
originalcode:
nop
nop
nop
nop
nop
exit:
jmp returnhere
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[DISABLE]
dealloc(newmem)
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C |
And that is working, but I have to enable it/disable it.
Here's my attempt at while keydown:
| Code: | [ENABLE]
alloc(newmem,2048)
alloc(notpressed,2048)
label(returnhere)
label(originalcode)
label(exit)
newmem:
pushad
pushfd
push 'X'
call GetAsyncKeyState
shr ax,#15
cmp ax,1
jne notpressed
nop
nop
nop
nop
nop
notpressed:
popfd
popad
originalcode:
movss [ebx+5C],xmm0
exit:
jmp returnhere
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[DISABLE]
dealloc(newmem)
dealloc(notpressed)
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C |
But whenever I press the key, X in this case, the game instantly crashes.
Hopefully you guys can help me out here. Thanks in advance!
|
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sun Mar 24, 2013 4:31 pm Post subject: |
|
|
Possibly because that it does the NOP part +popfd+popad
Try this
| Code: | [ENABLE]
alloc(newmem,2048)
//alloc(notpressed,2048) // why did you allocate new memory for this?
label(returnhere)
label(originalcode)
label(exit)
label(notpressed) //no need to allocated new memory
newmem:
pushad
pushfd
push 'X'
call GetAsyncKeyState
shr ax,#15
cmp ax,1
jne notpressed
nop
nop
nop
nop
nop
jmp exit //jumping back to the rest of the function.. if you don't add it, it will do the popfd and poad part + original code part.
notpressed:
popfd
popad
originalcode:
movss [ebx+5C],xmm0
jmp exit
exit:
jmp returnhere
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[DISABLE]
dealloc(newmem)
dealloc(notpressed)
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C |
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25832 Location: The netherlands
|
Posted: Sun Mar 24, 2013 4:31 pm Post subject: |
|
|
Are you sure this is the script you're using? Because pressing X has absolutely no effect whatsoever to the result. So it should have crashed when not pressing X as well
_________________
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 |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sun Mar 24, 2013 5:02 pm Post subject: |
|
|
Dark byte I think its because he/she did not add jump to exit.
It executes the other assembly lines.
Also,
I always get crash when I use push/pop fd,ad in Flash games.
So when I want to disable I use 2 ASM entries.
The first one is enabling it.
| Code: | [ENABLE]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
registersymbol(originalcode)
label(exit)
newmem:
originalcode:
nop
nop
nop
nop
nop
exit:
jmp returnhere
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[DISABLE]
dealloc(newmem)
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C |
And at the other one I do this
| Code: |
[ENABLE]
originalcode:
movss [ebx+5C],xmm0
[DISABLE]
originalcode:
nop
nop
nop
nop
nop
|
Assigan both,
Then add hotkey for example X to toggle the second script (Right Click > hotkeys).
And then it should work for you without the pain of crashing.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
xcynic Cheater
Reputation: 0
Joined: 28 Aug 2010 Posts: 31
|
Posted: Sun Mar 24, 2013 5:33 pm Post subject: |
|
|
Thanks for the answers.
Adding the jmp exit part did not work either (that's how I wrote the script in the begining, but to no avail.)
Dark Byte, I was trying to do what this tutorial here said: http://www.cheatengine.org/keypresstut.php
But maybe I misunderstood what it does. I'm very new to ASM and can quite frankly say that I don't understand most of the expressions I see.
How would one go about to make it so that if I press X (or whatever button) activates this code until the button is released:
| Code: |
[ENABLE]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)
newmem:
originalcode:
nop
nop
nop
nop
nop
exit:
jmp returnhere
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[DISABLE]
dealloc(newmem)
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C |
or do I need to write it into C++/C#/VB code for it to be able to work like that?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25832 Location: The netherlands
|
Posted: Sun Mar 24, 2013 6:09 pm Post subject: |
|
|
something like this:
| Code: |
[ENABLE]
alloc(newmem,2048)
label(returnhere)
label(exit)
newmem:
pushad
pushfd
push 'X'
call GetAsyncKeyState
shr ax,#15
cmp ax,1
je exit //if pressed do not execute the original code
movss [ebx+5C],xmm0
exit:
popfd
popad
jmp returnhere
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[DISABLE]
dealloc(newmem)
dealloc(notpressed)
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C
|
_________________
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 |
|
 |
SteveAndrew Master Cheater
Reputation: 30
Joined: 02 Sep 2012 Posts: 323
|
Posted: Sun Mar 24, 2013 6:32 pm Post subject: |
|
|
@xcynic: Try what Dark Byte suggested... It seems like your problem was you didn't popfd + popad in both code paths (that will for sure crash if you pushad and pushfd, but forget to popfd and popad)
Also forget putting the nops in your code, they don't do anything so don't put them there...
However if for some reason you can't use GetAsyncKeyState in that hook even with preserving the state of the registers and flags, then I suggest run your key handler in a separate thread (in which case you won't have to worry about messing with the registers)
Like this:
| Code: |
[enable]
alloc(newmem,2048)
alloc(KeyHandlerThread,256)
label(returnhere)
label(KeyIsDown)
label(KeyHandlerThread)
label(GravityCheatDisabled)
label(ExitKeyHandler)
label(KeyDownValue)
createthread(KeyHandlerThread)
registersymbol(GravityCheatDisabled)
newmem:
pushfd
cmp word [KeyDownValue],1
je KeyIsDown
popfd ///in all code paths you have to do this, since you pushed it
movss [ebx+5c],xmm0
jmp returnhere
KeyIsDown:
popfd //don't forget
jmp returnhere
KeyHandlerThread:
push 0a
call Sleep
cmp [GravityCheatDisabled],1
je ExitKeyHandler
push 'X'
call GetAsyncKeyState
shr ax,#15
mov [KeyDownValue],ax
jmp KeyHandlerThread
ExitKeyHandler:
ret
KeyDownValue:
dw 0
GravityCheatDisabled:
dd 0
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[disable]
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C
GravityCheatDisabled: //let key handler thread exit, but don't deallocate it!
dd 1
dealloc(newmem)
unregistersymbol(GravityCheatDisabled)
|
_________________
|
|
| Back to top |
|
 |
xcynic Cheater
Reputation: 0
Joined: 28 Aug 2010 Posts: 31
|
Posted: Mon Mar 25, 2013 5:39 am Post subject: |
|
|
| Dark Byte wrote: | something like this:
| Code: |
[ENABLE]
alloc(newmem,2048)
label(returnhere)
label(exit)
newmem:
pushad
pushfd
push 'X'
call GetAsyncKeyState
shr ax,#15
cmp ax,1
je exit //if pressed do not execute the original code
movss [ebx+5C],xmm0
exit:
popfd
popad
jmp returnhere
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[DISABLE]
dealloc(newmem)
dealloc(notpressed)
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C
|
|
Thanks for clearing that up, but it still doesn't work. It doesn't crash, but now all it does is to push me into the ground, not taking away the gravity. Weird.
| SteveAndrew wrote: | @xcynic: Try what Dark Byte suggested... It seems like your problem was you didn't popfd + popad in both code paths (that will for sure crash if you pushad and pushfd, but forget to popfd and popad)
Also forget putting the nops in your code, they don't do anything so don't put them there...
However if for some reason you can't use GetAsyncKeyState in that hook even with preserving the state of the registers and flags, then I suggest run your key handler in a separate thread (in which case you won't have to worry about messing with the registers)
Like this:
| Code: |
[enable]
alloc(newmem,2048)
alloc(KeyHandlerThread,256)
label(returnhere)
label(KeyIsDown)
label(KeyHandlerThread)
label(GravityCheatDisabled)
label(ExitKeyHandler)
label(KeyDownValue)
createthread(KeyHandlerThread)
registersymbol(GravityCheatDisabled)
newmem:
pushfd
cmp word [KeyDownValue],1
je KeyIsDown
popfd ///in all code paths you have to do this, since you pushed it
movss [ebx+5c],xmm0
jmp returnhere
KeyIsDown:
popfd //don't forget
jmp returnhere
KeyHandlerThread:
push 0a
call Sleep
cmp [GravityCheatDisabled],1
je ExitKeyHandler
push 'X'
call GetAsyncKeyState
shr ax,#15
mov [KeyDownValue],ax
jmp KeyHandlerThread
ExitKeyHandler:
ret
KeyDownValue:
dw 0
GravityCheatDisabled:
dd 0
DunDefGame.GetOutermost+2AF679:
jmp newmem
returnhere:
[disable]
DunDefGame.GetOutermost+2AF679:
movss [ebx+5C],xmm0
//Alt: db F3 0F 11 43 5C
GravityCheatDisabled: //let key handler thread exit, but don't deallocate it!
dd 1
dealloc(newmem)
unregistersymbol(GravityCheatDisabled)
|
|
Thanks for that, I see what you mean with needing to pop, but this still seems to make the game crash. Is there any good ebooks that explains assembly a bit more indepth that you'd recommend?
|
|
| Back to top |
|
 |
|
|
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
|
|