diff --git a/build/common.props b/build/common.props index db8aef9..4b47fe7 100644 --- a/build/common.props +++ b/build/common.props @@ -11,7 +11,7 @@ - 1.4.10 + 1.4.11 2.2.2 3.0.0.137 5.0.209 diff --git a/changelog.txt b/changelog.txt index 1669728..6f6caf8 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,11 @@ --------------------------------------------------------------------------------------------------- +Version: 1.4.11 +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.1.6,v1.2.5 +* Localizations are now shown in LauncherEx +* Potential System.Memory load fix +--------------------------------------------------------------------------------------------------- Version: 1.4.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.1.6,v1.2.0,v1.2.1,v1.2.2,v1.2.3,v1.2.5 +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.1.6,v1.2.5 * Added Traditional Chinese --------------------------------------------------------------------------------------------------- Version: 1.4.9 diff --git a/src/Bannerlord.BLSE.Loaders.LauncherEx/Bannerlord.BLSE.Loaders.LauncherEx.csproj b/src/Bannerlord.BLSE.Loaders.LauncherEx/Bannerlord.BLSE.Loaders.LauncherEx.csproj index 717eead..73e65b2 100644 --- a/src/Bannerlord.BLSE.Loaders.LauncherEx/Bannerlord.BLSE.Loaders.LauncherEx.csproj +++ b/src/Bannerlord.BLSE.Loaders.LauncherEx/Bannerlord.BLSE.Loaders.LauncherEx.csproj @@ -54,6 +54,10 @@ + + + + @@ -81,4 +85,19 @@ + + + System.Drawing.Common.dll + + + System.Memory.dll + + + System.Buffers.dll + + + System.Runtime.CompilerServices.Unsafe.dll + + + diff --git a/src/Bannerlord.BLSE.Loaders.LauncherEx/ModuleInitializer.cs b/src/Bannerlord.BLSE.Loaders.LauncherEx/ModuleInitializer.cs new file mode 100644 index 0000000..04489dc --- /dev/null +++ b/src/Bannerlord.BLSE.Loaders.LauncherEx/ModuleInitializer.cs @@ -0,0 +1,56 @@ +using System; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Threading; + +internal static class ModuleInitializer +{ + private static int _isAttached; + + [ModuleInitializer] + internal static void Action() + { + if (Interlocked.Exchange(ref _isAttached, 1) == 1) + return; + AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly; + } + + private static Assembly? ResolveAssembly(object? sender, ResolveEventArgs e) + { + if (e.Name is null) + return null; + + var assemblyName = new AssemblyName(e.Name); + if (assemblyName.Name is "System.Drawing.Common") + return ResolveLauncherExAssemblies(assemblyName); + if (assemblyName.Name is "System.Memory") + return ResolveLauncherExAssemblies(assemblyName); + if (assemblyName.Name is "System.Buffers") + return ResolveLauncherExAssemblies(assemblyName); + if (assemblyName.Name is "System.Runtime.CompilerServices.Unsafe") + return ResolveLauncherExAssemblies(assemblyName); + + return null; + } + + private static Assembly? ResolveLauncherExAssemblies(AssemblyName assemblyName) + { + var name = assemblyName.Name; + + var @namespace = "Bannerlord.BLSE.Loaders.LauncherEx."; + var resources = typeof(ModuleInitializer).Assembly.GetManifestResourceNames().Select(x => x.Remove(0, @namespace.Length)); + var toLoad = resources.FirstOrDefault(x => x.StartsWith(name)); + if (toLoad is not null) + { + using var resourceStream = typeof(ModuleInitializer).Assembly.GetManifestResourceStream($"{@namespace}{toLoad}")!; + using var ms = new MemoryStream(); + resourceStream.CopyTo(ms); + return Assembly.Load(ms.ToArray()); + } + + return null; + } +} \ No newline at end of file diff --git a/src/Bannerlord.BLSE.Loaders.LauncherEx/ModuleInitializerAttribute.cs b/src/Bannerlord.BLSE.Loaders.LauncherEx/ModuleInitializerAttribute.cs new file mode 100644 index 0000000..3109aea --- /dev/null +++ b/src/Bannerlord.BLSE.Loaders.LauncherEx/ModuleInitializerAttribute.cs @@ -0,0 +1,5 @@ +// ReSharper disable once CheckNamespace +namespace System.Runtime.CompilerServices; + +[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] +public sealed class ModuleInitializerAttribute : Attribute { } \ No newline at end of file diff --git a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj index f9d0165..14be25b 100644 --- a/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj +++ b/src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj @@ -38,40 +38,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + @@ -93,7 +63,7 @@ - + @@ -114,4 +84,12 @@ + + + $(ILRepackExcludeAssemblies);$(ProjectDir)$(OutputPath)System.Drawing.dll; + $(ILRepackExcludeAssemblies);$(ProjectDir)$(OutputPath)System.Drawing.Common.dll; + $(ILRepackExcludeAssemblies);$(ProjectDir)$(OutputPath)System.Drawing.Primitives.dll; + + + \ No newline at end of file diff --git a/src/Bannerlord.LauncherEx/Helpers/ConfigReader.cs b/src/Bannerlord.LauncherEx/Helpers/ConfigReader.cs index 62f74c0..7af8d15 100644 --- a/src/Bannerlord.LauncherEx/Helpers/ConfigReader.cs +++ b/src/Bannerlord.LauncherEx/Helpers/ConfigReader.cs @@ -1,12 +1,16 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; namespace Bannerlord.LauncherEx.Helpers { internal static class ConfigReader { + private static readonly string BOMMarkUtf8 = + Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); + public static readonly string GameConfigPath = Path.Combine($@"{Environment.GetFolderPath(Environment.SpecialFolder.Personal)}", "Mount and Blade II Bannerlord", "Configs", "BannerlordConfig.txt"); public static readonly string EngineConfigPath = @@ -19,6 +23,9 @@ public static Dictionary GetGameOptions(Func re try { var content = Encoding.UTF8.GetString(data); + if (content.StartsWith(BOMMarkUtf8, StringComparison.Ordinal)) + content = content.Remove(0, BOMMarkUtf8.Length); + foreach (var keyValue in content.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)) { var split = keyValue.Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries); @@ -38,6 +45,9 @@ public static Dictionary GetEngineOptions(Func try { var content = Encoding.UTF8.GetString(data); + if (content.StartsWith(BOMMarkUtf8, StringComparison.Ordinal)) + content = content.Remove(0, BOMMarkUtf8.Length); + foreach (var keyValue in content.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)) { var split = keyValue.Split(new[] { "=" }, StringSplitOptions.RemoveEmptyEntries); diff --git a/src/Bannerlord.LauncherEx/Manager.cs b/src/Bannerlord.LauncherEx/Manager.cs index 387dcb0..2e0957b 100644 --- a/src/Bannerlord.LauncherEx/Manager.cs +++ b/src/Bannerlord.LauncherEx/Manager.cs @@ -11,6 +11,7 @@ using System; using System.IO; +using System.Linq; using System.Runtime.CompilerServices; using System.Xml; @@ -46,11 +47,8 @@ public static void Enable() ViewModelPatch.Enable(_launcherHarmony); WidgetPrefabPatch.Enable(_launcherHarmony); - BUTRLocalizationManager.LoadLanguage(Load("Bannerlord.LauncherEx.Resources.Localization.EN.strings.xml")); - BUTRLocalizationManager.LoadLanguage(Load("Bannerlord.LauncherEx.Resources.Localization.RU.strings.xml")); - BUTRLocalizationManager.LoadLanguage(Load("Bannerlord.LauncherEx.Resources.Localization.CNs.strings.xml")); - BUTRLocalizationManager.LoadLanguage(Load("Bannerlord.LauncherEx.Resources.Localization.TR.strings.xml")); - BUTRLocalizationManager.LoadLanguage(Load("Bannerlord.LauncherEx.Resources.Localization.BR.strings.xml")); + foreach (var language in typeof(Manager).Assembly.GetManifestResourceNames().Where(x => x.StartsWith("Bannerlord.LauncherEx.Resources.Localization") && x.EndsWith("strings.xml"))) + BUTRLocalizationManager.LoadLanguage(Load(language)); BUTRLocalizationManager.ActiveLanguage = GetActiveLanguage(); GraphicsContextManager.Enable(_launcherHarmony); diff --git a/src/Bannerlord.LauncherEx/Resources/Localization/CNs/strings.xml b/src/Bannerlord.LauncherEx/Resources/Localization/CNs/strings.xml index 1f92b57..863fcb5 100644 --- a/src/Bannerlord.LauncherEx/Resources/Localization/CNs/strings.xml +++ b/src/Bannerlord.LauncherEx/Resources/Localization/CNs/strings.xml @@ -14,7 +14,7 @@ - +