Expand CInput class and add VerifyUserCmd to CUserCmd.

Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
aixxe 2016-12-20 13:17:49 +00:00
parent 3b12e00ad1
commit 13f8d44aa7
3 changed files with 129 additions and 2 deletions

View File

@ -1,10 +1,111 @@
#pragma once #pragma once
#define MAX_SPLITSCREEN_PLAYERS 1
enum MouseParams: int {
MOUSE_ACCEL_THRESHHOLD1 = 0,
MOUSE_ACCEL_THRESHHOLD2,
MOUSE_SPEED_FACTOR,
NUM_MOUSE_PARAMS
};
enum JoystickAxis_t {
JOY_AXIS_X = 0,
JOY_AXIS_Y,
JOY_AXIS_Z,
JOY_AXIS_R,
JOY_AXIS_U,
JOY_AXIS_V,
MAX_JOYSTICK_AXES,
};
typedef struct {
unsigned int AxisFlags;
unsigned int AxisMap;
unsigned int ControlMap;
} joy_axis_t;
struct Split_t {
int m_nDown[2];
int m_nState;
};
struct kbutton_t {
Split_t m_PerUser[MAX_SPLITSCREEN_PLAYERS];
};
class CKeyboardKey {
public:
char m_szName[32];
kbutton_t* m_pKey;
CKeyboardKey* m_pNext;
};
class CUserCmd; class CUserCmd;
class CVerifiedUserCmd;
class CInput { class CInput {
private:
virtual ~CInput(void) {};
public: public:
CUserCmd* GetUserCmd(int index) { bool m_fMouseInitialized;
return GetVirtualFunction<CUserCmd*(*)(CInput*, int)>(this, 8)(this, index); bool m_fMouseActive;
bool m_fJoystickAdvancedInit;
bool m_fHadJoysticks;
float m_flAccumulatedMouseXMovement;
float m_flAccumulatedMouseYMovement;
float m_flPreviousMouseXPosition;
float m_flPreviousMouseYPosition;
float m_flRemainingJoystickSampleTime;
float m_flKeyboardSampleTime;
bool m_fRestoreSPI;
int m_rgOrigMouseParms[NUM_MOUSE_PARAMS];
int m_rgNewMouseParms[NUM_MOUSE_PARAMS];
bool m_rgCheckMouseParam[NUM_MOUSE_PARAMS];
bool m_fMouseParmsValid;
joy_axis_t m_rgAxes[MAX_JOYSTICK_AXES];
CKeyboardKey* m_pKeys;
bool m_fCameraInterceptingMouse;
bool m_fCameraInThirdPerson;
bool m_fCameraMovingWithMouse;
bool m_fCameraDistanceMove;
int m_nCameraOldX;
int m_nCameraOldY;
int m_nCameraX;
int m_nCameraY;
bool m_CameraIsOrthographic;
QAngle m_angPreviousViewAngles;
float m_flLastForwardMove;
float m_flPreviousJoystickForward;
float m_flPreviousJoystickSide;
float m_flPreviousJoystickPitch;
float m_flPreviousJoystickYaw;
CUserCmd* m_pCommands;
CVerifiedUserCmd* m_pVerifiedCommands;
inline CUserCmd* GetUserCmd(int sequence) {
return &this->m_pCommands[sequence % MULTIPLAYER_BACKUP];
}
inline CVerifiedUserCmd* GetVerifiedUserCmd(int sequence) {
return &this->m_pVerifiedCommands[sequence % MULTIPLAYER_BACKUP];
}
inline void VerifyUserCmd(CUserCmd* cmd, int sequence) {
CVerifiedUserCmd* cmd_verified = this->GetVerifiedUserCmd(sequence);
cmd_verified->m_cmd = *cmd;
cmd_verified->m_crc = cmd->GetChecksum();
} }
}; };

View File

@ -18,6 +18,30 @@ class CUserCmd {
short mousedx; short mousedx;
short mousedy; short mousedy;
bool hasbeenpredicted; bool hasbeenpredicted;
inline CRC32_t GetChecksum() {
CRC32_t crc;
CRC32_Init(&crc);
CRC32_ProcessBuffer(&crc, &this->command_number, sizeof(this->command_number));
CRC32_ProcessBuffer(&crc, &this->tick_count, sizeof(this->tick_count));
CRC32_ProcessBuffer(&crc, &this->viewangles, sizeof(this->viewangles));
CRC32_ProcessBuffer(&crc, &this->forwardmove, sizeof(this->forwardmove));
CRC32_ProcessBuffer(&crc, &this->sidemove, sizeof(this->sidemove));
CRC32_ProcessBuffer(&crc, &this->upmove, sizeof(this->upmove));
CRC32_ProcessBuffer(&crc, &this->buttons, sizeof(this->buttons));
CRC32_ProcessBuffer(&crc, &this->impulse, sizeof(this->impulse));
CRC32_ProcessBuffer(&crc, &this->weaponselect, sizeof(this->weaponselect));
CRC32_ProcessBuffer(&crc, &this->weaponsubtype, sizeof(this->weaponsubtype));
CRC32_ProcessBuffer(&crc, &this->random_seed, sizeof(this->random_seed));
CRC32_ProcessBuffer(&crc, &this->mousedx, sizeof(this->mousedx));
CRC32_ProcessBuffer(&crc, &this->mousedy, sizeof(this->mousedy));
CRC32_Final(&crc);
return crc;
}
}; };
class CVerifiedUserCmd { class CVerifiedUserCmd {

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#define MULTIPLAYER_BACKUP 90
#define SIGNED_GUID_LEN 32 #define SIGNED_GUID_LEN 32
#define MAX_PLAYER_NAME_LENGTH 32 #define MAX_PLAYER_NAME_LENGTH 32