Skip to content

Commit

Permalink
Fix invalid file name when dumping compiler-generated methods (BepInE…
Browse files Browse the repository at this point in the history
…x#99)

I wasn't sure by which characters I should replace < and > with, but this fixes the dump when patching a compiler-generated method.
  • Loading branch information
Meivyn authored Jan 19, 2024
1 parent 2ea021a commit 11391db
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Harmony/Internal/Util/CecilEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal static class CecilEmitter

public static void Dump(MethodDefinition md, IEnumerable<string> dumpPaths, MethodBase original = null)
{
var name = $"HarmonyDump.{md.GetID(withType: false, simple: true).Replace(":", "_").Replace(" ", "_")}.{Guid.NewGuid().GetHashCode():X8}";
var name = $"HarmonyDump.{SanitizeTypeName(md.GetID(withType: false, simple: true))}.{Guid.NewGuid().GetHashCode():X8}";
var originalName = (original?.Name ?? md.Name).Replace('.', '_');
using var module = ModuleDefinition.CreateModule(name,
new ModuleParameters
Expand Down Expand Up @@ -120,4 +120,13 @@ operand is FieldReference fref &&
}
}
}

private static string SanitizeTypeName(string typeName)
{
return typeName
.Replace(":", "_")
.Replace(" ", "_")
.Replace("<", "{")
.Replace(">", "}");
}
}

0 comments on commit 11391db

Please sign in to comment.