[saco] Implement key stuff functions

This commit is contained in:
RD42 2023-10-31 21:15:51 +08:00
parent e7bebd1b9f
commit 49b2219015
5 changed files with 162 additions and 0 deletions

4
saco/game/address.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
#define ADDR_KEYSTATES 0xB73458

6
saco/game/common.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
#define PLAYER_PED_SLOTS 210

118
saco/game/keystuff.cpp Normal file
View File

@ -0,0 +1,118 @@
#include <stdio.h>
#include <windows.h>
#include "common.h"
#include "keystuff.h"
#include "address.h"
//-----------------------------------------------------------
GTA_CONTROLSET *pGcsInternalKeys = (GTA_CONTROLSET *)ADDR_KEYSTATES;
GTA_CONTROLSET GcsLocalPlayerKeys;
GTA_CONTROLSET GcsRemotePlayerKeys[PLAYER_PED_SLOTS];
BYTE byteSaveDriveByLeft;
BYTE byteSaveDriveByRight;
BYTE *pbyteDriveByLeft = (BYTE *)0xB6F1A4;
BYTE *pbyteDriveByRight = (BYTE *)0xB6F1A5;
//-----------------------------------------------------------
void GameKeyStatesInit()
{
int x=0;
memset(&GcsLocalPlayerKeys,0,sizeof(GTA_CONTROLSET));
while(x!=PLAYER_PED_SLOTS) {
memset(&GcsRemotePlayerKeys[x],0,sizeof(GTA_CONTROLSET));
x++;
}
}
//-----------------------------------------------------------
void GameStoreLocalPlayerKeys()
{
memcpy(&GcsLocalPlayerKeys,pGcsInternalKeys,sizeof(GTA_CONTROLSET));
// save current driveby state
byteSaveDriveByLeft = *pbyteDriveByLeft;
byteSaveDriveByRight = *pbyteDriveByRight;
}
//-----------------------------------------------------------
void GameSetLocalPlayerKeys()
{
memcpy(pGcsInternalKeys,&GcsLocalPlayerKeys,sizeof(GTA_CONTROLSET));
// restore the driveby state also
*pbyteDriveByLeft = byteSaveDriveByLeft;
*pbyteDriveByRight = byteSaveDriveByRight;
}
//-----------------------------------------------------------
void GameStoreRemotePlayerKeys(int iPlayer, GTA_CONTROLSET * pGcsKeyStates)
{
memcpy(&GcsRemotePlayerKeys[iPlayer],pGcsKeyStates,sizeof(GTA_CONTROLSET));
}
//-----------------------------------------------------------
void GameSetRemotePlayerKeys(int iPlayer)
{
// Use this to sync between player and remote player.
//memcpy(&GcsRemotePlayerKeys[iPlayer],&GcsLocalPlayerKeys,96);
memcpy(pGcsInternalKeys,&GcsRemotePlayerKeys[iPlayer],sizeof(GTA_CONTROLSET));
if(GcsRemotePlayerKeys[iPlayer].wKeys1[5]) { // lookl
*pbyteDriveByLeft = 1;
} else {
*pbyteDriveByLeft = 0;
}
if(GcsRemotePlayerKeys[iPlayer].wKeys1[7]) { // lookr
*pbyteDriveByRight = 1;
} else {
*pbyteDriveByRight = 0;
}
}
//-----------------------------------------------------------
GTA_CONTROLSET * GameGetInternalKeys()
{
return pGcsInternalKeys;
}
//-----------------------------------------------------------
GTA_CONTROLSET * GameGetLocalPlayerKeys()
{
return &GcsLocalPlayerKeys;
}
//-----------------------------------------------------------
GTA_CONTROLSET * GameGetPlayerKeys(int iPlayer)
{
return &GcsRemotePlayerKeys[iPlayer];
}
//-----------------------------------------------------------
void GameResetPlayerKeys(int iPlayer)
{
memset(&GcsRemotePlayerKeys[iPlayer],0,sizeof(GTA_CONTROLSET));
}
//-----------------------------------------------------------
void GameResetInternalKeys()
{
GTA_CONTROLSET *pInternals = GameGetInternalKeys();
memset((PVOID)pInternals,0,48 * sizeof(WORD));
}
//-----------------------------------------------------------

22
saco/game/keystuff.h Normal file
View File

@ -0,0 +1,22 @@
typedef struct _GTA_CONTROLSET
{
WORD wKeys1[24];
WORD wKeys2[24];
BYTE bytePadding1[212];
} GTA_CONTROLSET;
//-----------------------------------------------------------
void GameKeyStatesInit();
void GameStoreLocalPlayerKeys();
void GameSetLocalPlayerKeys();
void GameStoreRemotePlayerKeys(int iPlayer, GTA_CONTROLSET *pGcsKeyStates);
void GameSetRemotePlayerKeys(int iPlayer);
GTA_CONTROLSET *GameGetInternalKeys();
GTA_CONTROLSET *GameGetLocalPlayerKeys();
GTA_CONTROLSET *GameGetPlayerKeys(int iPlayer);
void GameResetPlayerKeys(int iPlayer);
void GameResetInternalKeys();
//-----------------------------------------------------------

View File

@ -113,6 +113,9 @@
<Filter
Name="game"
Filter="">
<File
RelativePath=".\game\address.h">
</File>
<File
RelativePath=".\game\audio.cpp">
</File>
@ -125,12 +128,21 @@
<File
RelativePath=".\game\camera.h">
</File>
<File
RelativePath=".\game\common.h">
</File>
<File
RelativePath=".\game\game.cpp">
</File>
<File
RelativePath=".\game\game.h">
</File>
<File
RelativePath=".\game\keystuff.cpp">
</File>
<File
RelativePath=".\game\keystuff.h">
</File>
</Filter>
<File
RelativePath=".\exceptbox.rc">