Skip to content

Unstrip ldtoken for fields #263

@ds5678

Description

@ds5678

As far as I know, this instruction is only used for array initializers that have constant data. I wrote a helper method:

public static Il2CppSystem.RuntimeFieldHandle ManagedFieldToIl2CppField(System.RuntimeMethodHandle handle)
{
    var methodInfo = System.Reflection.MethodInfo.GetMethodFromHandle(handle)!;
    var fieldInfoField = Il2CppInteropUtils.GetIl2CppFieldInfoPointerFieldForGeneratedFieldAccessor(methodInfo)!;
    var fieldInfoPtr = (nint)fieldInfoField.GetValue(null)!;
    var fieldInfo = (Il2CppSystem.Reflection.FieldInfo)Il2CppObjectPool.Get(fieldInfoPtr)!; // Not sure if this is how it works
    return fieldInfo.FieldHandle;
}

The unstripped code would be:

  • Use ldtoken on the get method of the field accessor property. There is no C# equivalent to this, but the runtime should handle it fine.
  • Call the helper method.

However, this would require either:

  • Support for constant field data in type injection
  • Refusing to translate ldtoken for unstripped fields

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions