Skip to content

Commit

Permalink
Rework triggerfix to take control of all player/trigger interactions,…
Browse files Browse the repository at this point in the history
… some misc changes (#264)

* Triggerfix rewrite

* Enable optimize on release builds
  • Loading branch information
zer0k-z authored Oct 26, 2024
1 parent 79c73d9 commit f04975c
Show file tree
Hide file tree
Showing 17 changed files with 1,196 additions and 821 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:

- name: Configure AMBuild
working-directory: build
run: python3 ../configure.py
run: python3 ../configure.py --enable-optimize

- name: Update version header
shell: bash
Expand Down
4 changes: 4 additions & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ for sdk_target in MMSPlugin.sdk_targets:
os.path.join(builder.sourcePath, 'src', 'kz', 'timer', 'personal_best.cpp'),

os.path.join(builder.sourcePath, 'src', 'kz', 'tip', 'kz_tip.cpp'),

os.path.join(builder.sourcePath, 'src', 'kz', 'trigger', 'callbacks.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'trigger', 'kz_trigger.cpp'),
os.path.join(builder.sourcePath, 'src', 'kz', 'trigger', 'mapping_api.cpp'),
]

binary.custom = [builder.tools.Protoc(protoc = sdk_target.protoc, sources = PROTOS)]
Expand Down
15 changes: 13 additions & 2 deletions src/kz/checkpoint/kz_checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../timer/kz_timer.h"
#include "../noclip/kz_noclip.h"
#include "../language/kz_language.h"
#include "kz/trigger/kz_trigger.h"
#include "utils/utils.h"

static_global class KZOptionServiceEventListener_Checkpoint : public KZOptionServiceEventListener
Expand Down Expand Up @@ -82,16 +83,18 @@ void KZCheckpointService::SetCheckpoint()
return;
}

if (this->player->modifiers.disableCheckpointsCount > 0)
if (!this->player->triggerService->CanPlaceCheckpoints())
{
this->player->languageService->PrintChat(true, false, "Can't Checkpoint (Anti Checkpoint Area)");
this->player->PlayErrorSound();
return;
}

u32 flags = pawn->m_fFlags();
if (!(flags & FL_ONGROUND) && !(pawn->m_MoveType() == MOVETYPE_LADDER))
{
this->player->languageService->PrintChat(true, false, "Can't Checkpoint (Midair)");
this->player->PlayErrorSound();
return;
}

Expand Down Expand Up @@ -124,16 +127,19 @@ void KZCheckpointService::UndoTeleport()
if (this->checkpoints.Count() <= 0 || this->undoTeleportData.origin.IsZero() || this->tpCount <= 0)
{
this->player->languageService->PrintChat(true, false, "Can't Undo (No Teleports)");
this->player->PlayErrorSound();
return;
}
if (!this->undoTeleportData.teleportOnGround)
{
this->player->languageService->PrintChat(true, false, "Can't Undo (TP Was Midair)");
this->player->PlayErrorSound();
return;
}
if (this->undoTeleportData.teleportInAntiCpTrigger)
{
this->player->languageService->PrintChat(true, false, "Can't Undo (AntiCp)");
this->player->PlayErrorSound();
return;
}

Expand All @@ -145,6 +151,7 @@ void KZCheckpointService::DoTeleport(i32 index)
if (this->checkpoints.Count() <= 0)
{
this->player->languageService->PrintChat(true, false, "Can't Teleport (No Checkpoints)");
this->player->PlayErrorSound();
return;
}
this->DoTeleport(this->checkpoints[this->currentCpIndex]);
Expand All @@ -158,9 +165,10 @@ void KZCheckpointService::DoTeleport(const Checkpoint cp)
return;
}

if (this->player->modifiers.disableTeleportsCount > 0)
if (!this->player->triggerService->CanTeleportToCheckpoints())
{
this->player->languageService->PrintChat(true, false, "Can't Teleport (Map)");
this->player->PlayErrorSound();
return;
}

Expand Down Expand Up @@ -252,6 +260,7 @@ void KZCheckpointService::TpToPrevCp()
if (this->checkpoints.Count() <= 0)
{
this->player->languageService->PrintChat(true, false, "Can't Teleport (No Checkpoints)");
this->player->PlayErrorSound();
return;
}
this->currentCpIndex = MAX(0, this->currentCpIndex - 1);
Expand All @@ -263,6 +272,7 @@ void KZCheckpointService::TpToNextCp()
if (this->checkpoints.Count() <= 0)
{
this->player->languageService->PrintChat(true, false, "Can't Teleport (No Checkpoints)");
this->player->PlayErrorSound();
return;
}
this->currentCpIndex = MIN(this->currentCpIndex + 1, this->checkpoints.Count() - 1);
Expand Down Expand Up @@ -329,6 +339,7 @@ void KZCheckpointService::SetStartPosition()
if (!pawn)
{
this->player->languageService->PrintChat(true, false, "Can't Set Custom Start Position (Generic)");
this->player->PlayErrorSound();
return;
}
this->hasCustomStartPosition = true;
Expand Down
5 changes: 3 additions & 2 deletions src/kz/jumpstats/kz_jumpstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../style/kz_style.h"
#include "../option/kz_option.h"
#include "../language/kz_language.h"
#include "kz/trigger/kz_trigger.h"

#include "tier0/memdbgon.h"

Expand Down Expand Up @@ -559,7 +560,7 @@ f32 Jump::GetDeviation()

JumpType KZJumpstatsService::DetermineJumpType()
{
if (this->jumps.Count() <= 0 || this->player->JustTeleported() || this->player->modifiers.disableJumpstatsCount)
if (this->jumps.Count() <= 0 || this->player->JustTeleported() || this->player->triggerService->ShouldDisableJumpstats())
{
return JumpType_Invalid;
}
Expand Down Expand Up @@ -666,7 +667,7 @@ void KZJumpstatsService::OnProcessMovement()
this->InvalidateJumpstats("First jump");
return;
}
if (this->player->modifiers.disableJumpstatsCount > 0)
if (this->player->triggerService->ShouldDisableJumpstats())
{
this->InvalidateJumpstats("Disabled By Map");
}
Expand Down
43 changes: 2 additions & 41 deletions src/kz/kz.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class KZStyleService;
class KZTelemetryService;
class KZTimerService;
class KZTipService;
struct KZCourseDescriptor;
struct Modifier;
class KZTriggerService;

class KZPlayer : public MovementPlayer
{
Expand Down Expand Up @@ -130,36 +129,11 @@ class KZPlayer : public MovementPlayer
virtual void OnChangeTeamPost(i32 team) override;
virtual void OnTeleport(const Vector *origin, const QAngle *angles, const Vector *velocity) override;

// Timer events
void MappingApiTriggerStartTouch(const KzTrigger *touched, const KZCourseDescriptor *course);
void MappingApiTriggerEndTouch(const KzTrigger *touched, const KZCourseDescriptor *course);

virtual bool OnTriggerStartTouch(CBaseTrigger *trigger) override;
virtual bool OnTriggerTouch(CBaseTrigger *trigger) override;
virtual bool OnTriggerEndTouch(CBaseTrigger *trigger) override;

void PlayErrorSound();

private:
bool hideLegs {};
f64 lastTeleportTime {};
CEntityHandle lastTouchedSingleBhop {};
i32 bhopTouchCount {};

class CSequentialBhopBuffer : public CFixedSizeCircularBuffer<CEntityHandle, 64>
{
virtual void ElementAlloc(CEntityHandle &element) {};
virtual void ElementRelease(CEntityHandle &element) {};
};

CSequentialBhopBuffer lastTouchedSequentialBhops {};
CUtlVectorFixed<KzTouchingTrigger, 64> kzTriggerTouchList {};

void AddKzTriggerToTouchList(const KzTrigger *trigger);
void RemoveKzTriggerFromTouchList(const KzTrigger *trigger);
void TouchAntibhopTrigger(KzTouchingTrigger touching);
bool TouchTeleportTrigger(KzTouchingTrigger touching);
void ResetBhopState();

public:
KZAnticheatService *anticheatService {};
Expand All @@ -182,20 +156,7 @@ class KZPlayer : public MovementPlayer
KZTelemetryService *telemetryService {};
KZTimerService *timerService {};
KZTipService *tipService {};

struct Modifiers
{
i32 disablePausingCount;
i32 disableCheckpointsCount;
i32 disableTeleportsCount;
i32 disableJumpstatsCount;
i32 enableSlideCount;
};

Modifiers modifiers {};
Modifiers lastModifiers {};
bool antiBhopActive;
bool lastAntiBhopActive;
KZTriggerService *triggerService {};

void EnableGodMode();

Expand Down
Loading

0 comments on commit f04975c

Please sign in to comment.