public void Dispose() { if (plugin != null) { try { plugin.Dispose(); plugin = null; inputPlugin = null; } catch (Exception e) { data.Status = PluginStatus.Error; LogFile.WriteLine($"Failed to dispose {data} because of an error: {e}"); } } }
public Main() { Log("Loading PluginLoader and dependencies..."); try { string dir = GetAssemblyDirectory(); harmony = Assembly.LoadFile(Path.Combine(dir, "0Harmony")); AppDomain.CurrentDomain.AssemblyResolve += ResolveHarmony; Assembly pluginLoaderAssembly = Assembly.LoadFile(Path.Combine(dir, "PluginLoader")); Type pluginType = typeof(IPlugin); Type pluginLoaderMain = pluginLoaderAssembly.GetTypes().Where(t => pluginType.IsAssignableFrom(t) && t.Name.Contains("Main")).FirstOrDefault(); if (pluginLoaderMain != null) { pluginLoader = (IHandleInputPlugin)Activator.CreateInstance(pluginLoaderMain); Log($"PluginLoader started."); } else { Log("Failed to find PluginLoader!"); } } catch (ReflectionTypeLoadException re) { Log("Error: " + re); foreach (Exception e in re.LoaderExceptions) { Log(e.ToString()); } MessageBox.Show(GetMainForm(), "Plugin Loader crashed! Check game log for more info."); CloseCustomSplashScreen(); } catch (Exception e) { Log("Error: " + e); MessageBox.Show(GetMainForm(), "Plugin Loader crashed: " + e); CloseCustomSplashScreen(); } }
public bool Instantiate() { try { plugin = (IPlugin)Activator.CreateInstance(mainType); inputPlugin = plugin as IHandleInputPlugin; } catch (Exception e) { ThrowError($"Failed to instantiate {data} because of an error: {e}"); return(false); } try { openConfigDialog = AccessTools.DeclaredMethod(mainType, "OpenConfigDialog", Array.Empty <Type>()); } catch (Exception e) { LogFile.WriteLine($"Unable to find OpenConfigDialog() in {data} due to an error: {e}"); openConfigDialog = null; } return(true); }