@@ -3,37 +3,27 @@ namespace Il2Cpp {
33 export class Assembly extends NativeStruct {
44 /** Gets the image of this assembly. */
55 get image ( ) : Il2Cpp . Image {
6- let get = function ( this : Il2Cpp . Assembly ) {
7- return new Il2Cpp . Image ( Il2Cpp . exports . assemblyGetImage ( this ) ) ;
8- } ;
9-
10- try {
11- Il2Cpp . exports . assemblyGetImage ;
12- } catch ( _ ) {
13- get = function ( this : Il2Cpp . Assembly ) {
14- // We need to get the System.Reflection.Module of the current assembly;
15- // System.Reflection.Assembly::GetModulesInternal, for some reason,
16- // throws a NullReferenceExceptionin Unity 5.3.8f1, so we must rely on
17- // System.Type::get_Module instead.
18- // Now we need to get any System.Type of this assembly.
19- // We cannot use System.Reflection.Assembly::GetTypes because it may
20- // return an empty array; hence we use System.Reflection.Assembly::GetType
21- // to retrieve <Module>, a class/type that seems to be always present
22- // (despite being excluded from System.Reflection.Assembly::GetTypes).
23- return new Il2Cpp . Image (
24- this . object
25- . method < Il2Cpp . Object > ( "GetType" , 1 )
26- . invoke ( Il2Cpp . string ( "<Module>" ) )
27- . method < Il2Cpp . Object > ( "get_Module" )
28- . invoke ( )
29- . field < NativePointer > ( "_impl" ) . value
30- ) ;
31- } ;
6+ if ( Il2Cpp . exports . assemblyGetImage . isNull ( ) ) {
7+ // We need to get the System.Reflection.Module of the current assembly;
8+ // System.Reflection.Assembly::GetModulesInternal, for some reason,
9+ // throws a NullReferenceExceptionin Unity 5.3.8f1, so we must rely on
10+ // System.Type::get_Module instead.
11+ // Now we need to get any System.Type of this assembly.
12+ // We cannot use System.Reflection.Assembly::GetTypes because it may
13+ // return an empty array; hence we use System.Reflection.Assembly::GetType
14+ // to retrieve <Module>, a class/type that seems to be always present
15+ // (despite being excluded from System.Reflection.Assembly::GetTypes).
16+ return new Il2Cpp . Image (
17+ this . object
18+ . method < Il2Cpp . Object > ( "GetType" , 1 )
19+ . invoke ( Il2Cpp . string ( "<Module>" ) )
20+ . method < Il2Cpp . Object > ( "get_Module" )
21+ . invoke ( )
22+ . field < NativePointer > ( "_impl" ) . value
23+ ) ;
3224 }
3325
34- getter ( Il2Cpp . Assembly . prototype , "image" , get , lazy ) ;
35-
36- return this . image ;
26+ return new Il2Cpp . Image ( Il2Cpp . exports . assemblyGetImage ( this ) ) ;
3727 }
3828
3929 /** Gets the name of this assembly. */
0 commit comments