Skip to content

Commit

Permalink
Merge pull request #87 from BUTR/dev
Browse files Browse the repository at this point in the history
v1.4.11
  • Loading branch information
Aragas authored Nov 26, 2023
2 parents c426181 + 9813351 commit 1902e3c
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 43 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!--Development Variables-->
<PropertyGroup>
<Version>1.4.10</Version>
<Version>1.4.11</Version>
<HarmonyVersion>2.2.2</HarmonyVersion>
<BUTRSharedVersion>3.0.0.137</BUTRSharedVersion>
<BUTRModuleManagerVersion>5.0.209</BUTRModuleManagerVersion>
Expand Down
7 changes: 6 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.229-beta" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="System.Buffers" Version="4.5.1" GeneratePathProperty="true" PrivateAssets="all" IncludeAssets="none" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" GeneratePathProperty="true" PrivateAssets="all" IncludeAssets="none" />
<PackageReference Include="System.Memory" Version="4.5.5" GeneratePathProperty="true" PrivateAssets="all" IncludeAssets="none" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" GeneratePathProperty="true" PrivateAssets="all" IncludeAssets="none" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -81,4 +85,19 @@
<ProjectReference Include="..\Bannerlord.BLSE.Shared\Bannerlord.BLSE.Shared.csproj" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="$(PkgSystem_Drawing_Common)\lib\net461\System.Drawing.Common.dll" Visible="false">
<Link>System.Drawing.Common.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgSystem_Memory)\lib\net461\System.Memory.dll" Visible="false">
<Link>System.Memory.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgSystem_Buffers)\lib\net461\System.Buffers.dll" Visible="false">
<Link>System.Buffers.dll</Link>
</EmbeddedResource>
<EmbeddedResource Include="$(PkgSystem_Runtime_CompilerServices_Unsafe)\lib\net461\System.Runtime.CompilerServices.Unsafe.dll" Visible="false">
<Link>System.Runtime.CompilerServices.Unsafe.dll</Link>
</EmbeddedResource>
</ItemGroup>

</Project>
56 changes: 56 additions & 0 deletions src/Bannerlord.BLSE.Loaders.LauncherEx/ModuleInitializer.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ReSharper disable once CheckNamespace
namespace System.Runtime.CompilerServices;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ModuleInitializerAttribute : Attribute { }
48 changes: 13 additions & 35 deletions src/Bannerlord.LauncherEx/Bannerlord.LauncherEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,10 @@
</PropertyGroup>

<ItemGroup>
<EmbeddedResource Include="Resources\Brushes\Launcher.xml" />
<EmbeddedResource Include="Resources\Prefabs\Launcher.MessageBox.xml" />
<EmbeddedResource Include="Resources\Prefabs\Launcher.Options.OptionTuple.xml" />
<EmbeddedResource Include="Resources\Prefabs\Widgets\Launcher.Scrollbar.xml" />
<EmbeddedResource Include="Resources\Prefabs\Widgets\Launcher.SearchBox.xml" />

<EmbeddedResource Include="Resources\Prefabs\Widgets\Launcher.ToggleButton.xml" />

<EmbeddedResource Include="Resources\Prefabs\Properties\Launcher.SettingsPropertyBoolView.xml" />
<EmbeddedResource Include="Resources\Prefabs\Properties\Launcher.SettingsPropertyButtonView.xml" />
<EmbeddedResource Include="Resources\Prefabs\Properties\Launcher.SettingsPropertyFloatView.xml" />
<EmbeddedResource Include="Resources\Prefabs\Properties\Launcher.SettingsPropertyIntView.xml" />
<EmbeddedResource Include="Resources\Prefabs\Properties\Launcher.SettingsPropertyStringView.xml" />

<EmbeddedResource Include="Resources\Prefabs\Launcher.Saves.SaveTuple.xml" />
<EmbeddedResource Include="Resources\Prefabs\Launcher.Saves.xml" />
<EmbeddedResource Include="Resources\Prefabs\Launcher.Mods.ModuleTuple.xml" />
<EmbeddedResource Include="Resources\Prefabs\Launcher.Mods.xml" />
<EmbeddedResource Include="Resources\Prefabs\Launcher.Options.xml" />

<EmbeddedResource Include="Resources\Textures\arrow_down.png" />
<EmbeddedResource Include="Resources\Textures\arrow_left.png" />
<EmbeddedResource Include="Resources\Textures\export.png" />
<EmbeddedResource Include="Resources\Textures\import.png" />
<EmbeddedResource Include="Resources\Textures\refresh.png" />
<EmbeddedResource Include="Resources\Textures\warm_overlay.png" />
<EmbeddedResource Include="Resources\Textures\folder.png" />
<EmbeddedResource Include="Resources\Textures\search.png" />

<EmbeddedResource Include="Resources\Localization\EN\strings.xml" />
<EmbeddedResource Include="Resources\Localization\RU\strings.xml" />
<EmbeddedResource Include="Resources\Localization\CNs\strings.xml" />
<EmbeddedResource Include="Resources\Localization\TR\strings.xml" />
<EmbeddedResource Include="Resources\Localization\BR\strings.xml" />
<EmbeddedResource Include="Resources\Brushes\**\*.xml" />
<EmbeddedResource Include="Resources\Prefabs\**\*.xml" />
<EmbeddedResource Include="Resources\Textures\*.png" />
<EmbeddedResource Include="Resources\Localization\*\strings.xml" />
</ItemGroup>

<ItemGroup>
Expand All @@ -93,7 +63,7 @@
<PackageReference Include="Mono.Cecil" Version="0.11.5" IncludeAssets="compile" />
<PackageReference Include="PolySharp" Version="1.13.2" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="StbSharp" Version="0.7.2.38" PrivateAssets="all" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Drawing.Common" Version="6.0.0" />
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

Expand All @@ -114,4 +84,12 @@
<CallTarget Targets="Build" />
</Target>

<Target Name="ExcludeAssembliesFromILRepack" BeforeTargets="ILRepackPrepare">
<PropertyGroup>
<ILRepackExcludeAssemblies>$(ILRepackExcludeAssemblies);$(ProjectDir)$(OutputPath)System.Drawing.dll;</ILRepackExcludeAssemblies>
<ILRepackExcludeAssemblies>$(ILRepackExcludeAssemblies);$(ProjectDir)$(OutputPath)System.Drawing.Common.dll;</ILRepackExcludeAssemblies>
<ILRepackExcludeAssemblies>$(ILRepackExcludeAssemblies);$(ProjectDir)$(OutputPath)System.Drawing.Primitives.dll;</ILRepackExcludeAssemblies>
</PropertyGroup>
</Target>

</Project>
10 changes: 10 additions & 0 deletions src/Bannerlord.LauncherEx/Helpers/ConfigReader.cs
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -19,6 +23,9 @@ public static Dictionary<string, string> GetGameOptions(Func<string, byte[]?> 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);
Expand All @@ -38,6 +45,9 @@ public static Dictionary<string, string> GetEngineOptions(Func<string, byte[]?>
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);
Expand Down
8 changes: 3 additions & 5 deletions src/Bannerlord.LauncherEx/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using System;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string id="LXlsSS8t" text="修复常见问题"/>
<string id="J9VbkLW4" text="修复常见问题,例如 0Harmony.dll 加载于 游戏目录/bin"/>
<string id="vUAqDj9H" text="紧凑模组列表"/>
<string id="Qn1aPNQM" text="缩小Mods列表"/>
<string id="Qn1aPNQM" text="使得各个 Mod 栏(框)更小更紧凑"/>
<string id="GUWbD65T" text="禁用二进制兼容检测"/>
<string id="lmpQeQBS" text="禁用启动器检测Mods的二进制兼容性"/>
<string id="iD27wEq7" text="隐藏骑手图像"/>
Expand Down

0 comments on commit 1902e3c

Please sign in to comment.