Harmony icon indicating copy to clipboard operation
Harmony copied to clipboard

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

Open Banane9 opened this issue 1 year ago • 2 comments
trafficstars

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

  • Create a patch that fails to apply due to an error in Cecil (not sure what exactly was the problem...)
  • Observe that no replacement IL is logged.

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):

  • OS: Windows 10, 64bit
  • .NET version: Mono, 5.11.0 as .NET Framework 4.6.57.0
  • Harmony version: 2.3.1 (thin)
  • Name of game or host application: Resonite

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

Banane9 avatar Mar 06 '24 22:03 Banane9

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.

pardeike avatar Mar 07 '24 00:03 pardeike

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.

Banane9 avatar Mar 07 '24 02:03 Banane9