Helpers.cs 897 B

1234567891011121314151617181920212223242526
  1. using System.IO;
  2. using System.Linq;
  3. using System.Reflection;
  4. using Mono.CecilX;
  5. namespace Mirror.Weaver
  6. {
  7. static class Helpers
  8. {
  9. // This code is taken from SerializationWeaver
  10. public static string UnityEngineDllDirectoryName()
  11. {
  12. string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
  13. return directoryName?.Replace(@"file:\", "");
  14. }
  15. public static bool IsEditorAssembly(AssemblyDefinition currentAssembly)
  16. {
  17. // we want to add the [InitializeOnLoad] attribute if it's available
  18. // -> usually either 'UnityEditor' or 'UnityEditor.CoreModule'
  19. return currentAssembly.MainModule.AssemblyReferences.Any(assemblyReference =>
  20. assemblyReference.Name.StartsWith(nameof(UnityEditor))
  21. );
  22. }
  23. }
  24. }