fix: INetworkMessageILPP failing to output registration code for network messages (#2256)
* fix Resolves the issue where NetworkMessageILPP was failing for users using different API Compatibility Settings.
This commit is contained in:
Родитель
ad633b2b95
Коммит
8d2218748a
|
@ -398,20 +398,21 @@ namespace Unity.Netcode.Editor.CodeGen
|
|||
return assemblyDefinition;
|
||||
}
|
||||
|
||||
public static (ModuleDefinition DotnetModule, ModuleDefinition UnityModule, ModuleDefinition NetcodeModule) FindBaseModules(AssemblyDefinition assemblyDefinition, PostProcessorAssemblyResolver assemblyResolver)
|
||||
private static void SearchForBaseModulesRecursive(AssemblyDefinition assemblyDefinition, PostProcessorAssemblyResolver assemblyResolver, ref ModuleDefinition unityModule, ref ModuleDefinition netcodeModule, HashSet<string> visited)
|
||||
{
|
||||
ModuleDefinition dotnetModule = null;
|
||||
ModuleDefinition unityModule = null;
|
||||
ModuleDefinition netcodeModule = null;
|
||||
|
||||
foreach (var module in assemblyDefinition.Modules)
|
||||
{
|
||||
if (dotnetModule == null && module.Name == DotnetModuleName)
|
||||
if (module == null)
|
||||
{
|
||||
dotnetModule = module;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unityModule != null && netcodeModule != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (unityModule == null && module.Name == UnityModuleName)
|
||||
{
|
||||
unityModule = module;
|
||||
|
@ -424,41 +425,46 @@ namespace Unity.Netcode.Editor.CodeGen
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (dotnetModule != null && unityModule != null && netcodeModule != null)
|
||||
if (unityModule != null && netcodeModule != null)
|
||||
{
|
||||
return (dotnetModule, unityModule, netcodeModule);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var assemblyNameReference in assemblyDefinition.MainModule.AssemblyReferences)
|
||||
{
|
||||
foreach (var module in assemblyResolver.Resolve(assemblyNameReference).Modules)
|
||||
if (assemblyNameReference == null)
|
||||
{
|
||||
if (dotnetModule == null && module.Name == DotnetModuleName)
|
||||
{
|
||||
dotnetModule = module;
|
||||
continue;
|
||||
}
|
||||
if (unityModule == null && module.Name == UnityModuleName)
|
||||
{
|
||||
unityModule = module;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (netcodeModule == null && module.Name == NetcodeModuleName)
|
||||
{
|
||||
netcodeModule = module;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (visited.Contains(assemblyNameReference.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dotnetModule != null && unityModule != null && netcodeModule != null)
|
||||
visited.Add(assemblyNameReference.Name);
|
||||
|
||||
var assembly = assemblyResolver.Resolve(assemblyNameReference);
|
||||
if (assembly == null)
|
||||
{
|
||||
return (dotnetModule, unityModule, netcodeModule);
|
||||
continue;
|
||||
}
|
||||
SearchForBaseModulesRecursive(assembly, assemblyResolver, ref unityModule, ref netcodeModule, visited);
|
||||
|
||||
if (unityModule != null && netcodeModule != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (dotnetModule, unityModule, netcodeModule);
|
||||
public static (ModuleDefinition UnityModule, ModuleDefinition NetcodeModule) FindBaseModules(AssemblyDefinition assemblyDefinition, PostProcessorAssemblyResolver assemblyResolver)
|
||||
{
|
||||
ModuleDefinition unityModule = null;
|
||||
ModuleDefinition netcodeModule = null;
|
||||
var visited = new HashSet<string>();
|
||||
SearchForBaseModulesRecursive(assemblyDefinition, assemblyResolver, ref unityModule, ref netcodeModule, visited);
|
||||
|
||||
return (unityModule, netcodeModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,13 +38,7 @@ namespace Unity.Netcode.Editor.CodeGen
|
|||
}
|
||||
|
||||
// modules
|
||||
(m_DotnetModule, _, m_NetcodeModule) = CodeGenHelpers.FindBaseModules(assemblyDefinition, m_AssemblyResolver);
|
||||
|
||||
if (m_DotnetModule == null)
|
||||
{
|
||||
m_Diagnostics.AddError($"Cannot find .NET module: {CodeGenHelpers.DotnetModuleName}");
|
||||
return null;
|
||||
}
|
||||
(_, m_NetcodeModule) = CodeGenHelpers.FindBaseModules(assemblyDefinition, m_AssemblyResolver);
|
||||
|
||||
if (m_NetcodeModule == null)
|
||||
{
|
||||
|
@ -104,7 +98,6 @@ namespace Unity.Netcode.Editor.CodeGen
|
|||
return new ILPostProcessResult(new InMemoryAssembly(pe.ToArray(), pdb.ToArray()), m_Diagnostics);
|
||||
}
|
||||
|
||||
private ModuleDefinition m_DotnetModule;
|
||||
private ModuleDefinition m_NetcodeModule;
|
||||
private PostProcessorAssemblyResolver m_AssemblyResolver;
|
||||
|
||||
|
@ -121,22 +114,16 @@ namespace Unity.Netcode.Editor.CodeGen
|
|||
|
||||
private bool ImportReferences(ModuleDefinition moduleDefinition)
|
||||
{
|
||||
TypeDefinition typeTypeDef = null;
|
||||
TypeDefinition listTypeDef = null;
|
||||
foreach (var dotnetTypeDef in m_DotnetModule.GetAllTypes())
|
||||
{
|
||||
if (typeTypeDef == null && dotnetTypeDef.Name == typeof(Type).Name)
|
||||
{
|
||||
typeTypeDef = dotnetTypeDef;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listTypeDef == null && dotnetTypeDef.Name == typeof(List<>).Name)
|
||||
{
|
||||
listTypeDef = dotnetTypeDef;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Different environments seem to have different situations...
|
||||
// Some have these definitions in netstandard.dll...
|
||||
// some seem to have them elsewhere...
|
||||
// Since they're standard .net classes they're not going to cause
|
||||
// the same issues as referencing other assemblies, in theory, since
|
||||
// the definitions should be standard and consistent across platforms
|
||||
// (i.e., there's no #if UNITY_EDITOR in them that could create
|
||||
// invalid IL code)
|
||||
TypeDefinition typeTypeDef = moduleDefinition.ImportReference(typeof(Type)).Resolve();
|
||||
TypeDefinition listTypeDef = moduleDefinition.ImportReference(typeof(List<>)).Resolve();
|
||||
|
||||
TypeDefinition messageHandlerTypeDef = null;
|
||||
TypeDefinition messageWithHandlerTypeDef = null;
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace Unity.Netcode.Editor.CodeGen
|
|||
}
|
||||
|
||||
// modules
|
||||
(_, m_UnityModule, m_NetcodeModule) = CodeGenHelpers.FindBaseModules(assemblyDefinition, m_AssemblyResolver);
|
||||
(m_UnityModule, m_NetcodeModule) = CodeGenHelpers.FindBaseModules(assemblyDefinition, m_AssemblyResolver);
|
||||
|
||||
if (m_UnityModule == null)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче