diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6b84a07 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,106 @@ +name: Build Release + +env: + REPOSITORY_FOLDER: "src" # subfolder with source code + PLUGIN_NAME: "LuckyDefuse" # main file of the project + +on: + push: + branches: + - main + paths: + - 'src/Version.cs' # only on change of the file with the version number string in it + workflow_dispatch: + +# job to create a new release +jobs: + create-release: + runs-on: ubuntu-latest + + steps: + - name: Get Repository Name + run: echo "REPOSITORY_NAME=`basename ${{ github.repository }}`" >> $GITHUB_ENV + + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Get Current Project Version Number From Version.cs + id: get_version + run: | + version=$(grep -oP '(?<=ModuleVersion => ")[^"]*' ${{ env.REPOSITORY_FOLDER }}/Version.cs) + echo "version=$version" >> $GITHUB_ENV + + - name: Get Current Release Version Number + id: get_latest_release + run: | + latest_release=$(curl -s -H "Authorization: token ${{ secrets.UPLOAD_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name) + echo "latest_release=$latest_release" >> $GITHUB_ENV + + - name: Compare Versions + id: compare_versions + run: | + if [ "${{ env.version }}" != "${{ env.latest_release }}" ]; then + echo "new_version=true" >> $GITHUB_ENV + else + echo "new_version=false" >> $GITHUB_ENV + fi + + - name: Install .NET + uses: actions/setup-dotnet@v2 + if: env.new_version == 'true' + with: + dotnet-version: '8.0.x' + + - name: Install Dependencies + if: env.new_version == 'true' + run: dotnet restore + + - name: Build ${{ env.REPOSITORY_NAME }} + if: env.new_version == 'true' + run: dotnet publish -c Release + + - name: Prepare ${{ env.REPOSITORY_NAME }}.info + if: env.new_version == 'true' + run: | + echo "version: ${{ env.version }}" > /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/publish/${{ env.PLUGIN_NAME }}.info + echo "repository: https://github.com/${{ github.repository }}" >> /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/publish/${{ env.PLUGIN_NAME }}.info + + - name: Prepare Release + if: env.new_version == 'true' + run: | + mv /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/publish/ /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0/${{ env.PLUGIN_NAME }}/ + + - name: Compress Release + if: env.new_version == 'true' + run: cd /home/runner/work/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_NAME }}/${{ env.REPOSITORY_FOLDER }}/bin/Release/net8.0 && zip -r /home/runner/work/${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip ${{ env.PLUGIN_NAME }} + + - name: Build Release Notes + if: env.new_version == 'true' + id: get_release_notes + run: | + release_notes=$(git log --pretty=format:"[%h](https://github.com/${{ github.repository }}/commit/%H) - %s (%an)" $(git describe --tags --abbrev=0)..HEAD) + echo "release_notes=$release_notes" >> $GITHUB_ENV + + - name: Add Release on Github + id: create_release + if: env.new_version == 'true' + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }} + with: + tag_name: ${{ env.version }} + release_name: ${{ env.version }} + body: ${{ env.release_notes }} + draft: false + prerelease: false + + - name: Upload ${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip + if: env.new_version == 'true' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.UPLOAD_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: /home/runner/work/${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip + asset_name: ${{ env.REPOSITORY_NAME }}-${{ env.version }}.zip + asset_content_type: application/zip diff --git a/LuckyDefusePlugin.cs.bkp b/LuckyDefusePlugin.cs.bkp deleted file mode 100644 index 3cbe264..0000000 --- a/LuckyDefusePlugin.cs.bkp +++ /dev/null @@ -1,131 +0,0 @@ -using System.Drawing; -using System.Security.Cryptography; -using System.Text.Json.Serialization; -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Modules.Entities.Constants; -using CounterStrikeSharp.API.Modules.Utils; - -namespace LuckyDefusePlugin; - -public class PluginConfig : BasePluginConfig -{ -} - -public class LuckyDefusePlugin : BasePlugin, IPluginConfig -{ - public override string ModuleName => "Lucky Defuse Plugin"; - public override string ModuleVersion => "1.0.0"; - - public PluginConfig Config { get; set; } - - private readonly Color[] _colors = - [ - Color.Cyan, Color.Magenta , Color.Yellow, Color.Black - ]; - private readonly List _entIds = []; - private CPlantedC4? _bomb; - private CCSPlayerController? _player; - - public void OnConfigParsed(PluginConfig? config) - { - if (config == null) return; - Config = config; - } - - public override void Load(bool hotReload) - { - RegisterEventHandler((@event, _) => - { - _entIds.Clear(); - - var bombs = Utilities.FindAllEntitiesByDesignerName("planted_c4"); - var bomb = bombs.First(); - _bomb = bomb; - _player = @event.Userid; - - //SpawnTargets(bomb.AbsOrigin!); - return HookResult.Continue; - }); - - RegisterEventHandler((@event, _) => - { - if (!_entIds.Any() || !_entIds.Contains(@event.EntindexKilled)) return HookResult.Continue; - var r = Random.Shared.Next(_colors.Length - 1); - if (r == 0) DefuseBomb(); - else DefuseBomb(); - _entIds.Clear(); - return HookResult.Continue; - }); - } - - private void SpawnTargets(Vector origin) - { - for (int i = 0; i < _colors.Length; ++i) - { - var prop = Utilities.CreateEntityByName("prop_physics_override")!; - if (prop.AbsOrigin == null || prop.AbsRotation == null || !prop.IsValid) - { - Console.WriteLine("[LuckyDefusePlugin][ERROR] Could not spawn entity!"); - return; - } - prop.AbsOrigin.X = origin.X; - prop.AbsOrigin.Y = origin.Y; - prop.AbsOrigin.Z = origin.Z + 64 + (i*40); - prop.Render = _colors[i]; - prop.Health = 100; - prop.Spawnflags = 2047; // motion disabled completely - prop.SetModel("models/dev/dev_cube.vmdl"); - prop.DispatchSpawn(); - _entIds.Add(prop.EntityHandle.Index); - } - } - - private void DefuseBomb() - { - if (_bomb == null || _player == null || !_bomb.IsValid) return; - var gameRules = Utilities.FindAllEntitiesByDesignerName("cs_gamerules").First(); - /*gameRules.BombDefused = true; - _bomb.BombDefused = true; - _bomb.DefuseCountDown = 0f; - _bomb.BeingDefused = true; - _bomb.BombTicking = false; - - var eventPtr = NativeAPI.CreateEvent("bomb_begindefuse", true); - NativeAPI.SetEventPlayerController(eventPtr, "userid", _player.Handle); - NativeAPI.SetEventBool(eventPtr, "haskit", true); - NativeAPI.FireEvent(eventPtr, false);*/ - - /*Server.NextFrame(() => - { - var eventPtr = NativeAPI.CreateEvent("round_end", true); - NativeAPI.SetEventInt(eventPtr, "winner", 1); - NativeAPI.SetEventInt(eventPtr, "reason", 0); - NativeAPI.SetEventString(eventPtr, "message", "test"); - NativeAPI.SetEventInt(eventPtr, "legacy", 0); - NativeAPI.SetEventInt(eventPtr, "player_count", 0); - NativeAPI.SetEventInt(eventPtr, "nomusic", 0); - NativeAPI.FireEvent(eventPtr, false); - });*/ - - /*var ents = Utilities.FindAllEntitiesByDesignerName("func_bomb_target"); - foreach (var ent in ents) - { - ent.Remove(); - }*/ - - /*gameRules.GameRules!.TerminateRound(5f, RoundEndReason.CTsWin); - gameRules.GameRules!.AccountCT++; - gameRules.GameRules!.TotalRoundsPlayed++; - _player.Team.*/ - - Server.PrintToChatAll("defused"); - } - - private void Boooom() - { - if (_bomb == null || !_bomb.IsValid) return; - _bomb.C4Blow = 1f; - Server.PrintToChatAll("well shit"); - } -} \ No newline at end of file diff --git a/LuckyDefusePlugin.sln b/cs2-lucky-defuse.sln similarity index 90% rename from LuckyDefusePlugin.sln rename to cs2-lucky-defuse.sln index 08081bb..23f3500 100644 --- a/LuckyDefusePlugin.sln +++ b/cs2-lucky-defuse.sln @@ -1,6 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuckyDefusePlugin", "LuckyDefusePlugin.csproj", "{1DA5A1A0-3AA7-42AC-9BDC-4DB15531869D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuckyDefuse", "src/LuckyDefuse.csproj", "{1DA5A1A0-3AA7-42AC-9BDC-4DB15531869D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/LuckyDefusePlugin.cs b/src/LuckyDefuse.cs similarity index 97% rename from LuckyDefusePlugin.cs rename to src/LuckyDefuse.cs index c3de4cc..8c0dce9 100644 --- a/LuckyDefusePlugin.cs +++ b/src/LuckyDefuse.cs @@ -8,7 +8,7 @@ using CounterStrikeSharp.API.Modules.Timers; using CounterStrikeSharp.API.Modules.Utils; -namespace LuckyDefusePlugin; +namespace LuckyDefuse; public class PluginConfig : BasePluginConfig { @@ -19,11 +19,10 @@ public class PluginConfig : BasePluginConfig public int NotificationDelay { get; set; } = 30; } -public class LuckyDefusePlugin : BasePlugin, IPluginConfig +public partial class LuckyDefuse : BasePlugin, IPluginConfig { public override string ModuleName => "Lucky Defuse Plugin"; public override string ModuleAuthor => "Jon-Mailes Graeffe "; - public override string ModuleVersion => "1.0.1"; public PluginConfig Config { get; set; } = null!; @@ -43,7 +42,7 @@ public class LuckyDefusePlugin : BasePlugin, IPluginConfig private bool _wireChosenManually; private bool _roundEnded; - public LuckyDefusePlugin() + public LuckyDefuse() { var options = new string[_colors.Length]; for (int i = 0; i < _colors.Length; ++i) diff --git a/LuckyDefusePlugin.csproj b/src/LuckyDefuse.csproj similarity index 100% rename from LuckyDefusePlugin.csproj rename to src/LuckyDefuse.csproj diff --git a/src/Version.cs b/src/Version.cs new file mode 100644 index 0000000..edea555 --- /dev/null +++ b/src/Version.cs @@ -0,0 +1,6 @@ +namespace LuckyDefuse; + +public partial class LuckyDefuse +{ + public override string ModuleVersion => "1.0.1"; +} \ No newline at end of file diff --git a/WireMenu.cs b/src/WireMenu.cs similarity index 98% rename from WireMenu.cs rename to src/WireMenu.cs index 4b81ea1..a0ef8a6 100644 --- a/WireMenu.cs +++ b/src/WireMenu.cs @@ -1,7 +1,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; -namespace LuckyDefusePlugin; +namespace LuckyDefuse; public class WireMenu(BasePlugin plugin, string title, string[] options) { diff --git a/lang/en.json b/src/lang/en.json similarity index 100% rename from lang/en.json rename to src/lang/en.json