public VRCModController(VRCMod mod) { this.mod = mod; MethodInfo[] methods = mod.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo method in methods) { if (method.Name.Equals("OnApplicationStart") && method.GetParameters().Length == 0) { onApplicationStartMethod = method; } if (method.Name.Equals("OnApplicationQuit") && method.GetParameters().Length == 0) { onApplicationQuitMethod = method; } if (method.Name.Equals("OnLevelWasLoaded") && method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(int)) { onLevelWasLoadedMethod = method; } if (method.Name.Equals("OnLevelWasInitialized") && method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType == typeof(int)) { onLevelWasInitializedMethod = method; } if (method.Name.Equals("OnUpdate") && method.GetParameters().Length == 0) { onUpdateMethod = method; } else if (method.Name.Equals("Update") && method.GetParameters().Length == 0 && onUpdateMethod == null) { onUpdateMethod = method; } if (method.Name.Equals("OnFixedUpdate") && method.GetParameters().Length == 0) { onFixedUpdateMethod = method; } else if (method.Name.Equals("FixedUpdate") && method.GetParameters().Length == 0 && onFixedUpdateMethod == null) { onFixedUpdateMethod = method; } if (method.Name.Equals("OnLateUpdate") && method.GetParameters().Length == 0) { onLateUpdateMethod = method; } else if (method.Name.Equals("LateUpdate") && method.GetParameters().Length == 0 && onLateUpdateMethod == null) { onLateUpdateMethod = method; } if (method.Name.Equals("OnGUI") && method.GetParameters().Length == 0) { onGUIMethod = method; } if (method.Name.Equals("OnModSettingsApplied") && method.GetParameters().Length == 0) { onModSettingsApplied = method; } } }
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 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); } }