From 4768c039d2b6fbe1d0e31c3aa6386dbbf7b09acd Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 7 Mar 2025 13:29:47 +0800 Subject: [PATCH] [fix] fixed hook failed in version below MacOS 11 --- Editor/3rds/UnityHook/HookUtils_OSX.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Editor/3rds/UnityHook/HookUtils_OSX.cs b/Editor/3rds/UnityHook/HookUtils_OSX.cs index 8e4a126..4efdb0b 100644 --- a/Editor/3rds/UnityHook/HookUtils_OSX.cs +++ b/Editor/3rds/UnityHook/HookUtils_OSX.cs @@ -16,7 +16,11 @@ namespace MonoHook static HookUtils() { - jit_write_protect_supported = pthread_jit_write_protect_supported_np() != 0; + try + { + jit_write_protect_supported = pthread_jit_write_protect_supported_np() != 0; + } + catch { } PropertyInfo p_SystemPageSize = typeof(Environment).GetProperty("SystemPageSize"); if (p_SystemPageSize == null) @@ -35,6 +39,16 @@ namespace MonoHook public static void MemCpy_Jit(void* pDst, byte[] src) { + if (!jit_write_protect_supported) + { + fixed(void * pSrc = &src[0]) + { + MemCpy(pDst, pSrc, src.Length); + } + + return; + } + fixed(void * p = &src[0]) { memcpy_jit(new IntPtr(pDst), new IntPtr(p), src.Length);