Skip to content

Commit

Permalink
INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed Jun 26, 2024
1 parent c844cf5 commit a3a1a97
Show file tree
Hide file tree
Showing 16 changed files with 737 additions and 0 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Build and Release

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build -c Release

release:
needs: build
runs-on: ubuntu-latest
permissions: write-all

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build -c Release

- name: Create Directories
run: |
mkdir -p plugin/plugins/AntiRush
mkdir -p plugin/shared/Menu
- name: Move Files
run: |
mv ./src/bin/Release/net8.0/* ./plugin/plugins/AntiRush
mv ./Menu/bin/Release/net8.0/* ./plugin/shared/Menu
- name: Remove .API
run: |
rm ./plugin/plugins/AntiRush/Menu.*
- name: Zip
run: |
cd plugin/
zip -r AntiRush-${{ github.sha }}.zip .
- name: Extract version and create tag
id: extract_version
run: |
version="1.0.4"
echo "Version found: $version"
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git tag $version
git push origin $version
echo "::set-output name=version::$version"
- name: Publish
uses: actions/upload-artifact@v4
with:
name: AntiRush-${{ github.sha }}
path: plugin

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.extract_version.outputs.version }}
release_name: ${{ steps.extract_version.outputs.version }}
body: |
This is an automated release.
draft: false
prerelease: false

- name: Upload Release Asset
id: upload_release_asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./plugin/AntiRush-${{ github.sha }}.zip
asset_name: AntiRush.zip
asset_content_type: application/zip
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/
obj/
.vs/
31 changes: 31 additions & 0 deletions AntiRush.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34928.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntiRush", "src\AntiRush.csproj", "{9B2DEBE8-1EEF-47E8-B890-D15A3F0FF109}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Menu", "..\Menu\src\Menu.csproj", "{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9B2DEBE8-1EEF-47E8-B890-D15A3F0FF109}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B2DEBE8-1EEF-47E8-B890-D15A3F0FF109}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B2DEBE8-1EEF-47E8-B890-D15A3F0FF109}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B2DEBE8-1EEF-47E8-B890-D15A3F0FF109}.Release|Any CPU.Build.0 = Release|Any CPU
{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5AC48D94-A9F6-4566-92A4-F78C39A9FCD6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9E0A8B2A-965F-41F5-A4FE-0443B1318011}
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"t": "T",
"ct": "CT",
"both": "Both",
"missingPermission": "Missing permission: {red}{0}",
"invalidInput": "Invalid input: '{lightred}{0}{default}' ({orange}{1}{default})",
"zone.Bounce": "Bounce",
"zone.Hurt": "Hurt",
"zone.Kill": "Kill",
"zone.Teleport": "Teleport",
"menu.Add": "Add Zone",
"menu.View": "View Zones",
"menu.Debug": "Debug: ",
"menu.Type": "Type: ",
"menu.Teams": "Teams: ",
"menu.Name": "Name: ",
"menu.Delay": "Delay: ",
"menu.Damage": "Damage: ",
"menu.Seconds": " Second(s)",
"menu.Save": "Save",
"menu.Shoot": "Shoot point: {0}"
}
84 changes: 84 additions & 0 deletions src/AntiRush.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using AntiRush.Enums;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;

namespace AntiRush;

public partial class AntiRush : BasePlugin
{
public override void Load(bool isReload)
{
RegisterListener<Listeners.OnTick>(OnTick);
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn);
RegisterEventHandler<EventBulletImpact>(OnBulletImpact);
RegisterEventHandler<EventPlayerConnect>(OnPlayerConnect);

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

if (!isReload)
return;

foreach (var controller in Utilities.GetPlayers())
_playerData.Add(controller, new PlayerData());

LoadJson(Server.MapName);
Server.ExecuteCommand("mp_restartgame 1");
}

private void BouncePlayer(CCSPlayerController controller)
{
var pos = _playerData[controller].LastPosition;
var vel = _playerData[controller].LastVelocity;
var speed = Math.Sqrt(vel.X * vel.X + vel.Y * vel.Y);

vel *= (-350 / (float)speed);
vel.Z = vel.Z <= 0f ? 150f : Math.Max(vel.Z, 150f);
controller.PlayerPawn.Value!.Teleport(pos, controller.PlayerPawn!.Value.EyeAngles, vel);
}

private void SaveZone(AddZoneMenu menu)
{
CsTeam[] teams = [];

switch (menu.Items[1].Option)
{
case 0:
teams = [CsTeam.Terrorist];
break;

case 1:
teams = [CsTeam.CounterTerrorist];
break;

case 2:
teams = [CsTeam.Terrorist, CsTeam.CounterTerrorist];
break;
}

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));

if (!float.TryParse(menu.Items[3].DataString, out var delay))
delay = 0.0f;

if (!int.TryParse(menu.Items[4].DataString, out var damage))
damage = 10;

var zone = new Zone((ZoneType)menu.Items[0].Option, teams, minPoint, maxPoint, menu.Items[2].DataString, delay, damage);
_zones.Add(zone);
}

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 };
}
}
26 changes: 26 additions & 0 deletions src/AntiRush.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<ItemGroup>
<Content Include="..\lang\**\*.*">
<Link>%(RecursiveDir)\lang\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<Target Name="CopyCustomContent" AfterTargets="AfterBuild">
<Copy SourceFiles="$(OutputPath)AntiRush.dll" DestinationFolder="\\wsl.localhost\Debian\home\user\cs2\game\csgo\addons\counterstrikesharp\plugins\AntiRush" />
<Copy SourceFiles="$(OutputPath)lang\en.json" DestinationFolder="\\wsl.localhost\Debian\home\user\cs2\game\csgo\addons\counterstrikesharp\plugins\AntiRush\lang" />
</Target>

</Project>
54 changes: 54 additions & 0 deletions src/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using AntiRush.Enums;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Utils;

namespace AntiRush;

public partial class AntiRush
{
public void CommandAntiRush(CCSPlayerController? controller, CommandInfo info)
{
if (!IsValidPlayer(controller))
return;

if (!AdminManager.PlayerHasPermissions(controller, "@css/generic"))
{
controller!.PrintToChat($"{Prefix}{Localizer["missingPermission", "@css/generic"]}");
return;
}

BuildMenu(controller!);
}

public void CommandAddZone(CCSPlayerController? controller, CommandInfo info)
{
if (!IsValidPlayer(controller))
return;

if (!AdminManager.PlayerHasPermissions(controller, "@css/root"))
{
controller!.PrintToChat($"{Prefix}{Localizer["missingPermission", "@css/root"]}");
return;
}

BuildMenu(controller!);
BuildMenu(controller!, MenuType.Add);
}

public void CommandViewZones(CCSPlayerController? controller, CommandInfo info)
{
if (!IsValidPlayer(controller))
return;

if (!AdminManager.PlayerHasPermissions(controller, "@css/generic"))
{
controller!.PrintToChat($"{Prefix}{Localizer["missingPermission", "@css/generic"]}");
return;
}

BuildMenu(controller!);
BuildMenu(controller!, MenuType.View);
}
}
8 changes: 8 additions & 0 deletions src/Enums/MenuType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AntiRush.Enums;

public enum MenuType
{
Main,
Add,
View
}
9 changes: 9 additions & 0 deletions src/Enums/ZoneType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AntiRush.Enums;

public enum ZoneType
{
Bounce,
Hurt,
Kill,
Teleport
}
Loading

0 comments on commit a3a1a97

Please sign in to comment.