Beispiel #1
0
        static bool Prefix()
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }
            if (LongEventHandler.currentEvent != null)
            {
                return(false);
            }
            if (Multiplayer.session.desynced)
            {
                return(false);
            }

            double delta = Time.deltaTime * 60.0;

            if (delta > 3)
            {
                delta = 3;
            }

            accumulator += delta;

            if (Timer >= tickUntil)
            {
                accumulator = 0;
            }
            else if (!Multiplayer.IsReplay && delta < 1.5 && tickUntil - Timer > 6)
            {
                accumulator += Math.Min(100, tickUntil - Timer - 6);
            }

            if (Multiplayer.IsReplay && replayTimeSpeed == TimeSpeed.Paused)
            {
                accumulator = 0;
            }

            if (skipToTickUntil)
            {
                skipTo = tickUntil;
            }

            if (skipTo >= 0 && Timer >= skipTo)
            {
                afterSkip?.Invoke();
                ClearSkipping();
            }

            SimpleProfiler.Start();
            Tick();
            SimpleProfiler.Pause();

            return(false);
        }
Beispiel #2
0
        static bool Prefix()
        {
            if (Multiplayer.Client == null)
            {
                return(true);
            }
            if (LongEventHandler.currentEvent != null)
            {
                return(false);
            }
            if (Multiplayer.session.desynced)
            {
                return(false);
            }

            double delta = time.ElapsedMillisDouble() / 1000.0 * 60.0;

            time.Restart();

            int maxDelta = MultiplayerMod.settings.aggressiveTicking ? 6 : 3;

            if (delta > maxDelta)
            {
                delta = maxDelta;
            }

            accumulator += delta;

            float okDelta = MultiplayerMod.settings.aggressiveTicking ? 2.5f : 1.7f;

            if (Timer >= tickUntil)
            {
                accumulator = 0;
            }
            else if (!Multiplayer.IsReplay && delta < okDelta && tickUntil - Timer > maxBehind)
            {
                accumulator += Math.Min(60, tickUntil - Timer - maxBehind);
            }

            if (Multiplayer.IsReplay && replayTimeSpeed == TimeSpeed.Paused)
            {
                accumulator = 0;
            }

            if (skipToTickUntil)
            {
                skipTo = tickUntil;
            }

            CheckFinishSkipping();
            if (MpVersion.IsDebug)
            {
                SimpleProfiler.Start();
            }

            updateTimer.Restart();
            Tick();
            lastUpdateTook = updateTimer.ElapsedMillisDouble();

            if (MpVersion.IsDebug)
            {
                SimpleProfiler.Pause();
            }

            CheckFinishSkipping();

            return(false);
        }
Beispiel #3
0
        static MultiplayerStatic()
        {
            Native.InitLmfPtr();

            // UnityEngine.Debug.Log instead of Verse.Log.Message because the server runs on its own thread
            ServerLog.info  = str => UnityEngine.Debug.Log($"MpServerLog: {str}");
            ServerLog.error = str => UnityEngine.Debug.Log($"MpServerLog Error: {str}");
            NetDebug.Logger = new ServerLog();

            SetUsername();

            if (SteamManager.Initialized)
            {
                SteamIntegration.InitCallbacks();
            }

            Log.Message($"Multiplayer version {MpVersion.Version}");
            Log.Message($"Player's username: {Multiplayer.username}");

            var persistentObj = new GameObject();

            persistentObj.AddComponent <OnMainThread>();
            UnityEngine.Object.DontDestroyOnLoad(persistentObj);

            MpConnectionState.SetImplementation(ConnectionStateEnum.ClientSteam, typeof(ClientSteamState));
            MpConnectionState.SetImplementation(ConnectionStateEnum.ClientJoining, typeof(ClientJoiningState));
            MpConnectionState.SetImplementation(ConnectionStateEnum.ClientPlaying, typeof(ClientPlayingState));

            MultiplayerData.CollectCursorIcons();

            PersistentDialog.BindAll(typeof(Multiplayer).Assembly);

            using (DeepProfilerWrapper.Section("Multiplayer MpPatches"))
                Multiplayer.harmony.DoAllMpPatches();

            using (DeepProfilerWrapper.Section("Multiplayer patches"))
                DoPatches();

            Log.messageQueue.maxMessages = 1000;

            DoubleLongEvent(() =>
            {
                MultiplayerData.CollectDefInfos();
                Sync.PostInitHandlers();
            }, "Loading"); // Right before the events from HandleCommandLine

            HandleRestartConnect();
            HandleCommandLine();

            if (Multiplayer.arbiterInstance)
            {
                RuntimeHelpers.RunClassConstructor(typeof(Text).TypeHandle);
            }

            using (DeepProfilerWrapper.Section("Multiplayer TakeModDataSnapshot"))
                JoinData.TakeModDataSnapshot();

            using (DeepProfilerWrapper.Section("MultiplayerData PrecacheMods"))
                MultiplayerData.PrecacheMods();

            if (GenCommandLine.CommandLineArgPassed("profiler"))
            {
                SimpleProfiler.Print("mp_prof_out.txt");
            }
        }