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

Commit

Permalink
Fixed crash at launch when an incompatible module is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Mar 17, 2022
1 parent 04dfd15 commit 2984f30
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!--Development Variables-->
<PropertyGroup>
<Version>1.7.3</Version>
<Version>1.7.4</Version>
<HarmonyVersion>2.0.4</HarmonyVersion>
<BUTRSharedVersion>2.0.0.78</BUTRSharedVersion>
<BUTRModuleManagerVersion>3.0.94</BUTRModuleManagerVersion>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 1.7.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
* Fixed crash at launch when an incompatible module is used
---------------------------------------------------------------------------------------------------
Version: 1.7.3
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
* Added option to disable binary compatibility check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@ internal static class InterceptorFeature
private delegate void OnInitializeSubModulesPrefixDelegate();
private delegate void OnLoadSubModulesPostfixDelegate();

private static IEnumerable<Type> GetInterceptorTypes() => AppDomain.CurrentDomain.GetAssemblies()
.Where(asm => !asm.IsDynamic && asm.CodeBase.Contains("Modules"))
.SelectMany(asm => asm.DefinedTypes.Where(type => type.GetCustomAttributes().Any(att =>
string.Equals(att.GetType().FullName, typeof(BUTRLoaderInterceptorAttribute).FullName, StringComparison.Ordinal))));
private static IEnumerable<Type> GetInterceptorTypes()
{
static bool CheckType(Type type) => type.GetCustomAttributes()
.Any(att => string.Equals(att.GetType().FullName, typeof(BUTRLoaderInterceptorAttribute).FullName, StringComparison.Ordinal));

foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().Where(asm => !asm.IsDynamic && asm.CodeBase.Contains("Modules")))
{
IEnumerable<Type> enumerable;
try
{
var types = assembly.GetTypes(); // Force type resolution
enumerable = types.Where(CheckType);
}
catch (ReflectionTypeLoadException)
{
enumerable = Enumerable.Empty<Type>(); // ignore the incompatibility, not our problem
}
foreach (var type in enumerable)
{
yield return type;
}
}
}

public static void Enable(Harmony harmony)
{
Expand Down

0 comments on commit 2984f30

Please sign in to comment.