[saco] Implemen/match CPlayerPed::SetKey(...)

This commit is contained in:
RD42 2024-10-15 16:57:03 +08:00
parent f6f40b4309
commit 1339b0159c
2 changed files with 234 additions and 0 deletions

View File

@ -78,6 +78,239 @@ void CPlayerPed::SetInitialState()
//-----------------------------------------------------------
void CPlayerPed::SetKeys(WORD wKeys, WORD lrAnalog, WORD udAnalog)
{
GTA_CONTROLSET *pPlayerKeys = GameGetPlayerKeys(m_bytePlayerNumber);
// LEFT/RIGHT
if(pPlayerKeys->wKeys1[0] && lrAnalog) {
pPlayerKeys->wKeys1[0] = lrAnalog;
pPlayerKeys->wKeys2[0] = lrAnalog;
}
else if(lrAnalog && !pPlayerKeys->wKeys1[0]) {
pPlayerKeys->wKeys1[0] = lrAnalog;
pPlayerKeys->wKeys2[0] = 0;
}
else if(!lrAnalog) {
pPlayerKeys->wKeys1[0] = 0;
pPlayerKeys->wKeys2[0] = 0;
}
// UP/DOWN
if(pPlayerKeys->wKeys1[1] && udAnalog) {
pPlayerKeys->wKeys1[1] = udAnalog;
pPlayerKeys->wKeys2[1] = udAnalog;
}
else if(udAnalog && !pPlayerKeys->wKeys1[1]) {
pPlayerKeys->wKeys1[1] = udAnalog;
pPlayerKeys->wKeys2[1] = 0;
}
else if(!udAnalog) {
pPlayerKeys->wKeys1[1] = 0;
pPlayerKeys->wKeys2[1] = 0;
}
// SECONDARY FIRE (4)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[4]) {
pPlayerKeys->wKeys1[4] = 0xFF;
pPlayerKeys->wKeys2[4] = 0xFF;
} else {
pPlayerKeys->wKeys1[4] = 0xFF;
pPlayerKeys->wKeys2[4] = 0x00;
}
} else {
pPlayerKeys->wKeys1[4] = 0x00;
pPlayerKeys->wKeys2[4] = 0x00;
}
wKeys >>= 1; // 1
// CROUCHING TOGGLE (18)
if(IsInVehicle() && wKeys & 1) {
if(pPlayerKeys->wKeys1[18]) {
pPlayerKeys->wKeys1[18] = 0xFF;
pPlayerKeys->wKeys2[18] = 0xFF;
} else {
pPlayerKeys->wKeys1[18] = 0xFF;
pPlayerKeys->wKeys2[18] = 0x00;
}
} else {
pPlayerKeys->wKeys1[18] = 0x00;
pPlayerKeys->wKeys2[18] = 0x00;
}
wKeys >>= 1; // 2
// FIRING (17)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[17]) {
pPlayerKeys->wKeys1[17] = 0xFF;
pPlayerKeys->wKeys2[17] = 0xFF;
} else {
pPlayerKeys->wKeys1[17] = 0xFF;
pPlayerKeys->wKeys2[17] = 0x00;
}
} else {
pPlayerKeys->wKeys1[17] = 0x00;
pPlayerKeys->wKeys2[17] = 0x00;
}
wKeys >>= 1; // 3
// SPRINT (16)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[16]) {
pPlayerKeys->wKeys1[16] = 0xFF;
pPlayerKeys->wKeys2[16] = 0xFF;
} else {
pPlayerKeys->wKeys1[16] = 0xFF;
pPlayerKeys->wKeys2[16] = 0x00;
}
} else {
pPlayerKeys->wKeys1[16] = 0x00;
pPlayerKeys->wKeys2[16] = 0x00;
}
wKeys >>= 1; // 4
// SECONDARY ONFOOT ATTACK (15)
if( (wKeys & 1) && !IsInJetpackMode() ) {
if(pPlayerKeys->wKeys1[15]) {
pPlayerKeys->wKeys1[15] = 0xFF;
pPlayerKeys->wKeys2[15] = 0xFF;
} else {
pPlayerKeys->wKeys1[15] = 0xFF;
pPlayerKeys->wKeys2[15] = 0x00;
}
} else {
pPlayerKeys->wKeys1[15] = 0x00;
pPlayerKeys->wKeys2[15] = 0x00;
}
wKeys >>= 1; // 5
// JUMP (14)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[14]) {
pPlayerKeys->wKeys1[14] = 0xFF;
pPlayerKeys->wKeys2[14] = 0xFF;
} else {
pPlayerKeys->wKeys1[14] = 0xFF;
pPlayerKeys->wKeys2[14] = 0x00;
}
} else {
pPlayerKeys->wKeys1[14] = 0x00;
pPlayerKeys->wKeys2[14] = 0x00;
}
wKeys >>= 1; // 6
// INCAR LOOK RIGHT (7)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[7]) {
pPlayerKeys->wKeys1[7] = 0xFF;
pPlayerKeys->wKeys2[7] = 0xFF;
} else {
pPlayerKeys->wKeys1[7] = 0xFF;
pPlayerKeys->wKeys2[7] = 0x00;
}
} else {
pPlayerKeys->wKeys1[7] = 0x00;
pPlayerKeys->wKeys2[7] = 0x00;
}
wKeys >>= 1; // 7
// INCAR HANDBRAKE / ONFOOT TARGET (6)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[6]) {
pPlayerKeys->wKeys1[6] = 0xFF;
pPlayerKeys->wKeys2[6] = 0xFF;
} else {
pPlayerKeys->wKeys1[6] = 0xFF;
pPlayerKeys->wKeys2[6] = 0x00;
}
} else {
pPlayerKeys->wKeys1[6] = 0x00;
pPlayerKeys->wKeys2[6] = 0x00;
}
wKeys >>= 1; // 8
// INCAR LOOK LEFT (5)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[5]) {
pPlayerKeys->wKeys1[5] = 0xFF;
pPlayerKeys->wKeys2[5] = 0xFF;
} else {
pPlayerKeys->wKeys1[5] = 0xFF;
pPlayerKeys->wKeys2[5] = 0x00;
}
} else {
pPlayerKeys->wKeys1[5] = 0x00;
pPlayerKeys->wKeys2[5] = 0x00;
}
wKeys >>= 1; // 9
// SUBMISSION (19)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[19] == 0xFF) {
pPlayerKeys->wKeys1[19] = 0xFF;
pPlayerKeys->wKeys2[19] = 0xFF;
} else {
pPlayerKeys->wKeys1[19] = 0xFF;
pPlayerKeys->wKeys2[19] = 0x00;
}
} else {
pPlayerKeys->wKeys1[19] = 0x00;
pPlayerKeys->wKeys2[19] = 0x00;
}
wKeys >>= 1; // 10
// WALKING (21)
if(wKeys & 1) {
if(pPlayerKeys->wKeys1[21] == 0xFF) {
pPlayerKeys->wKeys1[21] = 0xFF;
pPlayerKeys->wKeys2[21] = 0xFF;
} else {
pPlayerKeys->wKeys1[21] = 0xFF;
pPlayerKeys->wKeys2[21] = 0x00;
}
} else {
pPlayerKeys->wKeys1[21] = 0x00;
pPlayerKeys->wKeys2[21] = 0x00;
}
wKeys >>= 1; // 11
// ANALOG2 D/U
BYTE byteVal = wKeys & 3;
if(byteVal==2) {
pPlayerKeys->wKeys1[3] = (WORD)(128);
pPlayerKeys->wKeys2[3] = (WORD)(128);
} else if(byteVal==1) {
pPlayerKeys->wKeys1[3] = (WORD)(-128);
pPlayerKeys->wKeys2[3] = (WORD)(-128);
} else {
pPlayerKeys->wKeys1[3] = 0;
pPlayerKeys->wKeys2[3] = 0;
}
wKeys >>= 2; // 12-13
// ANALOG2 L/R
byteVal = wKeys & 3;
if(byteVal==2) {
pPlayerKeys->wKeys1[2] = (WORD)(128);
pPlayerKeys->wKeys2[2] = (WORD)(128);
} else if(byteVal==1) {
pPlayerKeys->wKeys1[2] = (WORD)(-128);
pPlayerKeys->wKeys2[2] = (WORD)(-128);
} else {
pPlayerKeys->wKeys1[2] = 0;
pPlayerKeys->wKeys2[2] = 0;
}
// 14-15
GameStoreRemotePlayerKeys(m_bytePlayerNumber,pPlayerKeys);
}
//-----------------------------------------------------------
WORD CPlayerPed::GetKeys(WORD * lrAnalog, WORD * udAnalog)
{
WORD wRet=0;

View File

@ -19,6 +19,7 @@ public:
void ResetPointers();
void SetInitialState();
void SetKeys(WORD wKeys, WORD lrAnalog, WORD udAnalog);
WORD GetKeys(WORD * lrAnalog, WORD * udAnalog);
BYTE GetSpecialKey();