From bfd359bfccfb71d56438cdf7af5d315f2336abf0 Mon Sep 17 00:00:00 2001 From: MSWS Date: Fri, 2 Feb 2024 18:21:20 -0800 Subject: [PATCH 01/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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/13] 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;