From 637f9f37dec5c9252487e2cddfc4cc061a6746f4 Mon Sep 17 00:00:00 2001 From: Wartori54 Date: Fri, 12 Jul 2024 20:58:08 +0200 Subject: [PATCH] Replace FieldReference to correct the TokenType --- Celeste.Mod.mm/Patches/TextMenu.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Celeste.Mod.mm/Patches/TextMenu.cs b/Celeste.Mod.mm/Patches/TextMenu.cs index 4399d2e65..b6475b62b 100644 --- a/Celeste.Mod.mm/Patches/TextMenu.cs +++ b/Celeste.Mod.mm/Patches/TextMenu.cs @@ -572,18 +572,19 @@ class PatchTextMenuSettingUpdateAttribute : Attribute { } static partial class MonoModRules { public static void PatchTextMenuOptionColor(ILContext context, CustomAttribute attrib) { - FieldReference f_UnselectedColor = context.Method.DeclaringType.FindField("UnselectedColor"); + FieldReference f_UnselectedColor = context.Method.DeclaringType.FindField("UnselectedColor")!; //Explicitly instantiate the generic Option type - GenericInstanceType genericInst = new GenericInstanceType(f_UnselectedColor.DeclaringType); + GenericInstanceType genericInst = new(f_UnselectedColor.DeclaringType); genericInst.GenericArguments.AddRange(f_UnselectedColor.DeclaringType.GenericParameters); - f_UnselectedColor.DeclaringType = genericInst; + // Replace the FieldReference in order to generate a `TokenType.MemberRef` (fields read from binary data use `TokenType.Field`) + f_UnselectedColor = new FieldReference(f_UnselectedColor.Name, f_UnselectedColor.FieldType, genericInst); ILCursor cursor = new ILCursor(context); cursor.GotoNext(instr => instr.MatchCall("Microsoft.Xna.Framework.Color", "get_White")); cursor.Emit(OpCodes.Ldarg_0); - cursor.Next.OpCode = OpCodes.Ldfld; - cursor.Next.Operand = f_UnselectedColor; + cursor.Next!.OpCode = OpCodes.Ldfld; + cursor.Next!.Operand = f_UnselectedColor; } public static void PatchTextMenuSettingUpdate(ILContext il, CustomAttribute _) {