From 3326d0e73d57f111f5dc09ae3e927b0c357d9cac Mon Sep 17 00:00:00 2001 From: Alessandro Proto Date: Thu, 27 Jul 2023 20:17:42 +0200 Subject: [PATCH] Moved plugins folder to appdata. Added config to disable plugins --- Capy64/Assets/default.json | 1 + Capy64/Capy64.cs | 13 ++++--------- Capy64/PluginManager/PluginLoader.cs | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Capy64/Assets/default.json b/Capy64/Assets/default.json index 6b04894..35ebe57 100644 --- a/Capy64/Assets/default.json +++ b/Capy64/Assets/default.json @@ -1,5 +1,6 @@ { "EngineMode": 0, + "SafeMode": false, "Window": { "Scale": 2 }, diff --git a/Capy64/Capy64.cs b/Capy64/Capy64.cs index 67b1f8e..8eddedc 100644 --- a/Capy64/Capy64.cs +++ b/Capy64/Capy64.cs @@ -112,7 +112,6 @@ public class Capy64 : Game private readonly InputManager _inputManager; private RenderTarget2D renderTarget; private readonly GraphicsDeviceManager _graphics; - private IServiceProvider _serviceProvider; private ulong _totalTicks = 0; private int tickrate = 0; private int everyTick => 60 / tickrate; @@ -122,7 +121,7 @@ public class Capy64 : Game Instance = this; _graphics = new GraphicsDeviceManager(this); - Content.RootDirectory = "Content"; + //Content.RootDirectory = "Content"; IsMouseVisible = true; EventEmitter = new(); @@ -131,11 +130,6 @@ public class Capy64 : Game Drawing = new(); } - public void ConfigureServices(IServiceProvider serviceProvider) - { - _serviceProvider = serviceProvider; - } - public void SetEngineMode(EngineMode mode) { switch (mode) @@ -265,7 +259,9 @@ public class Capy64 : Game Audio = new Audio(); NativePlugins = GetNativePlugins(); - Plugins = PluginLoader.LoadAllPlugins("plugins", _serviceProvider); + var safeMode = Configuration.GetValue("SafeMode", false); + if (!safeMode) + Plugins = PluginLoader.LoadAllPlugins(Path.Combine(AssetsPath, "plugins")); EventEmitter.RaiseInit(); @@ -284,7 +280,6 @@ public class Capy64 : Game foreach (var type in types) { var instance = (IComponent)Activator.CreateInstance(type, this); - //var instance = (IComponent)ActivatorUtilities.CreateInstance(_serviceProvider, type)!; plugins.Add(instance); } diff --git a/Capy64/PluginManager/PluginLoader.cs b/Capy64/PluginManager/PluginLoader.cs index 5bdcd2c..376c18a 100644 --- a/Capy64/PluginManager/PluginLoader.cs +++ b/Capy64/PluginManager/PluginLoader.cs @@ -32,7 +32,7 @@ internal class PluginLoader return loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(path))); } - public static List LoadAllPlugins(string pluginsPath, IServiceProvider provider) + public static List LoadAllPlugins(string pluginsPath) { if (!Directory.Exists(pluginsPath)) Directory.CreateDirectory(pluginsPath);