## GENERAL - The HUD loop now runs on the shared 16 Hz frame gate (SkillUtils.IsHudFrame) instead of keeping its own every-other-tick schedule, and fifteen skills that were refreshing their HUD on every single tick were moved onto that same gate. - Added SkillData.GetSnapshot(), a cached array of the registered skills, so the HUD no longer copies the whole skill bag every frame. The cache is invalidated together with the existing lookup map, so a reload still picks up new skills. - Added SkillUtils.ForceFullUpdateToAllChunked(), which spreads a full network update across frames (two clients per frame) instead of pushing one for every connected client in a single tick. The original ForceFullUpdateToAll is untouched, so the six skills that already call it keep their current behaviour. - BlastShot, Cypher and Iana now clear their HUD line in DisableSkill, so a stale line can no longer survive the skill being taken away. ## FIXES - SoundMaker threw a divide-by-zero on every tick when its cooldown was configured as 0, because the tick gate divides by that value. The cooldown is now clamped to at least 1. - Regeneration and RadarHack were calling the wrong SkillsInfo.DefaultSkillInfo overload, which silently dropped disableOnFreezeTime, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer and rarity. Every configured field now reaches the base class, so those two skills finally honour their own config. - Falcon Eye blocked the trigger on the wrong side of the check: picking up a weapon while back in the normal view locked primary and secondary fire, because the pickup handler tested for the player being in their own view instead of in the skill camera. - Spectator locked primary and secondary fire when its camera could not be created at all, which happens when no enemy is alive to spectate. The player stayed in the normal view with a weapon that would not fire until the round ended. ## SKILL IMPROVEMENTS - Wallhack: -- The glow build and the full network update now start when freeze time ends and are spread across frames, instead of running in a single tick the moment the skill is handed out. On a busy server this used to cost roughly 13 ms in one frame, close to a dropped tick at 64 tick; across four grants in an eight-hour session it no longer reaches the 2 ms profiler threshold at all. - Jackal: -- CheckTransmit resolves the trail relays once per frame rather than once per viewer, so the same entity lookups are no longer repeated for every client on the server. -- Removed an opponent list that was gathered in EnableSkill and never used. - ThrowingKnife: -- CheckTransmit builds the knife glow list once per frame, and the viewer index is resolved once per client instead of once per knife. - Glaz: -- The observer target is only resolved for players who do not own the skill themselves, and the lookup now bails out early when there is no observer target at all. - RadarHack and QuickShot: -- The skill check runs before the validity check, so players without the skill are skipped immediately instead of being fully validated first. - Distancer, HealingChicken and SoundMaker: -- These now return straight away while nobody holds the skill, rather than walking the player list every tick. ## DEBUG - Removed the [HITGROUP] mismatch check. Every recorded case was accounted for: ten were Aimbot rewriting the hit group as designed, and thirteen were non-bullet skill damage, which reports a generic hit group by nature. Dropping the check also removes a dictionary write from every damage event. - Removed the identity-split tag from the damage log. It was dead by construction, because the victim controller had already been routed before the comparison ran, so it could never report a difference. - Removed the player-shoot handler, which produced no output on this build. - [DMG] lines now print the routing fields only when the routed index actually differs from the original one, so the check remains as a tripwire without adding noise to every line. ## TRANSLATIONS - Turkish: reworded sixty-two entries that padded their sentences with second-person verb endings, dropped the English glosses left in parentheses, and settled every [css_useSkill] line into one shape. Also fixed genuine typos in Dracula, Giant, Thorns and Impostor. - All eight languages received the strings for the four new skills. (AI) ## NEW SKILLS: - Chameleon: The first player you kill gives you their skill. - Grapple Hook: Press [css_useSkill] to fire a hook at the point you are aiming at and pull yourself there. - Inheritance: When a teammate dies you can take over their skill. - Ricochet: Your bullets bounce off walls and can still hit enemies.
238 lines
No EOL
9.6 KiB
C#
238 lines
No EOL
9.6 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Entities;
|
|
using CounterStrikeSharp.API.Modules.Memory;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using src.utils;
|
|
using System.Collections.Concurrent;
|
|
using static src.jRandomSkills;
|
|
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;
|
|
|
|
namespace src.player.skills
|
|
{
|
|
public class Noclip : ISkill
|
|
{
|
|
private const Skills skillName = Skills.Noclip;
|
|
private static readonly ConcurrentDictionary<uint, PlayerSkillInfo> SkillPlayerInfo = [];
|
|
private static readonly object setLock = new();
|
|
|
|
public static void LoadSkill()
|
|
{
|
|
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
|
}
|
|
|
|
public static void NewRound()
|
|
{
|
|
lock (setLock)
|
|
SkillPlayerInfo.Clear();
|
|
}
|
|
|
|
public static void OnTick()
|
|
{
|
|
if (!SkillUtils.IsHudFrame()) return;
|
|
foreach (var player in PlayerManager.GetTickPlayers())
|
|
{
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
|
if (playerInfo?.Skill == skillName)
|
|
if (SkillPlayerInfo.TryGetValue(player.Index, out var skillInfo))
|
|
UpdateHUD(player, skillInfo);
|
|
}
|
|
}
|
|
|
|
public static void EnableSkill(CCSPlayerController player)
|
|
{
|
|
SkillPlayerInfo.TryAdd(player.Index, new PlayerSkillInfo
|
|
{
|
|
SteamID = player.Index,
|
|
CanUse = true,
|
|
IsFlying = false,
|
|
Cooldown = DateTime.MinValue,
|
|
LastPosition = null,
|
|
});
|
|
}
|
|
|
|
public static void DisableSkill(CCSPlayerController player)
|
|
{
|
|
SkillPlayerInfo.TryRemove(player.Index, out _);
|
|
SkillUtils.ResetPrintHTML(player);
|
|
}
|
|
|
|
private static void UpdateHUD(CCSPlayerController player, PlayerSkillInfo skillInfo)
|
|
{
|
|
float cooldown = 0;
|
|
float flying = 0;
|
|
if (skillInfo != null)
|
|
{
|
|
float time = (int)Math.Ceiling((skillInfo.Cooldown.AddSeconds(SkillsInfo.GetValue<float>(skillName, "cooldown")) - DateTime.Now).TotalSeconds);
|
|
cooldown = Math.Max(time, 0);
|
|
|
|
float flyingTime = (int)(skillInfo.Cooldown.AddSeconds(SkillsInfo.GetValue<float>(skillName, "duration")) - DateTime.Now).TotalMilliseconds;
|
|
flying = Math.Max(flyingTime, 0);
|
|
|
|
if (cooldown == 0 && skillInfo?.CanUse == false)
|
|
skillInfo.CanUse = true;
|
|
}
|
|
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(player!.Index);
|
|
if (playerInfo == null) return;
|
|
|
|
if (cooldown == 0)
|
|
{
|
|
playerInfo.PrintHTML = null;
|
|
return;
|
|
}
|
|
|
|
playerInfo.PrintHTML =
|
|
skillInfo?.IsFlying == true
|
|
? $"{player.GetTranslation("active_hud_info", $"<font color='#00FF00'>{Math.Round(flying / 100, 2)}</font>")}"
|
|
: $"{player.GetTranslation("hud_info", $"<font color='#FF0000'>{cooldown}</font>")}";
|
|
}
|
|
|
|
public static void UseSkill(CCSPlayerController player)
|
|
{
|
|
var playerPawn = player.PlayerPawn.Value;
|
|
if (playerPawn?.CBodyComponent == null) return;
|
|
|
|
uint playerIndex = player.Index;
|
|
|
|
if (SkillPlayerInfo.TryGetValue(playerIndex, out var skillInfo))
|
|
{
|
|
if (skillInfo.IsFlying)
|
|
{
|
|
StopFlying(player, skillInfo);
|
|
return;
|
|
}
|
|
|
|
if (skillInfo.CanUse)
|
|
{
|
|
var duration = SkillsInfo.GetValue<float>(skillName, "duration");
|
|
|
|
skillInfo.CanUse = false;
|
|
skillInfo.IsFlying = true;
|
|
skillInfo.Cooldown = DateTime.Now;
|
|
skillInfo.LastPosition = playerPawn.AbsOrigin == null ? null : new Vector(playerPawn.AbsOrigin.X, playerPawn.AbsOrigin.Y, playerPawn.AbsOrigin.Z);
|
|
|
|
SetNoclip(player, true);
|
|
skillInfo.Timer?.Kill();
|
|
|
|
skillInfo.Timer = Instance.AddTimer(duration, () =>
|
|
{
|
|
var player = Utilities.GetPlayerFromIndex((int)playerIndex);
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
var playerInfo = PlayerManager.GetPlayerByIndex(playerIndex);
|
|
if (playerInfo == null) return;
|
|
|
|
StopFlying(player, skillInfo);
|
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void SetNoclip(CCSPlayerController player, bool noclip = true)
|
|
{
|
|
if (player == null || !player.IsValid) return;
|
|
|
|
var playerPawn = player.PlayerPawn.Value;
|
|
if (playerPawn == null || !playerPawn.IsValid || player.LifeState != (byte)LifeState_t.LIFE_ALIVE) return;
|
|
|
|
playerPawn.MoveType = noclip ? MoveType_t.MOVETYPE_NOCLIP : MoveType_t.MOVETYPE_WALK;
|
|
Schema.SetSchemaValue(playerPawn.Handle, "CBaseEntity", "m_nActualMoveType", (int)playerPawn.MoveType);
|
|
Utilities.SetStateChanged(playerPawn, "CBaseEntity", "m_MoveType");
|
|
}
|
|
|
|
private static void StopFlying(CCSPlayerController player, PlayerSkillInfo skillInfo)
|
|
{
|
|
skillInfo.Timer?.Kill();
|
|
skillInfo.Timer = null;
|
|
|
|
if (!skillInfo.IsFlying) return;
|
|
skillInfo.IsFlying = false;
|
|
|
|
if (player == null || !player.IsValid || player.LifeState != (byte)LifeState_t.LIFE_ALIVE) return;
|
|
SetNoclip(player, false);
|
|
|
|
var playerPawn = player.PlayerPawn.Value;
|
|
if (playerPawn == null || !playerPawn.IsValid || skillInfo.IsFlying) return;
|
|
|
|
Vector? safePoint = GetCorrectPosition(player, skillInfo);
|
|
playerPawn.Teleport(safePoint ?? skillInfo.LastPosition, null, new Vector(0, 0, 0));
|
|
}
|
|
|
|
private static Vector? GetCorrectPosition(CCSPlayerController player, PlayerSkillInfo skillInfo)
|
|
{
|
|
var playerPawn = player.PlayerPawn.Value;
|
|
if (playerPawn == null || !playerPawn.IsValid || playerPawn.AbsOrigin == null) return null;
|
|
|
|
Vector currentPos = playerPawn.AbsOrigin;
|
|
float offset = 50;
|
|
|
|
Vector[] checkOffsets =
|
|
{
|
|
currentPos,
|
|
currentPos + new Vector(offset, 0, 10),
|
|
currentPos + new Vector(-offset, 0, 10),
|
|
currentPos + new Vector(0, offset, 10),
|
|
currentPos + new Vector(0, -offset, 10),
|
|
|
|
currentPos + new Vector(offset, 0, 60),
|
|
currentPos + new Vector(-offset, 0, 60),
|
|
currentPos + new Vector(0, offset, 60),
|
|
currentPos + new Vector(0, -offset, 60),
|
|
};
|
|
|
|
ulong mask = playerPawn.Collision.CollisionAttribute.InteractsWith;
|
|
ulong contents = playerPawn.Collision.CollisionGroup;
|
|
|
|
bool hasGround = false;
|
|
Vector stuckVector = new(currentPos.X, currentPos.Y, currentPos.Z);
|
|
|
|
foreach (Vector targetPos in checkOffsets)
|
|
{
|
|
Vector start = new(targetPos.X, targetPos.Y, targetPos.Z + 70);
|
|
Vector end = new(targetPos.X, targetPos.Y, targetPos.Z - 1000);
|
|
|
|
var groundResult = RayTrace.TraceShape(player, start, end, mask, contents);
|
|
if (!groundResult.HasValue || !groundResult.Value.DidHit) continue;
|
|
|
|
Vector newPos =
|
|
groundResult.Value.EndPos.Z > targetPos.Z
|
|
? new(groundResult.Value.EndPos.X, groundResult.Value.EndPos.Y, groundResult.Value.EndPos.Z)
|
|
: targetPos;
|
|
|
|
hasGround = true;
|
|
stuckVector = newPos;
|
|
|
|
var result = RayTrace.TraceHullShape(
|
|
targetPos,
|
|
targetPos,
|
|
player
|
|
);
|
|
|
|
if (result.HasValue && !result.Value.DidHit)
|
|
return newPos;
|
|
}
|
|
|
|
if (hasGround)
|
|
skillInfo.Cooldown = DateTime.Now.AddSeconds(-SkillsInfo.GetValue<float>(skillName, "cooldown") + SkillsInfo.GetValue<float>(skillName, "cooldownWhenStuck"));
|
|
return hasGround ? stuckVector : null;
|
|
}
|
|
|
|
public class PlayerSkillInfo
|
|
{
|
|
public ulong SteamID { get; set; }
|
|
public bool CanUse { get; set; }
|
|
public bool IsFlying { get; set; }
|
|
public DateTime Cooldown { get; set; }
|
|
public Vector? LastPosition { get; set; }
|
|
public Timer? Timer { get; set; }
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#44ebd4", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = true, bool needsTeammates = false, string requiredPermission = "", float? hudDuration = null, float? descriptionHudDuration = null, int maxPerServer = -1, Rarity rarity = Rarity.Common, float cooldown = 30f, float duration = 2f, float cooldownWhenStuck = 5f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer, rarity)
|
|
{
|
|
public float Cooldown { get; set; } = cooldown;
|
|
public float CooldownWhenStuck { get; set; } = cooldownWhenStuck;
|
|
public float Duration { get; set; } = duration;
|
|
}
|
|
}
|
|
} |