Skip to content

Commit

Permalink
Fix bugs in HasCustomAttribute affecting performance (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 authored Dec 25, 2024
1 parent 6013b89 commit 5a919d9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ private void InitPre29AttributeGeneratorAnalysis(int rangeIndex)
{
ulong generatorPtr;
if (AppContext.MetadataVersion < 27)
{
if (rangeIndex < 0)
{
RawIl2CppCustomAttributeData = Array.Empty<byte>();
return;
}

try
{
generatorPtr = AppContext.Binary.GetCustomAttributeGenerator(rangeIndex);
Expand All @@ -147,6 +154,7 @@ private void InitPre29AttributeGeneratorAnalysis(int rangeIndex)
RawIl2CppCustomAttributeData = Array.Empty<byte>();
return;
}
}
else
{
var baseAddress = CustomAttributeAssembly.CodeGenModule!.customAttributeCacheGenerator;
Expand Down Expand Up @@ -204,7 +212,7 @@ public void AnalyzeCustomAttributeData(bool allowAnalysis = true)

//Basically, extract actions from the analysis, and compare with the type list we have to resolve parameters and populate the CustomAttributes list.

foreach (var il2CppType in AttributeTypes!) //Assert nonnull because we're pre-29 at this point
foreach (var il2CppType in AttributeTypes ?? []) //Can be null for injected objects
{
var typeDef = il2CppType.AsClass();
var attributeTypeContext = AppContext.ResolveContextForType(typeDef) ?? throw new("Unable to find type " + typeDef.FullName);
Expand Down

0 comments on commit 5a919d9

Please sign in to comment.