From b4695a539b68e48ae2736cb7e4a2505391c99fa1 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Thu, 26 Feb 2026 11:33:24 -0800 Subject: [PATCH 1/2] Add implicit conversion operator from Il2CppVariableWidthIndex to int --- LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs b/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs index 0882f52c..0ef203c5 100644 --- a/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs +++ b/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Threading; namespace LibCpp2IL.Metadata; @@ -14,7 +14,7 @@ namespace LibCpp2IL.Metadata; /// - v105 extends this to MethodIndex /// /// -public record struct Il2CppVariableWidthIndex where T : ReadableClass +public readonly record struct Il2CppVariableWidthIndex where T : ReadableClass { //Statics here are per-T. private static int widthForThisTypeOnCurrentApplication = -1; // -1 means "not yet determined" @@ -27,7 +27,7 @@ public record struct Il2CppVariableWidthIndex where T : ReadableClass /// private static object readSessionLock = new object(); - private int value; + private readonly int value; public bool IsNull => value < 0; //The exact value of the "null" index depends on the width public bool IsNonNull => !IsNull; @@ -102,4 +102,6 @@ internal static void EndReadSession() widthForThisTypeOnCurrentApplication = -1; Monitor.Exit(readSessionLock); } + + public static implicit operator int(Il2CppVariableWidthIndex index) => index.value; } From 8988a436da8f4faaf289187f1745f68835de27dc Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Thu, 26 Feb 2026 11:37:35 -0800 Subject: [PATCH 2/2] Remove implicit operator --- LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs b/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs index 0ef203c5..e4bb306b 100644 --- a/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs +++ b/LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs @@ -102,6 +102,4 @@ internal static void EndReadSession() widthForThisTypeOnCurrentApplication = -1; Monitor.Exit(readSessionLock); } - - public static implicit operator int(Il2CppVariableWidthIndex index) => index.value; }