@@ -51,7 +51,7 @@ public static void ConfigureLib(bool allowUserToInputAddresses)
5151 LibCpp2IlMain . Settings . MetadataFixupFunc = Cpp2IlPluginManager . MetadataFixupFuncs is { } funcs ? ( originalBytes , version ) =>
5252 {
5353 Logger . InfoNewline ( "Received request for metadata fixup from LibCpp2Il. Calling registered plugin fixup functions..." ) ;
54-
54+
5555 foreach ( var func in funcs )
5656 {
5757 try
@@ -68,7 +68,7 @@ public static void ConfigureLib(bool allowUserToInputAddresses)
6868 Logger . ErrorNewline ( $ "Metadata fixup function threw an exception: { e } . Ignoring and trying next fixup function, if any...") ;
6969 }
7070 }
71-
71+
7272 //only get here if every fixup function returns null or throws.
7373 return null ;
7474 } : null ;
@@ -85,20 +85,16 @@ public static void InitializeLibCpp2Il(string assemblyPath, string metadataPath,
8585
8686 ConfigureLib ( allowUserToInputAddresses ) ;
8787
88- #if ! DEBUG
89- try
90- {
91- #endif
92- if ( ! LibCpp2IlMain . LoadFromFile ( assemblyPath , metadataPath , unityVersion ) )
93- throw new Exception ( "Initialization with LibCpp2Il failed" ) ;
94- #if ! DEBUG
95- }
96- catch ( Exception e )
97- {
98- throw new LibCpp2ILInitializationException ( "Fatal Exception initializing LibCpp2IL!" , e ) ;
99- }
100- #endif
101- OnLibInitialized ( ) ;
88+ try
89+ {
90+ var context = LibCpp2IlMain . LoadFromFileAsContext ( assemblyPath , metadataPath , unityVersion ) ;
91+ OnLibInitialized ( context ) ;
92+ }
93+ catch ( Exception e )
94+ {
95+ throw new LibCpp2ILInitializationException ( "Fatal Exception initializing LibCpp2IL!" , e ) ;
96+ }
97+
10298 }
10399
104100 [ MemberNotNull ( nameof ( CurrentAppContext ) ) ]
@@ -112,27 +108,24 @@ public static void InitializeLibCpp2Il(byte[] assemblyData, byte[] metadataData,
112108
113109 try
114110 {
115- if ( ! LibCpp2IlMain . Initialize ( assemblyData , metadataData , unityVersion ) )
116- throw new Exception ( "Initialization with LibCpp2Il failed" ) ;
111+ var context = LibCpp2IlMain . InitializeAsContext ( assemblyData , metadataData , unityVersion ) ;
112+ OnLibInitialized ( context ) ;
117113 }
118114 catch ( Exception e )
119115 {
120116 throw new LibCpp2ILInitializationException ( "Fatal Exception initializing LibCpp2IL!" , e ) ;
121117 }
122-
123- OnLibInitialized ( ) ;
124118 }
125119
126120 [ MemberNotNull ( nameof ( CurrentAppContext ) ) ]
127- private static void OnLibInitialized ( )
121+ private static void OnLibInitialized ( LibCpp2IlContext libContext )
128122 {
129- MiscUtils . Init ( ) ;
130- LibCpp2IlMain . Binary ! . AllCustomAttributeGenerators . ToList ( )
123+ libContext . Binary . AllCustomAttributeGenerators . ToList ( )
131124 . ForEach ( ptr => SharedState . AttributeGeneratorStarts . Add ( ptr ) ) ;
132125
133126 var start = DateTime . Now ;
134127 Logger . InfoNewline ( "Creating application model..." ) ;
135- CurrentAppContext = new ( LibCpp2IlMain . Binary , LibCpp2IlMain . TheMetadata ! ) ;
128+ CurrentAppContext = new ( libContext ) ;
136129 Logger . InfoNewline ( $ "Application model created in { ( DateTime . Now - start ) . TotalMilliseconds } ms") ;
137130 }
138131
@@ -144,8 +137,6 @@ public static void ResetInternalState()
144137
145138 AsmResolverUtils . Reset ( ) ;
146139
147- LibCpp2IlMain . Reset ( ) ;
148-
149140 CurrentAppContext = null ;
150141 }
151142
@@ -176,6 +167,6 @@ public static void ResetInternalState()
176167
177168 private static bool IsLibInitialized ( )
178169 {
179- return LibCpp2IlMain . Binary != null && LibCpp2IlMain . TheMetadata != null ;
170+ return CurrentAppContext != null ;
180171 }
181172}
0 commit comments