GetIl2CppFolderHook.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. using UnityEngine;
  7. using UnityEditor;
  8. using System.Runtime.CompilerServices;
  9. using MonoHook;
  10. using HybridCLR.Editor.BuildProcessors;
  11. using System.IO;
  12. namespace HybridCLR.MonoHook
  13. {
  14. #if UNITY_2022 || UNITY_2023_1_OR_NEWER
  15. [InitializeOnLoad]
  16. public class GetIl2CppFolderHook
  17. {
  18. private static MethodHook _hook;
  19. static GetIl2CppFolderHook()
  20. {
  21. if (_hook == null)
  22. {
  23. Type type = typeof(UnityEditor.EditorApplication).Assembly.GetType("UnityEditorInternal.IL2CPPUtils");
  24. MethodInfo miTarget = type.GetMethod("GetIl2CppFolder", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null,
  25. new Type[] { typeof(bool).MakeByRefType() }, null);
  26. MethodInfo miReplacement = new StripAssembliesDel(OverrideMethod).Method;
  27. MethodInfo miProxy = new StripAssembliesDel(PlaceHolderMethod).Method;
  28. _hook = new MethodHook(miTarget, miReplacement, miProxy);
  29. _hook.Install();
  30. }
  31. }
  32. private delegate string StripAssembliesDel(out bool isDevelopmentLocation);
  33. private static string OverrideMethod(out bool isDevelopmentLocation)
  34. {
  35. //Debug.Log("[GetIl2CppFolderHook] OverrideMethod");
  36. string result = PlaceHolderMethod(out isDevelopmentLocation);
  37. isDevelopmentLocation = false;
  38. return result;
  39. }
  40. [MethodImpl(MethodImplOptions.NoOptimization)]
  41. private static string PlaceHolderMethod(out bool isDevelopmentLocation)
  42. {
  43. Debug.LogError("[GetIl2CppFolderHook] PlaceHolderMethod");
  44. isDevelopmentLocation = false;
  45. return null;
  46. }
  47. }
  48. #endif
  49. }