Skip to content

Commit

Permalink
INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-wos committed Jun 7, 2024
1 parent f00a185 commit 8a1ff53
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 52 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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/Refiller
- name: Move Files
run: |
mv ./src/bin/Release/net8.0/* ./plugin/plugins/Refiller
- name: Zip
run: |
cd plugin/
zip -r Refiller-${{ github.sha }}.zip .
- 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 "actions@github.com"
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: Sessions-${{ 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/Sessions-${{ github.sha }}.zip
asset_name: Sessions.zip
asset_content_type: application/zip
55 changes: 3 additions & 52 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
bin/
obj/
.vs/
25 changes: 25 additions & 0 deletions Refiller.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

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}") = "Refiller", "src\Refiller.csproj", "{C62E916A-1F2B-456C-95DE-DA718B446F37}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C62E916A-1F2B-456C-95DE-DA718B446F37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C62E916A-1F2B-456C-95DE-DA718B446F37}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C62E916A-1F2B-456C-95DE-DA718B446F37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C62E916A-1F2B-456C-95DE-DA718B446F37}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5204CE6F-E75D-4148-9B62-B1B293097F09}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions Refiller.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/ConvertIfStatementToSwitchStatement/AssumeOpenTypeHierarchy/@EntryValue">True</s:Boolean></wpf:ResourceDictionary>
13 changes: 13 additions & 0 deletions src/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using CounterStrikeSharp.API.Core;
using System.Text.Json.Serialization;

namespace Refiller;

public class RefillerConfig : BasePluginConfig
{
public override int Version { get; set; } = 1;
[JsonPropertyName("AssistRefill")] public bool AssistRefill { get; set; } = true; // true, false
[JsonPropertyName("HealthRefill")] public string HealthRefill { get; set; } = "all"; // "all", "0", "100"
[JsonPropertyName("AmmoRefill")] public string AmmoRefill { get; set; } = "all"; // "all", "current", "off"
[JsonPropertyName("ArmorRefill")] public bool ArmorRefill { get; set; } = true; // true, false
}
9 changes: 9 additions & 0 deletions src/Globals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Refiller;

public partial class Refiller
{
public RefillerConfig Config { get; set; } = new();
public override string ModuleName => "Refiller";
public override string ModuleAuthor => "github.com/oscar-wos/Refiller";
public override string ModuleVersion => "1.0.0";
}
73 changes: 73 additions & 0 deletions src/Refiller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Utils;
using Microsoft.Extensions.Logging;

namespace Refiller;

public partial class Refiller : BasePlugin, IPluginConfig<RefillerConfig>
{
public void OnConfigParsed(RefillerConfig config)
{
Config = config;
}

public override void Load(bool isReload)
{
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath);
}

public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
{
var victim = @event.Userid;

if (victim == null || !victim.IsValid)
return HookResult.Continue;

List<CCSPlayerController?> players =
[
@event.Attacker,
Config.AssistRefill && @event.Attacker != @event.Assister ? @event.Assister : null
];

List<CHandle<CBasePlayerWeapon>> weapons = [];

foreach (var player in players.Where(player => player != null && player.IsValid))
{
if (Config.AmmoRefill == "all")
weapons.AddRange(player!.PlayerPawn!.Value!.WeaponServices!.MyWeapons);
else if (Config.AmmoRefill == "current")
weapons.Add(player!.PlayerPawn!.Value!.WeaponServices!.ActiveWeapon);

var currentHealth = player!.PlayerPawn.Value!.Health;

player!.PlayerPawn.Value!.Health = Config.HealthRefill switch
{
"all" => 100,
_ => currentHealth + int.Parse(Config.HealthRefill) >= 100 ? 100 : currentHealth + int.Parse(Config.HealthRefill)
};

if (Config.ArmorRefill)
player!.PlayerPawn.Value!.ArmorValue = 100;
}

Server.NextFrame(() =>
{
foreach (var weapon in weapons)
{
var weaponData = weapon.Value!.As<CCSWeaponBase>().VData;
if (weaponData == null)
continue;
Console.WriteLine($"{weaponData.Name}");
weapon.Value!.Clip1 = weaponData.MaxClip1;
weapon.Value!.ReserveAmmo[0] = weaponData.PrimaryReserveAmmoMax;
Utilities.SetStateChanged(weapon.Value!.As<CCSWeaponBase>(), "CBasePlayerWeapon", "m_pReserveAmmo");
}
});

return HookResult.Continue;
}
}
13 changes: 13 additions & 0 deletions src/Refiller.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<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" />
</ItemGroup>

</Project>

0 comments on commit 8a1ff53

Please sign in to comment.