diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml new file mode 100644 index 0000000..d99d60a --- /dev/null +++ b/.github/workflows/dotnet.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index c6127b3..3e16852 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ \ No newline at end of file diff --git a/Refiller.sln b/Refiller.sln new file mode 100644 index 0000000..a504b25 --- /dev/null +++ b/Refiller.sln @@ -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 diff --git a/Refiller.sln.DotSettings b/Refiller.sln.DotSettings new file mode 100644 index 0000000..9abb76c --- /dev/null +++ b/Refiller.sln.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/src/Config.cs b/src/Config.cs new file mode 100644 index 0000000..b8b59bb --- /dev/null +++ b/src/Config.cs @@ -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 +} \ No newline at end of file diff --git a/src/Globals.cs b/src/Globals.cs new file mode 100644 index 0000000..32a3b6d --- /dev/null +++ b/src/Globals.cs @@ -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"; +} \ No newline at end of file diff --git a/src/Refiller.cs b/src/Refiller.cs new file mode 100644 index 0000000..d366773 --- /dev/null +++ b/src/Refiller.cs @@ -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 +{ + public void OnConfigParsed(RefillerConfig config) + { + Config = config; + } + + public override void Load(bool isReload) + { + RegisterEventHandler(OnPlayerDeath); + } + + public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info) + { + var victim = @event.Userid; + + if (victim == null || !victim.IsValid) + return HookResult.Continue; + + List players = + [ + @event.Attacker, + Config.AssistRefill && @event.Attacker != @event.Assister ? @event.Assister : null + ]; + + List> 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().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(), "CBasePlayerWeapon", "m_pReserveAmmo"); + } + }); + + return HookResult.Continue; + } +} \ No newline at end of file diff --git a/src/Refiller.csproj b/src/Refiller.csproj new file mode 100644 index 0000000..f517ae0 --- /dev/null +++ b/src/Refiller.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + +