From 354527bb810d06f69f2a8c45d1a23f294d228caf Mon Sep 17 00:00:00 2001 From: Shockah Date: Wed, 9 Feb 2022 21:02:41 +0100 Subject: stop proxying nulls --- src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs b/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs index 99aea75c..1b6bf1d6 100644 --- a/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs +++ b/src/SMAPI/Framework/Reflection/InterfaceProxyBuilder.cs @@ -265,12 +265,24 @@ namespace StardewModdingAPI.Framework.Reflection } else { - // this.Glue.CreateInstanceForProxyTypeName(proxyTypeName, this.Instance.Call(args)) + var resultLocal = il.DeclareLocal(typeof(object)); // we store both unmodified and modified in here + EmitCallInstance(); + il.Emit(OpCodes.Stloc, resultLocal); + + // if (unmodifiedResultLocal == null) jump + var isNullLabel = il.DefineLabel(); + il.Emit(OpCodes.Ldloc, resultLocal); + il.Emit(OpCodes.Brfalse, isNullLabel); + il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldfld, glueField); il.Emit(OpCodes.Ldstr, returnValueProxyTypeName); - EmitCallInstance(); + il.Emit(OpCodes.Ldloc, resultLocal); il.Emit(OpCodes.Call, CreateInstanceForProxyTypeNameMethod); + il.Emit(OpCodes.Stloc, resultLocal); + + il.MarkLabel(isNullLabel); + il.Emit(OpCodes.Ldloc, resultLocal); } // return result -- cgit