HarmonyX icon indicating copy to clipboard operation
HarmonyX copied to clipboard

Patch method generation fail should not mark the patch as applied

Open ghorsington opened this issue 1 year ago • 0 comments

This needs more testing but based on initial reports:

When patch method generation fails, it appears that the patch is still marked as applied. This is likely because patch info is saved into a global state before the patch method is updated:

https://github.com/BepInEx/HarmonyX/blob/66b85747466feb874924376ace6ca346d39dab5e/Harmony/Public/PatchProcessor.cs#L159-L169

same for all other places where PatchFunctions.UpdateWrapper is called.

This causes more issues when trying to unpatch or add more patches in.

The logic should be refined as follows:

  • Update the patch state
  • Generate patch method and apply it
  • If the patch method cannot be applied, revert the patch info to the previous state

A functionally more stable approach might be to back up the previous patch state so it can be quickly restored.

ghorsington avatar Jul 29 '22 18:07 ghorsington