Skip to content
Open
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
20 changes: 17 additions & 3 deletions Assets/Mirror/Editor/Weaver/Helpers.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)
Expand Down
Loading