From c1c03090dafd9b1074e456dba8a7c71eccc65628 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 19 Mar 2023 00:09:39 +0000 Subject: [PATCH 01/33] Automated dotnet-format update --- .../Features/ContinueSaveFile/Patches/SandBoxSubModulePatch.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bannerlord.BLSE/Features/ContinueSaveFile/Patches/SandBoxSubModulePatch.cs b/src/Bannerlord.BLSE/Features/ContinueSaveFile/Patches/SandBoxSubModulePatch.cs index cc3ae74..15e2404 100644 --- a/src/Bannerlord.BLSE/Features/ContinueSaveFile/Patches/SandBoxSubModulePatch.cs +++ b/src/Bannerlord.BLSE/Features/ContinueSaveFile/Patches/SandBoxSubModulePatch.cs @@ -42,7 +42,7 @@ static void FailedToLoad(string message) MessageBoxDialog.Show(message, "Warning!"); } } - + if (AccessTools2.GetDelegate("SandBox.SandBoxSaveHelper:TryLoadSave") is not { } tryLoadSave) return true; if (GetSaveGameArg?.Invoke(Module.CurrentModule.StartupInfo) is not { } saveFileName) return true; if (saveFileName.EndsWith(".sav", StringComparison.OrdinalIgnoreCase)) saveFileName = saveFileName.Remove(saveFileName.Length - 4, 4); From a1bca17eb04674fb4a2546e1c984477a34397993 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:08:20 +0200 Subject: [PATCH 02/33] Added a mono compatible ILRepack fork, switched to ubuntu --- .github/workflows/publish.yml | 2 +- src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj | 3 +++ src/Bannerlord.BLSE/Bannerlord.BLSE.csproj | 2 +- src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj | 3 +++ src/nuget.config | 9 ++++++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8eae453..e482844 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,7 +25,7 @@ env: jobs: build: name: Publish - runs-on: windows-latest + runs-on: ubuntu-latest outputs: mod_version: ${{ steps.changelog.outputs.mod_version }} mod_description: ${{ steps.changelog.outputs.mod_description }} diff --git a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj index b1a211c..97c9c18 100644 --- a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj +++ b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj @@ -16,9 +16,12 @@ false true + $(ILRepackFX) + + diff --git a/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj b/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj index dd2f24c..0101a53 100644 --- a/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj +++ b/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj @@ -6,7 +6,7 @@ $(Version).$(GITHUB_RUN_NUMBER) netstandard2.0 - 10.0 + 11.0 enable x64 diff --git a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj index 6c72daa..2dccff3 100644 --- a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj +++ b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj @@ -23,8 +23,11 @@ true true false + $(ILRepackFX) + + diff --git a/src/nuget.config b/src/nuget.config index 432b482..eb3fc3b 100644 --- a/src/nuget.config +++ b/src/nuget.config @@ -3,5 +3,12 @@ + - + + + + + + + \ No newline at end of file From 42b51f3eecf8e39f20f2d53091a666e29c24faea Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:11:08 +0200 Subject: [PATCH 03/33] Update publish.yml --- .github/workflows/publish.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e482844..306be87 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -2,8 +2,6 @@ name: Publish on: push: - branches: - - master paths: - '.github/workflows/publish.yml' - 'src/Bannerlord.LauncherEx/**.*' @@ -64,7 +62,7 @@ jobs: # NEXUSMODS # ########################### publish-on-nexusmods: - if: false + if: false && github.ref == 'refs/heads/master' needs: ["build"] uses: BUTR/workflows/.github/workflows/release-nexusmods.yml@master with: @@ -82,6 +80,7 @@ jobs: # GITHUB # ########################### publish-on-github: + if: github.ref == 'refs/heads/master' needs: ["build"] uses: BUTR/workflows/.github/workflows/release-github.yml@master with: From 27c7e1018be3d620a0f6afe8b535dd8afacf08ee Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:25:38 +0200 Subject: [PATCH 04/33] Build fix? --- .github/workflows/publish.yml | 2 ++ src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 306be87..51196a2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -33,6 +33,8 @@ jobs: - name: Build Bannerlord.BLSE run: >- mkdir bannerlord; + dotnet build src/Bannerlord.BLSE/Bannerlord.BLSE.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + dotnet build src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; diff --git a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj index 97c9c18..e7d3179 100644 --- a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj +++ b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj @@ -33,12 +33,13 @@ - + + + - From 8be9408dd40bde9de589e6cad57b8e120b419279 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 15:33:06 +0000 Subject: [PATCH 05/33] Fixed Linux build --- .../Bannerlord.BLSE.Launcher.csproj | 2 +- .../Bannerlord.BLSE.LauncherEx.csproj | 2 +- .../Bannerlord.BLSE.Shared.csproj | 26 ++++++++++------- .../Bannerlord.BLSE.Standalone.csproj | 2 +- .../Bannerlord.LauncherEx.csproj | 29 ++++++++++--------- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj b/src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj index 687cf88..c88d786 100644 --- a/src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj +++ b/src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj @@ -2,7 +2,7 @@ net472 - 10.0 + 11.0 enable x64 winexe diff --git a/src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj b/src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj index 06c3343..d056f56 100644 --- a/src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj +++ b/src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj @@ -2,7 +2,7 @@ net472 - 10.0 + 11.0 enable x64 winexe diff --git a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj index e7d3179..7a9b59c 100644 --- a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj +++ b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj @@ -2,30 +2,30 @@ netstandard2.0 - 10.0 + 11.0 enable x64 library Bannerlord.BLSE.Shared $(DefineConstants);HARMONYEXTENSIONS_HARMONYX - + $(Configurations); false true false true - $(ILRepackFX) + $(PkgBUTR_ILRepack)\tools\net461\ILRepack.exe - + - - + + - + @@ -42,7 +42,7 @@ - + @@ -61,7 +61,13 @@ - + + $(MSBuildThisFileDirectory)..\Bannerlord.LauncherEx\Bannerlord.LauncherEx.csproj + "$([System.IO.Path]::GetFullPath('$(LauncherExProject)'))" + dotnet msbuild $(LauncherExProjectFull) --target:BuildExtended -p:GameVersion=%(GameAPIVersion.GameVersion) -p:Configuration=$(Configuration)_%(GameAPIVersion.Flat) -p:ILRepackTargetConfigurations=$(Configuration)_%(GameAPIVersion.Flat) + + + @@ -74,5 +80,5 @@ - + \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj b/src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj index 113e0c5..a88a4c4 100644 --- a/src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj +++ b/src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj @@ -2,7 +2,7 @@ net472 - 10.0 + 11.0 enable x64 winexe diff --git a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj index 2dccff3..1d4ceda 100644 --- a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj +++ b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj @@ -17,19 +17,6 @@ $(DefineConstants);$(GameVersionConstant);HARMONYEXTENSIONS_HARMONYX - - - false - true - true - false - $(ILRepackFX) - - - - - - Bannerlord.LauncherEx @@ -107,4 +94,20 @@ + + + false + true + true + false + $(PkgBUTR_ILRepack)\tools\net461\ILRepack.exe + + + + + + + + + \ No newline at end of file From a47b667515e60454931d974e403a050cadd63f92 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 15:38:26 +0000 Subject: [PATCH 06/33] Fix --- .github/workflows/publish.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 51196a2..8ad21ce 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,10 +31,8 @@ jobs: - uses: actions/checkout@v3 - name: Build Bannerlord.BLSE - run: >- + run: | mkdir bannerlord; - dotnet build src/Bannerlord.BLSE/Bannerlord.BLSE.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; - dotnet build src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; From 951f5b3a0e29eed2220f265804376b830ee1f7a6 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:03:46 +0000 Subject: [PATCH 07/33] Fix --- src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj | 5 ++--- src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj index 7a9b59c..7d5a23e 100644 --- a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj +++ b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj @@ -64,10 +64,9 @@ $(MSBuildThisFileDirectory)..\Bannerlord.LauncherEx\Bannerlord.LauncherEx.csproj "$([System.IO.Path]::GetFullPath('$(LauncherExProject)'))" - dotnet msbuild $(LauncherExProjectFull) --target:BuildExtended -p:GameVersion=%(GameAPIVersion.GameVersion) -p:Configuration=$(Configuration)_%(GameAPIVersion.Flat) -p:ILRepackTargetConfigurations=$(Configuration)_%(GameAPIVersion.Flat) - - + + diff --git a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj index 1d4ceda..bc16f1c 100644 --- a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj +++ b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj @@ -96,6 +96,7 @@ + $(GameVersionOverride) false true true From 495a7c568de7cff58e2df9b5da326d2e6130d2ad Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:36:22 +0000 Subject: [PATCH 08/33] Added devcontainer, build foix --- .devcontainer/Dockerfile | 29 +++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 11 +++++++++++ .github/workflows/publish.yml | 5 +++++ 3 files changed, 45 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..ade1755 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,29 @@ +FROM mcr.microsoft.com/vscode/devcontainers/base:ubuntu-20.04 + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + wget \ + ca-certificates \ + \ + # .NET dependencies + libc6 \ + libgcc1 \ + libgssapi-krb5-2 \ + libicu66 \ + libssl1.1 \ + libstdc++6 \ + zlib1g \ + \ + # Mono + mono-devel \ + # Install Microsoft package feed + && wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \ + && dpkg -i packages-microsoft-prod.deb \ + && rm packages-microsoft-prod.deb \ + \ + # Install .NET 6 & 7 + && apt-get update \ + && apt-get install -y --no-install-recommends \ + dotnet-sdk-6.0 \ + dotnet-sdk-7.0 \ + && rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5940eaa --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,11 @@ +{ + "name": ".NET Core & Mono", + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/devcontainers/features/powershell:1": { + "version": "latest" + } + } +} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8ad21ce..6af7193 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,6 +30,11 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Setup + uses: butr/actions-common-setup@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + - name: Build Bannerlord.BLSE run: | mkdir bannerlord; From e7af01862b9a3a6e241564081e02ab2441287396 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:40:36 +0000 Subject: [PATCH 09/33] Fix --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6af7193..4610fee 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -49,12 +49,12 @@ jobs: run: | dotnet tool install -g Bannerlord.ChangelogParser vers="$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" - echo "::set-output name=mod_version::$vers" + echo "mod_version::$vers" >> $GITHUB_OUTPUT desc="$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" desc="${desc//'%'/'%25'}" desc="${desc//$'\n'/'%0A'}" desc="${desc//$'\r'/'%0D'}" - echo "::set-output name=mod_description::$desc" + echo "mod_description::$desc" >> $GITHUB_OUTPUT shell: sh - name: Upload Bannerlord folder From e7737c209e74f4fd667daef36b11bbde05610151 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:44:47 +0000 Subject: [PATCH 10/33] Fix --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4610fee..3199ae4 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -49,12 +49,12 @@ jobs: run: | dotnet tool install -g Bannerlord.ChangelogParser vers="$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" - echo "mod_version::$vers" >> $GITHUB_OUTPUT + echo "mod_version=$vers" >> $GITHUB_OUTPUT desc="$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" desc="${desc//'%'/'%25'}" desc="${desc//$'\n'/'%0A'}" desc="${desc//$'\r'/'%0D'}" - echo "mod_description::$desc" >> $GITHUB_OUTPUT + echo "mod_description=$desc" >> $GITHUB_OUTPUT shell: sh - name: Upload Bannerlord folder From 229bd940e50fbba566e1baafc6c46f0e0e5db41c Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:47:16 +0000 Subject: [PATCH 11/33] Fix --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3199ae4..bdc1e2e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -55,7 +55,7 @@ jobs: desc="${desc//$'\n'/'%0A'}" desc="${desc//$'\r'/'%0D'}" echo "mod_description=$desc" >> $GITHUB_OUTPUT - shell: sh + shell: bash - name: Upload Bannerlord folder uses: actions/upload-artifact@v3 From 6c51fbdc8e74e65481ec7995a95a5e2092588b85 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:50:33 +0000 Subject: [PATCH 12/33] Fix --- .github/workflows/publish.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index bdc1e2e..a831696 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -48,13 +48,16 @@ jobs: id: changelog run: | dotnet tool install -g Bannerlord.ChangelogParser + + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + vers="$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" echo "mod_version=$vers" >> $GITHUB_OUTPUT + desc="$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" - desc="${desc//'%'/'%25'}" - desc="${desc//$'\n'/'%0A'}" - desc="${desc//$'\r'/'%0D'}" - echo "mod_description=$desc" >> $GITHUB_OUTPUT + echo "mod_description<<$EOF" >> $GITHUB_ENV + $desc >> $GITHUB_ENV + echo "$EOF" >> $GITHUB_ENV shell: bash - name: Upload Bannerlord folder From 512f8703fb954e46cf29ce5a70ac1cc2333e8885 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:53:03 +0000 Subject: [PATCH 13/33] Fix --- .github/workflows/publish.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a831696..b557215 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -51,12 +51,10 @@ jobs: EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) - vers="$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" - echo "mod_version=$vers" >> $GITHUB_OUTPUT + echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT - desc="$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" echo "mod_description<<$EOF" >> $GITHUB_ENV - $desc >> $GITHUB_ENV + $(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt") >> $GITHUB_ENV echo "$EOF" >> $GITHUB_ENV shell: bash From 7539c66f603c25991447f197fb51692d35ca1777 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:55:57 +0000 Subject: [PATCH 14/33] Fix --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b557215..9ab15f6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -54,7 +54,7 @@ jobs: echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT echo "mod_description<<$EOF" >> $GITHUB_ENV - $(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt") >> $GITHUB_ENV + bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt" >> $GITHUB_ENV echo "$EOF" >> $GITHUB_ENV shell: bash From 51e22c59d3f0fad2db053c3df37198c455d58a25 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 16:59:16 +0000 Subject: [PATCH 15/33] Fix --- .github/workflows/publish.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9ab15f6..99c8f03 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,7 +25,7 @@ jobs: name: Publish runs-on: ubuntu-latest outputs: - mod_version: ${{ steps.changelog.outputs.mod_version }} + mod_version: ${{ steps.mod_version.outputs.mod_version }} mod_description: ${{ steps.changelog.outputs.mod_description }} steps: - uses: actions/checkout@v3 @@ -45,18 +45,20 @@ jobs: shell: pwsh - name: Install and Run ChangelogParser - id: changelog - run: | - dotnet tool install -g Bannerlord.ChangelogParser - - EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + run: dotnet tool install -g Bannerlord.ChangelogParser + shell: sh - echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT + - id: mod_version + run: echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT + shell: sh + - id: mod_description + run: | + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) echo "mod_description<<$EOF" >> $GITHUB_ENV bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt" >> $GITHUB_ENV echo "$EOF" >> $GITHUB_ENV - shell: bash + shell: sh - name: Upload Bannerlord folder uses: actions/upload-artifact@v3 From fb9bdb20f0610891856db7ed6300d01372b5f840 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 17:02:46 +0000 Subject: [PATCH 16/33] Fix --- .github/workflows/publish.yml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 99c8f03..138a130 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,7 +25,7 @@ jobs: name: Publish runs-on: ubuntu-latest outputs: - mod_version: ${{ steps.mod_version.outputs.mod_version }} + mod_version: ${{ steps.changelog.outputs.mod_version }} mod_description: ${{ steps.changelog.outputs.mod_description }} steps: - uses: actions/checkout@v3 @@ -45,20 +45,21 @@ jobs: shell: pwsh - name: Install and Run ChangelogParser - run: dotnet tool install -g Bannerlord.ChangelogParser - shell: sh - - - id: mod_version - run: echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT - shell: sh - - - id: mod_description + id: changelog run: | + dotnet tool install -g Bannerlord.ChangelogParser + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) - echo "mod_description<<$EOF" >> $GITHUB_ENV - bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt" >> $GITHUB_ENV - echo "$EOF" >> $GITHUB_ENV - shell: sh + + echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT + + delimiter=$(openssl rand -hex 8) + { + echo "mod_description<<$delimiter" + bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt") + echo "$delimiter" + } >> "$GITHUB_OUTPUT" + shell: bash - name: Upload Bannerlord folder uses: actions/upload-artifact@v3 From 0d957efc3338252c5a07209d2fdedf5155f87f6c Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 17:04:40 +0000 Subject: [PATCH 17/33] Fix --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 138a130..d9ab0db 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -56,7 +56,7 @@ jobs: delimiter=$(openssl rand -hex 8) { echo "mod_description<<$delimiter" - bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt") + bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt" echo "$delimiter" } >> "$GITHUB_OUTPUT" shell: bash From dd0ae39cc1e812c2ea3a9087dc0096002deeb668 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 17:09:24 +0000 Subject: [PATCH 18/33] Fix --- .github/workflows/publish.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d9ab0db..390bce2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -53,12 +53,9 @@ jobs: echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT - delimiter=$(openssl rand -hex 8) - { - echo "mod_description<<$delimiter" - bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt" - echo "$delimiter" - } >> "$GITHUB_OUTPUT" + echo "mod_description<<$EOF" >> $GITHUB_ENV + echo "$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_ENV shell: bash - name: Upload Bannerlord folder From 3d245e7e254820a295f1e53ff5a1d5bdc32eaede Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 17:11:39 +0000 Subject: [PATCH 19/33] Fix --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 390bce2..a2b4763 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -53,9 +53,9 @@ jobs: echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT - echo "mod_description<<$EOF" >> $GITHUB_ENV + echo "mod_description<<$EOF" >> $GITHUB_OUTPUT echo "$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT - echo "$EOF" >> $GITHUB_ENV + echo "$EOF" >> $GITHUB_OUTPUT shell: bash - name: Upload Bannerlord folder From 5f7a4fc3a1826d903c26372cd9139fa7bf596380 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 17:38:48 +0000 Subject: [PATCH 20/33] Build fix --- .../Bannerlord.BLSE.Shared.csproj | 4 ++-- .../Bannerlord.LauncherEx.csproj | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj index 7d5a23e..23397be 100644 --- a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj +++ b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj @@ -65,8 +65,8 @@ $(MSBuildThisFileDirectory)..\Bannerlord.LauncherEx\Bannerlord.LauncherEx.csproj "$([System.IO.Path]::GetFullPath('$(LauncherExProject)'))" - - + + diff --git a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj index bc16f1c..6e1ccf3 100644 --- a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj +++ b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj @@ -9,6 +9,13 @@ 1.23.3 System.Diagnostics.CodeAnalysis.UnscopedRefAttribute true + false + $(Configuration) + $(PkgBUTR_ILRepack)\tools\net461\ILRepack.exe + false + true + true + false @@ -97,17 +108,7 @@ $(GameVersionOverride) - false - true - true - false - $(PkgBUTR_ILRepack)\tools\net461\ILRepack.exe - - - - - From 3fffc6affbb1bc51bbc1a0f9dfa4532b821ebf71 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 19 Mar 2023 17:54:21 +0000 Subject: [PATCH 21/33] Fix --- src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj | 4 ++-- src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj index 23397be..ceb0da5 100644 --- a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj +++ b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj @@ -65,8 +65,8 @@ $(MSBuildThisFileDirectory)..\Bannerlord.LauncherEx\Bannerlord.LauncherEx.csproj "$([System.IO.Path]::GetFullPath('$(LauncherExProject)'))" - - + + diff --git a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj index 6e1ccf3..7ba4a5c 100644 --- a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj +++ b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj @@ -106,9 +106,6 @@ - - $(GameVersionOverride) - From 115e2a4d2cd263a9eed99aca19d0d21c7d6e3f30 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Mon, 20 Mar 2023 14:06:05 +0200 Subject: [PATCH 22/33] Fixed Singleplayer not being shown by default --- build/common.props | 2 +- changelog.txt | 4 ++++ src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj | 2 +- src/Bannerlord.LauncherEx/Mixins/LauncherVMMixin.cs | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build/common.props b/build/common.props index 858597c..14261db 100644 --- a/build/common.props +++ b/build/common.props @@ -10,7 +10,7 @@ - 1.0.4 + 1.0.5 2.10.1 3.0.0.135 5.0.198 diff --git a/changelog.txt b/changelog.txt index 59ee879..d0e16be 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 1.0.5 +Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1 +* Fixed Singleplayer not being shown by default +--------------------------------------------------------------------------------------------------- Version: 1.0.4 Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1 * Show a message if the save game failed to load via the Continue feature diff --git a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj index 7ba4a5c..8fce17f 100644 --- a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj +++ b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj @@ -6,7 +6,7 @@ enable x64 full - 1.23.3 + 1.23.4 System.Diagnostics.CodeAnalysis.UnscopedRefAttribute true false diff --git a/src/Bannerlord.LauncherEx/Mixins/LauncherVMMixin.cs b/src/Bannerlord.LauncherEx/Mixins/LauncherVMMixin.cs index ba01e58..2f35777 100644 --- a/src/Bannerlord.LauncherEx/Mixins/LauncherVMMixin.cs +++ b/src/Bannerlord.LauncherEx/Mixins/LauncherVMMixin.cs @@ -311,9 +311,9 @@ public LauncherVMMixin(LauncherVM launcherVM) : base(launcherVM) ContentTabControlMarginRight = LauncherSettings.HideRandomImage ? 5 : 114; BackgroundHeight = LauncherSettings.BigMode ? 700 : 581; + IsDigitalCompanion2 = (bool?) launcherVM.GetPropertyValue("IsDigitalCompanion") ?? false; IsMultiplayer2 = launcherVM.IsMultiplayer; IsSingleplayer2 = launcherVM.IsSingleplayer; - IsDigitalCompanion2 = (bool?) launcherVM.GetPropertyValue("IsDigitalCompanion") ?? false; Refresh?.Invoke(launcherVM); } From 5f1105b1feaed725d6abca9020cfe6c4974bf71a Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 10:09:42 +0200 Subject: [PATCH 23/33] Added legacyCorruptedStateExceptionsPolicy for .NET Core Handle exceptions for everything until the game is started Better Harmony diagnostics --- changelog.txt | 1 + src/Bannerlord.BLSE.Shared/LauncherEx.cs | 21 -- .../ModuleInitializer.cs | 185 ++++++++++++++---- src/Bannerlord.BLSE.Shared/Program.cs | 2 + src/Bannerlord.BLSE.Shared/Standalone.cs | 1 - .../Utils/LauncherExceptionHandler.cs | 52 +++++ .../Utils/MessageBoxDialog.cs | 2 +- .../Utils/NtfsUnblocker.cs | 11 +- src/Bannerlord.BLSE.Shared/Utils/Unblocker.cs | 2 +- .../NETCoreLoader.cs | 3 + src/Bannerlord.BLSE/Bannerlord.BLSE.csproj | 1 + .../Interceptor/InterceptorFeature.cs | 2 +- 12 files changed, 209 insertions(+), 74 deletions(-) create mode 100644 src/Bannerlord.BLSE.Shared/Utils/LauncherExceptionHandler.cs diff --git a/changelog.txt b/changelog.txt index d0e16be..7d2c35a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Version: 1.0.5 Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1 * Fixed Singleplayer not being shown by default +* Better error messages --------------------------------------------------------------------------------------------------- Version: 1.0.4 Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1 diff --git a/src/Bannerlord.BLSE.Shared/LauncherEx.cs b/src/Bannerlord.BLSE.Shared/LauncherEx.cs index 5ce32fb..d2a8a97 100644 --- a/src/Bannerlord.BLSE.Shared/LauncherEx.cs +++ b/src/Bannerlord.BLSE.Shared/LauncherEx.cs @@ -25,8 +25,6 @@ public static class LauncherEx public static void Launch(string[] args) { - AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; - if (Environment.OSVersion.Version.Major >= 6) SetProcessDPIAware(); @@ -49,23 +47,4 @@ public static void Launch(string[] args) TaleWorlds.MountAndBlade.Launcher.Library.Program.Main(args); } } - - private static void CurrentDomainOnUnhandledException(object? _, UnhandledExceptionEventArgs e) - { - static string GetRecursiveException(Exception ex) => new StringBuilder() - .AppendLine() - .AppendLine($"Type: {ex.GetType().FullName}") - .AppendLine(!string.IsNullOrWhiteSpace(ex.Message) ? $"Message: {ex.Message}" : string.Empty) - .AppendLine(!string.IsNullOrWhiteSpace(ex.Source) ? $"Source: {ex.Source}" : string.Empty) - .AppendLine(!string.IsNullOrWhiteSpace(ex.StackTrace) ? $@"CallStack:{Environment.NewLine}{string.Join(Environment.NewLine, ex.StackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))}" : string.Empty) - .AppendLine(ex.InnerException != null ? $@"{Environment.NewLine}{Environment.NewLine}Inner {GetRecursiveException(ex.InnerException)}" : string.Empty) - .ToString(); - - using var fs = File.Open("BLSE_lasterror.log", FileMode.OpenOrCreate, FileAccess.Write); - fs.SetLength(0); - using var writer = new StreamWriter(fs); - writer.Write($@"BLSE Exception: -Version: {typeof(Program).Assembly.GetName().Version} -{(e.ExceptionObject is Exception ex ? GetRecursiveException(ex) : e.ToString())}"); - } } \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs b/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs index 6900e06..478c708 100644 --- a/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs +++ b/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs @@ -1,5 +1,4 @@ -using Bannerlord.BLSE.Shared; -using Bannerlord.BLSE.Shared.Utils; +using Bannerlord.BLSE.Shared.Utils; using Bannerlord.BUTR.Shared.Helpers; using Bannerlord.ModuleManager; @@ -82,65 +81,160 @@ internal static void Action() return null; } - private static string? ResolveHarmonyAssembliesFile(AssemblyName assemblyName) + private enum HarmonyDiscoveryResult { + Discovered, + ModuleMissing, + ModuleSubModuleMissing, + ModuleSubModuleCorrupted, + ModuleVersionWrong, + ModuleBinariesMissing, + ModuleHarmonyMissing, + UnknownIssue, + } + + private static HarmonyDiscoveryResult TryResolveHarmonyAssembliesFile(AssemblyName assemblyName, out string? path) + { + path = null; var assemblyNameFull = $"{assemblyName.Name}.dll"; var configName = new DirectoryInfo(Directory.GetCurrentDirectory()).Name; + var harmonyModuleFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../", "../", ModuleInfoHelper.ModulesFolder, "Bannerlord.Harmony")); - // TODO: Proper Steam discovery - var harmonySteamModuleFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../", "../", "../", "../", "workshop", "content", "261550", "2859188632")); - if (!Directory.Exists(harmonyModuleFolder) && !Directory.Exists(harmonySteamModuleFolder)) - { - MessageBoxDialog.Show("The Harmony module is missing!\nCan't launch with 'Bannerlord.Harmony' module missing!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error, 0, 0); - Environment.Exit(1); - return null; - } + if (!Directory.Exists(harmonyModuleFolder)) + return HarmonyDiscoveryResult.ModuleMissing; var harmonySubModule = Path.Combine(harmonyModuleFolder, ModuleInfoHelper.SubModuleFile); - var harmonySteamSubModule = Path.Combine(harmonySteamModuleFolder, ModuleInfoHelper.SubModuleFile); - if (!File.Exists(harmonySubModule) && !File.Exists(harmonySteamSubModule)) - { - MessageBoxDialog.Show($"The Harmony module is corrupted!\nCan't find '{ModuleInfoHelper.SubModuleFile}' in 'Bannerlord.Harmony'!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error, 0, 0); - Environment.Exit(1); - return null; - } + if (!File.Exists(harmonySubModule)) + return HarmonyDiscoveryResult.ModuleSubModuleMissing; var doc = new XmlDocument(); - doc.Load(File.Exists(harmonySubModule) ? harmonySubModule : File.Exists(harmonySteamSubModule) ? harmonySteamSubModule : string.Empty); + doc.Load(File.Exists(harmonySubModule) ? harmonySubModule : string.Empty); var harmonyModuleInfo = ModuleInfoExtended.FromXml(doc); if (harmonyModuleInfo is null) - { - MessageBoxDialog.Show($"The Harmony module is corrupted!\nFailed to read '{ModuleInfoHelper.SubModuleFile}'!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error, 0, 0); - Environment.Exit(1); - return null; - } + return HarmonyDiscoveryResult.ModuleSubModuleCorrupted; + if (new ApplicationVersionComparer().Compare(harmonyModuleInfo.Version, new ApplicationVersion(ApplicationVersionType.Release, 2, 10, 0, 0)) < 0) - { - MessageBoxDialog.Show("Wrong Harmony module version! At least v2.10.1.x is required!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error, 0, 0); - Environment.Exit(1); - return null; - } + return HarmonyDiscoveryResult.ModuleVersionWrong; var harmonyBinFolder = Path.Combine(harmonyModuleFolder, "bin", configName); - var harmonyBinSteamFolder = Path.Combine(harmonySteamModuleFolder, "bin", configName); - if (!Directory.Exists(harmonyBinFolder) && !Directory.Exists(harmonyBinSteamFolder)) - { - MessageBoxDialog.Show($"The Harmony module is corrupted!\nCan't find '{Path.Combine("bin", configName)}' in 'Bannerlord.Harmony'!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error, 0, 0); - Environment.Exit(1); - return null; - } + if (!Directory.Exists(harmonyBinFolder)) + return HarmonyDiscoveryResult.ModuleBinariesMissing; var assemblyFile = Path.Combine(harmonyBinFolder, assemblyNameFull); + if (!File.Exists(assemblyFile)) + return HarmonyDiscoveryResult.ModuleHarmonyMissing; + + path = File.Exists(assemblyFile) ? assemblyFile : string.Empty; + return HarmonyDiscoveryResult.Discovered; + } + private static HarmonyDiscoveryResult TryResolveHarmonyAssembliesFileFromSteam(AssemblyName assemblyName, out string? path) + { + path = null; + var assemblyNameFull = $"{assemblyName.Name}.dll"; + + var configName = new DirectoryInfo(Directory.GetCurrentDirectory()).Name; + + var harmonySteamModuleFolder = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "../", "../", "../", "../", "workshop", "content", "261550", "2859188632")); + if (!Directory.Exists(harmonySteamModuleFolder)) + return HarmonyDiscoveryResult.ModuleMissing; + + var harmonySteamSubModule = Path.Combine(harmonySteamModuleFolder, ModuleInfoHelper.SubModuleFile); + if (!File.Exists(harmonySteamSubModule)) + return HarmonyDiscoveryResult.ModuleSubModuleMissing; + + var doc = new XmlDocument(); + doc.Load(File.Exists(harmonySteamSubModule) ? harmonySteamSubModule : string.Empty); + var harmonyModuleInfo = ModuleInfoExtended.FromXml(doc); + if (harmonyModuleInfo is null) + return HarmonyDiscoveryResult.ModuleSubModuleCorrupted; + + if (new ApplicationVersionComparer().Compare(harmonyModuleInfo.Version, new ApplicationVersion(ApplicationVersionType.Release, 2, 10, 0, 0)) < 0) + return HarmonyDiscoveryResult.ModuleVersionWrong; + + var harmonyBinSteamFolder = Path.Combine(harmonySteamModuleFolder, "bin", configName); + if (!Directory.Exists(harmonyBinSteamFolder)) + return HarmonyDiscoveryResult.ModuleBinariesMissing; + var assemblySteamFile = Path.Combine(harmonyBinSteamFolder, assemblyNameFull); - if (!File.Exists(assemblyFile) && !File.Exists(assemblySteamFile)) + if (!File.Exists(assemblySteamFile)) + return HarmonyDiscoveryResult.ModuleHarmonyMissing; + + path = File.Exists(assemblySteamFile) ? assemblySteamFile : string.Empty; + return HarmonyDiscoveryResult.Discovered; + } + private static string? ResolveHarmonyAssembliesFile(AssemblyName assemblyName) + { + var assemblyNameFull = $"{assemblyName.Name}.dll"; + + var configName = new DirectoryInfo(Directory.GetCurrentDirectory()).Name; + var checkSteam = configName == "Win64_Shipping_Client"; + + var genericDiscoveryResult = TryResolveHarmonyAssembliesFile(assemblyName, out var genericHarmonyPath); + if (genericDiscoveryResult == HarmonyDiscoveryResult.Discovered) + return genericHarmonyPath; + + if (checkSteam && TryResolveHarmonyAssembliesFileFromSteam(assemblyName, out var steamHarmonyPath) == HarmonyDiscoveryResult.Discovered) + return steamHarmonyPath; + + switch (genericDiscoveryResult) { - MessageBoxDialog.Show($"The Harmony module is corrupted!\nCan't find '{assemblyNameFull}' in 'Bannerlord.Harmony'!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error, 0, 0); - Environment.Exit(1); - return null; - } + case HarmonyDiscoveryResult.ModuleMissing: + MessageBoxDialog.Show(@"The Harmony module is missing! +Can't launch with 'Bannerlord.Harmony' module missing! - return File.Exists(assemblyFile) ? assemblyFile : File.Exists(assemblySteamFile) ? assemblySteamFile : string.Empty; +If the module was installed manually, make sure that the module in installed in 'Modules/Bannerlord.Harmony'! +If Vortex is used, try to reinstall manually! +If Steam is used, download the Harmony mod from NexusMods!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error); + Environment.Exit(1); + return null; + case HarmonyDiscoveryResult.ModuleSubModuleMissing: + MessageBoxDialog.Show(@$"The Harmony module is corrupted! +Can't find '{ModuleInfoHelper.SubModuleFile}' in 'Bannerlord.Harmony'! + +If the module was installed manually, try to do a clean reinstall! +If Vortex is used, try to reinstall manually! +If Steam is used, download the Harmony mod from NexusMods!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error); + Environment.Exit(1); + return null; + case HarmonyDiscoveryResult.ModuleSubModuleCorrupted: + MessageBoxDialog.Show(@$"The Harmony module is corrupted! +Failed to read '{ModuleInfoHelper.SubModuleFile}'! + +If the module was installed manually, try to do a clean reinstall! +If Vortex is used, try to reinstall manually! +If Steam is used, download the Harmony mod from NexusMods!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error); + Environment.Exit(1); + return null; + case HarmonyDiscoveryResult.ModuleVersionWrong: + MessageBoxDialog.Show(@"The Harmony module is wrong! +At least v2.10.1.x is required! + +If the module was installed manually, find and install the latest version! +If Vortex is used, try to reinstall manually the latest version! +If Steam is used, download the latest Harmony mod from NexusMods!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error); + Environment.Exit(1); + return null; + case HarmonyDiscoveryResult.ModuleBinariesMissing: + MessageBoxDialog.Show(@$"The Harmony module is corrupted! +Can't find '{Path.Combine("bin", configName)}' in 'Bannerlord.Harmony'! + +If the module was installed manually, try to do a clean reinstall! +If Vortex is used, try to reinstall manually! +If Steam is used, download the Harmony mod from NexusMods!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error); + Environment.Exit(1); + return null; + case HarmonyDiscoveryResult.ModuleHarmonyMissing: + MessageBoxDialog.Show(@$"The Harmony module is corrupted! +Can't find '{assemblyNameFull}' in 'Bannerlord.Harmony'! + +If the module was installed manually, try to do a clean reinstall! +If Vortex is used, try to reinstall manually! +If Steam is used, download the Harmony mod from NexusMods!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error); + Environment.Exit(1); + return null; + } + return null; } private static Assembly? ResolveHarmonyAssembly(AssemblyName assemblyName) @@ -158,7 +252,12 @@ internal static void Action() var harmonyX = AssemblyDefinition.ReadAssembly(assemblyFile); if (harmonyX.Name.Version < new Version(2, 10, 1, 0)) { - MessageBoxDialog.Show("The Harmony module is corrupted!\nWrong 0Harmony.dll version! At least v2.10.1.x is required!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error, 0, 0); + MessageBoxDialog.Show(@"The Harmony module is corrupted! +Wrong 0Harmony.dll version! At least v2.10.1.x is required! + +If the module was installed manually, try to do a clean reinstall! +If Vortex is used, try to reinstall manually! +If Steam is used, download the Harmony mod from NexusMods!", "Error from BLSE!", MessageBoxButtons.Ok, MessageBoxIcon.Error); Environment.Exit(1); return null; } diff --git a/src/Bannerlord.BLSE.Shared/Program.cs b/src/Bannerlord.BLSE.Shared/Program.cs index 3f6a328..059021b 100644 --- a/src/Bannerlord.BLSE.Shared/Program.cs +++ b/src/Bannerlord.BLSE.Shared/Program.cs @@ -15,6 +15,8 @@ public static void Main(string[] args) { //PInvoke.ShowWindow(PInvoke.GetConsoleWindow(), SHOW_WINDOW_CMD.SW_HIDE); + LauncherExceptionHandler.Watch(); + switch (args[0]) { case "launcher": diff --git a/src/Bannerlord.BLSE.Shared/Standalone.cs b/src/Bannerlord.BLSE.Shared/Standalone.cs index 21df2b3..b0d429c 100644 --- a/src/Bannerlord.BLSE.Shared/Standalone.cs +++ b/src/Bannerlord.BLSE.Shared/Standalone.cs @@ -94,7 +94,6 @@ private static void TryLoadLoadOrderFromSaveFile(ref string[] args) } } - [STAThread] public static void Launch(string[] args) { if (Environment.OSVersion.Version.Major >= 6) diff --git a/src/Bannerlord.BLSE.Shared/Utils/LauncherExceptionHandler.cs b/src/Bannerlord.BLSE.Shared/Utils/LauncherExceptionHandler.cs new file mode 100644 index 0000000..4e17a20 --- /dev/null +++ b/src/Bannerlord.BLSE.Shared/Utils/LauncherExceptionHandler.cs @@ -0,0 +1,52 @@ +using HarmonyLib; +using HarmonyLib.BUTR.Extensions; + +using System; +using System.IO; +using System.Reflection; +using System.Text; + +namespace Bannerlord.BLSE.Shared.Utils; + +internal static class LauncherExceptionHandler +{ + private static readonly Harmony _harmony = new("Bannerlord.BLSE.Shared.Patches.LauncherExceptionHandler"); + + + public static void Watch() + { + Assembly.Load(new AssemblyName("TaleWorlds.Starter.Library")); + + _harmony.TryPatch( + AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"), + prefix: AccessTools2.Method(typeof(Unblocker), nameof(MainPrefix))); + + AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; + } + + private static void MainPrefix() + { + AppDomain.CurrentDomain.UnhandledException -= CurrentDomainOnUnhandledException; + + _harmony.Unpatch(AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"), AccessTools2.Method(typeof(Unblocker), nameof(MainPrefix))); + } + + private static void CurrentDomainOnUnhandledException(object? _, UnhandledExceptionEventArgs e) + { + static string GetRecursiveException(Exception ex) => new StringBuilder() + .AppendLine() + .AppendLine($"Type: {ex.GetType().FullName}") + .AppendLine(!string.IsNullOrWhiteSpace(ex.Message) ? $"Message: {ex.Message}" : string.Empty) + .AppendLine(!string.IsNullOrWhiteSpace(ex.Source) ? $"Source: {ex.Source}" : string.Empty) + .AppendLine(!string.IsNullOrWhiteSpace(ex.StackTrace) ? $@"CallStack:{Environment.NewLine}{string.Join(Environment.NewLine, ex.StackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))}" : string.Empty) + .AppendLine(ex.InnerException != null ? $@"{Environment.NewLine}{Environment.NewLine}Inner {GetRecursiveException(ex.InnerException)}" : string.Empty) + .ToString(); + + using var fs = File.Open("BLSE_lasterror.log", FileMode.OpenOrCreate, FileAccess.Write); + fs.SetLength(0); + using var writer = new StreamWriter(fs); + writer.Write($@"BLSE Exception: +Version: {typeof(Program).Assembly.GetName().Version} +{(e.ExceptionObject is Exception ex ? GetRecursiveException(ex) : e.ToString())}"); + } +} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Shared/Utils/MessageBoxDialog.cs b/src/Bannerlord.BLSE.Shared/Utils/MessageBoxDialog.cs index 6cbe9d9..7380347 100644 --- a/src/Bannerlord.BLSE.Shared/Utils/MessageBoxDialog.cs +++ b/src/Bannerlord.BLSE.Shared/Utils/MessageBoxDialog.cs @@ -4,7 +4,7 @@ namespace Bannerlord.BLSE.Shared.Utils; -public static class MessageBoxDialog +internal static class MessageBoxDialog { public static MessageBoxResult Show(string text) => (MessageBoxResult) PInvoke.MessageBox(HWND.Null, text, "\0", (MESSAGEBOX_STYLE) MessageBoxButtons.Ok); diff --git a/src/Bannerlord.BLSE.Shared/Utils/NtfsUnblocker.cs b/src/Bannerlord.BLSE.Shared/Utils/NtfsUnblocker.cs index 70ebf21..c68a7bf 100644 --- a/src/Bannerlord.BLSE.Shared/Utils/NtfsUnblocker.cs +++ b/src/Bannerlord.BLSE.Shared/Utils/NtfsUnblocker.cs @@ -3,12 +3,11 @@ using Windows.Win32; -namespace Bannerlord.BLSE.Shared.Utils +namespace Bannerlord.BLSE.Shared.Utils; + +internal static class NtfsUnblocker { - internal static class NtfsUnblocker - { - public static void UnblockDirectory(string path, string wildcard = "*") => Parallel.ForEach(Directory.EnumerateFiles(path, wildcard, SearchOption.AllDirectories), UnblockFile); + public static void UnblockDirectory(string path, string wildcard = "*") => Parallel.ForEach(Directory.EnumerateFiles(path, wildcard, SearchOption.AllDirectories), UnblockFile); - public static void UnblockFile(string fileName) => PInvoke.DeleteFile($"{fileName}:Zone.Identifier"); - } + public static void UnblockFile(string fileName) => PInvoke.DeleteFile($"{fileName}:Zone.Identifier"); } \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Shared/Utils/Unblocker.cs b/src/Bannerlord.BLSE.Shared/Utils/Unblocker.cs index cc06978..040399b 100644 --- a/src/Bannerlord.BLSE.Shared/Utils/Unblocker.cs +++ b/src/Bannerlord.BLSE.Shared/Utils/Unblocker.cs @@ -10,7 +10,7 @@ namespace Bannerlord.BLSE.Shared.Utils; -public static class Unblocker +internal static class Unblocker { private static readonly Harmony _harmony = new("Bannerlord.BLSE.Shared.Patches.Unblocker"); private static Thread? _currentUnblockingThread; diff --git a/src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs b/src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs index 1697ada..0b07d03 100644 --- a/src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs +++ b/src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs @@ -33,6 +33,9 @@ private static IntPtr NativeUTF8(string str) public static void Launch(string[] args) { + // Catch AccessViolation. .NET Core 3.1 still allows that + Environment.SetEnvironmentVariable("COMPlus_legacyCorruptedStateExceptionsPolicy", "1"); + // Disable aggressive inlining of JIT by disabling JIT Optimizations // TODO: This is kinda extreme. What could be done? Environment.SetEnvironmentVariable("COMPlus_JITMinOpts", "1"); diff --git a/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj b/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj index 0101a53..7fac1e9 100644 --- a/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj +++ b/src/Bannerlord.BLSE/Bannerlord.BLSE.csproj @@ -30,6 +30,7 @@ + diff --git a/src/Bannerlord.BLSE/Features/Interceptor/InterceptorFeature.cs b/src/Bannerlord.BLSE/Features/Interceptor/InterceptorFeature.cs index 95daa37..a98c660 100644 --- a/src/Bannerlord.BLSE/Features/Interceptor/InterceptorFeature.cs +++ b/src/Bannerlord.BLSE/Features/Interceptor/InterceptorFeature.cs @@ -54,7 +54,7 @@ private static IEnumerable GetLoadedModulePaths() { var configName = Common.ConfigName; - foreach (var moduleInfo in ModuleInfoHelper.GetLoadedModules().OfType()) + foreach (var moduleInfo in ModuleInfoHelper.GetLoadedModules()) { foreach (var subModule in moduleInfo.SubModules) { From 7015ab3382b25d512d6126cdf886ca684d12b448 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:34:04 +0200 Subject: [PATCH 24/33] Added a NativeAOT based launcher --- .../Bannerlord.BLSE.Core.Launcher.csproj | 67 +++++++ .../Bannerlord.BLSE.Core.LauncherEx.csproj | 66 +++++++ .../Bannerlord.BLSE.Core.Standalone.csproj | 54 ++++++ .../NETCoreLoader.cs | 92 +++++++++ .../NETFrameworkLoader.cs | 174 ++++++++++++++++++ .../Program.cs | 26 +++ .../Bannerlord.BLSE.Shared.csproj | 2 +- src/Bannerlord.BLSE.Shared/Program.cs | 6 + src/Bannerlord.BLSE.sln | 23 ++- 9 files changed, 508 insertions(+), 2 deletions(-) create mode 100644 src/Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj create mode 100644 src/Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj create mode 100644 src/Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj create mode 100644 src/Bannerlord.BLSE.Core.Standalone/NETCoreLoader.cs create mode 100644 src/Bannerlord.BLSE.Core.Standalone/NETFrameworkLoader.cs create mode 100644 src/Bannerlord.BLSE.Core.Standalone/Program.cs diff --git a/src/Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj b/src/Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj new file mode 100644 index 0000000..5b5eef9 --- /dev/null +++ b/src/Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj @@ -0,0 +1,67 @@ + + + + winexe + net7.0 + enable + enable + ../../resources/BLSE_SMALL.ico + true + $(DefineConstants);LAUNCHER; + Bannerlord.BLSE.Launcher + + true + true + full + none + false + + + + false + false + false + false + false + true + true + true + + true + false + Size + false + true + true + true + false + true + true + + + + + + NETCoreLoader.cs + + + NETFrameworkLoader.cs + + + Program.cs + + + + + + + + + + + + + + + + diff --git a/src/Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj b/src/Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj new file mode 100644 index 0000000..868d015 --- /dev/null +++ b/src/Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj @@ -0,0 +1,66 @@ + + + + winexe + net7.0 + enable + enable + ../../resources/BLSE_SMALL.ico + true + $(DefineConstants);LAUNCHEREX; + Bannerlord.BLSE.LauncherEx + + true + true + full + none + false + + + + false + false + false + false + false + true + true + true + + true + false + Size + false + true + true + true + false + true + true + + + + + NETCoreLoader.cs + + + NETFrameworkLoader.cs + + + Program.cs + + + + + + + + + + + + + + + + diff --git a/src/Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj b/src/Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj new file mode 100644 index 0000000..7459fc3 --- /dev/null +++ b/src/Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj @@ -0,0 +1,54 @@ + + + + winexe + net7.0 + enable + enable + ../../resources/BLSE_SMALL.ico + true + $(DefineConstants);STANDALONE; + Bannerlord.BLSE.Standalone + + true + true + full + none + false + + + + false + false + false + false + false + true + true + true + + true + false + Size + false + true + true + true + false + true + true + + + + + + + + + + + + + + + diff --git a/src/Bannerlord.BLSE.Core.Standalone/NETCoreLoader.cs b/src/Bannerlord.BLSE.Core.Standalone/NETCoreLoader.cs new file mode 100644 index 0000000..d9fd027 --- /dev/null +++ b/src/Bannerlord.BLSE.Core.Standalone/NETCoreLoader.cs @@ -0,0 +1,92 @@ +using System.Runtime.InteropServices; +using System.Text; + +namespace Bannerlord.BLSE.Core.Launcher; + +[UnmanagedFunctionPointer(CallingConvention.StdCall)] +file delegate void EntryDelegate(int argc, IntPtr[] argv); + +public static partial class NETCoreLoader +{ + private const string CoreCLRPath = "Microsoft.NETCore.App/coreclr.dll"; + + [LibraryImport(CoreCLRPath)] + private static partial int coreclr_initialize(IntPtr exePath, IntPtr appDomainFriendlyName, int propertyCount, IntPtr[] propertyKeys, IntPtr[] propertyValues, out IntPtr hostHandle, out IntPtr domainId); + + [LibraryImport(CoreCLRPath)] + private static partial int coreclr_create_delegate(IntPtr hostHandle, uint domainId, IntPtr entryPointAssemblyName, IntPtr entryPointTypeName, IntPtr entryPointMethodName, out IntPtr @delegate); + + private static IntPtr NativeUTF8(string str) + { + var length = Encoding.UTF8.GetByteCount(str); + var buffer = new byte[length + 1]; + Encoding.UTF8.GetBytes(str, 0, str.Length, buffer, 0); + buffer[buffer.Length - 1] = 0; + + var nativeBuffer = Marshal.AllocHGlobal(buffer.Length); + Marshal.Copy(buffer, 0, nativeBuffer, buffer.Length); + return nativeBuffer; + } + + public static void Launch(string[] args) + { + // Catch AccessViolation. .NET Core 3.1 still allows that + Environment.SetEnvironmentVariable("COMPlus_legacyCorruptedStateExceptionsPolicy", "1"); + + // Disable aggressive inlining of JIT by disabling JIT Optimizations + // TODO: This is kinda extreme. What could be done? + Environment.SetEnvironmentVariable("COMPlus_JITMinOpts", "1"); + + var path = AppDomain.CurrentDomain.BaseDirectory; + var rootFiles = Directory.GetFiles(Path.Combine(path), "*.dll", SearchOption.TopDirectoryOnly) + .Where(x => Path.GetFileName(x) != "Mono.Cecil.dll") // On .NET Core, the game distributes an old version of Mono.Cecil.dll. Ignore it. + .Select(x => $"{x};"); + var netcoreFiles = Directory.GetFiles(Path.Combine(path, "Microsoft.NETCore.App"), "*.dll", SearchOption.TopDirectoryOnly).Select(x => $"{x};"); + var aspCoreFiles = Directory.GetFiles(Path.Combine(path, "Microsoft.AspNetCore.App"), "*.dll", SearchOption.TopDirectoryOnly).Select(x => $"{x};"); + var winDeskFiles = Directory.GetFiles(Path.Combine(path, "Microsoft.WindowsDesktop.App"), "*.dll", SearchOption.TopDirectoryOnly).Select(x => $"{x};"); + // Do not set Modules .dll as trusted and to be loaded + var modulesFiles = Directory.GetFiles(Path.Combine(path, "..", "..", "Modules"), "*.dll", SearchOption.AllDirectories).Select(x => $"{x};"); + // The instantly loaded assembly files + var files = string.Join("", rootFiles.Concat(netcoreFiles).Concat(aspCoreFiles).Concat(winDeskFiles)/*.Concat(files5)*/); + + var propKeys = new IntPtr[] + { + NativeUTF8("TRUSTED_PLATFORM_ASSEMBLIES") + }; + var propValues = new IntPtr[] + { + NativeUTF8(files) + }; + + var initResult = coreclr_initialize( + NativeUTF8(path), + NativeUTF8("BLSE"), + 1, + propKeys, + propValues, + out var pCLRRuntimeHost, + out var domainId); + if (initResult < 0) + { + Console.WriteLine("Failed to initialize Bannerlord's .NET Core CLR!"); + return; + } + + var createDelegateResult = coreclr_create_delegate( + pCLRRuntimeHost, + (uint) domainId, + NativeUTF8("Bannerlord.BLSE.Shared"), + NativeUTF8("Bannerlord.BLSE.Shared.Program"), + NativeUTF8("NativeEntry"), + out var pMethod); + if (createDelegateResult < 0) + { + Console.WriteLine("Failed to get BLSE's entrypoint!"); + return; + } + + var args2 = args.Select(NativeUTF8).ToArray(); + var @delegate = Marshal.GetDelegateForFunctionPointer(pMethod); + @delegate(args.Length, args2); + } +} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Core.Standalone/NETFrameworkLoader.cs b/src/Bannerlord.BLSE.Core.Standalone/NETFrameworkLoader.cs new file mode 100644 index 0000000..faf19d8 --- /dev/null +++ b/src/Bannerlord.BLSE.Core.Standalone/NETFrameworkLoader.cs @@ -0,0 +1,174 @@ +using System.Runtime.InteropServices; + +namespace Bannerlord.BLSE; + +file unsafe struct ICLRRuntimeHost +{ + private ICLRRuntimeHostVtbl* vtbl; + + public static nint Release(ICLRRuntimeHost* host) + { + var release = (delegate*) host->vtbl->Release; + return release(host); + } + + public static nint Start(ICLRRuntimeHost* host) + { + var start = (delegate*) host->vtbl->Start; + return start(host); + } + + public static int ExecuteInDefaultAppDomain(ICLRRuntimeHost* host, string dllPath, string typeName, string methodName, string argument) + { + fixed (char* pDllPath = dllPath) + fixed (char* pTypeName = typeName) + fixed (char* pMethodName = methodName) + fixed (char* pArgument = argument) + { + var executeInDefaultAppDomain = (delegate*) host->vtbl->ExecuteInDefaultAppDomain; + + int returnVal; + var result = executeInDefaultAppDomain(host, pDllPath, pTypeName, pMethodName, pArgument, &returnVal); + return result == 0 ? returnVal : 1; + } + } +} +file unsafe struct ICLRRuntimeHostVtbl +{ + public void* QueryInterface; + public void* AddRef; + public void* Release; + public void* Start; + public void* Stop; + public void* SetHostControl; + public void* GetCLRControl; + public void* UnloadAppDomain; + public void* ExecuteInAppDomain; + public void* GetCurrentAppDomainId; + public void* ExecuteApplication; + public void* ExecuteInDefaultAppDomain; +} + +file unsafe struct ICLRRuntimeInfo +{ + private static Guid CLSID_CLRRuntimeHost = new("90F1A06E-7712-4762-86B5-7A5EBA6BDB02"); + private static Guid IID_ICLRRuntimeHost = new("90F1A06C-7712-4762-86B5-7A5EBA6BDB02"); + + private ICLRRuntimeInfoVtbl* vtbl; + + public static nint Release(ICLRRuntimeInfo* host) + { + var release = (delegate*) host->vtbl->Release; + return release(host); + } + + private static T* GetInterface(ICLRRuntimeInfo* host, Guid* rclsid, Guid* riid) where T : unmanaged + { + var getInterface = (delegate*) host->vtbl->GetInterface; + + T* ptr; + var result = getInterface(host, rclsid, riid, &ptr); + return ptr; + } + + public static ICLRRuntimeHost* GetRuntimeHost(ICLRRuntimeInfo* host) + { + fixed (Guid* clsid = &CLSID_CLRRuntimeHost) + fixed (Guid* iid = &IID_ICLRRuntimeHost) + { + return GetInterface(host, clsid, iid); + } + } +} +file unsafe struct ICLRRuntimeInfoVtbl +{ + public void* QueryInterface; + public void* AddRef; + public void* Release; + public void* GetVersionString; + public void* GetRuntimeDirectory; + public void* IsLoaded; + public void* LoadErrorString; + public void* LoadLibrary; + public void* GetProcAddress; + public void* GetInterface; + public void* IsLoadable; + public void* SetDefaultStartupFlags; + public void* GetDefaultStartupFlags; + public void* BindAsLegacyV2Runtime; + public void* IsStarted; +} + +file unsafe struct ICLRMetaHost +{ + private static Guid CLSID_CLRMetaHost = new("9280188D-0E8E-4867-B30C-7FA83884E8DE"); + private static Guid IID_ICLRMetaHost = new("D332DB9E-B9B3-4125-8207-A14884F53216"); + + private static Guid IID_ICLRRuntimeInfo = new("BD39D1D2-BA2F-486A-89B0-B4B0CB466891"); + + [DllImport("mscoree")] + private static extern int CLRCreateInstance(Guid* clsId, Guid* rIId, ICLRMetaHost** instance); + + private ICLRMetaHostVtbl *vtbl; + + public static ICLRMetaHost* Create() + { + fixed (Guid* clsid = &CLSID_CLRMetaHost) + fixed (Guid* iid = &IID_ICLRMetaHost) + { + ICLRMetaHost* host; + var result = CLRCreateInstance(clsid, iid, &host); + return host; + } + } + + public static nint Release(ICLRMetaHost* host) + { + var release = (delegate*) host->vtbl->Release; + return release(host); + } + + public static ICLRRuntimeInfo* GetRuntime(ICLRMetaHost* host, string str) + { + fixed (char* pStr = str) + fixed (Guid* iid = &IID_ICLRRuntimeInfo) + { + var getRuntime = (delegate*) host->vtbl->GetRuntime; + + ICLRRuntimeInfo* ptr; + var result = getRuntime(host, pStr, iid, &ptr); + return result == 0 ? ptr : null; + } + } +} +file unsafe struct ICLRMetaHostVtbl +{ + public void* QueryInterface; + public void* AddRef; + public void* Release; + public void* GetRuntime; + public void* GetVersionFromFile; + public void* EnumerateInstalledRuntimes; + public void* EnumerateLoadedRuntimes; + public void* RequestRuntimeLoadedNotification; + public void* QueryLegacyV2RuntimeBinding; + public void* ExitProcess; +} + +public static unsafe class NETFrameworkLoader +{ + public static void Launch(string[] args) + { + // Catch AccessViolation + Environment.SetEnvironmentVariable("COMPlus_legacyCorruptedStateExceptionsPolicy", "1"); + + var clrMetaHost = ICLRMetaHost.Create(); + var runtimeInfo = ICLRMetaHost.GetRuntime(clrMetaHost, "v4.0.30319"); + var runtimeHost = ICLRRuntimeInfo.GetRuntimeHost(runtimeInfo); + var startResult = ICLRRuntimeHost.Start(runtimeHost); + var executeResult = ICLRRuntimeHost.ExecuteInDefaultAppDomain(runtimeHost, "Bannerlord.BLSE.Shared.dll", "Bannerlord.BLSE.Shared.Program", "NativeEntry2", string.Join("|||", args)); + ICLRRuntimeInfo.Release(runtimeInfo); + ICLRRuntimeHost.Release(runtimeHost); + ICLRMetaHost.Release(clrMetaHost); + } +} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Core.Standalone/Program.cs b/src/Bannerlord.BLSE.Core.Standalone/Program.cs new file mode 100644 index 0000000..ae1b57a --- /dev/null +++ b/src/Bannerlord.BLSE.Core.Standalone/Program.cs @@ -0,0 +1,26 @@ +namespace Bannerlord.BLSE.Core.Launcher; + +public static class Program +{ + public static void Main(string[] args) + { +#if STANDALONE + args = new[] { "standalone" }.Concat(args).ToArray(); +#elif LAUNCHER + args = new[] { "launcher" }.Concat(args).ToArray(); +#elif LAUNCHEREX + args = new[] { "launcherex" }.Concat(args).ToArray(); +#endif + switch (new DirectoryInfo(Directory.GetCurrentDirectory()).Name) + { + case "Win64_Shipping_Client": + NETFrameworkLoader.Launch(args); + break; + case "Gaming.Desktop.x64_Shipping_Client": + NETCoreLoader.Launch(args); + break; + } + + NETFrameworkLoader.Launch(args); + } +} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj index ceb0da5..f0c4dd8 100644 --- a/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj +++ b/src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj @@ -63,7 +63,7 @@ $(MSBuildThisFileDirectory)..\Bannerlord.LauncherEx\Bannerlord.LauncherEx.csproj - "$([System.IO.Path]::GetFullPath('$(LauncherExProject)'))" + "$([System.IO.Path]::GetFullPath('$(LauncherExProject)'))" diff --git a/src/Bannerlord.BLSE.Shared/Program.cs b/src/Bannerlord.BLSE.Shared/Program.cs index 059021b..5e34f9d 100644 --- a/src/Bannerlord.BLSE.Shared/Program.cs +++ b/src/Bannerlord.BLSE.Shared/Program.cs @@ -53,4 +53,10 @@ public static void NativeEntry(int argc, IntPtr argv) } Main(args); } + + public static int NativeEntry2(string args) + { + Main(args.Split(new[] { "|||" }, StringSplitOptions.RemoveEmptyEntries)); + return 0; + } } \ No newline at end of file diff --git a/src/Bannerlord.BLSE.sln b/src/Bannerlord.BLSE.sln index 6bdd48b..e7c7dc6 100644 --- a/src/Bannerlord.BLSE.sln +++ b/src/Bannerlord.BLSE.sln @@ -39,6 +39,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bannerlord.BLSE.Launcher", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bannerlord.BLSE.LauncherEx", "Bannerlord.BLSE.LauncherEx\Bannerlord.BLSE.LauncherEx.csproj", "{57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.Launcher", "Bannerlord.BLSE.Core.Launcher\Bannerlord.BLSE.Core.Launcher.csproj", "{A99D50E0-924A-47A3-A465-5D53F2DDE4DE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.Standalone", "Bannerlord.BLSE.Core.Standalone\Bannerlord.BLSE.Core.Standalone.csproj", "{25C39C41-4013-440F-A1BA-5F25EF6A040B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.LauncherEx", "Bannerlord.BLSE.Core.LauncherEx\Bannerlord.BLSE.Core.LauncherEx.csproj", "{1605D5AF-A37B-4062-AAB7-DAA921AF74FC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -69,6 +75,18 @@ Global {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}.Debug|Any CPU.Build.0 = Debug|Any CPU {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}.Release|Any CPU.ActiveCfg = Release|Any CPU {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}.Release|Any CPU.Build.0 = Release|Any CPU + {A99D50E0-924A-47A3-A465-5D53F2DDE4DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A99D50E0-924A-47A3-A465-5D53F2DDE4DE}.Release|Any CPU.Build.0 = Release|Any CPU + {A99D50E0-924A-47A3-A465-5D53F2DDE4DE}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {A99D50E0-924A-47A3-A465-5D53F2DDE4DE}.Debug|Any CPU.Build.0 = Release|Any CPU + {25C39C41-4013-440F-A1BA-5F25EF6A040B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {25C39C41-4013-440F-A1BA-5F25EF6A040B}.Release|Any CPU.Build.0 = Release|Any CPU + {25C39C41-4013-440F-A1BA-5F25EF6A040B}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {25C39C41-4013-440F-A1BA-5F25EF6A040B}.Debug|Any CPU.Build.0 = Release|Any CPU + {1605D5AF-A37B-4062-AAB7-DAA921AF74FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1605D5AF-A37B-4062-AAB7-DAA921AF74FC}.Release|Any CPU.Build.0 = Release|Any CPU + {1605D5AF-A37B-4062-AAB7-DAA921AF74FC}.Debug|Any CPU.ActiveCfg = Release|Any CPU + {1605D5AF-A37B-4062-AAB7-DAA921AF74FC}.Debug|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -79,11 +97,14 @@ Global {EEDC1097-00DE-4029-89A3-FE6109D049A6} = {1269BCAA-0118-43EA-B0B3-39F615D95399} {1779DF86-6E17-45F5-B275-EE6B41E0BD48} = {1269BCAA-0118-43EA-B0B3-39F615D95399} {CF940410-3955-4361-BD7E-F78B870D8CD1} = {4BC92D7D-8CD2-41D4-BB6E-779974BB45EB} - {59A34CE4-AC23-495F-BC7B-133114E7E6D8} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} {15129193-D2B6-4A7C-97EF-3736ED1372CF} = {4BC92D7D-8CD2-41D4-BB6E-779974BB45EB} {2A068FA7-A291-43A8-9885-E11D03311BE0} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} {2D74327F-916D-4540-AF94-391EF1F90655} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} + {A99D50E0-924A-47A3-A465-5D53F2DDE4DE} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} + {25C39C41-4013-440F-A1BA-5F25EF6A040B} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} + {1605D5AF-A37B-4062-AAB7-DAA921AF74FC} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} + {59A34CE4-AC23-495F-BC7B-133114E7E6D8} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0632034B-46A0-49A8-998A-3ADB58648DC3} From 3b854f5a16fcb0e5f9f34ce776881b8d6ce7dd76 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:35:26 +0200 Subject: [PATCH 25/33] Removed old launchers --- .../Bannerlord.BLSE.Launcher.csproj | 38 -------- src/Bannerlord.BLSE.Launcher/README.md | 1 - .../Bannerlord.BLSE.LauncherEx.csproj | 38 -------- .../Properties/launchSettings.json | 9 -- src/Bannerlord.BLSE.LauncherEx/README.md | 1 - .../Bannerlord.BLSE.Standalone.csproj | 27 ------ .../NETCoreLoader.cs | 95 ------------------- .../NETFrameworkLoader.cs | 9 -- src/Bannerlord.BLSE.Standalone/Program.cs | 27 ------ .../Properties/launchSettings.json | 28 ------ src/Bannerlord.BLSE.Standalone/README.md | 1 - src/Bannerlord.BLSE.sln | 21 ---- 12 files changed, 295 deletions(-) delete mode 100644 src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj delete mode 100644 src/Bannerlord.BLSE.Launcher/README.md delete mode 100644 src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj delete mode 100644 src/Bannerlord.BLSE.LauncherEx/Properties/launchSettings.json delete mode 100644 src/Bannerlord.BLSE.LauncherEx/README.md delete mode 100644 src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj delete mode 100644 src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs delete mode 100644 src/Bannerlord.BLSE.Standalone/NETFrameworkLoader.cs delete mode 100644 src/Bannerlord.BLSE.Standalone/Program.cs delete mode 100644 src/Bannerlord.BLSE.Standalone/Properties/launchSettings.json delete mode 100644 src/Bannerlord.BLSE.Standalone/README.md diff --git a/src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj b/src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj deleted file mode 100644 index c88d786..0000000 --- a/src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj +++ /dev/null @@ -1,38 +0,0 @@ - - - - net472 - 11.0 - enable - x64 - winexe - ../../resources/BLSE_SMALL.ico - $(DefineConstants);LAUNCHER - - - - - NETCoreLoader.cs - - - NETFrameworkLoader.cs - - - Program.cs - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Launcher/README.md b/src/Bannerlord.BLSE.Launcher/README.md deleted file mode 100644 index 7736a1b..0000000 --- a/src/Bannerlord.BLSE.Launcher/README.md +++ /dev/null @@ -1 +0,0 @@ -Executable that has enables BLSE and launches the game's launcher. \ No newline at end of file diff --git a/src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj b/src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj deleted file mode 100644 index d056f56..0000000 --- a/src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj +++ /dev/null @@ -1,38 +0,0 @@ - - - - net472 - 11.0 - enable - x64 - winexe - ../../resources/BLSE_SMALL.ico - $(DefineConstants);LAUNCHEREX - - - - - NETCoreLoader.cs - - - NETFrameworkLoader.cs - - - Program.cs - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Bannerlord.BLSE.LauncherEx/Properties/launchSettings.json b/src/Bannerlord.BLSE.LauncherEx/Properties/launchSettings.json deleted file mode 100644 index af67dd2..0000000 --- a/src/Bannerlord.BLSE.LauncherEx/Properties/launchSettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "profiles": { - "BLSE Launcher": { - "commandName": "Executable", - "executablePath": "$(GameFolder)\\bin\\Win64_Shipping_Client\\$(AssemblyName).exe", - "workingDirectory": "$(GameFolder)\\bin\\Win64_Shipping_Client" - } - } -} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.LauncherEx/README.md b/src/Bannerlord.BLSE.LauncherEx/README.md deleted file mode 100644 index cbbb10f..0000000 --- a/src/Bannerlord.BLSE.LauncherEx/README.md +++ /dev/null @@ -1 +0,0 @@ -Executable that has enables BLSE and the game's launcher with BUTRLoader (LauncherEx). \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj b/src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj deleted file mode 100644 index a88a4c4..0000000 --- a/src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - net472 - 11.0 - enable - x64 - winexe - Bannerlord.BLSE.Standalone - ../../resources/BLSE_SMALL.ico - $(DefineConstants);STANDALONE - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs b/src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs deleted file mode 100644 index 0b07d03..0000000 --- a/src/Bannerlord.BLSE.Standalone/NETCoreLoader.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; - -namespace Bannerlord.BLSE; - -public static class NETCoreLoader -{ - private const string CoreCLRPath = "Microsoft.NETCore.App/coreclr.dll"; - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate void EntryDelegate(int argc, IntPtr[] argv); - - [DllImport(CoreCLRPath, CallingConvention = CallingConvention.StdCall)] - private static extern int coreclr_initialize(IntPtr exePath, IntPtr appDomainFriendlyName, int propertyCount, IntPtr[] propertyKeys, IntPtr[] propertyValues, out IntPtr hostHandle, out IntPtr domainId); - - [DllImport(CoreCLRPath, CallingConvention = CallingConvention.StdCall)] - private static extern int coreclr_create_delegate(IntPtr hostHandle, uint domainId, IntPtr entryPointAssemblyName, IntPtr entryPointTypeName, IntPtr entryPointMethodName, out IntPtr @delegate); - - private static IntPtr NativeUTF8(string str) - { - var length = Encoding.UTF8.GetByteCount(str); - var buffer = new byte[length + 1]; - Encoding.UTF8.GetBytes(str, 0, str.Length, buffer, 0); - buffer[buffer.Length - 1] = 0; - - var nativeBuffer = Marshal.AllocHGlobal(buffer.Length); - Marshal.Copy(buffer, 0, nativeBuffer, buffer.Length); - return nativeBuffer; - } - - public static void Launch(string[] args) - { - // Catch AccessViolation. .NET Core 3.1 still allows that - Environment.SetEnvironmentVariable("COMPlus_legacyCorruptedStateExceptionsPolicy", "1"); - - // Disable aggressive inlining of JIT by disabling JIT Optimizations - // TODO: This is kinda extreme. What could be done? - Environment.SetEnvironmentVariable("COMPlus_JITMinOpts", "1"); - - var path = AppDomain.CurrentDomain.BaseDirectory; - var rootFiles = Directory.GetFiles(Path.Combine(path), "*.dll", SearchOption.TopDirectoryOnly) - .Where(x => Path.GetFileName(x) != "Mono.Cecil.dll") // On .NET Core, the game distributes an old version of Mono.Cecil.dll. Ignore it. - .Select(x => $"{x};"); - var netcoreFiles = Directory.GetFiles(Path.Combine(path, "Microsoft.NETCore.App"), "*.dll", SearchOption.TopDirectoryOnly).Select(x => $"{x};"); - var aspCoreFiles = Directory.GetFiles(Path.Combine(path, "Microsoft.AspNetCore.App"), "*.dll", SearchOption.TopDirectoryOnly).Select(x => $"{x};"); - var winDeskFiles = Directory.GetFiles(Path.Combine(path, "Microsoft.WindowsDesktop.App"), "*.dll", SearchOption.TopDirectoryOnly).Select(x => $"{x};"); - // Do not set Modules .dll as trusted and to be loaded - var modulesFiles = Directory.GetFiles(Path.Combine(path, "..", "..", "Modules"), "*.dll", SearchOption.AllDirectories).Select(x => $"{x};"); - // The instantly loaded assembly files - var files = string.Join("", rootFiles.Concat(netcoreFiles).Concat(aspCoreFiles).Concat(winDeskFiles)/*.Concat(files5)*/); - - var propKeys = new IntPtr[] - { - NativeUTF8("TRUSTED_PLATFORM_ASSEMBLIES") - }; - var propValues = new IntPtr[] - { - NativeUTF8(files) - }; - - var initResult = coreclr_initialize( - NativeUTF8(path), - NativeUTF8("BLSE"), - 1, - propKeys, - propValues, - out var pCLRRuntimeHost, - out var domainId); - if (initResult < 0) - { - Console.WriteLine("Failed to initialize Bannerlord's .NET Core CLR!"); - return; - } - - var createDelegateResult = coreclr_create_delegate( - pCLRRuntimeHost, - (uint) domainId, - NativeUTF8("Bannerlord.BLSE.Shared"), - NativeUTF8("Bannerlord.BLSE.Shared.Program"), - NativeUTF8("NativeEntry"), - out var pMethod); - if (createDelegateResult < 0) - { - Console.WriteLine("Failed to get BLSE's entrypoint!"); - return; - } - - var args2 = args.Select(NativeUTF8).ToArray(); - var @delegate = Marshal.GetDelegateForFunctionPointer(pMethod); - @delegate(args.Length, args2); - } -} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Standalone/NETFrameworkLoader.cs b/src/Bannerlord.BLSE.Standalone/NETFrameworkLoader.cs deleted file mode 100644 index 6d569bb..0000000 --- a/src/Bannerlord.BLSE.Standalone/NETFrameworkLoader.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Bannerlord.BLSE; - -public static class NETFrameworkLoader -{ - public static void Launch(string[] args) - { - Shared.Program.Main(args); - } -} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Standalone/Program.cs b/src/Bannerlord.BLSE.Standalone/Program.cs deleted file mode 100644 index 03b3a05..0000000 --- a/src/Bannerlord.BLSE.Standalone/Program.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.IO; -using System.Linq; - -namespace Bannerlord.BLSE.Standalone; - -public static class Program -{ - public static void Main(string[] args) - { -#if STANDALONE - args = new[] { "standalone" }.Concat(args).ToArray(); -#elif LAUNCHER - args = new[] { "launcher" }.Concat(args).ToArray(); -#elif LAUNCHEREX - args = new[] { "launcherex" }.Concat(args).ToArray(); -#endif - switch (new DirectoryInfo(Directory.GetCurrentDirectory()).Name) - { - case "Win64_Shipping_Client": - NETFrameworkLoader.Launch(args); - break; - case "Gaming.Desktop.x64_Shipping_Client": - NETCoreLoader.Launch(args); - break; - } - } -} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Standalone/Properties/launchSettings.json b/src/Bannerlord.BLSE.Standalone/Properties/launchSettings.json deleted file mode 100644 index b3d82b2..0000000 --- a/src/Bannerlord.BLSE.Standalone/Properties/launchSettings.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "profiles": { - "BLSE Standalone Vanilla": { - "commandName": "Executable", - "executablePath": "$(GameFolder)\\bin\\Win64_Shipping_Client\\$(AssemblyName).exe", - "commandLineArgs": "/singleplayer _MODULES_*Native*SandBoxCore*Sandbox*StoryMode*CustomBattle*_MODULES_", - "workingDirectory": "$(GameFolder)\\bin\\Win64_Shipping_Client" - }, - "BLSE Standalone BUTR Stack": { - "commandName": "Executable", - "executablePath": "$(GameFolder)\\bin\\Win64_Shipping_Client\\$(AssemblyName).exe", - "commandLineArgs": "/singleplayer _MODULES_*Bannerlord.Harmony*Bannerlord.ButterLib*Bannerlord.UIExtenderEx*Bannerlord.MBOptionScreen*Native*SandBoxCore*Sandbox*StoryMode*CustomBattle*_MODULES_", - "workingDirectory": "$(GameFolder)\\bin\\Win64_Shipping_Client" - }, - "BLSE Standalone Save File": { - "commandName": "Executable", - "executablePath": "$(GameFolder)\\bin\\Win64_Shipping_Client\\$(AssemblyName).exe", - "commandLineArgs": "/singleplayer /continuesave sdfgs _MODULES_*Bannerlord.Harmony*Bannerlord.ButterLib*Bannerlord.UIExtenderEx*Bannerlord.MBOptionScreen*Native*SandBoxCore*Sandbox*StoryMode*CustomBattle*_MODULES_", - "workingDirectory": "$(GameFolder)\\bin\\Win64_Shipping_Client" - }, - "BLSE Standalone Save File Without Modules": { - "commandName": "Executable", - "executablePath": "$(GameFolder)\\bin\\Win64_Shipping_Client\\$(AssemblyName).exe", - "commandLineArgs": "/singleplayer /continuesave sdfgs", - "workingDirectory": "$(GameFolder)\\bin\\Win64_Shipping_Client" - } - } -} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Standalone/README.md b/src/Bannerlord.BLSE.Standalone/README.md deleted file mode 100644 index 8bbde1a..0000000 --- a/src/Bannerlord.BLSE.Standalone/README.md +++ /dev/null @@ -1 +0,0 @@ -Executable that has enables BLSE and launches the game directly without the launcher. \ No newline at end of file diff --git a/src/Bannerlord.BLSE.sln b/src/Bannerlord.BLSE.sln index e7c7dc6..6843531 100644 --- a/src/Bannerlord.BLSE.sln +++ b/src/Bannerlord.BLSE.sln @@ -33,12 +33,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bannerlord.BLSE.Shared", "B EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "loaders", "loaders", "{15129193-D2B6-4A7C-97EF-3736ED1372CF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bannerlord.BLSE.Standalone", "Bannerlord.BLSE.Standalone\Bannerlord.BLSE.Standalone.csproj", "{2A068FA7-A291-43A8-9885-E11D03311BE0}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bannerlord.BLSE.Launcher", "Bannerlord.BLSE.Launcher\Bannerlord.BLSE.Launcher.csproj", "{2D74327F-916D-4540-AF94-391EF1F90655}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bannerlord.BLSE.LauncherEx", "Bannerlord.BLSE.LauncherEx\Bannerlord.BLSE.LauncherEx.csproj", "{57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.Launcher", "Bannerlord.BLSE.Core.Launcher\Bannerlord.BLSE.Core.Launcher.csproj", "{A99D50E0-924A-47A3-A465-5D53F2DDE4DE}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.Standalone", "Bannerlord.BLSE.Core.Standalone\Bannerlord.BLSE.Core.Standalone.csproj", "{25C39C41-4013-440F-A1BA-5F25EF6A040B}" @@ -63,18 +57,6 @@ Global {59A34CE4-AC23-495F-BC7B-133114E7E6D8}.Debug|Any CPU.Build.0 = Debug|Any CPU {59A34CE4-AC23-495F-BC7B-133114E7E6D8}.Release|Any CPU.ActiveCfg = Release|Any CPU {59A34CE4-AC23-495F-BC7B-133114E7E6D8}.Release|Any CPU.Build.0 = Release|Any CPU - {2A068FA7-A291-43A8-9885-E11D03311BE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2A068FA7-A291-43A8-9885-E11D03311BE0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2A068FA7-A291-43A8-9885-E11D03311BE0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2A068FA7-A291-43A8-9885-E11D03311BE0}.Release|Any CPU.Build.0 = Release|Any CPU - {2D74327F-916D-4540-AF94-391EF1F90655}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2D74327F-916D-4540-AF94-391EF1F90655}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2D74327F-916D-4540-AF94-391EF1F90655}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2D74327F-916D-4540-AF94-391EF1F90655}.Release|Any CPU.Build.0 = Release|Any CPU - {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3}.Release|Any CPU.Build.0 = Release|Any CPU {A99D50E0-924A-47A3-A465-5D53F2DDE4DE}.Release|Any CPU.ActiveCfg = Release|Any CPU {A99D50E0-924A-47A3-A465-5D53F2DDE4DE}.Release|Any CPU.Build.0 = Release|Any CPU {A99D50E0-924A-47A3-A465-5D53F2DDE4DE}.Debug|Any CPU.ActiveCfg = Release|Any CPU @@ -98,9 +80,6 @@ Global {1779DF86-6E17-45F5-B275-EE6B41E0BD48} = {1269BCAA-0118-43EA-B0B3-39F615D95399} {CF940410-3955-4361-BD7E-F78B870D8CD1} = {4BC92D7D-8CD2-41D4-BB6E-779974BB45EB} {15129193-D2B6-4A7C-97EF-3736ED1372CF} = {4BC92D7D-8CD2-41D4-BB6E-779974BB45EB} - {2A068FA7-A291-43A8-9885-E11D03311BE0} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} - {2D74327F-916D-4540-AF94-391EF1F90655} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} - {57C98CA2-8BC5-4D5D-A9E8-608C4C2F14E3} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} {A99D50E0-924A-47A3-A465-5D53F2DDE4DE} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} {25C39C41-4013-440F-A1BA-5F25EF6A040B} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} {1605D5AF-A37B-4062-AAB7-DAA921AF74FC} = {15129193-D2B6-4A7C-97EF-3736ED1372CF} From 5a7b250f4257252ac117d6ed14b4034adcad63c9 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:38:58 +0200 Subject: [PATCH 26/33] Renamed Core to NativeAOT --- .../Bannerlord.BLSE.NativeAOT.Launcher.csproj} | 10 +++++----- .../Bannerlord.BLSE.NativeAOT.LauncherEx.csproj} | 8 ++++---- .../Bannerlord.BLSE.NativeAOT.Standalone.csproj} | 2 +- .../NETCoreLoader.cs | 2 +- .../NETFrameworkLoader.cs | 0 .../Program.cs | 2 +- src/Bannerlord.BLSE.sln | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) rename src/{Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj => Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.NativeAOT.Launcher.csproj} (90%) rename src/{Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj => Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.NativeAOT.LauncherEx.csproj} (90%) rename src/{Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj => Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.NativeAOT.Standalone.csproj} (98%) rename src/{Bannerlord.BLSE.Core.Standalone => Bannerlord.BLSE.NativeAOT.Standalone}/NETCoreLoader.cs (98%) rename src/{Bannerlord.BLSE.Core.Standalone => Bannerlord.BLSE.NativeAOT.Standalone}/NETFrameworkLoader.cs (100%) rename src/{Bannerlord.BLSE.Core.Standalone => Bannerlord.BLSE.NativeAOT.Standalone}/Program.cs (94%) diff --git a/src/Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj b/src/Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.NativeAOT.Launcher.csproj similarity index 90% rename from src/Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj rename to src/Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.NativeAOT.Launcher.csproj index 5b5eef9..bfc6a24 100644 --- a/src/Bannerlord.BLSE.Core.Launcher/Bannerlord.BLSE.Core.Launcher.csproj +++ b/src/Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.NativeAOT.Launcher.csproj @@ -40,20 +40,20 @@ - - + NETCoreLoader.cs - + NETFrameworkLoader.cs - + Program.cs + - + diff --git a/src/Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj b/src/Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.NativeAOT.LauncherEx.csproj similarity index 90% rename from src/Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj rename to src/Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.NativeAOT.LauncherEx.csproj index 868d015..4899b75 100644 --- a/src/Bannerlord.BLSE.Core.LauncherEx/Bannerlord.BLSE.Core.LauncherEx.csproj +++ b/src/Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.NativeAOT.LauncherEx.csproj @@ -40,19 +40,19 @@ - + NETCoreLoader.cs - + NETFrameworkLoader.cs - + Program.cs - + diff --git a/src/Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj b/src/Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.NativeAOT.Standalone.csproj similarity index 98% rename from src/Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj rename to src/Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.NativeAOT.Standalone.csproj index 7459fc3..729c679 100644 --- a/src/Bannerlord.BLSE.Core.Standalone/Bannerlord.BLSE.Core.Standalone.csproj +++ b/src/Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.NativeAOT.Standalone.csproj @@ -40,7 +40,7 @@ - + diff --git a/src/Bannerlord.BLSE.Core.Standalone/NETCoreLoader.cs b/src/Bannerlord.BLSE.NativeAOT.Standalone/NETCoreLoader.cs similarity index 98% rename from src/Bannerlord.BLSE.Core.Standalone/NETCoreLoader.cs rename to src/Bannerlord.BLSE.NativeAOT.Standalone/NETCoreLoader.cs index d9fd027..1a1cce2 100644 --- a/src/Bannerlord.BLSE.Core.Standalone/NETCoreLoader.cs +++ b/src/Bannerlord.BLSE.NativeAOT.Standalone/NETCoreLoader.cs @@ -1,7 +1,7 @@ using System.Runtime.InteropServices; using System.Text; -namespace Bannerlord.BLSE.Core.Launcher; +namespace Bannerlord.BLSE; [UnmanagedFunctionPointer(CallingConvention.StdCall)] file delegate void EntryDelegate(int argc, IntPtr[] argv); diff --git a/src/Bannerlord.BLSE.Core.Standalone/NETFrameworkLoader.cs b/src/Bannerlord.BLSE.NativeAOT.Standalone/NETFrameworkLoader.cs similarity index 100% rename from src/Bannerlord.BLSE.Core.Standalone/NETFrameworkLoader.cs rename to src/Bannerlord.BLSE.NativeAOT.Standalone/NETFrameworkLoader.cs diff --git a/src/Bannerlord.BLSE.Core.Standalone/Program.cs b/src/Bannerlord.BLSE.NativeAOT.Standalone/Program.cs similarity index 94% rename from src/Bannerlord.BLSE.Core.Standalone/Program.cs rename to src/Bannerlord.BLSE.NativeAOT.Standalone/Program.cs index ae1b57a..050723d 100644 --- a/src/Bannerlord.BLSE.Core.Standalone/Program.cs +++ b/src/Bannerlord.BLSE.NativeAOT.Standalone/Program.cs @@ -1,4 +1,4 @@ -namespace Bannerlord.BLSE.Core.Launcher; +namespace Bannerlord.BLSE; public static class Program { diff --git a/src/Bannerlord.BLSE.sln b/src/Bannerlord.BLSE.sln index 6843531..0258778 100644 --- a/src/Bannerlord.BLSE.sln +++ b/src/Bannerlord.BLSE.sln @@ -33,11 +33,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bannerlord.BLSE.Shared", "B EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "loaders", "loaders", "{15129193-D2B6-4A7C-97EF-3736ED1372CF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.Launcher", "Bannerlord.BLSE.Core.Launcher\Bannerlord.BLSE.Core.Launcher.csproj", "{A99D50E0-924A-47A3-A465-5D53F2DDE4DE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.NativeAOT.Launcher", "Bannerlord.BLSE.NativeAOT.Launcher\Bannerlord.BLSE.NativeAOT.Launcher.csproj", "{A99D50E0-924A-47A3-A465-5D53F2DDE4DE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.Standalone", "Bannerlord.BLSE.Core.Standalone\Bannerlord.BLSE.Core.Standalone.csproj", "{25C39C41-4013-440F-A1BA-5F25EF6A040B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.NativeAOT.Standalone", "Bannerlord.BLSE.NativeAOT.Standalone\Bannerlord.BLSE.NativeAOT.Standalone.csproj", "{25C39C41-4013-440F-A1BA-5F25EF6A040B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.Core.LauncherEx", "Bannerlord.BLSE.Core.LauncherEx\Bannerlord.BLSE.Core.LauncherEx.csproj", "{1605D5AF-A37B-4062-AAB7-DAA921AF74FC}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bannerlord.BLSE.NativeAOT.LauncherEx", "Bannerlord.BLSE.NativeAOT.LauncherEx\Bannerlord.BLSE.NativeAOT.LauncherEx.csproj", "{1605D5AF-A37B-4062-AAB7-DAA921AF74FC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 2af67a1d419bbe31186fec1fd4edf56a91f6af03 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:50:31 +0200 Subject: [PATCH 27/33] Release Fixed some warnings Adapted build --- build/common.props | 2 +- changelog.txt | 3 +- .../NETFrameworkLoader.cs | 132 +++++++++++------- 3 files changed, 82 insertions(+), 55 deletions(-) diff --git a/build/common.props b/build/common.props index 14261db..de09cd6 100644 --- a/build/common.props +++ b/build/common.props @@ -10,7 +10,7 @@ - 1.0.5 + 1.1.0 2.10.1 3.0.0.135 5.0.198 diff --git a/changelog.txt b/changelog.txt index 7d2c35a..592083d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,7 @@ --------------------------------------------------------------------------------------------------- -Version: 1.0.5 +Version: 1.1.0 Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1 +* The launchers are now native code instead of C#, but for the cost of increased size * Fixed Singleplayer not being shown by default * Better error messages --------------------------------------------------------------------------------------------------- diff --git a/src/Bannerlord.BLSE.NativeAOT.Standalone/NETFrameworkLoader.cs b/src/Bannerlord.BLSE.NativeAOT.Standalone/NETFrameworkLoader.cs index faf19d8..eb6226a 100644 --- a/src/Bannerlord.BLSE.NativeAOT.Standalone/NETFrameworkLoader.cs +++ b/src/Bannerlord.BLSE.NativeAOT.Standalone/NETFrameworkLoader.cs @@ -1,10 +1,15 @@ -using System.Runtime.InteropServices; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; namespace Bannerlord.BLSE; -file unsafe struct ICLRRuntimeHost +[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Local")] +[SuppressMessage("ReSharper", "UnusedVariable")] +file readonly unsafe struct ICLRRuntimeHost { - private ICLRRuntimeHostVtbl* vtbl; +#pragma warning disable CS0649 + private readonly ICLRRuntimeHostVtbl* vtbl; +#pragma warning restore CS0649 public static nint Release(ICLRRuntimeHost* host) { @@ -33,29 +38,37 @@ public static int ExecuteInDefaultAppDomain(ICLRRuntimeHost* host, string dllPat } } } -file unsafe struct ICLRRuntimeHostVtbl +[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Local")] +[SuppressMessage("ReSharper", "UnusedVariable")] +file readonly unsafe struct ICLRRuntimeHostVtbl { - public void* QueryInterface; - public void* AddRef; - public void* Release; - public void* Start; - public void* Stop; - public void* SetHostControl; - public void* GetCLRControl; - public void* UnloadAppDomain; - public void* ExecuteInAppDomain; - public void* GetCurrentAppDomainId; - public void* ExecuteApplication; - public void* ExecuteInDefaultAppDomain; +#pragma warning disable CS0649 + public readonly void* QueryInterface; + public readonly void* AddRef; + public readonly void* Release; + public readonly void* Start; + public readonly void* Stop; + public readonly void* SetHostControl; + public readonly void* GetCLRControl; + public readonly void* UnloadAppDomain; + public readonly void* ExecuteInAppDomain; + public readonly void* GetCurrentAppDomainId; + public readonly void* ExecuteApplication; + public readonly void* ExecuteInDefaultAppDomain; +#pragma warning restore CS0649 } -file unsafe struct ICLRRuntimeInfo +[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Local")] +[SuppressMessage("ReSharper", "UnusedVariable")] +file readonly unsafe struct ICLRRuntimeInfo { - private static Guid CLSID_CLRRuntimeHost = new("90F1A06E-7712-4762-86B5-7A5EBA6BDB02"); - private static Guid IID_ICLRRuntimeHost = new("90F1A06C-7712-4762-86B5-7A5EBA6BDB02"); - - private ICLRRuntimeInfoVtbl* vtbl; + private static readonly Guid CLSID_CLRRuntimeHost = new("90F1A06E-7712-4762-86B5-7A5EBA6BDB02"); + private static readonly Guid IID_ICLRRuntimeHost = new("90F1A06C-7712-4762-86B5-7A5EBA6BDB02"); +#pragma warning disable CS0649 + private readonly ICLRRuntimeInfoVtbl* vtbl; +#pragma warning restore CS0649 + public static nint Release(ICLRRuntimeInfo* host) { var release = (delegate*) host->vtbl->Release; @@ -80,36 +93,44 @@ public static nint Release(ICLRRuntimeInfo* host) } } } -file unsafe struct ICLRRuntimeInfoVtbl +[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Local")] +[SuppressMessage("ReSharper", "UnusedVariable")] +file readonly unsafe struct ICLRRuntimeInfoVtbl { - public void* QueryInterface; - public void* AddRef; - public void* Release; - public void* GetVersionString; - public void* GetRuntimeDirectory; - public void* IsLoaded; - public void* LoadErrorString; - public void* LoadLibrary; - public void* GetProcAddress; - public void* GetInterface; - public void* IsLoadable; - public void* SetDefaultStartupFlags; - public void* GetDefaultStartupFlags; - public void* BindAsLegacyV2Runtime; - public void* IsStarted; +#pragma warning disable CS0649 + public readonly void* QueryInterface; + public readonly void* AddRef; + public readonly void* Release; + public readonly void* GetVersionString; + public readonly void* GetRuntimeDirectory; + public readonly void* IsLoaded; + public readonly void* LoadErrorString; + public readonly void* LoadLibrary; + public readonly void* GetProcAddress; + public readonly void* GetInterface; + public readonly void* IsLoadable; + public readonly void* SetDefaultStartupFlags; + public readonly void* GetDefaultStartupFlags; + public readonly void* BindAsLegacyV2Runtime; + public readonly void* IsStarted; +#pragma warning restore CS0649 } -file unsafe struct ICLRMetaHost +[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Local")] +[SuppressMessage("ReSharper", "UnusedVariable")] +file readonly unsafe struct ICLRMetaHost { - private static Guid CLSID_CLRMetaHost = new("9280188D-0E8E-4867-B30C-7FA83884E8DE"); - private static Guid IID_ICLRMetaHost = new("D332DB9E-B9B3-4125-8207-A14884F53216"); + private static readonly Guid CLSID_CLRMetaHost = new("9280188D-0E8E-4867-B30C-7FA83884E8DE"); + private static readonly Guid IID_ICLRMetaHost = new("D332DB9E-B9B3-4125-8207-A14884F53216"); - private static Guid IID_ICLRRuntimeInfo = new("BD39D1D2-BA2F-486A-89B0-B4B0CB466891"); + private static readonly Guid IID_ICLRRuntimeInfo = new("BD39D1D2-BA2F-486A-89B0-B4B0CB466891"); [DllImport("mscoree")] private static extern int CLRCreateInstance(Guid* clsId, Guid* rIId, ICLRMetaHost** instance); - private ICLRMetaHostVtbl *vtbl; +#pragma warning disable CS0649 + private readonly ICLRMetaHostVtbl *vtbl; +#pragma warning restore CS0649 public static ICLRMetaHost* Create() { @@ -141,20 +162,25 @@ public static nint Release(ICLRMetaHost* host) } } } -file unsafe struct ICLRMetaHostVtbl +[SuppressMessage("ReSharper", "UnusedMethodReturnValue.Local")] +[SuppressMessage("ReSharper", "UnusedVariable")] +file readonly unsafe struct ICLRMetaHostVtbl { - public void* QueryInterface; - public void* AddRef; - public void* Release; - public void* GetRuntime; - public void* GetVersionFromFile; - public void* EnumerateInstalledRuntimes; - public void* EnumerateLoadedRuntimes; - public void* RequestRuntimeLoadedNotification; - public void* QueryLegacyV2RuntimeBinding; - public void* ExitProcess; +#pragma warning disable CS0649 + public readonly void* QueryInterface; + public readonly void* AddRef; + public readonly void* Release; + public readonly void* GetRuntime; + public readonly void* GetVersionFromFile; + public readonly void* EnumerateInstalledRuntimes; + public readonly void* EnumerateLoadedRuntimes; + public readonly void* RequestRuntimeLoadedNotification; + public readonly void* QueryLegacyV2RuntimeBinding; + public readonly void* ExitProcess; +#pragma warning restore CS0649 } +[SuppressMessage("ReSharper", "UnusedVariable")] public static unsafe class NETFrameworkLoader { public static void Launch(string[] args) From 6c65d8ab25b72c61018e58166e71660c6b9b46b8 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:51:38 +0200 Subject: [PATCH 28/33] Fix --- .github/workflows/publish.yml | 62 +++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a2b4763..3af6151 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,8 +21,8 @@ env: DOTNET_CLI_TELEMETRY_OPTOUT: true jobs: - build: - name: Publish + build-changelog: + name: Build Shared runs-on: ubuntu-latest outputs: mod_version: ${{ steps.changelog.outputs.mod_version }} @@ -30,6 +30,26 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Install and Run ChangelogParser + id: changelog + run: | + dotnet tool install -g Bannerlord.ChangelogParser + + EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + + echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT + + echo "mod_description<<$EOF" >> $GITHUB_OUTPUT + echo "$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT + echo "$EOF" >> $GITHUB_OUTPUT + shell: bash + + build-loaders: + name: Build Loaders + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + - name: Setup uses: butr/actions-common-setup@v2 with: @@ -38,26 +58,34 @@ jobs: - name: Build Bannerlord.BLSE run: | mkdir bannerlord; - dotnet build src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; dotnet build src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; shell: pwsh - - name: Install and Run ChangelogParser - id: changelog - run: | - dotnet tool install -g Bannerlord.ChangelogParser + - name: Upload Bannerlord folder + uses: actions/upload-artifact@v3 + with: + name: bannerlord + path: ./bannerlord/ + + build-shared: + name: Build Shared + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 - EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) + - name: Setup + uses: butr/actions-common-setup@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} - echo "mod_version=$(bannerlord_changelog_parser latestversion -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT + - name: Build Bannerlord.BLSE + run: | + mkdir bannerlord; + dotnet build src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + shell: pwsh - echo "mod_description<<$EOF" >> $GITHUB_OUTPUT - echo "$(bannerlord_changelog_parser fulldescription -f "$PWD/changelog.txt")" >> $GITHUB_OUTPUT - echo "$EOF" >> $GITHUB_OUTPUT - shell: bash - - name: Upload Bannerlord folder uses: actions/upload-artifact@v3 with: @@ -75,7 +103,7 @@ jobs: nexusmods_game_id: mountandblade2bannerlord nexusmods_mod_id: 1 mod_filename: BLSE - mod_version: ${{ needs.build.outputs.mod_version }} + mod_version: ${{ needs.build-changelog.outputs.mod_version }} mod_description: ${{ needs.build.outputs.mod_description }} artifact_name: bannerlord secrets: @@ -87,10 +115,10 @@ jobs: ########################### publish-on-github: if: github.ref == 'refs/heads/master' - needs: ["build"] + needs: ["build-changelog", "build-loaders", "build-shared"] uses: BUTR/workflows/.github/workflows/release-github.yml@master with: mod_id: Bannerlord.BLSE - mod_version: ${{ needs.build.outputs.mod_version }} + mod_version: ${{ needs.build-changelog.outputs.mod_version }} mod_description: ${{ needs.build.outputs.mod_description }} artifact_name: bannerlord From afe461f5c635635e226cf06843bee7946379fef5 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:52:12 +0200 Subject: [PATCH 29/33] Fix --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 3af6151..5688300 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -97,7 +97,7 @@ jobs: ########################### publish-on-nexusmods: if: false && github.ref == 'refs/heads/master' - needs: ["build"] + needs: ["build-changelog", "build-loaders", "build-shared"] uses: BUTR/workflows/.github/workflows/release-nexusmods.yml@master with: nexusmods_game_id: mountandblade2bannerlord From ada6f7d3b1741ecfc31cbf454df2cefd35ff34db Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:55:27 +0200 Subject: [PATCH 30/33] Fix --- .github/workflows/publish.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5688300..f1cc0d1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,9 +7,9 @@ on: - 'src/Bannerlord.LauncherEx/**.*' - 'src/Bannerlord.BLSE/**.*' - 'src/Bannerlord.BLSE.Shared/**.*' - - 'src/Bannerlord.BLSE.Standalone/**.*' - - 'src/Bannerlord.BLSE.Launcher/**.*' - - 'src/Bannerlord.BLSE.LauncherEx/**.*' + - 'src/Bannerlord.BLSE.NativeAOT.Standalone/**.*' + - 'src/Bannerlord.BLSE.NativeAOT.Launcher/**.*' + - 'src/Bannerlord.BLSE.NativeAOT.LauncherEx/**.*' workflow_dispatch: env: @@ -21,8 +21,8 @@ env: DOTNET_CLI_TELEMETRY_OPTOUT: true jobs: - build-changelog: - name: Build Shared + get-changelog: + name: Get Changelog runs-on: ubuntu-latest outputs: mod_version: ${{ steps.changelog.outputs.mod_version }} @@ -97,7 +97,7 @@ jobs: ########################### publish-on-nexusmods: if: false && github.ref == 'refs/heads/master' - needs: ["build-changelog", "build-loaders", "build-shared"] + needs: ["get-changelog", "build-loaders", "build-shared"] uses: BUTR/workflows/.github/workflows/release-nexusmods.yml@master with: nexusmods_game_id: mountandblade2bannerlord @@ -115,7 +115,7 @@ jobs: ########################### publish-on-github: if: github.ref == 'refs/heads/master' - needs: ["build-changelog", "build-loaders", "build-shared"] + needs: ["get-changelog", "build-loaders", "build-shared"] uses: BUTR/workflows/.github/workflows/release-github.yml@master with: mod_id: Bannerlord.BLSE From 27e1e22f9d86f553d0d9483616b540ca2ec4dd67 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 16:59:01 +0200 Subject: [PATCH 31/33] Fix --- .github/workflows/publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f1cc0d1..0852074 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -58,9 +58,9 @@ jobs: - name: Build Bannerlord.BLSE run: | mkdir bannerlord; - dotnet build src/Bannerlord.BLSE.Standalone/Bannerlord.BLSE.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; - dotnet build src/Bannerlord.BLSE.Launcher/Bannerlord.BLSE.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; - dotnet build src/Bannerlord.BLSE.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + dotnet build src/Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + dotnet build src/Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + dotnet build src/Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; shell: pwsh - name: Upload Bannerlord folder From bce6cd8604dc6b9b9889a055777603cb7fd0805d Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 17:10:12 +0200 Subject: [PATCH 32/33] Fix --- .github/workflows/publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0852074..c23c913 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -58,9 +58,9 @@ jobs: - name: Build Bannerlord.BLSE run: | mkdir bannerlord; - dotnet build src/Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; - dotnet build src/Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; - dotnet build src/Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + dotnet build src/Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.NativeAOT.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + dotnet build src/Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.NativeAOT.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + dotnet build src/Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.NativeAOT.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; shell: pwsh - name: Upload Bannerlord folder From ca1a504cabc079c30c3c2b165934bd9c73409d6b Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 22 Mar 2023 17:21:01 +0200 Subject: [PATCH 33/33] Parallel builds for speedup --- .github/workflows/publish.yml | 56 +++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c23c913..b89a207 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -44,8 +44,8 @@ jobs: echo "$EOF" >> $GITHUB_OUTPUT shell: bash - build-loaders: - name: Build Loaders + build-loaders-standalone: + name: Build Loaders Standalone runs-on: windows-latest steps: - uses: actions/checkout@v3 @@ -55,11 +55,57 @@ jobs: with: github-token: ${{secrets.GITHUB_TOKEN}} - - name: Build Bannerlord.BLSE + - name: Build Bannerlord.BLSE.NativeAOT.Standalone run: | mkdir bannerlord; dotnet build src/Bannerlord.BLSE.NativeAOT.Standalone/Bannerlord.BLSE.NativeAOT.Standalone.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + shell: pwsh + + - name: Upload Bannerlord folder + uses: actions/upload-artifact@v3 + with: + name: bannerlord + path: ./bannerlord/ + + + build-loaders-launcher: + name: Build Loaders Launcher + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup + uses: butr/actions-common-setup@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + + - name: Build Bannerlord.BLSE.NativeAOT.Launcher + run: | + mkdir bannerlord; dotnet build src/Bannerlord.BLSE.NativeAOT.Launcher/Bannerlord.BLSE.NativeAOT.Launcher.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; + shell: pwsh + + - name: Upload Bannerlord folder + uses: actions/upload-artifact@v3 + with: + name: bannerlord + path: ./bannerlord/ + + + build-loaders-launcherex: + name: Build Loaders LauncehrEx + runs-on: windows-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup + uses: butr/actions-common-setup@v2 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + + - name: Build Bannerlord.BLSE.NativeAOT.LauncherEx + run: | + mkdir bannerlord; dotnet build src/Bannerlord.BLSE.NativeAOT.LauncherEx/Bannerlord.BLSE.NativeAOT.LauncherEx.csproj --configuration Release -p:GameFolder="$PWD/bannerlord" /nowarn:MSB4011; shell: pwsh @@ -97,7 +143,7 @@ jobs: ########################### publish-on-nexusmods: if: false && github.ref == 'refs/heads/master' - needs: ["get-changelog", "build-loaders", "build-shared"] + needs: ["get-changelog", "build-loaders-standalone", "build-loaders-launcher", "build-loaders-launcherex", "build-shared"] uses: BUTR/workflows/.github/workflows/release-nexusmods.yml@master with: nexusmods_game_id: mountandblade2bannerlord @@ -115,7 +161,7 @@ jobs: ########################### publish-on-github: if: github.ref == 'refs/heads/master' - needs: ["get-changelog", "build-loaders", "build-shared"] + needs: ["get-changelog", "build-loaders-standalone", "build-loaders-launcher", "build-loaders-launcherex", "build-shared"] uses: BUTR/workflows/.github/workflows/release-github.yml@master with: mod_id: Bannerlord.BLSE