Пример #1
0
        private static void LoadModsFromAssembly(Assembly assembly)
        {
            try
            {
                foreach (Type t in assembly.GetLoadableTypes())
                {
                    if (t.IsSubclassOf(typeof(VRCMod)))
                    {
                        try
                        {
                            VRCMod modInstance = Activator.CreateInstance(t) as VRCMod;
                            Mods.Add(modInstance);
                            ModControllers.Add(new VRCModController(modInstance));
                            VRCModInfoAttribute modInfoAttribute = modInstance.GetType().GetCustomAttributes(typeof(VRCModInfoAttribute), true).FirstOrDefault() as VRCModInfoAttribute;
                            if (modInfoAttribute != null)
                            {
                                modInstance.Name         = modInfoAttribute.Name;
                                modInstance.Version      = modInfoAttribute.Version;
                                modInstance.Author       = modInfoAttribute.Author;
                                modInstance.DownloadLink = modInfoAttribute.DownloadLink;
                            }
                        }
                        catch (Exception e)
                        {
                            VRCModLogger.Log("[WARN] [ModManager] Could not load mod " + t.FullName + " in " + assembly.GetName() + "! " + e);
                        }
                    }

                    if (t.IsSubclassOf(typeof(VRModule)))
                    {
                        try
                        {
                            ModuleInfoAttribute moduleInfo;
                            if ((moduleInfo = (t.GetCustomAttributes(typeof(ModuleInfoAttribute), true).FirstOrDefault() as ModuleInfoAttribute)) != null)
                            {
                                VRCModLogger.Log("Adding component " + t);
                                VRModule vrmodule = ModComponent.modulesGameObject.gameObject.AddComponent(t) as VRModule;
                                Modules.Add(vrmodule);
                                vrmodule.Initialize(moduleInfo, moduleManager);
                            }
                        }
                        catch (Exception e)
                        {
                            VRCModLogger.Log("[WARN] [ModManager] Could not load module " + t.FullName + " in " + assembly.GetName() + "! " + e);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                VRCModLogger.LogError("[ModManager] Could not load " + assembly.GetName() + "! " + e);
            }
        }
Пример #2
0
        private static void LoadModsFromFile(string file, string exeName)
        {
            List <VRCMod> mods = new List <VRCMod>();

            if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
            {
                return;
            }

            try
            {
                Assembly assembly = Assembly.LoadFrom(file);

                foreach (Type t in assembly.GetLoadableTypes())
                {
                    if (t.IsSubclassOf(typeof(VRCMod)))
                    {
                        try
                        {
                            VRCMod modInstance = Activator.CreateInstance(t) as VRCMod;
                            _Mods.Add(modInstance);
                            _ModControllers.Add(new VRCModController(modInstance));
                            VRCModInfoAttribute modInfoAttribute = modInstance.GetType().GetCustomAttributes(typeof(VRCModInfoAttribute), true).FirstOrDefault() as VRCModInfoAttribute;
                            if (modInfoAttribute != null)
                            {
                                modInstance.Name         = modInfoAttribute.Name;
                                modInstance.Version      = modInfoAttribute.Version;
                                modInstance.Author       = modInfoAttribute.Author;
                                modInstance.DownloadLink = modInfoAttribute.DownloadLink;
                            }
                        }
                        catch (Exception e)
                        {
                            VRCModLogger.Log("[WARN] [ModManager] Could not load mod " + t.FullName + " in " + Path.GetFileName(file) + "! " + e);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                VRCModLogger.LogError("[ModManager] Could not load " + Path.GetFileName(file) + "! " + e);
            }
        }