public static void Create() { VRCModLogger.Log("[ModComponent] Loading VRLoader.dll"); LoadVRLoader(); VRCModLogger.Log("[ModComponent] VRLoader.dll loaded"); if (!Bootstrapper.loadmods) { return; } try { VRCModLogger.Log("[ModComponent] Creating components"); //First create the mod manager GO, so it gets updated before the modules. GameObject modManagerGO = new GameObject("IPA_ModManager"); modulesGameObject = new GameObject("IPA_VRModules"); modulesGameObject.SetActive(false); // We will enable it when the Ui scene will be loaded. modManagerGO.AddComponent <ModComponent>(); } catch (Exception e) { VRCModLogger.LogError("[ModComponent] Error while creating instance: " + e); } }
private static void LoadVRLoader() { try { Assembly.Load(Properties.Resources.VRLoader); } catch (Exception e) { VRCModLogger.LogError("[ModComponent] Error while loading VRLoader.dll: " + e); } }
void OnDestroy() { try { ModComponent.Create(); } catch (Exception e) { VRCModLogger.LogError(e.ToString()); } }
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); } }
private void Invoke(CompositeCall callback) { foreach (var modController in modControllers) { try { callback(modController); } catch (Exception ex) { VRCModLogger.LogError("{0}: {1}", modController.mod.Name, ex); } } }
public void OnLevelWasInitialized(int level) { foreach (var modController in modControllers) { try { modController.OnLevelWasInitialized(level); } catch (Exception ex) { VRCModLogger.LogError("{0}: {1}", modController.mod.Name, ex); } } }
public static IEnumerable <Type> GetLoadableTypes(this Assembly assembly) { if (assembly == null) { throw new ArgumentNullException(nameof(assembly)); } try { return(assembly.GetTypes()); } catch (ReflectionTypeLoadException e) { VRCModLogger.LogError("[ModManager] An error occured while getting types from assembly " + assembly.GetName().Name + ". Returning types from error.\n" + e); return(e.Types.Where(t => t != null)); } }
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); } }
internal static void LoadMods() { VRCModLogger.Log("Looking for mods"); string modDirectory = Path.Combine(Environment.CurrentDirectory, "Mods"); string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath); VRCModLogger.Log(exeName); Mods = new List <VRCMod>(); ModControllers = new List <VRCModController>(); Modules = new List <VRModule>(); if (moduleManager == null) { moduleManager = new ModuleManager(); ModComponent.Instance.gameObject.AddComponent <VRLoader.VRLoader>(); } if (!Directory.Exists(modDirectory)) { return; } string[] files = Directory.GetFiles(modDirectory, "*.dll"); foreach (string s in files) { if (!File.Exists(s) || !s.EndsWith(".dll", true, null)) { return; } VRCModLogger.Log("Loading " + s); try { byte[] data = File.ReadAllBytes(s); Assembly a = Assembly.Load(data); loadedAssemblies.Add(a); } catch (Exception e) { VRCModLogger.LogError("Unable to load assembly " + s + ":\n" + e); } } foreach (Assembly a in loadedAssemblies) { VRCModLogger.Log("Loading mods from " + a.GetName()); LoadModsFromAssembly(a); } // DEBUG VRCModLogger.Log("Running on Unity " + Application.unityVersion + ", using VRCModLoader " + VERSION); VRCModLogger.Log("-----------------------------"); VRCModLogger.Log("Loading mods from " + modDirectory + " and found " + Mods.Count + " VRCMods and " + Modules.Count + " VRModules."); VRCModLogger.Log("-----------------------------"); foreach (var mod in Mods) { VRCModLogger.Log(" " + mod.Name + " (" + mod.Version + ") by " + mod.Author + (mod.DownloadLink != null ? " (" + mod.DownloadLink + ")" : "")); } VRCModLogger.Log("-----------------------------"); foreach (var mod in Modules) { VRCModLogger.Log(" " + mod.Name + " (" + mod.Version + ") by " + mod.Author); } VRCModLogger.Log("-----------------------------"); }