Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Fixed some crash scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Jul 29, 2022
1 parent d162d6d commit b101d22
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 39 deletions.
4 changes: 2 additions & 2 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!--Development Variables-->
<PropertyGroup>
<Version>1.8.4</Version>
<Version>1.8.5</Version>
<HarmonyVersion>2.0.4</HarmonyVersion>
<BUTRSharedVersion>2.0.0.86</BUTRSharedVersion>
<BUTRModuleManagerVersion>4.0.118</BUTRModuleManagerVersion>
Expand Down Expand Up @@ -66,4 +66,4 @@
</ItemGroup>


</Project>
</Project>
6 changes: 5 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 1.8.5
Game Versions: e1.5.0,e1.5.1,e1.5.2,e1.5.3,e1.5.4,e1.5.5,e1.5.6,e1.5.7,e1.5.8,e1.5.9,e1.5.10,e1.6.0,e1.6.1,e1.6.2,e1.6.3,e1.6.4,e1.6.5,e1.7.0,e1.7.1,e1.7.2,e1.8.0
* Fixed some crash scenarios
---------------------------------------------------------------------------------------------------
Version: 1.8.4
Game Versions: e1.5.0,e1.5.1,e1.5.2,e1.5.3,e1.5.4,e1.5.5,e1.5.6,e1.5.7,e1.5.8,e1.5.9,e1.5.10,e1.6.0,e1.6.1,e1.6.2,e1.6.3,e1.6.4,e1.6.5,e1.7.0,e1.7.1,e1.7.2,e1.8.0
* Release fix
Expand Down Expand Up @@ -201,4 +205,4 @@ Version: 1.0.0
Game Versions: e1.5.0,e1.5.1,e1.5.2,e1.5.3,e1.5.4,e1.5.5,e1.5.6
* Initial release. For any game version.
* Will replace Fixed Launcher if installed!
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
57 changes: 33 additions & 24 deletions src/Bannerlord.BUTRLoader.LauncherEx/Patches/AssemblyLoaderPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,61 @@ public static bool Enable(Harmony harmony)
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool LoadFromPrefix(ref Assembly? __result, string assemblyFile)
{
if (assemblyFile.Contains("Modules"))
try
{
var module = ModuleInfoHelper.GetModuleByType(new TypeWrapper(Path.GetFullPath(assemblyFile)));
if (module is not null)
if (assemblyFile.Contains("Modules"))
{
var filename = Path.GetFileName(assemblyFile);
var subModule = module.SubModules.FirstOrDefault(sm => sm.DLLName == filename);
if (subModule is not null)
var module = ModuleInfoHelper.GetModuleByType(new TypeWrapper(Path.GetFullPath(assemblyFile)));
if (module is not null)
{
if (subModule.Tags.TryGetValue("LoadReferencesOnLoad", out var list) && string.Equals(list.FirstOrDefault(), "false", StringComparison.OrdinalIgnoreCase))
var filename = Path.GetFileName(assemblyFile);
var subModule = module.SubModules.FirstOrDefault(sm => sm.DLLName == filename);
if (subModule is not null)
{
try
if (subModule.Tags.TryGetValue("LoadReferencesOnLoad", out var list) && string.Equals(list.FirstOrDefault(), "false", StringComparison.OrdinalIgnoreCase))
{
__result = Assembly.LoadFrom(assemblyFile);
try
{
__result = Assembly.LoadFrom(assemblyFile);
}
catch (Exception)
{
__result = null;
}
return false;
}
catch (Exception)
{
__result = null;
}
return false;
}
}

}
}
}
catch (Exception) { }

return true;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool OnAssemblyResolvePrefix(ref Assembly? __result, object sender, ResolveEventArgs args)
{
if (sender is AppDomain { FriendlyName: "Compatibility Checker" } domain)
try
{
foreach (var assembly in domain.GetAssemblies())
if (sender is AppDomain { FriendlyName: "Compatibility Checker" } domain)
{
if (assembly.FullName == args.Name)
foreach (var assembly in domain.GetAssemblies())
{
__result = assembly;
return false;
if (assembly.FullName == args.Name)
{
__result = assembly;
return false;
}
}
}

var name = args.Name.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
__result = Assembly.LoadFrom(name[0]);
return false;
var name = args.Name.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
__result = Assembly.LoadFrom(name[0]);
return false;
}
}
catch (Exception) { }

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using HarmonyLib.BUTR.Extensions;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -32,19 +31,30 @@ public static bool Enable(Harmony harmony)
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool OnAssemblyResolvePrefix(ref Assembly? __result, ResolveEventArgs args)
{
var basePath = Utilities.GetBasePath();
var configName = Common.ConfigName;
var modulePath = Path.GetFullPath(Path.Combine(basePath, "Modules"));

var name = args.Name.Contains(',') ? $"{args.Name.Split(',')[0]}.dll" : args.Name;

var assemblies = ModuleInfoHelper.GetLoadedModules().Select(x => Directory.GetFiles(Path.Combine(modulePath, x.Id, "bin", configName), "*.dll")).ToArray();
var assembly = assemblies.SelectMany(x => x).FirstOrDefault(x => x.Contains(name));
if (assembly is not null)
try
{
__result = Assembly.LoadFrom(assembly);
return false;
var basePath = Utilities.GetBasePath();
var configName = Common.ConfigName;
var modulePath = Path.GetFullPath(Path.Combine(basePath, "Modules"));

var name = args.Name.Contains(',') ? $"{args.Name.Split(',')[0]}.dll" : args.Name;

var assemblies = ModuleInfoHelper.GetLoadedModules()
.Select(x => Path.Combine(modulePath, x.Id, "bin", configName))
.Where(Directory.Exists)
.Select(x => Directory.GetFiles(x, "*.dll")).ToArray();

var assembly = assemblies
.SelectMany(x => x)
.FirstOrDefault(x => x.Contains(name));

if (assembly is not null)
{
__result = Assembly.LoadFrom(assembly);
return false;
}
}
catch (Exception) { }

return true;
}
Expand Down

0 comments on commit b101d22

Please sign in to comment.