Exemple #1
0
 public void InstantiatePlugins()
 {
     LogFile.WriteLine($"Loading {plugins.Count} plugins");
     for (int i = plugins.Count - 1; i >= 0; i--)
     {
         PluginInstance p = plugins[i];
         if (!p.Instantiate())
         {
             plugins.RemoveAtFast(i);
         }
     }
 }
Exemple #2
0
 public void Init(object gameInstance)
 {
     LogFile.WriteLine($"Initializing {plugins.Count} plugins");
     for (int i = plugins.Count - 1; i >= 0; i--)
     {
         PluginInstance p = plugins[i];
         if (!p.Init(gameInstance))
         {
             plugins.RemoveAtFast(i);
         }
     }
     init = true;
 }
Exemple #3
0
 public void HandleInput()
 {
     if (init)
     {
         for (int i = plugins.Count - 1; i >= 0; i--)
         {
             PluginInstance p = plugins[i];
             if (!p.HandleInput())
             {
                 plugins.RemoveAtFast(i);
             }
         }
     }
 }
Exemple #4
0
 public void Update()
 {
     if (init)
     {
         for (int i = plugins.Count - 1; i >= 0; i--)
         {
             PluginInstance p = plugins[i];
             if (!p.Update())
             {
                 plugins.RemoveAtFast(i);
             }
         }
     }
 }
Exemple #5
0
        public bool TryGetPluginInstance(string id, out PluginInstance instance)
        {
            instance = null;
            if (!init)
            {
                return(false);
            }

            foreach (PluginInstance p in plugins)
            {
                if (p.Id == id)
                {
                    instance = p;
                    return(true);
                }
            }

            return(false);
        }
        public static bool TryGet(PluginData data, out PluginInstance instance)
        {
            instance = null;
            if (data.Status == PluginStatus.Error || !data.TryLoadAssembly(out Assembly a))
            {
                return(false);
            }

            Type pluginType = a.GetTypes().FirstOrDefault(t => typeof(IPlugin).IsAssignableFrom(t));

            if (pluginType == null)
            {
                LogFile.WriteLine($"Failed to load {data} because it does not contain an IPlugin");
                data.Error();
                return(false);
            }

            instance = new PluginInstance(data, a, pluginType);
            return(true);
        }
Exemple #7
0
        public Main()
        {
            Stopwatch sw = Stopwatch.StartNew();

            Splash = new SplashScreen();

            Instance = this;

            Cursor temp = Cursor.Current;

            Cursor.Current = Cursors.AppStarting;

            string pluginsDir = LoaderTools.PluginsDir;

            Directory.CreateDirectory(pluginsDir);

            LogFile.Init(pluginsDir);
            LogFile.WriteLine("Starting - v" + Assembly.GetExecutingAssembly().GetName().Version.ToString(3));

            // Fix tls 1.2 not supported on Windows 7 - github.com is tls 1.2 only
            try
            {
                ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
            }
            catch (NotSupportedException e)
            {
                LogFile.WriteLine("An error occurred while setting up networking, web requests will probably fail: " + e);
            }

            Splash.SetText("Finding references...");
            RoslynReferences.GenerateAssemblyList();

            AppDomain.CurrentDomain.AssemblyResolve += ResolveDependencies;

            Config = PluginConfig.Load(pluginsDir);
            List   = new PluginList(pluginsDir, Config);

            Config.Init(List);

            StatsClient.OverrideBaseUrl(Config.StatsServerBaseUrl);

            Splash.SetText("Patching...");
            LogFile.WriteLine("Patching");

            // Check harmony version
            Version expectedHarmony = new Version(HarmonyVersion);
            Version actualHarmony   = typeof(Harmony).Assembly.GetName().Version;

            if (expectedHarmony != actualHarmony)
            {
                LogFile.WriteLine($"WARNING: Unexpected Harmony version, plugins may be unstable. Expected {expectedHarmony} but found {actualHarmony}");
            }

            new Harmony("avaness.PluginLoader").PatchAll(Assembly.GetExecutingAssembly());

            Splash.SetText("Instantiating plugins...");
            LogFile.WriteLine("Instantiating plugins");
            foreach (string id in Config)
            {
                PluginData data = List[id];
                if (data is GitHubPlugin github)
                {
                    github.Init(pluginsDir);
                }
                if (PluginInstance.TryGet(data, out PluginInstance p))
                {
                    plugins.Add(p);
                    if (data.IsLocal)
                    {
                        HasLocal = true;
                    }
                }
            }

            sw.Stop();

            // FIXME: It can potentially run in the background speeding up the game's startup
            ReportEnabledPlugins();

            LogFile.WriteLine($"Finished startup. Took {sw.ElapsedMilliseconds}ms");

            Cursor.Current = temp;

            Splash.Delete();
            Splash = null;
        }