diff --git a/BaseHandlers/BasePlugin.cs b/BaseHandlers/BasePlugin.cs index f8536b7..95841d1 100644 --- a/BaseHandlers/BasePlugin.cs +++ b/BaseHandlers/BasePlugin.cs @@ -3,9 +3,12 @@ namespace BaseHandlers { - public class BasePlugin : Plugin + public class BasePlugin : IPlugin { - public override void Init() + public string Id => "baseplugin"; + public string Name => "Base Resource Handlers"; + + public static void Init() { EntryTypeRegistry.Register(EntryType.Renderable, new Renderable()); EntryTypeRegistry.Register(EntryType.EntryList, new IDList()); @@ -18,15 +21,5 @@ public override void Init() EntryTypeRegistry.Register(EntryType.StreetData, new StreetData()); EntryTypeRegistry.Register(EntryType.FlaptFile, new FlaptFile()); } - - public override string GetID() - { - return "baseplugin"; - } - - public override string GetName() - { - return "Base Resource Handlers"; - } } } diff --git a/BundleManager/BundleManager.csproj b/BundleManager/BundleManager.csproj index 0e57966..886bf75 100644 --- a/BundleManager/BundleManager.csproj +++ b/BundleManager/BundleManager.csproj @@ -12,8 +12,6 @@ - - @@ -21,29 +19,16 @@ + - - - - - - - - - - plugins\%(FileName)%(Extension) - Include - false - - false diff --git a/BundleManager/Program.cs b/BundleManager/Program.cs index 3e2b4b8..d1f38ff 100644 --- a/BundleManager/Program.cs +++ b/BundleManager/Program.cs @@ -34,7 +34,7 @@ public static void Main(string[] args) Application.SetHighDpiMode(HighDpiMode.PerMonitorV2); Application.SetCompatibleTextRenderingDefault(false); - PluginLoader.LoadPlugins(); + PluginLoader.InitializePlugins(); fileModeForm = new MainForm(); folderModeForm = new FileView(); diff --git a/LangEditor/LangPlugin.cs b/LangEditor/LangPlugin.cs index e4ed3da..8ccb527 100644 --- a/LangEditor/LangPlugin.cs +++ b/LangEditor/LangPlugin.cs @@ -3,21 +3,14 @@ namespace LangEditor { - public class LangPlugin : Plugin + public class LangPlugin : IPlugin { - public override void Init() - { - EntryTypeRegistry.Register(EntryType.Language, new Language()); - } + public string Id => "langplugin"; + public string Name => "Language Resource Handler"; - public override string GetID() + public static void Init() { - return "langplugin"; - } - - public override string GetName() - { - return "Language Resource Handler"; + EntryTypeRegistry.Register(EntryType.Language, new Language()); } } } diff --git a/LoopModel/LoopModelPlugin.cs b/LoopModel/LoopModelPlugin.cs index 569e1a0..72d150b 100644 --- a/LoopModel/LoopModelPlugin.cs +++ b/LoopModel/LoopModelPlugin.cs @@ -3,21 +3,14 @@ namespace LoopModel { - public class LoopModelPlugin : Plugin + public class LoopModelPlugin : IPlugin { - public override void Init() - { - EntryTypeRegistry.Register(EntryType.LoopModel, new LoopModelData()); - } + public string Id => "loopmodelplugin"; + public string Name => "LoopModel Resource Handler"; - public override string GetID() + public static void Init() { - return "loopmodelplugin"; - } - - public override string GetName() - { - return "LoopModel Resource Handler"; + EntryTypeRegistry.Register(EntryType.LoopModel, new LoopModelData()); } } } diff --git a/LuaList/LuaListPlugin.cs b/LuaList/LuaListPlugin.cs index 8ef9667..7dae64a 100644 --- a/LuaList/LuaListPlugin.cs +++ b/LuaList/LuaListPlugin.cs @@ -4,22 +4,14 @@ namespace LuaList { - public class LuaListPlugin : Plugin + public class LuaListPlugin : IPlugin { - public override void Init() + public string Id => "lualistplugin"; + public string Name => "Lua List Resource Handler"; + + public static void Init() { EntryTypeRegistry.Register(EntryType.LUAList, new LuaList()); } - - public override string GetID() - { - return "lualistplugin"; - } - - public override string GetName() - { - return "Lua List Resource Handler"; - } - } } diff --git a/ModelViewer/SceneRenderControl.Designer.cs b/ModelViewer/SceneRenderControl.Designer.cs index adc2afc..4e7054e 100644 --- a/ModelViewer/SceneRenderControl.Designer.cs +++ b/ModelViewer/SceneRenderControl.Designer.cs @@ -1,6 +1,3 @@ -using OpenTK; -using OpenTK.GLControl; - namespace ModelViewer { partial class SceneRenderControl @@ -31,38 +28,26 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.glcMain = new GLControl(); - this.tmrUpdate = new System.Windows.Forms.Timer(this.components); - this.SuspendLayout(); - // - // glcMain - // - this.glcMain.BackColor = System.Drawing.Color.Black; - this.glcMain.Dock = System.Windows.Forms.DockStyle.Fill; - this.glcMain.Location = new System.Drawing.Point(0, 0); - this.glcMain.Name = "glcMain"; - this.glcMain.Size = new System.Drawing.Size(150, 150); - this.glcMain.TabIndex = 1; - this.glcMain.Paint += new System.Windows.Forms.PaintEventHandler(this.glcMain_Paint); + components = new System.ComponentModel.Container(); + tmrUpdate = new System.Windows.Forms.Timer(this.components); + SuspendLayout(); // // tmrUpdate // - this.tmrUpdate.Interval = 17; - this.tmrUpdate.Tick += new System.EventHandler(this.tmrUpdate_Tick); + tmrUpdate.Interval = 17; + tmrUpdate.Tick += new System.EventHandler(this.tmrUpdate_Tick); // // SceneRenderControl // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.glcMain); - this.Name = "SceneRenderControl"; - this.ResumeLayout(false); + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + Name = "SceneRenderControl"; + Size = new System.Drawing.Size(175, 173); + ResumeLayout(false); } #endregion - - private GLControl glcMain; private System.Windows.Forms.Timer tmrUpdate; } } diff --git a/ModelViewer/SceneRenderControl.cs b/ModelViewer/SceneRenderControl.cs index ee55d2d..18d2ead 100644 --- a/ModelViewer/SceneRenderControl.cs +++ b/ModelViewer/SceneRenderControl.cs @@ -1,12 +1,15 @@ using System; using System.ComponentModel; +using System.Drawing; using System.Windows.Forms; using ModelViewer.SceneData; +using OpenTK.GLControl; namespace ModelViewer { public partial class SceneRenderControl : UserControl { + private GLControl glcMain; private GraphicsScene _graphicsScene; [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] @@ -23,12 +26,27 @@ public Scene Scene public SceneRenderControl() { InitializeComponent(); - _designMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime; - + if (!_designMode) + SetupGLControl(); _sceneChanged = true; } + private void SetupGLControl() + { + glcMain = new() + { + BackColor = Color.Black, + Dock = DockStyle.Fill, + Location = new Point(0, 0), + Name = "glcMain", + Size = new Size(150, 150), + TabIndex = 1 + }; + glcMain.Paint += new PaintEventHandler(this.glcMain_Paint); + Controls.Add(glcMain); + } + protected override void OnResize(EventArgs e) { base.OnResize(e); diff --git a/PVSFormat/PVSPlugin.cs b/PVSFormat/PVSPlugin.cs index 069575e..0ccae64 100644 --- a/PVSFormat/PVSPlugin.cs +++ b/PVSFormat/PVSPlugin.cs @@ -3,21 +3,14 @@ namespace PVSFormat { - public class PVSPlugin : Plugin + public class PVSPlugin : IPlugin { - public override void Init() - { - EntryTypeRegistry.Register(EntryType.ZoneList, new PVS()); - } + public string Id => "pvsplugin"; + public string Name => "PVS Resource Handler"; - public override string GetID() + public static void Init() { - return "pvsplugin"; - } - - public override string GetName() - { - return "PVS Resource Handler"; + EntryTypeRegistry.Register(EntryType.ZoneList, new PVS()); } } } diff --git a/PluginAPI/IPlugin.cs b/PluginAPI/IPlugin.cs new file mode 100644 index 0000000..a75a787 --- /dev/null +++ b/PluginAPI/IPlugin.cs @@ -0,0 +1,10 @@ +namespace PluginAPI +{ + public interface IPlugin + { + string Id { get; } + string Name { get; } + + public static abstract void Init(); + } +} diff --git a/PluginAPI/Plugin.cs b/PluginAPI/Plugin.cs deleted file mode 100644 index 01bf23b..0000000 --- a/PluginAPI/Plugin.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace PluginAPI -{ - public abstract class Plugin - { - public virtual void Init() - { - // Stub - } - - public abstract string GetID(); - - public abstract string GetName(); - - public virtual string GetDescription() - { - return null; - } - } -} diff --git a/PluginSystem/PluginLoader.cs b/PluginSystem/PluginLoader.cs index e7a43a5..71801d7 100644 --- a/PluginSystem/PluginLoader.cs +++ b/PluginSystem/PluginLoader.cs @@ -1,113 +1,46 @@ using PluginAPI; -using PluginSystem.Util; using System; using System.Collections.Generic; -using BundleUtilities; +using System.Reflection; namespace PluginSystem { - using System.IO; - using System.Reflection; public static class PluginLoader { - private static readonly Dictionary _plugins = new Dictionary(); - - private delegate void OnLog(string message); - private static event OnLog Log; - - private static void LogInfo(string message) - { - new LogWriter(message); - Log?.Invoke(message); - } - - private static void ScanPluginsFolder() + // Plugin classes. To add an entry here, the plugin's containing project + // must be added as a reference. + private static readonly List registeredPlugins = + [ + typeof(BaseHandlers.BasePlugin), + typeof(LangEditor.LangPlugin), + typeof(LoopModel.LoopModelPlugin), + typeof(LuaList.LuaListPlugin), + typeof(PVSFormat.PVSPlugin), + typeof(VaultFormat.AttribSysPlugin), + typeof(VehicleList.VehicleListPlugin), + typeof(WheelList.WheelListPlugin), + typeof(WorldCollisionHandler.WorldCollisionPlugin) + ]; + + // Runs each plugin's static initialization method. + public static void InitializePlugins() { - LogInfo("Scanning Plugins Folder"); - - string directory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins"); - Directory.CreateDirectory(directory); - string[] pluginDLLs = Directory.GetFiles(directory, "*.dll", SearchOption.TopDirectoryOnly); - - foreach (string pluginDLL in pluginDLLs) + Console.WriteLine("Initializing plugins..."); + int numPluginsInitialized = 0; + foreach (Type pluginType in registeredPlugins) { - try + if (pluginType.IsAssignableTo(typeof(IPlugin))) { - Assembly.LoadFile(pluginDLL); + MethodInfo initInfo = pluginType.GetMethod(nameof(IPlugin.Init)); + initInfo.Invoke(null, []); + numPluginsInitialized++; } - catch (Exception ex) + else { - LogInfo(ex.Message + "\n" + ex.StackTrace); + Console.WriteLine($"{pluginType.AssemblyQualifiedName} is not a valid plugin. Skipping."); } } - } - - private static void FindPlugins() - { - LogInfo("Finding Plugins"); - - Type pluginType = typeof(Plugin); - - List assemblies = AssemblyUtil.BuildAssemblyList(); - - foreach (Assembly assembly in assemblies) - { - LogInfo("Scanning Assembly: " + assembly.GetName().Name); - - foreach (Type type in assembly.GetTypes()) - { - if (!type.IsSubclassOf(pluginType)) - continue; - - try - { - Plugin plugin = Activator.CreateInstance(type, true) as Plugin; - if (plugin == null) - { - throw new InvalidCastException("Type is not plugin"); - } - - if (plugin.GetID() == null) - { - LogInfo(type.FullName + " is missing Plugin ID!"); - continue; - } - - if (_plugins.ContainsKey(plugin.GetID())) - continue; - _plugins.Add(plugin.GetID(), plugin); - - } catch (Exception ex) - { - string err = ex.Message + "\n" + ex.StackTrace; - LogInfo(err); - continue; - } - } - } - } - - private static void InitPlugin(Plugin plugin) - { - LogInfo("Initializing Plugin (" + plugin.GetID() + ":" + plugin.GetName() + ")"); - plugin.Init(); - } - - private static void InitPlugins() - { - LogInfo("Initializing Plugins"); - foreach (var plugin in _plugins) - { - InitPlugin(plugin.Value); - } - } - - public static void LoadPlugins() - { - LogInfo("Loading Plugins"); - ScanPluginsFolder(); - FindPlugins(); - InitPlugins(); + Console.WriteLine($"Initialized {numPluginsInitialized} plugins."); } } } diff --git a/PluginSystem/PluginSystem.csproj b/PluginSystem/PluginSystem.csproj index cc64a5c..0c3f50f 100644 --- a/PluginSystem/PluginSystem.csproj +++ b/PluginSystem/PluginSystem.csproj @@ -4,8 +4,15 @@ Library - - + + + + + + + + + \ No newline at end of file diff --git a/PluginSystem/Util/AssemblyUtil.cs b/PluginSystem/Util/AssemblyUtil.cs deleted file mode 100644 index 36c297a..0000000 --- a/PluginSystem/Util/AssemblyUtil.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; - -namespace PluginSystem.Util -{ - public static class AssemblyUtil - { - private static bool ContainsAssembly(this List self, string fullname) - { - foreach (Assembly assembly in self) - { - if (assembly.FullName == fullname) - return true; - } - - return false; - } - - private static void AddAssemblyWithReferences(this List self, Assembly assembly) - { - if (!self.Contains(assembly)) - self.Add(assembly); - - AssemblyName[] references = assembly.GetReferencedAssemblies(); - foreach (AssemblyName reference in references) - { - if (self.ContainsAssembly(reference.FullName)) - continue; - - try - { - self.AddAssemblyWithReferences(Assembly.Load(reference)); - } - catch { } - } - } - - internal static List BuildAssemblyList() - { - List assemblies = new List(); - foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) - { - AddAssemblyWithReferences(assemblies, assembly); - } - - return assemblies; - } - } -} diff --git a/VaultFormat/AttribSysPlugin.cs b/VaultFormat/AttribSysPlugin.cs index 4a44da1..7e20e36 100644 --- a/VaultFormat/AttribSysPlugin.cs +++ b/VaultFormat/AttribSysPlugin.cs @@ -3,21 +3,14 @@ namespace VaultFormat { - public class AttribSysPlugin : Plugin + public class AttribSysPlugin : IPlugin { - public override void Init() - { - EntryTypeRegistry.Register(EntryType.AttribSysVault, new AttribSys()); - } + public string Id => "attribsysplugin"; + public string Name => "AttribSys Resource Handler"; - public override string GetID() + public static void Init() { - return "attribsysplugin"; - } - - public override string GetName() - { - return "AttribSys Resource Handler"; + EntryTypeRegistry.Register(EntryType.AttribSysVault, new AttribSys()); } } } diff --git a/VaultFormat/AttribSysVaultPlugin.cs b/VaultFormat/AttribSysVaultPlugin.cs deleted file mode 100644 index d0efab5..0000000 --- a/VaultFormat/AttribSysVaultPlugin.cs +++ /dev/null @@ -1,23 +0,0 @@ -using BundleFormat; -using PluginAPI; - -namespace VaultFormat -{ - public class AttribsSysVaultPlugin : Plugin - { - public override void Init() - { - EntryTypeRegistry.Register(EntryType.AttribSysVault, new AttribSys()); - } - - public override string GetID() - { - return "attribsysplugin"; - } - - public override string GetName() - { - return "Attribsys Resource Handler"; - } - } -} diff --git a/VehicleList/VehicleListPlugin.cs b/VehicleList/VehicleListPlugin.cs index fac4ef8..467bfaf 100644 --- a/VehicleList/VehicleListPlugin.cs +++ b/VehicleList/VehicleListPlugin.cs @@ -3,21 +3,14 @@ namespace VehicleList { - public class VehicleListPlugin : Plugin + public class VehicleListPlugin : IPlugin { - public override void Init() - { - EntryTypeRegistry.Register(EntryType.VehicleList, new VehicleListData()); - } + public string Id => "vehiclelistplugin"; + public string Name => "VehicleList Resource Handler"; - public override string GetID() + public static void Init() { - return "vehiclelistplugin"; - } - - public override string GetName() - { - return "VehicleList Resource Handler"; + EntryTypeRegistry.Register(EntryType.VehicleList, new VehicleListData()); } } } diff --git a/WheelList/WheelListPlugin.cs b/WheelList/WheelListPlugin.cs index ddec0ea..bd8ac19 100644 --- a/WheelList/WheelListPlugin.cs +++ b/WheelList/WheelListPlugin.cs @@ -3,21 +3,14 @@ namespace WheelList { - public class WheelListPlugin : Plugin + public class WheelListPlugin : IPlugin { - public override void Init() + public string Id => "wheellistplugin"; + public string Name => "WheelList Resource Handler"; + + public static void Init() { EntryTypeRegistry.Register(EntryType.WheelList, new WheelListData()); } - - public override string GetID() - { - return "wheellistplugin"; - } - - public override string GetName() - { - return "WheelList Resource Handler"; - } } } diff --git a/WorldCollisionHandler/WorldCollisionPlugin.cs b/WorldCollisionHandler/WorldCollisionPlugin.cs index ed44f44..e55c908 100644 --- a/WorldCollisionHandler/WorldCollisionPlugin.cs +++ b/WorldCollisionHandler/WorldCollisionPlugin.cs @@ -7,9 +7,12 @@ namespace WorldCollisionHandler { - public class WorldCollisionPlugin : Plugin + public class WorldCollisionPlugin : IPlugin { - public override void Init() + public string Id => "worldcolplugin"; + public string Name => "World Collision Handler"; + + public static void Init() { EntryTypeRegistry.Register(EntryType.PolygonSoupList, new PolygonSoupList()); @@ -17,19 +20,9 @@ public override void Init() PluginCommandRegistry.Register("remove_wreck_surfaces", "Remove Wreck Surfaces", RemoveWreckSurfaces, IsWorldCol); } - public override string GetID() - { - return "worldcolplugin"; - } - - public override string GetName() - { - return "World Collision Handler"; - } - #region Extra Tools - private bool IsWorldCol(BundleArchive archive) + private static bool IsWorldCol(BundleArchive archive) { for (int i = 0; i < archive.Entries.Count; i++) { @@ -42,7 +35,7 @@ private bool IsWorldCol(BundleArchive archive) return false; } - private void DumpAllCollisions(IWin32Window window, BundleArchive archive) + private static void DumpAllCollisions(IWin32Window window, BundleArchive archive) { if (archive == null) return; @@ -91,7 +84,7 @@ private void DumpAllCollisions(IWin32Window window, BundleArchive archive) } } - private void RemoveWreckSurfaces(IWin32Window window, BundleArchive archive) + private static void RemoveWreckSurfaces(IWin32Window window, BundleArchive archive) { for (int i = 0; i < archive.Entries.Count; i++) {