3
3
using Mono . Collections . Generic ;
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . IO ;
6
7
using System . Linq ;
7
8
8
9
namespace Il2CppDumper
@@ -18,6 +19,7 @@ public class DummyAssemblyGenerator
18
19
private Dictionary < Il2CppGenericParameter , GenericParameter > genericParameterDic = new Dictionary < Il2CppGenericParameter , GenericParameter > ( ) ;
19
20
private MethodDefinition attributeAttribute ;
20
21
private TypeReference stringType ;
22
+ private TypeSystem typeSystem ;
21
23
private Dictionary < int , FieldDefinition > fieldDefinitionDic = new Dictionary < int , FieldDefinition > ( ) ;
22
24
private Dictionary < int , PropertyDefinition > propertyDefinitionDic = new Dictionary < int , PropertyDefinition > ( ) ;
23
25
private Dictionary < int , MethodDefinition > methodDefinitionDic = new Dictionary < int , MethodDefinition > ( ) ;
@@ -29,14 +31,16 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor, bool addToken)
29
31
il2Cpp = il2CppExecutor . il2Cpp ;
30
32
31
33
//Il2CppDummyDll
32
- var il2CppDummyDll = Il2CppDummyDll . Create ( ) ;
34
+ var il2CppDummyDll = AssemblyDefinition . ReadAssembly ( new MemoryStream ( Resource1 . Il2CppDummyDll ) ) ;
33
35
Assemblies . Add ( il2CppDummyDll ) ;
34
- var addressAttribute = il2CppDummyDll . MainModule . Types . First ( x => x . Name == "AddressAttribute" ) . Methods [ 0 ] ;
35
- var fieldOffsetAttribute = il2CppDummyDll . MainModule . Types . First ( x => x . Name == "FieldOffsetAttribute" ) . Methods [ 0 ] ;
36
- attributeAttribute = il2CppDummyDll . MainModule . Types . First ( x => x . Name == "AttributeAttribute" ) . Methods [ 0 ] ;
37
- var metadataOffsetAttribute = il2CppDummyDll . MainModule . Types . First ( x => x . Name == "MetadataOffsetAttribute" ) . Methods [ 0 ] ;
38
- var tokenAttribute = il2CppDummyDll . MainModule . Types . First ( x => x . Name == "TokenAttribute" ) . Methods [ 0 ] ;
39
- stringType = il2CppDummyDll . MainModule . TypeSystem . String ;
36
+ var dummyMD = il2CppDummyDll . MainModule ;
37
+ var addressAttribute = dummyMD . Types . First ( x => x . Name == "AddressAttribute" ) . Methods [ 0 ] ;
38
+ var fieldOffsetAttribute = dummyMD . Types . First ( x => x . Name == "FieldOffsetAttribute" ) . Methods [ 0 ] ;
39
+ attributeAttribute = dummyMD . Types . First ( x => x . Name == "AttributeAttribute" ) . Methods [ 0 ] ;
40
+ var metadataOffsetAttribute = dummyMD . Types . First ( x => x . Name == "MetadataOffsetAttribute" ) . Methods [ 0 ] ;
41
+ var tokenAttribute = dummyMD . Types . First ( x => x . Name == "TokenAttribute" ) . Methods [ 0 ] ;
42
+ stringType = dummyMD . TypeSystem . String ;
43
+ typeSystem = dummyMD . TypeSystem ;
40
44
41
45
var resolver = new MyAssemblyResolver ( ) ;
42
46
var moduleParameters = new ModuleParameters
@@ -217,7 +221,7 @@ public DummyAssemblyGenerator(Il2CppExecutor il2CppExecutor, bool addToken)
217
221
{
218
222
var methodDef = metadata . methodDefs [ i ] ;
219
223
var methodName = metadata . GetStringFromIndex ( methodDef . nameIndex ) ;
220
- var methodDefinition = new MethodDefinition ( methodName , ( MethodAttributes ) methodDef . flags , typeDefinition . Module . ImportReference ( typeof ( void ) ) ) ;
224
+ var methodDefinition = new MethodDefinition ( methodName , ( MethodAttributes ) methodDef . flags , typeDefinition . Module . ImportReference ( typeSystem . Void ) ) ;
221
225
methodDefinition . ImplAttributes = ( MethodImplAttributes ) methodDef . iflags ;
222
226
typeDefinition . Methods . Add ( methodDefinition ) ;
223
227
//genericParameter
@@ -462,41 +466,41 @@ private TypeReference GetTypeReference(MemberReference memberReference, Il2CppTy
462
466
switch ( il2CppType . type )
463
467
{
464
468
case Il2CppTypeEnum . IL2CPP_TYPE_OBJECT :
465
- return moduleDefinition . ImportReference ( typeof ( object ) ) ;
469
+ return moduleDefinition . ImportReference ( typeSystem . Object ) ;
466
470
case Il2CppTypeEnum . IL2CPP_TYPE_VOID :
467
- return moduleDefinition . ImportReference ( typeof ( void ) ) ;
471
+ return moduleDefinition . ImportReference ( typeSystem . Void ) ;
468
472
case Il2CppTypeEnum . IL2CPP_TYPE_BOOLEAN :
469
- return moduleDefinition . ImportReference ( typeof ( bool ) ) ;
473
+ return moduleDefinition . ImportReference ( typeSystem . Boolean ) ;
470
474
case Il2CppTypeEnum . IL2CPP_TYPE_CHAR :
471
- return moduleDefinition . ImportReference ( typeof ( char ) ) ;
475
+ return moduleDefinition . ImportReference ( typeSystem . Char ) ;
472
476
case Il2CppTypeEnum . IL2CPP_TYPE_I1 :
473
- return moduleDefinition . ImportReference ( typeof ( sbyte ) ) ;
477
+ return moduleDefinition . ImportReference ( typeSystem . SByte ) ;
474
478
case Il2CppTypeEnum . IL2CPP_TYPE_U1 :
475
- return moduleDefinition . ImportReference ( typeof ( byte ) ) ;
479
+ return moduleDefinition . ImportReference ( typeSystem . Byte ) ;
476
480
case Il2CppTypeEnum . IL2CPP_TYPE_I2 :
477
- return moduleDefinition . ImportReference ( typeof ( short ) ) ;
481
+ return moduleDefinition . ImportReference ( typeSystem . Int16 ) ;
478
482
case Il2CppTypeEnum . IL2CPP_TYPE_U2 :
479
- return moduleDefinition . ImportReference ( typeof ( ushort ) ) ;
483
+ return moduleDefinition . ImportReference ( typeSystem . UInt16 ) ;
480
484
case Il2CppTypeEnum . IL2CPP_TYPE_I4 :
481
- return moduleDefinition . ImportReference ( typeof ( int ) ) ;
485
+ return moduleDefinition . ImportReference ( typeSystem . Int32 ) ;
482
486
case Il2CppTypeEnum . IL2CPP_TYPE_U4 :
483
- return moduleDefinition . ImportReference ( typeof ( uint ) ) ;
487
+ return moduleDefinition . ImportReference ( typeSystem . UInt32 ) ;
484
488
case Il2CppTypeEnum . IL2CPP_TYPE_I :
485
- return moduleDefinition . ImportReference ( typeof ( IntPtr ) ) ;
489
+ return moduleDefinition . ImportReference ( typeSystem . IntPtr ) ;
486
490
case Il2CppTypeEnum . IL2CPP_TYPE_U :
487
- return moduleDefinition . ImportReference ( typeof ( UIntPtr ) ) ;
491
+ return moduleDefinition . ImportReference ( typeSystem . UIntPtr ) ;
488
492
case Il2CppTypeEnum . IL2CPP_TYPE_I8 :
489
- return moduleDefinition . ImportReference ( typeof ( long ) ) ;
493
+ return moduleDefinition . ImportReference ( typeSystem . Int64 ) ;
490
494
case Il2CppTypeEnum . IL2CPP_TYPE_U8 :
491
- return moduleDefinition . ImportReference ( typeof ( ulong ) ) ;
495
+ return moduleDefinition . ImportReference ( typeSystem . UInt64 ) ;
492
496
case Il2CppTypeEnum . IL2CPP_TYPE_R4 :
493
- return moduleDefinition . ImportReference ( typeof ( float ) ) ;
497
+ return moduleDefinition . ImportReference ( typeSystem . Single ) ;
494
498
case Il2CppTypeEnum . IL2CPP_TYPE_R8 :
495
- return moduleDefinition . ImportReference ( typeof ( double ) ) ;
499
+ return moduleDefinition . ImportReference ( typeSystem . Double ) ;
496
500
case Il2CppTypeEnum . IL2CPP_TYPE_STRING :
497
- return moduleDefinition . ImportReference ( typeof ( string ) ) ;
501
+ return moduleDefinition . ImportReference ( typeSystem . String ) ;
498
502
case Il2CppTypeEnum . IL2CPP_TYPE_TYPEDBYREF :
499
- return moduleDefinition . ImportReference ( typeof ( TypedReference ) ) ;
503
+ return moduleDefinition . ImportReference ( typeSystem . TypedReference ) ;
500
504
case Il2CppTypeEnum . IL2CPP_TYPE_CLASS :
501
505
case Il2CppTypeEnum . IL2CPP_TYPE_VALUETYPE :
502
506
{
0 commit comments