public static T CreateMelon <T>(this WrapperData creationData) where T : MelonBase { MelonBase baseMelon = CreateMelon(creationData); if (baseMelon == null) { return(default);
private static MelonBase CheckForMelonInFrame(StackTrace st, int frame = 0) { StackFrame sf = st.GetFrame(frame); if (sf == null) { return(null); } MethodBase method = sf.GetMethod(); if (method == null) { return(null); } Type methodClassType = method.DeclaringType; if (methodClassType == null) { return(null); } Assembly asm = methodClassType.Assembly; if (asm == null) { return(null); } MelonBase melon = MelonHandler.Plugins.Find(x => (x.Assembly == asm)); if (melon == null) { melon = MelonHandler.Mods.Find(x => (x.Assembly == asm)); } return(melon); }
internal static void ManualMelonError(MelonBase melon, string txt) { string namesection = null; if (melon != null) { namesection = melon.Info.Name.Replace(" ", "_"); } ManualError(namesection, txt); }
private static void SendWarning(string txt) { string namesection = null; MelonBase melon = MelonUtils.GetMelonFromStackTrace(); if (melon != null) { namesection = melon.Info.Name; } ManualWarning(namesection, txt); }
internal static void ManualMelonError(MelonBase melon, string txt) { string namesection = null; if (melon != null) { namesection = melon.Info.Name.Replace(" ", "_"); } PushMessageToBepInEx(namesection, txt, LogLevel.Error); RunErrorCallbacks(namesection, txt ?? "null"); }
private static void SendError(string txt) { string namesection = null; MelonBase melon = GetMelonFromStackTrace(); if (melon != null) { namesection = melon.Info.Name.Replace(" ", "_"); } Internal_Error(namesection, txt); RunErrorCallbacks(namesection, txt); }
private static void SendMsg(ConsoleColor msgcolor, string msg) { ConsoleColor meloncolor = MelonLogger.DefaultMelonColor; string namesection = null; MelonBase melon = MelonUtils.GetMelonFromStackTrace(); if (melon != null) { namesection = melon.Info.Name.Replace(" ", "_"); msgcolor = melon.ConsoleColor; } Internal_Msg(meloncolor, msgcolor, namesection, msg); MsgCallbackHandler?.Invoke(meloncolor, msgcolor, namesection, msg); }
private static void SendMsg(ConsoleColor txtcolor, string txt) { ConsoleColor meloncolor = DefaultMelonColor; string namesection = null; MelonBase melon = MelonUtils.GetMelonFromStackTrace(); if (melon != null) { namesection = melon.Info.Name.Replace(" ", "_"); meloncolor = melon.ConsoleColor; } Internal_Msg(meloncolor, txtcolor, namesection, txt); RunMsgCallbacks(meloncolor, txtcolor, namesection, txt); }
private static void SendMsg(ConsoleColor txtcolor, string txt) { ConsoleColor meloncolor = DefaultMelonColor; string namesection = null; MelonBase melon = MelonUtils.GetMelonFromStackTrace(); if (melon != null) { namesection = melon.Info.Name.Replace(" ", "_"); meloncolor = melon.ConsoleColor; } PushMessageToBepInEx(namesection, txt, LogLevel.Message); RunMsgCallbacks(meloncolor, txtcolor, namesection, txt ?? "null"); }
private static void NativeMsg(ConsoleColor namesection_color, ConsoleColor txt_color, string namesection, string txt) { if (string.IsNullOrEmpty(namesection)) { MelonBase melon = MelonUtils.GetMelonFromStackTrace(); if (melon != null) { namesection = melon.Info?.Name?.Replace(" ", "_"); namesection_color = melon.ConsoleColor; } } Internal_Msg(namesection_color, txt_color, namesection, txt ?? "null"); RunMsgCallbacks(namesection_color, txt_color, namesection, txt ?? "null"); }
private static void InitializeModOrPlugin(MelonBase modOrPlugin) { string harmonyId = modOrPlugin.Assembly.FullName; HarmonyInstance harmony = HarmonyInstance.Create(harmonyId); try { harmony.PatchAll(modOrPlugin.Assembly); modOrPlugin.OnApplicationStart(); } catch (Exception) { harmony.UnpatchAll(harmonyId); throw; } }
public static MelonBase GetMelonFromStackTrace() { StackTrace st = new StackTrace(3, true); if (st.FrameCount <= 0) { return(null); } MelonBase output = CheckForMelonInFrame(st); if (output == null) { output = CheckForMelonInFrame(st, 1); } if (output == null) { output = CheckForMelonInFrame(st, 2); } return(output); }