diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..b160cfd --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "tcli": { + "version": "0.2.3", + "commands": [ + "tcli" + ] + } + } +} diff --git a/.env.example b/.env.example deleted file mode 100644 index 1ea155c..0000000 --- a/.env.example +++ /dev/null @@ -1,5 +0,0 @@ -GAME_DIR="C:\Program Files (x86)\Steam\steamapps\common\Lethal Company" -# Semicolon ';' seperated list of dirs to deploy to -DEPLOY_TARGETS="C:\Program Files (x86)\Steam\steamapps\common\Lethal Company\BepInEx\plugins" -# Uncomment below to build without needing the game installed. -#USE_STUBBED_LIBS=1 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1a58f3..bffbbfd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,41 +1,32 @@ - name: Build on: - pull_request: - branches: [ master, main ] push: - branches: [ master, main ] + branches: [ master ] + pull_request: jobs: build: runs-on: ubuntu-latest - env: - USE_STUBBED_LIBS: 1 steps: - - name: Checkout Repo - uses: actions/checkout@v3 - - - name: Output Short Sha Commit - run: | - export SHORT_SHA=$(git rev-parse --short ${{ github.sha }}) - echo "RELEASE_VERSION=${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}-${SHORT_SHA}" >> "$GITHUB_ENV" - shell: bash + - name: Checkout Repo + uses: actions/checkout@v4 - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x - - name: Grant execute permissions for build script - run: chmod +x build.sh + - name: Restore project + run: | + dotnet restore + dotnet tool restore - - name: Build - run: ./build.sh --configuration=Release --target=BuildThunderstore + - name: Build project + run: dotnet build -c Release - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: input-utils - path: LethalCompanyInputUtils/bin/Release/netstandard2.1/upload/ - retention-days: 30 \ No newline at end of file + - name: Upload Artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: ./dist/*.zip \ No newline at end of file diff --git a/.github/workflows/release-tags.yml b/.github/workflows/release-tags.yml index 1ef0431..02f9693 100644 --- a/.github/workflows/release-tags.yml +++ b/.github/workflows/release-tags.yml @@ -11,89 +11,142 @@ permissions: jobs: build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Restore project + run: | + dotnet restore + dotnet tool restore + + - name: Build and pack project + run: dotnet pack -c Release + + - name: Upload Thunderstore artifact + uses: actions/upload-artifact@v4 + with: + name: thunderstore-build + path: ./dist/*.zip + + - name: Upload nupkg artifact + uses: actions/upload-artifact@v4 + with: + name: nupkg-build + path: ./*/bin/Release/*.nupkg + + upload-release-artifacts: + name: Upload Release Artifacts + needs: build runs-on: ubuntu-latest env: - USE_STUBBED_LIBS: 1 RELEASE_VERSION: ${{ github.ref_name }} steps: - - name: Checkout Repo - uses: actions/checkout@v3 - - - name: Setup .NET - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 8.0.x - - - name: Grant execute permissions for build script - run: chmod +x build.sh - - - name: Build Thunderstore Package - run: ./build.sh --configuration=Release --target=BuildThunderstore - - - name: Build NuGet Package - run: ./build.sh --configuration=Release --target=BuildNuGet - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: input-utils - path: LethalCompanyInputUtils/bin/Release/netstandard2.1/upload/ - retention-days: 30 - - - name: Setup NuGet Push Source - run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Rune580/index.json" - - - name: Get NuGet Package path - run: | - for fn in LethalCompanyInputUtils/bin/Release/netstandard2.1/artifacts/*.nupkg; do echo "NUGET_PKG_PATH=${fn}" >> "$GITHUB_ENV"; done; - shell: bash - continue-on-error: true + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Download artifacts + uses: actions/download-artifact@v4 + + - name: Delete old release if it already exists + run: gh release delete --yes "${RELEASE_VERSION}" + continue-on-error: true + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Release under current tag + run: | + export "CHANGELOG_FILE=$(mktemp --suffix=.md)" + echo "CHANGELOG_FILE=${CHANGELOG_FILE}" >> $GITHUB_ENV + gh api --method POST -H "Accept: application/vnd.github+json" \ + "/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ + -f tag_name="${RELEASE_VERSION}" \ + --jq ".body" > "${CHANGELOG_FILE}" + cat "${CHANGELOG_FILE}" + gh release create "${RELEASE_VERSION}" -F "${CHANGELOG_FILE}" thunderstore-build/*.zip nupkg-build/*/bin/Release/*.nupkg + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + deploy-to-nuget: + name: Deploy to Nuget + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Download nupkg artifact + uses: actions/download-artifact@v4 + with: + name: nupkg-build + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Publish to NuGet.org + env: + NUGET_API_TOKEN: ${{ secrets.NUGET_RELEASE_API_KEY }} + run: | + dotnet nuget push ./*/bin/Release/*.nupkg --api-key $NUGET_API_TOKEN --source https://api.nuget.org/v3/index.json - - name: Push NuGet Package (GitHub Packages) - run: dotnet nuget push "${NUGET_PKG_PATH}" --source "github" - - - name: Push NuGet Package (nuget.org) - run: dotnet nuget push "${NUGET_PKG_PATH}" --api-key $NUGET_API_TOKEN --source https://api.nuget.org/v3/index.json - env: - NUGET_API_TOKEN: ${{ secrets.NUGET_RELEASE_API_KEY }} - - - name: Delete old release if it already exists - run: gh release delete --yes "${RELEASE_VERSION}" - continue-on-error: true - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Release under current tag - run: | - export "CHANGELOG_FILE=$(mktemp --suffix=.md)" - echo "CHANGELOG_FILE=${CHANGELOG_FILE}" >> $GITHUB_ENV - gh api --method POST -H "Accept: application/vnd.github+json" \ - "/repos/${GITHUB_REPOSITORY}/releases/generate-notes" \ - -f tag_name="${RELEASE_VERSION}" \ - --jq ".body" > "${CHANGELOG_FILE}" - cat "${CHANGELOG_FILE}" - gh release create "${RELEASE_VERSION}" -F "${CHANGELOG_FILE}" LethalCompanyInputUtils/bin/Release/netstandard2.1/upload/*.zip - shell: bash - continue-on-error: true - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Get upload file path - run: | - for fn in LethalCompanyInputUtils/bin/Release/netstandard2.1/upload/*.zip; do echo "THUNDERSTORE_PKG_PATH=${fn}" >> "$GITHUB_ENV"; done; - shell: bash - continue-on-error: true - - - name: Upload Thunderstore Package - uses: GreenTF/upload-thunderstore-package@v4.1 - with: - namespace: Rune580 - name: LethalCompany_InputUtils - description: Empty - version: ${{ github.ref_name }} - community: lethal-company - token: ${{ secrets.THUNDERSTORE_TOKEN }} - repo: thunderstore.io - categories: | - libraries - file: ${{ env.THUNDERSTORE_PKG_PATH }} + deploy-to-github-pkgs: + name: Deploy to GitHub Packages + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Download nupkg artifact + uses: actions/download-artifact@v4 + with: + name: nupkg-build + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Setup NuGet Push Source + run: dotnet nuget add source --username USERNAME --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/Rune580/index.json" + + - name: Publish to GitHub Packages + run: | + dotnet nuget push ./*/bin/Release/*.nupkg --source "github" + + deploy-to-thunderstore: + name: Deploy to Thunderstore + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout Repo + uses: actions/checkout@v4 + + - name: Download Thunderstore artifact + uses: actions/download-artifact@v4 + with: + name: thunderstore-build + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + - name: Restore project tools + run: dotnet tool restore + + - name: Publish to Thunderstore + env: + TCLI_AUTH_TOKEN: ${{ secrets.THUNDERSTORE_TOKEN }} + run: | + dotnet build -target:PublishThunderstoreArtifact diff --git a/.gitignore b/.gitignore index 9ee8e84..7058d57 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ riderModule.iml .idea/ **.user -.env \ No newline at end of file +.env + +dist/ \ No newline at end of file diff --git a/LethalCompanyInputUtils.sln b/LethalCompanyInputUtils.sln index d737138..b633b8b 100644 --- a/LethalCompanyInputUtils.sln +++ b/LethalCompanyInputUtils.sln @@ -2,15 +2,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LethalCompanyInputUtils", "LethalCompanyInputUtils\LethalCompanyInputUtils.csproj", "{94E68A23-78B8-4D27-BCA6-B14C238F9D67}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "build", "build\Build.csproj", "{566DD797-F558-4E46-92A7-31080C736C97}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C126025D-A702-4C8C-840F-85F8AD98A91D}" ProjectSection(SolutionItems) = preProject - build-settings.json = build-settings.json - .env = .env - manifest.json = manifest.json - READEME.md = README.md + README.md = README.md CHANGELOG.md = CHANGELOG.md + thunderstore.toml = Thunderstore/thunderstore.toml EndProjectSection EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LethalCompanyInputUtils.SourceGen", "LethalCompanyInputUtils.SourceGen\LethalCompanyInputUtils.SourceGen.csproj", "{D0544F61-1C64-44A0-A2BB-6DC53C41F2A2}" @@ -21,8 +18,6 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {566DD797-F558-4E46-92A7-31080C736C97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {566DD797-F558-4E46-92A7-31080C736C97}.Release|Any CPU.ActiveCfg = Release|Any CPU {94E68A23-78B8-4D27-BCA6-B14C238F9D67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {94E68A23-78B8-4D27-BCA6-B14C238F9D67}.Debug|Any CPU.Build.0 = Debug|Any CPU {94E68A23-78B8-4D27-BCA6-B14C238F9D67}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/LethalCompanyInputUtils/LethalCompanyInputUtils.csproj b/LethalCompanyInputUtils/LethalCompanyInputUtils.csproj index 4e5604e..1e9b794 100644 --- a/LethalCompanyInputUtils/LethalCompanyInputUtils.csproj +++ b/LethalCompanyInputUtils/LethalCompanyInputUtils.csproj @@ -5,16 +5,55 @@ preview enable true + true + Rune580 + LethalCompanyInputUtils + LethalCompanyInputUtils + com.rune580.LethalCompanyInputUtils + Lethal Company Input Utils + + + + + Rune580.Mods.LethalCompany.InputUtils + README.md + LGPL-3.0-or-later + https://github.com/Rune580/LethalCompanyInputUtils + inpututils-static-icon.png + https://github.com/Rune580/LethalCompanyInputUtils + git + - + + + + + + + + dev + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + @@ -26,16 +65,6 @@ - - ..\.gameReferences\ - ..\libs\ - - - - - - - PreserveNewest @@ -44,4 +73,41 @@ PreserveNewest + + + + $(MinVerMajor).$(MinVerMinor).$(MinVerPatch) + $(PlainVersion) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user.example b/LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user.example new file mode 100644 index 0000000..01f71da --- /dev/null +++ b/LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user.example @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LethalCompanyInputUtils/LethalCompanyInputUtilsPlugin.cs b/LethalCompanyInputUtils/LethalCompanyInputUtilsPlugin.cs index f05d572..d6e7d20 100644 --- a/LethalCompanyInputUtils/LethalCompanyInputUtilsPlugin.cs +++ b/LethalCompanyInputUtils/LethalCompanyInputUtilsPlugin.cs @@ -12,22 +12,18 @@ namespace LethalCompanyInputUtils; -[BepInPlugin(ModId, ModName, ModVersion)] +[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] [BepInDependency("ainavt.lc.lethalconfig", SoftDependency)] [BepInDependency("BMX.LobbyCompatibility", SoftDependency)] public class LethalCompanyInputUtilsPlugin : BaseUnityPlugin { - public const string ModId = "com.rune580.LethalCompanyInputUtils"; - public const string ModName = "Lethal Company Input Utils"; - public const string ModVersion = "0.7.4"; - private Harmony? _harmony; private void Awake() { Logging.SetLogSource(Logger); - _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), ModId); + _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginInfo.PLUGIN_GUID); SceneManager.activeSceneChanged += OnSceneChanged; InputSystem.onDeviceChange += OnDeviceChanged; @@ -45,7 +41,7 @@ private void Awake() ModCompat.Init(this); - Logging.Info($"InputUtils {ModVersion} has finished loading!"); + Logging.Info($"InputUtils {PluginInfo.PLUGIN_VERSION} has finished loading!"); SceneManager.activeSceneChanged += TryExportLayoutsOnLoad; } diff --git a/LethalCompanyInputUtils/Utils/FsUtils.cs b/LethalCompanyInputUtils/Utils/FsUtils.cs index 7d16863..5d91ed2 100644 --- a/LethalCompanyInputUtils/Utils/FsUtils.cs +++ b/LethalCompanyInputUtils/Utils/FsUtils.cs @@ -45,7 +45,7 @@ public static string AssetBundlesDir private static string? GetAssetBundlesDir() { - if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(LethalCompanyInputUtilsPlugin.ModId, out var pluginInfo)) + if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(PluginInfo.PLUGIN_GUID, out var pluginInfo)) return null; var dllLoc = pluginInfo.Location; @@ -94,7 +94,7 @@ public static string LocaleDir private static string? GetLocaleDir() { - if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(LethalCompanyInputUtilsPlugin.ModId, out var pluginInfo)) + if (!BepInEx.Bootstrap.Chainloader.PluginInfos.TryGetValue(PluginInfo.PLUGIN_GUID, out var pluginInfo)) return null; var dllLoc = pluginInfo.Location; diff --git a/LethalCompanyInputUtils/Utils/Logging.cs b/LethalCompanyInputUtils/Utils/Logging.cs index 0bffff0..7d967c9 100644 --- a/LethalCompanyInputUtils/Utils/Logging.cs +++ b/LethalCompanyInputUtils/Utils/Logging.cs @@ -20,7 +20,7 @@ public static void Error(string msg) { if (_logSource is null) { - Debug.LogError($"[{LethalCompanyInputUtilsPlugin.ModName}] [Error] {msg}"); + Debug.LogError($"[{PluginInfo.PLUGIN_NAME}] [Error] {msg}"); } else { @@ -32,7 +32,7 @@ public static void Warn(string msg) { if (_logSource is null) { - Debug.LogWarning($"[{LethalCompanyInputUtilsPlugin.ModName}] [Warning] {msg}"); + Debug.LogWarning($"[{PluginInfo.PLUGIN_NAME}] [Warning] {msg}"); } else { @@ -44,7 +44,7 @@ public static void Info(string msg) { if (_logSource is null) { - Debug.Log($"[{LethalCompanyInputUtilsPlugin.ModName}] [Info] {msg}"); + Debug.Log($"[{PluginInfo.PLUGIN_NAME}] [Info] {msg}"); } else { diff --git a/README.md b/README.md index 7c438fc..c3c69ec 100644 --- a/README.md +++ b/README.md @@ -281,55 +281,18 @@ Check out Unity's documentation for their [InputSystem](https://docs.unity3d.com ## Build Instructions -### Build Script Args -- `--target=TARGET` - - Valid targets: - - Build (default) - - FetchRefs - - Deploy (requires a valid `GAME_DIR` env var) - - BuildThunderstore - - BuildNuGet -- `--configuration=MSBUILDCONFIGURATION` - - Valid configurations: - - Debug (default) - - Release - -Check `Build/Build.cs` for the source code of the build script. - -### Linux Clone and enter the repo. ```shell git clone https://github.com/Rune580/LethalCompanyInputUtils && cd LethalCompanyInputUtils ``` -Copy and rename `.env.example` to `.env`. +(Optional) Copy and rename `LethalCompanyInputUtils.csproj.user.example` to `LethalCompanyInputUtils.csproj.user`. +Edit `LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user` to fit your needs. ```shell -cp .env.example .env +cp LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user.example LethalCompanyInputUtils/LethalCompanyInputUtils.csproj.user ``` -Edit `.env` to fit your needs, a valid installation of Lethal Company is required unless `USE_STUBBED_LIBS` is set. - -Run ./build.sh to run the default build task. -```shell -./build.sh -``` - -### Windows -Clone the repo. -```shell -git clone https://github.com/Rune580/LethalCompanyInputUtils -``` -Enter the cloned repo. -```shell -cd LethalCompanyInputUtils -``` -Copy and rename `.env.example` to `.env`. -```shell -cp .env.example .env -``` -Edit `.env` to fit your needs, a valid installation of Lethal Company is required unless `USE_STUBBED_LIBS` is set. - -Run ./build.ps1 to run the default build task. +Build the project using your IDE of choice or with the following command ```shell -.\build.ps1 +dotnet build ``` ## Contact diff --git a/icon.png b/Thunderstore/icons/inpututils-static-icon.png similarity index 100% rename from icon.png rename to Thunderstore/icons/inpututils-static-icon.png diff --git a/Thunderstore/thunderstore.toml b/Thunderstore/thunderstore.toml new file mode 100644 index 0000000..9ff4f3e --- /dev/null +++ b/Thunderstore/thunderstore.toml @@ -0,0 +1,42 @@ +[config] +schemaVerison = "0.0.1" + +[general] +repository = "https://thunderstore.io" + +[package] +namespace = "Rune580" +name = "LethalCompany_InputUtils" +description = "API/Library for creating Unity InputActions with in-game re-binding support. Provides an alternative UI that allows for supporting mods to have in-game re-bindable keybinds." +websiteUrl = "https://github.com/Rune580/LethalCompanyInputUtils" +containsNsfwContent = false + +[package.dependencies] +BepInEx-BepInExPack = "5.4.2100" + +[build] +icon = "icons/inpututils-static-icon.png" +readme = "../README.md" +outdir = "../dist" + +[[build.copy]] +source = "../LethalCompanyInputUtils/bin/Release/netstandard2.1/LethalCompanyInputUtils.dll" +target = "plugins/LethalCompanyInputUtils/" + +[[build.copy]] +source = "../LethalCompanyInputUtils/bin/Release/netstandard2.1/LethalCompanyInputUtils.pdb" +target = "plugins/LethalCompanyInputUtils/" + +[[build.copy]] +source = "../CHANGELOG.md" +target = "/" + +[[build.copy]] +source = "../LICENSE" +target = "/" + +[publish] +communities = [ "lethal-company" ] + +[publish.categories] +riskofrain2 = [ "mods", "libraries", "client-side" ] \ No newline at end of file diff --git a/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.dll b/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.dll index 0b075a4..9e9c3f8 100644 Binary files a/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.dll and b/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.dll differ diff --git a/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.pdb b/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.pdb index 9779023..d0c7b87 100644 Binary files a/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.pdb and b/Unity-LethalCompanyInputUtils/Packages/LethalCompanyInputUtils/LethalCompanyInputUtils.pdb differ diff --git a/build-settings.json b/build-settings.json deleted file mode 100644 index 19ce74f..0000000 --- a/build-settings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "References": [ - "Assembly-CSharp.dll", - "Newtonsoft.Json.dll", - "Unity.InputSystem.dll", - "UnityEngine.UI.dll", - "Unity.TextMeshPro.dll" - ], - "ProjectFile": "./LethalCompanyInputUtils/LethalCompanyInputUtils.csproj", - "UnityProjectDir": "./Unity-LethalCompanyInputUtils/", - "ManifestAuthor": "Rune580" -} \ No newline at end of file diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index a707719..0000000 --- a/build.ps1 +++ /dev/null @@ -1,2 +0,0 @@ -dotnet run --project build/Build.csproj -- $args -exit $LASTEXITCODE; \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100644 index dfd6b85..0000000 --- a/build.sh +++ /dev/null @@ -1 +0,0 @@ -dotnet run --project ./build/Build.csproj -- "$@" diff --git a/build/Build.cs b/build/Build.cs deleted file mode 100644 index bbdfb4f..0000000 --- a/build/Build.cs +++ /dev/null @@ -1,418 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.IO.Compression; -using System.Linq; -using System.Text.Json; -using BepInEx.AssemblyPublicizer; -using build.Utils; -using Cake.Common; -using Cake.Common.IO; -using Cake.Common.Tools.DotNet; -using Cake.Common.Tools.DotNet.Build; -using Cake.Common.Tools.DotNet.MSBuild; -using Cake.Common.Tools.DotNet.Pack; -using Cake.Core; -using Cake.Frosting; -using dotenv.net; - -namespace build; - -public static class Build -{ - public static int Main(string[] args) - { - return new CakeHost() - .UseContext() - .Run(args); - } -} - -// ReSharper disable once ClassNeverInstantiated.Global -public class BuildContext : FrostingContext -{ - #region Arguments - - public readonly string MsBuildConfiguration; - public AbsolutePath? GameDir { get; } - - public readonly string? Version; - - #endregion - - - #region Settings - - public string[] References { get; } - public CSharpProject Project { get; } - public AbsolutePath UnityProjectDir { get; } - public string ManifestAuthor { get; } - - #endregion - - - #region Env - - public AbsolutePath SolutionPath { get; } - public bool UseStubbedLibs { get; } - public AbsolutePath[] DeployTargets { get; } - - #endregion - - public readonly AbsolutePath GameReferencesDir = new AbsolutePath("../") / ".gameReferences"; - public AbsolutePath BuildDir { get; } - public AbsolutePath UnityAssetBundlesDir { get; } - - public BuildContext(ICakeContext context) : base(context) - { - DotEnv.Load(new DotEnvOptions(envFilePaths: new[] { "../.env" })); - - MsBuildConfiguration = context.Argument("configuration", "Debug"); - Version = context.EnvironmentVariable("RELEASE_VERSION"); - - SolutionPath = context.GetFiles("../*.sln") - .First() - .FullPath; - - var settings = ProjectBuildSettings.LoadFromFile("../build-settings.json"); - if (settings is null) - throw new InvalidOperationException(); - - var projectFilePath = (AbsolutePath)"../" / settings.ProjectFile; - References = settings.References; - Project = new CSharpProject(projectFilePath); - UnityProjectDir = (AbsolutePath)"../" / settings.UnityProjectDir; - ManifestAuthor = settings.ManifestAuthor; - - UseStubbedLibs = context.Environment.GetEnvironmentVariable("USE_STUBBED_LIBS") is not null; - GameDir = GetGameDirArg(context); - - string deployTargetEnv = context.Environment.GetEnvironmentVariable("DEPLOY_TARGETS"); - if (deployTargetEnv is not null) - { - DeployTargets = deployTargetEnv - .Split(";") - .Select(dir => new AbsolutePath(dir)) - .ToArray(); - } - else - { - DeployTargets = []; - } - - BuildDir = Project.Directory / "bin" / MsBuildConfiguration / "netstandard2.1"; - UnityAssetBundlesDir = UnityProjectDir / "AssetBundles" / "StandaloneWindows"; - } - - private AbsolutePath? GetGameDirArg(ICakeContext context) - { - return UseStubbedLibs ? null : new AbsolutePath(context.Arg("gameDir")); - } -} - -[TaskName("FetchRefs")] -public sealed class FetchReferences : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return !context.UseStubbedLibs; - } - - public override void Run(BuildContext context) - { - context.GameReferencesDir.EnsureDirectoryExists(); - - AbsolutePath srcDir = context.GameDir! / "Lethal Company_Data" / "Managed"; - - foreach (var reference in context.References) - { - AbsolutePath srcFile = srcDir / reference; - AbsolutePath dstFile = context.GameReferencesDir / reference; - - File.Copy(srcFile, dstFile, true); - } - } -} - -[TaskName("Restore")] -public sealed class RestoreTask : FrostingTask -{ - public override void Run(BuildContext context) - { - context.DotNetRestore(context.SolutionPath); - } -} - -[TaskName("UpdateAssetBundles")] -public sealed class UpdateAssetBundles : FrostingTask -{ - public override void Run(BuildContext context) - { - context.UnityAssetBundlesDir.GlobFiles("ui-assets") - .CopyFilesTo(context.Project.Directory / "AssetBundles"); - } -} - -[TaskName("Build")] -[IsDependentOn(typeof(RestoreTask))] -[IsDependentOn(typeof(FetchReferences))] -[IsDependentOn(typeof(UpdateAssetBundles))] -public sealed class BuildTask : FrostingTask -{ - public override void Run(BuildContext context) - { - context.DotNetBuild(context.SolutionPath, new DotNetBuildSettings - { - Configuration = context.MsBuildConfiguration - }); - } -} - -[TaskName("StubAndDeployRequiredDepsToUnity")] -public sealed class StubAndDeployRequiredUnityDeps : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - if (context.GameDir is null) - return false; - - AbsolutePath destDir = context.UnityProjectDir / "Packages" / context.Project.Name; - if (!Directory.Exists(destDir)) - return true; - - string[] depsToFind = [ "BepInEx.dll", "0Harmony.dll" ]; - var stubbedDeps = destDir.GlobFiles(depsToFind); - if (stubbedDeps.Count != depsToFind.Length) - return true; - - return false; - } - - public override void Run(BuildContext context) - { - AbsolutePath destDir = context.UnityProjectDir / "Packages" / context.Project.Name; - destDir.EnsureDirectoryExists(); - - var coreDir = context.GameDir! / "BepInEx" / "core"; - var depsToStub = coreDir.GlobFiles("BepInEx.dll", "0Harmony.dll"); - - var stubOptions = new AssemblyPublicizerOptions - { - Strip = true, - IncludeOriginalAttributesAttribute = false - }; - - foreach (var dep in depsToStub) - AssemblyPublicizer.Publicize(dep, destDir / dep.Name, stubOptions); - } -} - -[TaskName("DeployUnity")] -[IsDependentOn(typeof(BuildTask))] -[IsDependentOn(typeof(StubAndDeployRequiredUnityDeps))] -public sealed class DeployToUnity : FrostingTask -{ - public override void Run(BuildContext context) - { - AbsolutePath unityPkgDir = context.UnityProjectDir / "Packages"; - - var project = context.Project; - - AbsolutePath destDir = unityPkgDir / project.Name; - destDir.EnsureDirectoryExists(); - - context.BuildDir.GlobFiles("*.dll", "*.pdb") - .CopyFilesTo(destDir); - } -} - -[TaskName("Deploy")] -[IsDependentOn(typeof(BuildTask))] -public sealed class DeployToGame : FrostingTask -{ - public override bool ShouldRun(BuildContext context) - { - return context.GameDir is not null; - } - - public override void Run(BuildContext context) - { - var project = context.Project; - var assetBundlesDir = context.BuildDir / "AssetBundles"; - var localeDir = context.BuildDir / "Locale"; - - foreach (var target in context.DeployTargets) - { - AbsolutePath destDir = target / project.Name; - destDir.EnsureDirectoryExists(); - - context.BuildDir.GlobFiles("*.dll", "*.pdb") - .CopyFilesTo(destDir); - - assetBundlesDir.GlobFiles("*") - .CopyFilesTo(destDir / "AssetBundles"); - - localeDir.GlobFiles("*.json") - .CopyFilesTo(destDir / "Locale"); - } - } -} - -[TaskName("DebugMod")] -[IsDependentOn(typeof(DeployToGame))] -public sealed class DebugMod : FrostingTask -{ - public override void Run(BuildContext context) - { - string host; - var args = "start steam://rungameid/1966720"; - - if (OperatingSystem.IsWindows()) - { - host = "cmd.exe"; - args = $"/C {args}"; - } - else - { - host = "/bin/bash"; - args = $"-c \"{args}\""; - } - - using var startGame = new Process(); - startGame.StartInfo.FileName = host; - startGame.StartInfo.Arguments = args; - startGame.StartInfo.CreateNoWindow = false; - startGame.StartInfo.UseShellExecute = true; - startGame.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - - startGame.Start(); - startGame.WaitForExit(); - } -} - -[TaskName("BuildThunderstore")] -[IsDependentOn(typeof(BuildTask))] -public sealed class BuildThunderstorePackage : FrostingTask -{ - public override void Run(BuildContext context) - { - AbsolutePath manifestFile = "manifest.json"; - AbsolutePath iconFile = "icon.png"; - AbsolutePath readmeFile = "README.md"; - AbsolutePath changelogFile = "CHANGELOG.md"; - - var project = context.Project; - - AbsolutePath publishDir = context.BuildDir / "publish"; - publishDir.CleanAndCreateDirectory(); - - var modDir = publishDir / "plugins" / project.Name; - modDir.CreateDirectory(); - - context.BuildDir.GlobFiles("*.dll", "*.pdb") - .CopyFilesTo(modDir); - - var assetBundlesDir = context.BuildDir / "AssetBundles"; - assetBundlesDir.GlobFiles("*") - .CopyFilesTo(modDir / "AssetBundles"); - - var localeDir = context.BuildDir / "Locale"; - localeDir.GlobFiles("*.json") - .CopyFilesTo(modDir / "Locale"); - - File.Copy("../" / manifestFile, publishDir / manifestFile, true); - File.Copy("../" / iconFile, publishDir / iconFile, true); - File.Copy("../" / readmeFile, publishDir / readmeFile, true); - File.Copy("../" / changelogFile, publishDir / changelogFile, true); - - var manifest = JsonSerializer.Deserialize(File.ReadAllText(publishDir / manifestFile)); - - var uploadDir = context.BuildDir / "upload"; - uploadDir.CleanAndCreateDirectory(); - - var version = context.Version ?? manifest!.version_number; - var destFile = uploadDir / $"{context.ManifestAuthor}-{manifest!.name}-{version}.zip"; - destFile.DeleteFile(); - - ZipFile.CreateFromDirectory(publishDir, destFile); - } -} - -[TaskName("BuildNuGet")] -[IsDependentOn(typeof(BuildTask))] -public sealed class BuildNuGetPackage : FrostingTask -{ - public override void Run(BuildContext context) - { - AbsolutePath manifestFile = (AbsolutePath)"../" / "manifest.json"; - var manifest = JsonSerializer.Deserialize(File.ReadAllText(manifestFile)); - if (manifest is null) - throw new InvalidOperationException(); - - AbsolutePath readmeFile = (AbsolutePath)"../" / "README.md"; - File.Copy(readmeFile, context.BuildDir / "README.md", true); - - AbsolutePath changelogFile = (AbsolutePath)"../" / "CHANGELOG.md"; - File.Copy(changelogFile, context.BuildDir / "CHANGELOG.md", true); - - AbsolutePath iconFile = (AbsolutePath)"../" / "icon.png"; - File.Copy(iconFile, context.BuildDir / "icon.png", true); - - AbsolutePath licenseFile = (AbsolutePath)"../" / "LICENSE"; - File.Copy(licenseFile, context.BuildDir / "LICENSE", true); - - var dllFile = $"{context.Project.Name}.dll"; - var nuspecContent = $""" - - - - {context.ManifestAuthor}.Mods.LethalCompany.InputUtils - {manifest.version_number} - {manifest.description} - {context.ManifestAuthor} - {manifest.website_url} - README.md - https://cdn.rune580.dev/icons/lethalcompany_inpututils/icon.png - icon.png - LICENSE - - - - - - - - - - - - - - """; - - var nuspecFile = context.BuildDir / $"{context.Project.Name}.nuspec"; - File.WriteAllText(nuspecFile, nuspecContent); - - var msBuildSettings = new DotNetMSBuildSettings - { - Properties = - { - ["NuspecFile"] = [nuspecFile] - } - }; - - var packSettings = new DotNetPackSettings - { - NoBuild = true, - Configuration = "Release", - OutputDirectory = (string)(context.BuildDir / "artifacts"), - MSBuildSettings = msBuildSettings - }; - - context.DotNetPack(context.Project.Directory, packSettings); - } -} - -[TaskName("Default")] -[IsDependentOn(typeof(BuildTask))] -public class DefaultTask : FrostingTask; \ No newline at end of file diff --git a/build/Build.csproj b/build/Build.csproj deleted file mode 100644 index 147b757..0000000 --- a/build/Build.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - Exe - net8.0 - $(MSBuildProjectDirectory) - preview - enable - - - - - - - \ No newline at end of file diff --git a/build/ProjectBuildSettings.cs b/build/ProjectBuildSettings.cs deleted file mode 100644 index fe80fd1..0000000 --- a/build/ProjectBuildSettings.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.IO; -using System.Text.Json; -using build.Utils; - -namespace build; - -public class ProjectBuildSettings -{ - public required string[] References { get; init; } - public required string ProjectFile { get; init; } - public required string UnityProjectDir { get; init; } - public required string ManifestAuthor { get; init; } - - public static ProjectBuildSettings? LoadFromFile(AbsolutePath filePath) - { - return JsonSerializer.Deserialize(File.ReadAllText(filePath)); - } -} \ No newline at end of file diff --git a/build/Utils/AbsolutePath.cs b/build/Utils/AbsolutePath.cs deleted file mode 100644 index 0470c0e..0000000 --- a/build/Utils/AbsolutePath.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Cake.Core.IO; -using Path = System.IO.Path; - -namespace build.Utils; - -public class AbsolutePath -{ - private readonly string _path; - - public string Name => Path.GetFileName(_path); - - public AbsolutePath(string path) - { - if (path.StartsWith("./")) - path = path[2..]; - - _path = path; - } - - public void EnsureDirectoryExists() - { - if (!Directory.Exists(_path)) - Directory.CreateDirectory(_path); - } - - public void CleanAndCreateDirectory() - { - if (Directory.Exists(_path)) - Directory.Delete(_path, true); - - Directory.CreateDirectory(_path); - } - - public void CreateDirectory() - { - Directory.CreateDirectory(_path); - } - - public void DeleteFile() - { - if (File.Exists(_path)) - File.Delete(_path); - } - - public List GlobFiles(params string[] patterns) - { - return GlobFiles(SearchOption.AllDirectories, patterns); - } - - public List GlobFiles(SearchOption option, params string[] patterns) - { - return patterns.SelectMany(pattern => Directory.GetFiles(_path, pattern, option)) - .Select(x => (AbsolutePath) x) - .ToList(); - } - - public static implicit operator AbsolutePath(string path) => new(path); - public static implicit operator AbsolutePath(FilePath path) => new(path.FullPath); - public static implicit operator AbsolutePath(DirectoryPath path) => new(path.FullPath); - - public static implicit operator string(AbsolutePath path) => path._path; - public static implicit operator FilePath(AbsolutePath path) => path._path; - - public static AbsolutePath operator /(AbsolutePath left, AbsolutePath right) - { - var separator = !left._path.EndsWith('/') && !right._path.StartsWith('/') - ? $"{Path.DirectorySeparatorChar}" - : ""; - - return new AbsolutePath($"{left._path}{separator}{right._path}"); - } - - public static AbsolutePath operator /(AbsolutePath left, string right) - { - return left / (AbsolutePath)right; - } -} - -internal static class AbsolutePathUtils -{ - public static void CopyFilesTo(this IEnumerable files, AbsolutePath destDir) - { - destDir.EnsureDirectoryExists(); - - foreach (var file in files) - { - var destFile = destDir / file.Name; - File.Copy(file, destFile, true); - } - } - - public static void DeleteFiles(this IEnumerable files) - { - foreach (var file in files) - File.Delete(file); - } -} \ No newline at end of file diff --git a/build/Utils/CSharpProject.cs b/build/Utils/CSharpProject.cs deleted file mode 100644 index 4b9f329..0000000 --- a/build/Utils/CSharpProject.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.IO; - -namespace build.Utils; - -public class CSharpProject -{ - public AbsolutePath FilePath { get; } - public string Name { get; } - public AbsolutePath Directory { get; } - - public CSharpProject(AbsolutePath filePath) - { - FilePath = filePath; - Name = Path.GetFileNameWithoutExtension(filePath); - Directory = Path.GetDirectoryName(filePath)!; - } -} \ No newline at end of file diff --git a/build/Utils/ContextExtensions.cs b/build/Utils/ContextExtensions.cs deleted file mode 100644 index 9fc9032..0000000 --- a/build/Utils/ContextExtensions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Cake.Common; -using Cake.Core; - -namespace build.Utils; - -internal static class ContextExtensions -{ - public static string Arg(this ICakeContext context, string name) - { - var envVar = context.EnvironmentVariable(name.ToUpperSnakeCase()); - return envVar ?? context.Argument(name); - } -} \ No newline at end of file diff --git a/build/Utils/StringExtensions.cs b/build/Utils/StringExtensions.cs deleted file mode 100644 index b764be4..0000000 --- a/build/Utils/StringExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Linq; -using System.Text; - -namespace build.Utils; - -internal static class StringExtensions -{ - public static string ToUpperSnakeCase(this string text) - { - StringBuilder builder = new StringBuilder(); - bool first = true; - - foreach (var character in text.Select(c => c.ToString())) - { - if (first) - { - first = false; - builder.Append(character.ToUpper()); - continue; - } - - if (character.IsUpperCase()) - builder.Append('_'); - - builder.Append(character.ToUpper()); - } - - return builder.ToString(); - } - - private static bool IsUpperCase(this string text) - { - return string.Equals(text, text.ToUpper()); - } -} \ No newline at end of file diff --git a/build/Utils/ThunderstoreManifest.cs b/build/Utils/ThunderstoreManifest.cs deleted file mode 100644 index 09ee03b..0000000 --- a/build/Utils/ThunderstoreManifest.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace build.Utils; - -public class ThunderStoreManifest -{ - public string name { get; set; } - public string version_number { get; set; } - public string website_url { get; set; } - public string description { get; set; } - public string[] dependencies { get; set; } -} \ No newline at end of file diff --git a/libs/Assembly-CSharp.dll b/libs/Assembly-CSharp.dll deleted file mode 100644 index 5d5bbd7..0000000 Binary files a/libs/Assembly-CSharp.dll and /dev/null differ diff --git a/libs/Newtonsoft.Json.dll b/libs/Newtonsoft.Json.dll deleted file mode 100644 index 933e47c..0000000 Binary files a/libs/Newtonsoft.Json.dll and /dev/null differ diff --git a/libs/README.md b/libs/README.md deleted file mode 100644 index 7cb9619..0000000 --- a/libs/README.md +++ /dev/null @@ -1 +0,0 @@ -This directory contains stubbed libraries required for automatic builds \ No newline at end of file diff --git a/libs/Unity.InputSystem.dll b/libs/Unity.InputSystem.dll deleted file mode 100644 index f36621c..0000000 Binary files a/libs/Unity.InputSystem.dll and /dev/null differ diff --git a/libs/Unity.TextMeshPro.dll b/libs/Unity.TextMeshPro.dll deleted file mode 100644 index abb9576..0000000 Binary files a/libs/Unity.TextMeshPro.dll and /dev/null differ diff --git a/libs/UnityEngine.UI.dll b/libs/UnityEngine.UI.dll deleted file mode 100644 index 5266a63..0000000 Binary files a/libs/UnityEngine.UI.dll and /dev/null differ diff --git a/manifest.json b/manifest.json deleted file mode 100644 index c3180db..0000000 --- a/manifest.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "LethalCompany_InputUtils", - "version_number": "0.7.4", - "website_url": "https://github.com/Rune580/LethalCompanyInputUtils", - "description": "API/Library for creating Unity InputActions with in-game re-binding support. Provides an alternative UI that allows for supporting mods to have in-game re-bindable keybinds.", - "dependencies": [ - "BepInEx-BepInExPack-5.4.2100" - ] -} \ No newline at end of file