Пример #1
0
        internal static bool PatchMethods()
        {
            try
            {
                // Left room
                MethodInfo onLeftRoomMethod = typeof(NetworkManager).GetMethod(
                    nameof(NetworkManager.OnLeftRoom),
                    BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                    null,
                    Type.EmptyTypes,
                    null);
                origOnLeftRoom = Patch <OnLeftRoom>(onLeftRoomMethod, GetDetour(nameof(OnLeftRoomPatch)));
            }
            catch (Exception e)
            {
                MelonLogger.Error("Failed to patch OnLeftRoom\n" + e.Message);
                return(false);
            }

            try
            {
                // Faded to and joined and initialized room
                MethodInfo fadeMethod = typeof(VRCUiManager).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).First(
                    m => m.Name.StartsWith("Method_Public_Void_String_Single_Action_") &&
                    m.Name.IndexOf("PDM", StringComparison.OrdinalIgnoreCase) == -1 &&
                    m.GetParameters().Length == 3);
                origFadeTo = Patch <FadeTo>(fadeMethod, GetDetour(nameof(FadeToPatch)));
            }
            catch (Exception e)
            {
                MelonLogger.Error("Failed to patch FadeTo\n" + e.Message);
                return(false);
            }

            if (Utilities.IsInVR)
            {
                try
                {
                    // Fixes spinning issue
                    // TL;DR Prevents the tracking manager from applying rotational force
                    MethodInfo applyPlayerMotionMethod = typeof(VRCTrackingManager).GetMethods(BindingFlags.Public | BindingFlags.Static)
                                                         .Where(
                        m => m.Name.StartsWith("Method_Public_Static_Void_Vector3_Quaternion") &&
                        !m.Name.Contains("_PDM_")).First(
                        m => XrefScanner.UsedBy(m).Any(
                            xrefInstance => xrefInstance.Type == XrefType.Method &&
                            xrefInstance.TryResolve()?.ReflectedType
                            ?.Equals(typeof(VRC_StationInternal))
                            == true));
                    origApplyPlayerMotion = Patch <ApplyPlayerMotion>(applyPlayerMotionMethod, GetDetour(nameof(ApplyPlayerMotionPatch)));
                }
                catch (Exception e)
                {
                    MelonLogger.Error("Failed to patch ApplyPlayerMotion\n" + e.Message);
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
    private void Client_OnStateChangeAction(ClientState clientState)
    {
        switch (clientState)
        {
        case ClientState.JoinedLobby:
            LocalPlayerID = LocalPlayer.ID;
            OnJoinedLobby?.Invoke();
            break;

        case ClientState.DisconnectingFromMasterserver:
            OnDisconnectedFromMasterServer?.Invoke();
            break;

        case ClientState.ConnectedToGameserver:
            OnConnectedToGameServer?.Invoke();
            break;

        case ClientState.Joining:
            OnJoinedGame?.Invoke();
            break;

        case ClientState.Joined:
            LocalPlayerID = LocalPlayer.ID;
            OnJoinedRoom?.Invoke();
            break;

        case ClientState.Leaving:
            OnLeftRoom?.Invoke();
            break;

        case ClientState.Disconnected:
            OnDisconnected?.Invoke();
            break;

        case ClientState.ConnectedToMasterserver:
            CreateOrJoinRoom();
            OnConnectedToMasterServer?.Invoke();
            break;

        case ClientState.ConnectedToNameServer:
            if (string.IsNullOrEmpty(client.CloudRegion))
            {
                client.OpGetRegions();
            }
            break;
        }
    }