• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SamboyCoding / Cpp2IL / 25641285720

10 May 2026 10:18PM UTC coverage: 35.104% (-0.2%) from 35.33%
25641285720

Pull #542

github

web-flow
Merge 9249bcb5b into 6af99f218
Pull Request #542: Remove static mutable state from LibCpp2IL 2: Electric Boogaloo

1877 of 6693 branches covered (28.04%)

Branch coverage included in aggregate %.

303 of 569 new or added lines in 66 files covered. (53.25%)

12 existing lines in 11 files now uncovered.

4394 of 11171 relevant lines covered (39.33%)

268486.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.23
/LibCpp2IL/Metadata/Il2CppMethodDefinition.cs
1
using System.Linq;
2
using System.Reflection;
3
using LibCpp2IL.BinaryStructures;
4
using LibCpp2IL.Logging;
5
using LibCpp2IL.Reflection;
6

7
namespace LibCpp2IL.Metadata;
8

9
public class Il2CppMethodDefinition : ReadableClass
10
{
11
    public int nameIndex;
12
    public Il2CppVariableWidthIndex<Il2CppTypeDefinition> declaringTypeIdx;
13
    public Il2CppVariableWidthIndex<Il2CppType> returnTypeIdx;
14
    [Version(Min = 31)] public uint returnParameterToken;
15
    public Il2CppVariableWidthIndex<Il2CppParameterDefinition> parameterStart;
16
    [Version(Max = 24)] public int customAttributeIndex;
17
    public Il2CppVariableWidthIndex<Il2CppGenericContainer> genericContainerIndex;
18
    [Version(Max = 24.15f)] public int methodIndex;
19
    [Version(Max = 24.15f)] public int invokerIndex;
20
    [Version(Max = 24.15f)] public int delegateWrapperIndex;
21
    [Version(Max = 24.15f)] public int rgctxStartIndex;
22
    [Version(Max = 24.15f)] public int rgctxCount;
23
    public uint token;
24
    public ushort flags;
25
    public ushort iflags;
26
    public ushort slot;
27
    public ushort parameterCount;
28

29
    public MethodAttributes Attributes => (MethodAttributes)flags;
831,356✔
30

31
    public bool IsStatic => (Attributes & MethodAttributes.Static) != 0;
15,360✔
32

33
    public Il2CppVariableWidthIndex<Il2CppMethodDefinition> MethodIndex => OwningContext.ReflectionCache.GetMethodIndexFromMethod(this);
571,885✔
34

35
    public string? Name { get; private set; }
1,627,234✔
36

37
    public string? GlobalKey => DeclaringType == null ? null : DeclaringType.Name + "." + Name + "()";
318,193!
38

39
    public Il2CppType? RawReturnType => OwningContext.Binary.GetType(returnTypeIdx);
584,709✔
40

NEW
41
    public Il2CppTypeReflectionData? ReturnType => LibCpp2ILUtils.GetTypeReflectionData(OwningContext.Binary.GetType(returnTypeIdx));
×
42

43
    public Il2CppTypeDefinition? DeclaringType => OwningContext.Metadata.GetTypeDefinitionFromIndex(declaringTypeIdx);
3,302,074✔
44

45
    private ulong? _methodPointer = null;
46

47
    public ulong MethodPointer
48
    {
49
        get
50
        {
51
            if (!_methodPointer.HasValue)
2,841,164✔
52
            {
53
                if (DeclaringType == null)
571,885!
54
                {
NEW
55
                    LibLogger.WarnNewline($"Couldn't get method pointer for {Name}. DeclaringType is null");
×
56
                    return 0;
×
57
                }
58

59
                var asmIdx = 0; //Not needed pre-24.2
571,885✔
60
                if (MetadataVersion >= 27)
571,885✔
61
                {
62
                    asmIdx = OwningContext.Binary.GetCodegenModuleIndexByName(DeclaringType!.DeclaringAssembly!.Name!);
136,735✔
63
                }
64
                else if (MetadataVersion >= 24.2f)
435,150✔
65
                {
66
                    asmIdx = DeclaringType!.DeclaringAssembly!.assemblyIndex;
435,150✔
67
                }
68

69
                _methodPointer = OwningContext.Binary.GetMethodPointer(methodIndex, MethodIndex, asmIdx, token);
571,885✔
70
            }
71

72
            return _methodPointer.Value;
2,841,164✔
73
        }
74
    }
75

NEW
76
    public long MethodOffsetInFile => MethodPointer == 0 ? 0 : OwningContext.Binary.TryMapVirtualAddressToRaw(MethodPointer, out var ret) ? ret : 0;
×
77

NEW
78
    public ulong Rva => MethodPointer == 0 ? 0 : OwningContext.Binary.GetRva(MethodPointer);
×
79

80
    public string? HumanReadableSignature => ReturnType == null || Parameters == null || Name == null ? null : $"{ReturnType} {Name}({string.Join(", ", Parameters.AsEnumerable())})";
×
81

82
    public Il2CppParameterDefinition[]? InternalParameterData
83
    {
84
        get
85
        {
86
            if (parameterStart.IsNull || parameterCount == 0)
1,893,489✔
87
                return [];
223,757✔
88

89
            var ret = new Il2CppParameterDefinition[parameterCount];
1,669,732✔
90

91
            for (var i = 0; i < parameterCount; i++)
12,414,544✔
92
            {
93
                ret[i] = OwningContext.Metadata.GetParameterDefinitionFromIndex(Il2CppVariableWidthIndex<Il2CppParameterDefinition>.MakeTemporaryForFixedWidthUsage(parameterStart.Value + i));
4,537,540✔
94
            }
95

96
            return ret;
1,669,732✔
97
        }
98
    }
99

100
    public Il2CppType[]? InternalParameterTypes => InternalParameterData == null
×
101
        ? null
×
NEW
102
        : InternalParameterData.Select(paramDef => OwningContext.Binary.GetType(paramDef.typeIndex))
×
103
            .ToArray();
×
104

105
    private Il2CppParameterReflectionData[]? _cachedParameters;
106

107
    public Il2CppParameterReflectionData[]? Parameters
108
    {
109
        get
110
        {
111
            if (_cachedParameters == null && InternalParameterData != null)
680✔
112
            {
113
                _cachedParameters = InternalParameterData
680✔
114
                    .Select((paramDef, idx) =>
680✔
115
                    {
680✔
116
                        var paramType = OwningContext.Binary.GetType(paramDef.typeIndex);
695✔
117
                        var paramFlags = (ParameterAttributes)paramType.Attrs;
695✔
118
                        var paramDefaultData = (paramFlags & ParameterAttributes.HasDefault) != 0 
695✔
119
                            ? OwningContext.Metadata.GetParameterDefaultValueFromIndex(Il2CppVariableWidthIndex<Il2CppParameterDefinition>.MakeTemporaryForFixedWidthUsage(parameterStart.Value + idx)) //DynamicWidth: value is computed so temp usage is ok
695✔
120
                            : null;
695✔
121
                        return new Il2CppParameterReflectionData
695✔
122
                        {
695✔
123
                            Type = LibCpp2ILUtils.GetTypeReflectionData(paramType)!,
695✔
124
                            ParameterName = OwningContext.Metadata.GetStringFromIndex(paramDef.nameIndex),
695✔
125
                            Attributes = paramFlags,
695✔
126
                            RawType = paramType,
695✔
127
                            DefaultValue = paramDefaultData == null ? null : LibCpp2ILUtils.GetDefaultValue(paramDefaultData.dataIndex, paramDefaultData.typeIndex, OwningContext),
695✔
128
                            ParameterIndex = idx,
695✔
129
                        };
695✔
130
                    }).ToArray();
680✔
131
            }
132

133
            return _cachedParameters;
680✔
134
        }
135
    }
136

137
    public Il2CppGenericContainer? GenericContainer => genericContainerIndex.IsNull ? null : OwningContext.Metadata.GetGenericContainerFromIndex(genericContainerIndex);
124,854✔
138
    
139
    public bool IsUnmanagedCallersOnly => (iflags & 0xF000) != 0;
87,030✔
140
    
141
    public MethodImplAttributes MethodImplAttributes => (MethodImplAttributes)(iflags & ~0xF000);
87,030✔
142

143
    public override string? ToString()
144
    {
145
        return $"Il2CppMethodDefinition[Name='{Name}', ReturnType={ReturnType}, DeclaringType={DeclaringType}]";
×
146
    }
147

148
    public override void Read(ClassReadingBinaryReader reader)
149
    {
150
        nameIndex = reader.ReadInt32();
1,221,337✔
151

152
        //Cache name now
153
        var pos = reader.Position;
1,221,337✔
154
        Name = ((Il2CppMetadata)reader).ReadStringFromIndexNoReadLock(nameIndex);
1,221,337✔
155
        reader.Position = pos;
1,221,337✔
156

157
        declaringTypeIdx = Il2CppVariableWidthIndex<Il2CppTypeDefinition>.Read(reader);
1,221,337✔
158
        returnTypeIdx = Il2CppVariableWidthIndex<Il2CppType>.Read(reader);
1,221,337✔
159

160
        if (IsAtLeast(31))
1,221,337✔
161
            returnParameterToken = reader.ReadUInt32();
136,735✔
162

163
        parameterStart = Il2CppVariableWidthIndex<Il2CppParameterDefinition>.Read(reader);
1,221,337✔
164

165
        if (IsAtMost(24))
1,221,337!
166
            customAttributeIndex = reader.ReadInt32();
×
167

168
        genericContainerIndex = Il2CppVariableWidthIndex<Il2CppGenericContainer>.Read(reader);
1,221,337✔
169

170
        if (IsAtMost(24.15f))
1,221,337✔
171
        {
172
            methodIndex = reader.ReadInt32();
177,366✔
173
            invokerIndex = reader.ReadInt32();
177,366✔
174
            delegateWrapperIndex = reader.ReadInt32();
177,366✔
175
            rgctxStartIndex = reader.ReadInt32();
177,366✔
176
            rgctxCount = reader.ReadInt32();
177,366✔
177
        }
178

179
        token = reader.ReadUInt32();
1,221,337✔
180

181
        flags = reader.ReadUInt16();
1,221,337✔
182
        iflags = reader.ReadUInt16();
1,221,337✔
183
        slot = reader.ReadUInt16();
1,221,337✔
184
        parameterCount = reader.ReadUInt16();
1,221,337✔
185
    }
1,221,337✔
186
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc