Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prestrafe to CKZ, fix bugs with bhop and turning detection #69

Merged
merged 10 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ for sdk_target in MMSPlugin.sdk_targets:

mode_binary.compiler.cxxincludes += CXXINCLUDES

if mode_binary.compiler.target.platform == 'linux':
mode_binary.compiler.postlink += [
os.path.join(sdk['path'], 'lib', 'linux64', 'mathlib.a'),
]
mode_binary.sources += [
os.path.join(sdk['path'], 'public', 'tier0', 'memoverride.cpp')
]
elif mode_binary.compiler.target.platform == 'windows':
mode_binary.compiler.postlink += [
os.path.join(sdk['path'], 'lib', 'public', 'win64', 'mathlib.lib'),
]

mode_binary.sources += [
os.path.join(builder.sourcePath, 'src', 'utils', 'schema.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'mode', 'kz_mode_ckz.cpp'),
Expand Down
40 changes: 28 additions & 12 deletions src/kz/jumpstats/kz_jumpstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define JS_MAX_LADDERJUMP_OFFSET 2.0f
#define JS_MAX_BHOP_GROUND_TIME 0.05f
#define JS_MAX_DUCKBUG_RESET_TIME 0.05f
#define JS_MAX_NOCLIP_RESET_TIME 0.4f
#define JS_MAX_WEIRDJUMP_FALL_OFFSET 64.0f
#define JS_TOUCH_GRACE_PERIOD 0.04f
#define JS_EPSILON 0.03125f
Expand Down Expand Up @@ -573,7 +574,7 @@ void KZJumpstatsService::OnProcessMovement()
if (this->jumps.Count() == 0)
{
this->AddJump();
this->InvalidateJumpstats();
this->InvalidateJumpstats("First jump");
return;
}
this->CheckValidMoveType();
Expand All @@ -589,7 +590,7 @@ void KZJumpstatsService::OnChangeMoveType(MoveType_t oldMoveType)
else if (oldMoveType == MOVETYPE_WALK && this->player->GetPawn()->m_MoveType() == MOVETYPE_LADDER)
{
// Not really a valid jump for jumpstats purposes.
this->InvalidateJumpstats();
this->InvalidateJumpstats("Invalid movetype change");
this->EndJump();
}
}
Expand Down Expand Up @@ -645,6 +646,7 @@ void KZJumpstatsService::UpdateJump()
this->DetectEdgebug();
this->DetectInvalidCollisions();
this->DetectInvalidGains();
this->DetectNoclip();
}

void KZJumpstatsService::EndJump()
Expand All @@ -668,7 +670,7 @@ void KZJumpstatsService::EndJump()
void KZJumpstatsService::PrintJumpToChat(KZPlayer *target, Jump *jump)
{
const char *jumpColor = distanceTierColors[jump->GetJumpPlayer()->modeService->GetDistanceTier(jump->GetJumpType(), jump->GetDistance())];
utils::CPrintChat(target->GetController(), "%s %s%s{grey}: %s%.1f {grey}| {olive}%i {grey}Strafes | {olive}%2.f%% {grey}Sync | {olive}%.2f {grey}Pre | {olive}%.2f {grey}Max\n\
utils::CPrintChat(target->GetController(), "%s %s%s{grey}: %s%.1f {grey}| {olive}%i {grey}Strafes | {olive}%.0f%% {grey}Sync | {olive}%.2f {grey}Pre | {olive}%.2f {grey}Max\n\
{grey}BA {olive}%.0f%% {grey}| OL {olive}%.0f%% {grey}| DA {olive}%.0f%% {grey}| {olive}%.1f {grey}Deviation | {olive}%.1f {grey}Width | {olive}%.2f {grey}Height",
KZ_CHAT_PREFIX,
jumpColor,
Expand All @@ -689,10 +691,16 @@ void KZJumpstatsService::PrintJumpToChat(KZPlayer *target, Jump *jump)

void KZJumpstatsService::PrintJumpToConsole(KZPlayer *target, Jump *jump)
{
utils::PrintConsole(target->GetController(), "%s jumped %.4f units with a %s",
char invalidateReason[256]{};
if (jump->invalidateReason[0] != '\0')
{
V_snprintf(invalidateReason, sizeof(invalidateReason), "(%s)", jump->invalidateReason);
}
utils::PrintConsole(target->GetController(), "%s jumped %.4f units with a %s %s",
jump->GetJumpPlayer()->GetController()->m_iszPlayerName(),
jump->GetDistance(),
jumpTypeStr[jump->GetJumpType()]);
jumpTypeStr[jump->GetJumpType()],
invalidateReason);
utils::PrintConsole(target->GetController(), "%s | %i Strafes | %.1f%% Sync | %.2f Pre | %.2f Max | %.0f%% BA | %.0f%% OL | %.0f%% DA | %.2f Height\n%.0f%% GainEff | %.3f Airpath | %.1f Deviation | %.1f Width | %.4f Airtime | %.1f Offset | %.2f/%.2f Crouched",
jump->GetJumpPlayer()->modeService->GetModeShortName(),
jump->strafes.Count(),
Expand Down Expand Up @@ -755,11 +763,11 @@ void KZJumpstatsService::PrintJumpToConsole(KZPlayer *target, Jump *jump)
angRatioString);
}
}
void KZJumpstatsService::InvalidateJumpstats()
void KZJumpstatsService::InvalidateJumpstats(const char *reason)
{
if (this->jumps.Count() > 0 && !this->jumps.Tail().AlreadyEnded())
{
this->jumps.Tail().Invalidate();
this->jumps.Tail().Invalidate(reason);
}
}

Expand Down Expand Up @@ -792,7 +800,15 @@ void KZJumpstatsService::CheckValidMoveType()
// Invalidate jumpstats if movetype is invalid.
if (this->player->GetPawn()->m_MoveType() != MOVETYPE_WALK && this->player->GetPawn()->m_MoveType() != MOVETYPE_LADDER)
{
this->InvalidateJumpstats();
this->InvalidateJumpstats("Invalid movetype");
}
}

void KZJumpstatsService::DetectNoclip()
{
if (this->lastNoclipTime + JS_MAX_NOCLIP_RESET_TIME > g_pKZUtils->GetServerGlobals()->curtime)
{
this->InvalidateJumpstats("Just noclipped");
}
}

Expand All @@ -802,7 +818,7 @@ void KZJumpstatsService::DetectEdgebug()
// If the player suddenly gain speed from negative speed, they probably edgebugged.
if (this->player->moveDataPre.m_vecVelocity.z < 0.0f && this->player->currentMoveData->m_vecVelocity.z > this->player->moveDataPre.m_vecVelocity.z)
{
this->InvalidateJumpstats();
this->InvalidateJumpstats("Potential edgebug");
}
}

Expand All @@ -816,7 +832,7 @@ void KZJumpstatsService::DetectInvalidCollisions()
// while other collisions do after a certain duration.
if (this->jumps.Tail().touchDuration > JS_TOUCH_GRACE_PERIOD)
{
this->InvalidateJumpstats();
this->InvalidateJumpstats("Invalid collisions");
}
if (this->player->moveDataPre.m_vecVelocity.z > 0.0f)
{
Expand All @@ -837,15 +853,15 @@ void KZJumpstatsService::DetectInvalidGains()

if (actualSpeed - speed > JS_SPEED_MODIFICATION_TOLERANCE && actualSpeed > JS_EPSILON)
{
this->InvalidateJumpstats();
this->InvalidateJumpstats("Invalid gains");
}
}

void KZJumpstatsService::DetectExternalModifications()
{
if ((this->player->currentMoveData->m_vecAbsOrigin - this->player->moveDataPost.m_vecAbsOrigin).LengthSqr() > JS_TELEPORT_DISTANCE_SQUARED)
{
this->InvalidateJumpstats();
this->InvalidateJumpstats("Externally modified");
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/kz/jumpstats/kz_jumpstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Jump
public:
CCopyableUtlVector<Strafe> strafes;
f32 touchDuration{};
char invalidateReason[256]{};

public:
Jump() {}
Expand All @@ -177,7 +178,7 @@ class Jump
void UpdateAACallPost(Vector wishdir, f32 wishspeed, f32 accel);
void Update();
void End();
void Invalidate() { this->valid = false; };
void Invalidate(const char *reason) { this->valid = false; V_strncpy(this->invalidateReason, reason, sizeof(this->invalidateReason)); }
void MarkHitHead() { this->hitHead = true; };

Strafe *GetCurrentStrafe();
Expand Down Expand Up @@ -221,7 +222,6 @@ class KZJumpstatsService : public KZBaseService
f32 lastGroundSpeedCappedTime{};
f32 lastMovementProcessedTime{};
f32 tpmPreSpeed{};

public:
void OnProcessMovement();
void OnChangeMoveType(MoveType_t oldMoveType);
Expand All @@ -239,13 +239,14 @@ class KZJumpstatsService : public KZBaseService
void AddJump();
void UpdateJump();
void EndJump();
void InvalidateJumpstats();
void InvalidateJumpstats(const char *reason = NULL);
void OnAirAccelerate();
void OnAirAcceleratePost(Vector wishdir, f32 wishspeed, f32 accel);
void UpdateAACallPost();
void ToggleJSAlways();

void CheckValidMoveType();
void DetectNoclip();
void DetectEdgebug();
void DetectInvalidCollisions();
void DetectInvalidGains();
Expand Down
2 changes: 1 addition & 1 deletion src/kz/kz_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void KZPlayer::OnChangeMoveType(MoveType_t oldMoveType)

void KZPlayer::OnTeleport(const Vector *origin, const QAngle *angles, const Vector *velocity)
{
this->jumpstatsService->InvalidateJumpstats();
this->jumpstatsService->InvalidateJumpstats("Teleported");
}

void KZPlayer::EnableGodMode()
Expand Down
Loading