Skip to content

Commit

Permalink
Merge pull request #1 from oscar-wos/dev
Browse files Browse the repository at this point in the history
sub-release
  • Loading branch information
oscar-wos authored Jun 28, 2024
2 parents 04c5c9f + 8e74821 commit 9f5ac39
Show file tree
Hide file tree
Showing 18 changed files with 918 additions and 0 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Build and Release

on: push

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: checkout all the submodules
uses: actions/checkout@v4
with:
submodules: recursive

- 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
with:
submodules: recursive

- 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/${{ github.event.repository.name }}
mkdir -p ./plugin/shared/Menu
- 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.*
- name: Zip
run: |
zip -r ${{ github.event.repository.name }}-${{ github.sha }}.zip ./plugin
- name: Extract version and create tag
id: extract_version
run: |
version=$(grep -oP 'public override string ModuleVersion => "\K(.*)(?=";)' ./src/Globals.cs)
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: ${{ github.event.repository.name }}-${{ 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: ./${{ github.event.repository.name }}-${{ github.sha }}.zip
asset_name: ${{ github.event.repository.name }}.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/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Menu"]
path = Menu
url = https://github.com/oscar-wos/Menu.git
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
1 change: 1 addition & 0 deletions Menu
Submodule Menu added at de0de8
29 changes: 29 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"t": "T",
"ct": "CT",
"both": "Both",
"missingPermission": "Missing permission: {red}{0}",
"invalidInput": "Invalid input: '{lightred}{0}{default}' ({orange}{1}{default})",
"delayRemaining": "{0} in {1} second(s)",
"saving": "Saving zone '{0}' {1}",
"zone.Bounce": "Bounce",
"zone.Hurt": "Hurt",
"zone.Kill": "Kill",
"zone.Teleport": "Teleport",
"menu.Add": "Add Zone",
"menu.View": "View Zones",
"menu.None": "No Zones",
"menu.Zones": "Zones:",
"menu.Teleport": "Teleport to center",
"menu.Delete": "Delete",
"menu.Debug": "Debug:",
"menu.Type": "Type:",
"menu.Teams": "Teams:",
"menu.Name": "Name:",
"menu.Delay": "Delay:",
"menu.Damage": "Damage:",
"menu.Seconds": "second(s)",
"menu.PerSecond": "per second",
"menu.Save": "Save",
"menu.Shoot": "Shoot point: {0}"
}
134 changes: 134 additions & 0 deletions src/AntiRush.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using AntiRush.Enums;

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<EventPlayerConnectFull>(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[controller] = new PlayerData();

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

private void SaveZone(CCSPlayerController controller)
{
var menu = _playerData[controller].AddZone;

CsTeam[] teams = menu!.Items[1].Option switch
{
0 => [CsTeam.Terrorist],
1 => [CsTeam.CounterTerrorist],
2 => [CsTeam.Terrorist, CsTeam.CounterTerrorist],
_ => []
};

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));
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 : 10;
var name = menu.Items[2].DataString;

if (name.Length == 0)
name = "noname";

var printMessage = $"{Prefix}{Localizer["saving", name, FormatZoneString(zoneType)]} | {Localizer["menu.Teams"]} [";

if (teams.Contains(CsTeam.Terrorist))
printMessage += $"{ChatColors.LightYellow}{Localizer["t"]}{ChatColors.White}";

if (teams.Contains(CsTeam.CounterTerrorist))
printMessage += $"{(teams.Contains(CsTeam.Terrorist) ? "|" : "")}{ChatColors.Blue}{Localizer["ct"]}{ChatColors.White}";

printMessage += "]";

if (zoneType != ZoneType.Bounce)
printMessage += $" | {Localizer["menu.Delay"]} {ChatColors.Green}{delay}{ChatColors.White}";

if (zoneType == ZoneType.Hurt)
printMessage += $" | {Localizer["menu.Damage"]} {ChatColors.Green}{damage}{ChatColors.White}";

controller.PrintToChat(printMessage);

var zone = new Zone(zoneType, teams, minPoint, maxPoint, name, delay, damage);
_zones.Add(zone);
SaveJson(Server.MapName);
}

private bool DoAction(CCSPlayerController controller, Zone zone)
{
if (zone.Type != ZoneType.Bounce && Server.CurrentTime - _playerData[controller].LastMessage >= 1)
controller.PrintToChat($"{Prefix}{FormatZoneString(zone.Type)}");

_playerData[controller].LastMessage = Server.CurrentTime;

switch (zone.Type)
{
case ZoneType.Bounce:
var speed = Math.Sqrt(_playerData[controller].LastVelocity.X * _playerData[controller].LastVelocity.X + _playerData[controller].LastVelocity.Y * _playerData[controller].LastVelocity.Y);

_playerData[controller].LastVelocity *= (-350 / (float)speed);
_playerData[controller].LastVelocity.Z = _playerData[controller].LastVelocity.Z <= 0f ? 150f : Math.Min(_playerData[controller].LastVelocity.Z, 150f);
controller.PlayerPawn.Value!.Teleport(_playerData[controller].LastPosition, controller.PlayerPawn.Value.EyeAngles, _playerData[controller].LastVelocity);
return true;

case ZoneType.Hurt:
if (Server.CurrentTime % 1 != 0)
return false;

controller.PlayerPawn.Value!.Health -= zone.Damage;
Utilities.SetStateChanged(controller.PlayerPawn.Value, "CBaseEntity", "m_iHealth");

if (controller.PlayerPawn.Value.Health <= 0)
controller.PlayerPawn.Value.CommitSuicide(true, true);

return false;

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

case ZoneType.Teleport:
controller.PlayerPawn.Value!.Teleport(_playerData[controller].SpawnPos, controller.PlayerPawn.Value.EyeAngles, Vector.Zero);
return false;
}

return false;
}

private string FormatZoneString(ZoneType type)
{
return type switch
{
ZoneType.Bounce => $"{ChatColors.Yellow}{Localizer["zone.Bounce"]}{ChatColors.White}",
ZoneType.Hurt => $"{ChatColors.Orange}{Localizer["zone.Hurt"]}{ChatColors.White}",
ZoneType.Kill => $"{ChatColors.Red}{Localizer["zone.Kill"]}{ChatColors.White}",
ZoneType.Teleport => $"{ChatColors.Magenta}{Localizer["zone.Teleport"]}{ChatColors.White}",
_ => ""
};
}

private static bool IsValidPlayer(CCSPlayerController? player)
{
return player != null && player is { IsValid: true, Connected: PlayerConnectedState.PlayerConnected, PawnIsAlive: true, IsBot: false };
}
}
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" Condition=" '$(Configuration)' == 'Debug' ">
<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>
53 changes: 53 additions & 0 deletions src/Commands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using AntiRush.Enums;

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

0 comments on commit 9f5ac39

Please sign in to comment.