From ed99fa26f2a219789e316f5b9e432d95d1dabecb Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Wed, 30 Dec 2020 19:36:53 -0500 Subject: [PATCH] Add fix for durability errors while connecting to server --- CLre/Fixes/BugfixAttribute.cs | 6 +- .../Fixes/ClientDurabilityNodeErrorRemover.cs | 67 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 CLre/Fixes/ClientDurabilityNodeErrorRemover.cs diff --git a/CLre/Fixes/BugfixAttribute.cs b/CLre/Fixes/BugfixAttribute.cs index 9d48d5a..f406374 100644 --- a/CLre/Fixes/BugfixAttribute.cs +++ b/CLre/Fixes/BugfixAttribute.cs @@ -23,6 +23,7 @@ namespace CLre.Fixes HarmonyPatch, Initialiser, Workaround, + API, Debug } @@ -106,7 +107,10 @@ namespace CLre.Fixes sb.AppendFormat("[TARGET: {0}] ", target.FullName); } sb.AppendFormat("[ID: {0}] ", id); - sb.AppendFormat("({0}M/{1}P/{2}I/{3}W/{4}D/{5}T)", bugfixTypeCount[(byte) BugfixType.Miscellaneous], bugfixTypeCount[(byte) BugfixType.HarmonyPatch], bugfixTypeCount[(byte) BugfixType.Initialiser], bugfixTypeCount[(byte) BugfixType.Workaround], bugfixTypeCount[(byte) BugfixType.Debug], total); + sb.AppendFormat("({0}M/{1}P/{2}I/{3}W/{4}A/{5}D/{6}T)", + bugfixTypeCount[(byte) BugfixType.Miscellaneous], bugfixTypeCount[(byte) BugfixType.HarmonyPatch], + bugfixTypeCount[(byte) BugfixType.Initialiser], bugfixTypeCount[(byte) BugfixType.Workaround], + bugfixTypeCount[(byte) BugfixType.API], bugfixTypeCount[(byte) BugfixType.Debug], total); return sb.ToString(); } } diff --git a/CLre/Fixes/ClientDurabilityNodeErrorRemover.cs b/CLre/Fixes/ClientDurabilityNodeErrorRemover.cs new file mode 100644 index 0000000..c88189f --- /dev/null +++ b/CLre/Fixes/ClientDurabilityNodeErrorRemover.cs @@ -0,0 +1,67 @@ +using System.Reflection; +using HarmonyLib; + +namespace CLre.Fixes +{ + [Bugfix(name = "ClientDurabilityNodeErrorRemover", + description = "Disable OnServerNotifyChange() callback when it will error", + more = "https://trello.com/c/YT3VbXpZ/15-durability-log-error", + component = BugfixType.API, id = 3)] + public static class DurabilityNodeErrorRemover + { + public static void Disable() => DurabilityGUIEngineClient_OnServerNotifyChange_Patch.IsDisabled = true; + + public static void Enable() => DurabilityGUIEngineClient_OnServerNotifyChange_Patch.IsDisabled = false; + } + + [Bugfix(name = "ClientDurabilityNodeErrorRemover", + description = "Disable OnServerNotifyChange() callback when it will error", + more = "https://trello.com/c/YT3VbXpZ/15-durability-log-error", + component = BugfixType.HarmonyPatch, id = 3)] + [HarmonyPatch] + class DurabilityGUIEngineClient_OnServerNotifyChange_Patch + { + internal static bool AnyDurabilityClientNodeExists = false; + + internal static bool IsDisabled = false; + + [HarmonyPrefix] + public static bool BeforeMethodCall() + { +#if DEBUG + API.Utility.Logging.MetaLog("Intercepting DurabilityGUIEngineClient.OnServerNotifyChange()"); +#endif + return AnyDurabilityClientNodeExists || IsDisabled; + } + + [HarmonyTargetMethod] + public static MethodBase Target() + { + return AccessTools.Method("Game.Durability.Client.DurabilityGUIEngineClient:OnServerNotifyChange"); + } + } + + [Bugfix(name = "ClientDurabilityNodeErrorRemover", + description = "Disable OnServerNotifyChange() callback when it will error", + more = "https://trello.com/c/YT3VbXpZ/15-durability-log-error", + component = BugfixType.HarmonyPatch, id = 3)] + [HarmonyPatch] + class DurabilityGUIEngineClientSplit_Add_Patch + { + + [HarmonyPrefix] + public static void BeforeMethodCall() + { +#if DEBUG + API.Utility.Logging.MetaLog("Intercepting DurabilityGUIEngineClientSplit.Add()"); +#endif + DurabilityGUIEngineClient_OnServerNotifyChange_Patch.AnyDurabilityClientNodeExists = true; + } + + [HarmonyTargetMethod] + public static MethodBase Target() + { + return AccessTools.Method("Game.Durability.Client.DurabilityGuiEngineClientSplit:Add", new []{ AccessTools.TypeByName("Game.Durability.Client.DurabilityClientNode")}); + } + } +} \ No newline at end of file