fix: #2503 Weaver Custom Read Write functions for Serialization not working over multiple assembly definitions

This commit is contained in:
mischa 2024-03-08 15:11:30 +08:00
parent f10bc77195
commit 65f33dee90
2 changed files with 23 additions and 1 deletions

View File

@ -98,7 +98,13 @@ public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters p
// let's make it obvious why we returned null for easier debugging.
// NOTE: if this fails for "System.Private.CoreLib":
// ILPostProcessorReflectionImporter fixes it!
Log.Warning($"ILPostProcessorAssemblyResolver.Resolve: Failed to find file for {name}");
// the fix for #2503 started showing this warning for Bee.BeeDriver on mac,
// which is for compilation. we can ignore that one.
if (name.Name != "Bee.BeeDriver")
{
Log.Warning($"ILPostProcessorAssemblyResolver.Resolve: Failed to find file for {name}");
}
return null;
}

View File

@ -1,4 +1,5 @@
// finds all readers and writers and register them
using System.Collections.Generic;
using System.Linq;
using Mono.CecilX;
using Mono.CecilX.Cil;
@ -17,6 +18,21 @@ public static bool Process(AssemblyDefinition CurrentAssembly, IAssemblyResolver
// otherwise Unity crashes when running tests
ProcessMirrorAssemblyClasses(CurrentAssembly, resolver, Log, writers, readers, ref WeavingFailed);
// process dependencies first, this way weaver can process types of other assemblies properly.
// fixes: https://github.com/MirrorNetworking/Mirror/issues/2503
//
// find NetworkReader/Writer extensions in referenced assemblies
// save a copy of the collection enumerator since it appears to be modified at some point during iteration
IEnumerable<AssemblyNameReference> assemblyReferences = CurrentAssembly.MainModule.AssemblyReferences.ToList();
foreach (AssemblyNameReference assemblyNameReference in assemblyReferences)
{
AssemblyDefinition referencedAssembly = resolver.Resolve(assemblyNameReference);
if (referencedAssembly != null)
{
ProcessAssemblyClasses(CurrentAssembly, referencedAssembly, writers, readers, ref WeavingFailed);
}
}
// find readers/writers in the assembly we are in right now.
return ProcessAssemblyClasses(CurrentAssembly, CurrentAssembly, writers, readers, ref WeavingFailed);
}