jRandomSkills/WASDMenuAPI - SRC Files/WASDMenuAPI.cs
ByDexter 25cd8eb989 v1.2.2.b6
Performance & stability pass (issue #34 + audit)

General:
- DisableAll resets only skills active in the previous round instead of all loaded skills (~89ms -> ~5ms)
- Removed per-tick LINQ/allocations, O(1) HUD skill lookups, translation substitutions moved to load time
- ForceFullUpdate creates the network service once per broadcast; view-angle guard only skips a genuine (0,0,0) placeholder
- Debug hooks/logging only active when DebugMode is enabled (single reused writer)
- Player skill state unified to a single collection (fixes a rare disconnect race)
- Gamedata signatures resolved lazily/isolated; hardened tick/transmit paths against invalid handles
- Description HUD honours always-show / -1 duration consistently across all assignment paths

Skills:
- Jester: fixed the no-damage effect leaking after a mid-round skill change (Thief/Deactivator)
- Jackal: fixed trail entities accumulating over a round
- Falcon Eye / Third Eye / Spectator: camera state cleared on disable

Also: added missing translation keys as untranslated markers across language files.

Fixes #34
2026-07-05 21:48:29 +03:00

68 lines
2.2 KiB
C#

using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using WASDMenuAPI.Classes;
namespace WASDMenuAPI;
public class WASDMenuAPI
{
public static string ModuleName => "WASDMenuAPI";
public static string ModuleVersion => "1.0.2";
public static string ModuleAuthor => "Interesting";
public static readonly Dictionary<ulong, WasdMenuPlayer> Players = [];
public static void LoadPlugin(BasePlugin basePlugin, bool hotReload)
{
basePlugin.RegisterEventHandler<EventPlayerActivate>((@event, info) =>
{
if (@event.Userid != null)
Players[@event.Userid.SteamID] = new WasdMenuPlayer
{
Player = @event.Userid,
Buttons = 0
};
return HookResult.Continue;
});
basePlugin.RegisterEventHandler<EventPlayerDisconnect>((@event, info) =>
{
if (@event.Userid != null) Players.Remove(@event.Userid.SteamID);
return HookResult.Continue;
});
basePlugin.RegisterListener<Listeners.OnTick>(OnTick);
if(hotReload)
foreach (var pl in Utilities.GetPlayers())
{
Players[pl.SteamID] = new WasdMenuPlayer
{
Player = pl,
Buttons = pl.Buttons
};
}
}
public static void OnTick()
{
foreach (var player in Players.Values.Where(p => p.MainMenu != null && p.Player?.IsValid == true))
{
if ((player.Buttons & PlayerButtons.Forward) == 0 && (player.Player.Buttons & PlayerButtons.Forward) != 0)
{
player.ScrollUp();
}
else if((player.Buttons & PlayerButtons.Back) == 0 && (player.Player.Buttons & PlayerButtons.Back) != 0)
{
player.ScrollDown();
}
else if((player.Buttons & PlayerButtons.Use) == 0 && (player.Player.Buttons & PlayerButtons.Use) != 0)
{
player.Choose();
}
player.Buttons = player.Player.Buttons;
if (!string.IsNullOrEmpty(player.CenterHtml))
player.Player.PrintToCenterHtml(player.CenterHtml);
}
}
}