コード例 #1
0
ファイル: Hooking.cs プロジェクト: ehefk/VRCEyeTracking
        public static unsafe void SetupHooking()
        {
            try
            {
                var intPtr = (IntPtr)typeof(VRCAvatarManager.MulticastDelegateNPublicSealedVoGaVRBoUnique)
                             .GetField(
                    "NativeMethodInfoPtr_Invoke_Public_Virtual_New_Void_GameObject_VRC_AvatarDescriptor_Boolean_0",
                    BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                Imports.Hook(intPtr,
                             new Action <IntPtr, IntPtr, IntPtr, bool>(OnAvatarInstantiated).Method.MethodHandle
                             .GetFunctionPointer());
                _onAvatarInstantiatedDelegate =
                    Marshal.GetDelegateForFunctionPointer <AvatarInstantiatedDelegate>(*(IntPtr *)(void *)intPtr);

                intPtr = (IntPtr)typeof(VRCAvatarManager)
                         .GetField(
                    "NativeMethodInfoPtr_Method_Public_Boolean_ApiAvatar_String_Single_MulticastDelegateNPublicSealedVoGaVRBoUnique_0",
                    BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                Imports.Hook(intPtr,
                             new Action <IntPtr, IntPtr, string, float, IntPtr>(OnAvatarSwitch).Method.MethodHandle
                             .GetFunctionPointer());
                _avatarSwitch = Marshal.GetDelegateForFunctionPointer <OnAvatarSwitchDelegate>(*(IntPtr *)(void *)intPtr);
            }
            catch (Exception ex)
            {
                MelonLogger.Msg("Patch Failed " + ex);
            }
        }
コード例 #2
0
        private static unsafe void HookCallbackFunctions()
        {
            IntPtr funcToHook = (IntPtr)typeof(VRCAvatarManager.MulticastDelegateNPublicSealedVoGaVRBoUnique).GetField("NativeMethodInfoPtr_Invoke_Public_Virtual_New_Void_GameObject_VRC_AvatarDescriptor_Boolean_0", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null);

            Hook(funcToHook, new System.Action <IntPtr, IntPtr, IntPtr, bool>(OnAvatarInstantiated).Method.MethodHandle.GetFunctionPointer());
            onAvatarInstantiatedDelegate = Marshal.GetDelegateForFunctionPointer <AvatarInstantiatedDelegate>(*(IntPtr *)funcToHook);
            IceLogger.Log(((onAvatarInstantiatedDelegate != null) ? "Hooked onAvatarInstantiatedDelegate!" : "onAvatarInstantiatedDelegate: critical error!!"));

            funcToHook = (IntPtr)typeof(NetworkManager).GetField("NativeMethodInfoPtr_Method_Public_Void_Player_0", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null);
            Hook(funcToHook, new System.Action <IntPtr, IntPtr>(OnPlayerLeft).Method.MethodHandle.GetFunctionPointer());
            onPlayerLeftDelegate = Marshal.GetDelegateForFunctionPointer <PlayerLeftDelegate>(*(IntPtr *)funcToHook);
            IceLogger.Log(((onPlayerLeftDelegate != null) ? "Hooked onPlayerLeftDelegate!" : "onPlayerLeftDelegate: critical error!!"));

            funcToHook = (IntPtr)typeof(NetworkManager).GetField("NativeMethodInfoPtr_OnJoinedRoom_Public_Virtual_Final_New_Void_3", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null);
            Hook(funcToHook, new System.Action <IntPtr>(OnJoinedRoom).Method.MethodHandle.GetFunctionPointer());
            onJoinedRoom = Marshal.GetDelegateForFunctionPointer <JoinedRoom>(*(IntPtr *)funcToHook);
            IceLogger.Log(((onJoinedRoom != null) ? "Hooked onJoinedRoom!" : "onJoinedRoom: critical error!!"));

            if (onPlayerLeftDelegate == null || onAvatarInstantiatedDelegate == null || onJoinedRoom == null)
            {
                enabled = false;
                IceLogger.Log("Multiplayer Dynamic Bones mod suffered a critical error!");
            }
        }