From 9808ab3360b818e4a57e4eda6b027d10e2727a43 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 3 Nov 2023 20:42:58 +0100 Subject: [PATCH 1/2] fix for defuse time needed --- CS2InstantDefuse/CS2InstantDefuse.cs | 60 ++++++++++++++++------------ 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/CS2InstantDefuse/CS2InstantDefuse.cs b/CS2InstantDefuse/CS2InstantDefuse.cs index 42c63c7..a4558cc 100644 --- a/CS2InstantDefuse/CS2InstantDefuse.cs +++ b/CS2InstantDefuse/CS2InstantDefuse.cs @@ -18,10 +18,10 @@ public class CS2InstantDefuse : BasePlugin private float _bombPlantedTime = float.NaN; private bool _bombTicking = false; - private int _molotovThread = 0; - private int _heThread = 0; + private int _molotovThreat = 0; + private int _heThreat = 0; - private List _infernoThread = new List(); + private List _infernoThreat = new List(); public override void Load(bool hotReload) { @@ -46,22 +46,26 @@ public override void Load(bool hotReload) [GameEventHandler] private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) { - if(@event.Weapon == "smokegrenade" || @event.Weapon == "flashbang" || @event.Weapon == "decoy") + this.Log($"OnGrenadeThrown: {@event.Weapon} - isBot: {@event.Userid?.IsBot}"); + + if (@event.Weapon == "smokegrenade" || @event.Weapon == "flashbang" || @event.Weapon == "decoy") { return HookResult.Continue; } if(@event.Weapon == "hegrenade") { - this._heThread++; + this._heThreat++; } if(@event.Weapon == "incgrenade" || @event.Weapon == "molotov") { - this._molotovThread++; + this._molotovThreat++; } - this.PrintThreadLevel(); + + + this.PrintThreatLevel(); return HookResult.Continue; } @@ -94,9 +98,9 @@ private HookResult OnInfernoStartBurn(EventInfernoStartburn @event, GameEventInf return HookResult.Continue; } - this._infernoThread.Add(@event.Entityid); + this._infernoThreat.Add(@event.Entityid); - this.PrintThreadLevel(); + this.PrintThreatLevel(); return HookResult.Continue; } @@ -104,9 +108,9 @@ private HookResult OnInfernoStartBurn(EventInfernoStartburn @event, GameEventInf [GameEventHandler] private HookResult OnInfernoExtinguish(EventInfernoExtinguish @event, GameEventInfo info) { - this._infernoThread.Remove(@event.Entityid); + this._infernoThreat.Remove(@event.Entityid); - this.PrintThreadLevel(); + this.PrintThreatLevel(); return HookResult.Continue; } @@ -114,9 +118,9 @@ private HookResult OnInfernoExtinguish(EventInfernoExtinguish @event, GameEventI [GameEventHandler] private HookResult OnInfernoExpire(EventInfernoExpire @event, GameEventInfo info) { - this._infernoThread.Remove(@event.Entityid); + this._infernoThreat.Remove(@event.Entityid); - this.PrintThreadLevel(); + this.PrintThreatLevel(); return HookResult.Continue; } @@ -124,9 +128,9 @@ private HookResult OnInfernoExpire(EventInfernoExpire @event, GameEventInfo info [GameEventHandler] private HookResult OnHeGrenadeDetonate(EventHegrenadeDetonate @event, GameEventInfo info) { - this._heThread--; + this._heThreat--; - this.PrintThreadLevel(); + this.PrintThreatLevel(); return HookResult.Continue; } @@ -134,9 +138,9 @@ private HookResult OnHeGrenadeDetonate(EventHegrenadeDetonate @event, GameEventI [GameEventHandler] private HookResult OnMolotovDetonate(EventMolotovDetonate @event, GameEventInfo info) { - this._molotovThread--; + this._molotovThreat--; - this.PrintThreadLevel(); + this.PrintThreatLevel(); return HookResult.Continue; } @@ -148,9 +152,9 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) this._bombPlantedTime = float.NaN; this._bombTicking = false; - this._heThread = 0; - this._molotovThread = 0; - this._infernoThread = new List(); + this._heThreat = 0; + this._molotovThreat = 0; + this._infernoThreat = new List(); return HookResult.Continue; } @@ -193,9 +197,9 @@ private bool TryInstantDefuse(CCSPlayerController player) return false; } - this.PrintThreadLevel(); + this.PrintThreatLevel(); - if(this._heThread != 0 || this._molotovThread != 0 || this._infernoThread.Any()) + if(this._heThreat > 0 || this._molotovThreat > 0 || this._infernoThreat.Any()) { Server.PrintToChatAll($"Instant Defuse not possible because a grenade thread is active!"); this.Log($"Instant Defuse not possible because a grenade thread is active!"); @@ -223,7 +227,13 @@ private bool TryInstantDefuse(CCSPlayerController player) var bombTimeUntilDetonation = plantedBomb.TimerLength - (Server.CurrentTime - this._bombPlantedTime); - bool bombCanBeDefusedInTime = (bombTimeUntilDetonation - plantedBomb.DefuseLength) >= 0.0f; + var defuseLength = plantedBomb.DefuseLength; + if(defuseLength != 5 && defuseLength != 10) + { + defuseLength = player.PawnHasDefuser ? 5 : 10; + } + + bool bombCanBeDefusedInTime = (bombTimeUntilDetonation - defuseLength) >= 0.0f; if(!bombCanBeDefusedInTime) { @@ -272,9 +282,9 @@ private bool TeamHasAlivePlayers(CsTeam team) return plantedBombList.FirstOrDefault(); } - private void PrintThreadLevel() + private void PrintThreatLevel() { - this.Log($"Thread-Levels: HE [{this._heThread}], Molotov [{this._molotovThread}], Inferno [{this._infernoThread.Count}]"); + this.Log($"Threat-Levels: HE [{this._heThreat}], Molotov [{this._molotovThreat}], Inferno [{this._infernoThreat.Count}]"); } private string PluginInfo() From 96ff38a33a94036bc19969c764f29608612c3981 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 3 Nov 2023 21:20:19 +0100 Subject: [PATCH 2/2] Fixed bomb defuse without enough time left Should also have fixed Issue #3 --- CS2InstantDefuse/CS2InstantDefuse.cs | 39 +++++++++++++++++++++------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/CS2InstantDefuse/CS2InstantDefuse.cs b/CS2InstantDefuse/CS2InstantDefuse.cs index a4558cc..fa021c8 100644 --- a/CS2InstantDefuse/CS2InstantDefuse.cs +++ b/CS2InstantDefuse/CS2InstantDefuse.cs @@ -12,7 +12,7 @@ namespace CS2InstantDefuse public class CS2InstantDefuse : BasePlugin { public override string ModuleName => "CS2InstantDefuse"; - public override string ModuleVersion => "1.0.0"; + public override string ModuleVersion => "1.0.1"; public override string ModuleAuthor => "LordFetznschaedl"; public override string ModuleDescription => "Simple Plugin that allowes the bomb to be instantly defused when no enemy is alive and no utility is in use"; @@ -40,13 +40,29 @@ public override void Load(bool hotReload) this.RegisterEventHandler(OnHeGrenadeDetonate); this.RegisterEventHandler(OnMolotovDetonate); + + // Comment in if you need to debug the defuse stuff. + //this.RegisterEventHandler(OnBombBeep); + } + + [GameEventHandler] + private HookResult OnBombBeep(EventBombBeep @event, GameEventInfo info) + { + var plantedBomb = this.FindPlantedBomb(); + if (plantedBomb == null) + { + this.Log("Planted bomb is null!"); + return HookResult.Continue; + } + + Server.PrintToChatAll($"{plantedBomb.TimerLength - (Server.CurrentTime - this._bombPlantedTime)}"); + return HookResult.Continue; } - [GameEventHandler] private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) { - this.Log($"OnGrenadeThrown: {@event.Weapon} - isBot: {@event.Userid?.IsBot}"); + //this.Log($"OnGrenadeThrown: {@event.Weapon} - isBot: {@event.Userid?.IsBot}"); if (@event.Weapon == "smokegrenade" || @event.Weapon == "flashbang" || @event.Weapon == "decoy") { @@ -63,8 +79,6 @@ private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info this._molotovThreat++; } - - this.PrintThreatLevel(); return HookResult.Continue; @@ -128,7 +142,10 @@ private HookResult OnInfernoExpire(EventInfernoExpire @event, GameEventInfo info [GameEventHandler] private HookResult OnHeGrenadeDetonate(EventHegrenadeDetonate @event, GameEventInfo info) { - this._heThreat--; + if(this._heThreat > 0) + { + this._heThreat--; + } this.PrintThreatLevel(); @@ -138,7 +155,10 @@ private HookResult OnHeGrenadeDetonate(EventHegrenadeDetonate @event, GameEventI [GameEventHandler] private HookResult OnMolotovDetonate(EventMolotovDetonate @event, GameEventInfo info) { - this._molotovThreat--; + if (this._molotovThreat > 0) + { + this._molotovThreat--; + } this.PrintThreatLevel(); @@ -201,8 +221,8 @@ private bool TryInstantDefuse(CCSPlayerController player) if(this._heThreat > 0 || this._molotovThreat > 0 || this._infernoThreat.Any()) { - Server.PrintToChatAll($"Instant Defuse not possible because a grenade thread is active!"); - this.Log($"Instant Defuse not possible because a grenade thread is active!"); + Server.PrintToChatAll($"Instant Defuse not possible because a grenade threat is active!"); + this.Log($"Instant Defuse not possible because a grenade threat is active!"); return false; } @@ -232,6 +252,7 @@ private bool TryInstantDefuse(CCSPlayerController player) { defuseLength = player.PawnHasDefuser ? 5 : 10; } + this.Log($"DefuseLength: {defuseLength}"); bool bombCanBeDefusedInTime = (bombTimeUntilDetonation - defuseLength) >= 0.0f;