HarmonyX
HarmonyX copied to clipboard
Patch method generation fail should not mark the patch as applied
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.