Skip to content

Commit

Permalink
Only log MonoMod crimes once
Browse files Browse the repository at this point in the history
  • Loading branch information
Popax21 committed Oct 6, 2023
1 parent 4474811 commit 4d7cf07
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Celeste.Mod.mm/Mod/Helpers/LegacyMonoMod/Misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MonoMod.Cil;
using MonoMod.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -74,6 +75,8 @@ public sealed class MonoModCrimeException : Exception {
public MonoModCrimeException(string descr) : base($"MONOMOD CRIME DETECTED - THIS IS A BUG: {descr}") {}
}

private static HashSet<(string descr, Assembly perpetrator, string backtrace)> loggedCrimes = new();

public static void ReportMonoModCrime(string descr, MethodBase perpetrator) {
Module perpetratorMod = null;
try {
Expand All @@ -92,18 +95,20 @@ public static void ReportMonoModCrime(string descr, Assembly perpetrator) {

// This means that a mod did something objectively wrong (=a bug in the mod)
// But because it "used to worked":tm:, we can't give them the crash they deserve
// So we at least yell at them loudly in the log file ._.
Logger.Log(LogLevel.Error, "legacy-monomod", "##################################################################################");
Logger.Log(LogLevel.Error, "legacy-monomod", " MONOMOD CRIME DETECTED ");
Logger.Log(LogLevel.Error, "legacy-monomod", "##################################################################################");
Logger.Log(LogLevel.Error, "legacy-monomod", " !!! This means one of your mods has a bug !!! ");
Logger.Log(LogLevel.Error, "legacy-monomod", " However, for the sake of backwards compatibility, a crash has been prevented ");
Logger.Log(LogLevel.Error, "legacy-monomod", " Please report this to the mod author so that they can fix their mod! ");
Logger.Log(LogLevel.Error, "legacy-monomod", "");
if (perpetratorMeta != null)
Logger.Log(LogLevel.Error, "legacy-monomod", $"Suspected perpetrator: {perpetratorMeta.Name} version {perpetratorMeta.VersionString} [{perpetratorMeta.Version}]");
Logger.Log(LogLevel.Error, "legacy-monomod", $"Details of infraction: {descr}");
Logger.LogDetailed(LogLevel.Error, "legacy-monomod", $"Stacktrace:");
// So we at least yell at them loudly in the log file (once) ._.
if (!string.IsNullOrWhiteSpace(perpetratorMeta?.PathDirectory) || loggedCrimes.Add((descr, perpetrator, Environment.StackTrace))) {
Logger.Log(LogLevel.Error, "legacy-monomod", "##################################################################################");
Logger.Log(LogLevel.Error, "legacy-monomod", " MONOMOD CRIME DETECTED ");
Logger.Log(LogLevel.Error, "legacy-monomod", "##################################################################################");
Logger.Log(LogLevel.Error, "legacy-monomod", " !!! This means one of your mods has a bug !!! ");
Logger.Log(LogLevel.Error, "legacy-monomod", " However, for the sake of backwards compatibility, a crash has been prevented ");
Logger.Log(LogLevel.Error, "legacy-monomod", " Please report this to the mod author so that they can fix their mod! ");
Logger.Log(LogLevel.Error, "legacy-monomod", "");
if (perpetratorMeta != null)
Logger.Log(LogLevel.Error, "legacy-monomod", $"Suspected perpetrator: {perpetratorMeta.Name} version {perpetratorMeta.VersionString} [{perpetratorMeta.Version}]");
Logger.Log(LogLevel.Error, "legacy-monomod", $"Details of infraction: {descr}");
Logger.LogDetailed(LogLevel.Error, "legacy-monomod", $"Stacktrace:");
}

// If we know that the offender is a directory mod (which implies that this is a mod dev), still crash >:)
if (!string.IsNullOrEmpty(perpetratorMeta?.PathDirectory))
Expand Down

0 comments on commit 4d7cf07

Please sign in to comment.