mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix(ReaderWriterProcessor) : When crossing assemblies problem (#3864)
* fix(ReaderWriterProcessor) Recursively handle the Network Reader/Writer required by CurrentAssembly.AssemblyReferences. * Remove brackets to one line statement. #3864 suggestion
This commit is contained in:
parent
f42eed3b16
commit
cdc58fdba9
@ -22,19 +22,47 @@ public static bool Process(AssemblyDefinition CurrentAssembly, IAssemblyResolver
|
|||||||
// fixes: https://github.com/MirrorNetworking/Mirror/issues/2503
|
// fixes: https://github.com/MirrorNetworking/Mirror/issues/2503
|
||||||
//
|
//
|
||||||
// find NetworkReader/Writer extensions in referenced assemblies
|
// 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<AssemblyDefinition> assemblyReferences = FindProcessTargetAssemblies(CurrentAssembly, resolver)
|
||||||
IEnumerable<AssemblyNameReference> assemblyReferences = CurrentAssembly.MainModule.AssemblyReferences.ToList();
|
.Where(assembly => assembly != null && assembly != CurrentAssembly);
|
||||||
foreach (AssemblyNameReference assemblyNameReference in assemblyReferences)
|
|
||||||
{
|
foreach (AssemblyDefinition referencedAssembly in assemblyReferences)
|
||||||
AssemblyDefinition referencedAssembly = resolver.Resolve(assemblyNameReference);
|
|
||||||
if (referencedAssembly != null)
|
|
||||||
{
|
|
||||||
ProcessAssemblyClasses(CurrentAssembly, referencedAssembly, writers, readers, ref WeavingFailed);
|
ProcessAssemblyClasses(CurrentAssembly, referencedAssembly, writers, readers, ref WeavingFailed);
|
||||||
}
|
|
||||||
|
return ProcessAssemblyClasses(CurrentAssembly, CurrentAssembly, writers, readers, ref WeavingFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find readers/writers in the assembly we are in right now.
|
static List<AssemblyDefinition> FindProcessTargetAssemblies(AssemblyDefinition assembly, IAssemblyResolver resolver)
|
||||||
return ProcessAssemblyClasses(CurrentAssembly, CurrentAssembly, writers, readers, ref WeavingFailed);
|
{
|
||||||
|
HashSet<string> processedAssemblies = new HashSet<string>();
|
||||||
|
List<AssemblyDefinition> assemblies = new List<AssemblyDefinition>();
|
||||||
|
|
||||||
|
ProcessAssembly(assembly);
|
||||||
|
|
||||||
|
return assemblies;
|
||||||
|
|
||||||
|
void ProcessAssembly(AssemblyDefinition current)
|
||||||
|
{
|
||||||
|
// 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)
|
||||||
|
{
|
||||||
|
AssemblyDefinition referencedAssembly = resolver.Resolve(reference);
|
||||||
|
if (referencedAssembly != null)
|
||||||
|
ProcessAssembly(referencedAssembly);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ProcessMirrorAssemblyClasses(AssemblyDefinition CurrentAssembly, IAssemblyResolver resolver, Logger Log, Writers writers, Readers readers, ref bool WeavingFailed)
|
static void ProcessMirrorAssemblyClasses(AssemblyDefinition CurrentAssembly, IAssemblyResolver resolver, Logger Log, Writers writers, Readers readers, ref bool WeavingFailed)
|
||||||
|
Loading…
Reference in New Issue
Block a user