From aae6dc5de31e404da942dde0e9de2974a35db515 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sat, 15 Apr 2023 20:59:39 +0300 Subject: [PATCH] Xbox version CTD fix --- build/common.props | 2 +- changelog.txt | 4 ++++ .../NETCoreLoader.Hosting.cs | 1 + src/Bannerlord.BLSE.Shared/ModuleInitializer.cs | 6 +++--- .../Utils/ReflectionParser.cs | 16 ++++++++++++++++ 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/Bannerlord.BLSE.Shared/Utils/ReflectionParser.cs diff --git a/build/common.props b/build/common.props index 3e04068..d7f4f87 100644 --- a/build/common.props +++ b/build/common.props @@ -10,7 +10,7 @@ - 1.3.2 + 1.3.3 2.2.2 3.0.0.136 5.0.198 diff --git a/changelog.txt b/changelog.txt index 4844431..e0f9da7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,8 @@ --------------------------------------------------------------------------------------------------- +Version: 1.3.3 +Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2 +* Xbox version CTD fix +--------------------------------------------------------------------------------------------------- Version: 1.3.2 Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2 * Added EnableDPIScaling setting to remove DPI scaling on high resolution diff --git a/src/Bannerlord.BLSE.Loaders.Standalone/NETCoreLoader.Hosting.cs b/src/Bannerlord.BLSE.Loaders.Standalone/NETCoreLoader.Hosting.cs index 5235c59..4506d15 100644 --- a/src/Bannerlord.BLSE.Loaders.Standalone/NETCoreLoader.Hosting.cs +++ b/src/Bannerlord.BLSE.Loaders.Standalone/NETCoreLoader.Hosting.cs @@ -40,6 +40,7 @@ public static void Launch(string[] args) // Catch AccessViolation. .NET Core 3.1 still allows that Environment.SetEnvironmentVariable("COMPlus_legacyCorruptedStateExceptionsPolicy", "1"); + // TODO: Remove once Lib.Harmony v2.3 is out // Disable aggressive inlining of JIT by disabling JIT Tiered Compilation Environment.SetEnvironmentVariable("COMPlus_TieredCompilation", "0"); diff --git a/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs b/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs index bb7179c..8c63817 100644 --- a/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs +++ b/src/Bannerlord.BLSE.Shared/ModuleInitializer.cs @@ -247,9 +247,9 @@ At least v2.2.2.x is required! var assemblyFile = ResolveHarmonyAssembliesFile(assemblyName); if (string.IsNullOrEmpty(assemblyFile)) return null; - - var harmony = Assembly.ReflectionOnlyLoadFrom(assemblyFile); - if (harmony.GetName().Version < new Version(2, 2, 2, 0)) + + + if (ReflectionParser.GetAssemblyVersion(assemblyFile) < new Version(2, 2, 2, 0)) { MessageBoxDialog.Show(@"The Harmony module is corrupted! Wrong 0Harmony.dll version! At least v2.2.2.x is required! diff --git a/src/Bannerlord.BLSE.Shared/Utils/ReflectionParser.cs b/src/Bannerlord.BLSE.Shared/Utils/ReflectionParser.cs new file mode 100644 index 0000000..df81f83 --- /dev/null +++ b/src/Bannerlord.BLSE.Shared/Utils/ReflectionParser.cs @@ -0,0 +1,16 @@ +using Mono.Cecil; + +using System; + +namespace Bannerlord.BLSE.Shared.Utils +{ + public static class ReflectionParser + { + public static Version GetAssemblyVersion(string? path) + { + if (path is null) return new Version(); + var assemblyDefinition = AssemblyDefinition.ReadAssembly(path); + return assemblyDefinition.Name.Version; + } + } +} \ No newline at end of file