## Shared Systems * **DecoyTracker** - owner-aware decoy tracking shared by FrozenDecoy, GravityDecoy and MagneticDecoy, replacing the per-skill position dictionaries. * **DebugCategory** - new flag enum backing the numeric `DebugMode`, with automatic migration from the old boolean value. * **SkillsInfo.GetSkillConfig** - indexed skill config lookup replacing the linear scan used by draws and HUD rendering. * **SkillNames** - cached enum name table, removing repeated `ToString()` calls from the draw path. * **SkillUtils.HideCarriedEntities** - shared carried-weapon resolution for C4Camouflage, Ghost and Ninja. ## Performance * **Skill draw** - replaced the O(n²) config lookup; rounds exceeding the perf threshold dropped from 89% to 0.3%. * **CheckTransmit** - the weapon chain is now resolved once per hidden pawn instead of once per receiver; Ghost cost down 61%. * **Pilot** - the exhaust trail is paused and resumed instead of being destroyed and recreated on every jump release. * **MagneticDecoy** - config reads and the pawn list are hoisted out of the per-decoy loop. * **FrozenDecoy** - config reads are hoisted out of the per-tick loop. * **Debug** - the damage hook is only installed when damage logging is enabled. ## Fixes * **PsychicDefusing** - can no longer finish a defuse and award an extra round after the round has already ended. * **Spectator** - now picks a different enemy on each activation and no longer creates an unused camera prop every time the skill is switched off. * **Random** - replaced the shared `Random` instance with `Random.Shared`, preventing degenerate results from concurrent use. * **Baseball** - decoys are removed when their owner dies or loses the skill. * **FrozenDecoy, GravityDecoy, MagneticDecoy** - decoys and their ground rings are removed when the skill is taken away. * **ThirdEye** - fixed the camera check dereferencing a missing `CameraServices`, and the door toggle now verifies the entity class before casting. * **Round start** - fixed `[gamerules unavailable]` appearing on the first freeze-time end after every map change. * **Config** - added migration for keys missing from existing configuration files. ## Menu * **WASDMenuAPI** - fixed a malformed `<font>` tag that wrapped every non-hovered menu row in an unclosed attribute. * **WSAD menu** - the controls line is no longer dropped when the header line is hidden. * **HtmlHudCustomisation** - line size options left empty now hide their line instead of emitting an invalid font class. ## Debug * **DebugMode** - changed from a boolean to a number with concatenated category digits: `1` Skill, `2` Round, `3` Entity, `4` Damage. `123` enables Skill, Round and Entity. `0` disables logging. Existing `true` values migrate automatically. * **EntityManager** - entity creation, destruction and failures are now logged under the Entity category instead of the server console. * Startup now reports which debug categories are active.
151 lines
No EOL
6.1 KiB
C#
151 lines
No EOL
6.1 KiB
C#
using CounterStrikeSharp.API;
|
|
using CounterStrikeSharp.API.Core;
|
|
using CounterStrikeSharp.API.Modules.Entities;
|
|
using CounterStrikeSharp.API.Modules.Utils;
|
|
using src.utils;
|
|
using System.Collections.Concurrent;
|
|
using System.Drawing;
|
|
|
|
namespace src.player.skills
|
|
{
|
|
public class ThirdEye : ISkill
|
|
{
|
|
private const Skills skillName = Skills.ThirdEye;
|
|
private const string cameraViewModel = "models/sprays/spray_plane.vmdl";
|
|
private static readonly ConcurrentDictionary<uint, (uint, uint)> cameras = [];
|
|
private static readonly object setLock = new();
|
|
|
|
public static void LoadSkill()
|
|
{
|
|
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
|
jRandomSkills.Instance.AddToManifest(cameraViewModel);
|
|
}
|
|
|
|
public static void NewRound()
|
|
{
|
|
foreach (var cameraIndex in cameras.Values)
|
|
EntityManager.DestroyEntity(cameraIndex.Item2);
|
|
|
|
lock (setLock)
|
|
cameras.Clear();
|
|
}
|
|
|
|
public static void UseSkill(CCSPlayerController player)
|
|
{
|
|
var playerPawn = player.PlayerPawn.Value;
|
|
if (playerPawn?.CBodyComponent == null) return;
|
|
ChangeCamera(player);
|
|
}
|
|
|
|
public static void DisableSkill(CCSPlayerController player)
|
|
{
|
|
if (player == null) return;
|
|
ChangeCamera(player, true);
|
|
EntityManager.DestroyPlayerEntities(player.Index);
|
|
cameras.TryRemove(player.Index, out _);
|
|
}
|
|
|
|
public static bool IsOrginalCamera(CCSPlayerController player)
|
|
{
|
|
if (player == null || !player.IsValid) return true;
|
|
|
|
var pawn = player.PlayerPawn?.Value;
|
|
if (pawn == null || !pawn.IsValid) return true;
|
|
|
|
var cameraServices = pawn.CameraServices;
|
|
if (cameraServices == null) return true;
|
|
|
|
if (cameras.TryGetValue(player.Index, out var cameraInfo) && cameraInfo.Item1 != 0)
|
|
return cameraServices.ViewEntity.Raw == cameraInfo.Item1;
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void OnTick()
|
|
{
|
|
foreach (var player in PlayerManager.GetTickPlayers())
|
|
if (cameras.TryGetValue(player.Index, out var cameraInfo) && cameraInfo.Item2 != 0)
|
|
{
|
|
var pawn = player.PlayerPawn.Value;
|
|
if (pawn == null || !pawn.IsValid || pawn.AbsOrigin == null) continue;
|
|
if (pawn.LifeState != (byte)LifeState_t.LIFE_ALIVE)
|
|
{
|
|
ChangeCamera(player, true);
|
|
continue;
|
|
}
|
|
|
|
var pos = pawn.AbsOrigin - SkillUtils.GetForwardVector(pawn.EyeAngles) * SkillsInfo.GetValue<float>(skillName, "distance");
|
|
pos.Z += pawn.ViewOffset.Z;
|
|
|
|
var cam = Utilities.GetEntityFromIndex<CDynamicProp>((int)cameraInfo.Item2);
|
|
if (cam == null || cam.AbsOrigin == null || cam.AbsRotation == null) continue;
|
|
cam.Teleport(pos, pawn.V_angle);
|
|
}
|
|
}
|
|
|
|
private static void ChangeCamera(CCSPlayerController player, bool forceToDefault = false)
|
|
{
|
|
uint orginalCameraRaw;
|
|
uint newCameraRaw;
|
|
var pawn = player.PlayerPawn.Value;
|
|
if (cameras.TryGetValue(player.Index, out var cameraInfo) && cameraInfo.Item2 != 0)
|
|
{
|
|
orginalCameraRaw = cameraInfo.Item1;
|
|
|
|
var cam = Utilities.GetEntityFromIndex<CDynamicProp>((int)cameraInfo.Item2);
|
|
if (cam == null || !cam.IsValid) return;
|
|
|
|
newCameraRaw = cam.EntityHandle.Raw;
|
|
}
|
|
else
|
|
{
|
|
orginalCameraRaw = pawn!.CameraServices!.ViewEntity.Raw;
|
|
newCameraRaw = CreateCamera(player);
|
|
}
|
|
|
|
if (newCameraRaw == 0)
|
|
return;
|
|
|
|
if (forceToDefault)
|
|
pawn!.CameraServices!.ViewEntity.Raw = orginalCameraRaw;
|
|
else
|
|
pawn!.CameraServices!.ViewEntity.Raw =
|
|
pawn.CameraServices!.ViewEntity!.Raw == orginalCameraRaw
|
|
? newCameraRaw
|
|
: orginalCameraRaw;
|
|
Utilities.SetStateChanged(pawn, "CBasePlayerPawn", "m_pCameraServices");
|
|
}
|
|
|
|
private static uint CreateCamera(CCSPlayerController player)
|
|
{
|
|
var camera = EntityManager.CreateTrackedDynamicProp(player.Index);
|
|
if (camera == null || !camera.IsValid) return 0;
|
|
|
|
var pawn = player.PlayerPawn.Value;
|
|
if (pawn == null) return 0;
|
|
|
|
Server.NextFrame(() =>
|
|
{
|
|
if (camera == null || !camera.IsValid) return;
|
|
if (pawn == null || !pawn.IsValid || pawn.AbsOrigin == null) return;
|
|
|
|
var camNode = camera.CBodyComponent?.SceneNode?.Owner?.Entity;
|
|
if (camNode != null)
|
|
camNode.Flags = (uint)(camNode.Flags & ~(1 << 2));
|
|
|
|
camera.SetModel(cameraViewModel);
|
|
camera.Render = Color.FromArgb(0, 255, 255, 255);
|
|
camera.Teleport(pawn.AbsOrigin, pawn.EyeAngles);
|
|
camera.DispatchSpawn();
|
|
});
|
|
|
|
cameras.AddOrUpdate(player.Index, (pawn.CameraServices!.ViewEntity.Raw, camera.Index), (v, k) => (pawn.CameraServices!.ViewEntity.Raw, camera.Index));
|
|
return camera.EntityHandle.Raw;
|
|
}
|
|
|
|
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#1b04cc", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", float? hudDuration = null, float? descriptionHudDuration = null, int maxPerServer = -1, Rarity rarity = Rarity.Common, float distance = 100f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission, hudDuration, descriptionHudDuration, maxPerServer, rarity)
|
|
{
|
|
public float Distance { get; set; } = distance;
|
|
}
|
|
}
|
|
} |