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 


HELP Assembly Hotkey
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sun Feb 19, 2017 5:05 pm    Post subject: HELP Assembly Hotkey Reply with quote

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
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Sun Feb 19, 2017 6:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
SunBeam
I post too much
Reputation: 65

Joined: 25 Feb 2005
Posts: 4022
Location: Romania

PostPosted: Sun Feb 19, 2017 6:40 pm    Post subject: Reply with quote

@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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Sun Feb 19, 2017 6:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Sun Feb 19, 2017 6:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Sun Feb 19, 2017 7:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Mon Feb 20, 2017 5:45 am    Post subject: Reply with quote

++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
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Feb 20, 2017 9:32 am    Post subject: Reply with quote

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
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Mon Feb 20, 2017 10:56 am    Post subject: Reply with quote

++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
View user's profile Send private message
SunBeam
I post too much
Reputation: 65

Joined: 25 Feb 2005
Posts: 4022
Location: Romania

PostPosted: Mon Feb 20, 2017 11:05 am    Post subject: Reply with quote

@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 Smile 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
View user's profile Send private message
++METHOS
I post too much
Reputation: 92

Joined: 29 Oct 2010
Posts: 4197

PostPosted: Mon Feb 20, 2017 11:26 am    Post subject: Reply with quote

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. Very Happy
Back to top
View user's profile Send private message
Filipe_Br
Master Cheater
Reputation: 3

Joined: 07 Jan 2016
Posts: 272
Location: My house

PostPosted: Mon Feb 20, 2017 2:56 pm    Post subject: Reply with quote

SunBeam wrote:


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

Interesting now you read minds.

_________________
...
Back to top
View user's profile Send private message
SunBeam
I post too much
Reputation: 65

Joined: 25 Feb 2005
Posts: 4022
Location: Romania

PostPosted: Mon Feb 20, 2017 4:54 pm    Post subject: Reply with quote

And this is where I stop replying to your threads; as I said, not that important.
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 42

Joined: 09 Nov 2005
Posts: 2672

PostPosted: Tue Feb 21, 2017 5:10 am    Post subject: Reply with quote

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.

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Tue Feb 21, 2017 8:53 am    Post subject: Reply with quote

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
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
Goto page 1, 2  Next
Page 1 of 2

 
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