Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Cpp2IL.Core/Model/Contexts/AssemblyAnalysisContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class AssemblyAnalysisContext : HasCustomAttributesAndName
/// </summary>
public IEnumerable<TypeAnalysisContext> TopLevelTypes => Types.Where(t => t.DeclaringType == null);

/// <summary>
/// The analysis context objects for all types exported by this assembly.
/// </summary>
public IEnumerable<TypeAnalysisContext> ExportedTypes => (Definition?.Image.ExportedTypes ?? []).Select(t => AppContext.ResolveContextForType(t)!);

/// <summary>
/// The code gen module for this assembly.
///
Expand Down Expand Up @@ -185,7 +190,7 @@ public AssemblyAnalysisContext(Il2CppAssemblyDefinition? assemblyDefinition, App

InitCustomAttributeData();

foreach (var il2CppTypeDefinition in Definition.Image.Types!)
foreach (var il2CppTypeDefinition in Definition.Image.Types)
{
var typeContext = new TypeAnalysisContext(il2CppTypeDefinition, this);
Types.Add(typeContext);
Expand Down
8 changes: 8 additions & 0 deletions Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public static void ConfigureHierarchy(AssemblyAnalysisContext asmCtx)
foreach (var interfaceType in typeCtx.InterfaceContexts)
typeDefinition.Interfaces.Add(new(interfaceType.ToTypeSignature(typeDefinition.DeclaringModule!).ToTypeDefOrRef()));
}

var assemblyDefinition = asmCtx.GetExtraData<AssemblyDefinition>("AsmResolverAssembly") ?? throw new("AsmResolver assembly not found in assembly analysis context for " + asmCtx);
var moduleDefinition = assemblyDefinition.ManifestModule!;
foreach (var typeCtx in asmCtx.ExportedTypes)
{
var owningAssembly = typeCtx.DeclaringAssembly.GetExtraData<AssemblyDefinition>("AsmResolverAssembly") ?? throw new("AsmResolver assembly not found in assembly analysis context for " + typeCtx.DeclaringAssembly);
moduleDefinition.ExportedTypes.Add(new ExportedType(owningAssembly.ToAssemblyReference(), typeCtx.Namespace, typeCtx.Name));
}
}

private static void PopulateGenericParamsForType(TypeAnalysisContext cppTypeDefinition, TypeDefinition ilTypeDefinition)
Expand Down
9 changes: 8 additions & 1 deletion LibCpp2IL/Metadata/Il2CppImageDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ public class Il2CppImageDefinition : ReadableClass

public string? Name => OwningContext.Metadata.GetStringFromIndex(nameIndex);

public Il2CppTypeDefinition[]? Types => Enumerable
public Il2CppTypeDefinition[] Types => Enumerable
.Range(firstTypeIndex.Value, (int)typeCount)
.Select(Il2CppVariableWidthIndex<Il2CppTypeDefinition>.MakeTemporaryForFixedWidthUsage) // DynWidth: using Enumerable.Range, not read from file, so making temp is ok
.Select(OwningContext.Metadata.GetTypeDefinitionFromIndex)
.ToArray();

public Il2CppTypeDefinition[]? ExportedTypes => IsAtLeast(24)
? Enumerable
.Range(exportedTypeStart.Value, (int)exportedTypeCount)
.Select(OwningContext.Metadata.GetExportedTypeDefintionFromIndex)
.ToArray()
: null;

public override string ToString()
{
return $"Il2CppImageDefinition[Name={Name}]";
Expand Down
13 changes: 13 additions & 0 deletions LibCpp2IL/Metadata/Il2CppMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
public Il2CppFieldRef[] fieldRefs;
private Il2CppGenericParameter[] genericParameters;
public Il2CppVariableWidthIndex<Il2CppType>[] constraintIndices;
public int[] exportedTypes;

public int[] referencedAssemblies;

Expand Down Expand Up @@ -186,7 +187,7 @@
return new Il2CppMetadata(new MemoryStream(bytes), unityVersion, actualVersion);
}

private Il2CppMetadata(MemoryStream stream, UnityVersion unityVersion, float metadataVersion) : base(stream)

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (osx-arm64, Cpp2IL)

Non-nullable property 'OwningContext' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (osx-arm64, Cpp2IL)

Non-nullable field 'exportedTypes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (osx-arm64, Cpp2IL)

Non-nullable field 'TypeInlineArrays' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (linux-arm64, Cpp2IL)

Non-nullable property 'OwningContext' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (linux-arm64, Cpp2IL)

Non-nullable field 'exportedTypes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Build Single-File Artifact (linux-arm64, Cpp2IL)

Non-nullable field 'TypeInlineArrays' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Publish Dev Package

Non-nullable property 'OwningContext' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Publish Dev Package

Non-nullable field 'exportedTypes' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 190 in LibCpp2IL/Metadata/Il2CppMetadata.cs

View workflow job for this annotation

GitHub Actions / Run Tests & Publish Dev Package

Non-nullable field 'TypeInlineArrays' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
UnityVersion = unityVersion;
MetadataVersion = metadataVersion;
Expand Down Expand Up @@ -370,6 +371,16 @@
stringLiterals = ReadMetadataClassArray<Il2CppStringLiteral>(metadataHeader.stringLiteral);
LibLogger.VerboseNewline($"OK ({(DateTime.Now - start).TotalMilliseconds} ms)");

if (MetadataVersion > 24)
{
LibLogger.Verbose("\tReading exported types...");
start = DateTime.Now;

exportedTypes = ReadClassArrayAtRawAddr<int>(metadataHeader.exportedTypeDefinitions.Offset, metadataHeader.exportedTypeDefinitions.Size / sizeof(int));

LibLogger.VerboseNewline($"OK ({(DateTime.Now - start).TotalMilliseconds} ms)");
}

if (MetadataVersion < 24.2f)
{
LibLogger.Verbose("\tReading RGCTX data...");
Expand Down Expand Up @@ -685,6 +696,8 @@
}

public Il2CppTypeDefinition GetTypeDefinitionFromIndex(Il2CppVariableWidthIndex<Il2CppTypeDefinition> index) => typeDefs[index.Value];

public Il2CppTypeDefinition GetExportedTypeDefintionFromIndex(int index) => typeDefs[exportedTypes[index]];

public Il2CppGenericContainer GetGenericContainerFromIndex(Il2CppVariableWidthIndex<Il2CppGenericContainer> index) => genericContainers[index.Value];

Expand Down
Loading