diff --git a/Harmony/Internal/DynamicTools.cs b/Harmony/Internal/DynamicTools.cs index ea9471e0..e3e33ad1 100644 --- a/Harmony/Internal/DynamicTools.cs +++ b/Harmony/Internal/DynamicTools.cs @@ -70,6 +70,7 @@ internal static LocalBuilder[] DeclareLocalVariables(MethodBase original, ILGene internal static LocalBuilder DeclareLocalVariable(ILGenerator generator, Type type) { if (type.IsByRef) type = type.GetElementType(); + if (type.IsEnum) type = Enum.GetUnderlyingType(type); if (AccessTools.IsClass(type)) { @@ -92,7 +93,7 @@ internal static LocalBuilder DeclareLocalVariable(ILGenerator generator, Type ty Emitter.Emit(generator, OpCodes.Ldc_R4, (float)0); else if (type == typeof(double)) Emitter.Emit(generator, OpCodes.Ldc_R8, (double)0); - else if (type == typeof(long)) + else if (type == typeof(long) || type == typeof(ulong)) Emitter.Emit(generator, OpCodes.Ldc_I8, (long)0); else Emitter.Emit(generator, OpCodes.Ldc_I4, 0);