From bfd359bfccfb71d56438cdf7af5d315f2336abf0 Mon Sep 17 00:00:00 2001 From: MSWS Date: Fri, 2 Feb 2024 18:21:20 -0800 Subject: [PATCH 01/27] Bump version --- src/Jailbreak/Jailbreak.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jailbreak/Jailbreak.cs b/src/Jailbreak/Jailbreak.cs index 1eb90d25..dc607697 100644 --- a/src/Jailbreak/Jailbreak.cs +++ b/src/Jailbreak/Jailbreak.cs @@ -16,7 +16,7 @@ namespace Jailbreak; public class Jailbreak : BasePlugin { public override string ModuleName => "Jailbreak"; - public override string ModuleVersion => "0.1.0.{GIT_VERSION}"; + public override string ModuleVersion => "0.2.0.{GIT_VERSION}"; public override string ModuleAuthor => "EdgeGamers Development"; private IServiceProvider _provider; From 4986723510f0b65c0a6cf7d6fd75ff14184ba56e Mon Sep 17 00:00:00 2001 From: MSWS Date: Fri, 2 Feb 2024 22:57:34 -0800 Subject: [PATCH 02/27] Add rebel module --- Jailbreak.sln | 7 ++ mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj | 14 +++ mod/Jailbreak.Rebel/RebelListener.cs | 41 +++++++ mod/Jailbreak.Rebel/RebelManager.cs | 100 ++++++++++++++++++ mod/Jailbreak.Rebel/RebelServiceExtension.cs | 16 +++ .../Mod/Rebel/IRebelService.cs | 19 ++++ src/Jailbreak/Jailbreak.csproj | 1 + src/Jailbreak/JailbreakServiceCollection.cs | 1 + 8 files changed, 199 insertions(+) create mode 100644 mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj create mode 100644 mod/Jailbreak.Rebel/RebelListener.cs create mode 100644 mod/Jailbreak.Rebel/RebelManager.cs create mode 100644 mod/Jailbreak.Rebel/RebelServiceExtension.cs create mode 100644 public/Jailbreak.Public/Mod/Rebel/IRebelService.cs diff --git a/Jailbreak.sln b/Jailbreak.sln index 9570efb8..30f97c74 100644 --- a/Jailbreak.sln +++ b/Jailbreak.sln @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang", "lang", "{CDCDE44E-0 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.English", "lang\Jailbreak.English\Jailbreak.English.csproj", "{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Rebel", "mod\Jailbreak.Rebel\Jailbreak.Rebel.csproj", "{CB2391A1-6CDD-496F-B8D6-674FD6268038}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -56,6 +58,10 @@ Global {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.Build.0 = Release|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581} @@ -65,5 +71,6 @@ Global {28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} {446E0B6F-E4FE-45E6-BD9B-BD943698327A} = {59311734-3648-43C2-B43C-385718B0D103} {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF} = {CDCDE44E-01D2-4B76-99DA-A57E1E956038} + {CB2391A1-6CDD-496F-B8D6-674FD6268038} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} EndGlobalSection EndGlobal diff --git a/mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj b/mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj new file mode 100644 index 00000000..128ff34e --- /dev/null +++ b/mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + + diff --git a/mod/Jailbreak.Rebel/RebelListener.cs b/mod/Jailbreak.Rebel/RebelListener.cs new file mode 100644 index 00000000..a8f82b8b --- /dev/null +++ b/mod/Jailbreak.Rebel/RebelListener.cs @@ -0,0 +1,41 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Rebel; + +namespace Jailbreak.Teams; + +public class RebelListener : IPluginBehavior +{ + private IRebelService _rebelService; + + public RebelListener(IRebelService rebelService) + { + _rebelService = rebelService; + } + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnPlayerHurt); + } + + HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsValid) + return HookResult.Continue; + if (player.GetTeam() != CsTeam.CounterTerrorist) + return HookResult.Continue; + + var attacker = @event.Attacker; + if (!attacker.IsValid) + return HookResult.Continue; + + if (attacker.GetTeam() != CsTeam.Terrorist) + return HookResult.Continue; + + _rebelService.MarkRebel(attacker, 120); + return HookResult.Continue; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs new file mode 100644 index 00000000..15b46289 --- /dev/null +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -0,0 +1,100 @@ +using System.Drawing; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Rebel; + +namespace Jailbreak.Teams; + +public class RebelManager : IPluginBehavior, IRebelService +{ + private Dictionary rebelTimes = new(); + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnPlayerDisconnect); + + parent.AddTimer(1f, () => + { + foreach (var player in GetActiveRebels()) + { + if (!player.IsValid) + continue; + + if (GetRebelTimeLeft(player) <= 0) + { + UnmarkRebel(player); + continue; + } + + ApplyRebelColor(player); + } + }); + } + + HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) + { + if (rebelTimes.ContainsKey(@event.Userid)) + { + rebelTimes.Remove(@event.Userid); + } + + return HookResult.Continue; + } + + public ISet GetActiveRebels() + { + return rebelTimes.Keys.ToHashSet(); + } + + public float GetRebelTimeLeft(CCSPlayerController player) + { + if (rebelTimes.TryGetValue(player, out float time)) + { + return time - DateTime.Now.Ticks / 1000f; + } + + return 0; + } + + public bool MarkRebel(CCSPlayerController player, float time) + { + rebelTimes.Add(player, DateTime.Now.Ticks / 1000f + time); + ApplyRebelColor(player); + return true; + } + + public void UnmarkRebel(CCSPlayerController player) + { + player.PrintToChat("You are no longer a rebel"); + rebelTimes.Remove(player); + ApplyRebelColor(player); + } + + // https://www.desmos.com/calculator/g2v6vvg7ax + private float GetRebelTimePercentage(CCSPlayerController player) + { + float x = GetRebelTimeLeft(player); + if (x > 120) + return 1; + if (x <= 0) + return 0; + return (float)(100 - (120 - x) * (Math.Sqrt(120 - x)) / 13f) / 100; + } + + private void ApplyRebelColor(CCSPlayerController player) + { + if (!player.IsValid || player.Pawn.Value == null) + return; + var percentage = GetRebelTimePercentage(player); + var inverse = 1 - percentage; + var inverseInt = (int)(inverse * 255); + var color = Color.FromArgb(254, (int)percentage * 255, inverseInt, inverseInt); + if (percentage <= 0) + { + color = Color.FromArgb(254, 255, 255, 255); + } + + player.Pawn.Value.Render = color; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/RebelServiceExtension.cs b/mod/Jailbreak.Rebel/RebelServiceExtension.cs new file mode 100644 index 00000000..057552e1 --- /dev/null +++ b/mod/Jailbreak.Rebel/RebelServiceExtension.cs @@ -0,0 +1,16 @@ +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Rebel; +using Jailbreak.Public.Mod.Teams; + +using Microsoft.Extensions.DependencyInjection; + +namespace Jailbreak.Teams; + +public static class RebelServiceExtension +{ + public static void AddJailbreakRebel(this IServiceCollection collection) + { + collection.AddPluginBehavior(); + collection.AddPluginBehavior(); + } +} diff --git a/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs b/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs new file mode 100644 index 00000000..f1fba6a5 --- /dev/null +++ b/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs @@ -0,0 +1,19 @@ +using CounterStrikeSharp.API.Core; + +namespace Jailbreak.Public.Mod.Rebel; + +public interface IRebelService +{ + ISet GetActiveRebels(); + + bool IsRebel(CCSPlayerController player) + { + return GetRebelTimeLeft(player) > 0; + } + + float GetRebelTimeLeft(CCSPlayerController player); + + bool MarkRebel(CCSPlayerController player, float time); + + void UnmarkRebel(CCSPlayerController player); +} \ No newline at end of file diff --git a/src/Jailbreak/Jailbreak.csproj b/src/Jailbreak/Jailbreak.csproj index 0a0c71f4..212d15e7 100644 --- a/src/Jailbreak/Jailbreak.csproj +++ b/src/Jailbreak/Jailbreak.csproj @@ -35,6 +35,7 @@ + diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 30322612..4f70c9df 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -32,6 +32,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) serviceCollection.AddJailbreakGeneric(); serviceCollection.AddJailbreakWarden(); serviceCollection.AddJailbreakTeams(); + serviceCollection.AddJailbreakRebel(); // Add in english localization serviceCollection.AddLanguage(config => From b08f51bf161bd2bf63c0d0103be8c2ebeb3b2927 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 13:27:40 -0800 Subject: [PATCH 03/27] Merge feat/rebel --- Jailbreak.sln | 7 ++ mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj | 14 +++ mod/Jailbreak.Rebel/RebelListener.cs | 41 +++++++ mod/Jailbreak.Rebel/RebelManager.cs | 100 ++++++++++++++++++ mod/Jailbreak.Rebel/RebelServiceExtension.cs | 16 +++ .../Mod/Rebel/IRebelService.cs | 19 ++++ src/Jailbreak/Jailbreak.csproj | 1 + src/Jailbreak/JailbreakServiceCollection.cs | 1 + 8 files changed, 199 insertions(+) create mode 100644 mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj create mode 100644 mod/Jailbreak.Rebel/RebelListener.cs create mode 100644 mod/Jailbreak.Rebel/RebelManager.cs create mode 100644 mod/Jailbreak.Rebel/RebelServiceExtension.cs create mode 100644 public/Jailbreak.Public/Mod/Rebel/IRebelService.cs diff --git a/Jailbreak.sln b/Jailbreak.sln index 9570efb8..30f97c74 100644 --- a/Jailbreak.sln +++ b/Jailbreak.sln @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lang", "lang", "{CDCDE44E-0 EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.English", "lang\Jailbreak.English\Jailbreak.English.csproj", "{FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Rebel", "mod\Jailbreak.Rebel\Jailbreak.Rebel.csproj", "{CB2391A1-6CDD-496F-B8D6-674FD6268038}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -56,6 +58,10 @@ Global {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Debug|Any CPU.Build.0 = Debug|Any CPU {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.ActiveCfg = Release|Any CPU {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF}.Release|Any CPU.Build.0 = Release|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581} @@ -65,5 +71,6 @@ Global {28EE05E4-8FE3-4CC6-AA03-0C533EFBFBF2} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} {446E0B6F-E4FE-45E6-BD9B-BD943698327A} = {59311734-3648-43C2-B43C-385718B0D103} {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF} = {CDCDE44E-01D2-4B76-99DA-A57E1E956038} + {CB2391A1-6CDD-496F-B8D6-674FD6268038} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} EndGlobalSection EndGlobal diff --git a/mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj b/mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj new file mode 100644 index 00000000..128ff34e --- /dev/null +++ b/mod/Jailbreak.Rebel/Jailbreak.Rebel.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + + diff --git a/mod/Jailbreak.Rebel/RebelListener.cs b/mod/Jailbreak.Rebel/RebelListener.cs new file mode 100644 index 00000000..a8f82b8b --- /dev/null +++ b/mod/Jailbreak.Rebel/RebelListener.cs @@ -0,0 +1,41 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Rebel; + +namespace Jailbreak.Teams; + +public class RebelListener : IPluginBehavior +{ + private IRebelService _rebelService; + + public RebelListener(IRebelService rebelService) + { + _rebelService = rebelService; + } + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnPlayerHurt); + } + + HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsValid) + return HookResult.Continue; + if (player.GetTeam() != CsTeam.CounterTerrorist) + return HookResult.Continue; + + var attacker = @event.Attacker; + if (!attacker.IsValid) + return HookResult.Continue; + + if (attacker.GetTeam() != CsTeam.Terrorist) + return HookResult.Continue; + + _rebelService.MarkRebel(attacker, 120); + return HookResult.Continue; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs new file mode 100644 index 00000000..15b46289 --- /dev/null +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -0,0 +1,100 @@ +using System.Drawing; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Rebel; + +namespace Jailbreak.Teams; + +public class RebelManager : IPluginBehavior, IRebelService +{ + private Dictionary rebelTimes = new(); + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnPlayerDisconnect); + + parent.AddTimer(1f, () => + { + foreach (var player in GetActiveRebels()) + { + if (!player.IsValid) + continue; + + if (GetRebelTimeLeft(player) <= 0) + { + UnmarkRebel(player); + continue; + } + + ApplyRebelColor(player); + } + }); + } + + HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) + { + if (rebelTimes.ContainsKey(@event.Userid)) + { + rebelTimes.Remove(@event.Userid); + } + + return HookResult.Continue; + } + + public ISet GetActiveRebels() + { + return rebelTimes.Keys.ToHashSet(); + } + + public float GetRebelTimeLeft(CCSPlayerController player) + { + if (rebelTimes.TryGetValue(player, out float time)) + { + return time - DateTime.Now.Ticks / 1000f; + } + + return 0; + } + + public bool MarkRebel(CCSPlayerController player, float time) + { + rebelTimes.Add(player, DateTime.Now.Ticks / 1000f + time); + ApplyRebelColor(player); + return true; + } + + public void UnmarkRebel(CCSPlayerController player) + { + player.PrintToChat("You are no longer a rebel"); + rebelTimes.Remove(player); + ApplyRebelColor(player); + } + + // https://www.desmos.com/calculator/g2v6vvg7ax + private float GetRebelTimePercentage(CCSPlayerController player) + { + float x = GetRebelTimeLeft(player); + if (x > 120) + return 1; + if (x <= 0) + return 0; + return (float)(100 - (120 - x) * (Math.Sqrt(120 - x)) / 13f) / 100; + } + + private void ApplyRebelColor(CCSPlayerController player) + { + if (!player.IsValid || player.Pawn.Value == null) + return; + var percentage = GetRebelTimePercentage(player); + var inverse = 1 - percentage; + var inverseInt = (int)(inverse * 255); + var color = Color.FromArgb(254, (int)percentage * 255, inverseInt, inverseInt); + if (percentage <= 0) + { + color = Color.FromArgb(254, 255, 255, 255); + } + + player.Pawn.Value.Render = color; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/RebelServiceExtension.cs b/mod/Jailbreak.Rebel/RebelServiceExtension.cs new file mode 100644 index 00000000..057552e1 --- /dev/null +++ b/mod/Jailbreak.Rebel/RebelServiceExtension.cs @@ -0,0 +1,16 @@ +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Rebel; +using Jailbreak.Public.Mod.Teams; + +using Microsoft.Extensions.DependencyInjection; + +namespace Jailbreak.Teams; + +public static class RebelServiceExtension +{ + public static void AddJailbreakRebel(this IServiceCollection collection) + { + collection.AddPluginBehavior(); + collection.AddPluginBehavior(); + } +} diff --git a/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs b/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs new file mode 100644 index 00000000..f1fba6a5 --- /dev/null +++ b/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs @@ -0,0 +1,19 @@ +using CounterStrikeSharp.API.Core; + +namespace Jailbreak.Public.Mod.Rebel; + +public interface IRebelService +{ + ISet GetActiveRebels(); + + bool IsRebel(CCSPlayerController player) + { + return GetRebelTimeLeft(player) > 0; + } + + float GetRebelTimeLeft(CCSPlayerController player); + + bool MarkRebel(CCSPlayerController player, float time); + + void UnmarkRebel(CCSPlayerController player); +} \ No newline at end of file diff --git a/src/Jailbreak/Jailbreak.csproj b/src/Jailbreak/Jailbreak.csproj index 0a0c71f4..212d15e7 100644 --- a/src/Jailbreak/Jailbreak.csproj +++ b/src/Jailbreak/Jailbreak.csproj @@ -35,6 +35,7 @@ + diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 30322612..4f70c9df 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -32,6 +32,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) serviceCollection.AddJailbreakGeneric(); serviceCollection.AddJailbreakWarden(); serviceCollection.AddJailbreakTeams(); + serviceCollection.AddJailbreakRebel(); // Add in english localization serviceCollection.AddLanguage(config => From f47f249b24609d20b18ab3a4d3fd3be5f8f4c6e3 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 14:15:05 -0800 Subject: [PATCH 04/27] Fix dict functions, add repeat flag --- mod/Jailbreak.Rebel/RebelManager.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 15b46289..4d680e3a 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -1,6 +1,7 @@ using System.Drawing; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Timers; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Rebel; @@ -29,7 +30,7 @@ public void Start(BasePlugin parent) ApplyRebelColor(player); } - }); + }, TimerFlags.REPEAT); } HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) @@ -59,7 +60,7 @@ public float GetRebelTimeLeft(CCSPlayerController player) public bool MarkRebel(CCSPlayerController player, float time) { - rebelTimes.Add(player, DateTime.Now.Ticks / 1000f + time); + rebelTimes[player] = DateTime.Now.Ticks / 1000f + time; ApplyRebelColor(player); return true; } @@ -87,6 +88,7 @@ private void ApplyRebelColor(CCSPlayerController player) if (!player.IsValid || player.Pawn.Value == null) return; var percentage = GetRebelTimePercentage(player); + player.PrintToConsole("Rebel percentage: " + percentage); var inverse = 1 - percentage; var inverseInt = (int)(inverse * 255); var color = Color.FromArgb(254, (int)percentage * 255, inverseInt, inverseInt); From 53fd5e9cd047b61fe28749ea95e430465603731a Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 14:22:28 -0800 Subject: [PATCH 05/27] Fix types --- mod/Jailbreak.Rebel/RebelManager.cs | 14 +++++++------- public/Jailbreak.Public/Mod/Rebel/IRebelService.cs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 4d680e3a..b0c9fd30 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -9,7 +9,7 @@ namespace Jailbreak.Teams; public class RebelManager : IPluginBehavior, IRebelService { - private Dictionary rebelTimes = new(); + private Dictionary rebelTimes = new(); public void Start(BasePlugin parent) { @@ -48,19 +48,19 @@ public ISet GetActiveRebels() return rebelTimes.Keys.ToHashSet(); } - public float GetRebelTimeLeft(CCSPlayerController player) + public long GetRebelTimeLeft(CCSPlayerController player) { - if (rebelTimes.TryGetValue(player, out float time)) + if (rebelTimes.TryGetValue(player, out long time)) { - return time - DateTime.Now.Ticks / 1000f; + return time - DateTimeOffset.Now.ToUnixTimeSeconds(); } return 0; } - public bool MarkRebel(CCSPlayerController player, float time) + public bool MarkRebel(CCSPlayerController player, long time) { - rebelTimes[player] = DateTime.Now.Ticks / 1000f + time; + rebelTimes[player] = DateTimeOffset.Now.ToUnixTimeSeconds() + time; ApplyRebelColor(player); return true; } @@ -75,7 +75,7 @@ public void UnmarkRebel(CCSPlayerController player) // https://www.desmos.com/calculator/g2v6vvg7ax private float GetRebelTimePercentage(CCSPlayerController player) { - float x = GetRebelTimeLeft(player); + long x = GetRebelTimeLeft(player); if (x > 120) return 1; if (x <= 0) diff --git a/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs b/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs index f1fba6a5..87363d8c 100644 --- a/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs +++ b/public/Jailbreak.Public/Mod/Rebel/IRebelService.cs @@ -11,9 +11,9 @@ bool IsRebel(CCSPlayerController player) return GetRebelTimeLeft(player) > 0; } - float GetRebelTimeLeft(CCSPlayerController player); + long GetRebelTimeLeft(CCSPlayerController player); - bool MarkRebel(CCSPlayerController player, float time); + bool MarkRebel(CCSPlayerController player, long time); void UnmarkRebel(CCSPlayerController player); } \ No newline at end of file From 0cdae59da0c126f1c7ee33824b8da02b9416dfd6 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 14:35:28 -0800 Subject: [PATCH 06/27] Debug color --- mod/Jailbreak.Rebel/RebelManager.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index b0c9fd30..837586d6 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -1,4 +1,5 @@ using System.Drawing; +using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Timers; @@ -14,6 +15,7 @@ public class RebelManager : IPluginBehavior, IRebelService public void Start(BasePlugin parent) { parent.RegisterEventHandler(OnPlayerDisconnect); + parent.RegisterEventHandler(OnRoundStart); parent.AddTimer(1f, () => { @@ -33,6 +35,16 @@ public void Start(BasePlugin parent) }, TimerFlags.REPEAT); } + private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) + { + rebelTimes.Clear(); + foreach (var player in Utilities.GetPlayers()) + { + ApplyRebelColor(player); + } + return HookResult.Continue; + } + HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) { if (rebelTimes.ContainsKey(@event.Userid)) @@ -92,11 +104,13 @@ private void ApplyRebelColor(CCSPlayerController player) var inverse = 1 - percentage; var inverseInt = (int)(inverse * 255); var color = Color.FromArgb(254, (int)percentage * 255, inverseInt, inverseInt); + player.PrintToConsole("Color: " + color.ToString()); if (percentage <= 0) { color = Color.FromArgb(254, 255, 255, 255); } + player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; player.Pawn.Value.Render = color; } } \ No newline at end of file From f4518b165c636f69bfe74e7fdc884608f06203a9 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 14:40:37 -0800 Subject: [PATCH 07/27] Properly round --- mod/Jailbreak.Rebel/RebelManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 837586d6..5e7e2bc3 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -103,7 +103,7 @@ private void ApplyRebelColor(CCSPlayerController player) player.PrintToConsole("Rebel percentage: " + percentage); var inverse = 1 - percentage; var inverseInt = (int)(inverse * 255); - var color = Color.FromArgb(254, (int)percentage * 255, inverseInt, inverseInt); + var color = Color.FromArgb(254, (int) Math.Round(percentage * 255.0), inverseInt, inverseInt); player.PrintToConsole("Color: " + color.ToString()); if (percentage <= 0) { From 88345fd19f3738154494d2343eaad7d6a275d356 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 14:49:27 -0800 Subject: [PATCH 08/27] Fix color --- mod/Jailbreak.Rebel/RebelManager.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 5e7e2bc3..c35556e4 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -16,7 +16,7 @@ public void Start(BasePlugin parent) { parent.RegisterEventHandler(OnPlayerDisconnect); parent.RegisterEventHandler(OnRoundStart); - + parent.AddTimer(1f, () => { foreach (var player in GetActiveRebels()) @@ -40,8 +40,11 @@ private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) rebelTimes.Clear(); foreach (var player in Utilities.GetPlayers()) { - ApplyRebelColor(player); + if (!player.IsValid) + continue; + ApplyRebelColor(player); } + return HookResult.Continue; } @@ -99,13 +102,10 @@ private void ApplyRebelColor(CCSPlayerController player) { if (!player.IsValid || player.Pawn.Value == null) return; - var percentage = GetRebelTimePercentage(player); - player.PrintToConsole("Rebel percentage: " + percentage); - var inverse = 1 - percentage; - var inverseInt = (int)(inverse * 255); - var color = Color.FromArgb(254, (int) Math.Round(percentage * 255.0), inverseInt, inverseInt); + var percentRGB = (int)Math.Round(GetRebelTimePercentage(player) * 255.0); + var color = Color.FromArgb(254, 255, percentRGB, percentRGB); player.PrintToConsole("Color: " + color.ToString()); - if (percentage <= 0) + if (percentRGB <= 0) { color = Color.FromArgb(254, 255, 255, 255); } From 2497052704e3d082d68e8c32bfbe17d1f8dae42f Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 15:02:00 -0800 Subject: [PATCH 09/27] Update locale --- .../Rebel/RebelNotifications.cs | 21 +++++++++++++++++++ mod/Jailbreak.Rebel/RebelManager.cs | 15 ++++++++++--- .../Views/IRebelNotifications.cs | 8 +++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 lang/Jailbreak.English/Rebel/RebelNotifications.cs create mode 100644 public/Jailbreak.Formatting/Views/IRebelNotifications.cs diff --git a/lang/Jailbreak.English/Rebel/RebelNotifications.cs b/lang/Jailbreak.English/Rebel/RebelNotifications.cs new file mode 100644 index 00000000..c7f2e913 --- /dev/null +++ b/lang/Jailbreak.English/Rebel/RebelNotifications.cs @@ -0,0 +1,21 @@ +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Formatting.Base; +using Jailbreak.Formatting.Core; +using Jailbreak.Formatting.Objects; +using Jailbreak.Formatting.Views; + +namespace Jailbreak.English.Rebel; + +public class RebelNotifications : IRebelNotifications +{ + public static FormatObject PREFIX = new HiddenFormatObject( $" {ChatColors.Darkred}[{ChatColors.LightRed}Rebel{ChatColors.Darkred}]" ) + { + // Hide in panorama and center text + Plain = false, + Panorama = false, + Chat = true, + }; + public IView NO_LONGER_REBEL => new SimpleView(writer => + writer + .Line(PREFIX, "You are no longer a rebel.")); +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index c35556e4..b38bb427 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -3,6 +3,8 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Timers; +using Jailbreak.Formatting.Extensions; +using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Rebel; @@ -11,6 +13,12 @@ namespace Jailbreak.Teams; public class RebelManager : IPluginBehavior, IRebelService { private Dictionary rebelTimes = new(); + private IRebelNotifications notifs; + + public RebelManager(IRebelNotifications notifs) + { + this.notifs = notifs; + } public void Start(BasePlugin parent) { @@ -82,7 +90,8 @@ public bool MarkRebel(CCSPlayerController player, long time) public void UnmarkRebel(CCSPlayerController player) { - player.PrintToChat("You are no longer a rebel"); + notifs.NO_LONGER_REBEL.ToPlayerChat(player); + rebelTimes.Remove(player); ApplyRebelColor(player); } @@ -102,14 +111,14 @@ private void ApplyRebelColor(CCSPlayerController player) { if (!player.IsValid || player.Pawn.Value == null) return; - var percentRGB = (int)Math.Round(GetRebelTimePercentage(player) * 255.0); + var percentRGB = 255 - (int)Math.Round(GetRebelTimePercentage(player) * 255.0); var color = Color.FromArgb(254, 255, percentRGB, percentRGB); - player.PrintToConsole("Color: " + color.ToString()); if (percentRGB <= 0) { color = Color.FromArgb(254, 255, 255, 255); } + player.PrintToConsole("Color: " + color); player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; player.Pawn.Value.Render = color; } diff --git a/public/Jailbreak.Formatting/Views/IRebelNotifications.cs b/public/Jailbreak.Formatting/Views/IRebelNotifications.cs new file mode 100644 index 00000000..4631baec --- /dev/null +++ b/public/Jailbreak.Formatting/Views/IRebelNotifications.cs @@ -0,0 +1,8 @@ +using Jailbreak.Formatting.Base; + +namespace Jailbreak.Formatting.Views; + +public interface IRebelNotifications +{ + public IView NO_LONGER_REBEL { get; } +} \ No newline at end of file From 882719904008de6921a414ded4308ade862f8cb2 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 15:06:14 -0800 Subject: [PATCH 10/27] Dialects are not languages --- lang/Jailbreak.English/Rebel/RebelNotifications.cs | 3 ++- public/Jailbreak.Formatting/Logistics/LanguageConfig.cs | 4 ++++ src/Jailbreak/JailbreakServiceCollection.cs | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lang/Jailbreak.English/Rebel/RebelNotifications.cs b/lang/Jailbreak.English/Rebel/RebelNotifications.cs index c7f2e913..53ffd2ad 100644 --- a/lang/Jailbreak.English/Rebel/RebelNotifications.cs +++ b/lang/Jailbreak.English/Rebel/RebelNotifications.cs @@ -1,12 +1,13 @@ using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Base; using Jailbreak.Formatting.Core; +using Jailbreak.Formatting.Logistics; using Jailbreak.Formatting.Objects; using Jailbreak.Formatting.Views; namespace Jailbreak.English.Rebel; -public class RebelNotifications : IRebelNotifications +public class RebelNotifications : IRebelNotifications, ILanguage { public static FormatObject PREFIX = new HiddenFormatObject( $" {ChatColors.Darkred}[{ChatColors.LightRed}Rebel{ChatColors.Darkred}]" ) { diff --git a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs index 47cc15be..bc07c36a 100644 --- a/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs +++ b/public/Jailbreak.Formatting/Logistics/LanguageConfig.cs @@ -22,4 +22,8 @@ public void WithRatio() public void WithWarden() where TWarden : class, ILanguage, IWardenNotifications => _collection.AddSingleton(); + + public void WithRebel() + where TRebel : class, ILanguage, IRebelNotifications + => _collection.AddSingleton(); } diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 4f70c9df..a74e08fb 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -3,6 +3,7 @@ using CounterStrikeSharp.API.Core; using Jailbreak.Config; +using Jailbreak.English.Rebel; using Jailbreak.English.Teams; using Jailbreak.English.Warden; using Jailbreak.Formatting.Languages; @@ -39,6 +40,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) { config.WithRatio(); config.WithWarden(); + config.WithRebel(); }); } } From 4a119764f3cf88ded1225db603d7df172749f99e Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 15:36:23 -0800 Subject: [PATCH 11/27] Update state --- mod/Jailbreak.Rebel/RebelManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index b38bb427..798b28e9 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -121,5 +121,6 @@ private void ApplyRebelColor(CCSPlayerController player) player.PrintToConsole("Color: " + color); player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; player.Pawn.Value.Render = color; + Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clRender"); } } \ No newline at end of file From 5090e3361d417780664b1ed04f85067534b083b4 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 15:44:59 -0800 Subject: [PATCH 12/27] Fix color delay --- mod/Jailbreak.Rebel/RebelManager.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 798b28e9..5fc69f91 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -111,9 +111,10 @@ private void ApplyRebelColor(CCSPlayerController player) { if (!player.IsValid || player.Pawn.Value == null) return; - var percentRGB = 255 - (int)Math.Round(GetRebelTimePercentage(player) * 255.0); + var percent = GetRebelTimePercentage(player); + var percentRGB = 255 - (int)Math.Round(percent * 255.0); var color = Color.FromArgb(254, 255, percentRGB, percentRGB); - if (percentRGB <= 0) + if (percent <= 0) { color = Color.FromArgb(254, 255, 255, 255); } @@ -121,6 +122,6 @@ private void ApplyRebelColor(CCSPlayerController player) player.PrintToConsole("Color: " + color); player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; player.Pawn.Value.Render = color; - Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clRender"); + Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clrRender"); } } \ No newline at end of file From cabb831c92c2a0c1935b6ee13568fe03bbf9d819 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 15:50:34 -0800 Subject: [PATCH 13/27] Fix warden coloring --- mod/Jailbreak.Warden/Global/WardenBehavior.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mod/Jailbreak.Warden/Global/WardenBehavior.cs b/mod/Jailbreak.Warden/Global/WardenBehavior.cs index be888ffd..a0ae3d87 100644 --- a/mod/Jailbreak.Warden/Global/WardenBehavior.cs +++ b/mod/Jailbreak.Warden/Global/WardenBehavior.cs @@ -62,6 +62,7 @@ public bool TrySetWarden(CCSPlayerController controller) { _warden.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; _warden.Pawn.Value.Render = Color.Blue; + Utilities.SetStateChanged(_warden.Pawn.Value, "CBaseModelEntity", "m_clrRender"); } _notifications.NEW_WARDEN(_warden) @@ -77,9 +78,12 @@ public bool TryRemoveWarden() return false; _hasWarden = false; - + if (_warden != null && _warden.Pawn.Value != null) + { _warden.Pawn.Value.Render = Color.FromArgb(254, 255, 255, 255); + Utilities.SetStateChanged(_warden.Pawn.Value, "CBaseModelEntity", "m_clrRender"); + } _warden = null; From 36dcbae1d26011e416d206c985a0eb2393f5eb68 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 16:16:24 -0800 Subject: [PATCH 14/27] Bump version --- mod/Jailbreak.Warden/Global/WardenBehavior.cs | 1 + src/Jailbreak/Jailbreak.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mod/Jailbreak.Warden/Global/WardenBehavior.cs b/mod/Jailbreak.Warden/Global/WardenBehavior.cs index a0ae3d87..e46e575e 100644 --- a/mod/Jailbreak.Warden/Global/WardenBehavior.cs +++ b/mod/Jailbreak.Warden/Global/WardenBehavior.cs @@ -81,6 +81,7 @@ public bool TryRemoveWarden() if (_warden != null && _warden.Pawn.Value != null) { + _warden.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; _warden.Pawn.Value.Render = Color.FromArgb(254, 255, 255, 255); Utilities.SetStateChanged(_warden.Pawn.Value, "CBaseModelEntity", "m_clrRender"); } diff --git a/src/Jailbreak/Jailbreak.cs b/src/Jailbreak/Jailbreak.cs index dc607697..4a751b1f 100644 --- a/src/Jailbreak/Jailbreak.cs +++ b/src/Jailbreak/Jailbreak.cs @@ -16,7 +16,7 @@ namespace Jailbreak; public class Jailbreak : BasePlugin { public override string ModuleName => "Jailbreak"; - public override string ModuleVersion => "0.2.0.{GIT_VERSION}"; + public override string ModuleVersion => "0.2.1.{GIT_VERSION}"; public override string ModuleAuthor => "EdgeGamers Development"; private IServiceProvider _provider; From 6e33cec4cc32cf1361bcd6a74b73691e637e87df Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 16:27:10 -0800 Subject: [PATCH 15/27] Remove debug --- mod/Jailbreak.Rebel/RebelManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 5fc69f91..f7f50a12 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -119,7 +119,6 @@ private void ApplyRebelColor(CCSPlayerController player) color = Color.FromArgb(254, 255, 255, 255); } - player.PrintToConsole("Color: " + color); player.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; player.Pawn.Value.Render = color; Utilities.SetStateChanged(player.Pawn.Value, "CBaseModelEntity", "m_clrRender"); From 3bb78f02cfe1b22aedd8b9cf1809191b41466e61 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 17:20:16 -0800 Subject: [PATCH 16/27] Merge rebel --- mod/Jailbreak.Rebel/RebelManager.cs | 2 +- mod/Jailbreak.Rebel/RebelServiceExtension.cs | 4 ++-- src/Jailbreak/JailbreakServiceCollection.cs | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index f7f50a12..1307ac17 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -43,7 +43,7 @@ public void Start(BasePlugin parent) }, TimerFlags.REPEAT); } - private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) + HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { rebelTimes.Clear(); foreach (var player in Utilities.GetPlayers()) diff --git a/mod/Jailbreak.Rebel/RebelServiceExtension.cs b/mod/Jailbreak.Rebel/RebelServiceExtension.cs index 057552e1..835a7e41 100644 --- a/mod/Jailbreak.Rebel/RebelServiceExtension.cs +++ b/mod/Jailbreak.Rebel/RebelServiceExtension.cs @@ -1,10 +1,10 @@ using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Rebel; using Jailbreak.Public.Mod.Teams; - +using Jailbreak.Teams; using Microsoft.Extensions.DependencyInjection; -namespace Jailbreak.Teams; +namespace Jailbreak.Rebel; public static class RebelServiceExtension { diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index a74e08fb..9bb15007 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -10,6 +10,7 @@ using Jailbreak.Formatting.Logistics; using Jailbreak.Generic; using Jailbreak.Public.Configuration; +using Jailbreak.Rebel; using Jailbreak.Teams; using Jailbreak.Warden; From 641dc85243b44ba885b6f016ca2d4c91e4590a1b Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 3 Feb 2024 18:54:21 -0800 Subject: [PATCH 17/27] Start work on warden laser (#13) --- .../Paint/WardenPaintBehavior.cs | 87 +++++++++++++++++++ .../WardenServiceExtension.cs | 2 + .../Extensions/VectorExtensions.cs | 42 +++++++++ 3 files changed, 131 insertions(+) create mode 100644 mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs create mode 100644 public/Jailbreak.Public/Extensions/VectorExtensions.cs diff --git a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs new file mode 100644 index 00000000..96d69a60 --- /dev/null +++ b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs @@ -0,0 +1,87 @@ +using System.Drawing; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Timers; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Draw; +using Jailbreak.Public.Mod.Warden; + +namespace Jailbreak.Warden.Paint; + +public class WardenPaintBehavior : IPluginBehavior +{ + private IWardenService _warden; + private BasePlugin parent; + + public WardenPaintBehavior(IWardenService warden) + { + _warden = warden; + } + + public void Start(BasePlugin parent) + { + this.parent = parent; + parent.AddTimer(0.5f, Paint, TimerFlags.REPEAT); + } + + private void Paint() + { + if (!_warden.HasWarden) + return; + var warden = _warden.Warden; + if (warden == null || !warden.IsValid) + return; + + if ((warden.Buttons & PlayerButtons.Use) == 0) + return; + if (warden.Pawn.Value == null || warden.PlayerPawn.Value == null) + return; + CBasePlayerPawn pawn = warden.Pawn.Value; + CCSPlayerPawn playerPawn = warden.PlayerPawn.Value; + if (!pawn.IsValid || !playerPawn.IsValid || pawn.CameraServices == null) + return; + + CPlayer_CameraServices camera = pawn.CameraServices; + + var start = pawn.LookTargetPosition; + + new BeamCircle(parent, start, 40, 5).Draw(15f); + + Vector cameraOrigin = new Vector(pawn?.AbsOrigin?.X, pawn?.AbsOrigin?.Y, + pawn.AbsOrigin.Z + camera.OldPlayerViewOffsetZ); + QAngle eye_angle = warden.PlayerPawn.Value.EyeAngles; + double pitch = (Math.PI / 180) * eye_angle.X; + double yaw = (Math.PI / 180) * eye_angle.Y; + Vector eye_vector = new Vector((float)(Math.Cos(pitch) * Math.Cos(yaw)), + (float)(Math.Cos(pitch) * Math.Sin(yaw)), (float)(-Math.Sin(pitch))); + + start = FindFloorIntersection(cameraOrigin, eye_vector, pawn.AbsOrigin.Z); + if (start == null) + return; + var circle = new BeamCircle(parent, start, 40, 5); + circle.SetColor(Color.Red); + circle.Draw(15f); + } + + private Vector? FindFloorIntersection(Vector start, Vector angle, float z) + { + float pitch = angle.X; // 90 = straight down, -90 = straight up + // normalize so 0 = straight down, 180 = straight up + pitch = (pitch + 270) % 360; + if (pitch > 180) + pitch -= 180; + if (pitch >= 90) + return null; + float angle_a = 90; + float side_b = z; + float angle_c = pitch; + + float side_a = (float)(angle_c * Math.Sin(angle_a) / Math.Sin(180 - angle_a - angle_c)); + + Vector destination = start.Clone(); + destination.Add(angle.Clone().Normalize().Scale(side_a)); + return destination; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Warden/WardenServiceExtension.cs b/mod/Jailbreak.Warden/WardenServiceExtension.cs index b0716735..2344a1da 100644 --- a/mod/Jailbreak.Warden/WardenServiceExtension.cs +++ b/mod/Jailbreak.Warden/WardenServiceExtension.cs @@ -5,6 +5,7 @@ using Jailbreak.Warden.Commands; using Jailbreak.Warden.Global; using Jailbreak.Warden.Markers; +using Jailbreak.Warden.Paint; using Jailbreak.Warden.Selection; using Microsoft.Extensions.DependencyInjection; @@ -20,5 +21,6 @@ public static void AddJailbreakWarden(this IServiceCollection serviceCollection) serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); } } diff --git a/public/Jailbreak.Public/Extensions/VectorExtensions.cs b/public/Jailbreak.Public/Extensions/VectorExtensions.cs new file mode 100644 index 00000000..4e894e6a --- /dev/null +++ b/public/Jailbreak.Public/Extensions/VectorExtensions.cs @@ -0,0 +1,42 @@ +using CounterStrikeSharp.API.Modules.Utils; + +namespace Jailbreak.Public.Extensions; + +public static class VectorExtensions +{ + public static Vector Clone(this Vector vector) + { + var vec = new Vector + { + X = vector.X, + Y = vector.Y, + Z = vector.Z + }; + return vec; + } + + public static Vector Add(this Vector vector, Vector other) + { + vector.X += other.X; + vector.Y += other.Y; + vector.Z += other.Z; + return vector; + } + + public static Vector Scale(this Vector vector, float scale) + { + vector.X *= scale; + vector.Y *= scale; + vector.Z *= scale; + return vector; + } + + public static Vector Normalize(this Vector vector) + { + var length = vector.Length(); + vector.X /= length; + vector.Y /= length; + vector.Z /= length; + return vector; + } +} \ No newline at end of file From c8c8b87f2e98dc6b820af1af34cdad3176372829 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 21:57:46 -0800 Subject: [PATCH 18/27] Merge wardenlaser --- .../Paint/WardenPaintBehavior.cs | 135 ++++++++++++++++++ .../WardenServiceExtension.cs | 2 + .../Extensions/VectorExtensions.cs | 56 ++++++++ .../Jailbreak.Public/Mod/Draw/BeamCircle.cs | 2 +- public/Jailbreak.Public/Mod/Draw/BeamLine.cs | 5 + 5 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs create mode 100644 public/Jailbreak.Public/Extensions/VectorExtensions.cs diff --git a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs new file mode 100644 index 00000000..752b4796 --- /dev/null +++ b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs @@ -0,0 +1,135 @@ +using System.Drawing; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Timers; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Draw; +using Jailbreak.Public.Mod.Warden; + +namespace Jailbreak.Warden.Paint; + +public class WardenPaintBehavior : IPluginBehavior +{ + private IWardenService _warden; + private BasePlugin parent; + private Vector? _lastPosition; + private BeamLine? _beamLine; + + public WardenPaintBehavior(IWardenService warden) + { + _warden = warden; + } + + public void Start(BasePlugin parent) + { + this.parent = parent; + // parent.AddTimer(0.1f, Paint, TimerFlags.REPEAT); + parent.RegisterListener(Paint); + } + + private void Paint() + { + if (!_warden.HasWarden) + { + _beamLine?.Remove(); + _beamLine = null; + return; + } + var warden = _warden.Warden; + if (warden == null || !warden.IsValid) + return; + + if ((warden.Buttons & PlayerButtons.Use) == 0) + { + _beamLine?.Remove(); + _beamLine = null; + return; + } + + Vector? position = FindFloorIntersection(warden); + if (position == null) + return; + + if (_beamLine == null) + { + _beamLine = new BeamLine(parent, position, position); + _beamLine.SetColor(Color.FromArgb(200, 150, 150, 255)); + _beamLine.Draw(); + } + + var start = _lastPosition ?? position; + start = start.Clone(); + + var eyeLocation = warden.Pawn.Value!.AbsOrigin!.Clone(); + eyeLocation.Z += warden.Pawn.Value!.CameraServices!.OldPlayerViewOffsetZ; + if (_lastPosition != null && position.DistanceSquared(_lastPosition) < 25 * 25) + { + return; + } + + _lastPosition = position; + if (start.DistanceSquared(position) > 150 * 150 || start.Z - position.Z > 0.001f) + { + start = position; + } + + new BeamLine(parent, start.Clone(), position.Clone()).Draw(10f); + _beamLine.Move(eyeLocation, position.Clone()); + _beamLine.Update(); + } + + private Vector? FindFloorIntersection(CCSPlayerController player) + { + if (player.Pawn.Value == null || player.PlayerPawn.Value == null) + return null; + CBasePlayerPawn pawn = player.Pawn.Value; + CCSPlayerPawn playerPawn = player.PlayerPawn.Value; + if (!pawn.IsValid || !playerPawn.IsValid || pawn.CameraServices == null) + return null; + + CPlayer_CameraServices camera = pawn.CameraServices; + Vector cameraOrigin = new Vector(pawn?.AbsOrigin?.X, pawn?.AbsOrigin?.Y, + pawn.AbsOrigin.Z + camera.OldPlayerViewOffsetZ); + QAngle eye_angle = player.PlayerPawn.Value.EyeAngles; + + double pitch = (Math.PI / 180) * eye_angle.X; + double yaw = (Math.PI / 180) * eye_angle.Y; + + // get direction vector from angles + Vector eye_vector = new Vector((float)(Math.Cos(yaw) * Math.Cos(pitch)), + (float)(Math.Sin(yaw) * Math.Cos(pitch)), (float)(-Math.Sin(pitch))); + + return FindFloorIntersection(cameraOrigin, eye_vector, new Vector(eye_angle.X, eye_angle.Y, eye_angle.Z), + pawn.AbsOrigin.Z); + } + + private Vector? FindFloorIntersection(Vector start, Vector worldAngles, Vector rotationAngles, float z) + { + float pitch = rotationAngles.X; // 90 = straight down, -90 = straight up, 0 = straight ahead + // normalize so 0 = straight down, 180 = straight up, 90 = straight ahead + pitch = 90 - pitch; + if (pitch >= 90) + return null; + float angle_a = ToRadians(90); + float side_b = start.Z - z; + float angle_c = ToRadians(pitch); + + + float angle_b = 180 - 90 - pitch; + float side_a = side_b * MathF.Sin(ToRadians(90)) / MathF.Sin(ToRadians(angle_b)); + float side_c = MathF.Sqrt(side_b * side_b + side_a * side_a - 2 * side_b * side_a * MathF.Cos(angle_c)); + + Vector destination = start.Clone(); + destination.X += worldAngles.X * side_c; + destination.Y += worldAngles.Y * side_c; + destination.Z = z; + return destination; + } + + private static float ToRadians(float angle) + { + return (float)(Math.PI / 180) * angle; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Warden/WardenServiceExtension.cs b/mod/Jailbreak.Warden/WardenServiceExtension.cs index b0716735..2344a1da 100644 --- a/mod/Jailbreak.Warden/WardenServiceExtension.cs +++ b/mod/Jailbreak.Warden/WardenServiceExtension.cs @@ -5,6 +5,7 @@ using Jailbreak.Warden.Commands; using Jailbreak.Warden.Global; using Jailbreak.Warden.Markers; +using Jailbreak.Warden.Paint; using Jailbreak.Warden.Selection; using Microsoft.Extensions.DependencyInjection; @@ -20,5 +21,6 @@ public static void AddJailbreakWarden(this IServiceCollection serviceCollection) serviceCollection.AddPluginBehavior(); serviceCollection.AddPluginBehavior(); + serviceCollection.AddPluginBehavior(); } } diff --git a/public/Jailbreak.Public/Extensions/VectorExtensions.cs b/public/Jailbreak.Public/Extensions/VectorExtensions.cs new file mode 100644 index 00000000..158b738d --- /dev/null +++ b/public/Jailbreak.Public/Extensions/VectorExtensions.cs @@ -0,0 +1,56 @@ +using CounterStrikeSharp.API.Modules.Utils; + +namespace Jailbreak.Public.Extensions; + +public static class VectorExtensions +{ + public static Vector Clone(this Vector vector) + { + var vec = new Vector + { + X = vector.X, + Y = vector.Y, + Z = vector.Z + }; + return vec; + } + + public static Vector Add(this Vector vector, Vector other) + { + vector.X += other.X; + vector.Y += other.Y; + vector.Z += other.Z; + return vector; + } + + public static Vector Scale(this Vector vector, float scale) + { + vector.X *= scale; + vector.Y *= scale; + vector.Z *= scale; + return vector; + } + + public static Vector Normalize(this Vector vector) + { + var length = vector.Length(); + vector.X /= length; + vector.Y /= length; + vector.Z /= length; + return vector; + } + + public static float Distance(this Vector vector, Vector other) + { + return (float)System.Math.Sqrt(vector.DistanceSquared(other)); + } + + public static float DistanceSquared(this Vector vector, Vector other) + { + return (float)( + System.Math.Pow(vector.X - other.X, 2) + + System.Math.Pow(vector.Y - other.Y, 2) + + System.Math.Pow(vector.Z - other.Z, 2) + ); + } +} \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs index ccd38a99..bdfe9a94 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs @@ -8,7 +8,7 @@ namespace Jailbreak.Public.Mod.Draw; public class BeamCircle : BeamedShape { - private BeamLine[] lines; + private BeamLine?[] lines; private Vector[] offsets; private float radius; diff --git a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs index c79b3596..2bb8ba2a 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs @@ -25,6 +25,11 @@ public void Move(Vector start, Vector end) public override void Draw() { + if(this.beam != null) + { + this.beam.Remove(); + this.beam = null; + } var beam = Utilities.CreateEntityByName("env_beam"); if (beam == null) return; beam.RenderMode = RenderMode_t.kRenderTransColor; From 971e93e48073ae39beae99e19652f121defff602 Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 3 Feb 2024 23:15:29 -0800 Subject: [PATCH 19/27] Feat/logs (#14) * Start work on logs * More work on logs --- Jailbreak.sln | 7 ++ mod/Jailbreak.Logs/Jailbreak.Logs.csproj | 13 ++++ mod/Jailbreak.Logs/LogsCommand.cs | 29 ++++++++ mod/Jailbreak.Logs/LogsListeners.cs | 70 +++++++++++++++++++ mod/Jailbreak.Logs/LogsManager.cs | 63 +++++++++++++++++ mod/Jailbreak.Logs/LogsServiceExtension.cs | 15 ++++ mod/Jailbreak.Rebel/RebelManager.cs | 15 +++- .../Jailbreak.Public/Mod/Logs/ILogService.cs | 11 +++ src/Jailbreak/Jailbreak.csproj | 1 + src/Jailbreak/JailbreakServiceCollection.cs | 2 + 10 files changed, 223 insertions(+), 3 deletions(-) create mode 100644 mod/Jailbreak.Logs/Jailbreak.Logs.csproj create mode 100644 mod/Jailbreak.Logs/LogsCommand.cs create mode 100644 mod/Jailbreak.Logs/LogsListeners.cs create mode 100644 mod/Jailbreak.Logs/LogsManager.cs create mode 100644 mod/Jailbreak.Logs/LogsServiceExtension.cs create mode 100644 public/Jailbreak.Public/Mod/Logs/ILogService.cs diff --git a/Jailbreak.sln b/Jailbreak.sln index 30f97c74..4e9a7f23 100644 --- a/Jailbreak.sln +++ b/Jailbreak.sln @@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.English", "lang\J EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Rebel", "mod\Jailbreak.Rebel\Jailbreak.Rebel.csproj", "{CB2391A1-6CDD-496F-B8D6-674FD6268038}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Logs", "mod\Jailbreak.Logs\Jailbreak.Logs.csproj", "{CE6EC648-E7F9-4CE7-B28F-8C7995830F35}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,6 +64,10 @@ Global {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.Build.0 = Release|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581} @@ -72,5 +78,6 @@ Global {446E0B6F-E4FE-45E6-BD9B-BD943698327A} = {59311734-3648-43C2-B43C-385718B0D103} {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF} = {CDCDE44E-01D2-4B76-99DA-A57E1E956038} {CB2391A1-6CDD-496F-B8D6-674FD6268038} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} EndGlobalSection EndGlobal diff --git a/mod/Jailbreak.Logs/Jailbreak.Logs.csproj b/mod/Jailbreak.Logs/Jailbreak.Logs.csproj new file mode 100644 index 00000000..233a12cd --- /dev/null +++ b/mod/Jailbreak.Logs/Jailbreak.Logs.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/mod/Jailbreak.Logs/LogsCommand.cs b/mod/Jailbreak.Logs/LogsCommand.cs new file mode 100644 index 00000000..5b261387 --- /dev/null +++ b/mod/Jailbreak.Logs/LogsCommand.cs @@ -0,0 +1,29 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Logs; + +namespace Jailbreak.Logs; + +public class LogsCommand : IPluginBehavior +{ + private ILogService logs; + + public LogsCommand(ILogService logs) + { + this.logs = logs; + } + + [ConsoleCommand("css_logs")] + public void Command_Logs(CCSPlayerController? executor, CommandInfo info) + { + if (executor == null) + return; + + foreach (var log in logs.GetLogMessages()) + { + executor.PrintToConsole(log); + } + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsListeners.cs b/mod/Jailbreak.Logs/LogsListeners.cs new file mode 100644 index 00000000..d0049893 --- /dev/null +++ b/mod/Jailbreak.Logs/LogsListeners.cs @@ -0,0 +1,70 @@ +using CounterStrikeSharp.API.Core; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Logs; + +namespace Jailbreak.Logs; + +public class LogsListeners : IPluginBehavior +{ + private ILogService logs; + + public LogsListeners(ILogService logs) + { + this.logs = logs; + } + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnPlayerHurt); + parent.RegisterEventHandler(OnGrenadeThrown); + } + + private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsValid) + return HookResult.Continue; + var grenade = @event.Weapon; + + logs.AddLogMessage($"{logs.FormatPlayer(player)} threw a {grenade}"); + + return HookResult.Continue; + } + + private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsValid) + return HookResult.Continue; + var attacker = @event.Attacker; + + bool isWorld = attacker == null || !attacker.IsValid; + int health = @event.Health; + + if (isWorld) + { + if (health > 0) + { + logs.AddLogMessage($"The world hurt {logs.FormatPlayer(player)} for {health} damage"); + } + else + { + logs.AddLogMessage($"The world killed {logs.FormatPlayer(player)}"); + } + } + else + { + if (health > 0) + { + logs.AddLogMessage( + $"{logs.FormatPlayer(attacker!)} hurt {logs.FormatPlayer(player)} for {health} damage"); + } + else + { + logs.AddLogMessage($"{logs.FormatPlayer(attacker!)} killed {logs.FormatPlayer(player)}"); + } + } + + return HookResult.Continue; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsManager.cs b/mod/Jailbreak.Logs/LogsManager.cs new file mode 100644 index 00000000..a6bb247d --- /dev/null +++ b/mod/Jailbreak.Logs/LogsManager.cs @@ -0,0 +1,63 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Logs; +using Jailbreak.Public.Mod.Rebel; +using Jailbreak.Public.Mod.Warden; + +namespace Jailbreak.Logs; + +public class LogsManager : IPluginBehavior, ILogService +{ + private readonly List _logMessages = new(); + private long startTime; + private IWardenService wardenService; + private IRebelService rebelService; + + public LogsManager(IWardenService wardenService, IRebelService rebelService) + { + this.wardenService = wardenService; + this.rebelService = rebelService; + } + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnRoundStart); + } + + private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) + { + startTime = DateTimeOffset.Now.ToUnixTimeSeconds(); + ClearLogMessages(); + return HookResult.Continue; + } + + public void AddLogMessage(string message) + { + // format to [MM:SS] message + string prefix = $"[{TimeSpan.FromSeconds(DateTimeOffset.Now.ToUnixTimeSeconds() - startTime):mm\\:ss}] "; + _logMessages.Add(prefix + message); + } + + public ICollection GetLogMessages() + { + return _logMessages; + } + + public void ClearLogMessages() + { + _logMessages.Clear(); + } + + public string FormatPlayer(CCSPlayerController player) + { + if (wardenService.IsWarden(player)) + return $"{player.PlayerName} (WARDEN)"; + if (player.GetTeam() == CsTeam.CounterTerrorist) + return $"{player.PlayerName} (CT)"; + if (rebelService.IsRebel(player)) + return $"{player.PlayerName} (REBEL)"; + return $"{player.PlayerName} (Prisoner)"; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsServiceExtension.cs b/mod/Jailbreak.Logs/LogsServiceExtension.cs new file mode 100644 index 00000000..d84c5161 --- /dev/null +++ b/mod/Jailbreak.Logs/LogsServiceExtension.cs @@ -0,0 +1,15 @@ +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Logs; +using Microsoft.Extensions.DependencyInjection; + +namespace Jailbreak.Logs; + +public static class LogsServiceExtension +{ + public static void AddLogsService(this IServiceCollection services) + { + services.AddPluginBehavior(); + + services.AddPluginBehavior(); + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 1307ac17..dbee5935 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -6,6 +6,7 @@ using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Logs; using Jailbreak.Public.Mod.Rebel; namespace Jailbreak.Teams; @@ -14,10 +15,12 @@ public class RebelManager : IPluginBehavior, IRebelService { private Dictionary rebelTimes = new(); private IRebelNotifications notifs; - - public RebelManager(IRebelNotifications notifs) + private ILogService logs; + + public RebelManager(IRebelNotifications notifs, ILogService logs) { this.notifs = notifs; + this.logs = logs; } public void Start(BasePlugin parent) @@ -83,6 +86,11 @@ public long GetRebelTimeLeft(CCSPlayerController player) public bool MarkRebel(CCSPlayerController player, long time) { + if (!rebelTimes.ContainsKey(player)) + { + logs.AddLogMessage(player.PlayerName + " is now a rebel."); + } + rebelTimes[player] = DateTimeOffset.Now.ToUnixTimeSeconds() + time; ApplyRebelColor(player); return true; @@ -91,7 +99,8 @@ public bool MarkRebel(CCSPlayerController player, long time) public void UnmarkRebel(CCSPlayerController player) { notifs.NO_LONGER_REBEL.ToPlayerChat(player); - + logs.AddLogMessage(player.PlayerName + " is no longer a rebel."); + rebelTimes.Remove(player); ApplyRebelColor(player); } diff --git a/public/Jailbreak.Public/Mod/Logs/ILogService.cs b/public/Jailbreak.Public/Mod/Logs/ILogService.cs new file mode 100644 index 00000000..29fc8899 --- /dev/null +++ b/public/Jailbreak.Public/Mod/Logs/ILogService.cs @@ -0,0 +1,11 @@ +using CounterStrikeSharp.API.Core; + +namespace Jailbreak.Public.Mod.Logs; + +public interface ILogService +{ + void AddLogMessage(string message); + ICollection GetLogMessages(); + void ClearLogMessages(); + string FormatPlayer(CCSPlayerController player); +} \ No newline at end of file diff --git a/src/Jailbreak/Jailbreak.csproj b/src/Jailbreak/Jailbreak.csproj index 212d15e7..c4f3890a 100644 --- a/src/Jailbreak/Jailbreak.csproj +++ b/src/Jailbreak/Jailbreak.csproj @@ -36,6 +36,7 @@ + diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 9bb15007..0f5607af 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -9,6 +9,7 @@ using Jailbreak.Formatting.Languages; using Jailbreak.Formatting.Logistics; using Jailbreak.Generic; +using Jailbreak.Logs; using Jailbreak.Public.Configuration; using Jailbreak.Rebel; using Jailbreak.Teams; @@ -35,6 +36,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) serviceCollection.AddJailbreakWarden(); serviceCollection.AddJailbreakTeams(); serviceCollection.AddJailbreakRebel(); + serviceCollection.AddLogsService(); // Add in english localization serviceCollection.AddLanguage(config => From a4caf4e0ca2212e03060caefc4b167914a8bdb0c Mon Sep 17 00:00:00 2001 From: Isaac Date: Sat, 3 Feb 2024 23:18:04 -0800 Subject: [PATCH 20/27] Feat/warden laser (#15) * Start work on warden laser * Working commit * Add warden beam * Improvements to drawing --- .../Markers/WardenMarkerBehavior.cs | 35 ++++++++++++++++++- .../Paint/WardenPaintBehavior.cs | 24 ++----------- .../Extensions/VectorExtensions.cs | 2 +- .../Jailbreak.Public/Mod/Draw/BeamCircle.cs | 6 ++++ public/Jailbreak.Public/Mod/Draw/BeamLine.cs | 6 +--- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs index e8ba7f07..c4919994 100644 --- a/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs +++ b/mod/Jailbreak.Warden/Markers/WardenMarkerBehavior.cs @@ -3,6 +3,7 @@ using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Draw; using Jailbreak.Public.Mod.Warden; @@ -12,7 +13,12 @@ public class WardenMarkerBehavior : IPluginBehavior { private readonly IWardenService _warden; - private DrawableShape? _marker; + private BeamCircle? _marker; + + private Vector? currentPos; + private const float MIN_RADIUS = 60f, MAX_RADIUS = 360f; + private float radius = MIN_RADIUS; + private long placementTime = 0; public WardenMarkerBehavior(IWardenService warden) { @@ -33,7 +39,34 @@ public HookResult OnPing(EventPlayerPing @event, GameEventInfo info) if (!_warden.IsWarden(player)) return HookResult.Handled; Vector vec = new Vector(@event.X, @event.Y, @event.Z); + + if (currentPos != null) + { + float distance = currentPos.Distance(vec); + long timeElapsed = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() - placementTime; + if (timeElapsed < 500) + { + if (distance <= MAX_RADIUS * 1.5) + { + distance = Math.Clamp(distance, MIN_RADIUS, MAX_RADIUS); + _marker?.SetRadius(distance); + _marker?.Update(); + radius = distance; + return HookResult.Handled; + } + } + else if (distance <= radius) + { + _marker?.Remove(); + return HookResult.Handled; + } + } + + radius = MIN_RADIUS; + currentPos = vec; + placementTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); _marker?.Move(vec); + _marker?.SetRadius(radius); _marker?.Update(); return HookResult.Handled; } diff --git a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs index 752b4796..ef52504c 100644 --- a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs +++ b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs @@ -15,7 +15,6 @@ public class WardenPaintBehavior : IPluginBehavior private IWardenService _warden; private BasePlugin parent; private Vector? _lastPosition; - private BeamLine? _beamLine; public WardenPaintBehavior(IWardenService warden) { @@ -25,26 +24,20 @@ public WardenPaintBehavior(IWardenService warden) public void Start(BasePlugin parent) { this.parent = parent; - // parent.AddTimer(0.1f, Paint, TimerFlags.REPEAT); parent.RegisterListener(Paint); } - + private void Paint() { if (!_warden.HasWarden) - { - _beamLine?.Remove(); - _beamLine = null; return; - } + var warden = _warden.Warden; if (warden == null || !warden.IsValid) return; if ((warden.Buttons & PlayerButtons.Use) == 0) { - _beamLine?.Remove(); - _beamLine = null; return; } @@ -52,23 +45,14 @@ private void Paint() if (position == null) return; - if (_beamLine == null) - { - _beamLine = new BeamLine(parent, position, position); - _beamLine.SetColor(Color.FromArgb(200, 150, 150, 255)); - _beamLine.Draw(); - } - var start = _lastPosition ?? position; start = start.Clone(); - var eyeLocation = warden.Pawn.Value!.AbsOrigin!.Clone(); - eyeLocation.Z += warden.Pawn.Value!.CameraServices!.OldPlayerViewOffsetZ; if (_lastPosition != null && position.DistanceSquared(_lastPosition) < 25 * 25) { return; } - + _lastPosition = position; if (start.DistanceSquared(position) > 150 * 150 || start.Z - position.Z > 0.001f) { @@ -76,8 +60,6 @@ private void Paint() } new BeamLine(parent, start.Clone(), position.Clone()).Draw(10f); - _beamLine.Move(eyeLocation, position.Clone()); - _beamLine.Update(); } private Vector? FindFloorIntersection(CCSPlayerController player) diff --git a/public/Jailbreak.Public/Extensions/VectorExtensions.cs b/public/Jailbreak.Public/Extensions/VectorExtensions.cs index f0bf4335..158b738d 100644 --- a/public/Jailbreak.Public/Extensions/VectorExtensions.cs +++ b/public/Jailbreak.Public/Extensions/VectorExtensions.cs @@ -14,7 +14,7 @@ public static Vector Clone(this Vector vector) }; return vec; } - + public static Vector Add(this Vector vector, Vector other) { vector.X += other.X; diff --git a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs index bdfe9a94..7bc034b8 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamCircle.cs @@ -59,4 +59,10 @@ public override void Draw() } } } + + public void SetRadius(float radius) + { + this.radius = radius; + offsets = generateOffsets(); + } } \ No newline at end of file diff --git a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs index 2bb8ba2a..3a073e34 100644 --- a/public/Jailbreak.Public/Mod/Draw/BeamLine.cs +++ b/public/Jailbreak.Public/Mod/Draw/BeamLine.cs @@ -25,11 +25,7 @@ public void Move(Vector start, Vector end) public override void Draw() { - if(this.beam != null) - { - this.beam.Remove(); - this.beam = null; - } + Remove(); var beam = Utilities.CreateEntityByName("env_beam"); if (beam == null) return; beam.RenderMode = RenderMode_t.kRenderTransColor; From ff1a930b16cdc689fa694fdf4ffeb9718c409b68 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sat, 3 Feb 2024 23:28:30 -0800 Subject: [PATCH 21/27] merge logs --- Jailbreak.sln | 7 ++ mod/Jailbreak.Logs/Jailbreak.Logs.csproj | 13 ++++ mod/Jailbreak.Logs/LogsCommand.cs | 29 ++++++++ mod/Jailbreak.Logs/LogsListeners.cs | 70 +++++++++++++++++++ mod/Jailbreak.Logs/LogsManager.cs | 63 +++++++++++++++++ mod/Jailbreak.Logs/LogsServiceExtension.cs | 16 +++++ mod/Jailbreak.Rebel/RebelManager.cs | 15 +++- .../Jailbreak.Public/Mod/Logs/ILogService.cs | 11 +++ src/Jailbreak/Jailbreak.csproj | 1 + src/Jailbreak/JailbreakServiceCollection.cs | 2 + 10 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 mod/Jailbreak.Logs/Jailbreak.Logs.csproj create mode 100644 mod/Jailbreak.Logs/LogsCommand.cs create mode 100644 mod/Jailbreak.Logs/LogsListeners.cs create mode 100644 mod/Jailbreak.Logs/LogsManager.cs create mode 100644 mod/Jailbreak.Logs/LogsServiceExtension.cs create mode 100644 public/Jailbreak.Public/Mod/Logs/ILogService.cs diff --git a/Jailbreak.sln b/Jailbreak.sln index 30f97c74..4e9a7f23 100644 --- a/Jailbreak.sln +++ b/Jailbreak.sln @@ -24,6 +24,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.English", "lang\J EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Rebel", "mod\Jailbreak.Rebel\Jailbreak.Rebel.csproj", "{CB2391A1-6CDD-496F-B8D6-674FD6268038}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jailbreak.Logs", "mod\Jailbreak.Logs\Jailbreak.Logs.csproj", "{CE6EC648-E7F9-4CE7-B28F-8C7995830F35}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,6 +64,10 @@ Global {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB2391A1-6CDD-496F-B8D6-674FD6268038}.Release|Any CPU.Build.0 = Release|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {9135CCC9-66C5-4A9C-AE3C-91475B5F0437} = {177DA48D-8306-4102-918D-992569878581} @@ -72,5 +78,6 @@ Global {446E0B6F-E4FE-45E6-BD9B-BD943698327A} = {59311734-3648-43C2-B43C-385718B0D103} {FC2D6F50-BCFF-41E6-A965-6C73CC01C3BF} = {CDCDE44E-01D2-4B76-99DA-A57E1E956038} {CB2391A1-6CDD-496F-B8D6-674FD6268038} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} + {CE6EC648-E7F9-4CE7-B28F-8C7995830F35} = {36BA84C0-291C-4930-A7C6-97CDF8F7F0D7} EndGlobalSection EndGlobal diff --git a/mod/Jailbreak.Logs/Jailbreak.Logs.csproj b/mod/Jailbreak.Logs/Jailbreak.Logs.csproj new file mode 100644 index 00000000..233a12cd --- /dev/null +++ b/mod/Jailbreak.Logs/Jailbreak.Logs.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/mod/Jailbreak.Logs/LogsCommand.cs b/mod/Jailbreak.Logs/LogsCommand.cs new file mode 100644 index 00000000..5b261387 --- /dev/null +++ b/mod/Jailbreak.Logs/LogsCommand.cs @@ -0,0 +1,29 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Commands; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Logs; + +namespace Jailbreak.Logs; + +public class LogsCommand : IPluginBehavior +{ + private ILogService logs; + + public LogsCommand(ILogService logs) + { + this.logs = logs; + } + + [ConsoleCommand("css_logs")] + public void Command_Logs(CCSPlayerController? executor, CommandInfo info) + { + if (executor == null) + return; + + foreach (var log in logs.GetLogMessages()) + { + executor.PrintToConsole(log); + } + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsListeners.cs b/mod/Jailbreak.Logs/LogsListeners.cs new file mode 100644 index 00000000..d0049893 --- /dev/null +++ b/mod/Jailbreak.Logs/LogsListeners.cs @@ -0,0 +1,70 @@ +using CounterStrikeSharp.API.Core; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Logs; + +namespace Jailbreak.Logs; + +public class LogsListeners : IPluginBehavior +{ + private ILogService logs; + + public LogsListeners(ILogService logs) + { + this.logs = logs; + } + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnPlayerHurt); + parent.RegisterEventHandler(OnGrenadeThrown); + } + + private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsValid) + return HookResult.Continue; + var grenade = @event.Weapon; + + logs.AddLogMessage($"{logs.FormatPlayer(player)} threw a {grenade}"); + + return HookResult.Continue; + } + + private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) + { + var player = @event.Userid; + if (!player.IsValid) + return HookResult.Continue; + var attacker = @event.Attacker; + + bool isWorld = attacker == null || !attacker.IsValid; + int health = @event.Health; + + if (isWorld) + { + if (health > 0) + { + logs.AddLogMessage($"The world hurt {logs.FormatPlayer(player)} for {health} damage"); + } + else + { + logs.AddLogMessage($"The world killed {logs.FormatPlayer(player)}"); + } + } + else + { + if (health > 0) + { + logs.AddLogMessage( + $"{logs.FormatPlayer(attacker!)} hurt {logs.FormatPlayer(player)} for {health} damage"); + } + else + { + logs.AddLogMessage($"{logs.FormatPlayer(attacker!)} killed {logs.FormatPlayer(player)}"); + } + } + + return HookResult.Continue; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsManager.cs b/mod/Jailbreak.Logs/LogsManager.cs new file mode 100644 index 00000000..a6bb247d --- /dev/null +++ b/mod/Jailbreak.Logs/LogsManager.cs @@ -0,0 +1,63 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Utils; +using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Logs; +using Jailbreak.Public.Mod.Rebel; +using Jailbreak.Public.Mod.Warden; + +namespace Jailbreak.Logs; + +public class LogsManager : IPluginBehavior, ILogService +{ + private readonly List _logMessages = new(); + private long startTime; + private IWardenService wardenService; + private IRebelService rebelService; + + public LogsManager(IWardenService wardenService, IRebelService rebelService) + { + this.wardenService = wardenService; + this.rebelService = rebelService; + } + + public void Start(BasePlugin parent) + { + parent.RegisterEventHandler(OnRoundStart); + } + + private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) + { + startTime = DateTimeOffset.Now.ToUnixTimeSeconds(); + ClearLogMessages(); + return HookResult.Continue; + } + + public void AddLogMessage(string message) + { + // format to [MM:SS] message + string prefix = $"[{TimeSpan.FromSeconds(DateTimeOffset.Now.ToUnixTimeSeconds() - startTime):mm\\:ss}] "; + _logMessages.Add(prefix + message); + } + + public ICollection GetLogMessages() + { + return _logMessages; + } + + public void ClearLogMessages() + { + _logMessages.Clear(); + } + + public string FormatPlayer(CCSPlayerController player) + { + if (wardenService.IsWarden(player)) + return $"{player.PlayerName} (WARDEN)"; + if (player.GetTeam() == CsTeam.CounterTerrorist) + return $"{player.PlayerName} (CT)"; + if (rebelService.IsRebel(player)) + return $"{player.PlayerName} (REBEL)"; + return $"{player.PlayerName} (Prisoner)"; + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsServiceExtension.cs b/mod/Jailbreak.Logs/LogsServiceExtension.cs new file mode 100644 index 00000000..815ad70d --- /dev/null +++ b/mod/Jailbreak.Logs/LogsServiceExtension.cs @@ -0,0 +1,16 @@ +using Jailbreak.Public.Extensions; +using Jailbreak.Public.Mod.Logs; +using Microsoft.Extensions.DependencyInjection; + +namespace Jailbreak.Logs; + +public static class LogsServiceExtension +{ + public static void AddLogsService(this IServiceCollection services) + { + services.AddPluginBehavior(); + + services.AddPluginBehavior(); + services.AddPluginBehavior(); + } +} \ No newline at end of file diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index 1307ac17..dbee5935 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -6,6 +6,7 @@ using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Mod.Logs; using Jailbreak.Public.Mod.Rebel; namespace Jailbreak.Teams; @@ -14,10 +15,12 @@ public class RebelManager : IPluginBehavior, IRebelService { private Dictionary rebelTimes = new(); private IRebelNotifications notifs; - - public RebelManager(IRebelNotifications notifs) + private ILogService logs; + + public RebelManager(IRebelNotifications notifs, ILogService logs) { this.notifs = notifs; + this.logs = logs; } public void Start(BasePlugin parent) @@ -83,6 +86,11 @@ public long GetRebelTimeLeft(CCSPlayerController player) public bool MarkRebel(CCSPlayerController player, long time) { + if (!rebelTimes.ContainsKey(player)) + { + logs.AddLogMessage(player.PlayerName + " is now a rebel."); + } + rebelTimes[player] = DateTimeOffset.Now.ToUnixTimeSeconds() + time; ApplyRebelColor(player); return true; @@ -91,7 +99,8 @@ public bool MarkRebel(CCSPlayerController player, long time) public void UnmarkRebel(CCSPlayerController player) { notifs.NO_LONGER_REBEL.ToPlayerChat(player); - + logs.AddLogMessage(player.PlayerName + " is no longer a rebel."); + rebelTimes.Remove(player); ApplyRebelColor(player); } diff --git a/public/Jailbreak.Public/Mod/Logs/ILogService.cs b/public/Jailbreak.Public/Mod/Logs/ILogService.cs new file mode 100644 index 00000000..29fc8899 --- /dev/null +++ b/public/Jailbreak.Public/Mod/Logs/ILogService.cs @@ -0,0 +1,11 @@ +using CounterStrikeSharp.API.Core; + +namespace Jailbreak.Public.Mod.Logs; + +public interface ILogService +{ + void AddLogMessage(string message); + ICollection GetLogMessages(); + void ClearLogMessages(); + string FormatPlayer(CCSPlayerController player); +} \ No newline at end of file diff --git a/src/Jailbreak/Jailbreak.csproj b/src/Jailbreak/Jailbreak.csproj index 212d15e7..c4f3890a 100644 --- a/src/Jailbreak/Jailbreak.csproj +++ b/src/Jailbreak/Jailbreak.csproj @@ -36,6 +36,7 @@ + diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 9bb15007..0f5607af 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -9,6 +9,7 @@ using Jailbreak.Formatting.Languages; using Jailbreak.Formatting.Logistics; using Jailbreak.Generic; +using Jailbreak.Logs; using Jailbreak.Public.Configuration; using Jailbreak.Rebel; using Jailbreak.Teams; @@ -35,6 +36,7 @@ public void ConfigureServices(IServiceCollection serviceCollection) serviceCollection.AddJailbreakWarden(); serviceCollection.AddJailbreakTeams(); serviceCollection.AddJailbreakRebel(); + serviceCollection.AddLogsService(); // Add in english localization serviceCollection.AddLanguage(config => From cd8f1e74654a4ae77d85e7b901d3314236b17240 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sun, 4 Feb 2024 00:06:20 -0800 Subject: [PATCH 22/27] Fix circular dependency --- mod/Jailbreak.Logs/LogsManager.cs | 9 ++++++--- src/Jailbreak/JailbreakServiceCollection.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mod/Jailbreak.Logs/LogsManager.cs b/mod/Jailbreak.Logs/LogsManager.cs index a6bb247d..d04a1248 100644 --- a/mod/Jailbreak.Logs/LogsManager.cs +++ b/mod/Jailbreak.Logs/LogsManager.cs @@ -5,6 +5,7 @@ using Jailbreak.Public.Mod.Logs; using Jailbreak.Public.Mod.Rebel; using Jailbreak.Public.Mod.Warden; +using Microsoft.Extensions.DependencyInjection; namespace Jailbreak.Logs; @@ -15,15 +16,17 @@ public class LogsManager : IPluginBehavior, ILogService private IWardenService wardenService; private IRebelService rebelService; - public LogsManager(IWardenService wardenService, IRebelService rebelService) + private IServiceProvider _serviceProvider; + public LogsManager(IServiceProvider serviceProvider) { - this.wardenService = wardenService; - this.rebelService = rebelService; + _serviceProvider = serviceProvider; } public void Start(BasePlugin parent) { parent.RegisterEventHandler(OnRoundStart); + wardenService = _serviceProvider.GetRequiredService(); + rebelService = _serviceProvider.GetRequiredService(); } private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) diff --git a/src/Jailbreak/JailbreakServiceCollection.cs b/src/Jailbreak/JailbreakServiceCollection.cs index 0f5607af..99a8ef80 100644 --- a/src/Jailbreak/JailbreakServiceCollection.cs +++ b/src/Jailbreak/JailbreakServiceCollection.cs @@ -33,10 +33,10 @@ public void ConfigureServices(IServiceCollection serviceCollection) serviceCollection.AddTransient(); serviceCollection.AddJailbreakGeneric(); + serviceCollection.AddLogsService(); serviceCollection.AddJailbreakWarden(); serviceCollection.AddJailbreakTeams(); serviceCollection.AddJailbreakRebel(); - serviceCollection.AddLogsService(); // Add in english localization serviceCollection.AddLanguage(config => From 5c972c464c5ae1cbfc8e5c591df46bad4a93c1c8 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sun, 4 Feb 2024 00:25:30 -0800 Subject: [PATCH 23/27] Log more things --- mod/Jailbreak.Logs/LogsCommand.cs | 10 ++-- mod/Jailbreak.Logs/LogsListeners.cs | 23 +++++++- mod/Jailbreak.Logs/LogsManager.cs | 54 ++++++++++++++++++- mod/Jailbreak.Warden/Global/WardenBehavior.cs | 10 ++-- .../Jailbreak.Public/Mod/Logs/ILogService.cs | 1 + 5 files changed, 86 insertions(+), 12 deletions(-) diff --git a/mod/Jailbreak.Logs/LogsCommand.cs b/mod/Jailbreak.Logs/LogsCommand.cs index 5b261387..cd356112 100644 --- a/mod/Jailbreak.Logs/LogsCommand.cs +++ b/mod/Jailbreak.Logs/LogsCommand.cs @@ -1,5 +1,6 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Logs; @@ -16,14 +17,9 @@ public LogsCommand(ILogService logs) } [ConsoleCommand("css_logs")] + [RequiresPermissionsOr("@css/ban", "@css/generic", "@css/kick")] public void Command_Logs(CCSPlayerController? executor, CommandInfo info) { - if (executor == null) - return; - - foreach (var log in logs.GetLogMessages()) - { - executor.PrintToConsole(log); - } + logs.PrintLogs(executor); } } \ No newline at end of file diff --git a/mod/Jailbreak.Logs/LogsListeners.cs b/mod/Jailbreak.Logs/LogsListeners.cs index d0049893..3c4461b1 100644 --- a/mod/Jailbreak.Logs/LogsListeners.cs +++ b/mod/Jailbreak.Logs/LogsListeners.cs @@ -1,4 +1,5 @@ -using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Mod.Logs; @@ -17,6 +18,26 @@ public void Start(BasePlugin parent) { parent.RegisterEventHandler(OnPlayerHurt); parent.RegisterEventHandler(OnGrenadeThrown); + parent.HookEntityOutput("func_button", "OnPressed", OnButtonPressed); + } + + private HookResult OnButtonPressed(CEntityIOOutput output, string name, CEntityInstance activator, + CEntityInstance caller, CVariant value, float delay) + { + if (!activator.IsValid) + return HookResult.Continue; + int index = (int)activator.Index; + CCSPlayerPawn? pawn = Utilities.GetEntityFromIndex(index); + if (!pawn.IsValid) + return HookResult.Continue; + if (!pawn.OriginalController.IsValid) + return HookResult.Continue; + CBaseEntity? ent = Utilities.GetEntityFromIndex((int)caller.Index); + if (!ent.IsValid) + return HookResult.Continue; + logs.AddLogMessage( + $"{logs.FormatPlayer(pawn.OriginalController.Value!)} pressed a button {ent.Entity?.Name ?? "Unlabeled"} -> {output?.Connections?.TargetDesc ?? "None"}"); + return HookResult.Continue; } private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) diff --git a/mod/Jailbreak.Logs/LogsManager.cs b/mod/Jailbreak.Logs/LogsManager.cs index d04a1248..06fef3af 100644 --- a/mod/Jailbreak.Logs/LogsManager.cs +++ b/mod/Jailbreak.Logs/LogsManager.cs @@ -1,4 +1,5 @@ -using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Public.Behaviors; using Jailbreak.Public.Extensions; @@ -17,6 +18,7 @@ public class LogsManager : IPluginBehavior, ILogService private IRebelService rebelService; private IServiceProvider _serviceProvider; + public LogsManager(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; @@ -25,10 +27,26 @@ public LogsManager(IServiceProvider serviceProvider) public void Start(BasePlugin parent) { parent.RegisterEventHandler(OnRoundStart); + parent.RegisterEventHandler(OnRoundEnd); wardenService = _serviceProvider.GetRequiredService(); rebelService = _serviceProvider.GetRequiredService(); } + private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) + { + foreach (var player in Utilities.GetPlayers()) + { + if (!player.IsValid || player.IsBot || player.IsHLTV) + continue; + foreach (var log in _logMessages) + { + player.PrintToConsole(log); + } + } + + return HookResult.Continue; + } + private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) { startTime = DateTimeOffset.Now.ToUnixTimeSeconds(); @@ -63,4 +81,38 @@ public string FormatPlayer(CCSPlayerController player) return $"{player.PlayerName} (REBEL)"; return $"{player.PlayerName} (Prisoner)"; } + + + public void PrintLogs(CCSPlayerController? player) + { + if (player == null) + { + printLogs(Server.PrintToConsole); + } + else if (player.IsValid && !player.IsBot && !player.IsHLTV) + { + printLogs(player.PrintToConsole); + } + } + + private void printLogs(Delegate printFunction) + { + if (!GetLogMessages().Any()) + { + printFunction.DynamicInvoke("No logs to display."); + return; + } + + printFunction.DynamicInvoke("********************************"); + printFunction.DynamicInvoke("***** BEGIN JAILBREAK LOGS *****"); + printFunction.DynamicInvoke("********************************"); + foreach (string log in GetLogMessages()) + { + printFunction.DynamicInvoke(log); + } + + printFunction.DynamicInvoke("********************************"); + printFunction.DynamicInvoke("****** END JAILBREAK LOGS ******"); + printFunction.DynamicInvoke("********************************"); + } } \ No newline at end of file diff --git a/mod/Jailbreak.Warden/Global/WardenBehavior.cs b/mod/Jailbreak.Warden/Global/WardenBehavior.cs index e46e575e..ad5cc0bf 100644 --- a/mod/Jailbreak.Warden/Global/WardenBehavior.cs +++ b/mod/Jailbreak.Warden/Global/WardenBehavior.cs @@ -12,7 +12,7 @@ using Jailbreak.Formatting.Core; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; - +using Jailbreak.Public.Mod.Logs; using Microsoft.Extensions.Logging; using Serilog; @@ -22,16 +22,18 @@ namespace Jailbreak.Warden.Global; public class WardenBehavior : IPluginBehavior, IWardenService { private ILogger _logger; + private ILogService logs; private IWardenNotifications _notifications; private bool _hasWarden; private CCSPlayerController? _warden; - public WardenBehavior(ILogger logger, IWardenNotifications notifications) + public WardenBehavior(ILogger logger, IWardenNotifications notifications, ILogService logs) { _logger = logger; _notifications = notifications; + this.logs = logs; } /// @@ -68,7 +70,8 @@ public bool TrySetWarden(CCSPlayerController controller) _notifications.NEW_WARDEN(_warden) .ToAllChat() .ToAllCenter(); - + + logs.AddLogMessage($"{_warden.PlayerName} is now the warden."); return true; } @@ -84,6 +87,7 @@ public bool TryRemoveWarden() _warden.Pawn.Value.RenderMode = RenderMode_t.kRenderTransColor; _warden.Pawn.Value.Render = Color.FromArgb(254, 255, 255, 255); Utilities.SetStateChanged(_warden.Pawn.Value, "CBaseModelEntity", "m_clrRender"); + logs.AddLogMessage($"{_warden.PlayerName} is no longer the warden."); } _warden = null; diff --git a/public/Jailbreak.Public/Mod/Logs/ILogService.cs b/public/Jailbreak.Public/Mod/Logs/ILogService.cs index 29fc8899..8e528f62 100644 --- a/public/Jailbreak.Public/Mod/Logs/ILogService.cs +++ b/public/Jailbreak.Public/Mod/Logs/ILogService.cs @@ -8,4 +8,5 @@ public interface ILogService ICollection GetLogMessages(); void ClearLogMessages(); string FormatPlayer(CCSPlayerController player); + void PrintLogs(CCSPlayerController? player); } \ No newline at end of file From 58b869ae95bdb88099053e85e6b7c64c0c67b8df Mon Sep 17 00:00:00 2001 From: MSWS Date: Sun, 4 Feb 2024 00:29:58 -0800 Subject: [PATCH 24/27] Bump version --- src/Jailbreak/Jailbreak.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Jailbreak/Jailbreak.cs b/src/Jailbreak/Jailbreak.cs index 4a751b1f..a6af5aba 100644 --- a/src/Jailbreak/Jailbreak.cs +++ b/src/Jailbreak/Jailbreak.cs @@ -16,7 +16,7 @@ namespace Jailbreak; public class Jailbreak : BasePlugin { public override string ModuleName => "Jailbreak"; - public override string ModuleVersion => "0.2.1.{GIT_VERSION}"; + public override string ModuleVersion => "0.3.0.{GIT_VERSION}"; public override string ModuleAuthor => "EdgeGamers Development"; private IServiceProvider _provider; From f06ead9540dac7b3be61eff4f13ae01d78cbf237 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sun, 4 Feb 2024 11:30:09 -0800 Subject: [PATCH 25/27] Remove Z axis check --- mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs index ef52504c..a4f7d89d 100644 --- a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs +++ b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs @@ -54,7 +54,7 @@ private void Paint() } _lastPosition = position; - if (start.DistanceSquared(position) > 150 * 150 || start.Z - position.Z > 0.001f) + if (start.DistanceSquared(position) > 150 * 150) { start = position; } From 2d83ad25d06d4f61e5aa602a23d6f0880cd634e7 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sun, 4 Feb 2024 17:04:09 -0800 Subject: [PATCH 26/27] Add connection checks --- mod/Jailbreak.Logs/LogsListeners.cs | 7 ++++--- mod/Jailbreak.Logs/LogsManager.cs | 4 ++-- mod/Jailbreak.Rebel/RebelListener.cs | 4 ++-- mod/Jailbreak.Rebel/RebelManager.cs | 7 ++++--- mod/Jailbreak.Teams/Queue/QueueBehavior.cs | 4 ++-- .../Paint/WardenPaintBehavior.cs | 2 +- .../Extensions/PlayerExtensions.cs | 17 +++++++++++++++++ .../Mod/Warden/IWardenService.cs | 3 ++- 8 files changed, 34 insertions(+), 14 deletions(-) diff --git a/mod/Jailbreak.Logs/LogsListeners.cs b/mod/Jailbreak.Logs/LogsListeners.cs index 3c4461b1..6305e041 100644 --- a/mod/Jailbreak.Logs/LogsListeners.cs +++ b/mod/Jailbreak.Logs/LogsListeners.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Logs; namespace Jailbreak.Logs; @@ -43,7 +44,7 @@ private HookResult OnButtonPressed(CEntityIOOutput output, string name, CEntityI private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info) { var player = @event.Userid; - if (!player.IsValid) + if (!player.IsReal()) return HookResult.Continue; var grenade = @event.Weapon; @@ -55,11 +56,11 @@ private HookResult OnGrenadeThrown(EventGrenadeThrown @event, GameEventInfo info private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) { var player = @event.Userid; - if (!player.IsValid) + if (!player.IsReal()) return HookResult.Continue; var attacker = @event.Attacker; - bool isWorld = attacker == null || !attacker.IsValid; + bool isWorld = attacker == null || !attacker.IsReal(); int health = @event.Health; if (isWorld) diff --git a/mod/Jailbreak.Logs/LogsManager.cs b/mod/Jailbreak.Logs/LogsManager.cs index 06fef3af..382b005d 100644 --- a/mod/Jailbreak.Logs/LogsManager.cs +++ b/mod/Jailbreak.Logs/LogsManager.cs @@ -36,7 +36,7 @@ private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info) { foreach (var player in Utilities.GetPlayers()) { - if (!player.IsValid || player.IsBot || player.IsHLTV) + if(!player.IsReal()) continue; foreach (var log in _logMessages) { @@ -89,7 +89,7 @@ public void PrintLogs(CCSPlayerController? player) { printLogs(Server.PrintToConsole); } - else if (player.IsValid && !player.IsBot && !player.IsHLTV) + else if (player.IsReal()) { printLogs(player.PrintToConsole); } diff --git a/mod/Jailbreak.Rebel/RebelListener.cs b/mod/Jailbreak.Rebel/RebelListener.cs index a8f82b8b..d5a955d0 100644 --- a/mod/Jailbreak.Rebel/RebelListener.cs +++ b/mod/Jailbreak.Rebel/RebelListener.cs @@ -23,13 +23,13 @@ public void Start(BasePlugin parent) HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info) { var player = @event.Userid; - if (!player.IsValid) + if (!player.IsReal()) return HookResult.Continue; if (player.GetTeam() != CsTeam.CounterTerrorist) return HookResult.Continue; var attacker = @event.Attacker; - if (!attacker.IsValid) + if (!attacker.IsReal()) return HookResult.Continue; if (attacker.GetTeam() != CsTeam.Terrorist) diff --git a/mod/Jailbreak.Rebel/RebelManager.cs b/mod/Jailbreak.Rebel/RebelManager.cs index dbee5935..426976d2 100644 --- a/mod/Jailbreak.Rebel/RebelManager.cs +++ b/mod/Jailbreak.Rebel/RebelManager.cs @@ -6,6 +6,7 @@ using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Logs; using Jailbreak.Public.Mod.Rebel; @@ -32,7 +33,7 @@ public void Start(BasePlugin parent) { foreach (var player in GetActiveRebels()) { - if (!player.IsValid) + if (!player.IsReal()) continue; if (GetRebelTimeLeft(player) <= 0) @@ -51,7 +52,7 @@ HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info) rebelTimes.Clear(); foreach (var player in Utilities.GetPlayers()) { - if (!player.IsValid) + if (!player.IsReal()) continue; ApplyRebelColor(player); } @@ -118,7 +119,7 @@ private float GetRebelTimePercentage(CCSPlayerController player) private void ApplyRebelColor(CCSPlayerController player) { - if (!player.IsValid || player.Pawn.Value == null) + if (!player.IsReal() || player.Pawn.Value == null) return; var percent = GetRebelTimePercentage(player); var percentRGB = 255 - (int)Math.Round(percent * 255.0); diff --git a/mod/Jailbreak.Teams/Queue/QueueBehavior.cs b/mod/Jailbreak.Teams/Queue/QueueBehavior.cs index 3bf72a50..9133a528 100644 --- a/mod/Jailbreak.Teams/Queue/QueueBehavior.cs +++ b/mod/Jailbreak.Teams/Queue/QueueBehavior.cs @@ -135,7 +135,7 @@ public void ForceGuard(CCSPlayerController player) /// public HookResult OnRequestToJoinTeam(CCSPlayerController? invoked, CommandInfo command) { - if (invoked == null || !invoked.IsValid) + if(invoked == null || !invoked.IsReal()) return HookResult.Continue; var state = _state.Get(invoked); @@ -174,7 +174,7 @@ public HookResult OnRequestToJoinTeam(CCSPlayerController? invoked, CommandInfo public HookResult OnPlayerSpawn(EventPlayerSpawn ev, GameEventInfo info) { var player = ev.Userid; - if (!player.IsValid) + if (!player.IsReal()) return HookResult.Continue; var state = _state.Get(ev.Userid); diff --git a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs index a4f7d89d..d66c558a 100644 --- a/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs +++ b/mod/Jailbreak.Warden/Paint/WardenPaintBehavior.cs @@ -33,7 +33,7 @@ private void Paint() return; var warden = _warden.Warden; - if (warden == null || !warden.IsValid) + if (warden == null || !warden.IsReal()) return; if ((warden.Buttons & PlayerButtons.Use) == 0) diff --git a/public/Jailbreak.Public/Extensions/PlayerExtensions.cs b/public/Jailbreak.Public/Extensions/PlayerExtensions.cs index 2b842a2d..81d8da65 100644 --- a/public/Jailbreak.Public/Extensions/PlayerExtensions.cs +++ b/public/Jailbreak.Public/Extensions/PlayerExtensions.cs @@ -9,4 +9,21 @@ public static CsTeam GetTeam(this CCSPlayerController controller) { return (CsTeam)controller.TeamNum; } + + public static bool IsReal(this CCSPlayerController player) + { + // Do nothing else before this: + // Verifies the handle points to an entity within the global entity list. + if (!player.IsReal()) + return false; + + if(player.Connected != PlayerConnectedState.PlayerConnected) + return false; + + if (player.IsBot || player.IsHLTV) + return false; + + return true; + } + } diff --git a/public/Jailbreak.Public/Mod/Warden/IWardenService.cs b/public/Jailbreak.Public/Mod/Warden/IWardenService.cs index 5ae3c882..249fae1a 100644 --- a/public/Jailbreak.Public/Mod/Warden/IWardenService.cs +++ b/public/Jailbreak.Public/Mod/Warden/IWardenService.cs @@ -1,4 +1,5 @@ using CounterStrikeSharp.API.Core; +using Jailbreak.Public.Extensions; namespace Jailbreak.Public.Mod.Warden; @@ -14,7 +15,7 @@ public interface IWardenService bool IsWarden(CCSPlayerController? player) { - if (player == null || !player.IsValid) + if (player == null || !player.IsReal()) return false; return HasWarden && Warden != null && Warden.Slot == player.Slot; } From aa766b968fc3f660a5e72f0a39c00e4c5dbdcbe4 Mon Sep 17 00:00:00 2001 From: MSWS Date: Sun, 4 Feb 2024 17:18:46 -0800 Subject: [PATCH 27/27] I am a dumbass --- public/Jailbreak.Public/Extensions/PlayerExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/Jailbreak.Public/Extensions/PlayerExtensions.cs b/public/Jailbreak.Public/Extensions/PlayerExtensions.cs index 81d8da65..3e55bc6a 100644 --- a/public/Jailbreak.Public/Extensions/PlayerExtensions.cs +++ b/public/Jailbreak.Public/Extensions/PlayerExtensions.cs @@ -14,7 +14,7 @@ public static bool IsReal(this CCSPlayerController player) { // Do nothing else before this: // Verifies the handle points to an entity within the global entity list. - if (!player.IsReal()) + if (!player.IsValid) return false; if(player.Connected != PlayerConnectedState.PlayerConnected)