Unofficial CardLife revival project, pronounced like "celery"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.5KB

  1. using System.Reflection;
  2. using HarmonyLib;
  3. namespace CLre.Fixes
  4. {
  5. [Bugfix(name = "ClientDurabilityNodeErrorRemover",
  6. description = "Disable OnServerNotifyChange() callback when it will error",
  7. more = "https://trello.com/c/YT3VbXpZ/15-durability-log-error",
  8. component = BugfixType.API, id = 3)]
  9. public static class DurabilityNodeErrorRemover
  10. {
  11. public static void Disable() => DurabilityGUIEngineClient_OnServerNotifyChange_Patch.IsDisabled = true;
  12. public static void Enable() => DurabilityGUIEngineClient_OnServerNotifyChange_Patch.IsDisabled = false;
  13. }
  14. [Bugfix(name = "ClientDurabilityNodeErrorRemover",
  15. description = "Disable OnServerNotifyChange() callback when it will error",
  16. more = "https://trello.com/c/YT3VbXpZ/15-durability-log-error",
  17. component = BugfixType.HarmonyPatch, id = 3)]
  18. [HarmonyPatch]
  19. class DurabilityGUIEngineClient_OnServerNotifyChange_Patch
  20. {
  21. internal static bool AnyDurabilityClientNodeExists = false;
  22. internal static bool IsDisabled = false;
  23. [HarmonyPrefix]
  24. public static bool BeforeMethodCall()
  25. {
  26. #if DEBUG
  27. API.Utility.Logging.MetaLog("Intercepting DurabilityGUIEngineClient.OnServerNotifyChange()");
  28. #endif
  29. return AnyDurabilityClientNodeExists || IsDisabled;
  30. }
  31. [HarmonyTargetMethod]
  32. public static MethodBase Target()
  33. {
  34. return AccessTools.Method("Game.Durability.Client.DurabilityGUIEngineClient:OnServerNotifyChange");
  35. }
  36. }
  37. [Bugfix(name = "ClientDurabilityNodeErrorRemover",
  38. description = "Disable OnServerNotifyChange() callback when it will error",
  39. more = "https://trello.com/c/YT3VbXpZ/15-durability-log-error",
  40. component = BugfixType.HarmonyPatch, id = 3)]
  41. [HarmonyPatch]
  42. class DurabilityGUIEngineClientSplit_Add_Patch
  43. {
  44. [HarmonyPrefix]
  45. public static void BeforeMethodCall()
  46. {
  47. #if DEBUG
  48. API.Utility.Logging.MetaLog("Intercepting DurabilityGUIEngineClientSplit.Add()");
  49. #endif
  50. DurabilityGUIEngineClient_OnServerNotifyChange_Patch.AnyDurabilityClientNodeExists = true;
  51. }
  52. [HarmonyTargetMethod]
  53. public static MethodBase Target()
  54. {
  55. return AccessTools.Method("Game.Durability.Client.DurabilityGuiEngineClientSplit:Add", new []{ AccessTools.TypeByName("Game.Durability.Client.DurabilityClientNode")});
  56. }
  57. }
  58. }