### Retrieve Method Definition by Address Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Gets basic method details from a global address. ```c# Il2CppMethodDefinition method = LibCpp2IlMain.GetMethodDefinitionByGlobalAddress(0x182938239); ``` -------------------------------- ### Retrieve Field Reference by Address Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Gets a field definition from a global address. ```c# Il2CppFieldDefinition fieldDef = LibCpp2IlMain.GetFieldGlobalByAddress(0x182933215); ``` -------------------------------- ### Create Custom Processing Layer for Method Statistics Source: https://context7.com/samboycoding/cpp2il/llms.txt Extend Cpp2IlProcessingLayer to analyze application context before output generation. This example collects method statistics. ```csharp using Cpp2IL.Core.Api; using Cpp2IL.Core.Model.Contexts; public class MethodStatisticsProcessingLayer : Cpp2IlProcessingLayer { public override string Name => "Method Statistics"; public override string Id => "methodstats"; public override void PreProcess(ApplicationAnalysisContext context, List layers) { // Called before processing begins // Can modify the list of layers that will run Console.WriteLine("Preparing to collect method statistics..."); } public override void Process(ApplicationAnalysisContext appContext, Action? progressCallback = null) { var allMethods = appContext.AllTypes.SelectMany(t => t.Methods).ToList(); int total = allMethods.Count; int processed = 0; int totalBytes = 0; int staticMethods = 0; int virtualMethods = 0; var methodsByAssembly = new Dictionary(); foreach (var method in allMethods) { totalBytes += method.RawBytes.Length; if (method.IsStatic) staticMethods++; if (method.IsVirtual) virtualMethods++; var asmName = method.DeclaringType?.DeclaringAssembly?.Name ?? "Unknown"; methodsByAssembly.TryAdd(asmName, 0); methodsByAssembly[asmName]++; processed++; progressCallback?.Invoke(processed, total); } // Store results in context for use by output formats appContext.PutExtraData("MethodStats", new { TotalMethods = total, TotalBytes = totalBytes, StaticMethods = staticMethods, VirtualMethods = virtualMethods, MethodsByAssembly = methodsByAssembly }); Console.WriteLine($"Analyzed {total} methods ({totalBytes} bytes total)"); Console.WriteLine($"Static: {staticMethods}, Virtual: {virtualMethods}"); } } // Usage from command line: // Cpp2IL --game-path=C:\Game --use-processor=methodstats --output-as=dummydll ``` -------------------------------- ### Retrieve String Literal by Address Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Gets a string literal from a global address. ```c# string literal = LibCpp2IlMain.GetLiteralByAddress(0x182197654); ``` -------------------------------- ### Create Custom JSON Output Format Source: https://context7.com/samboycoding/cpp2il/llms.txt Extend Cpp2IlOutputFormat to generate custom JSON output from analyzed IL2CPP data. This example creates a 'JSON Type Dump' format. ```csharp using Cpp2IL.Core.Api; using Cpp2IL.Core.Model.Contexts; public class JsonDumpOutputFormat : Cpp2IlOutputFormat { public override string OutputFormatId => "jsondump"; public override string OutputFormatName => "JSON Type Dump"; public override void OnOutputFormatSelected() { // Called when this format is selected, before binary is loaded // Use this to configure library settings if needed } public override void DoOutput(ApplicationAnalysisContext context, string outputRoot) { Directory.CreateDirectory(outputRoot); var typeData = context.AllTypes.Select(t => new { FullName = t.FullName, Namespace = t.Namespace, Name = t.Name, Token = $ ``` ```csharp "0x{t.Token:X}", IsEnum = t.IsEnumType, Fields = t.Fields.Select(f => new { Name = f.Name, Type = f.FieldType?.ToString(), Offset = $ ``` ```csharp "0x{f.Offset:X}", IsStatic = f.IsStatic }), Methods = t.Methods.Select(m => new { Name = m.Name, ReturnType = m.ReturnType?.ToString(), Address = $ ``` ```csharp "0x{m.UnderlyingPointer:X}", Parameters = m.Parameters.Select(p => new { Name = p.Name, Type = p.ParameterType?.ToString() }) }), Properties = t.Properties.Select(p => new { Name = p.Name, Type = p.PropertyType?.ToString(), HasGetter = p.Getter != null, HasSetter = p.Setter != null }) }).ToList(); var json = System.Text.Json.JsonSerializer.Serialize(typeData, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(Path.Combine(outputRoot, "types.json"), json); } } // Register the output format in a plugin public class MyPlugin : Cpp2IlPlugin { public override string Name => "My Custom Plugin"; public override string Description => "Adds custom output formats"; public override void OnLoad() { OutputFormatRegistry.Register(); } } ``` -------------------------------- ### Get Type by Name Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Utility methods to retrieve type definitions by name, optionally specifying a namespace. ```c# //Signature: Il2CppTypeDefinition type = typeLibCpp2IlReflection.GetType(typeName, optionalNamespaceName); //Examples: Il2CppTypeDefinition type = LibCpp2IlReflection.GetType("String"); type = LibCpp2IlReflection.GetType("List`1"); type = LibCpp2IlReflection.GetType("Object", "UnityEngine"); ``` -------------------------------- ### Initialize LibCpp2IL from File Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Loads metadata and assembly files from the hard drive. Requires the Unity version, which can be retrieved from globalgamemanagers or the Unity engine executable. ```c# var unityVersion = new [] {2019, 2, 0}; //You'll have to get this from globalgamemanagers or the unity engine exe's file version. if (!LibCpp2IlMain.LoadFromFile(gameAssemblyPath, globalMetadataPath, unityVersion)) { Console.WriteLine("initialization failed!"); return; } ``` -------------------------------- ### Initialize LibCpp2IL Source: https://github.com/samboycoding/cpp2il/blob/development/Cpp2IL.Core/README_CORE.md Initializes the library using file paths or byte arrays. Requires a Unity version array with at least three elements (major, minor, patch). ```csharp Cpp2IlApi.InitializeLibCpp2Il ``` ```csharp [2020, 3, 1] ``` ```csharp Cpp2IlApi.DetermineUnityVersion ``` -------------------------------- ### Initialize LibCpp2IL from Byte Array Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Initializes the library by providing the content of the metadata and assembly files as byte arrays. ```c# var unityVersion = new [] {2019, 2, 0}; //You'll have to get this from globalgamemanagers or the unity engine exe's file version. if (!LibCpp2IlMain.Initialize(gameAssemblyBytes, globalMetadataBytes, unityVersion)) { Console.WriteLine("initialization failed!"); return; } ``` -------------------------------- ### Initialize Cpp2IL API from File Paths Source: https://context7.com/samboycoding/cpp2il/llms.txt Initializes the library using direct file paths to the binary and metadata. This must be called before accessing the ApplicationAnalysisContext. ```csharp using Cpp2IL.Core; using AssetRipper.Primitives; // Initialize from file paths string binaryPath = @"C:\Game\GameAssembly.dll"; string metadataPath = @"C:\Game\Game_Data\il2cpp_data\Metadata\global-metadata.dat"; UnityVersion unityVersion = new UnityVersion(2021, 3, 0); // Initialize the library Cpp2IlApi.InitializeLibCpp2Il(binaryPath, metadataPath, unityVersion); // Access the application context after initialization ApplicationAnalysisContext context = Cpp2IlApi.CurrentAppContext; Console.WriteLine($"Loaded {context.Assemblies.Count} assemblies"); Console.WriteLine($"Unity Version: {context.UnityVersion}"); Console.WriteLine($"Metadata Version: {context.MetadataVersion}"); // List all types in the application foreach (var assembly in context.Assemblies) { Console.WriteLine($"Assembly: {assembly.Name}"); foreach (var type in assembly.Types) { Console.WriteLine($" Type: {type.FullName}"); } } // Clean up when done Cpp2IlApi.ResetInternalState(); ``` -------------------------------- ### Cpp2IlApi.InitializeLibCpp2Il (File Path) Source: https://context7.com/samboycoding/cpp2il/llms.txt Initializes the Cpp2IL library using file paths for the binary and metadata. This is the primary entry point for file-based analysis. ```APIDOC ## Cpp2IlApi.InitializeLibCpp2Il (File Path) ### Description Initializes the Cpp2IL library from file paths on disk. This must be called before using most other API functions. The method loads the IL2CPP binary and metadata files, parses their structures, and creates an ApplicationAnalysisContext for further analysis. ### Parameters - **binaryPath** (string) - Required - Path to the GameAssembly.dll or libil2cpp.so file. - **metadataPath** (string) - Required - Path to the global-metadata.dat file. - **unityVersion** (UnityVersion) - Required - The Unity version of the target game. ### Request Example Cpp2IlApi.InitializeLibCpp2Il(@"C:\Game\GameAssembly.dll", @"C:\Game\Game_Data\il2cpp_data\Metadata\global-metadata.dat", new UnityVersion(2021, 3, 0)); ``` -------------------------------- ### Create a Cpp2IL Plugin Source: https://context7.com/samboycoding/cpp2il/llms.txt Implement a Cpp2IlPlugin to add custom support for game files, processing layers, and output formats. Register custom handlers and fixups within the OnLoad method. ```csharp using Cpp2IL.Core; using Cpp2IL.Core.Api; using Cpp2IL.Core.Attributes; using LibCpp2IL; [RegisterCpp2IlPlugin] public class MyGamePlugin : Cpp2IlPlugin { public override string Name => "My Game Support Plugin"; public override string Description => "Adds support for encrypted game files"; public override void OnLoad() { // Register custom output formats OutputFormatRegistry.Register(); // Register custom processing layers ProcessingLayerRegistry.Register(); // Register a metadata fixup function for encrypted metadata RegisterMetadataFixupFunc((originalBytes, unityVersion) => { // Check if this is encrypted metadata we can handle if (originalBytes.Length > 4 && originalBytes[0] == 0xDE && originalBytes[1] == 0xAD) { Logger.Info("Decrypting metadata..."); byte[] decrypted = DecryptMetadata(originalBytes); return decrypted; } return null; // Return null if we can't handle it }); // Register handler for when registration struct location fails RegisterBinaryRegistrationFuncFallbackHandler((binary, searchStart, searchEnd) => { Logger.Info("Attempting fallback registration struct search..."); // Return (codeRegPtr, metadataRegPtr) or (0, 0) if not found return (0ul, 0ul); }); } public override bool HandleGamePath(string gamePath, ref Cpp2IlRuntimeArgs args) { // Handle custom game container formats (e.g., proprietary archives) if (Path.GetExtension(gamePath) == ".mygame") { // Extract files to temp location string tempBinary = GetTemporaryFilePath(); string tempMeta = GetTemporaryFilePath(); ExtractGameFiles(gamePath, tempBinary, tempMeta); args.PathToAssembly = tempBinary; args.PathToMetadata = tempMeta; args.UnityVersion = new AssetRipper.Primitives.UnityVersion(2021, 3, 0); args.Valid = true; return true; } return false; } protected override void OnFinish() { // Called when processing completes // Temporary files from GetTemporaryFilePath() are automatically cleaned up Logger.Info("Plugin cleanup complete"); } private byte[] DecryptMetadata(byte[] encrypted) { // Your decryption logic here return encrypted; } private void ExtractGameFiles(string archive, string binaryOut, string metaOut) { // Your extraction logic here } } ``` -------------------------------- ### Initialize Cpp2IL API from Byte Arrays Source: https://context7.com/samboycoding/cpp2il/llms.txt Initializes the library using byte arrays, allowing for pre-processing or decryption of the binary and metadata files. ```csharp using Cpp2IL.Core; using AssetRipper.Primitives; // Load files into byte arrays (allows pre-processing/decryption) byte[] binaryBytes = File.ReadAllBytes(@"C:\Game\GameAssembly.dll"); byte[] metadataBytes = File.ReadAllBytes(@"C:\Game\Game_Data\il2cpp_data\Metadata\global-metadata.dat"); // Optionally decrypt or modify the bytes here // binaryBytes = DecryptBinary(binaryBytes); // metadataBytes = DecryptMetadata(metadataBytes); UnityVersion unityVersion = new UnityVersion(2021, 3, 0); // Initialize from byte arrays Cpp2IlApi.InitializeLibCpp2Il(binaryBytes, metadataBytes, unityVersion); // Now you can access the analysis context var context = Cpp2IlApi.CurrentAppContext; Console.WriteLine($"Loaded application with {context.AllTypes.Count()} types"); ``` -------------------------------- ### Execute Cpp2IL CLI Commands Source: https://context7.com/samboycoding/cpp2il/llms.txt Common command-line operations for analyzing Unity games, including path specification, version forcing, and processor configuration. ```bash # Basic Windows game analysis Cpp2IL --game-path=C:\Path\To\Your\Game --output-as=dummydll --output-to=./output # Android APK analysis Cpp2IL --game-path=/path/to/game.apk --output-as=dummydll # Force specific paths and version when auto-detection fails Cpp2IL --force-binary-path=/path/to/GameAssembly.dll \ --force-metadata-path=/path/to/global-metadata.dat \ --force-unity-version=2021.3.0 \ --output-as=dummydll # Enable verbose logging for debugging Cpp2IL --game-path=C:\Game --verbose --output-as=dummydll # List available output formats Cpp2IL --list-output-formats # List available processing layers Cpp2IL --list-processors # Use processing layers to inject attributes Cpp2IL --game-path=C:\Game --use-processor=attributeinjector --output-as=dummydll ``` -------------------------------- ### Cpp2IlApi.InitializeLibCpp2Il (Byte Arrays) Source: https://context7.com/samboycoding/cpp2il/llms.txt Initializes the Cpp2IL library using byte arrays, allowing for pre-processing or decryption of the binary and metadata files. ```APIDOC ## Cpp2IlApi.InitializeLibCpp2Il (Byte Arrays) ### Description Initializes the Cpp2IL library from byte arrays instead of file paths. This is useful when you need to pre-process or decrypt the binary and metadata files before loading them. ### Parameters - **binaryBytes** (byte[]) - Required - Byte array containing the binary data. - **metadataBytes** (byte[]) - Required - Byte array containing the metadata data. - **unityVersion** (UnityVersion) - Required - The Unity version of the target game. ### Request Example Cpp2IlApi.InitializeLibCpp2Il(binaryBytes, metadataBytes, new UnityVersion(2021, 3, 0)); ``` -------------------------------- ### Analyze IL2CPP Application with ApplicationAnalysisContext Source: https://context7.com/samboycoding/cpp2il/llms.txt Access the global application context to retrieve assemblies, types, and methods by address. ```csharp using Cpp2IL.Core; using Cpp2IL.Core.Model.Contexts; // After initializing Cpp2IlApi var appContext = Cpp2IlApi.CurrentAppContext; // Access assemblies foreach (var assembly in appContext.Assemblies) { Console.WriteLine($"Assembly: {assembly.Name} v{assembly.Version}"); } // Get assembly by name AssemblyAnalysisContext? mscorlib = appContext.GetAssemblyByName("mscorlib"); AssemblyAnalysisContext? gameAssembly = appContext.GetAssemblyByName("Assembly-CSharp"); // Access all types across all assemblies foreach (var type in appContext.AllTypes) { if (type.Namespace == "UnityEngine") Console.WriteLine($"UnityEngine type: {type.Name}"); } // Find methods by address (useful for analyzing call targets) ulong methodAddress = 0x180385033; if (appContext.MethodsByAddress.TryGetValue(methodAddress, out var methods)) { foreach (var method in methods) Console.WriteLine($"Method at address: {method.Name}"); } // Access system types for common operations var systemTypes = appContext.SystemTypes; Console.WriteLine($"System.Object: {systemTypes.SystemObjectType?.FullName}"); Console.WriteLine($"System.String: {systemTypes.SystemStringType?.FullName}"); // Store custom data in the context appContext.PutExtraData("MyCustomKey", "MyCustomValue"); string? value = appContext.GetExtraData("MyCustomKey"); ``` -------------------------------- ### Generate Dummy Assemblies Source: https://github.com/samboycoding/cpp2il/blob/development/Cpp2IL.Core/README_CORE.md Generates and returns a list of Cecil AssemblyDefinition objects representing the IL2CPP application's type model. Requires prior library initialization. ```csharp Cpp2IlApi.MakeDummyDLLs ``` -------------------------------- ### Programmatic Cpp2IL Execution Source: https://context7.com/samboycoding/cpp2il/llms.txt Run the Cpp2IL pipeline programmatically by initializing Cpp2IlApi, configuring Cpp2IlRuntimeArgs, and then executing the pipeline. ```csharp using Cpp2IL; using Cpp2IL.Core; using Cpp2IL.Core.Api; using AssetRipper.Primitives; // Initialize plugins first Cpp2IlApi.Init(); // Configure runtime arguments var args = new Cpp2IlRuntimeArgs { PathToAssembly = @"C:\Game\GameAssembly.dll", PathToMetadata = @"C:\Game\Game_Data\il2cpp_data\Metadata\global-metadata.dat", UnityVersion = new UnityVersion(2021, 3, 0), OutputRootDirectory = @"C:\Output", Valid = true, LowMemoryMode = false }; // Select output format args.OutputFormat = OutputFormatRegistry.GetFormat("dummydll"); // Select processing layers args.ProcessingLayersToRun = new List { ProcessingLayerRegistry.GetById("attributeinjector"), ProcessingLayerRegistry.GetById("attributeanalyzer") }; // Add configuration options for processing layers args.ProcessingLayerConfigurationOptions["attr-injector-use-ez-diff"] = "true"; // Run the full pipeline Cpp2IlApi.RuntimeOptions = args; Cpp2IlApi.InitializeLibCpp2Il(args.PathToAssembly, args.PathToMetadata, args.UnityVersion); // Run processing layers foreach (var layer in args.ProcessingLayersToRun) { Console.WriteLine($"Running {layer.Name}..."); layer.Process(Cpp2IlApi.CurrentAppContext); } // Generate output if (args.OutputFormat != null) { Console.WriteLine($"Outputting as {args.OutputFormat.OutputFormatName}..."); args.OutputFormat.DoOutput(Cpp2IlApi.CurrentAppContext, args.OutputRootDirectory); } Console.WriteLine("Done!"); ``` -------------------------------- ### Access IL2CPP Metadata via Low-Level API Source: https://context7.com/samboycoding/cpp2il/llms.txt Use this snippet to access IL2CPP binary and metadata directly using virtual addresses. Ensure LibCpp2IlApi is initialized before use. ```csharp using LibCpp2IL; using LibCpp2IL.Metadata; using LibCpp2IL.Reflection; // After initializing via Cpp2IlApi, LibCpp2IlMain is also initialized // Access the binary and metadata directly Il2CppBinary binary = LibCpp2IlMain.Binary!; Il2CppMetadata metadata = LibCpp2IlMain.TheMetadata!; Console.WriteLine($"Metadata Version: {LibCpp2IlMain.MetadataVersion}"); // Get type by virtual address (from disassembly analysis) ulong typeAddress = 0x180623548; Il2CppTypeReflectionData? typeData = LibCpp2IlMain.GetTypeGlobalByAddress(typeAddress); if (typeData != null) { Console.WriteLine($"Type at address: {typeData}"); Console.WriteLine($"Is Generic: {typeData.isGenericType}"); } // Get method definition by address ulong methodGlobalAddress = 0x182938239; Il2CppMethodDefinition? methodDef = LibCpp2IlMain.GetMethodDefinitionByGlobalAddress(methodGlobalAddress); if (methodDef != null) { Console.WriteLine($"Method: {methodDef.Name}"); Console.WriteLine($"Declaring Type: {methodDef.DeclaringType?.FullName}"); } // Get method with generic information MetadataUsage? methodUsage = LibCpp2IlMain.GetMethodGlobalByAddress(methodGlobalAddress); if (methodUsage?.Type == MetadataUsageType.MethodRef) { var genericRef = methodUsage.AsGenericMethodRef(); Console.WriteLine($"Generic Method: {genericRef.BaseMethod.Name}"); Console.WriteLine($"Type Generic Params: {string.Join(", ", genericRef.TypeGenericParams)}"); Console.WriteLine($"Method Generic Params: {string.Join(", ", genericRef.MethodGenericParams)}"); } // Get field by address ulong fieldAddress = 0x182933215; Il2CppFieldDefinition? fieldDef = LibCpp2IlMain.GetFieldGlobalByAddress(fieldAddress); if (fieldDef != null) { Console.WriteLine($"Field: {fieldDef.Name}"); } // Get string literal by address ulong literalAddress = 0x182197654; string? literal = LibCpp2IlMain.GetLiteralByAddress(literalAddress); if (literal != null) { Console.WriteLine($"String Literal: \"{literal}\""); } // Get methods at a specific pointer address var methodsAtPtr = LibCpp2IlMain.GetManagedMethodImplementationsAtAddress(0x180385033); if (methodsAtPtr != null) { foreach (var m in methodsAtPtr) Console.WriteLine($"Method at ptr: {m.HumanReadableSignature}"); } ``` -------------------------------- ### ApplicationAnalysisContext Source: https://context7.com/samboycoding/cpp2il/llms.txt The top-level context representing a loaded IL2CPP application, providing access to assemblies, types, and metadata. ```APIDOC ## ApplicationAnalysisContext ### Description The top-level context representing a loaded IL2CPP application. Provides access to all assemblies, types, methods, and metadata in the application. ### Properties - **Assemblies** (IEnumerable) - Collection of all loaded assemblies. - **AllTypes** (IEnumerable) - Collection of all types across all assemblies. - **MethodsByAddress** (Dictionary) - Mapping of memory addresses to methods. - **SystemTypes** (object) - Access to common system types like Object and String. ``` -------------------------------- ### Inspecting Method Metadata Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Access method names, pointers, return types, and parameter details from the metadata. ```c# //In this example, string.Join(string separator, string[] value) is the first-defined method in the metadata, but it could be a different order. var join = type.Methods[0]; Console.Log(join.Name); //Join Console.Log($"0x{join.MethodPointer:X}"); //0x180385033 //Getting the file address of a method Console.Log($"Join is in-assembly at address 0x{LibCpp2IlMain.ThePe.MapVirtualAddressToRaw(join.MethodPointer):X}"); //Join is in-assembly at address 0x385033 //ReturnType is a ReflectionData again, like interfaces are Console.Log(join.ReturnType); //System.String //DeclaringType gives you the original Il2CppTypeDefinition back Console.Log(join.DeclaringType.FullName); //System.String //Parameters are Il2CppParameterReflectionData objects, objects to contain information on a parameter, such as its name, type, and default value. //ToString on these also returns their canonical form. Console.Log(join.Parameters[0].Type) //System.String Console.Log(join.Parameters[1].Type) //System.String[] Console.Log(join.Parameters[1].Type.isType) //false Console.Log(join.Parameters[1].Type.isArray) //true Console.Log(join.Parameters[1].Type.arrayType) //System.String ``` -------------------------------- ### Resolve Base Method from Address Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Look up the base method definition for a specific memory address using the ConcreteGenericImplementationsByAddress dictionary. ```c# var genericImplementations = LibCpp2IlMain.ThePe.ConcreteGenericImplementationsByAddress[0x123456789]; Console.WriteLine(genericImplementations[0].BaseMethod.HumanReadableSignature); ``` -------------------------------- ### Determine Unity Version with Cpp2IlApi Source: https://context7.com/samboycoding/cpp2il/llms.txt Use these methods to identify the Unity version from game executables, globalgamemanagers, or data.unity3d streams. ```csharp using Cpp2IL.Core; using AssetRipper.Primitives; // Determine Unity version automatically string unityPlayerPath = @"C:\Game\Game.exe"; // The main executable string gameDataPath = @"C:\Game\Game_Data"; // The _Data folder UnityVersion version = Cpp2IlApi.DetermineUnityVersion(unityPlayerPath, gameDataPath); if (version != default) { Console.WriteLine($"Detected Unity version: {version}"); // Output: Detected Unity version: 2021.3.0f1 } else { Console.WriteLine("Could not determine Unity version automatically"); } // Alternative: Get version directly from globalgamemanagers bytes byte[] ggmBytes = File.ReadAllBytes(@"C:\Game\Game_Data\globalgamemanagers"); UnityVersion versionFromGgm = Cpp2IlApi.GetVersionFromGlobalGameManagers(ggmBytes); // Or from data.unity3d stream (for large files) using var stream = File.OpenRead(@"C:\Game\Game_Data\data.unity3d"); UnityVersion versionFromUnity3d = Cpp2IlApi.GetVersionFromDataUnity3D(stream); ``` -------------------------------- ### Retrieve Concrete Generic Method Variants Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Access the ConcreteGenericMethods dictionary to find existing implementations for a specific generic method definition. ```c# var listType = LibCpp2IlReflection.GetType("List`1", "System"); var addMethod = listType.Methods.First(m => m.Name == "Add"); var variants = LibCpp2IlMain.ThePe.ConcreteGenericMethods[addMethod]; Console.WriteLine(addMethod.MethodPointer); //0xdeadbeef Console.WriteLine(variants[0].BaseMethod.MethodPointer); //Same as above Console.WriteLine(variants[0].GenericParams[0]); //Could be, for example, "System.Int32" //The below may or may not give the original method pointer. //The original pointer is the implementation for `T`. //This will be the same as the implementation for `object` //This variant, assuming it is for Int32, should be a different pointer. //If it's for a class such as `string`, it will be the same pointer. Console.WriteLine(variants[0].GenericVariantPtr); //0x123456789 ``` -------------------------------- ### Accessing Inheritance and Interface Data Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Retrieve base class information and interface definitions, including generic parameters, using Il2CppTypeReflectionData. ```c# //Base class Console.WriteLine(type.BaseType.FullName); //System.Object //Interface data, including generic parameters. //Il2CppTypeReflectionData is a wrapper around Il2CppTypeDefinition that allows for generics. //ToString on these returns their canonical form. Il2CppTypeReflectionData[] interfaces = type.Interfaces; var enumerableOfChar = interfaces[5]; Console.WriteLine(enumerableOfChar); //System.Collections.Generic.IEnumerable`1 Console.WriteLine(enumerableOfChar.isType); //true Console.WriteLine(enumerableOfChar.isGenericType); //true Console.WriteLine(enumerableOfChar.baseType.FullName); //System.Collections.Generic.IEnumerable`1 Console.WriteLine(enumerableOfChar.genericParams[0]); //System.Char Console.WriteLine(enumerableOfChar.genericParams[0].isType); //true Console.WriteLine(enumerableOfChar.genericParams[0].isGenericType); //false ``` -------------------------------- ### Inspecting Event Metadata Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Access event information, including adder, remover, and invoker methods. ```c# var appDomain = LibCpp2IlReflection.GetType("AppDomain", "System"); Console.Log(appDomain.Events.Length); //3 Console.Log(appDomain.Events[0].Name); //DomainUnload Console.Log(appDomain.Events[0].EventType); //System.EventHandler //Adder returns an Il2CppMethodDefinition and represents the method used to add a listener to the event. //Remover also exists, as does Invoker. Console.Log(appDomain.Events[0].Adder.Name); //add_DomainUnload //Type returns an Il2CppTypeReflectionData, as it's just a standard method parameter. Console.Log(appDomain.Events[0].Adder.Parameters[0].Type); //System.EventHandler ``` -------------------------------- ### Access Type Properties Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Retrieves basic metadata properties such as namespace and full name for a given type definition. ```c# Il2CppTypeDefinition type = LibCpp2IlReflection.GetType("String"); Console.WriteLine(type.Namespace); //System Console.WriteLine(type.Name); //String Console.WriteLine(type.FullName); //System.String ``` -------------------------------- ### ContainsUnimplementedInstructionsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Marks methods that contain at least one unimplemented instruction. ```APIDOC ## ContainsUnimplementedInstructionsAttribute ### Description This method contains at least one instruction that is not implemented. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] ``` -------------------------------- ### Accessing Field Metadata Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Retrieve field information, noting that fields maintain a defined order in the metadata. ```c# //Accessing the string's internal length field. Note that unlike methods, fields DO have a defined order and they are presented in that order. var lengthField = type.Fields[0]; Console.WriteLine(lengthField.Name); //m_stringLength //FieldType is an Il2CppTypeReflectionData, the ToString of which gives the name of the class. Console.WriteLine(lengthField.FieldType); //System.Int32 ``` -------------------------------- ### ContainsUnimplementedInstructionsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Marks methods that contain at least one instruction that is not implemented. Use to flag methods with unimplemented or placeholder instructions. ```cs /// /// This method contains at least one instruction that is not implemented. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class ContainsUnimplementedInstructionsAttribute : Attribute { } ``` -------------------------------- ### Cpp2IlApi.DetermineUnityVersion Source: https://context7.com/samboycoding/cpp2il/llms.txt Methods for automatically detecting the Unity version from game files or streams. ```APIDOC ## Cpp2IlApi.DetermineUnityVersion ### Description Automatically determines the Unity version from game files. It attempts to read the version from globalgamemanagers or data.unity3d files, and falls back to the executable's file version info on Windows. ### Parameters #### Method Parameters - **unityPlayerPath** (string) - Required - The path to the main game executable. - **gameDataPath** (string) - Required - The path to the game's _Data folder. ### Response - **UnityVersion** (object) - The detected Unity version or default if not found. ``` -------------------------------- ### Access Types and Members via Reflection API Source: https://context7.com/samboycoding/cpp2il/llms.txt Use this snippet to access types, methods, fields, and properties by name, similar to System.Reflection. Handles generic types and nested types. ```csharp using LibCpp2IL.Reflection; using LibCpp2IL.Metadata; // Get type by name Il2CppTypeDefinition? stringType = LibCpp2IlReflection.GetType("String", "System"); Il2CppTypeDefinition? listType = LibCpp2IlReflection.GetType("List`1", "System.Collections.Generic"); Il2CppTypeDefinition? gameObject = LibCpp2IlReflection.GetType("GameObject", "UnityEngine"); if (stringType != null) { Console.WriteLine($"Type: {stringType.FullName}"); Console.WriteLine($"Token: 0x{stringType.Token:X}"); // Access base type Console.WriteLine($"Base Type: {stringType.BaseType?.FullName}"); // Access interfaces (as Il2CppTypeReflectionData for generic support) Console.WriteLine("Interfaces:"); foreach (var iface in stringType.Interfaces) { Console.WriteLine($" {iface}"); if (iface.isGenericType) { Console.WriteLine($" Base Type: {iface.baseType?.FullName}"); Console.WriteLine($" Generic Params: {string.Join(", ", iface.genericParams)}"); } } // Access methods Console.WriteLine("Methods:"); foreach (var method in stringType.Methods.Take(5)) { Console.WriteLine($" {method.Name}"); Console.WriteLine($" Return Type: {method.ReturnType}"); Console.WriteLine($" Pointer: 0x{method.MethodPointer:X}"); Console.WriteLine($" Parameters: {string.Join(", ", method.Parameters.Select(p => $"{p.Type} {p.ParameterName}"))}"); } // Access fields Console.WriteLine("Fields:"); foreach (var field in stringType.Fields) { Console.WriteLine($" {field.FieldType} {field.Name}"); } // Access properties Console.WriteLine("Properties:"); foreach (var prop in stringType.Properties) { Console.WriteLine($" {prop.PropertyType} {prop.Name}"); if (prop.Getter != null) Console.WriteLine($" Getter: {prop.Getter.Name}"); } // Access nested types if (stringType.NestedTypes.Any()) { Console.WriteLine("Nested Types:"); foreach (var nested in stringType.NestedTypes) Console.WriteLine($" {nested.Name}"); } } ``` -------------------------------- ### Retrieve Type Reference by Address Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Resolves a type definition from a virtual address using Il2CppTypeReflectionData. ```c# //Il2CppTypeReflectionData is a wrapper around type definitions to allow for generic params and arrays. Il2CppTypeReflectionData type = LibCpp2IlMain.GetTypeGlobalByAddress(0x180623548); ``` -------------------------------- ### CallAnalysisNotSupportedAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Marks methods that have no instructions to analyze and are not abstract or interface declarations. Use when a method is empty and cannot be analyzed. ```cs /// /// This method has no instructions to analyze and is not abstract nor an interface declaration. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class CallAnalysisNotSupportedAttribute : Attribute { } ``` -------------------------------- ### Inspect Types with TypeAnalysisContext Source: https://context7.com/samboycoding/cpp2il/llms.txt Iterate through type definitions to inspect fields, methods, properties, events, and nested types. ```csharp using Cpp2IL.Core; using Cpp2IL.Core.Model.Contexts; var appContext = Cpp2IlApi.CurrentAppContext; var assembly = appContext.GetAssemblyByName("Assembly-CSharp"); foreach (var type in assembly.Types) { Console.WriteLine($"\n=== {type.FullName} ==="); Console.WriteLine($"Namespace: {type.Namespace}"); Console.WriteLine($"Token: 0x{type.Token:X}"); Console.WriteLine($"Is Enum: {type.IsEnumType}"); Console.WriteLine($"Is Value Type: {type.Definition?.IsValueType}"); // Access base type if (type.BaseType != null) Console.WriteLine($"Base Type: {type.BaseType.FullName}"); // List fields Console.WriteLine("Fields:"); foreach (var field in type.Fields) { Console.WriteLine($" {field.Name}: {field.FieldType} (offset: 0x{field.Offset:X})"); Console.WriteLine($" Static: {field.IsStatic}, Token: 0x{field.Token:X}"); } // List methods Console.WriteLine("Methods:"); foreach (var method in type.Methods) { Console.WriteLine($" {method.Name}({string.Join(", ", method.Parameters.Select(p => p.Name))})"); Console.WriteLine($" Return Type: {method.ReturnType}"); Console.WriteLine($" Address: 0x{method.UnderlyingPointer:X}"); Console.WriteLine($" RVA: 0x{method.Rva:X}"); Console.WriteLine($" Body Length: {method.RawBytes.Length} bytes"); } // List properties Console.WriteLine("Properties:"); foreach (var prop in type.Properties) { Console.WriteLine($" {prop.PropertyType} {prop.Name}"); Console.WriteLine($" Has Getter: {prop.Getter != null}"); Console.WriteLine($" Has Setter: {prop.Setter != null}"); } // List events Console.WriteLine("Events:"); foreach (var evt in type.Events) { Console.WriteLine($" {evt.EventType} {evt.Name}"); } // Access nested types foreach (var nested in type.NestedTypes) { Console.WriteLine($"Nested Type: {nested.Name}"); } } ``` -------------------------------- ### Retrieving Property Metadata Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Access property names, associated getter/setter methods, and property types. ```c# var lengthProperty = type.Properties[1]; Console.WriteLine(lengthProperty.Name); //Length Console.WriteLine(lengthProperty.Getter.Name); //get_Length Console.WriteLine(lengthProperty.Setter); //null //PropertyType is an Il2CppTypeReflectionData object Console.WriteLine(lengthProperty.PropertyType); //System.Int32 Console.WriteLine(lengthProperty.DeclaringType.FullName); //System.String ``` -------------------------------- ### Retrieve Complex Method Data Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Handles generic method references by checking the MetadataUsage type and extracting generic parameters if present. ```c# MetadataUsage? usage = LibCpp2IlMain.GetMethodGlobalByAddress(0x182938239); if(usage == null) return; if(usage.Type == MetadataUsageType.MethodRef) { var genericMethodRef = usage.AsGenericMethodRef(); Console.WriteLine(genericMethodRef.declaringType); //Il2CppTypeDefinition Console.WriteLine(genericMethodRef.baseMethod); //Il2CppMethodDefinition, equal to the one returned by the above method Console.WriteLine(genericMethodRef.typeGenericParams); //Il2CppTypeReflectionData[] Console.WriteLine(genericMethodRef.methodGenericParams); //Il2CppTypeReflectionData[] } else { //Method is not generic Console.WriteLine(usage.AsMethod()); //Il2CppMethodDefinition } ``` -------------------------------- ### CallAnalysisNotSupportedAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Marks methods that have no instructions to analyze and are not abstract nor interface declarations. ```APIDOC ## CallAnalysisNotSupportedAttribute ### Description This method has no instructions to analyze and is not abstract nor an interface declaration. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] ``` -------------------------------- ### TypeAnalysisContext Source: https://context7.com/samboycoding/cpp2il/llms.txt Represents a type definition with access to fields, methods, properties, events, and nested types. ```APIDOC ## TypeAnalysisContext ### Description Represents a type definition with access to fields, methods, properties, events, and nested types. ### Properties - **FullName** (string) - The full name of the type. - **Fields** (IEnumerable) - List of fields defined in the type. - **Methods** (IEnumerable) - List of methods defined in the type. - **Properties** (IEnumerable) - List of properties defined in the type. - **Events** (IEnumerable) - List of events defined in the type. - **NestedTypes** (IEnumerable) - List of types nested within this type. ``` -------------------------------- ### DeduplicatedMethodAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that a method's instructions have been deduplicated by the compiler and it shares its address with other methods. ```APIDOC ## DeduplicatedMethodAttribute ### Description This method's instructions have been deduplicated by the compiler, and it shares its address with other methods. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] ``` -------------------------------- ### DeduplicatedMethodAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that a method's instructions have been deduplicated by the compiler and share an address with other methods. Use when a method's code is identical to another and its address is not unique. ```cs using System; namespace Cpp2ILInjected.CallAnalysis; /// /// This method's instructions have been deduplicated by the compiler, and it shares its address with other methods. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class DeduplicatedMethodAttribute : Attribute { } ``` -------------------------------- ### CallsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that this method calls a specified method. ```APIDOC ## CallsAttribute ### Description This method calls the method specified. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] ### Properties - **Type** (object) - Description of the called method's type. - **Member** (string) - The name of the called member. - **MemberTypeParameters** (object[]) - Type parameters of the called method. - **MemberParameters** (object[]) - Parameters of the called method. - **ReturnType** (object) - The return type of the called method. ``` -------------------------------- ### Querying Nested Types Source: https://github.com/samboycoding/cpp2il/blob/development/LibCpp2IL/README.md Retrieve nested type definitions from a parent type. ```c# var transform = LibCpp2IlReflection.GetType("Transform", "UnityEngine"); Console.Log(transform.NestedTypes[0].Name); //Enumerator Console.Log(transform.NestedTypes[0].DeclaringType.FullName); //UnityEngine.Transform ``` -------------------------------- ### CallsUnknownMethodsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that this method calls at least one unknown method. ```APIDOC ## CallsUnknownMethodsAttribute ### Description This method calls at least one unknown method. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] ### Properties - **Count** (int) - The number of unknown methods called. ``` -------------------------------- ### CallsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that a method calls another specified method. Use to track direct calls made by a method. ```cs /// /// This method calls the method specified. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public sealed class CallsAttribute : Attribute { public object Type; public string Member; public object[] MemberTypeParameters; public object[] MemberParameters; public object ReturnType; } ``` -------------------------------- ### CallsDeduplicatedMethodsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that this method calls at least one deduplicated method. ```APIDOC ## CallsDeduplicatedMethodsAttribute ### Description This method calls at least one deduplicated method. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] ### Properties - **Count** (int) - The number of deduplicated methods called. ``` -------------------------------- ### ContainsInvalidInstructionsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Marks methods that contain at least one invalid instruction. Use to identify methods with corrupted or malformed instructions. ```cs /// /// This method contains at least one instruction that is invalid. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class ContainsInvalidInstructionsAttribute : Attribute { } ``` -------------------------------- ### ContainsInvalidInstructionsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Marks methods that contain at least one invalid instruction. ```APIDOC ## ContainsInvalidInstructionsAttribute ### Description This method contains at least one instruction that is invalid. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] ``` -------------------------------- ### CallsUnknownMethodsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that a method calls at least one unknown method. Use when a method's calls include those to methods that could not be resolved. Stores the count of such calls. ```cs /// /// This method calls at least one unknown method. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class CallsUnknownMethodsAttribute : Attribute { public int Count; } ``` -------------------------------- ### CalledByAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that this method is called from a specified method. This attribute is not emitted if there are a large number of callers. ```APIDOC ## CalledByAttribute ### Description This method is called from the method specified. ### Remarks This attribute is not emitted if there are a large amount of callers. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] ### Properties - **Type** (object) - Description of the caller's type. - **Member** (string) - The name of the calling member. - **MemberTypeParameters** (object[]) - Type parameters of the calling member. - **MemberParameters** (object[]) - Parameters of the calling member. - **ReturnType** (object) - The return type of the calling member. ``` -------------------------------- ### CallerCountAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Stores the number of direct calls to this method. Similar to the attribute generated by Unhollower. ```APIDOC ## CallerCountAttribute ### Description The number of direct calls to this method. ### Remarks This attribute is similar in form and function to the one generated by Unhollower. ### Attribute Usage [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] ### Properties - **Count** (int) - The number of direct callers. ``` -------------------------------- ### CallerCountAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Stores the number of direct calls to a method. This attribute is similar to the one generated by Unhollower. Use to quickly check how many methods call a specific method. ```cs /// /// The number of direct calls to this method. /// /// /// This attribute is similar in form and function to the one generated by Unhollower. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class CallerCountAttribute : Attribute { public int Count; } ``` -------------------------------- ### CalledByAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that a method is called by another specified method. This attribute is not emitted if there are a large number of callers. Use to track direct callers. ```cs /// /// This method is called from the method specified. /// /// /// This attribute is not emitted if there are a large amount of callers. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public sealed class CalledByAttribute : Attribute { public object Type; public string Member; public object[] MemberTypeParameters; public object[] MemberParameters; public object ReturnType; } ``` -------------------------------- ### CallsDeduplicatedMethodsAttribute Source: https://github.com/samboycoding/cpp2il/blob/development/docs/CallAnalyzer.md Indicates that a method calls at least one deduplicated method. Use when a method's calls include those to deduplicated methods. Stores the count of such calls. ```cs /// /// This method calls at least one deduplicated method. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] public sealed class CallsDeduplicatedMethodsAttribute : Attribute { public int Count; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.