diff --git a/NLog.config b/NLog.config
index 270fe34..3ac0285 100644
--- a/NLog.config
+++ b/NLog.config
@@ -12,6 +12,6 @@
-
+
\ No newline at end of file
diff --git a/Torch/Managers/PatchManager/MSIL/MsilInstruction.cs b/Torch/Managers/PatchManager/MSIL/MsilInstruction.cs
index b4f6281..4614098 100644
--- a/Torch/Managers/PatchManager/MSIL/MsilInstruction.cs
+++ b/Torch/Managers/PatchManager/MSIL/MsilInstruction.cs
@@ -1,5 +1,7 @@
using System;
+using System.Collections.Concurrent;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
@@ -103,6 +105,9 @@ namespace Torch.Managers.PatchManager.MSIL
///
public HashSet Labels { get; } = new HashSet();
+
+ private static readonly ConcurrentDictionary _setterInfoForInlines = new ConcurrentDictionary();
+
///
/// Sets the inline value for this instruction.
///
@@ -111,6 +116,23 @@ namespace Torch.Managers.PatchManager.MSIL
/// This instruction
public MsilInstruction InlineValue(T o)
{
+ Type type = typeof(T);
+ while (type != null)
+ {
+ if (!_setterInfoForInlines.TryGetValue(type, out PropertyInfo target))
+ {
+ Type genType = typeof(MsilOperandInline<>).MakeGenericType(type);
+ target = genType.GetProperty(nameof(MsilOperandInline.Value));
+ _setterInfoForInlines[type] = target;
+ }
+ Debug.Assert(target?.DeclaringType != null);
+ if (target.DeclaringType.IsInstanceOfType(Operand))
+ {
+ target.SetValue(Operand, o);
+ return this;
+ }
+ type = type.BaseType;
+ }
((MsilOperandInline)Operand).Value = o;
return this;
}
diff --git a/Torch/Managers/PatchManager/Transpile/MethodContext.cs b/Torch/Managers/PatchManager/Transpile/MethodContext.cs
index 1e69606..7d316f7 100644
--- a/Torch/Managers/PatchManager/Transpile/MethodContext.cs
+++ b/Torch/Managers/PatchManager/Transpile/MethodContext.cs
@@ -143,7 +143,7 @@ namespace Torch.Managers.PatchManager.Transpile
public string ToHumanMsil()
{
- return string.Join("\n", _instructions.Select(x => $"IL_{x.Offset:X4}: {x.StackChange()} {x}"));
+ return string.Join("\n", _instructions.Select(x => $"IL_{x.Offset:X4}: {x.StackChange():+0;-#} {x}"));
}
private static readonly Dictionary OpCodeLookup;
diff --git a/Torch/Managers/PatchManager/Transpile/MethodTranspiler.cs b/Torch/Managers/PatchManager/Transpile/MethodTranspiler.cs
index 25ea7dc..33faedb 100644
--- a/Torch/Managers/PatchManager/Transpile/MethodTranspiler.cs
+++ b/Torch/Managers/PatchManager/Transpile/MethodTranspiler.cs
@@ -16,8 +16,8 @@ namespace Torch.Managers.PatchManager.Transpile
var context = new MethodContext(baseMethod);
context.Read();
context.CheckIntegrity();
- _log.Trace("Input Method:");
- _log.Trace(context.ToHumanMsil);
+// _log.Trace("Input Method:");
+// _log.Trace(context.ToHumanMsil);
var methodContent = (IEnumerable)context.Instructions;
foreach (var transpiler in transpilers)