Skip to content

Commit

Permalink
feat: implement anti-C-Bug mechanism for Desert Eagle (#304)
Browse files Browse the repository at this point in the history
MrDave1999 authored Jan 22, 2025
1 parent 6880e74 commit 94775b7
Showing 2 changed files with 58 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Application/Players/AntiCBug/AntiCBugSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
namespace CTF.Application.Players.AntiCBug;

public class AntiCBugSystem(UnixTimeSeconds unixTimeSeconds) : ISystem
{
[Event]
public void OnPlayerConnect(Player player)
{
player.AddComponent<LastFiredTimeComponent>();
}

[Event]
public void OnPlayerKeyStateChange(Player player, Keys newKeys, Keys oldKeys)
{
if (player.State != PlayerState.OnFoot)
return;

var lastFiredTimeComponent = player.GetComponent<LastFiredTimeComponent>();
if (player.SpecialAction != SpecialAction.Duck &&
KeyUtils.HasPressed(newKeys, oldKeys, Keys.Fire))
{
lastFiredTimeComponent.Value = player.Weapon switch
{
Weapon.Deagle => unixTimeSeconds.Value,
_ => default
};
}
else if (KeyUtils.HasPressed(newKeys, oldKeys, Keys.Crouch))
{
long currentTime = unixTimeSeconds.Value;
long elapsedTime = currentTime - lastFiredTimeComponent.Value;
if (elapsedTime < 1)
{
player.GameText("~r~~h~DON'T C-BUG!", 3000, 4);
player.ApplyAnimation(
animationLibrary: "PED",
animationName: "getup",
fDelta: 4.1f,
loop: false,
lockX: false,
lockY: false,
freeze: false,
time: 0,
forceSync: false
);
}
}
}
}
10 changes: 10 additions & 0 deletions src/Application/Players/AntiCBug/LastFiredTimeComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CTF.Application.Players.AntiCBug;

/// <summary>
/// Represents a component that stores the last shot time and
/// is used to detect rapid shooting techniques such as C-Bug.
/// </summary>
public class LastFiredTimeComponent : Component
{
public long Value { get; set; }
}

0 comments on commit 94775b7

Please sign in to comment.