2using System.Reflection;
3using System.Runtime.CompilerServices;
4using System.Collections.Generic;
5using System.Collections.Immutable;
10using Microsoft.Xna.Framework;
15 public class GhostDetector
17 public static bool Dead {
get;
set; }
18 public static Action<string> OnDetect;
23 public static bool Check(
24 [CallerMemberName]
string memberName =
"",
25 [CallerFilePath]
string source =
"",
26 [CallerLineNumber]
int lineNumber = 0
31 string at = $
"{CutFilePath(source)}:{lineNumber} {memberName}";
33 if (ShouldReport(at)) OnDetect?.Invoke(at);
39 public static string CutFilePath(
string path)
41 int i = path.IndexOf(
"CSharp");
42 if (i == -1) i = path.IndexOf(
"SharedSource");
43 if (i == -1) i = path.IndexOf(
"ClientSource");
44 if (i == -1) i = path.IndexOf(
"ServerSource");
46 if (i == -1)
return path;
47 return path.Substring(i);
51 public static int MinDetections = 3;
52 public static int MaxDetections = 6;
53 public static Dictionary<string, int> Detections =
new();
54 public static bool ShouldReport(
string at)
56 if (!Detections.ContainsKey(at)) Detections[at] = 1;
57 else Detections[at]++;
59 return MinDetections < Detections[at] && Detections[at] <= MaxDetections;
65 public static void Activate()
69 Log($
"{CUI.HookIdentifier} GUI just died, It seems that there is a mod conflict");
70 Log($
"At {at}", Color.Orange);
74 public static void Deactivate()
79 public static void Log(
object msg, Color? color =
null)
81 color ??= Color.Yellow;
82 LuaCsLogger.LogMessage($
"{msg ?? "null"}", color * 0.8f, color);