Skip to content

Commit

Permalink
fix: try SubModule fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed Jun 27, 2024
1 parent b9c027f commit 5fa4b61
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 53 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build -c Release

Expand All @@ -35,9 +32,6 @@ jobs:
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build -c Release

Expand Down
32 changes: 10 additions & 22 deletions src/AntiRush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override void Load(bool isReload)
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventBulletImpact>(OnBulletImpact);
RegisterEventHandler<EventPlayerConnect>(OnPlayerConnect);
RegisterEventHandler<EventPlayerConnectFull>(OnPlayerConnect);

AddCommand("css_antirush", "Anti-Rush", CommandAntiRush);
AddCommand("css_addzone", "Add Zone", CommandAddZone);
Expand All @@ -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");
Expand All @@ -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));
Expand All @@ -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 };
}
}
21 changes: 14 additions & 7 deletions src/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Globals.cs
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
14 changes: 11 additions & 3 deletions src/Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonBombsite>(json);
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Listeners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand Down Expand Up @@ -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);
}
}
14 changes: 7 additions & 7 deletions src/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
{
Expand Down Expand Up @@ -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 = "<font color=\"#ADD8E6\">" }]));
addZoneMenu.AddItem(new MenuItem(MenuItemType.Button, [new CustomButton(Localizer["menu.Save"], c => SaveZone(c)) { Prefix = "<font color=\"#ADD8E6\">" }]));

addZoneMenu.Items[3].DataString = "0.0";
addZoneMenu.Items[4].DataString = "10";
Expand All @@ -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;
}
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 5fa4b61

Please sign in to comment.