Skip to content

Commit

Permalink
Merge pull request #794 from Wartori54/text-menu-cecil-missuse
Browse files Browse the repository at this point in the history
Replace FieldReference to correct the TokenType
  • Loading branch information
maddie480 authored Jul 16, 2024
2 parents d825d6f + 637f9f3 commit 5c387ef
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Celeste.Mod.mm/Patches/TextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> 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 _) {
Expand Down

0 comments on commit 5c387ef

Please sign in to comment.