Warmup-safe skill assignment, PerfLog header

- Treat null GameRules as "not ready" so skills are never assigned during
  warmup right after plugin load/hot-reload (SetSkill + RoundStart)
- PerfLog writes a header line on first measurement so the perf file
  appears immediately when PerfMode is active
This commit is contained in:
ByDexter 2026-07-06 03:30:59 +03:00
parent b68a033b4c
commit 380d2ca731
5 changed files with 22 additions and 3 deletions

View file

@ -71,7 +71,9 @@
<Message Text="Copying compiled DLL from $(SourceDLL) to $(ServerDLL)" Importance="High" /> <Message Text="Copying compiled DLL from $(SourceDLL) to $(ServerDLL)" Importance="High" />
<ItemGroup> <ItemGroup>
<CompiledDLL Include="$(SourceDLL)\jRandomSkills.dll" /> <CompiledDLL Include="$(SourceDLL)\jRandomSkills.dll" />
<CompiledDLL Include="$(SourceDLL)\jRandomSkills.pdb" />
<CompiledDLL Include="$(SourceDLL)\WASDMenuAPI.dll" /> <CompiledDLL Include="$(SourceDLL)\WASDMenuAPI.dll" />
<CompiledDLL Include="$(SourceDLL)\WASDMenuAPI.pdb" />
<CompiledDLL Include="$(SourceDLL)\MaxMind.Db.dll" /> <CompiledDLL Include="$(SourceDLL)\MaxMind.Db.dll" />
<CompiledDLL Include="$(SourceDLL)\Newtonsoft.Json.dll" /> <CompiledDLL Include="$(SourceDLL)\Newtonsoft.Json.dll" />
</ItemGroup> </ItemGroup>

View file

@ -14,7 +14,22 @@ namespace src.player
public static bool Enabled => Config.LoadedConfig.PerfMode; public static bool Enabled => Config.LoadedConfig.PerfMode;
public static long Start() => Enabled ? Stopwatch.GetTimestamp() : 0; private static bool _headerWritten;
public static long Start()
{
if (!Enabled) return 0;
// Write a header on the first measurement so the perf file appears immediately
// when PerfMode is active - makes "is it working?" instantly visible.
if (!_headerWritten)
{
_headerWritten = true;
Write($"PerfMode enabled (plugin v{Instance.ModuleVersion})");
}
return Stopwatch.GetTimestamp();
}
// One-shot measurement: logs "label took X.XXms" when the elapsed time reaches the threshold. // One-shot measurement: logs "label took X.XXms" when the elapsed time reaches the threshold.
public static void End(string label, long startTimestamp, double thresholdMs = 1.0) public static void End(string label, long startTimestamp, double thresholdMs = 1.0)

View file

@ -595,7 +595,7 @@ namespace src.player
{ {
lock (setLock) lock (setLock)
{ {
bool isWarmup = Instance.GameRules != null && Instance.GameRules.WarmupPeriod == true; bool isWarmup = Instance.GameRules == null || Instance.GameRules.WarmupPeriod == true;
isTransmitRegistered = false; isTransmitRegistered = false;
Instance.AddTimer(.1f, () => DisableAll(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); Instance.AddTimer(.1f, () => DisableAll(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
@ -877,7 +877,9 @@ namespace src.player
{ {
if (Instance == null) return; if (Instance == null) return;
if (Instance.GameRules != null && Instance.GameRules.WarmupPeriod == true) // GameRules can be null for a short window right after plugin load/hot-reload;
// treat that as "not ready" so skills are never assigned during warmup by accident.
if (Instance.GameRules == null || Instance.GameRules.WarmupPeriod == true)
{ {
setSkillTimer?.Kill(); setSkillTimer?.Kill();
return; return;