protected virtual void OnPlayerLeft(Player player)
        {
            PlayerLeftDelegate handler = PlayerLeft;

            if (handler != null)
            {
                handler(this, player);
            }
        }
Exemple #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!");
            }
        }