Skip to content

Commit

Permalink
Merge pull request #66 from BUTR/dev
Browse files Browse the repository at this point in the history
v1.4.0
  • Loading branch information
Aragas committed Jul 5, 2023
2 parents aad0e49 + 4d75a08 commit eac352d
Show file tree
Hide file tree
Showing 33 changed files with 436 additions and 111 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
# NEXUSMODS #
###########################
publish-on-nexusmods:
if: false && github.ref == 'refs/heads/master'
if: github.ref == 'refs/heads/master'
needs: ["get-changelog", "build"]
uses: BUTR/workflows/.github/workflows/release-nexusmods.yml@master
with:
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
with:
name: bannerlord
path: ./artifact
- uses: game-ci/steam-deploy@v2
- uses: game-ci/steam-deploy@v3
with:
username: ${{ secrets.STEAM_USERNAME }}
password: ${{ secrets.STEAM_PASSWORD }}
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ Can opted-in by passing **/unblock** in command-line args.
* **Interceptor** - BLSE checks if the is a class with a custom attribute named ***BLSEInterceptorAttribute***. If it's found it checks if there are the following signatures:
* **static void OnInitializeSubModulesPrefix()** - will execute just before the game starts to initialize the SubModules. This gives us the ability to add SubModules declared in other programming languages like [Python](https://github.com/BUTR/Bannerlord.Python) and [Lua](https://github.com/BUTR/Bannerlord.Lua)
* **static void OnLoadSubModulesPostfix()** - will execute just after all SubModules were initialized

* **Exception Interceptor** - BLSE intercepts unhandled exceptions and patches all managed (C#) entrypoints that the native (C/C++) game code calls, thus ensuring that all exceptions are catched
* Can be opted-out with settings in LauncherEx or via command-line args **/enablecrashhandlerwhendebuggerisattached** to enable the interceptor when a debugger is attached or **/disableautogenexceptions** to disable the managed entrypoints patching

## LauncherEx
**LauncherEx** is the UI module. It expands the native launcher with the following features:
* **Option Tab** - provides Game and Engine options, plus the following Launcher options.
Expand Down
4 changes: 2 additions & 2 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

<!--Development Variables-->
<PropertyGroup>
<Version>1.3.10</Version>
<Version>1.4.0</Version>
<HarmonyVersion>2.2.2</HarmonyVersion>
<BUTRSharedVersion>3.0.0.136</BUTRSharedVersion>
<BUTRSharedVersion>3.0.0.137</BUTRSharedVersion>
<BUTRModuleManagerVersion>5.0.209</BUTRModuleManagerVersion>
<HarmonyExtensionsVersion>3.2.0.77</HarmonyExtensionsVersion>
<HarmonyAnalyzerVersion>1.0.1.50</HarmonyAnalyzerVersion>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 1.4.0
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0
* Added a global exception handler with integration support and settings
* Added a temporary Watchdog disabler for v1.2.0
---------------------------------------------------------------------------------------------------
Version: 1.3.10
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.2.0
* Fixed translation for loaded before-after messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
-->

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.188-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.229-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<Target Name="PublishOnBuild" AfterTargets="Build">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
-->

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.188-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.229-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<Target Name="PublishRoslynExecutableProjects" AfterTargets="Build">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
-->

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.188-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.229-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

<Target Name="PublishRoslynExecutableProjects" AfterTargets="Build">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void Launch(string[] args)
NtfsUnblocker.UnblockFile("Bannerlord.BLSE.Shared.dll");
var sharedAssembly = Assembly.LoadFrom("Bannerlord.BLSE.Shared.dll");
Trace.Assert(sharedAssembly is not null);
var sharedMainDelegate = (Main) Delegate.CreateDelegate(typeof(Main), sharedAssembly.GetType("Bannerlord.BLSE.Shared.Program"), "Main");
var sharedMainDelegate = (Main) Delegate.CreateDelegate(typeof(Main), sharedAssembly!.GetType("Bannerlord.BLSE.Shared.Program"), "Main");
sharedMainDelegate(args);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Bannerlord.BLSE.Shared/Bannerlord.BLSE.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core" Version="$(GameVersion).*-*" IncludeAssets="compile" PrivateAssets="all" />

<PackageReference Include="Bannerlord.BUTR.Shared" Version="$(BUTRSharedVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<!-- We need our own implementation of Bannerlord.ModuleManager.Source so won't load it from Bannerlord.LauncherEx that is dynamically resolved -->
<PackageReference Include="Bannerlord.ModuleManager.Source" PrivateAssets="all" Version="$(BUTRModuleManagerVersion)" />
<PackageReference Include="Harmony.Extensions" Version="$(HarmonyExtensionsVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="IsExternalInit" Version="1.0.3" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />

<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.188-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.229-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" IncludeAssets="compile" PrivateAssets="all" />
<PackageReference Include="System.Memory" Version="4.5.5" PrivateAssets="all" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Bannerlord.BLSE.Shared/Launcher.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Bannerlord.BLSE.Features.AssemblyResolver;
using Bannerlord.BLSE.Features.Commands;
using Bannerlord.BLSE.Features.ContinueSaveFile;
using Bannerlord.BLSE.Features.ExceptionInterceptor;
using Bannerlord.BLSE.Features.Interceptor;
using Bannerlord.BLSE.Features.Xbox;

Expand Down
34 changes: 34 additions & 0 deletions src/Bannerlord.BLSE.Shared/LauncherEx.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Bannerlord.BLSE.Features.AssemblyResolver;
using Bannerlord.BLSE.Features.Commands;
using Bannerlord.BLSE.Features.ContinueSaveFile;
using Bannerlord.BLSE.Features.ExceptionInterceptor;
using Bannerlord.BLSE.Features.Interceptor;
using Bannerlord.BLSE.Features.Xbox;
using Bannerlord.BLSE.Shared.NoExceptions;
using Bannerlord.BLSE.Shared.Utils;
using Bannerlord.LauncherEx;

using HarmonyLib;
using HarmonyLib.BUTR.Extensions;

using System;
using System.Linq;
Expand Down Expand Up @@ -37,6 +40,11 @@ public static void Launch(string[] args)
Manager.Enable();

ModuleInitializer.Disable();

_featureHarmony.TryPatch(
AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"),
prefix: AccessTools2.Method(typeof(LauncherEx), nameof(MainPrefix)));

if (args.Contains("/noexceptions"))
{
ProgramEx.Main(args);
Expand All @@ -46,4 +54,30 @@ public static void Launch(string[] args)
TaleWorlds.MountAndBlade.Launcher.Library.Program.Main(args);
}
}

private static void MainPrefix()
{
var disableCrashHandler = LauncherSettings.DisableCrashHandlerWhenDebuggerIsAttached && DebuggerUtils.IsDebuggerAttached();
if (!disableCrashHandler)
{
ExceptionInterceptorFeature.Enable();
}

if (!LauncherSettings.DisableCatchAutoGenExceptions)
{
ExceptionInterceptorFeature.EnableAutoGens();
}

if (!LauncherSettings.UseVanillaCrashHandler)
{
// TODO: Use the CLI when available
#if !DEBUG
// We do not copy System.Memory.dll and System.Runtime.CompilerServices.Unsafe.dll, which are required
// They are included in Release with ILMerge
WatchdogHandler.DisableTWWatchdog();
#endif
}

_featureHarmony.Unpatch(AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"), AccessTools2.Method(typeof(LauncherEx), nameof(MainPrefix)));
}
}
3 changes: 2 additions & 1 deletion src/Bannerlord.BLSE.Shared/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bannerlord.BLSE.Shared.Utils;

using Bannerlord.BLSE.Shared.Utils;
using Bannerlord.BUTR.Shared.Helpers;
using Bannerlord.ModuleManager;

Expand Down
5 changes: 4 additions & 1 deletion src/Bannerlord.BLSE.Shared/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ GetConsoleWindow
ShowWindow
SetProcessDPIAware
OpenProcessToken
GetTokenInformation
GetTokenInformation
NtQueryInformationProcess
LoadLibrary
VirtualProtect
8 changes: 8 additions & 0 deletions src/Bannerlord.BLSE.Shared/Standalone.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Bannerlord.BLSE.Features.AssemblyResolver;
using Bannerlord.BLSE.Features.Commands;
using Bannerlord.BLSE.Features.ContinueSaveFile;
using Bannerlord.BLSE.Features.ExceptionInterceptor;
using Bannerlord.BLSE.Features.Interceptor;
using Bannerlord.BLSE.Features.Xbox;
using Bannerlord.BLSE.Shared.Utils;
Expand Down Expand Up @@ -106,6 +107,13 @@ public static void Launch(string[] args)
CommandsFeature.Enable(_featureHarmony);
XboxFeature.Enable(_featureHarmony);

var disableCrashHandler = !args.Contains("/enablecrashhandlerwhendebuggerisattached") && DebuggerUtils.IsDebuggerAttached();
if (!disableCrashHandler)
ExceptionInterceptorFeature.Enable();

if (!args.Contains("/disableautogenexceptions"))
ExceptionInterceptorFeature.EnableAutoGens();

ModuleInitializer.Disable();
TaleWorlds.Starter.Library.Program.Main(args);
}
Expand Down
33 changes: 33 additions & 0 deletions src/Bannerlord.BLSE.Shared/Utils/DebuggerDetection/ProcessDebug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Diagnostics;

using Windows.Win32;
using Windows.Win32.System.Threading;

namespace Bannerlord.BLSE.Shared.Utils.DebuggerDetection
{
internal static class ProcessDebug
{
private const PROCESSINFOCLASS PROCESS_DEBUG_OBJECT_HANDLE = (PROCESSINFOCLASS) 30;

/// <summary>
/// Starting with Windows XP, a "debug object" is created for a debugged process.
/// Here's an example of checking for a "debug object" in the current process:
/// If a debug object exists, then the process is being debugged.
/// It was originally published on https://www.apriorit.com/
/// </summary>
public static unsafe bool CheckProcessDebugObjectHandle()
{
void* processInformation = null;
uint returnLength = 0;
var status = PInvoke.NtQueryInformationProcess
(
Process.GetCurrentProcess().SafeHandle,
PROCESS_DEBUG_OBJECT_HANDLE,
processInformation,
(uint) sizeof(nint),
ref returnLength
);
return status == 0 && processInformation != null;
}
}
}
2 changes: 2 additions & 0 deletions src/Bannerlord.BLSE.Shared/Utils/DebuggerDetection/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Source code taken from https://github.com/MrakDev/Anti-Debug-Collection
Additional reference: https://www.apriorit.com/dev-blog/367-anti-reverse-engineering-protection-techniques-to-use-before-releasing-software
21 changes: 21 additions & 0 deletions src/Bannerlord.BLSE.Shared/Utils/DebuggerUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Bannerlord.BLSE.Shared.Utils.DebuggerDetection;

using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Bannerlord.BLSE.Shared.Utils
{
public static class DebuggerUtils
{
public static bool IsDebuggerAttached()
{
if (Debugger.IsAttached)
return true;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
return ProcessDebug.CheckProcessDebugObjectHandle();

return false;
}
}
}
12 changes: 8 additions & 4 deletions src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.IO;
using System.Reflection;

#if SHARED
using Bannerlord.ModuleManager;
#endif

namespace Bannerlord.BLSE.Shared.Utils;

public enum HarmonyDiscoveryResult
Expand Down Expand Up @@ -35,11 +39,11 @@ private static HarmonyDiscoveryResult TryResolveHarmonyAssembliesFile(AssemblyNa

var doc = new System.Xml.XmlDocument();
doc.Load(File.Exists(harmonySubModule) ? harmonySubModule : string.Empty);
var harmonyModuleInfo = ModuleManager.ModuleInfoExtended.FromXml(doc);
var harmonyModuleInfo = ModuleInfoExtended.FromXml(doc);

Check warning on line 42 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ModuleInfoExtended' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs' conflicts with the imported type 'ModuleInfoExtended' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs'.

Check warning on line 42 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ModuleInfoExtended' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs' conflicts with the imported type 'ModuleInfoExtended' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs'.
if (harmonyModuleInfo is null)
return HarmonyDiscoveryResult.ModuleSubModuleCorrupted;

if (new ModuleManager.ApplicationVersionComparer().Compare(harmonyModuleInfo.Version, new ModuleManager.ApplicationVersion(ModuleManager.ApplicationVersionType.Release, 2, 2, 2, 0)) < 0)
if (new ApplicationVersionComparer().Compare(harmonyModuleInfo.Version, new ApplicationVersion(ApplicationVersionType.Release, 2, 2, 2, 0)) < 0)

Check warning on line 46 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ApplicationVersionComparer' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs' conflicts with the imported type 'ApplicationVersionComparer' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs'.

Check warning on line 46 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ApplicationVersion' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs' conflicts with the imported type 'ApplicationVersion' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs'.

Check warning on line 46 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ApplicationVersionType' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs' conflicts with the imported type 'ApplicationVersionType' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs'.

Check warning on line 46 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ApplicationVersionComparer' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs' conflicts with the imported type 'ApplicationVersionComparer' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs'.

Check warning on line 46 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ApplicationVersion' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs' conflicts with the imported type 'ApplicationVersion' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs'.

Check warning on line 46 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ApplicationVersionType' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs' conflicts with the imported type 'ApplicationVersionType' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs'.
return HarmonyDiscoveryResult.ModuleVersionWrong;
#endif

Expand Down Expand Up @@ -73,11 +77,11 @@ private static HarmonyDiscoveryResult TryResolveHarmonyAssembliesFileFromSteam(A

var doc = new System.Xml.XmlDocument();
doc.Load(File.Exists(harmonySteamSubModule) ? harmonySteamSubModule : string.Empty);
var harmonyModuleInfo = ModuleManager.ModuleInfoExtended.FromXml(doc);
var harmonyModuleInfo = ModuleInfoExtended.FromXml(doc);

Check warning on line 80 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ModuleInfoExtended' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs' conflicts with the imported type 'ModuleInfoExtended' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs'.

Check warning on line 80 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ModuleInfoExtended' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs' conflicts with the imported type 'ModuleInfoExtended' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ModuleInfoExtended.cs'.
if (harmonyModuleInfo is null)
return HarmonyDiscoveryResult.ModuleSubModuleCorrupted;

if (new ModuleManager.ApplicationVersionComparer().Compare(harmonyModuleInfo.Version, new ModuleManager.ApplicationVersion(ModuleManager.ApplicationVersionType.Release, 2, 10, 0, 0)) < 0)
if (new ApplicationVersionComparer().Compare(harmonyModuleInfo.Version, new ApplicationVersion(ApplicationVersionType.Release, 2, 10, 0, 0)) < 0)

Check warning on line 84 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ApplicationVersionComparer' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs' conflicts with the imported type 'ApplicationVersionComparer' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs'.

Check warning on line 84 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ApplicationVersion' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs' conflicts with the imported type 'ApplicationVersion' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs'.

Check warning on line 84 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Win64_Shipping_Client)

The type 'ApplicationVersionType' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs' conflicts with the imported type 'ApplicationVersionType' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs'.

Check warning on line 84 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ApplicationVersionComparer' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs' conflicts with the imported type 'ApplicationVersionComparer' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionComparer.cs'.

Check warning on line 84 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ApplicationVersion' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs' conflicts with the imported type 'ApplicationVersion' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersion.cs'.

Check warning on line 84 in src/Bannerlord.BLSE.Shared/Utils/HarmonyFinder.cs

View workflow job for this annotation

GitHub Actions / Build Bannerlord.BLSE.Shared (Gaming.Desktop.x64_Shipping_Client)

The type 'ApplicationVersionType' in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs' conflicts with the imported type 'ApplicationVersionType' in 'Bannerlord.LauncherManager, Version=1.0.77.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '/home/runner/.nuget/packages/bannerlord.modulemanager.source/5.0.209/contentFiles/cs/netstandard2.0/Bannerlord.ModuleManager/ApplicationVersionType.cs'.
return HarmonyDiscoveryResult.ModuleVersionWrong;
#endif

Expand Down
36 changes: 20 additions & 16 deletions src/Bannerlord.BLSE.Shared/Utils/LauncherExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using HarmonyLib;
using Bannerlord.BLSE.Features.ExceptionInterceptor;

using HarmonyLib;
using HarmonyLib.BUTR.Extensions;

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Text;

namespace Bannerlord.BLSE.Shared.Utils;
Expand All @@ -15,28 +15,21 @@ internal static class LauncherExceptionHandler
{
private static readonly Harmony _harmony = new("Bannerlord.BLSE.Shared.Patches.LauncherExceptionHandler");


public static void Watch()
{
var asm = Assembly.LoadFrom("TaleWorlds.Starter.Library.dll");
Trace.Assert(asm is not null);

_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;
prefix: AccessTools2.DeclaredMethod(typeof(LauncherExceptionHandler), nameof(MainPrefix)));

_harmony.Unpatch(AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"), AccessTools2.Method(typeof(Unblocker), nameof(MainPrefix)));
// If ButterLib/BEW is not available or the stage is too early, use our built-in just in case
ExceptionInterceptorFeature.Enable();
ExceptionInterceptorFeature.OnException += ExceptionInterceptorFeatureOnException;
}

[HandleProcessCorruptedStateExceptions, SecurityCritical]
private static void CurrentDomainOnUnhandledException(object? _, UnhandledExceptionEventArgs e)
private static void ExceptionInterceptorFeatureOnException(Exception exception)
{
static string GetRecursiveException(Exception ex) => new StringBuilder()
.AppendLine()
Expand All @@ -52,6 +45,17 @@ private static void CurrentDomainOnUnhandledException(object? _, UnhandledExcept
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())}");
{GetRecursiveException(exception)}");
}

private static void MainPrefix()
{
// After launch we rely on ButterLib/BEW being available
ExceptionInterceptorFeature.OnException -= ExceptionInterceptorFeatureOnException;
ExceptionInterceptorFeature.Disable();

_harmony.Unpatch(
AccessTools2.DeclaredMethod("TaleWorlds.Starter.Library.Program:Main"),
AccessTools2.DeclaredMethod(typeof(LauncherExceptionHandler), nameof(MainPrefix)));
}
}
Loading

0 comments on commit eac352d

Please sign in to comment.