[C++] SetGameKeyState

dphome

Well-known member
Joined
Mar 21, 2020
Messages
458
Solutions
9
Reaction score
166
Location
Poland
ver 1 (sa_masterPL)
Code:
#define GTA_KEYS    0xB73458
DWORD SGKS;
void SetGameKeyState(BYTE key, BYTE state)
{
    SGKS = GTA_KEYS + key;
    memset((void*)SGKS, state, 1);
};

ver 2 (0x_)
Code:
void SetGameKeyState(BYTE key, BYTE state)
{
    memset(reinterpret_cast<void*>(0xB73458 + key), state, 1);
}

ver 3 (0x_)
Code:
void SetGameKeyState(BYTE key, BYTE state)
{
    *(uint8_t*)(0xB73458 + key) = state;
}
ver 4 (DarkP1xel)
Code:
void __cdecl SetGameKeyState(const unsigned __int8 i8Key, const __int16 i16State)
{
    *reinterpret_cast<__int16 *>(0xB73458 + i8Key) = i16State;
    return;
}

usage:
Code:
SetGameKeyState(0x20, 0);
SetGameKeyState(0x20, 255);
 
Last edited:

0x_

Wtf I'm not new....
Staff member
Administrator
Joined
Feb 18, 2013
Messages
1,123
Reaction score
174
Nice that you post some snippets but there are some things that don't make sense:
  1. GTA_KEYS is a m0d_sa macro use the address so it works w/o s0b or add the macro above.
  2. "SGKS" doesn't have to be a global or even a local
  3. You shouldn't really require a memset call for that.
two possible variants for you:
C++:
void SetGameKeyState(BYTE key, BYTE state)
{
    memset(reinterpret_cast<void*>(0xB73458 + key), state, 1);
}

// or without memset
void SetGameKeyState(BYTE key, BYTE state)
{
    *(uint8_t*)(0xB73458 + key) = state;
}
 
Top