public UMMLoader() { Logger = base.Logger; if (ModInfo == null) { harmony.Patch(AccessTools.Method("DateFile:Awake"), null, new HarmonyMethod(this.GetType(), "Prefix")); ModInfo = new UnityModManager.ModInfo(); ModInfo.AssemblyName = Assembly.GetExecutingAssembly().GetName().Name; ModInfo.Author = "Yan"; ModInfo.DisplayName = "UnityModManagerLoader"; ModInfo.Version = "0.16.1.0"; } AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; }
public void AddErrorMod(Dictionary <UnityModManager.ModInfo, List <string> > obj, UnityModManager.ModInfo modInfo, string message) { if (obj.TryGetValue(modInfo, out List <string> value)) { if (!value.Contains(message)) { value.Add(message); } } else { obj.Add(modInfo, new List <string>() { message }); } }
public bool TryGetErrorMods(string logString, string stackString, out Dictionary <UnityModManager.ModInfo, List <string> > result) { Dictionary <UnityModManager.ModInfo, List <string> > errorMods = new Dictionary <UnityModManager.ModInfo, List <string> >(); try { List <string> modStr = new List <string>(); foreach (var mod in UnityModManager.modEntries) { modStr.Clear(); modStr = GetModStr(mod); if (modStr.Count <= 0) { break; } foreach (var name in modStr) { if (logString.Contains(name)) { ExceptionHelper.Instance.AddErrorMod(errorMods, mod.Info, name); } if (stackString.Contains(name)) { ExceptionHelper.Instance.AddErrorMod(errorMods, mod.Info, name); } } } string pattern = @"(?<= )\S+?_Patch\d+"; foreach (Match match in Regex.Matches(logString + stackString, pattern)) { string matchString = match.Groups[0].Value; string fullName = matchString.Substring(0, matchString.LastIndexOf('_')); int num = fullName.LastIndexOf('.'); string methodName = fullName.Substring(num + 1, fullName.Length - fullName.LastIndexOf('.') - 1); string typeName = fullName.Substring(0, fullName.LastIndexOf('.')); string index = matchString.Substring(matchString.LastIndexOf("_Patch") + 6, matchString.Length - (matchString.LastIndexOf("_Patch") + 6)); Type classtyp = AccessTools.TypeByName(typeName); if (classtyp == null) { Main.Logger.Log($"无法获取到{fullName}的类型"); continue; } MethodInfo methodInfo = classtyp.GetMethod(methodName, AccessTools.all); if (methodInfo == null) { Main.Logger.Log($"无法获取到{fullName}的方法"); continue; } var info = PatchProcessor.GetPatchInfo(methodInfo); if (info == null) { Main.Logger.Log($"无法获取到对{fullName}的补丁"); continue; } int patchIndex = int.Parse(index); foreach (var patch in info.Prefixes) { if (patch.index == patchIndex) { UnityModManager.ModInfo modInfo = UnityModManager.FindMod(patch.owner).Info; ExceptionHelper.Instance.AddErrorMod(errorMods, modInfo, matchString + ".Prefix()"); } } foreach (var patch in info.Postfixes) { if (patch.index == patchIndex) { UnityModManager.ModInfo modInfo = UnityModManager.FindMod(patch.owner).Info; ExceptionHelper.Instance.AddErrorMod(errorMods, modInfo, matchString + ".Postfix()"); } } } result = errorMods; return(true); } catch (Exception e) { errorMods.Clear(); errorMods.Add(Main.modEntry.Info, new List <string>() { e.Message, e.StackTrace }); result = errorMods; return(false); } }