From c22083423114fbcb3af47c543569b655cb71f8d4 Mon Sep 17 00:00:00 2001 From: quaK <38787176+Joelrau@users.noreply.github.com> Date: Sat, 20 May 2023 17:11:32 +0300 Subject: [PATCH] Restore cg_thirdperson --- src/client/component/thirdperson.cpp | 84 ++++++++++++++++++++++++++++ src/client/game/structs.hpp | 62 +++++++++++++++++--- 2 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 src/client/component/thirdperson.cpp diff --git a/src/client/component/thirdperson.cpp b/src/client/component/thirdperson.cpp new file mode 100644 index 00000000..c6573f48 --- /dev/null +++ b/src/client/component/thirdperson.cpp @@ -0,0 +1,84 @@ +#include +#include "loader/component_loader.hpp" + +#include "game/game.hpp" +#include "game/dvars.hpp" + +#include "scheduler.hpp" + +#include + +namespace thirdperson +{ + namespace + { + game::dvar_t* cg_thirdPerson = nullptr; + game::dvar_t* cg_thirdPersonRange = nullptr; + game::dvar_t* cg_thirdPersonAngle = nullptr; + + namespace mp + { + __int64 sub_1D5950_stub([[maybe_unused]] int local_client_num, game::mp::cg_s* a2) + { + auto next_snap = a2->nextSnap; + if (next_snap->ps.pm_type < 7u) + { + int link_flags = next_snap->ps.linkFlags; + if ((link_flags & 2) == 0 && (next_snap->ps.otherFlags & 4) == 0) + { + auto client_globals = a2; + if (!client_globals->unk2 || !client_globals->unk3) + { + if (cg_thirdPerson && cg_thirdPerson->current.enabled) + { + return 1; + } + + if (!(link_flags & (1 << 0xE)) || client_globals->unk3) + return (link_flags >> 27) & 1; + if (link_flags & (1 << 0x1D)) + return 0; + if (!(link_flags & (1 << 0x1C))) + return a2->unk1; + } + } + } + return 1; + } + + void sub_10C280_stub(int local_client_num, float angle, float range, int a4, int a5, int a6, int a7) + { + angle = cg_thirdPersonAngle->current.value; + range = cg_thirdPersonRange->current.value; + utils::hook::invoke(0x10C280_b, local_client_num, angle, range, a4, a5, a6, a7); + } + } + + } + + class component final : public component_interface + { + public: + void post_unpack() override + { + if (!game::environment::is_mp()) + { + return; + } + + scheduler::once([]() + { + cg_thirdPerson = dvars::register_bool("cg_thirdPerson", 0, 4, "Use third person view"); + cg_thirdPersonAngle = dvars::register_float("cg_thirdPersonAngle", 356.0f, -180.0f, 360.0f, 4, + "The angle of the camera from the player in third person view"); + cg_thirdPersonRange = dvars::register_float("cg_thirdPersonRange", 120.0f, 0.0f, 1024, 4, + "The range of the camera from the player in third person view"); + }, scheduler::main); + + utils::hook::jump(0x1D5950_b, mp::sub_1D5950_stub); + utils::hook::call(0x10C26B_b, mp::sub_10C280_stub); + } + }; +} + +REGISTER_COMPONENT(thirdperson::component) diff --git a/src/client/game/structs.hpp b/src/client/game/structs.hpp index 0ebd5057..c8ec0308 100644 --- a/src/client/game/structs.hpp +++ b/src/client/game/structs.hpp @@ -1931,16 +1931,20 @@ namespace game { char __pad0[2]; char pm_type; // 2 - char __pad1[18573]; + char __pad1[297]; + float angles[3]; // 300 304 308 + char __pad2[18264]; sessionState_t sessionState; - char __pad2[220]; // 254 + char __pad3[220]; // 254 team_t team; - char __pad3[30]; + char __pad4[30]; char name[32]; // 18834 - char __pad4[622]; + char __pad5[622]; int flags; // 19488 }; // size = ? + static_assert(offsetof(gclient_s, angles) == 300); + static_assert(offsetof(gclient_s, sessionState) == 18576); static_assert(offsetof(gclient_s, team) == 18800); static_assert(offsetof(gclient_s, name) == 18834); static_assert(offsetof(gclient_s, flags) == 19488); @@ -1974,14 +1978,58 @@ namespace game struct playerState_s { - int clientNum; - char __pad0[116]; + char clientNum; + char __pad0[1]; + char pm_type; + char __pad1[44]; + int otherFlags; + char __pad2[28]; + int pm_time; + int pm_flags; + int eFlags; + int linkFlags; + char __pad3[24]; vec3_t origin; vec3_t velocity; - char __pad1[312]; + char __pad4[312]; int sprintButtonUpRequired; }; + static_assert(offsetof(playerState_s, pm_type) == 2); + //static_assert(offsetof(playerState_s, groundEntityNum) == 34); + static_assert(offsetof(playerState_s, otherFlags) == 48); + static_assert(offsetof(playerState_s, pm_time) == 80); + static_assert(offsetof(playerState_s, pm_flags) == 84); + static_assert(offsetof(playerState_s, eFlags) == 88); + static_assert(offsetof(playerState_s, linkFlags) == 92); + static_assert(offsetof(playerState_s, origin) == 120); + static_assert(offsetof(playerState_s, velocity) == 132); + static_assert(offsetof(playerState_s, sprintButtonUpRequired) == 456); + + struct snapshot_s + { + playerState_s ps; + }; + + struct cg_s + { + char __pad0[18680]; + snapshot_s* nextSnap; + char __pad1[582400]; + int unk1; + int renderingThirdPerson; + char __pad2[378580]; + int unk2; + char __pad3[16]; + int unk3; + }; + + static_assert(offsetof(cg_s, nextSnap) == 18680); + static_assert(offsetof(cg_s, unk1) == 601088); + static_assert(offsetof(cg_s, renderingThirdPerson) == 601092); + static_assert(offsetof(cg_s, unk2) == 979676); + static_assert(offsetof(cg_s, unk3) == 979696); + struct pmove_t { playerState_s* ps;