Skip to content

Commit

Permalink
Loose fix for embedded dependences
Browse files Browse the repository at this point in the history
  • Loading branch information
javisar committed Jan 26, 2019
1 parent 9886411 commit bc4700b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Binary file modified Managed/ModLoader.dll
Binary file not shown.
36 changes: 28 additions & 8 deletions Source/ModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,38 @@ private static List<Assembly> CheckForDependences(List<Assembly> modAssemblies)

try
{
ModLogger.WriteLine("Loading: " + modAssembly.FullName);

ModLogger.WriteLine("\tChecking " + modAssembly.FullName);
bool correct = true;
foreach (AssemblyName referenced in modAssembly.GetReferencedAssemblies())
{
ModLogger.WriteLine("\t" + referenced.FullName);
ModLogger.WriteLine("\t\t" + referenced.FullName);
try
{
Assembly dependence = Assembly.ReflectionOnlyLoad(referenced.FullName);
if (dependence == null)
{
correct = false;
ModLogger.Error.WriteLine("\tCannot find dependence: " + referenced.FullName);

continue;

}

}
catch (Exception ex)
{
correct = false;
ModLogger.Error.WriteLine("\tCannot find dependence: " + referenced.FullName);
ModLogger.Error.WriteLine(ex);
continue;
ModLogger.WriteLine("\t\t\tChecking embedded dependences:");
correct = CheckForEmbeddedDependence(referenced.Name, modAssembly);
if (!correct)
{
ModLogger.Error.WriteLine("\tCannot find dependence: " + referenced.FullName);
ModLogger.Error.WriteLine(ex);
continue;
}

}
}

if (correct)
{
loadableMods.Add(modAssembly);
Expand All @@ -127,6 +134,19 @@ private static List<Assembly> CheckForDependences(List<Assembly> modAssemblies)
return loadableMods;
}

private static bool CheckForEmbeddedDependence(string name, Assembly modAssembly)
{
// Load embedded resources to check inner dependences
string[] resources = modAssembly.GetManifestResourceNames();
foreach (string resource in resources)
{
ModLogger.WriteLine("\t\t\t" + resource);
if (resource.Contains(name))
return true;
}
return false;
}

private static List<Assembly> ApplyHarmonyPatches([NotNull] List<Assembly> modAssemblies)
{
ModLogger.WriteLine("Applying Harmony patches");
Expand Down

0 comments on commit bc4700b

Please sign in to comment.