From 8a1ff53dc797d2975fb5fd3bf615b2a51fe9d2ee Mon Sep 17 00:00:00 2001
From: oscar <29248751+oscar-wos@users.noreply.github.com>
Date: Fri, 7 Jun 2024 18:36:50 +0100
Subject: [PATCH 1/3] INIT
---
.github/workflows/dotnet.yml | 96 ++++++++++++++++++++++++++++++++++++
.gitignore | 55 ++-------------------
Refiller.sln | 25 ++++++++++
Refiller.sln.DotSettings | 2 +
src/Config.cs | 13 +++++
src/Globals.cs | 9 ++++
src/Refiller.cs | 73 +++++++++++++++++++++++++++
src/Refiller.csproj | 13 +++++
8 files changed, 234 insertions(+), 52 deletions(-)
create mode 100644 .github/workflows/dotnet.yml
create mode 100644 Refiller.sln
create mode 100644 Refiller.sln.DotSettings
create mode 100644 src/Config.cs
create mode 100644 src/Globals.cs
create mode 100644 src/Refiller.cs
create mode 100644 src/Refiller.csproj
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
+
+
+
+
+
+
+
From 06fa5f8a84fe5066cace4a9eaa7e9b5060232d9f Mon Sep 17 00:00:00 2001
From: oscar <29248751+oscar-wos@users.noreply.github.com>
Date: Fri, 7 Jun 2024 18:53:41 +0100
Subject: [PATCH 2/3] fix: Moved health to nextframe
---
.github/workflows/dotnet.yml | 6 +++---
Refiller.sln.DotSettings | 2 --
src/Refiller.cs | 34 ++++++++++++++++++++--------------
3 files changed, 23 insertions(+), 19 deletions(-)
delete mode 100644 Refiller.sln.DotSettings
diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml
index d99d60a..3937302 100644
--- a/.github/workflows/dotnet.yml
+++ b/.github/workflows/dotnet.yml
@@ -68,7 +68,7 @@ jobs:
- name: Publish
uses: actions/upload-artifact@v4
with:
- name: Sessions-${{ github.sha }}
+ name: Refiller-${{ github.sha }}
path: plugin
- name: Create Release
@@ -91,6 +91,6 @@ jobs:
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_path: ./plugin/Refiller-${{ github.sha }}.zip
+ asset_name: Refiller.zip
asset_content_type: application/zip
\ No newline at end of file
diff --git a/Refiller.sln.DotSettings b/Refiller.sln.DotSettings
deleted file mode 100644
index 9abb76c..0000000
--- a/Refiller.sln.DotSettings
+++ /dev/null
@@ -1,2 +0,0 @@
-
- True
\ No newline at end of file
diff --git a/src/Refiller.cs b/src/Refiller.cs
index d366773..07beb64 100644
--- a/src/Refiller.cs
+++ b/src/Refiller.cs
@@ -27,7 +27,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
List players =
[
@event.Attacker,
- Config.AssistRefill && @event.Attacker != @event.Assister ? @event.Assister : null
+ Config.AssistRefill ? @event.Assister : null
];
List> weapons = [];
@@ -38,17 +38,6 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
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(() =>
@@ -60,12 +49,29 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
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");
}
+
+ foreach (var player in players.Where(player => player != null && player.IsValid))
+ {
+ 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)
+ };
+
+ Utilities.SetStateChanged(player!.PlayerPawn.Value!, "CBaseEntity", "m_iHealth");
+
+ if (!Config.ArmorRefill)
+ continue;
+
+ player!.PlayerPawn.Value!.ArmorValue = 100;
+ Utilities.SetStateChanged(player!.PlayerPawn.Value!, "CCSPlayerPawn", "m_ArmorValue");
+ }
});
return HookResult.Continue;
From 5a4a478f80b47d05a3bc85b9eead34ba793f39af Mon Sep 17 00:00:00 2001
From: oscar <29248751+oscar-wos@users.noreply.github.com>
Date: Fri, 7 Jun 2024 19:01:01 +0100
Subject: [PATCH 3/3] docs: Update README
---
README.md | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 2dd52cb..ce89d6b 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,9 @@
-# Refiller
-CS2 - Heal
+`counterstrikesharp/configs/plugins/Refiller/Refiller.json`
+```json
+{
+ "AssistRefill": // true, false - Apply refill's to assisters
+ "HealthRefill": // "all", "0", "100" - Amount of health to refill
+ "AmmoRefill": // "all", "current", "off" - "all" = slot1,slot2,slot3,slot4 - "current" = current weapon
+ "ArmorRefill": // true, false - Refill armor
+}
+```
\ No newline at end of file