From 5fa4b61b7651e1dffc6445468d06ac2247caeecf Mon Sep 17 00:00:00 2001 From: oscar <29248751+oscar-wos@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:32:59 +0100 Subject: [PATCH] fix: try SubModule fix --- .github/workflows/dotnet.yml | 6 ------ src/AntiRush.cs | 32 ++++++++++---------------------- src/Events.cs | 21 ++++++++++++++------- src/Globals.cs | 5 +++-- src/Json.cs | 14 +++++++++++--- src/Listeners.cs | 12 ++++++------ src/Menus.cs | 14 +++++++------- 7 files changed, 51 insertions(+), 53 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index b654aa8..6ca0d74 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -15,9 +15,6 @@ jobs: with: dotnet-version: '8.0.x' - - name: Restore dependencies - run: dotnet restore - - name: Build run: dotnet build -c Release @@ -35,9 +32,6 @@ jobs: with: dotnet-version: '8.0.x' - - name: Restore dependencies - run: dotnet restore - - name: Build run: dotnet build -c Release diff --git a/src/AntiRush.cs b/src/AntiRush.cs index 1ae536d..3f248e4 100644 --- a/src/AntiRush.cs +++ b/src/AntiRush.cs @@ -13,7 +13,7 @@ public override void Load(bool isReload) RegisterListener(OnMapStart); RegisterEventHandler(OnPlayerSpawn); RegisterEventHandler(OnBulletImpact); - RegisterEventHandler(OnPlayerConnect); + RegisterEventHandler(OnPlayerConnect); AddCommand("css_antirush", "Anti-Rush", CommandAntiRush); AddCommand("css_addzone", "Add Zone", CommandAddZone); @@ -23,7 +23,7 @@ public override void Load(bool isReload) return; foreach (var controller in Utilities.GetPlayers()) - _playerData.Add(controller, new PlayerData()); + _playerData[controller] = new PlayerData(); LoadJson(Server.MapName); Server.ExecuteCommand("mp_restartgame 1"); @@ -40,24 +40,17 @@ private void BouncePlayer(CCSPlayerController controller) controller.PlayerPawn.Value!.Teleport(pos, controller.PlayerPawn!.Value.EyeAngles, vel); } - private void SaveZone(AddZoneMenu menu) + private void SaveZone(CCSPlayerController controller) { - CsTeam[] teams = []; + var menu = _playerData[controller].AddZone; - switch (menu.Items[1].Option) + CsTeam[] teams = menu!.Items[1].Option switch { - case 0: - teams = [CsTeam.Terrorist]; - break; - - case 1: - teams = [CsTeam.CounterTerrorist]; - break; - - case 2: - teams = [CsTeam.Terrorist, CsTeam.CounterTerrorist]; - break; - } + 0 => [CsTeam.Terrorist], + 1 => [CsTeam.CounterTerrorist], + 2 => [CsTeam.Terrorist, CsTeam.CounterTerrorist], + _ => [] + }; var minPoint = new Vector(Math.Min(menu.Points[0].X, menu.Points[1].X), Math.Min(menu.Points[0].Y, menu.Points[1].Y), Math.Min(menu.Points[0].Z, menu.Points[1].Z)); var maxPoint = new Vector(Math.Max(menu.Points[0].X, menu.Points[1].X), Math.Max(menu.Points[0].Y, menu.Points[1].Y), Math.Max(menu.Points[0].Z, menu.Points[1].Z)); @@ -76,9 +69,4 @@ private static bool IsValidPlayer(CCSPlayerController? player) { return player != null && player is { IsValid: true, Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true, IsBot: false }; } - - private static bool VectorIsZero(Vector vector) - { - return vector is { X: 0.0f, Y: 0.0f, Z: 0.0f }; - } } \ No newline at end of file diff --git a/src/Events.cs b/src/Events.cs index 5cb7cb3..86072b0 100644 --- a/src/Events.cs +++ b/src/Events.cs @@ -9,10 +9,13 @@ private HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info) { var controller = @event.Userid; - if (controller == null || !controller.IsValid || !_playerData.TryGetValue(controller!, out var value)) + if (controller == null || !controller.IsValid) return HookResult.Continue; - value.SpawnPos = new Vector(controller!.PlayerPawn!.Value!.AbsOrigin!.X, controller!.PlayerPawn!.Value!.AbsOrigin.Y, controller!.PlayerPawn!.Value!.AbsOrigin.Z); + if (!_playerData.ContainsKey(controller!)) + _playerData[controller!] = new PlayerData(); + + _playerData[controller!].SpawnPos = new Vector(controller!.PlayerPawn!.Value!.AbsOrigin!.X, controller!.PlayerPawn!.Value!.AbsOrigin.Y, controller!.PlayerPawn!.Value!.AbsOrigin.Z); return HookResult.Continue; } @@ -24,9 +27,12 @@ private HookResult OnBulletImpact(EventBulletImpact @event, GameEventInfo info) if (!IsValidPlayer(controller) || !_playerData.TryGetValue(controller!, out var value) || value.AddZone == null || !Menu.IsCurrentMenu(controller!, value.AddZone)) return HookResult.Continue; - if (VectorIsZero(value.AddZone.Points[0])) + if (!value.AddZone.Points[0].IsZero() && !value.AddZone.Points[1].IsZero()) + return HookResult.Continue; + + if (value.AddZone.Points[0].IsZero()) value.AddZone.Points[0] = new Vector(@event.X, @event.Y, @event.Z); - else if (VectorIsZero(value.AddZone.Points[1])) + else if (value.AddZone.Points[1].IsZero()) value.AddZone.Points[1] = new Vector(@event.X, @event.Y, @event.Z); Menu.PopMenu(controller!, value.AddZone); @@ -35,14 +41,15 @@ private HookResult OnBulletImpact(EventBulletImpact @event, GameEventInfo info) return HookResult.Continue; } - private HookResult OnPlayerConnect(EventPlayerConnect @event, GameEventInfo info) + private HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info) { var controller = @event.Userid; - if (controller == null || !controller.IsValid || !_playerData.ContainsKey(controller)) + if (controller == null || !controller.IsValid) return HookResult.Continue; - _playerData.Add(controller, new PlayerData()); + if (!_playerData.ContainsKey(controller!)) + _playerData[controller] = new PlayerData(); return HookResult.Continue; } diff --git a/src/Globals.cs b/src/Globals.cs index 0d42f2c..6d9d0e0 100644 --- a/src/Globals.cs +++ b/src/Globals.cs @@ -1,9 +1,10 @@ -using AntiRush.Enums; -using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes; using CounterStrikeSharp.API.Modules.Utils; namespace AntiRush; +[MinimumApiVersion(245)] public partial class AntiRush { public override string ModuleName => "Anti-Rush"; diff --git a/src/Json.cs b/src/Json.cs index fb29d9b..d320d47 100644 --- a/src/Json.cs +++ b/src/Json.cs @@ -13,10 +13,7 @@ public void LoadJson(string mapName) var path = $"../../csgo/addons/counterstrikesharp/configs/plugins/Zones/{mapName}.json"; if (!File.Exists(path)) - { - Logger.LogError($"File {path} does not exist."); return; - } /* var json = File.ReadAllText(path); var obj = JsonSerializer.Deserialize(json); @@ -40,6 +37,17 @@ void AddZone(Bombsite bombsite, JsonZone zone) } */ } + + public void SaveJson(string mapName) + { + var path = $"../../csgo/addons/counterstrikesharp/configs/plugins/Zones/{mapName}.json"; + + if (!File.Exists(path)) + { + Logger.LogError($"File {path} does not exist."); + return; + } + } } public class JsonZone diff --git a/src/Listeners.cs b/src/Listeners.cs index c619a5a..4297260 100644 --- a/src/Listeners.cs +++ b/src/Listeners.cs @@ -6,11 +6,6 @@ namespace AntiRush; public partial class AntiRush { - private void OnMapStart(string mapName) - { - LoadJson(mapName); - } - private void OnTick() { foreach (var controller in Utilities.GetPlayers().Where(player => player is { IsValid: true, PawnIsAlive: true })) @@ -39,9 +34,14 @@ private void OnTick() if (bounce) continue; - + _playerData[controller].LastPosition = controller!.PlayerPawn.Value!.AbsOrigin!; _playerData[controller].LastVelocity = controller.PlayerPawn.Value.AbsVelocity; } } + + private void OnMapStart(string mapName) + { + LoadJson(mapName); + } } \ No newline at end of file diff --git a/src/Menus.cs b/src/Menus.cs index f4c90eb..ebd72bc 100644 --- a/src/Menus.cs +++ b/src/Menus.cs @@ -78,7 +78,7 @@ private void BuildMainMenu(CCSPlayerController controller, bool updateMenu = fal return; } - var customButton = (CustomButton)selectedItem!.Values![selectedItem.Option]; + var customButton = (CustomButton)selectedItem.Values![selectedItem.Option]; customButton.Callback.Invoke(controller); break; @@ -100,7 +100,7 @@ private void BuildAddZoneMenu(CCSPlayerController controller) if (_playerData[controller].AddZone == null) addZoneMenu.AddItem(new MenuItem(MenuItemType.Text, new MenuValue(Localizer["menu.Shoot", "1"]))); - else if (VectorIsZero(_playerData[controller].AddZone!.Points[1])) + else if (_playerData[controller].AddZone!.Points[1].IsZero()) addZoneMenu.AddItem(new MenuItem(MenuItemType.Text, new MenuValue(Localizer["menu.Shoot", "2"]))); else { @@ -131,7 +131,7 @@ private void BuildAddZoneMenu(CCSPlayerController controller) ? new MenuItem(MenuItemType.Input, new MenuValue(Localizer["menu.Damage"])) : new MenuItem(MenuItemType.Spacer)); - addZoneMenu.AddItem(new MenuItem(MenuItemType.Button, [new CustomButton(Localizer["menu.Save"], c => SaveZone(_playerData[controller].AddZone!)) { Prefix = "" }])); + addZoneMenu.AddItem(new MenuItem(MenuItemType.Button, [new CustomButton(Localizer["menu.Save"], c => SaveZone(c)) { Prefix = "" }])); addZoneMenu.Items[3].DataString = "0.0"; addZoneMenu.Items[4].DataString = "10"; @@ -156,19 +156,19 @@ private void BuildAddZoneMenu(CCSPlayerController controller) if (buttons == MenuButtons.Input) { if (menu.Option == 2 && selectedItem!.DataString.Length > 16) - selectedItem!.DataString = selectedItem!.DataString[..16]; + selectedItem.DataString = selectedItem.DataString[..16]; if (menu.Option == 3 && !float.TryParse(selectedItem!.DataString, out _)) { controller.PrintToChat($"{Prefix}{Localizer["invalidInput", selectedItem.DataString, "float"]}"); - selectedItem.DataString = ""; + selectedItem.DataString = "0.0"; menu.AcceptInput = true; } if (menu.Option == 4 && !int.TryParse(selectedItem!.DataString, out _)) { controller.PrintToChat($"{Prefix}{Localizer["invalidInput", selectedItem.DataString, "int"]}"); - selectedItem.DataString = ""; + selectedItem.DataString = "10"; menu.AcceptInput = true; } } @@ -181,7 +181,7 @@ private void BuildAddZoneMenu(CCSPlayerController controller) if (buttons == MenuButtons.Select && selectedItem is { Type: MenuItemType.Button }) { - var customButton = (CustomButton)selectedItem!.Values![selectedItem.Option]; + var customButton = (CustomButton)selectedItem.Values![selectedItem.Option]; customButton.Callback.Invoke(controller); Menu.ClearMenus(controller); }