SetGameKeyState

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
I want to translate cleo into C ++

Code:
{$CLEO .cs}
0000: update_script_to_03dl

while true
    wait 0
    if and
        0AB0:   key_pressed 0x02
        0AB0:   key_pressed 0x52
        02D8:   actor $PLAYER_ACTOR current_weapon == 24
    then
        0393: actor $PLAYER_ACTOR perform_animation "PYTHON_FIRE" at 1.337 times_normal_rate
        0AB1: @FAKE_KEYPRESS 2 _OFFSET_KEY_ 0x22 _STATE_ 255{fire}
        wait 55
        0AB1: @FAKE_KEYPRESS 2 _OFFSET_KEY_ 0xC _STATE_ 0{aim}
        0AB1: @FAKE_KEYPRESS 2 _OFFSET_KEY_ 0x24 _STATE_ 255{crouch}
        0393: actor $PLAYER_ACTOR perform_animation "PYTHON_FIRE" at 1.0 times_normal_rate
    end
end

:FAKE_KEYPRESS
2@ = 0xB73458
005A: 2@ += 0@  // (int)
0A8C: write_memory 2@ size 1 value 1@ virtual_protect 0
0AB2: ret 0

C++:
void cbug()
    {
        while (true)
        {
            if (autoCbug)
            {
                if (GetAsyncKeyState(0x52))
                {
                    SetGameKeyState(0x22, 255);
                    Sleep(55);
                    SetGameKeyState(0xC, 0);
                    SetGameKeyState(0x24, 255);
                }
            }
        }
    }

but its didnt work
if i remove Sleep(55); then the C key will not be pressed (0x24), but the rest are pressed normally

C++:
void SetGameKeyState(BYTE key, BYTE state)
    {
        *(uint8_t*)(0xB73458 + key) = state;
    }
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
in the plugin for overwriting key statuses, they need to be rewritten after updating the game, but before application
between CPad::Update and CGame: Process
any thread will execute asynchronously with your hook
you need to hook CPad :: Update and rewrite the status of the keys there, good luck!
 

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
166
Location
Poland
because "sleep" is not alternative for "wait", i also have this problem too and double pressing does not work for me

SetGameKeyState(0x20, 0);
Sleep(10);
SetGameKeyState(0x20, 255);
Sleep(10);
SetGameKeyState(0x20, 0);
Sleep(10);
SetGameKeyState(0x20, 255);

//edit 0x20
 
Last edited:

0x_

Wtf I'm not new....
Administrator
Joined
Feb 18, 2013
Messages
1,118
Reaction score
166
First you shouldn't sleep I bet you're creating another thread to be able to sleep (otherwise the game would hang) GTA:SA is not threadsafe or whatsoever you're not gonna be sychronized w/ the game run your stuff in the game thread and run it there and use GetTickCount or whatsoever.
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
First you shouldn't sleep I bet you're creating another thread to be able to sleep (otherwise the game would hang) GTA:SA is not threadsafe or whatsoever you're not gonna be sychronized w/ the game run your stuff in the game thread and run it there and use GetTickCount or whatsoever.
i hook gameLoop (0x53BEE0),
and added a keystroke there, it doesn’t work.
hook works
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
First you shouldn't sleep I bet you're creating another thread to be able to sleep (otherwise the game would hang) GTA:SA is not threadsafe or whatsoever you're not gonna be sychronized w/ the game run your stuff in the game thread and run it there and use GetTickCount or whatsoever.
give example bro)
 

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
166
Location
Poland
yeah, shit and this is not alternative for sleep.
 

0x_

Wtf I'm not new....
Administrator
Joined
Feb 18, 2013
Messages
1,118
Reaction score
166
Rarely see such unthankful people but I guess that's how it goes, GetTickCount is an actual alternative.
Sleep is blocking the execution GetTickCount isn't, no matter what I am not willing to help anymore if you guys bash input of other people. If the suggestion of other people are shit, then you probably know better. So do better.
 

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
166
Location
Poland
If we have to kneel with every stupid answer, then someone is wrong, oh really sorry.
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
Rarely see such unthankful people but I guess that's how it goes, GetTickCount is an actual alternative.
Sleep is blocking the execution GetTickCount isn't, no matter what I am not willing to help anymore if you guys bash input of other people. If the suggestion of other people are shit, then you probably know better. So do better.
bro I said that I hooked CPad:: UpdatePads and put a click in GetTickCount there, this does not work
the weapon doesn't fire and I just can't punch
 
Last edited:

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
Rarely see such unthankful people but I guess that's how it goes, GetTickCount is an actual alternative.
Sleep is blocking the execution GetTickCount isn't, no matter what I am not willing to help anymore if you guys bash input of other people. If the suggestion of other people are shit, then you probably know better. So do better.
I am not thankless, just the proposed solution is incorrect
FYP told me that pressing buttons should happen AFTER CPad::UpdatePads
 

bladee

Member
Joined
Nov 7, 2017
Messages
19
Reaction score
5
Rarely see such unthankful people but I guess that's how it goes, GetTickCount is an actual alternative.
Sleep is blocking the execution GetTickCount isn't, no matter what I am not willing to help anymore if you guys bash input of other people. If the suggestion of other people are shit, then you probably know better. So do better.
it turns out, you need to hook some other function that runs immediately after UpdatePads
 

SIGKILL

Active member
Joined
Apr 29, 2020
Messages
37
Reaction score
22
Location
Earth
Maybe share which function you need to hook so other people who read this can use that information?
 
Top