View previous topic :: View next topic |
Author |
Message |
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Sun Feb 19, 2017 5:05 pm Post subject: HELP Assembly Hotkey |
|
|
How can I make an assembly script that checks if a key is pressed. Example:
Code: |
newmem:
cmp [VK_V],1
je code1
jmp code2
|
This script is just an example, for you to understand what I want to do.
(I know you can set key, to enable and disable a script. So do not come up with a response of this)
_________________
... |
|
Back to top |
|
|
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Sun Feb 19, 2017 6:00 pm Post subject: |
|
|
This can be achieved a few different ways. Depending on whether or not the target process is 32-bit or 64-bit, whether you want to incorporate Lua, use strictly ASM and/or if you want to use the target's own code etc..
Here is one example:
Code: | push 56 //Virtual-Key code for 'V' key in hex
call GetAsyncKeyState
cmp ax,1
jne originalcode |
|
|
Back to top |
|
|
SunBeam I post too much Reputation: 65
Joined: 25 Feb 2005 Posts: 4022 Location: Romania
|
Posted: Sun Feb 19, 2017 6:40 pm Post subject: |
|
|
@Filipe_Br: You've seen this in far too many scripts to ask this. Adding to METHOS' post:
Code: | push 56 // VK_V
call user32.GetAsyncKeyState
test ax,ax
jne DoStuff |
BR,
Sun
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4299
|
Posted: Sun Feb 19, 2017 6:42 pm Post subject: |
|
|
Be careful with the return value of GetAsyncKeyState.
Quote: | If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. | MSDN
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Sun Feb 19, 2017 6:48 pm Post subject: |
|
|
Does not work. I tried the following script in the cheat engine "Step 2" tutorial.
Code: |
[ENABLE]
alloc(mem, 1000)
label(code)
createthread(mem)
mem:
push 56
call GetAsyncKeyState
cmp ax,1
je code
jmp mem
code:
push eax
mov eax,Tutorial-i386.exe+1FC5D0
mov [eax+480],#500
pop eax
jmp mem
[DISABLE]
|
Code: |
[ENABLE]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(exit)
newmem:
push 56
call GetAsyncKeyState
cmp ax,1
jne originalcode
mov [ebx+480],#500
cmp [ebx+00000480],000003E8
jmp exit
originalcode:
cmp [ebx+00000480],000003E8
exit:
jmp returnhere
"Tutorial-i386.exe"+23CC3:
jmp newmem
nop
nop
nop
nop
nop
returnhere:
[DISABLE]
dealloc(newmem)
"Tutorial-i386.exe"+23CC3:
cmp [ebx+00000480],000003E8
//Alt: db 81 BB 80 04 00 00 E8 03 00 00 |
_________________
... |
|
Back to top |
|
|
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Sun Feb 19, 2017 7:03 pm Post subject: |
|
|
Try pushad/popad and repeatedly pressing V key.
Code: | newmem:
pushad
push 56
call GetAsyncKeyState
cmp ax,1
popad
jne originalcode
mov [ebx+480],#500
cmp [ebx+00000480],000003E8
jmp exit |
By the way, I do not prefer doing it this way. I prefer to use the game code, or to set up a trigger. For example:
Code: | [ENABLE]
alloc(newmem,2048)
label(returnhere)
label(originalcode)
label(key)
registersymbol(key)
newmem:
cmp byte ptr [key],1
je @f
jmp originalcode
@@:
mov byte ptr [key],0
add [ebx+480],#20
originalcode:
cmp [ebx+00000480],000003E8
jmp returnhere
key:
db 0
"Tutorial-i386.exe"+23CC3:
jmp newmem
nop
nop
nop
nop
nop
returnhere:
[DISABLE]
dealloc(newmem)
"Tutorial-i386.exe"+23CC3:
cmp [ebx+00000480],000003E8
//Alt: db 81 BB 80 04 00 00 E8 03 00 00
unregistersymbol(key) |
Then, just add the custom address to your table after activation, and put key in the address field. Set the data type to byte and then assign whatever hotkey that you want for your boolean (value of 1, for your compare).
|
|
Back to top |
|
|
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Mon Feb 20, 2017 5:45 am Post subject: |
|
|
++METHOS Using any CE Hotkey is not my goal, if it were I would not have created this topic.
SunBeam You seem to watch me, you know better than I which topics I visited.[/b]
_________________
... |
|
Back to top |
|
|
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Mon Feb 20, 2017 9:32 am Post subject: |
|
|
Filipe_Br wrote: | ++METHOS Using any CE Hotkey is not my goal, if it were I would not have created this topic. | -Sigh. I cannot force understanding, unfortunately.
If you are not satisfied with the methods that I have outlined in my previous post, then refer to my original post and provide more details regarding what you 'require':
++METHOS wrote: | This can be achieved a few different ways. Depending on whether or not the target process is 32-bit or 64-bit, whether you want to incorporate Lua, use strictly ASM and/or if you want to use the target's own code etc.. |
Based on your original post, I gave you what you were asking for (you are welcome, by the way). However, since you have quickly discovered that this is sometimes not an ideal solution, I provided you with a better alternative.
|
|
Back to top |
|
|
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Mon Feb 20, 2017 10:56 am Post subject: |
|
|
++METHOS No need to stress. I just wanted to show that: Even though using CE hotkeys is more efficient, my goal is to do this in assembly.
That's because I wanted a script that did not need the CE open to work.
_________________
... |
|
Back to top |
|
|
SunBeam I post too much Reputation: 65
Joined: 25 Feb 2005 Posts: 4022 Location: Romania
|
Posted: Mon Feb 20, 2017 11:05 am Post subject: |
|
|
@Felipe_Br: I'm hacking two games at the moment. One's almost done, Sniper Elite 4, the other on-going: theHunter - Call of the Wild. I wish you were that important to be supervised No, I don't watch any threads you read, I simply assumed you're on to something like this, as most posts of yours I've read were aimed at hotkey-ing some code you have, creating a trainer without CE, etc.
The code METHOS posted works in ASM without the need for CE. It's only a matter of how you code your tool: .exe or .dll, OpenProcess or injection. The ASM-compiled code should work just fine.
What you'd actually want is a trainer template, but are too shy to ask for. Besides, the internet is full of them. Here, have a read: http://df2anarchy.free.fr/htana/traitool/tut8.html and second post from this thread.
Peace,
Sun
|
|
Back to top |
|
|
++METHOS I post too much Reputation: 92
Joined: 29 Oct 2010 Posts: 4197
|
Posted: Mon Feb 20, 2017 11:26 am Post subject: |
|
|
Filipe_Br wrote: | I just wanted to show that: Even though using CE hotkeys is more efficient, my goal is to do this in assembly.
That's because I wanted a script that did not need the CE open to work. | -The method that I have posted can be used independent of CE. If you do not want to rely on calls, then you can try using the target's own code to produce what you need. You can search for mouse clicks, key presses and even controller buttons, just as you would any other, in-game values. Once you find the instruction(s) that are handling said values, simply write a script to isolate the address/value that you need, and merge the script with whatever you are working on and perform your check there.
Also, I am not stressed. I am annoyed.
|
|
Back to top |
|
|
Filipe_Br Master Cheater Reputation: 3
Joined: 07 Jan 2016 Posts: 272 Location: My house
|
Posted: Mon Feb 20, 2017 2:56 pm Post subject: |
|
|
Interesting now you read minds.
_________________
... |
|
Back to top |
|
|
SunBeam I post too much Reputation: 65
Joined: 25 Feb 2005 Posts: 4022 Location: Romania
|
Posted: Mon Feb 20, 2017 4:54 pm Post subject: |
|
|
And this is where I stop replying to your threads; as I said, not that important.
|
|
Back to top |
|
|
STN I post too much Reputation: 42
Joined: 09 Nov 2005 Posts: 2672
|
Posted: Tue Feb 21, 2017 5:10 am Post subject: |
|
|
Filipe_Br Methos code is fine, are you sure the code is even executed? Also how quickly is it executing? That matters a lot.
Also instead of criticizing people helping you, why not show some appreciation.
_________________
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4299
|
Posted: Tue Feb 21, 2017 8:53 am Post subject: |
|
|
I suppose I need to be more explicit. If the goal is to conditionally execute code contingent on the state of the key at the time the script is run, ++METHOS's code is not going to work as intended.
Comparing the return value of GetAsyncKeyState with 1 will set the ZF only if the least significant bit of the result is set. This has two implications: the key is not down during the call, and the key was pressed between the previous invocation of GetAsyncKeyState and the current invocation (this shouldn't be relied on; see MSDN for info). Therefore, the relevant code will never run if the key is pressed, and it isn't guaranteed to run even if you press it between invocations.
SunBeam's method of checking if any bits are set should work perfectly fine.
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
|