From be603201fb3df6ed5db592769812a8b312ceb425 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Wed, 16 Sep 2026 15:17:14 -0400 Subject: [PATCH] fix: Improve Weaver Helpers / Unity 6K compatibility --- Assets/Mirror/Editor/Weaver/Helpers.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Assets/Mirror/Editor/Weaver/Helpers.cs b/Assets/Mirror/Editor/Weaver/Helpers.cs index 56b73851005..2f0df88a07a 100644 --- a/Assets/Mirror/Editor/Weaver/Helpers.cs +++ b/Assets/Mirror/Editor/Weaver/Helpers.cs @@ -1,7 +1,9 @@ using System.IO; using System.Linq; -using System.Reflection; using Mono.CecilX; +#if UNITY_6000_0_OR_NEWER +using UnityEngine; +#endif namespace Mirror.Weaver { @@ -10,8 +12,20 @@ static class Helpers // This code is taken from SerializationWeaver public static string UnityEngineDllDirectoryName() { - string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); - return directoryName?.Replace(@"file:\", ""); +#if UNITY_6000_0_OR_NEWER + // Unity loads many assemblies from streams, so Location/CodeBase are empty. + // GetLoadedAssemblyPath() is Unity's mapping back to the original file. + string assemblyPath = typeof(UnityEngine.Object).Assembly.GetLoadedAssemblyPath(); + if (!string.IsNullOrEmpty(assemblyPath)) + return Path.GetDirectoryName(assemblyPath); +#endif + + // Fallback used by CompilationFinishedHook for CoreModule + string coreModule = UnityEditorInternal.InternalEditorUtility.GetEngineCoreModuleAssemblyPath(); + if (!string.IsNullOrEmpty(coreModule)) + return Path.GetDirectoryName(coreModule); + + return null; } public static bool IsEditorAssembly(AssemblyDefinition currentAssembly)