From 1be76bd0c4afb4ecda73b36899ef6b4ee9b5afe3 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 29 Jul 2024 19:22:00 +0200 Subject: [PATCH] InputSystem: add reverse engineered CInput class Reverse engineered classes that will be required to implement per-optic ALC scalars in-game. --- src/game/CMakeLists.txt | 8 +- src/game/client/in_main.cpp | 20 +++++ src/game/client/input.h | 142 +++++++++++++++++++++++++++++++++++ src/game/client/kbutton.h | 37 +++++++++ src/game/shared/pingcmd.h | 49 ++++++++++++ src/game/shared/shareddefs.h | 8 ++ src/game/shared/usercmd.h | 21 ++++-- 7 files changed, 279 insertions(+), 6 deletions(-) create mode 100644 src/game/client/in_main.cpp create mode 100644 src/game/client/kbutton.h create mode 100644 src/game/shared/pingcmd.h diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index b74f82d9..fb1c560c 100644 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -40,9 +40,13 @@ add_sources( SOURCE_GROUP "Collision" add_sources( SOURCE_GROUP "Network" "shared/playernet_vars.h" + "shared/usermessages.h" +) + +add_sources( SOURCE_GROUP "Input" "shared/usercmd.cpp" "shared/usercmd.h" - "shared/usermessages.h" + "shared/pingcmd.h" ) add_sources( SOURCE_GROUP "Utility" @@ -194,8 +198,10 @@ add_sources( SOURCE_GROUP "Player" ) add_sources( SOURCE_GROUP "Input" + "client/in_main.cpp" "client/input.cpp" "client/input.h" + "client/kbutton.h" ) add_sources( SOURCE_GROUP "Rendering" diff --git a/src/game/client/in_main.cpp b/src/game/client/in_main.cpp new file mode 100644 index 00000000..1942a8a3 --- /dev/null +++ b/src/game/client/in_main.cpp @@ -0,0 +1,20 @@ +//========= Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ============// +// +// Purpose: builds an intended movement command to send to the server +// +// $Workfile: $ +// $Date: $ +// $NoKeywords: $ +//=======================================================================================// +#include "kbutton.h" +#include "engine/client/cl_splitscreen.h" + +kbutton_t::Split_t& kbutton_t::GetPerUser( int nSlot /*=-1*/ ) +{ + if ( nSlot == -1 ) + { + ASSERT_LOCAL_PLAYER_RESOLVABLE(); + nSlot = GET_ACTIVE_SPLITSCREEN_SLOT(); + } + return m_PerUser[ nSlot ]; +} diff --git a/src/game/client/input.h b/src/game/client/input.h index e5a1712a..6bb0d281 100644 --- a/src/game/client/input.h +++ b/src/game/client/input.h @@ -1,9 +1,32 @@ #ifndef CLIENT_INPUT_H #define CLIENT_INPUT_H +#include "inputsystem/inputstacksystem.h" + #include "game/shared/weapon_types.h" #include "game/shared/shared_activity.h" +#include "game/shared/ehandle.h" +#include "game/shared/pingcmd.h" +#include "game/shared/usercmd.h" #include "game/client/iinput.h" +#include "kbutton.h" + +FORWARD_DECLARE_HANDLE( InputContextHandle_t ); + +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +class CKeyboardKey +{ +public: + // Name for key + char name[ 32 ]; + // Pointer to the underlying structure + kbutton_t *pkey; + // Next key in key list. + CKeyboardKey *next; +}; + class CInput : public IInput { public: @@ -44,7 +67,126 @@ public: public: // Hook statics static void VSetCustomWeaponActivity( CInput* pInput, sharedactivity_e weaponActivity ); + +protected: + typedef struct + { + unsigned int AxisFlags; + unsigned int AxisMap; + unsigned int ControlMap; + } joy_axis_t; + private: + struct UserInput_t + { + float m_flAccumulatedMouseXMovement; + float m_flAccumulatedMouseYMovement; + float m_flRemainingJoystickSampleTime; + float m_flKeyboardSampleTime; + _BYTE gap10[12]; + float m_flLastSwapSelectTime; + float m_flUnk20; + float m_flUnk24; + float m_flLastButtonPressTime; + + // Joystick Axis data + joy_axis_t m_rgAxes[ MAX_JOYSTICK_AXES ]; + + // Is the 3rd person camera using the mouse? + bool m_fCameraInterceptingMouse; + // Are we in 3rd person view? + bool m_fCameraInThirdPerson; + // Should we move view along with mouse? + bool m_fCameraMovingWithMouse; + // What is the current camera offset from the view origin? + Vector3D m_vecCameraOffset; + // Is the camera in distance moving mode? + bool m_fCameraDistanceMove; + // Old and current mouse position readings. + int m_nCameraOldX; + int m_nCameraOldY; + int m_nCameraX; + int m_nCameraY; + + float unkFloat_B0; + int m_nPreviousCmdButtons; + bool m_unknown_A0; + float m_flUnknownTime_A4; + _BYTE gapB0[8]; + + // User linked button pairs. + LinkedInputPairs_t m_linkedInput; + + QAngle m_angPreviousViewAngles; + QAngle m_angPreviousViewAnglesTilt; + float m_flLastForwardMove; + int m_nClearInputState; + CUserCmdExtended* m_pCommands; + PingCommand_s m_pingCommands[ NUM_PING_COMMANDS ]; + int m_nPrimarySelectedInventorySlot; + int m_nSecondarySelectedInventorySlot_MAYBE; + bool m_bUnknown160; + bool m_bUnknown161; + __int16 m_weaponSelect_Or_weaponMods_see_140701430; + sharedactivity_e m_weaponActivity; + bool m_activatedWeaponIndex; + CameraThirdData_t* m_pCameraThirdData; + int m_nCamCommand; + float m_flPreviousJoystickForwardMove; + float m_flPreviousJoystickSideMove; + float m_flPreviousJoystickYaw; + float m_flPreviousJoystickPitch; + float m_flJoystickDebounceYawAmount; + float m_flJoystickDebouncePitchAmount; + bool m_bJoystickDebounced; + float m_flJoystickDebounceYaw; + float m_flJoystickDebouncePitch; + float m_flSomeInputSampleFrameTime; + _BYTE gap1A0[4]; + + // Set until polled by CreateMove and cleared + CHandle< void* /*C_WeaponX*/ > m_hSelectedWeapon; + bool m_bAutoAim_UnknownBool1AC; + bool m_bAutoAim_UnknownBool1AD; + bool m_bUnknownBool1AE; + bool m_bUnknownBool1AF; + bool m_bAutoAim_UnknownBool1B0; + bool m_bAutoAim_UnknownBool1B1; + bool m_bUnknownBool1B2; + float m_flUnknownFloat1B4; + float m_flUnknownFloat1B8; + Vector3D m_vecUnknown1BC; + QAngle m_angUnknown1C8; + bool m_bUnknown1D4; + bool m_bUnknown1D5; + bool m_bZooming; + _BYTE gap1D7[29]; + float m_flZoomScale; + Vector2D m_vecZoomAnchor; + _BYTE gap200_endsAt_E30[3120]; + }; + + // Has the mouse been initialized? + bool m_fMouseInitialized; + // Is the mosue active? + bool m_fMouseActive; + // Has the joystick advanced initialization been run? + bool m_fJoystickAdvancedInit; + // Between controller and mouse, what's the primary input + bool m_bControllerMode; + + bool m_bUnk1; + bool m_bUnk2; + bool m_bUnk3; + bool m_bUnk4; + + // List of queryable keys + CKeyboardKey* m_pKeys; + + UserInput_t m_User; + + InputContextHandle_t m_hInputContext; + InputContext_t m_hPushedInputContext; }; inline void(*v_CInput__SetCustomWeaponActivity)(CInput* pInput, sharedactivity_e weaponActivity); diff --git a/src/game/client/kbutton.h b/src/game/client/kbutton.h new file mode 100644 index 00000000..63392992 --- /dev/null +++ b/src/game/client/kbutton.h @@ -0,0 +1,37 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// +#if !defined( KBUTTON_H ) +#define KBUTTON_H +#ifdef _WIN32 +#pragma once +#endif + +#include "game/shared/shareddefs.h" + +struct kbutton_t +{ + struct Split_t + { + // key nums holding it down + int down[ 2 ]; + // low bit is down state + int state; + }; + + Split_t &GetPerUser( int nSlot = -1 ); + + Split_t m_PerUser[ MAX_SPLITSCREEN_PLAYERS ]; +}; + +struct LinkedInputPairs_t +{ + int buttonPairs[ 2 ]; + int linkedOutput; +}; + +#endif // KBUTTON_H diff --git a/src/game/shared/pingcmd.h b/src/game/shared/pingcmd.h new file mode 100644 index 00000000..ed6c9959 --- /dev/null +++ b/src/game/shared/pingcmd.h @@ -0,0 +1,49 @@ +//=============================================================================// +// +// Purpose: Player ping input commands +// +//=============================================================================// +#ifndef PINGCMD_H +#define PINGCMD_H + +#include "mathlib/vector.h" +#include "game/shared/ehandle.h" + +enum PingCommandType_e +{ + PING_INVALID = 0, + + PING_QUEUE_TRACE, + PING_EXECUTE_QUEUED, + PING_USE_PROMPT, + PING_ENEMY_SPOTTED, + + // Not a command!!! + LAST_PING_COMMAND = PING_ENEMY_SPOTTED, + NUM_PING_COMMANDS = LAST_PING_COMMAND +}; + +struct PingCommand_s +{ + PingCommand_s() + { + Reset(); + } + + void Reset() + { + commandType = PING_INVALID; + pingType = 0; + entityHandle.Term(); + userTicketId = -1; + pingOrigin.Init(); + } + + PingCommandType_e commandType; + int pingType; + CBaseHandle entityHandle; + int userTicketId; + Vector3D pingOrigin; +}; + +#endif // PINGCMD_H diff --git a/src/game/shared/shareddefs.h b/src/game/shared/shareddefs.h index 45078bbe..b6385db8 100644 --- a/src/game/shared/shareddefs.h +++ b/src/game/shared/shareddefs.h @@ -47,4 +47,12 @@ typedef enum // !TODO[ AMOS ]: Confirm this! USE_TOGGLE = 3 } USE_TYPE; + +#define MAX_SPLITSCREEN_PLAYERS 2 + +inline bool IsSplitScreenSupported() +{ + return (MAX_SPLITSCREEN_PLAYERS > 1) ? true : false; +} + #endif // SHAREDDEFS_H \ No newline at end of file diff --git a/src/game/shared/usercmd.h b/src/game/shared/usercmd.h index e964c45b..b2014c56 100644 --- a/src/game/shared/usercmd.h +++ b/src/game/shared/usercmd.h @@ -13,6 +13,8 @@ #include "tier1/bitbuf.h" #include "mathlib/vector.h" +#include "pingcmd.h" + //------------------------------------------------------------------------------------- // Console variables //------------------------------------------------------------------------------------- @@ -60,31 +62,34 @@ public: byte impulse; byte cycleslot; byte weaponindex; - short weaponselect; + __unaligned __declspec(align(1)) __int16 weaponselect; + bool bUnk39; short weaponactivity; int nUnk3C; bool controllermode; bool fixangles; bool setlastcycleslot; - char pad_0x0034[149]; + char pad_0x0034[5]; + char unkData[144]; // Zipline vars (see [r5apex_ds+8A6573] for read). bool placedZiplineStation; char unk[3]; - int nUnkDC; + float fUnkDC; Vector3D beginStationOrigin; Vector3D stationWorldRelative; float fUnkF8; Vector3D endStationOrigin; QAngle stationWorldAngles; - char pad_0x00114[112]; + PingCommand_s m_pingCommands[NUM_PING_COMMANDS]; int32_t randomseed; byte bUnk188; bool bUnk189; bool normalizepitch; - __int16 nUnk18B; + bool linkedButtonPairPress; + _BYTE gap18C; char pad_0x0188[3]; Vector3D headposition; float_t maxpitch; @@ -102,6 +107,12 @@ public: static_assert(sizeof(CUserCmd) == 0x1DC); +class CUserCmdExtended : public CUserCmd +{ + // todo: reverse engineer. + char unknown_extended[164]; +}; + int ReadUserCmd(bf_read* buf, CUserCmd* move, CUserCmd* from); ///////////////////////////////////////////////////////////////////////////////