1414using BepInEx . Unity . IL2CPP . Hook ;
1515using BepInEx . Unity . IL2CPP . Logging ;
1616using Cpp2IL . Core ;
17+ using Cpp2IL . Core . Api ;
18+ using Cpp2IL . Core . InstructionSets ;
19+ using Cpp2IL . Core . OutputFormats ;
20+ using Cpp2IL . Core . ProcessingLayers ;
1721using HarmonyLib ;
1822using Il2CppInterop . Common ;
1923using Il2CppInterop . Generator ;
2933
3034namespace BepInEx . Unity . IL2CPP ;
3135
32- internal static class Il2CppInteropManager
36+ internal static partial class Il2CppInteropManager
3337{
38+ static Il2CppInteropManager ( )
39+ {
40+ InstructionSetRegistry . RegisterInstructionSet < X86InstructionSet > ( DefaultInstructionSets . X86_32 ) ;
41+ InstructionSetRegistry . RegisterInstructionSet < X86InstructionSet > ( DefaultInstructionSets . X86_64 ) ;
42+ LibCpp2IlBinaryRegistry . RegisterBuiltInBinarySupport ( ) ;
43+ }
44+
3445 private static readonly ConfigEntry < bool > UpdateInteropAssemblies =
3546 ConfigFile . CoreConfig . Bind ( "IL2CPP" ,
3647 "UpdateInteropAssemblies" ,
@@ -199,17 +210,18 @@ private static void GenerateInteropAssemblies()
199210
200211 AppDomain . CurrentDomain . AddCecilPlatformAssemblies ( UnityBaseLibsDirectory ) ;
201212 DownloadUnityAssemblies ( ) ;
202- var dummyAssemblies = RunCpp2Il ( ) ;
213+ var asmResolverAssemblies = RunCpp2Il ( ) ;
214+ var cecilAssemblies = new AsmToCecilConverter ( asmResolverAssemblies ) . ConvertAll ( ) ;
203215
204216 if ( DumpDummyAssemblies . Value )
205217 {
206218 var dummyPath = Path . Combine ( Paths . BepInExRootPath , "dummy" ) ;
207219 Directory . CreateDirectory ( dummyPath ) ;
208- foreach ( var assemblyDefinition in dummyAssemblies )
220+ foreach ( var assemblyDefinition in cecilAssemblies )
209221 assemblyDefinition . Write ( Path . Combine ( dummyPath , $ "{ assemblyDefinition . Name . Name } .dll") ) ;
210222 }
211223
212- RunIl2CppInteropGenerator ( dummyAssemblies ) ;
224+ RunIl2CppInteropGenerator ( cecilAssemblies ) ;
213225
214226 File . WriteAllText ( HashPath , ComputeHash ( ) ) ;
215227 }
@@ -242,7 +254,7 @@ private static void DownloadUnityAssemblies()
242254 }
243255 }
244256
245- private static List < AssemblyDefinition > RunCpp2Il ( )
257+ private static List < AsmResolver . DotNet . AssemblyDefinition > RunCpp2Il ( )
246258 {
247259 Logger . LogMessage ( "Running Cpp2IL to generate dummy assemblies" ) ;
248260
@@ -252,40 +264,44 @@ private static List<AssemblyDefinition> RunCpp2Il()
252264 "Metadata" ,
253265 "global-metadata.dat" ) ;
254266
255- List < AssemblyDefinition > sourceAssemblies ;
256-
257267 var stopwatch = new Stopwatch ( ) ;
258268 stopwatch . Start ( ) ;
259269
260270 var cpp2IlLogger = BepInEx . Logging . Logger . CreateLogSource ( "Cpp2IL" ) ;
261271
262- Cpp2IL . Core . Logger . VerboseLog += ( message , s ) =>
272+ Cpp2IL . Core . Logging . Logger . VerboseLog += ( message , s ) =>
263273 cpp2IlLogger . LogDebug ( $ "[{ s } ] { message . Trim ( ) } ") ;
264- Cpp2IL . Core . Logger . InfoLog += ( message , s ) =>
274+ Cpp2IL . Core . Logging . Logger . InfoLog += ( message , s ) =>
265275 cpp2IlLogger . LogInfo ( $ "[{ s } ] { message . Trim ( ) } ") ;
266- Cpp2IL . Core . Logger . WarningLog += ( message , s ) =>
276+ Cpp2IL . Core . Logging . Logger . WarningLog += ( message , s ) =>
267277 cpp2IlLogger . LogWarning ( $ "[{ s } ] { message . Trim ( ) } ") ;
268- Cpp2IL . Core . Logger . ErrorLog += ( message , s ) =>
278+ Cpp2IL . Core . Logging . Logger . ErrorLog += ( message , s ) =>
269279 cpp2IlLogger . LogError ( $ "[{ s } ] { message . Trim ( ) } ") ;
270280
271281 var unityVersion = UnityInfo . Version ;
272- Cpp2IlApi . InitializeLibCpp2Il ( GameAssemblyPath , metadataPath , new int [ ]
282+ Cpp2IlApi . InitializeLibCpp2Il ( GameAssemblyPath , metadataPath , unityVersion , false ) ;
283+
284+ List < Cpp2IlProcessingLayer > processingLayers = new ( ) { new AttributeInjectorProcessingLayer ( ) , } ;
285+
286+ foreach ( var cpp2IlProcessingLayer in processingLayers )
273287 {
274- unityVersion . Major ,
275- unityVersion . Minor ,
276- unityVersion . Build ,
277- } , false ) ;
278- sourceAssemblies = Cpp2IlApi . MakeDummyDLLs ( ) ;
279- Cpp2IlApi . RunAttributeRestorationForAllAssemblies ( null ,
280- LibCpp2IlMain . MetadataVersion >= 29 ||
281- LibCpp2IlMain . Binary ! . InstructionSet is InstructionSet . X86_32
282- or InstructionSet . X86_64 ) ;
283- Cpp2IlApi . DisposeAndCleanupAll ( ) ;
288+ cpp2IlProcessingLayer . PreProcess ( Cpp2IlApi . CurrentAppContext , processingLayers ) ;
289+ }
290+
291+ foreach ( var cpp2IlProcessingLayer in processingLayers )
292+ {
293+ cpp2IlProcessingLayer . Process ( Cpp2IlApi . CurrentAppContext ) ;
294+ }
295+
296+ var assemblies = new AsmResolverDummyDllOutputFormat ( ) . BuildAssemblies ( Cpp2IlApi . CurrentAppContext ) ;
297+
298+ LibCpp2IlMain . Reset ( ) ;
299+ Cpp2IlApi . CurrentAppContext = null ;
284300
285301 stopwatch . Stop ( ) ;
286302 Logger . LogInfo ( $ "Cpp2IL finished in { stopwatch . Elapsed } ") ;
287303
288- return sourceAssemblies ;
304+ return assemblies ;
289305 }
290306
291307 private static void RunIl2CppInteropGenerator ( List < AssemblyDefinition > sourceAssemblies )
0 commit comments