Skip to content
Closed

2 #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,23 @@ jobs:
run: dotnet restore

- name: Build
run: dotnet build -c Release
run: dotnet build -c Release

- name: Create Directories
run: |
mkdir -p plugin/plugins/${{ github.event.repository.name }}

- name: Move Files
run: |
mv ./src/bin/Release/net8.0/* ./plugin/plugins/${{ github.event.repository.name }}

- name: Zip
run: |
cd ./plugin
zip -r ${{ github.event.repository.name }}-${{ github.sha }}.zip .

- name: Publish
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-${{ github.sha }}
path: ./plugin
20 changes: 8 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,30 @@ jobs:
- name: Create Directories
run: |
mkdir -p plugin/plugins/${{ github.event.repository.name }}
mkdir -p plugin/shared/Menu
mkdir -p plugin/gamedata

- name: Move Files
run: |
mv ./src/bin/Release/net8.0/* ./plugin/plugins/${{ github.event.repository.name }}
mv ./Menu/src/bin/Release/net8.0/* ./plugin/shared/Menu

- name: Remove .API
run: |
rm ./plugin/plugins/${{ github.event.repository.name }}/Menu.*
mv ./gamedata/* ./plugin/gamedata

- name: Zip
run: |
cd ./plugin
zip -r ${{ github.event.repository.name }}-${{ github.sha }}.zip .

- name: Extract version
id: extract_version
run: |
version=$(grep -oP 'public override string ModuleVersion => "\K(.*)(?=";)' ./src/Globals.cs)
echo "::set-output name=version::$version"

- name: Publish
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}-${{ github.sha }}
path: ./plugin

- name: Extract version
id: extract_version
run: |
version=$(grep -oP 'public override string ModuleVersion => "\K(.*)(?=";)' ./src/Globals.cs)
echo "::set-output name=version::$version"

- name: Create Tag
run: |
git config --global user.email "actions@github.com"
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "CSSharpUtils"]
path = CSSharpUtils
url = https://github.com/oscar-wos/CSSharpUtils
[submodule "FixVectorLeak"]
path = FixVectorLeak
url = https://github.com/oscar-wos/FixVectorLeak
6 changes: 6 additions & 0 deletions AntiRush.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menu", "Menu\src\Menu.cspro
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSSharpUtils", "CSSharpUtils\CSSharpUtils\CSSharpUtils.csproj", "{794D24A4-83A3-4F67-94DE-09087FC9554E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixVectorLeak", "FixVectorLeak\FixVectorLeak.csproj", "{819E87B2-A320-E7BB-96D6-D3592826755C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.Build.0 = Release|Any CPU
{819E87B2-A320-E7BB-96D6-D3592826755C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{819E87B2-A320-E7BB-96D6-D3592826755C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{819E87B2-A320-E7BB-96D6-D3592826755C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{819E87B2-A320-E7BB-96D6-D3592826755C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion CSSharpUtils
1 change: 1 addition & 0 deletions FixVectorLeak
Submodule FixVectorLeak added at 0f5cd6
2 changes: 1 addition & 1 deletion Menu
Submodule Menu updated from 9f8bc0 to bfd12b
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ https://www.youtube.com/watch?v=AkaBeFJcTv8
`addons/counterstrikesharp/configs/plugins/AntiRush/AntiRush.json`
```json
{
"Version": 8,
"Version": 9,
"Prefix": "{White}[{Lime}AntiRush{White}] ",
"Messages": "simple", // "simple", "detailed", "off"
"DrawZones": false, // Draw zones
"Warmup": false, // Do zones in warmup
Expand All @@ -16,6 +17,6 @@ https://www.youtube.com/watch?v=AkaBeFJcTv8
"Countdown": [ 60, 30, 15, 10, 5, 3, 2, 1 ],
"MinPlayers": 1, // Minimum total players currently in a team for zones to work
"MaxPlayers": 64, // Maximum total players for zones to work, if currentPlayers >= MaxPlayers zones are disabled
"ConfigVersion": 8
"ConfigVersion": 9
}
```
9 changes: 9 additions & 0 deletions gamedata/AntiRush.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"RunCommand": {
"signatures": {
"library": "server",
"windows": "\\x48\\x89\\x5C\\x24\\x18\\x48\\x89\\x6C\\x24\\x20\\x57\\x48\\x83\\xEC\\x20\\x48\\x8B\\xDA",
"linux": "\\x55\\x48\\x89\\xE5\\x41\\x55\\x49\\x89\\xF5\\x41\\x54\\x49\\x89\\xFC\\xE8\\x2A\\x2A\\x2A\\x2A\\x48\\x85\\xC0\\x74\\x30"
}
}
}
91 changes: 58 additions & 33 deletions src/AntiRush.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
using CounterStrikeSharp.API;
using Microsoft.Extensions.Logging;
using System.Runtime.InteropServices;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using AntiRush.Classes;
using AntiRush.Enums;
using AntiRush.Extensions;
using CSSharpUtils.Extensions;
using CSSharpUtils.Utils;
using FixVectorLeak.src;
using FixVectorLeak.src.Structs;

namespace AntiRush;

Expand All @@ -14,7 +21,8 @@ public void OnConfigParsed(AntiRushConfig config)
config.Reload();

Config = config;
_countdown = Config.Countdown.Select(c => (float)c).ToArray();
Prefix = ChatUtils.FormatMessage(config.Prefix);
_countdown = [.. Config.Countdown.Select(c => (float)c)];
}

public override void Load(bool isReload)
Expand All @@ -29,24 +37,36 @@ public override void Load(bool isReload)

AddCommand("css_antirush", "Anti-Rush", CommandAntiRush);
AddCommand("css_addzone", "Add Zone", CommandAddZone);
//AddCommand("css_viewzones", "View Zones", CommandViewZones);

LoadJson(Server.MapName);

Server.NextFrame(() =>
{
foreach (var controller in Utilities.GetPlayers())
_playerData[controller] = new PlayerData();
foreach (var player in Utilities.GetPlayers())
_playerData[player] = new PlayerData();

if (Config.RestartOnLoad)
Server.ExecuteCommand("mp_restartgame 1");
});

_isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

Logger.LogInformation("{ModuleName} loaded successfully!", ModuleName);
_ProcessMovement = new(GameData.GetSignature("RunCommand"));
_ProcessMovement!.Hook(OnProcessMovement, HookMode.Pre);
}

private void SaveZone(CCSPlayerController controller)
public override void Unload(bool isReload)
{
var menu = _playerData[controller].AddZone;
Logger.LogInformation("{ModuleName} unloaded successfully!", ModuleName);
_ProcessMovement!.Unhook(OnProcessMovement, HookMode.Pre);
}

private void SaveZone(CCSPlayerController player)
{
var menu = _playerData[player].AddZoneMenu;
_playerData[player].AddZone?.Clear();

CsTeam[] teams = menu!.Items[1].Option switch
{
0 => [CsTeam.Terrorist],
Expand All @@ -56,8 +76,8 @@ private void SaveZone(CCSPlayerController controller)
};

var zoneType = (ZoneType)menu.Items[0].Option;
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));
float[] minPoint = [Math.Min(menu.Points[0]!.Value.X, menu.Points[1]!.Value.X), Math.Min(menu.Points[0]!.Value.Y, menu.Points[1]!.Value.Y), Math.Min(menu.Points[0]!.Value.Z, menu.Points[1]!.Value.Z)];
float[] maxPoint = [Math.Max(menu.Points[0]!.Value.X, menu.Points[1]!.Value.X), Math.Max(menu.Points[0]!.Value.Y, menu.Points[1]!.Value.Y), Math.Max(menu.Points[0]!.Value.Z, menu.Points[1]!.Value.Z)];
var delay = zoneType != ZoneType.Bounce && float.TryParse(menu.Items[3].DataString, out var valueDelay) ? (float)Math.Floor(valueDelay * 10) / 10 : 0;
var damage = zoneType == ZoneType.Hurt && int.TryParse(menu.Items[4].DataString, out var valueDamage) ? valueDamage : 0;
var name = menu.Items[2].DataString;
Expand All @@ -81,84 +101,89 @@ private void SaveZone(CCSPlayerController controller)
if (zoneType == ZoneType.Hurt)
printMessage += $" | {Localizer["menu.Damage"]} {ChatColors.Green}{damage}{ChatColors.White}";

controller.PrintToChat(printMessage);
player.PrintToChat(printMessage);
SaveJson(Server.MapName);

if (Config.DrawZones)
zone.Draw();

if (_playerData.TryGetValue(player, out var playerData))
playerData.AddZone?.Clear();
}

private bool PrintAction(CCSPlayerController controller, Zone zone)
private bool PrintAction(CCSPlayerController player, Zone zone)
{
if (!controller.IsValid(true) || !(Server.CurrentTime - _playerData[controller].LastMessage >= 1))
if (!player.IsValid(true) || !(Server.CurrentTime - _playerData[player].LastMessage >= 1))
return false;

if (zone.Type == ZoneType.Hurt && Server.CurrentTime % 1 != 0)
if (zone.Type is ZoneType.Hurt && Server.CurrentTime % 1 != 0)
return false;

switch (Config.Messages)
{
case "simple":
controller.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");
player.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");
return true;

case "detailed":
if (zone.Type is (ZoneType.Bounce or ZoneType.Teleport))
if (zone.Type is (ZoneType.Bounce or ZoneType.Teleport or ZoneType.Wall))
{
controller.PrintToChat(Config.NoRushTime != 0
player.PrintToChat(Config.NoRushTime != 0
? $"{Prefix}{Localizer["rushDelayRemaining", zone.ToString(Localizer), (_roundStart + Config.NoRushTime - Server.CurrentTime).ToString("0")]}"
: $"{Prefix}{zone.ToString(Localizer)}");

return true;
}

if (zone.Type == ZoneType.Hurt)
if (zone.Type is ZoneType.Hurt)
{
controller.PrintToChat($"{Prefix}{Localizer["hurtDamage", zone.ToString(Localizer), zone.Damage]}");
player.PrintToChat($"{Prefix}{Localizer["hurtDamage", zone.ToString(Localizer), zone.Damage]}");
return true;
}
controller.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");

player.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");
return true;
}

return false;
}

private void DoAction(CCSPlayerController controller, Zone zone)
private void DoAction(CCSPlayerController player, Zone zone)
{
const PlayerButtons checkButtons = PlayerButtons.Forward | PlayerButtons.Back | PlayerButtons.Moveleft | PlayerButtons.Moveright;
if (player.PlayerPawn.Value?.MovementServices is null)
return;

if (PrintAction(player, zone))
_playerData[player].LastMessage = Server.CurrentTime;

if (PrintAction(controller, zone))
_playerData[controller].LastMessage = Server.CurrentTime;
if (zone.Type is (ZoneType.Bounce or ZoneType.Wall))
_playerData[player].BlockButtons = Server.TickedTime + 0.3;

switch (zone.Type)
{
case ZoneType.Bounce:
if ((controller.Buttons & checkButtons) != 0)
controller.PlayerPawn.Value?.Teleport(new Vector(_playerData[controller].LastPos[0], _playerData[controller].LastPos[1], _playerData[controller].LastPos[2]), null, new Vector(_playerData[controller].LastVel[0], _playerData[controller].LastVel[1], _playerData[controller].LastVel[2]));

else
controller.Bounce(_playerData[controller].LastPos, _playerData[controller].LastVel);
player.Bounce(_playerData[player].LastPos, _playerData[player].LastVel);

return;

case ZoneType.Hurt:
if (Server.CurrentTime % 1 == 0)
controller.Damage(zone.Damage);
player.Damage(zone.Damage);

return;

case ZoneType.Kill:
controller.PlayerPawn.Value!.CommitSuicide(true, true);
player.PlayerPawn.Value.CommitSuicide(true, true);
return;

case ZoneType.Teleport:
controller.PlayerPawn.Value!.Teleport(_playerData[controller].SpawnPos, controller.PlayerPawn.Value.EyeAngles, Vector.Zero);
if (_playerData[player].SpawnPos is not null)
player.PlayerPawn.Value.Teleport(_playerData[player].SpawnPos, velocity: new Vector_t());

return;

case ZoneType.Wall:
controller.PlayerPawn.Value?.Teleport(new Vector(_playerData[controller].LastPos[0], _playerData[controller].LastPos[1], _playerData[controller].LastPos[2]), null, Vector.Zero);
player.PlayerPawn.Value.Teleport(new Vector_t(_playerData[player].LastPos[0], _playerData[player].LastPos[1], _playerData[player].LastPos[2]), velocity: new Vector_t());
return;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/AntiRush.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="*" ExcludeAssets="runtime" />
<ProjectReference Include="..\CSSharpUtils\CSSharpUtils\CSSharpUtils.csproj" />
<ProjectReference Include="..\FixVectorLeak\FixVectorLeak.csproj" />
<ProjectReference Include="..\Menu\src\Menu.csproj" />
</ItemGroup>

Expand Down
17 changes: 17 additions & 0 deletions src/Classes/PlayerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using AntiRush.Enums;
using FixVectorLeak.src.Structs;

namespace AntiRush.Classes;

public class PlayerData
{
public AddZoneMenu? AddZoneMenu { get; set; } = null;
public Zone? AddZone { get; set; } = null;
public float LastMessage { get; set; }
public bool Debug { get; set; }
public bool[] DebugOptions { get; set; } = new bool[Enum.GetValues(typeof(ZoneType)).Length];
public Vector_t? SpawnPos { get; set; } = null;
public float[] LastPos { get; set; } = [];
public float[] LastVel { get; set; } = [];
public double BlockButtons { get; set; } = 0;
}
2 changes: 1 addition & 1 deletion src/ZoneData.cs → src/Classes/ZoneData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AntiRush;
namespace AntiRush.Classes;

public class ZoneData
{
Expand Down
Loading