// --- Separate methods (Main is too big anyways lol) private static void LoadPlugins() { XConsole.PrintInfo($"Now loading all custom add-ons from {Path.GetFileName(PluginsFolderLocation)}/ folder."); _loadedPlugins = new List <PluginInfo>(); if (Directory.Exists(PluginsFolderLocation)) { foreach (var file in Directory.GetFiles(PluginsFolderLocation, "*.dll")) { var fileName = Path.GetFileName(file); try { Assembly assembly = Assembly.LoadFile(file); if (assembly.EntryPoint != null) { XConsole.PrintError($"{fileName} is a .NET executable, not a class library!"); continue; } var types = assembly.GetTypes().Where(a => a.GetInterfaces().Contains(typeof(IOsuPatchPlugin))).ToList(); if (!types.Any()) { XConsole.PrintError($"{fileName} assembly does not contain a valid IOsuPatchPlugin class."); continue; } foreach (var type in types) { var plugin = (IOsuPatchPlugin)Activator.CreateInstance(type); plugin.Load(_obfOsuModule); XConsole.PrintInfo($"{fileName}: Loaded plugin: {type.Name}"); _loadedPlugins.Add(new PluginInfo(fileName, type.Name, plugin)); } } catch (BadImageFormatException) { XConsole.PrintError($"{fileName} is not a valid .NET assembly file!"); } catch (Exception ex) { XConsole.PrintError($"Unable to load {fileName}! Details:\n" + ex); } } } else { Directory.CreateDirectory(PluginsFolderLocation); } }
private static int Exit(string msg = "") => XConsole.PrintError(msg);