Ejemplo n.º 1
0
        public static void LoadMP(MyObjectBuilder_World world, MyMultiplayerBase multiplayerSession)
        {
            SeamlessClient.TryShow("Starting LoadMP!");


            //var MySessionConstructor = MySessionType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[2] { typeof(MySyncLayer), typeof(bool) }, null);
            //MySession.Static = (MySession)MySessionConstructor.Invoke(new object[] { MyMultiplayer.Static.SyncLayer, true });
            MySession.Static.Mods            = World.Checkpoint.Mods;
            MySession.Static.Settings        = World.Checkpoint.Settings;
            MySession.Static.CurrentPath     = MyLocalCache.GetSessionSavesPath(MyUtils.StripInvalidChars(world.Checkpoint.SessionName), contentFolder: false, createIfNotExists: false);
            MySession.Static.WorldBoundaries = world.Checkpoint.WorldBoundaries;
            MySession.Static.InGameTime      = MyObjectBuilder_Checkpoint.DEFAULT_DATE;



            // MySession.Static.Players.LoadConnectedPlayers(world.Checkpoint);

            //typeof(MySession).GetMethod("PrepareBaseSession", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(MyObjectBuilder_Checkpoint), typeof(MyObjectBuilder_Sector) }, null).Invoke(MySession.Static, new object[] { world.Checkpoint, world.Sector });

            if (MyFakes.MP_SYNC_CLUSTERTREE)
            {
                SeamlessClient.TryShow("Deserializing Clusters!");
                //MyPhysics.DeserializeClusters(world.Clusters);
            }



            //_ = world.Checkpoint.ControlledObject;
            //world.Checkpoint.ControlledObject = -1L;
            LoadOnlinePlayers(world.Checkpoint);
            LoadWorld(world.Checkpoint, world.Sector);
            SeamlessClient.TryShow("Loading World Complete!");
        }
        private void endActionLoadSaves(IMyAsyncResult result, MyGuiScreenProgressAsync screen)
        {
            screen.CloseScreen();

            var selectedRow = m_worldsTable.SelectedRow;
            var world       = (MySteamWorkshop.SubscribedItem)selectedRow.UserData;



            string safeName        = MyUtils.StripInvalidChars(world.Title);
            var    tempSessionPath = MyLocalCache.GetSessionSavesPath(safeName, false, false);

            if (Directory.Exists(tempSessionPath))
            {
                OverwriteWorldDialog();
            }
            else
            {
                MySteamWorkshop.CreateWorldInstanceAsync(world, MySteamWorkshop.MyWorkshopPathInfo.CreateWorldInfo(), false, delegate(bool success, string sessionPath)
                {
                    if (success)
                    {
                        OnSuccess(sessionPath);
                    }
                });
            }
        }
Ejemplo n.º 3
0
        private bool TrySaveAs()
        {
            MyStringId?errorType = null;

            if (m_nameTextbox.Text.Length < 5)
            {
                errorType = MySpaceTexts.ErrorNameTooShort;
            }
            else if (m_nameTextbox.Text.Length > 30)
            {
                errorType = MySpaceTexts.ErrorNameTooLong;
            }


            if (m_existingSessionNames != null)
            {
                foreach (var name in m_existingSessionNames)
                {
                    if (name == m_nameTextbox.Text)
                    {
                        errorType = MySpaceTexts.ErrorNameAlreadyExists;
                    }
                }
            }

            if (errorType != null)
            {
                var messageBox = MyGuiSandbox.CreateMessageBox(
                    messageText: MyTexts.Get(errorType.Value),
                    messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError));
                messageBox.SkipTransition = true;
                messageBox.InstantClose   = false;
                MyGuiSandbox.AddScreen(messageBox);
                return(false);
            }

            if (m_fromMainMenu)
            {
                string name = MyUtils.StripInvalidChars(m_nameTextbox.Text);
                if (string.IsNullOrWhiteSpace(name))
                {
                    name = MyLocalCache.GetSessionSavesPath(name + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false);
                }
                MyAsyncSaving.Start(customName: name);
                MySession.Static.Name = m_nameTextbox.Text;
                this.CloseScreen();
                return(true);
            }

            m_copyFrom.SessionName = m_nameTextbox.Text;
            MyGuiSandbox.AddScreen(new MyGuiScreenProgressAsync(MySpaceTexts.SavingPleaseWait, null,
                                                                beginAction: () => new SaveResult(MyUtils.StripInvalidChars(m_nameTextbox.Text), m_sessionPath, m_copyFrom),
                                                                endAction: (result, screen) => { screen.CloseScreen(); this.CloseScreen(); }));
            return(true);
        }
            void SaveAsync(string newSaveName, string sessionPath, MyWorldInfo copyFrom)
            {
                // Try a simple path, then a random if it already exists
                var newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName, false, false);

                while (Directory.Exists(newSessionPath))
                {
                    newSessionPath = MyLocalCache.GetSessionSavesPath(newSaveName + MyUtils.GetRandomInt(int.MaxValue).ToString("########"), false, false);
                }
                Directory.CreateDirectory(newSessionPath);
                MyUtils.CopyDirectory(sessionPath, newSessionPath);
                ulong sizeInBytes;
                var   checkpoint = MyLocalCache.LoadCheckpoint(newSessionPath, out sizeInBytes);

                Debug.Assert(checkpoint != null);
                checkpoint.SessionName = copyFrom.SessionName;
                checkpoint.WorkshopId  = null;
                MyLocalCache.SaveCheckpoint(checkpoint, newSessionPath);
                MyLocalCache.SaveLastLoadedTime(newSessionPath, DateTime.Now);
            }
        private void SetWorldSettings()
        {
            //MyEntities.MemoryLimitAddFailureReset();

            //Clear old list
            MySession.Static.PromotedUsers.Clear();
            MySession.Static.CreativeTools.Clear();
            Dictionary <ulong, AdminSettingsEnum> AdminSettingsList = (Dictionary <ulong, AdminSettingsEnum>)Patches.RemoteAdminSettings.GetValue(MySession.Static);

            AdminSettingsList.Clear();



            // Set new world settings
            MySession.Static.Name        = MyStatControlText.SubstituteTexts(TargetWorld.Checkpoint.SessionName);
            MySession.Static.Description = TargetWorld.Checkpoint.Description;

            MySession.Static.Mods                     = TargetWorld.Checkpoint.Mods;
            MySession.Static.Settings                 = TargetWorld.Checkpoint.Settings;
            MySession.Static.CurrentPath              = MyLocalCache.GetSessionSavesPath(MyUtils.StripInvalidChars(TargetWorld.Checkpoint.SessionName), contentFolder: false, createIfNotExists: false);
            MySession.Static.WorldBoundaries          = TargetWorld.Checkpoint.WorldBoundaries;
            MySession.Static.InGameTime               = MyObjectBuilder_Checkpoint.DEFAULT_DATE;
            MySession.Static.ElapsedGameTime          = new TimeSpan(TargetWorld.Checkpoint.ElapsedGameTime);
            MySession.Static.Settings.EnableSpectator = false;


            MySession.Static.Password = TargetWorld.Checkpoint.Password;
            MySession.Static.PreviousEnvironmentHostility = TargetWorld.Checkpoint.PreviousEnvironmentHostility;
            MySession.Static.RequiresDX = TargetWorld.Checkpoint.RequiresDX;
            MySession.Static.CustomLoadingScreenImage = TargetWorld.Checkpoint.CustomLoadingScreenImage;
            MySession.Static.CustomLoadingScreenText  = TargetWorld.Checkpoint.CustomLoadingScreenText;
            MySession.Static.CustomSkybox             = TargetWorld.Checkpoint.CustomSkybox;


            MySession.Static.Gpss = new MyGpsCollection();
            MySession.Static.Gpss.LoadGpss(TargetWorld.Checkpoint);
            MyRenderProxy.RebuildCullingStructure();
            //MySession.Static.Toolbars.LoadToolbars(checkpoint);

            Sync.Players.RespawnComponent.InitFromCheckpoint(TargetWorld.Checkpoint);


            // Set new admin settings

            if (TargetWorld.Checkpoint.PromotedUsers != null)
            {
                MySession.Static.PromotedUsers = TargetWorld.Checkpoint.PromotedUsers.Dictionary;
            }
            else
            {
                MySession.Static.PromotedUsers = new Dictionary <ulong, MyPromoteLevel>();
            }



            foreach (KeyValuePair <MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> item in TargetWorld.Checkpoint.AllPlayersData.Dictionary)
            {
                ulong             clientId          = item.Key.GetClientId();
                AdminSettingsEnum adminSettingsEnum = (AdminSettingsEnum)item.Value.RemoteAdminSettings;
                if (TargetWorld.Checkpoint.RemoteAdminSettings != null && TargetWorld.Checkpoint.RemoteAdminSettings.Dictionary.TryGetValue(clientId, out var value))
                {
                    adminSettingsEnum = (AdminSettingsEnum)value;
                }
                if (!MyPlatformGameSettings.IsIgnorePcuAllowed)
                {
                    adminSettingsEnum &= ~AdminSettingsEnum.IgnorePcu;
                    adminSettingsEnum &= ~AdminSettingsEnum.KeepOriginalOwnershipOnPaste;
                }


                AdminSettingsList[clientId] = adminSettingsEnum;
                if (!Sync.IsDedicated && clientId == Sync.MyId)
                {
                    Patches.AdminSettings.SetValue(MySession.Static, adminSettingsEnum);

                    //m_adminSettings = adminSettingsEnum;
                }



                if (!MySession.Static.PromotedUsers.TryGetValue(clientId, out var value2))
                {
                    value2 = MyPromoteLevel.None;
                }
                if (item.Value.PromoteLevel > value2)
                {
                    MySession.Static.PromotedUsers[clientId] = item.Value.PromoteLevel;
                }
                if (!MySession.Static.CreativeTools.Contains(clientId) && item.Value.CreativeToolsEnabled)
                {
                    MySession.Static.CreativeTools.Add(clientId);
                }
            }
        }