From 24d64f9b8ec37ef8e24ee8b63c2289f9d69f649f Mon Sep 17 00:00:00 2001 From: "zer0.k" Date: Mon, 4 Dec 2023 20:49:53 +0700 Subject: [PATCH] WIP modes --- AMBuilder | 2 +- src/kz/kz.h | 2 ++ src/kz/mode/kz_mode.h | 8 ++++++++ src/kz/mode/kz_mode_ckz.cpp | 30 ++++++++++++++++++++++++++++++ src/kz/mode/kz_mode_ckz.h | 22 ++++++++++++++++++++++ src/kz/mode/kz_mode_manager.cpp | 27 +++++++++++++-------------- src/kz/mode/kz_mode_mod.cpp | 2 -- src/movement/movement.h | 2 ++ src/movement/mv_hooks.cpp | 4 +++- src/utils/addresses.h | 4 ++++ src/utils/datatypes.h | 30 ++++++++++++++++++++---------- src/utils/interfaces.h | 1 + src/utils/utils.cpp | 13 +++++++++++-- src/utils/utils.h | 3 ++- 14 files changed, 119 insertions(+), 31 deletions(-) create mode 100644 src/kz/mode/kz_mode_ckz.cpp create mode 100644 src/kz/mode/kz_mode_ckz.h delete mode 100644 src/kz/mode/kz_mode_mod.cpp diff --git a/AMBuilder b/AMBuilder index af3e9651d..131c34dad 100644 --- a/AMBuilder +++ b/AMBuilder @@ -76,7 +76,7 @@ for sdk_name in MMSPlugin.sdks: os.path.join(builder.sourcePath, 'src', 'kz', 'jumpstats', 'kz_jumpstats.cpp'), os.path.join(builder.sourcePath, 'src', 'kz', 'measure', 'kz_measure.cpp'), os.path.join(builder.sourcePath, 'src', 'kz', 'mode', 'kz_mode_manager.cpp'), - os.path.join(builder.sourcePath, 'src', 'kz', 'mode', 'kz_mode_mod.cpp'), + os.path.join(builder.sourcePath, 'src', 'kz', 'mode', 'kz_mode_ckz.cpp'), os.path.join(builder.sourcePath, 'src', 'kz', 'mode', 'kz_mode_vnl.cpp'), os.path.join(builder.sourcePath, 'src', 'kz', 'option', 'kz_option.cpp'), os.path.join(builder.sourcePath, 'src', 'kz', 'quiet', 'kz_quiet.cpp'), diff --git a/src/kz/kz.h b/src/kz/kz.h index 90ed52eb4..58ef0a8ad 100644 --- a/src/kz/kz.h +++ b/src/kz/kz.h @@ -41,6 +41,8 @@ class KZPlayer : public MovementPlayer } void Init(); virtual void Reset() override; + + virtual f32 GetPlayerMaxSpeed() override; virtual void OnStartProcessMovement() override; virtual void OnStopProcessMovement() override; diff --git a/src/kz/mode/kz_mode.h b/src/kz/mode/kz_mode.h index f80f8c75d..46e4f1d27 100644 --- a/src/kz/mode/kz_mode.h +++ b/src/kz/mode/kz_mode.h @@ -1,6 +1,7 @@ #pragma once #include "../kz.h" #include "../jumpstats/kz_jumpstats.h" + class KZPlayer; class KZModeService : public KZBaseService @@ -15,6 +16,7 @@ class KZModeService : public KZBaseService namespace KZ::mode { + void InitModeCvars(); void InitModeService(KZPlayer *player); inline const char *modeCvarNames[] = @@ -39,6 +41,12 @@ namespace KZ::mode "sv_wateraccelerate", "sv_water_slow_amount" }; + + constexpr u32 numCvar = sizeof(KZ::mode::modeCvarNames) / sizeof(KZ::mode::modeCvarNames[0]); + + inline ConVar *modeCvars[numCvar]; + + void ApplyModeCvarValues(char **values); void DisableReplicatedModeCvars(); void EnableReplicatedModeCvars(); }; \ No newline at end of file diff --git a/src/kz/mode/kz_mode_ckz.cpp b/src/kz/mode/kz_mode_ckz.cpp new file mode 100644 index 000000000..606e82584 --- /dev/null +++ b/src/kz/mode/kz_mode_ckz.cpp @@ -0,0 +1,30 @@ +#include "kz_mode_ckz.h" + +const char *KZClassicModeService::GetModeName() +{ + return "Classic"; +} +const char *KZClassicModeService::GetModeShortName() +{ + return "CKZ"; +} + +DistanceTier KZClassicModeService::GetDistanceTier(JumpType jumpType, f32 distance) +{ + // No tiers given for 'Invalid' jumps. + if (jumpType == JumpType_Invalid || jumpType == JumpType_FullInvalid + || jumpType == JumpType_Fall || jumpType == JumpType_Other + || distance > 500.0f) + { + return DistanceTier_None; + } + + // Get highest tier distance that the jump beats + DistanceTier tier = DistanceTier_None; + while (tier + 1 < DISTANCETIER_COUNT && distance >= distanceTiers[jumpType][tier]) + { + tier = (DistanceTier)(tier + 1); + } + + return tier; +} \ No newline at end of file diff --git a/src/kz/mode/kz_mode_ckz.h b/src/kz/mode/kz_mode_ckz.h new file mode 100644 index 000000000..b78acd661 --- /dev/null +++ b/src/kz/mode/kz_mode_ckz.h @@ -0,0 +1,22 @@ +#pragma once +#include "kz_mode.h" + +class KZClassicModeService : public KZModeService +{ + using KZModeService::KZModeService; +public: + virtual const char *GetModeName() override; + virtual const char *GetModeShortName() override; + virtual DistanceTier GetDistanceTier(JumpType jumpType, f32 distance) override; + f32 distanceTiers[JUMPTYPE_COUNT - 3][DISTANCETIER_COUNT] = + { + {217.0f, 265.0f, 270.0f, 275.0f, 280.0f, 285.0f}, // LJ + {217.0f, 270.0f, 275.0f, 280.0f, 285.0f, 290.0f}, // BH + {217.0f, 270.0f, 275.0f, 280.0f, 285.0f, 290.0f}, // MBH + {217.0f, 270.0f, 275.0f, 280.0f, 285.0f, 290.0f}, // WJ + {120.0f, 180.0f, 185.0f, 190.0f, 195.0f, 200.0f}, // LAJ + {217.0f, 260.0f, 265.0f, 270.0f, 275.0f, 280.0f}, // LAH + {217.0f, 270.0f, 275.0f, 280.0f, 285.0f, 290.0f}, // JB + }; + +}; \ No newline at end of file diff --git a/src/kz/mode/kz_mode_manager.cpp b/src/kz/mode/kz_mode_manager.cpp index c2f96eed4..183c75b76 100644 --- a/src/kz/mode/kz_mode_manager.cpp +++ b/src/kz/mode/kz_mode_manager.cpp @@ -2,6 +2,15 @@ #include "kz_mode_vnl.h" #include "interfaces/interfaces.h" +void KZ::mode::InitModeCvars() +{ + for (u32 i = 0; i < numCvar; i++) + { + ConVarHandle cvarHandle = g_pCVar->FindConVar(KZ::mode::modeCvarNames[i]); + if (!cvarHandle.IsValid()) continue; + modeCvars[i] = g_pCVar->GetConVar(cvarHandle); + } +} void KZ::mode::InitModeService(KZPlayer *player) { @@ -10,28 +19,18 @@ void KZ::mode::InitModeService(KZPlayer *player) void KZ::mode::DisableReplicatedModeCvars() { - u32 numCvar = sizeof(KZ::mode::modeCvarNames) / sizeof(KZ::mode::modeCvarNames[0]); - for (u32 i = 0; i < numCvar; ++i) { - ConVarHandle cvarHandle = g_pCVar->FindConVar(KZ::mode::modeCvarNames[i]); - if (!cvarHandle.IsValid()) continue; - ConVar *cvar = g_pCVar->GetConVar(cvarHandle); - - cvar->flags &= ~FCVAR_REPLICATED; + assert(modeCvars[i]); + modeCvars[i]->flags &= ~FCVAR_REPLICATED; } } void KZ::mode::EnableReplicatedModeCvars() { - u32 numCvar = sizeof(KZ::mode::modeCvarNames) / sizeof(KZ::mode::modeCvarNames[0]); - for (u32 i = 0; i < numCvar; ++i) { - ConVarHandle cvarHandle = g_pCVar->FindConVar(KZ::mode::modeCvarNames[i]); - if (!cvarHandle.IsValid()) continue; - ConVar *cvar = g_pCVar->GetConVar(cvarHandle); - - cvar->flags |= FCVAR_REPLICATED; + assert(modeCvars[i]); + modeCvars[i]->flags |= FCVAR_REPLICATED; } } \ No newline at end of file diff --git a/src/kz/mode/kz_mode_mod.cpp b/src/kz/mode/kz_mode_mod.cpp deleted file mode 100644 index 177538aa4..000000000 --- a/src/kz/mode/kz_mode_mod.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "../kz.h" -#include "kz_mode.h" \ No newline at end of file diff --git a/src/movement/movement.h b/src/movement/movement.h index 204d8c434..be27dc40e 100644 --- a/src/movement/movement.h +++ b/src/movement/movement.h @@ -70,6 +70,8 @@ class MovementPlayer void InvalidateTimer(bool playErrorSound = true); virtual void Reset(); + virtual f32 GetPlayerMaxSpeed(); + virtual void OnStartProcessMovement(); virtual void OnStopProcessMovement(); diff --git a/src/movement/mv_hooks.cpp b/src/movement/mv_hooks.cpp index bfeeb8af9..63c3360f0 100644 --- a/src/movement/mv_hooks.cpp +++ b/src/movement/mv_hooks.cpp @@ -31,7 +31,9 @@ void movement::InitDetours() f32 FASTCALL movement::Detour_GetMaxSpeed(CCSPlayerPawn *pawn) { - return GetMaxSpeed(pawn); + f32 newMaxSpeed; + + if (newMaxSpeed <= 0.0f) return GetMaxSpeed(pawn); } void FASTCALL movement::Detour_ProcessMovement(CCSPlayer_MovementServices *ms, CMoveData *mv) diff --git a/src/utils/addresses.h b/src/utils/addresses.h index 53d6c9fd8..941e215b9 100644 --- a/src/utils/addresses.h +++ b/src/utils/addresses.h @@ -156,6 +156,9 @@ namespace sigs // called after MoveInit in PlayerMoveNew in switch statement with movetype 5 DECLARE_SIG(Duck, "\x48\x8B\xC4\x48\x89\x58\x20\x55\x56\x57\x41\x56\x41\x57\x48\x8D\xA8\xD8\xFE\xFF\xFF"); + // CTraceFilterForPlayerHeadCollision vtable + DECLARE_SIG(CanUnduck, "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x4C\x8D\xAD\x10\xFF\xFF\xFF\x41\x54\x49\x89\xFC\x4C\x89\xEF\x53\x48\x89\xF3\x48\x81\xEC\x58\x01\x00\x00"); + // sv_ladder_dampen DECLARE_SIG(LadderMove, "\x40\x55\x56\x57\x41\x54\x41\x55\x48\x8D\xAC\x24\xE0\xFC\xFF\xFF"); @@ -227,6 +230,7 @@ namespace sigs DECLARE_SIG(CheckWater, "\x55\x48\x89\xE5\x41\x54\x49\x89\xF4\x53\x48\x89\xFB\x48\x81\xEC\x2A\x2A\x2A\x2A\x48"); DECLARE_SIG(CheckVelocity, "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x49\x89\xFD\x41\x54\x53\x48\x89\xF3\x48\x83\xEC\x2A\x48\x8B\x7F"); DECLARE_SIG(Duck, "\x55\x48\x89\xE5\x41\x57\x41\x56\x49\x89\xFE\x41\x55\x45\x31\xED\x41\x54\x49\x89\xF4\x53\x48\x81"); + DECLARE_SIG(CanUnduck, "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x4C\x8D\xAD\x10\xFF\xFF\xFF\x41\x54\x49\x89\xFC\x4C\x89\xEF\x53\x48\x89\xF3\x48\x81\xEC\x58\x01\x00\x00"); DECLARE_SIG(LadderMove, "\x48\xB8\x00\x00\x00\x00\xFF\xFF\xFF\xFF\x55\x48\x89\xE5\x41\x57\x49\x89\xFF\x41\x56\x41\x55\x41\x54\x4C"); DECLARE_SIG(CheckJumpButton, "\x55\x48\x89\xE5\x41\x56\x41\x55\x41\x54\x49\x89\xF4\xBE\x2A\x2A\x2A\x2A\x53\x48\x89\xFB\x48\x83\xEC\x2A\xE8"); DECLARE_SIG(OnJump, "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x49\x89\xFC\x53\x48\x89\xF3\x48\x83\xEC\x2A\x48\x8B\x7F"); diff --git a/src/utils/datatypes.h b/src/utils/datatypes.h index 9acc79497..d4c76e481 100644 --- a/src/utils/datatypes.h +++ b/src/utils/datatypes.h @@ -35,7 +35,7 @@ class CCSPlayerPawn; struct TransmitInfo { CBitVec<16384> *m_pTransmitEdict; - uint8_t unknown[552]; + uint8 unknown[552]; CPlayerSlot m_nClientEntityIndex; }; @@ -88,7 +88,7 @@ enum InputBitMask_t : uint64_t }; // used with EmitSound_t -enum gender_t : uint8_t +enum gender_t : uint8 { GENDER_NONE = 0x0, GENDER_MALE = 0x1, @@ -159,22 +159,23 @@ class CBaseTrigger : public CBaseEntity2 struct trace_t_s2 { - uint8_t traceunknown0[8]; // 0 + uint8 traceunknown0[8]; // 0 CBaseEntity *m_pEnt; // 8 - uint8_t traceunknown1[24]; // 16 + uint8 traceunknown1[24]; // 16 int contents; // 40 - uint8_t traceunknown2[4]; // 44 (this is probably just alignment padding) + uint8 traceunknown2[4]; // 44 (this is probably just alignment padding) __m128i traceunknown3; // 48 __m128i traceunknown4; // 64 - uint8_t traceunknown5[40]; + uint8 traceunknown5[40]; Vector startpos; Vector endpos; Vector planeNormal; Vector traceunknown6; - uint8_t traceunknown7[4]; + uint8 traceunknown7[4]; float fraction; - uint8_t traceunknown8[7]; + uint8 traceunknown8[7]; bool startsolid; + uint8 traceunknown9[9]; }; struct touchlist_t { @@ -185,7 +186,7 @@ struct touchlist_t { class CTraceFilterPlayerMovementCS { public: - uint8_t tfunk[64]; + uint8 tfunk[64]; }; struct vis_info_t @@ -199,5 +200,14 @@ struct vis_info_t struct CCheckTransmitInfoS2 { CBitVec<16384> *m_pTransmitEdict; - uint8_t unk[1000]; + uint8 unk[1000]; +}; + +struct Ray_t_s2 +{ + Vector start; +}; + +class CTraceFilterKZ +{ }; \ No newline at end of file diff --git a/src/utils/interfaces.h b/src/utils/interfaces.h index 9791b1ab8..392ba9892 100644 --- a/src/utils/interfaces.h +++ b/src/utils/interfaces.h @@ -16,4 +16,5 @@ namespace interfaces inline ISource2Server *pServer = nullptr; inline IGameEventManager2 *pGameEventManager = nullptr; inline IGameEventSystem *pGameEventSystem = nullptr; + inline void *pPhysicsQuery = nullptr; } \ No newline at end of file diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 8059d7ad0..07372d897 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -50,7 +50,7 @@ bool interfaces::Initialize(ISmmAPI *ismm, char *error, size_t maxlen) GET_V_IFACE_CURRENT(GetEngineFactory, g_pNetworkMessages, INetworkMessages, NETWORKMESSAGES_INTERFACE_VERSION); GET_V_IFACE_CURRENT(GetEngineFactory, interfaces::pGameEventSystem, IGameEventSystem, GAMEEVENTSYSTEM_INTERFACE_VERSION); interfaces::pGameEventManager = (IGameEventManager2 *)(CALL_VIRTUAL(uintptr_t, offsets::GetEventManager, interfaces::pServer) - 8); - + interfaces::pPhysicsQuery = (void *) return true; } @@ -296,5 +296,14 @@ void utils::SendConVarValue(CPlayerSlot slot, ConVar *conVar, const char *value) void utils::SendMultipleConVarValues(CPlayerSlot slot, ConVar **conVar, const char **value, int size) { - // TODO + INetworkSerializable *netmsg = g_pNetworkMessages->FindNetworkMessagePartial("SetConVar"); + CNETMsg_SetConVar *msg = new CNETMsg_SetConVar; + for (u32 i = 0; i < size; i++) + { + CMsg_CVars_CVar *cvar = msg->mutable_convars()->add_cvars(); + cvar->set_name(conVar[i]->m_pszName); + cvar->set_value(value[i]); + } + CSingleRecipientFilter filter(slot.Get()); + interfaces::pGameEventSystem->PostEventAbstract(0, false, &filter, netmsg, msg, 0); } \ No newline at end of file diff --git a/src/utils/utils.h b/src/utils/utils.h index 578fe5ea1..2244082ca 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -13,13 +13,14 @@ typedef void TracePlayerBBoxForGround_t (const Vector &start, const Vector &end, typedef void InitGameTrace_t(trace_t_s2 *trace); typedef IGameEventListener2 *GetLegacyGameEventListener_t(CPlayerSlot slot); typedef void SnapViewAngles_t(CBasePlayerPawn *pawn, const QAngle &angle); -// TODO: why? +// Seems to be caused by different call convention? #ifdef _WIN32 typedef void EmitSoundFunc_t(u64 &unknown, IRecipientFilter &filter, CEntityIndex ent, const EmitSound_t ¶ms); #else typedef void EmitSoundFunc_t(IRecipientFilter &filter, CEntityIndex ent, const EmitSound_t ¶ms); #endif +typedef bool TraceShape_t(void *physicsQuery, Ray_t_s2 ray, Vector start, Vector end, CTraceFilterKZ tf, trace_t_s2 trace); extern ClientPrintFilter_t *UTIL_ClientPrintFilter;