From 54f08bd88731a7217e03b56075b0a8290c2380cc Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 19 Jan 2023 15:25:45 +0100 Subject: [PATCH] Work-in-progress user command executor * Added some getters in 'CBaseEntity' and 'CServerNetworkProperty'. * Implemented 'CPlayer::SetTimeBase'. * WIP implementation of 'CPlayer::RunNullCommand'. --- r5dev/game/server/gameinterface.h | 4 ++ r5dev/game/server/networkproperty.cpp | 15 ++++- r5dev/game/server/networkproperty.h | 5 ++ r5dev/game/server/player.cpp | 96 +++++++++++++++++++++++++++ r5dev/game/server/player.h | 41 ++++++++++++ r5dev/game/shared/entitylist_base.cpp | 24 +++++++ r5dev/game/shared/entitylist_base.h | 30 +++++++++ r5dev/game/shared/shareddefs.h | 27 ++++++++ r5dev/public/baseentity.cpp | 39 +++++++++++ r5dev/public/baseentity.h | 9 +++ r5dev/public/const.h | 7 +- r5dev/sdklauncher/basepanel.cpp | 2 +- r5dev/vproj/clientsdk.vcxproj | 3 + r5dev/vproj/clientsdk.vcxproj.filters | 9 +++ r5dev/vproj/dedicated.vcxproj | 5 ++ r5dev/vproj/dedicated.vcxproj.filters | 15 +++++ r5dev/vproj/gamesdk.vcxproj | 5 ++ r5dev/vproj/gamesdk.vcxproj.filters | 15 +++++ 18 files changed, 348 insertions(+), 3 deletions(-) create mode 100644 r5dev/game/server/player.cpp create mode 100644 r5dev/game/shared/entitylist_base.cpp create mode 100644 r5dev/game/shared/entitylist_base.h create mode 100644 r5dev/game/shared/shareddefs.h create mode 100644 r5dev/public/baseentity.cpp diff --git a/r5dev/game/server/gameinterface.h b/r5dev/game/server/gameinterface.h index d9f3fe1a..c6a944c7 100644 --- a/r5dev/game/server/gameinterface.h +++ b/r5dev/game/server/gameinterface.h @@ -4,6 +4,8 @@ // // $NoKeywords: $ //=============================================================================// +#ifndef GAMEINTERFACE_H +#define GAMEINTERFACE_H #include "public/eiface.h" //----------------------------------------------------------------------------- @@ -83,3 +85,5 @@ class VServerGameDLL : public IDetour /////////////////////////////////////////////////////////////////////////////// REGISTER(VServerGameDLL); + +#endif // GAMEINTERFACE_H \ No newline at end of file diff --git a/r5dev/game/server/networkproperty.cpp b/r5dev/game/server/networkproperty.cpp index d551aff2..e5284d57 100644 --- a/r5dev/game/server/networkproperty.cpp +++ b/r5dev/game/server/networkproperty.cpp @@ -1,3 +1,16 @@ +//===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + #include "core/stdafx.h" #include "public/baseentity.h" -#include "public/basehandle.h" \ No newline at end of file +#include "public/basehandle.h" +#include "networkproperty.h" + +edict_t CServerNetworkProperty::GetEdict(void) const +{ + return m_edict; +} diff --git a/r5dev/game/server/networkproperty.h b/r5dev/game/server/networkproperty.h index 26b16d9c..b2db5629 100644 --- a/r5dev/game/server/networkproperty.h +++ b/r5dev/game/server/networkproperty.h @@ -13,9 +13,14 @@ #include "public/iservernetworkable.h" #include "public/server_class.h" +#include "public/edict.h" struct CServerNetworkProperty : IServerNetworkable { +public: + edict_t GetEdict() const; + +private: CBaseEntity* m_pOuter; ServerClass* m_pServerClass; int m_edict; diff --git a/r5dev/game/server/player.cpp b/r5dev/game/server/player.cpp new file mode 100644 index 00000000..dea1cd36 --- /dev/null +++ b/r5dev/game/server/player.cpp @@ -0,0 +1,96 @@ +//======== Copyright (c) Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// +#include "core/stdafx.h" +#include "player.h" +#include "gameinterface.h" +#include "game/shared/shareddefs.h" + +//------------------------------------------------------------------------------ +// Purpose: executes a null command for this player +//------------------------------------------------------------------------------ +void CPlayer::RunNullCommand(void) +{ + float flOldFrameTime = g_pGlobals->m_fFrameTime; + float flOldCurTime = g_pGlobals->m_fCurTime; + + pl.fixangle = FIXANGLE_NONE; + + SetTimeBase(g_pGlobals->m_fCurTime); + + + // !TODO: Run command.. + + g_pGlobals->m_fFrameTime = flOldFrameTime; + g_pGlobals->m_fCurTime = flOldCurTime; +} + +//------------------------------------------------------------------------------ +// Purpose: gets the eye angles of this player +// Input : &angles - +// Output : QAngle* +//------------------------------------------------------------------------------ +QAngle* CPlayer::EyeAngles(QAngle& angles) +{ + return v_CPlayer__EyeAngles(this, &angles); +} + +//------------------------------------------------------------------------------ +// Purpose: sets the time base for this player +// Input : flTimeBase - +//------------------------------------------------------------------------------ +inline void CPlayer::SetTimeBase(float flTimeBase) +{ + float flTime = TIME_TO_TICKS(flTimeBase); + + if (flTime < 0.0f) + flTime = 0.0f; + + SetLastUCmdSimulationRemainderTime(flTime); + + float flSomeTime = flTimeBase - m_lastUCmdSimulationRemainderTime * g_pGlobals->m_nTickInterval; + if (flSomeTime >= 0.0) + { + flTime = flSomeTime; + } + + SetTotalExtraClientCmdTimeAttempted(flTime); +} + +//------------------------------------------------------------------------------ +// Purpose: sets the last user cmd simulation remainder time +// Input : flRemainderTime - +//------------------------------------------------------------------------------ +void CPlayer::SetLastUCmdSimulationRemainderTime(float flRemainderTime) +{ + if (m_lastUCmdSimulationRemainderTime != flRemainderTime) + { + edict_t nEdict = NetworkProp()->GetEdict(); + if (nEdict != FL_EDICT_INVALID) + { + _InterlockedOr16(g_pGlobals->m_pUnk0 + nEdict + 32, 0x200u); + } + + m_totalExtraClientCmdTimeAttempted = flRemainderTime; + } +} + +//------------------------------------------------------------------------------ +// Purpose: sets the total extra client cmd time attempted +// Input : flAttemptedTime - +//------------------------------------------------------------------------------ +void CPlayer::SetTotalExtraClientCmdTimeAttempted(float flAttemptedTime) +{ + if (m_totalExtraClientCmdTimeAttempted != flAttemptedTime) + { + edict_t nEdict = NetworkProp()->GetEdict(); + if (nEdict != FL_EDICT_INVALID) + { + _InterlockedOr16(g_pGlobals->m_pUnk0 + nEdict + 32, 0x200u); + } + + m_totalExtraClientCmdTimeAttempted = flAttemptedTime; + } +} diff --git a/r5dev/game/server/player.h b/r5dev/game/server/player.h index 292ece94..87e26b92 100644 --- a/r5dev/game/server/player.h +++ b/r5dev/game/server/player.h @@ -231,6 +231,15 @@ struct SpeedChangeHistoryEntry class CPlayer : public CBaseCombatCharacter { +public: + void RunNullCommand(void); + QAngle* EyeAngles(QAngle& angles); + + void SetTimeBase(float flTimeBase); + void SetLastUCmdSimulationRemainderTime(float flRemainderTime); + void SetTotalExtraClientCmdTimeAttempted(float flAttemptedTime); + +private: int m_StuckLast; char gap_5a8c[4]; CPlayerLocalData m_Local; @@ -763,4 +772,36 @@ class CPlayer : public CBaseCombatCharacter int m_armsModelIndex; }; +inline CMemory p_CPlayer__EyeAngles; +inline auto v_CPlayer__EyeAngles = p_CPlayer__EyeAngles.RCast(); + +//inline CMemory p_CBaseEntity__GetBaseEntity; +//inline auto v_CBaseEntity__GetBaseEntity = p_CBaseEntity__GetBaseEntity.RCast(); + +/////////////////////////////////////////////////////////////////////////////// +class VPlayer : public IDetour +{ + virtual void GetAdr(void) const + { + spdlog::debug("| FUN: CPlayer::EyeAngles : {:#18x} |\n", p_CPlayer__EyeAngles.GetPtr()); + //spdlog::debug("| FUN: CBaseEntity::GetBaseEntity : {:#18x} |\n", p_CBaseEntity__GetBaseEntity.GetPtr()); + spdlog::debug("+----------------------------------------------------------------+\n"); + } + virtual void GetFun(void) const + { + p_CPlayer__EyeAngles = g_GameDll.FindPatternSIMD("40 53 48 83 EC 30 F2 0F 10 05 ?? ?? ?? ??"); + v_CPlayer__EyeAngles = p_CPlayer__EyeAngles.RCast(); + + //p_CBaseEntity__GetBaseEntity = g_GameDll.FindPatternSIMD("8B 91 ?? ?? ?? ?? 83 FA FF 74 1F 0F B7 C2 48 8D 0D ?? ?? ?? ?? C1 EA 10 48 8D 04 40 48 03 C0 39 54 C1 08 75 05 48 8B 04 C1 C3 33 C0 C3 CC CC CC 48 8B 41 30"); + //v_CBaseEntity__GetBaseEntity = p_CBaseEntity__GetBaseEntity.RCast(); + } + virtual void GetVar(void) const { } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(VPlayer); + #endif // PLAYER_H diff --git a/r5dev/game/shared/entitylist_base.cpp b/r5dev/game/shared/entitylist_base.cpp new file mode 100644 index 00000000..c1c04266 --- /dev/null +++ b/r5dev/game/shared/entitylist_base.cpp @@ -0,0 +1,24 @@ +//====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======// +// +// Purpose: +// +//=============================================================================// + +#include "core/stdafx.h" +#include "entitylist_base.h" +#include "public/ihandleentity.h" + +// memdbgon must be the last include file in a .cpp file!!! +//#include "tier0/memdbgon.h" + +enum +{ + SERIAL_MASK = 0x7fff // the max value of a serial number, rolls back to 0 when it hits this limit +}; + +void CEntInfo::ClearLinks() +{ + m_pPrev = m_pNext = this; +} + +// !TODO: entity list. diff --git a/r5dev/game/shared/entitylist_base.h b/r5dev/game/shared/entitylist_base.h new file mode 100644 index 00000000..12fc7cae --- /dev/null +++ b/r5dev/game/shared/entitylist_base.h @@ -0,0 +1,30 @@ +//====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======// +// +// Purpose: +// +//=============================================================================// + +#ifndef ENTITYLIST_BASE_H +#define ENTITYLIST_BASE_H +#ifdef _WIN32 +#pragma once +#endif +#include "public/ihandleentity.h" + +class CEntInfo +{ +public: + IHandleEntity* m_pEntity; + int m_SerialNumber; + CEntInfo* m_pPrev; + CEntInfo* m_pNext; +#ifdef GAME_DLL + string_t m_iName; + string_t m_iClassName; +#endif + + void ClearLinks(); +}; + + +#endif // ENTITYLIST_BASE_H \ No newline at end of file diff --git a/r5dev/game/shared/shareddefs.h b/r5dev/game/shared/shareddefs.h new file mode 100644 index 00000000..74a90c87 --- /dev/null +++ b/r5dev/game/shared/shareddefs.h @@ -0,0 +1,27 @@ +//======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ====== +// +// Purpose: Definitions that are shared by the game DLL and the client DLL. +// +//=============================================================================== + + +#ifndef SHAREDDEFS_H +#define SHAREDDEFS_H +#ifdef _WIN32 +#pragma once +#endif + +#ifndef CLIENT_DLL +#include "game/server/gameinterface.h" + +#define TICK_INTERVAL (g_pGlobals->m_nTickInterval) + +#define TIME_TO_TICKS( dt ) ( (int)( 0.5f + (float)(dt) / TICK_INTERVAL ) ) +#define TICKS_TO_TIME( t ) ( TICK_INTERVAL *( t ) ) +#define ROUND_TO_TICKS( t ) ( TICK_INTERVAL * TIME_TO_TICKS( t ) ) +#define TICK_NEVER_THINK (-1) + +#endif // !CLIENT_DLL + + +#endif // SHAREDDEFS_H \ No newline at end of file diff --git a/r5dev/public/baseentity.cpp b/r5dev/public/baseentity.cpp new file mode 100644 index 00000000..27150199 --- /dev/null +++ b/r5dev/public/baseentity.cpp @@ -0,0 +1,39 @@ +//======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ====== +// +// Purpose: The base class from which all game entities are derived. +// +//=============================================================================== +#include "core/stdafx.h" +#include "baseentity.h" + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +CCollisionProperty* CBaseEntity::CollisionProp() +{ + return &m_Collision; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +const CCollisionProperty* CBaseEntity::CollisionProp() const +{ + return &m_Collision; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +CServerNetworkProperty* CBaseEntity::NetworkProp() +{ + return &m_Network; +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +const CServerNetworkProperty* CBaseEntity::NetworkProp() const +{ + return &m_Network; +} diff --git a/r5dev/public/baseentity.h b/r5dev/public/baseentity.h index 6e5fc501..498d056d 100644 --- a/r5dev/public/baseentity.h +++ b/r5dev/public/baseentity.h @@ -20,6 +20,15 @@ class CBaseEntity : public IServerEntity { + // non-virtual methods. Don't override these! +public: + // An inline version the game code can use + CCollisionProperty* CollisionProp(); + const CCollisionProperty* CollisionProp() const; + CServerNetworkProperty* NetworkProp(); + const CServerNetworkProperty* NetworkProp() const; + +private: char m_RefEHandle[4]; char gap_c[4]; void* m_collideable; diff --git a/r5dev/public/const.h b/r5dev/public/const.h index df797416..9c9b6ed7 100644 --- a/r5dev/public/const.h +++ b/r5dev/public/const.h @@ -14,13 +14,18 @@ #define MAX_EDICTS (1<SuspendLayout(); this->SetAutoScaleDimensions({ 6, 13 }); this->SetAutoScaleMode(Forms::AutoScaleMode::Font); - this->SetText("SDK Launcher"); + this->SetText("Launcher"); this->SetClientSize({ WindowX, WindowY }); this->SetFormBorderStyle(Forms::FormBorderStyle::FixedSingle); this->SetStartPosition(Forms::FormStartPosition::CenterParent); diff --git a/r5dev/vproj/clientsdk.vcxproj b/r5dev/vproj/clientsdk.vcxproj index cbe6b624..013f3e78 100644 --- a/r5dev/vproj/clientsdk.vcxproj +++ b/r5dev/vproj/clientsdk.vcxproj @@ -64,6 +64,7 @@ + @@ -234,8 +235,10 @@ + + diff --git a/r5dev/vproj/clientsdk.vcxproj.filters b/r5dev/vproj/clientsdk.vcxproj.filters index 836ac559..b17cc3d8 100644 --- a/r5dev/vproj/clientsdk.vcxproj.filters +++ b/r5dev/vproj/clientsdk.vcxproj.filters @@ -657,6 +657,9 @@ sdk\game\shared + + sdk\game\shared + @@ -1922,6 +1925,12 @@ sdk\game\shared + + sdk\game\shared + + + sdk\game\shared + diff --git a/r5dev/vproj/dedicated.vcxproj b/r5dev/vproj/dedicated.vcxproj index bcc4b663..307bad28 100644 --- a/r5dev/vproj/dedicated.vcxproj +++ b/r5dev/vproj/dedicated.vcxproj @@ -191,8 +191,10 @@ + + @@ -550,8 +552,10 @@ + + @@ -587,6 +591,7 @@ NotUsing NotUsing + diff --git a/r5dev/vproj/dedicated.vcxproj.filters b/r5dev/vproj/dedicated.vcxproj.filters index 1648ec85..e2f24bab 100644 --- a/r5dev/vproj/dedicated.vcxproj.filters +++ b/r5dev/vproj/dedicated.vcxproj.filters @@ -1356,6 +1356,12 @@ sdk\game\shared + + sdk\game\shared + + + sdk\game\shared + @@ -1703,6 +1709,15 @@ sdk\game\server + + sdk\game\shared + + + sdk\game\server + + + sdk\public + diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index a36496f0..93b914cb 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -70,9 +70,11 @@ + + @@ -110,6 +112,7 @@ NotUsing NotUsing + @@ -264,8 +267,10 @@ + + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 9704f794..e2e5529a 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -702,6 +702,15 @@ sdk\game\shared + + sdk\game\shared + + + sdk\game\server + + + sdk\public + @@ -2060,6 +2069,12 @@ sdk\game\shared + + sdk\game\shared + + + sdk\game\shared +