public override void OnApplicationStart() { MelonLogger.Msg("Initializing..."); Instance = this; melonLoaderEventSubscribers = MelonHandler.Mods .Select(mod => mod.Assembly.GetTypes()) .SelectMany(types => types) .Where(type => { try { return(type.IsSubclassOf(typeof(MelonLoaderEvents)) || Attribute.GetCustomAttribute(type, typeof(MelonLoaderEventsAttribute)) != null); } catch { return(false); } }) .OrderBy((type) => { MelonLoaderEventsPriorityAttribute priority = (MelonLoaderEventsPriorityAttribute)Attribute.GetCustomAttribute(type, typeof(MelonLoaderEventsPriorityAttribute)); return(priority == null ? 0 : priority.priority); }) .Select(type => type.IsSubclassOf(typeof(MelonLoaderEvents)) ? Activator.CreateInstance(type) : type) .ToArray(); // Keep some calls normal because they need to run before everything else XrefUtils.Init(); try { UiManager.Init(); } catch (Exception ex) { MelonLogger.Error("Error while initializing UiManager:\n" + ex.ToString()); } foreach (object subscriber in melonLoaderEventSubscribers) { try { if (subscriber is Type subscriberAsType) { try { subscriberAsType.GetMethod("OnApplicationStart", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)?.Invoke(null, null); } catch (ArgumentException) { throw new ArgumentException($"Type {subscriberAsType.Name} which is subscribed to MelonLoaderEvents via an attribute has an OnApplicationStart that is not static."); } } else { (subscriber as MelonLoaderEvents).OnApplicationStart(); } } catch (Exception ex) { MelonLogger.Error($"Exception during OnApplicationStart:\n{ex}"); } } VRCUtils.OnUiManagerInit += OnUiManagerInit; }
internal static void Init() { portalInfo = typeof(VRCFlowManager).GetMethods() .Where(mb => mb.Name.StartsWith("Method_Public_Void_String_WorldTransitionInfo_")).First().GetParameters()[1].ParameterType; portalInfoEnum = portalInfo.GetNestedTypes().First(); enterWorld = typeof(VRCFlowManager).GetMethods() .Where(mb => mb.Name.StartsWith($"Method_Public_Void_String_String_{portalInfo.Name}_Action_1_String_Boolean_") && !mb.Name.Contains("PDM") && XrefUtils.CheckMethod(mb, "EnterWorld called with an invalid world id.")).First(); enterPortal = typeof(PortalInternal).GetMethods() .Where(mb => mb.Name.StartsWith("Method_Public_Void_") && mb.Name.Length <= 21 && XrefUtils.CheckUsedBy(mb, "OnTriggerEnter")).First(); }