Restore cg_thirdperson

This commit is contained in:
quaK 2023-05-20 17:11:32 +03:00
parent 1998940550
commit c220834231
2 changed files with 139 additions and 7 deletions

View File

@ -0,0 +1,84 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "scheduler.hpp"
#include <utils/hook.hpp>
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<void>(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)

View File

@ -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;