/// <summary> /// Scans the mod to see if it has loaded the assembly in to app domain. /// </summary> /// /// <param name="mod">The <see cref="PluginInfo"/> to scan.</param> /// <param name="assemblyName">The name of the assembly to search for.</param> /// <param name="details">If found, the <see cref="ModAssembly"/> struct containing details.</param> /// /// <returns>Returns <c>true</c> if successful, otherwise <c>false</c>.</returns> private static bool TryGetLoadedAssembly(PluginInfo mod, string assemblyName, out ModAssembly details) { List <Assembly> assemblies = mod.GetAssemblies(); foreach (Assembly asm in assemblies) { if (asm.GetName().Name == assemblyName) { string hash = string.Empty; if (TryGetAssemblyPath(mod, assemblyName, out string fullPath)) { if (Md5.TryGetHash(fullPath, out string md5Hash)) { hash = md5Hash; } } details = new ModAssembly { ModPath = mod.modPath, ModName = GetName(mod), ModEnabled = mod.isEnabled, Folder = Path.GetFileName(mod.modPath), AsmDetails = asm.GetName(), AsmLoaded = true, AsmMD5Hash = hash, }; return(true); } } details = default; return(false); }
/// <summary> /// Scans the mod folder to see if contains an unloaded copy of the assembly. /// </summary> /// /// <param name="mod">The <see cref="PluginInfo"/> to scan.</param> /// <param name="assemblyName">The name of the assembly to search for.</param> /// <param name="details">If found, the <see cref="ModAssembly"/> struct containing details.</param> /// /// <returns>Returns <c>true</c> if successful, otherwise <c>false</c>.</returns> private static bool TryGetUnloadedAssembly(PluginInfo mod, string assemblyName, out ModAssembly details) { details = default; // we're only interested in Harmony for now... if (assemblyName != "0Harmony") { return(false); } if (TryGetAssemblyPath(mod, assemblyName, out string fullPath)) { details = new ModAssembly { ModPath = mod.modPath, ModName = GetName(mod), ModEnabled = mod.isEnabled, Folder = Path.GetFileName(mod.modPath), AsmLoaded = false, }; if (Md5.TryGetHash(fullPath, out string md5Hash)) { details.AsmMD5Hash = md5Hash; } if (Assemblies.TryGetAssemblyDetailsWithoutLoading(fullPath, out AssemblyName asmDetails)) { details.AsmDetails = asmDetails; } return(true); } return(false); }