Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ReaderWriterProcessor) : When crossing assemblies problem #3864

Merged
merged 2 commits into from
Oct 7, 2024
Merged
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
46 changes: 37 additions & 9 deletions Assets/Mirror/Editor/Weaver/Processors/ReaderWriterProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,47 @@ public static bool Process(AssemblyDefinition CurrentAssembly, IAssemblyResolver
// 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)
IEnumerable<AssemblyDefinition> assemblyReferences = FindProcessTargetAssemblies(CurrentAssembly, resolver)
.Where(assembly => assembly != null && assembly != CurrentAssembly);

foreach (AssemblyDefinition referencedAssembly in assemblyReferences)
ProcessAssemblyClasses(CurrentAssembly, referencedAssembly, writers, readers, ref WeavingFailed);

return ProcessAssemblyClasses(CurrentAssembly, CurrentAssembly, writers, readers, ref WeavingFailed);
}

static List<AssemblyDefinition> FindProcessTargetAssemblies(AssemblyDefinition assembly, IAssemblyResolver resolver)
{
HashSet<string> processedAssemblies = new HashSet<string>();
List<AssemblyDefinition> assemblies = new List<AssemblyDefinition>();

ProcessAssembly(assembly);

return assemblies;

void ProcessAssembly(AssemblyDefinition current)
{
AssemblyDefinition referencedAssembly = resolver.Resolve(assemblyNameReference);
if (referencedAssembly != null)
// If the assembly has already been processed, we skip it
if (current.FullName == Weaver.MirrorAssemblyName || !processedAssemblies.Add(current.FullName))
return;

IEnumerable<AssemblyNameReference> references = current.MainModule.AssemblyReferences;

// If there is no Mirror reference, there will be no ReaderWriter or NetworkMessage, so skip
if (references.All(reference => reference.Name != Weaver.MirrorAssemblyName))
return;

// Add the assembly to the processed set and list
assemblies.Add(current);

// Process the references of the current assembly
foreach (AssemblyNameReference reference in references)
{
ProcessAssemblyClasses(CurrentAssembly, referencedAssembly, writers, readers, ref WeavingFailed);
AssemblyDefinition referencedAssembly = resolver.Resolve(reference);
if (referencedAssembly != null)
ProcessAssembly(referencedAssembly);
}
}

// find readers/writers in the assembly we are in right now.
return ProcessAssemblyClasses(CurrentAssembly, CurrentAssembly, writers, readers, ref WeavingFailed);
}

static void ProcessMirrorAssemblyClasses(AssemblyDefinition CurrentAssembly, IAssemblyResolver resolver, Logger Log, Writers writers, Readers readers, ref bool WeavingFailed)
Expand Down