diff --git a/Torch/Managers/PatchManager/MSIL/MsilInstructionExtensions.cs b/Torch/Managers/PatchManager/MSIL/MsilInstructionExtensions.cs
index 4629f7f..74b8912 100644
--- a/Torch/Managers/PatchManager/MSIL/MsilInstructionExtensions.cs
+++ b/Torch/Managers/PatchManager/MSIL/MsilInstructionExtensions.cs
@@ -198,5 +198,73 @@ namespace Torch.Managers.PatchManager.MSIL
return new MsilInstruction(argument.Position < 0xFF ? OpCodes.Ldarga_S : OpCodes.Ldarga).InlineValue(argument);
}
#endregion
+
+ #region Constant Utils
+ ///
+ /// Determines if this instruction is a constant int load instruction.
+ ///
+ /// Instruction
+ /// True if this instruction pushes a constant int onto the stack
+ public static bool IsConstIntLoad(this MsilInstruction m)
+ {
+ if (m.OpCode == OpCodes.Ldc_I4_0)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_1)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_2)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_3)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_4)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_5)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_6)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_7)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_8)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4_M1)
+ return true;
+ if (m.OpCode == OpCodes.Ldc_I4)
+ return true;
+ return m.OpCode == OpCodes.Ldc_I4_S;
+ }
+
+ ///
+ /// Gets the constant int this instruction pushes onto the stack.
+ ///
+ /// Instruction
+ /// The constant int
+ public static int GetConstInt(this MsilInstruction m)
+ {
+ if (m.OpCode == OpCodes.Ldc_I4_0)
+ return 0;
+ if (m.OpCode == OpCodes.Ldc_I4_1)
+ return 1;
+ if (m.OpCode == OpCodes.Ldc_I4_2)
+ return 2;
+ if (m.OpCode == OpCodes.Ldc_I4_3)
+ return 3;
+ if (m.OpCode == OpCodes.Ldc_I4_4)
+ return 4;
+ if (m.OpCode == OpCodes.Ldc_I4_5)
+ return 5;
+ if (m.OpCode == OpCodes.Ldc_I4_6)
+ return 6;
+ if (m.OpCode == OpCodes.Ldc_I4_7)
+ return 7;
+ if (m.OpCode == OpCodes.Ldc_I4_8)
+ return 8;
+ if (m.OpCode == OpCodes.Ldc_I4_M1)
+ return -1;
+ if (m.OpCode == OpCodes.Ldc_I4)
+ return ((MsilOperandInline) m.Operand).Value;
+ if (m.OpCode == OpCodes.Ldc_I4_S)
+ return ((MsilOperandInline)m.Operand).Value;
+ throw new ArgumentException($"Can't get constant int from instruction {m}");
+ }
+ #endregion
}
}