daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Thu Apr 04, 2019 9:58 am Post subject: Check/Toggle hotkey script |
|
|
32 Bit version (64 should be easy to done).
Code: | call _GetAsyncKeyState(VK) |
with a given virtual key, sets eax to 0 or 1 (where 1 is pressed);
Code: | call _ToggleHotkey(VK,VaribleADDR) |
with given virtualkey and some address to change state (0 to 1 or 1 to 0);
It saves last call status in _GetAsyncKeyStack
I use this for either applying actions when key is down (_GetAsyncKeyState),
or to apply everytime key state has changed.
Don't forget to backup registers and flags (pushfd pushad, popad popfd)
Code: | globalalloc(_GetAsyncKeyStack,255) // hotkey toggle memory stack (Up and down states)
label(_GetAsyncKeyState)
label(_ToggleHotkey)
_GetAsyncKeyState:
push ebp
mov ebp,esp // stack
push ecx
push [ebp+8]
call GetAsyncKeyState
test eax,eax
je @F
mov eax,1 //Force it to 1, as we only care if it's pressed or not
@@: // clean up registers
pop ecx
pop ebp
ret 4 // returns eax == 1 or eax == 0
_ToggleHotkey:
push ebp
mov ebp,esp // stack
push ebx
push edx
mov ebx,[ebp+8]
push ebx
//push [ebp+8]
call _GetAsyncKeyState
mov dl,byte ptr [_GetAsyncKeyStack+ebx] // last tick state
cmp al,dl // compare new state versus old state
je @F // state has not changed so exit
mov byte [_GetAsyncKeyStack+ebx],al // save new state (as it has changed)
test al,al // test if key is 0
je @F // exit if 0
mov ebx,1
mov edx,[ebp+c]
sub ebx,[edx] // quick status swap... variable = 0 -> 1 - 0 = 1 | variable = 1 -> 1-1 = 0
mov [edx],ebx
@@:
pop edx
pop ebx
pop ebp
ret 8 |
some example of using
Code: | (...)
globalalloc(hook,512)
label(hookHeader)
label(active)
label(UselessCounter)
label(MoreHotkeysFunction)
label(originalcode)
label(CleanExit)
label(returnToCode)
(...)
hook:
//jmp backupRegisters
hookHeader:
push active // push pointer to globalVar
push 60 // Decimal -> 96 VK_NUMPAD0
call _ToggleHotkey
// call _GetAsyncKeyState
// test eax,eax // check if mouse down -> eax == result, if eax == 0 quit
cmp [active],0
je @F
mov [ecx+50],999 // upon pressing once VK_NUMPAD0
//call MoreHotkeysFunction
@@:
jmp CleanExit
MoreHotkeysFunction:
push activeLootVac
push 64
call _ToggleHotkey
// toggle Enemies vac
push activeEnemiesVac
push 65
call _ToggleHotkey
// toggle projectile vac
push activeProjectileVac
push 66
call _ToggleHotkey
push 66 // VK_NUMPAD6
call _GetAsyncKeyState
test eax,eax
je @F // key state is not pressed
mov eax,[UselessCounter] // key is pressed so as long as it pressed inc useless counter
inc eax
mov [UselessCounter],eax
}
@@:
ret
CleanExit:
//jmp restoreRegisters
originalcode:
mov eax,[ecx+50]
jmp returnToCode
active:
dd 0
UselessCounter:
dd 0
"game.exe"+A2BE7E: // should be frequent called function, otherwise you will have to time your key press according to game events
jmp hook
nop
nop
nop
returnToCode:
|
_________________
I'm rusty and getting older, help me re-learn lua. |
|