{$CLEO}
0000:
repeat
wait 50
until 0AFA: is_samp_available
while true
wait 0
if key_down 48 // key 0 (not numpad)
then
while key_down 48 // necessary because key needs to be unpressed before setting the hook (because callback will ignore "key_up" message and assume it's pressed all the time, resulting in another hook after unhook)
wait 1
end
0AC6: 30@ = label @KeyboardHookCallback offset
call @GetThreadID 0 _threadID 28@
call @SetWindowsHookEx 4 type 2{WH_KEYBOARD - local} /*13{WH_KEYBOARD_LL - global}*/ callback 30@ hinstance 0 thread_id 28@ _returnedHookHandle 31@ // if your game crashes while hooked (using global hook) use ctrl+alt+del
printf "Keyboard input should be ~R~disabled ~W~now" 5000
wait 5000
call @UnhookWindowsHookEx 1 hook_handle 31@
printf "Keyboard input should be ~G~enabled ~W~ again now" 2000
// it just doesn't work for mouse for some reason (it works in .exe version in the same configuration I used for keyboard)
// maybe it's because of the way gta handles mouse input, just a guess (or I messed something up)
//0AC6: 30@ = label @MouseHookCallback offset
//call @SetWindowsHookEx 4 type 14 {WH_MOUSE_LL} callback 30@ _returnedHookHandle 29@
//call @UnhookWindowsHookEx 1 hook_handle 29@
end
end
/*
//call @LockKeyboardAndMouseInput 1 lock_state 1
//call @LockKeyboardAndMouseInput 1 lock_state 0
:LockKeyboardAndMouseInput // works only when ran as administrator in .exe version, maybe that's the reason why it doesn't work in game
0AA2: 31@ = load_library "User32.dll"
if 0AA4: 31@ = get_proc_address "BlockInput" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx
then
0AA7: 31@ push 1 pop 0 bool_fBlockIt 0@ _returned 30@
if 30@ > 0
then
chatmsg "Success" -1
//success
else
chatmsg "Failure" -1
//failure
{"If the function succeeds, the return value is nonzero.
If input is already blocked, the return value is zero. To get extended error information, call GetLastError."}
end
end
0AA3: free_library 31@
ret 0
*/
:SetWindowsHookEx
{
0@ _In_ int idHook (hook type - WH_KEYBOARD_LL which is 13)
1@ _In_ HOOKPROC lpfn (pointer to callback function)
2@ _In_ HINSTANCE hMod (idk, can be 0)
3@ _In_ DWORD dwThreadId (idk, can be 0)
}
0AA2: 31@ = load_library "user32.dll"
if 0AA4: 30@ = get_proc_address "SetWindowsHookExA" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx
then
0AA7: 30@ push 4 pop 0 dwThreadId 3@ hMod 2@ lpfn 1@ idHook 0@ _returned 29@
if 29@ > 0
then
//chatmsg "Hooked successfully" -1
else
chatmsg "Failed to hook" -1
end
else
chatmsg "Failed to find SetWindowsHookEx function" -1
end
0AA3: free_library 31@
ret 1 29@
:UnhookWindowsHookEx
{
0@ - hook handle
}
0AA2: 31@ = load_library "user32.dll"
if 0AA4: 30@ = get_proc_address "UnhookWindowsHookEx" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx
then
0AA7: 30@ push 1 pop 0 idHook 0@ _returned 29@
if 29@ > 0
then
//chatmsg "Unhooked successfully" -1
else
chatmsg "Failed to unhook" -1
end
else
chatmsg "Failed to find UnhookWindowsHookEx function" -1
end
0AA3: free_library 31@
ret 0
:KeyboardHookCallback // just returns 1
hex
B8 01 00 00 00 // mov eax 1
C2 0C 00// ret (?)
end
/*
:MouseHookCallback
hex
B8 01 00 00 00 // mov eax 1
C2 0C 00// ret (?)
end
*/
:GetThreadID // used to make local hook (global hook would not allow you to use keyboard after game crashes or if you forget to unhook it in the code)
0AA2: 31@ = load_library "kernel32.dll"
if 0AA4: 30@ = get_proc_address "GetCurrentThreadId" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx
then
0AA7: 30@ push 0 pop 0 _returnedThreadID 28@
else
chatmsg "Failed to find GetCurrentThreadId function" -1
end
0AA3: free_library 31@
ret 1 28@
monday said:Code:{$CLEO} 0000: repeat wait 50 until 0AFA: is_samp_available while true wait 0 if key_down 48 // key 0 (not numpad) then while key_down 48 // necessary because key needs to be unpressed before setting the hook (because callback will ignore "key_up" message and assume it's pressed all the time, resulting in another hook after unhook) wait 1 end 0AC6: 30@ = label @KeyboardHookCallback offset call @GetThreadID 0 _threadID 28@ call @SetWindowsHookEx 4 type 2{WH_KEYBOARD - local} /*13{WH_KEYBOARD_LL - global}*/ callback 30@ hinstance 0 thread_id 28@ _returnedHookHandle 31@ // if your game crashes while hooked (using global hook) use ctrl+alt+del printf "Keyboard input should be ~R~disabled ~W~now" 5000 wait 5000 call @UnhookWindowsHookEx 1 hook_handle 31@ printf "Keyboard input should be ~G~enabled ~W~ again now" 2000 // it just doesn't work for mouse for some reason (it works in .exe version in the same configuration I used for keyboard) // maybe it's because of the way gta handles mouse input, just a guess (or I messed something up) //0AC6: 30@ = label @MouseHookCallback offset //call @SetWindowsHookEx 4 type 14 {WH_MOUSE_LL} callback 30@ _returnedHookHandle 29@ //call @UnhookWindowsHookEx 1 hook_handle 29@ end end /* //call @LockKeyboardAndMouseInput 1 lock_state 1 //call @LockKeyboardAndMouseInput 1 lock_state 0 :LockKeyboardAndMouseInput // works only when ran as administrator in .exe version, maybe that's the reason why it doesn't work in game 0AA2: 31@ = load_library "User32.dll" if 0AA4: 31@ = get_proc_address "BlockInput" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 31@ push 1 pop 0 bool_fBlockIt 0@ _returned 30@ if 30@ > 0 then chatmsg "Success" -1 //success else chatmsg "Failure" -1 //failure {"If the function succeeds, the return value is nonzero. If input is already blocked, the return value is zero. To get extended error information, call GetLastError."} end end 0AA3: free_library 31@ ret 0 */ :SetWindowsHookEx { 0@ _In_ int idHook (hook type - WH_KEYBOARD_LL which is 13) 1@ _In_ HOOKPROC lpfn (pointer to callback function) 2@ _In_ HINSTANCE hMod (idk, can be 0) 3@ _In_ DWORD dwThreadId (idk, can be 0) } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "SetWindowsHookExA" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 4 pop 0 dwThreadId 3@ hMod 2@ lpfn 1@ idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Hooked successfully" -1 else chatmsg "Failed to hook" -1 end else chatmsg "Failed to find SetWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 1 29@ :UnhookWindowsHookEx { 0@ - hook handle } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "UnhookWindowsHookEx" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 1 pop 0 idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Unhooked successfully" -1 else chatmsg "Failed to unhook" -1 end else chatmsg "Failed to find UnhookWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 0 :KeyboardHookCallback // just returns 1 hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end /* :MouseHookCallback hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end */ :GetThreadID // used to make local hook (global hook would not allow you to use keyboard after game crashes or if you forget to unhook it in the code) 0AA2: 31@ = load_library "kernel32.dll" if 0AA4: 30@ = get_proc_address "GetCurrentThreadId" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 0 pop 0 _returnedThreadID 28@ else chatmsg "Failed to find GetCurrentThreadId function" -1 end 0AA3: free_library 31@ ret 1 28@
I managed to do it for keyboard but not for mouse, idk why it doesn't work for mouse, you could try searching "camera lock" / "set actor lock" opcodes + if cursor is visible then get its position and repetatively set it back to it unless you want to "unfreeze" the mouse
monday said:Code:{$CLEO} 0000: repeat wait 50 until 0AFA: is_samp_available while true wait 0 if key_down 48 // key 0 (not numpad) then while key_down 48 // necessary because key needs to be unpressed before setting the hook (because callback will ignore "key_up" message and assume it's pressed all the time, resulting in another hook after unhook) wait 1 end 0AC6: 30@ = label @KeyboardHookCallback offset call @GetThreadID 0 _threadID 28@ call @SetWindowsHookEx 4 type 2{WH_KEYBOARD - local} /*13{WH_KEYBOARD_LL - global}*/ callback 30@ hinstance 0 thread_id 28@ _returnedHookHandle 31@ // if your game crashes while hooked (using global hook) use ctrl+alt+del printf "Keyboard input should be ~R~disabled ~W~now" 5000 wait 5000 call @UnhookWindowsHookEx 1 hook_handle 31@ printf "Keyboard input should be ~G~enabled ~W~ again now" 2000 // it just doesn't work for mouse for some reason (it works in .exe version in the same configuration I used for keyboard) // maybe it's because of the way gta handles mouse input, just a guess (or I messed something up) //0AC6: 30@ = label @MouseHookCallback offset //call @SetWindowsHookEx 4 type 14 {WH_MOUSE_LL} callback 30@ _returnedHookHandle 29@ //call @UnhookWindowsHookEx 1 hook_handle 29@ end end /* //call @LockKeyboardAndMouseInput 1 lock_state 1 //call @LockKeyboardAndMouseInput 1 lock_state 0 :LockKeyboardAndMouseInput // works only when ran as administrator in .exe version, maybe that's the reason why it doesn't work in game 0AA2: 31@ = load_library "User32.dll" if 0AA4: 31@ = get_proc_address "BlockInput" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 31@ push 1 pop 0 bool_fBlockIt 0@ _returned 30@ if 30@ > 0 then chatmsg "Success" -1 //success else chatmsg "Failure" -1 //failure {"If the function succeeds, the return value is nonzero. If input is already blocked, the return value is zero. To get extended error information, call GetLastError."} end end 0AA3: free_library 31@ ret 0 */ :SetWindowsHookEx { 0@ _In_ int idHook (hook type - WH_KEYBOARD_LL which is 13) 1@ _In_ HOOKPROC lpfn (pointer to callback function) 2@ _In_ HINSTANCE hMod (idk, can be 0) 3@ _In_ DWORD dwThreadId (idk, can be 0) } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "SetWindowsHookExA" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 4 pop 0 dwThreadId 3@ hMod 2@ lpfn 1@ idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Hooked successfully" -1 else chatmsg "Failed to hook" -1 end else chatmsg "Failed to find SetWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 1 29@ :UnhookWindowsHookEx { 0@ - hook handle } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "UnhookWindowsHookEx" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 1 pop 0 idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Unhooked successfully" -1 else chatmsg "Failed to unhook" -1 end else chatmsg "Failed to find UnhookWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 0 :KeyboardHookCallback // just returns 1 hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end /* :MouseHookCallback hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end */ :GetThreadID // used to make local hook (global hook would not allow you to use keyboard after game crashes or if you forget to unhook it in the code) 0AA2: 31@ = load_library "kernel32.dll" if 0AA4: 30@ = get_proc_address "GetCurrentThreadId" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 0 pop 0 _returnedThreadID 28@ else chatmsg "Failed to find GetCurrentThreadId function" -1 end 0AA3: free_library 31@ ret 1 28@
I managed to do it for keyboard but not for mouse, idk why it doesn't work for mouse, you could try searching "camera lock" / "set actor lock" opcodes + if cursor is visible then get its position and repetatively set it back to it unless you want to "unfreeze" the mouse
oh boimonday said:Code:{$CLEO} 0000: repeat wait 50 until 0AFA: is_samp_available while true wait 0 if key_down 48 // key 0 (not numpad) then while key_down 48 // necessary because key needs to be unpressed before setting the hook (because callback will ignore "key_up" message and assume it's pressed all the time, resulting in another hook after unhook) wait 1 end 0AC6: 30@ = label @KeyboardHookCallback offset call @GetThreadID 0 _threadID 28@ call @SetWindowsHookEx 4 type 2{WH_KEYBOARD - local} /*13{WH_KEYBOARD_LL - global}*/ callback 30@ hinstance 0 thread_id 28@ _returnedHookHandle 31@ // if your game crashes while hooked (using global hook) use ctrl+alt+del printf "Keyboard input should be ~R~disabled ~W~now" 5000 wait 5000 call @UnhookWindowsHookEx 1 hook_handle 31@ printf "Keyboard input should be ~G~enabled ~W~ again now" 2000 // it just doesn't work for mouse for some reason (it works in .exe version in the same configuration I used for keyboard) // maybe it's because of the way gta handles mouse input, just a guess (or I messed something up) //0AC6: 30@ = label @MouseHookCallback offset //call @SetWindowsHookEx 4 type 14 {WH_MOUSE_LL} callback 30@ _returnedHookHandle 29@ //call @UnhookWindowsHookEx 1 hook_handle 29@ end end /* //call @LockKeyboardAndMouseInput 1 lock_state 1 //call @LockKeyboardAndMouseInput 1 lock_state 0 :LockKeyboardAndMouseInput // works only when ran as administrator in .exe version, maybe that's the reason why it doesn't work in game 0AA2: 31@ = load_library "User32.dll" if 0AA4: 31@ = get_proc_address "BlockInput" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 31@ push 1 pop 0 bool_fBlockIt 0@ _returned 30@ if 30@ > 0 then chatmsg "Success" -1 //success else chatmsg "Failure" -1 //failure {"If the function succeeds, the return value is nonzero. If input is already blocked, the return value is zero. To get extended error information, call GetLastError."} end end 0AA3: free_library 31@ ret 0 */ :SetWindowsHookEx { 0@ _In_ int idHook (hook type - WH_KEYBOARD_LL which is 13) 1@ _In_ HOOKPROC lpfn (pointer to callback function) 2@ _In_ HINSTANCE hMod (idk, can be 0) 3@ _In_ DWORD dwThreadId (idk, can be 0) } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "SetWindowsHookExA" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 4 pop 0 dwThreadId 3@ hMod 2@ lpfn 1@ idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Hooked successfully" -1 else chatmsg "Failed to hook" -1 end else chatmsg "Failed to find SetWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 1 29@ :UnhookWindowsHookEx { 0@ - hook handle } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "UnhookWindowsHookEx" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 1 pop 0 idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Unhooked successfully" -1 else chatmsg "Failed to unhook" -1 end else chatmsg "Failed to find UnhookWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 0 :KeyboardHookCallback // just returns 1 hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end /* :MouseHookCallback hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end */ :GetThreadID // used to make local hook (global hook would not allow you to use keyboard after game crashes or if you forget to unhook it in the code) 0AA2: 31@ = load_library "kernel32.dll" if 0AA4: 30@ = get_proc_address "GetCurrentThreadId" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 0 pop 0 _returnedThreadID 28@ else chatmsg "Failed to find GetCurrentThreadId function" -1 end 0AA3: free_library 31@ ret 1 28@
I managed to do it for keyboard but not for mouse, idk why it doesn't work for mouse, you could try searching "camera lock" / "set actor lock" opcodes + if cursor is visible then get its position and repetatively set it back to it unless you want to "unfreeze" the mouse
monday said:@springfield
I thought the same but I have no idea how to do it...
@CSprite
It's adapted to cleo from this:
https://www.unknowncheats.me/forum/c-and-c-/83707-setwindowshookex-example.html
that's the method I used: http://ugbase.eu/Thread-Tutorial-Using-functions-from-Windows-libraries
Only the HookCallback function content is replaced with "return 1;"
monday said:Code:{$CLEO} 0000: repeat wait 50 until 0AFA: is_samp_available while true wait 0 if key_down 48 // key 0 (not numpad) then while key_down 48 // necessary because key needs to be unpressed before setting the hook (because callback will ignore "key_up" message and assume it's pressed all the time, resulting in another hook after unhook) wait 1 end 0AC6: 30@ = label @KeyboardHookCallback offset call @GetThreadID 0 _threadID 28@ call @SetWindowsHookEx 4 type 2{WH_KEYBOARD - local} /*13{WH_KEYBOARD_LL - global}*/ callback 30@ hinstance 0 thread_id 28@ _returnedHookHandle 31@ // if your game crashes while hooked (using global hook) use ctrl+alt+del printf "Keyboard input should be ~R~disabled ~W~now" 5000 wait 5000 call @UnhookWindowsHookEx 1 hook_handle 31@ printf "Keyboard input should be ~G~enabled ~W~ again now" 2000 // it just doesn't work for mouse for some reason (it works in .exe version in the same configuration I used for keyboard) // maybe it's because of the way gta handles mouse input, just a guess (or I messed something up) //0AC6: 30@ = label @MouseHookCallback offset //call @SetWindowsHookEx 4 type 14 {WH_MOUSE_LL} callback 30@ _returnedHookHandle 29@ //call @UnhookWindowsHookEx 1 hook_handle 29@ end end /* //call @LockKeyboardAndMouseInput 1 lock_state 1 //call @LockKeyboardAndMouseInput 1 lock_state 0 :LockKeyboardAndMouseInput // works only when ran as administrator in .exe version, maybe that's the reason why it doesn't work in game 0AA2: 31@ = load_library "User32.dll" if 0AA4: 31@ = get_proc_address "BlockInput" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 31@ push 1 pop 0 bool_fBlockIt 0@ _returned 30@ if 30@ > 0 then chatmsg "Success" -1 //success else chatmsg "Failure" -1 //failure {"If the function succeeds, the return value is nonzero. If input is already blocked, the return value is zero. To get extended error information, call GetLastError."} end end 0AA3: free_library 31@ ret 0 */ :SetWindowsHookEx { 0@ _In_ int idHook (hook type - WH_KEYBOARD_LL which is 13) 1@ _In_ HOOKPROC lpfn (pointer to callback function) 2@ _In_ HINSTANCE hMod (idk, can be 0) 3@ _In_ DWORD dwThreadId (idk, can be 0) } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "SetWindowsHookExA" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 4 pop 0 dwThreadId 3@ hMod 2@ lpfn 1@ idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Hooked successfully" -1 else chatmsg "Failed to hook" -1 end else chatmsg "Failed to find SetWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 1 29@ :UnhookWindowsHookEx { 0@ - hook handle } 0AA2: 31@ = load_library "user32.dll" if 0AA4: 30@ = get_proc_address "UnhookWindowsHookEx" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 1 pop 0 idHook 0@ _returned 29@ if 29@ > 0 then //chatmsg "Unhooked successfully" -1 else chatmsg "Failed to unhook" -1 end else chatmsg "Failed to find UnhookWindowsHookEx function" -1 end 0AA3: free_library 31@ ret 0 :KeyboardHookCallback // just returns 1 hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end /* :MouseHookCallback hex B8 01 00 00 00 // mov eax 1 C2 0C 00// ret (?) end */ :GetThreadID // used to make local hook (global hook would not allow you to use keyboard after game crashes or if you forget to unhook it in the code) 0AA2: 31@ = load_library "kernel32.dll" if 0AA4: 30@ = get_proc_address "GetCurrentThreadId" library 31@ //https://msdn.microsoft.com/en-us/library/ms646290%28VS.85%29.aspx then 0AA7: 30@ push 0 pop 0 _returnedThreadID 28@ else chatmsg "Failed to find GetCurrentThreadId function" -1 end 0AA3: free_library 31@ ret 1 28@
I managed to do it for keyboard but not for mouse, idk why it doesn't work for mouse, you could try searching "camera lock" / "set actor lock" opcodes + if cursor is visible then get its position and repetatively set it back to it unless you want to "unfreeze" the mouse