diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs index 3e4a7744..94a989a9 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Correction.cs @@ -47,12 +47,13 @@ namespace IPA.Config.Stores il.Emit(OpCodes.Call, member.Nullable_Value.GetGetMethod()); } - if (!member.ConversionType.IsValueType) + var convType = member.ConversionType; + if (!convType.IsValueType) { // currently the only thing for this is where expect == Map, so do generate shit - var copyFrom = typeof(IGeneratedStore<>).MakeGenericType(member.ConversionType).GetMethod(nameof(IGeneratedStore.CopyFrom)); + var copyFrom = typeof(IGeneratedStore<>).MakeGenericType(convType).GetMethod(nameof(IGeneratedStore.CopyFrom)); var noCreate = il.DefineLabel(); - var valLocal = GetLocal(member.Type); + var valLocal = GetLocal(convType); if (!alwaysNew) { @@ -69,7 +70,7 @@ namespace IPA.Config.Stores il.Emit(OpCodes.Brtrue_S, noCreate); il.Emit(OpCodes.Pop); } - EmitCreateChildGenerated(il, member.Type, parentobj); + EmitCreateChildGenerated(il, convType, parentobj); il.MarkLabel(noCreate); il.Emit(OpCodes.Dup); @@ -79,7 +80,12 @@ namespace IPA.Config.Stores } else { - // TODO: impl the rest of this + // for special value types, we'll go ahead and correct each of their members + var structure = ReadObjectMembers(convType); + + var valueLocal = GetLocal(convType); + il.Emit(OpCodes.Stloc, valueLocal); + } if (member.IsNullable) @@ -87,5 +93,15 @@ namespace IPA.Config.Stores il.MarkLabel(endLabel); } + + private static void EmitLoadCorrectStore(ILGenerator il, SerializedMemberInfo member, bool shouldLock, bool alwaysNew, GetLocal GetLocal, + Action loadFrom, Action storeTo, Action parentobj) + { + EmitStore(il, member, il => + { + EmitLoad(il, member, loadFrom); // load the member + EmitCorrectMember(il, member, shouldLock, alwaysNew, GetLocal, storeTo, parentobj); // correct it + }, storeTo); + } } } diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs index f8ccffd4..00ec352b 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/MakeCreator.cs @@ -124,11 +124,7 @@ namespace IPA.Config.Stores foreach (var member in structure) { - EmitStore(il, member, il => - { - EmitLoad(il, member, GetMethodThis); // load the member - EmitCorrectMember(il, member, false, true, GetLocal, GetMethodThis, GetMethodThis); // correct it - }, GetMethodThis); + EmitLoadCorrectStore(il, member, false, true, GetLocal, GetMethodThis, GetMethodThis, GetMethodThis); } il.Emit(OpCodes.Pop); @@ -594,11 +590,7 @@ namespace IPA.Config.Stores { il.BeginExceptionBlock(); - EmitStore(il, member, il => - { - EmitLoad(il, member, il => il.Emit(OpCodes.Ldarg_1)); - EmitCorrectMember(il, member, false, false, GetLocal, GetMethodThis, GetMethodThis); - }, GetMethodThis); + EmitLoadCorrectStore(il, member, false, false, GetLocal, il => il.Emit(OpCodes.Ldarg_1), GetMethodThis, GetMethodThis); il.BeginCatchBlock(typeof(Exception));