pardeike / Harmony

A library for patching, replacing and decorating .NET and Mono methods during runtime
https://www.patreon.com/pardeike
MIT License
5.15k stars 485 forks source link

When applying a patch fails, the replacement's IL is not printed to the debug log #597

Open Banane9 opened 6 months ago

Banane9 commented 6 months ago

Describe the bug When using the [HarmonyDebug] attributes or setting Harmony.DEBUG = true, the replacement's IL should be logged to the Harmony.log.txt file. However, when the construction of the method fails because of Cecil, no replacement IL is logged.

To Reproduce

Harmony.log.txt output with blank replacements

Exception that caused the patch to fail

Expected behavior The IL constructed for the replacement should always be logged, before it is finalized with Cecil and potentially fails to log.

Screenshots / Code See Reproduction.

Runtime environment (please complete the following information):

Additional context Discussion in discord starting here: https://discord.com/channels/131466550938042369/361891646742462467/1215048908628299787

pardeike commented 6 months ago

Transpiler are chained and their results is collected, then logged. If an exceptions occurs in a transpiler there is no result yet. Which means there is nothing to log.

Banane9 commented 6 months ago

If an exceptions occurs in a transpiler there is no result yet.

But there is no exception in the transpiler - the exception occurs in Cecil when Harmony tries to "compile" the CodeInstructions back into a replacement method. But it looks like the logging only occurs after that step, which makes it hard to tell what the problem with the IL was.