Skip to content

Commit 569283c

Browse files
authored
Merge pull request #17 from oscar-wos/2.0.0
2.0.0
2 parents 4ee0383 + a4216a7 commit 569283c

26 files changed

+646
-319
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,25 @@ jobs:
2121
run: dotnet restore
2222

2323
- name: Build
24-
run: dotnet build -c Release
24+
run: dotnet build -c Release
25+
26+
- name: Create Directories
27+
run: |
28+
mkdir -p plugin/plugins/${{ github.event.repository.name }}
29+
mkdir -p plugin/gamedata
30+
31+
- name: Move Files
32+
run: |
33+
mv ./src/bin/Release/net8.0/* ./plugin/plugins/${{ github.event.repository.name }}
34+
mv ./gamedata/* ./plugin/gamedata
35+
36+
- name: Zip
37+
run: |
38+
cd ./plugin
39+
zip -r ${{ github.event.repository.name }}-${{ github.sha }}.zip .
40+
41+
- name: Publish
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: ${{ github.event.repository.name }}-${{ github.sha }}
45+
path: ./plugin

.github/workflows/release.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,30 @@ jobs:
5151
- name: Create Directories
5252
run: |
5353
mkdir -p plugin/plugins/${{ github.event.repository.name }}
54-
mkdir -p plugin/shared/Menu
54+
mkdir -p plugin/gamedata
5555
5656
- name: Move Files
5757
run: |
5858
mv ./src/bin/Release/net8.0/* ./plugin/plugins/${{ github.event.repository.name }}
59-
mv ./Menu/src/bin/Release/net8.0/* ./plugin/shared/Menu
60-
61-
- name: Remove .API
62-
run: |
63-
rm ./plugin/plugins/${{ github.event.repository.name }}/Menu.*
59+
mv ./gamedata/* ./plugin/gamedata
6460
6561
- name: Zip
6662
run: |
6763
cd ./plugin
6864
zip -r ${{ github.event.repository.name }}-${{ github.sha }}.zip .
6965
70-
- name: Extract version
71-
id: extract_version
72-
run: |
73-
version=$(grep -oP 'public override string ModuleVersion => "\K(.*)(?=";)' ./src/Globals.cs)
74-
echo "::set-output name=version::$version"
75-
7666
- name: Publish
7767
uses: actions/upload-artifact@v4
7868
with:
7969
name: ${{ github.event.repository.name }}-${{ github.sha }}
8070
path: ./plugin
8171

72+
- name: Extract version
73+
id: extract_version
74+
run: |
75+
version=$(grep -oP 'public override string ModuleVersion => "\K(.*)(?=";)' ./src/Globals.cs)
76+
echo "::set-output name=version::$version"
77+
8278
- name: Create Tag
8379
run: |
8480
git config --global user.email "actions@github.com"

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "CSSharpUtils"]
55
path = CSSharpUtils
66
url = https://github.com/oscar-wos/CSSharpUtils
7+
[submodule "FixVectorLeak"]
8+
path = FixVectorLeak
9+
url = https://github.com/oscar-wos/FixVectorLeak

AntiRush.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menu", "Menu\src\Menu.cspro
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSSharpUtils", "CSSharpUtils\CSSharpUtils\CSSharpUtils.csproj", "{794D24A4-83A3-4F67-94DE-09087FC9554E}"
1111
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixVectorLeak", "FixVectorLeak\FixVectorLeak.csproj", "{819E87B2-A320-E7BB-96D6-D3592826755C}"
13+
EndProject
1214
Global
1315
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1416
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,10 @@ Global
2729
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Debug|Any CPU.Build.0 = Debug|Any CPU
2830
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.ActiveCfg = Release|Any CPU
2931
{794D24A4-83A3-4F67-94DE-09087FC9554E}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{819E87B2-A320-E7BB-96D6-D3592826755C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{819E87B2-A320-E7BB-96D6-D3592826755C}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{819E87B2-A320-E7BB-96D6-D3592826755C}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{819E87B2-A320-E7BB-96D6-D3592826755C}.Release|Any CPU.Build.0 = Release|Any CPU
3036
EndGlobalSection
3137
GlobalSection(SolutionProperties) = preSolution
3238
HideSolutionNode = FALSE

FixVectorLeak

Submodule FixVectorLeak added at 0f5cd6e

Menu

Submodule Menu updated from 9f8bc03 to bfd12bd

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ https://www.youtube.com/watch?v=AkaBeFJcTv8
33
`addons/counterstrikesharp/configs/plugins/AntiRush/AntiRush.json`
44
```json
55
{
6-
"Version": 8,
6+
"Version": 9,
7+
"Prefix": "{White}[{Lime}AntiRush{White}] ",
78
"Messages": "simple", // "simple", "detailed", "off"
89
"DrawZones": false, // Draw zones
910
"Warmup": false, // Do zones in warmup
@@ -16,6 +17,6 @@ https://www.youtube.com/watch?v=AkaBeFJcTv8
1617
"Countdown": [ 60, 30, 15, 10, 5, 3, 2, 1 ],
1718
"MinPlayers": 1, // Minimum total players currently in a team for zones to work
1819
"MaxPlayers": 64, // Maximum total players for zones to work, if currentPlayers >= MaxPlayers zones are disabled
19-
"ConfigVersion": 8
20+
"ConfigVersion": 9
2021
}
2122
```

gamedata/AntiRush.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"RunCommand": {
3+
"signatures": {
4+
"library": "server",
5+
"windows": "\\x48\\x89\\x5C\\x24\\x18\\x48\\x89\\x6C\\x24\\x20\\x57\\x48\\x83\\xEC\\x20\\x48\\x8B\\xDA",
6+
"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"
7+
}
8+
}
9+
}

src/AntiRush.cs

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
using CounterStrikeSharp.API;
1+
using Microsoft.Extensions.Logging;
2+
using System.Runtime.InteropServices;
3+
using CounterStrikeSharp.API;
24
using CounterStrikeSharp.API.Core;
35
using CounterStrikeSharp.API.Modules.Utils;
6+
using AntiRush.Classes;
47
using AntiRush.Enums;
8+
using AntiRush.Extensions;
59
using CSSharpUtils.Extensions;
10+
using CSSharpUtils.Utils;
11+
using FixVectorLeak.src;
12+
using FixVectorLeak.src.Structs;
613

714
namespace AntiRush;
815

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

1623
Config = config;
17-
_countdown = Config.Countdown.Select(c => (float)c).ToArray();
24+
Prefix = ChatUtils.FormatMessage(config.Prefix);
25+
_countdown = [.. Config.Countdown.Select(c => (float)c)];
1826
}
1927

2028
public override void Load(bool isReload)
@@ -29,35 +37,47 @@ public override void Load(bool isReload)
2937

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

3441
LoadJson(Server.MapName);
3542

3643
Server.NextFrame(() =>
3744
{
38-
foreach (var controller in Utilities.GetPlayers())
39-
_playerData[controller] = new PlayerData();
45+
foreach (var player in Utilities.GetPlayers())
46+
_playerData[player] = new PlayerData();
4047

4148
if (Config.RestartOnLoad)
4249
Server.ExecuteCommand("mp_restartgame 1");
4350
});
51+
52+
_isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
53+
54+
Logger.LogInformation("{ModuleName} loaded successfully!", ModuleName);
55+
_ProcessMovement = new(GameData.GetSignature("RunCommand"));
56+
_ProcessMovement!.Hook(OnProcessMovement, HookMode.Pre);
4457
}
4558

46-
private void SaveZone(CCSPlayerController controller)
59+
public override void Unload(bool isReload)
4760
{
48-
var menu = _playerData[controller].AddZone;
61+
Logger.LogInformation("{ModuleName} unloaded successfully!", ModuleName);
62+
_ProcessMovement!.Unhook(OnProcessMovement, HookMode.Pre);
63+
}
4964

65+
private void SaveZone(CCSPlayerController player)
66+
{
67+
var menu = _playerData[player].AddZoneMenu;
68+
_playerData[player].AddZone?.Clear();
69+
5070
CsTeam[] teams = menu!.Items[1].Option switch
5171
{
52-
0 => [CsTeam.Terrorist],
53-
1 => [CsTeam.CounterTerrorist],
54-
2 => [CsTeam.Terrorist, CsTeam.CounterTerrorist],
72+
0 => [CsTeam.Terrorist, CsTeam.CounterTerrorist],
73+
1 => [CsTeam.Terrorist],
74+
2 => [CsTeam.CounterTerrorist],
5575
_ => []
5676
};
5777

5878
var zoneType = (ZoneType)menu.Items[0].Option;
59-
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));
60-
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));
79+
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)];
80+
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)];
6181
var delay = zoneType != ZoneType.Bounce && float.TryParse(menu.Items[3].DataString, out var valueDelay) ? (float)Math.Floor(valueDelay * 10) / 10 : 0;
6282
var damage = zoneType == ZoneType.Hurt && int.TryParse(menu.Items[4].DataString, out var valueDamage) ? valueDamage : 0;
6383
var name = menu.Items[2].DataString;
@@ -81,84 +101,89 @@ private void SaveZone(CCSPlayerController controller)
81101
if (zoneType == ZoneType.Hurt)
82102
printMessage += $" | {Localizer["menu.Damage"]} {ChatColors.Green}{damage}{ChatColors.White}";
83103

84-
controller.PrintToChat(printMessage);
104+
player.PrintToChat(printMessage);
85105
SaveJson(Server.MapName);
86106

87107
if (Config.DrawZones)
88108
zone.Draw();
109+
110+
if (_playerData.TryGetValue(player, out var playerData))
111+
playerData.AddZone?.Clear();
89112
}
90113

91-
private bool PrintAction(CCSPlayerController controller, Zone zone)
114+
private bool PrintAction(CCSPlayerController player, Zone zone)
92115
{
93-
if (!controller.IsValid(true) || !(Server.CurrentTime - _playerData[controller].LastMessage >= 1))
116+
if (!player.IsValid(true) || !(Server.CurrentTime - _playerData[player].LastMessage >= 1))
94117
return false;
95118

96-
if (zone.Type == ZoneType.Hurt && Server.CurrentTime % 1 != 0)
119+
if (zone.Type is ZoneType.Hurt && Server.CurrentTime % 1 != 0)
97120
return false;
98121

99122
switch (Config.Messages)
100123
{
101124
case "simple":
102-
controller.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");
125+
player.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");
103126
return true;
104127

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

112135
return true;
113136
}
114137

115-
if (zone.Type == ZoneType.Hurt)
138+
if (zone.Type is ZoneType.Hurt)
116139
{
117-
controller.PrintToChat($"{Prefix}{Localizer["hurtDamage", zone.ToString(Localizer), zone.Damage]}");
140+
player.PrintToChat($"{Prefix}{Localizer["hurtDamage", zone.ToString(Localizer), zone.Damage]}");
118141
return true;
119142
}
120-
121-
controller.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");
143+
144+
player.PrintToChat($"{Prefix}{zone.ToString(Localizer)}");
122145
return true;
123146
}
124147

125148
return false;
126149
}
127150

128-
private void DoAction(CCSPlayerController controller, Zone zone)
151+
private void DoAction(CCSPlayerController player, Zone zone)
129152
{
130-
const PlayerButtons checkButtons = PlayerButtons.Forward | PlayerButtons.Back | PlayerButtons.Moveleft | PlayerButtons.Moveright;
153+
if (player.PlayerPawn.Value?.MovementServices is null)
154+
return;
155+
156+
if (PrintAction(player, zone))
157+
_playerData[player].LastMessage = Server.CurrentTime;
131158

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

135162
switch (zone.Type)
136163
{
137164
case ZoneType.Bounce:
138-
if ((controller.Buttons & checkButtons) != 0)
139-
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]));
140-
141-
else
142-
controller.Bounce(_playerData[controller].LastPos, _playerData[controller].LastVel);
165+
player.Bounce(_playerData[player].LastPos, _playerData[player].LastVel);
143166

144167
return;
145168

146169
case ZoneType.Hurt:
147170
if (Server.CurrentTime % 1 == 0)
148-
controller.Damage(zone.Damage);
171+
player.Damage(zone.Damage);
149172

150173
return;
151174

152175
case ZoneType.Kill:
153-
controller.PlayerPawn.Value!.CommitSuicide(true, true);
176+
player.PlayerPawn.Value.CommitSuicide(true, true);
154177
return;
155178

156179
case ZoneType.Teleport:
157-
controller.PlayerPawn.Value!.Teleport(_playerData[controller].SpawnPos, controller.PlayerPawn.Value.EyeAngles, Vector.Zero);
180+
if (_playerData[player].SpawnPos is not null)
181+
player.PlayerPawn.Value.Teleport(_playerData[player].SpawnPos, velocity: new Vector_t());
182+
158183
return;
159184

160185
case ZoneType.Wall:
161-
controller.PlayerPawn.Value?.Teleport(new Vector(_playerData[controller].LastPos[0], _playerData[controller].LastPos[1], _playerData[controller].LastPos[2]), null, Vector.Zero);
186+
player.PlayerPawn.Value.Teleport(new Vector_t(_playerData[player].LastPos[0], _playerData[player].LastPos[1], _playerData[player].LastPos[2]), velocity: new Vector_t());
162187
return;
163188
}
164189
}

0 commit comments

Comments
 (0)