@@ -5,16 +5,36 @@ namespace LibCpp2IL.BinaryStructures;
55
66public class Il2CppRGCTXDefinition : ReadableClass
77{
8+ // Populated by Il2CppBinary.Init (codegen module init) for per-context usage.
9+ internal Il2CppBinary ? OwningBinary { get ; set ; }
10+ internal Il2CppMetadata ? OwningMetadata { get ; set ; }
11+
812 public Il2CppRGCTXDataType type ;
913 public int _rawIndex ;
1014
1115 public int MethodIndex => _defData ? . MethodIndex ?? _constrainedData ! . MethodIndex ;
1216
1317 public int TypeIndex => _defData ? . TypeIndex ?? _constrainedData ! . TypeIndex ;
1418
15- public Il2CppMethodSpec ? MethodSpec => LibCpp2IlMain . Binary ? . GetMethodSpec ( MethodIndex ) ;
19+ public Il2CppMethodSpec ? MethodSpec
20+ {
21+ get
22+ {
23+ var binary = OwningBinary ?? LibCpp2IlMain . Binary ;
24+ return binary ? . GetMethodSpec ( MethodIndex ) ;
25+ }
26+ }
1627
17- public Il2CppTypeReflectionData ? Type => LibCpp2ILUtils . GetTypeReflectionData ( LibCpp2IlMain . Binary ! . GetType ( Il2CppVariableWidthIndex < Il2CppType > . MakeTemporaryForFixedWidthUsage ( TypeIndex ) ) ) ;
28+ public Il2CppTypeReflectionData ? Type
29+ {
30+ get
31+ {
32+ var binary = OwningBinary ?? LibCpp2IlMain . Binary ;
33+ if ( binary == null ) return null ;
34+ var t = binary . GetType ( Il2CppVariableWidthIndex < Il2CppType > . MakeTemporaryForFixedWidthUsage ( TypeIndex ) ) ;
35+ return LibCpp2ILUtils . GetTypeReflectionData ( t ) ;
36+ }
37+ }
1838
1939
2040 public class Il2CppRGCTXDefinitionData : ReadableClass
@@ -45,6 +65,7 @@ public override void Read(ClassReadingBinaryReader reader)
4565 private Il2CppRGCTXConstrainedData ? _constrainedData ;
4666
4767 private Il2CppRGCTXDefinitionData ? _defData ;
68+
4869 public override void Read ( ClassReadingBinaryReader reader )
4970 {
5071 type = IsLessThan ( 29 ) ? ( Il2CppRGCTXDataType ) reader . ReadInt32 ( ) : ( Il2CppRGCTXDataType ) reader . ReadInt64 ( ) ;
@@ -56,24 +77,30 @@ public override void Read(ClassReadingBinaryReader reader)
5677 else
5778 {
5879 var va = reader . ReadNUint ( ) ;
80+ var bakPosition = reader . Position ;
81+
82+ var binary = OwningBinary ?? LibCpp2IlMain . Binary ;
83+ if ( binary == null )
84+ {
85+ // Can't resolve VA -> raw without a binary context. Leave as-is.
86+ reader . Position = bakPosition ;
87+ return ;
88+ }
89+
90+ reader . Position = binary . MapVirtualAddressToRaw ( va ) ;
91+
5992 if ( type == Il2CppRGCTXDataType . IL2CPP_RGCTX_DATA_CONSTRAINED )
6093 {
61- var bakPosition = reader . Position ;
62- reader . Position = LibCpp2IlMain . Binary ! . MapVirtualAddressToRaw ( va ) ;
6394 _constrainedData = new Il2CppRGCTXConstrainedData ( ) ;
6495 _constrainedData . Read ( reader ) ;
65- reader . Position = bakPosition ;
6696 }
6797 else
6898 {
69- var bakPosition = reader . Position ;
70- reader . Position = LibCpp2IlMain . Binary ! . MapVirtualAddressToRaw ( va ) ;
7199 _defData = new Il2CppRGCTXDefinitionData ( ) ;
72100 _defData . Read ( reader ) ;
73- reader . Position = bakPosition ;
74101 }
75102
103+ reader . Position = bakPosition ;
76104 }
77-
78105 }
79106}
0 commit comments