Improve recovery of Il2Cpp explicit interface overrides

* Resolves #1682
This commit is contained in:
ds5678 2025-02-24 16:12:22 -08:00
parent c171e7e946
commit b489c3d805
5 changed files with 4 additions and 61 deletions

View File

@ -58,7 +58,6 @@ public class ExportHandler
protected virtual IEnumerable<IAssetProcessor> GetProcessors()
{
yield return new IEnumeratorRepairProcessor();
if (Settings.ImportSettings.ScriptContentLevel == ScriptContentLevel.Level1)
{
yield return new MethodStubbingProcessor();

View File

@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="AssetRipper.IO.Endian" Version="2.0.0" />
<PackageReference Include="AssetRipper.Primitives" Version="3.1.5" />
<PackageReference Include="AssetRipper.Primitives" Version="3.1.6" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
<PackageReference Include="SharpCompress" Version="0.39.0" />
<PackageReference Include="ZstdSharp.Port" Version="0.8.4" />

View File

@ -10,9 +10,9 @@
<PackageReference Include="AsmResolver.DotNet" Version="6.0.0-beta.2" />
<PackageReference Include="AssetRipper.Gee.External.Capstone" Version="2.3.2" />
<PackageReference Include="AssetRipper.Mining.PredefinedAssets" Version="1.4.0" />
<PackageReference Include="AssetRipper.Primitives" Version="3.1.5" />
<PackageReference Include="AssetRipper.Primitives" Version="3.1.6" />
<PackageReference Include="AssetRipper.Tpk" Version="1.0.1" />
<PackageReference Include="Samboy063.Cpp2IL.Core" Version="2022.1.0-development.1197" />
<PackageReference Include="Samboy063.Cpp2IL.Core" Version="2022.1.0-development.1215" />
</ItemGroup>
<ItemGroup>

View File

@ -1,56 +0,0 @@
using AsmResolver.DotNet;
using AsmResolver.DotNet.Signatures;
using AsmResolver.PE.DotNet.Metadata.Tables;
using AssetRipper.Import.Structure.Assembly;
using AssetRipper.Import.Structure.Assembly.Managers;
using System.Collections;
namespace AssetRipper.Processing.Assemblies;
/// <summary>
/// Fixes IEnumerator implementations in IL2CPP assemblies.
/// </summary>
/// <remarks>
/// For no apparent reason, compiler-generated IEnumerator.MoveNext implementations seem to be invalid, which causes problems for ILSpy.
/// The methods are compiled as `private bool MoveNext()`, but they should be `public bool MoveNext()`.
/// Alternatively, they could be `bool System.Collections.IEnumerator.MoveNext()`, but it's better not to change the method signature.
/// </remarks>
public sealed class IEnumeratorRepairProcessor : IAssetProcessor
{
public void Process(GameData gameData) => Process(gameData.AssemblyManager);
private static void Process(IAssemblyManager manager)
{
if (manager.ScriptingBackend != ScriptingBackend.IL2Cpp)
{
return; // Not sure if Mono needs this
}
manager.ClearStreamCache();
foreach (ModuleDefinition module in manager.GetAssemblies().SelectMany(a => a.Modules))
{
foreach (TypeDefinition type in module.GetAllTypes().Where(t => t.IsNestedPrivate && t.IsCompilerGenerated() && t.Implements("System.Collections", "IEnumerator")))
{
const string MoveNext = nameof(IEnumerator.MoveNext);
const string FullName = "System.Collections.IEnumerator.MoveNext";
if (type.MethodImplementations.Any(m => m.Body?.Name?.Value is MoveNext or FullName))
{
continue;
}
MethodDefinition? method = type.Methods.FirstOrDefault(m =>
{
return m.Name == MoveNext
&& m.Parameters.Count == 0
&& m.Signature?.ReturnType is CorLibTypeSignature { ElementType: ElementType.Boolean };
});
if (method is null)
{
continue;
}
method.IsPublic = true;
}
}
}
}

View File

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AssetRipper.Primitives" Version="3.1.5" />
<PackageReference Include="AssetRipper.Primitives" Version="3.1.6" />
</ItemGroup>
</Project>