Skip to content

Commit

Permalink
WIP modes
Browse files Browse the repository at this point in the history
  • Loading branch information
zer0k-z committed Dec 4, 2023
1 parent 19f5a91 commit 24d64f9
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 31 deletions.
2 changes: 1 addition & 1 deletion AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions src/kz/kz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/kz/mode/kz_mode.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once
#include "../kz.h"
#include "../jumpstats/kz_jumpstats.h"

class KZPlayer;

class KZModeService : public KZBaseService
Expand All @@ -15,6 +16,7 @@ class KZModeService : public KZBaseService

namespace KZ::mode
{
void InitModeCvars();
void InitModeService(KZPlayer *player);

inline const char *modeCvarNames[] =
Expand All @@ -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();
};
30 changes: 30 additions & 0 deletions src/kz/mode/kz_mode_ckz.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
22 changes: 22 additions & 0 deletions src/kz/mode/kz_mode_ckz.h
Original file line number Diff line number Diff line change
@@ -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
};

};
27 changes: 13 additions & 14 deletions src/kz/mode/kz_mode_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
}
2 changes: 0 additions & 2 deletions src/kz/mode/kz_mode_mod.cpp

This file was deleted.

2 changes: 2 additions & 0 deletions src/movement/movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class MovementPlayer
void InvalidateTimer(bool playErrorSound = true);

virtual void Reset();
virtual f32 GetPlayerMaxSpeed();

virtual void OnStartProcessMovement();
virtual void OnStopProcessMovement();

Expand Down
4 changes: 3 additions & 1 deletion src/movement/mv_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/utils/addresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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");
Expand Down
30 changes: 20 additions & 10 deletions src/utils/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CCSPlayerPawn;
struct TransmitInfo
{
CBitVec<16384> *m_pTransmitEdict;
uint8_t unknown[552];
uint8 unknown[552];
CPlayerSlot m_nClientEntityIndex;
};

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -185,7 +186,7 @@ struct touchlist_t {
class CTraceFilterPlayerMovementCS
{
public:
uint8_t tfunk[64];
uint8 tfunk[64];
};

struct vis_info_t
Expand All @@ -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
{
};
1 change: 1 addition & 0 deletions src/utils/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ namespace interfaces
inline ISource2Server *pServer = nullptr;
inline IGameEventManager2 *pGameEventManager = nullptr;
inline IGameEventSystem *pGameEventSystem = nullptr;
inline void *pPhysicsQuery = nullptr;
}
13 changes: 11 additions & 2 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
3 changes: 2 additions & 1 deletion src/utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &params);
#else
typedef void EmitSoundFunc_t(IRecipientFilter &filter, CEntityIndex ent, const EmitSound_t &params);
#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;

Expand Down

0 comments on commit 24d64f9

Please sign in to comment.