Пример #1
0
        private static void LoadWorld(MyObjectBuilder_Checkpoint checkpoint, MyObjectBuilder_Sector sector)
        {
            Dictionary <ulong, AdminSettingsEnum> AdminSettingsList = (Dictionary <ulong, AdminSettingsEnum>)RemoteAdminSettings.GetValue(MySession.Static);

            AdminSettingsList.Clear();

            MySession.Static.PromotedUsers.Clear();
            MySession.Static.CreativeTools.Clear();

            MyEntities.MemoryLimitAddFailureReset();
            MySession.Static.ElapsedGameTime = new TimeSpan(checkpoint.ElapsedGameTime);
            MySession.Static.InGameTime      = checkpoint.InGameTime;
            MySession.Static.Name            = MyStatControlText.SubstituteTexts(checkpoint.SessionName);
            MySession.Static.Description     = checkpoint.Description;


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



            foreach (KeyValuePair <MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> item in checkpoint.AllPlayersData.Dictionary)
            {
                ulong             clientId          = item.Key.GetClientId();
                AdminSettingsEnum adminSettingsEnum = (AdminSettingsEnum)item.Value.RemoteAdminSettings;
                if (checkpoint.RemoteAdminSettings != null && 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)
                {
                    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);
                }
            }


            //MySession.Static.WorkshopId = checkpoint.WorkshopId;
            MySession.Static.Password = checkpoint.Password;
            MySession.Static.PreviousEnvironmentHostility = checkpoint.PreviousEnvironmentHostility;
            MySession.Static.RequiresDX = checkpoint.RequiresDX;
            MySession.Static.CustomLoadingScreenImage = checkpoint.CustomLoadingScreenImage;
            MySession.Static.CustomLoadingScreenText  = checkpoint.CustomLoadingScreenText;
            MySession.Static.CustomSkybox             = checkpoint.CustomSkybox;
            //FixIncorrectSettings(Settings);
            // MySession.Static.AppVersionFromSave = checkpoint.AppVersion;
            //MyToolbarComponent.InitCharacterToolbar(checkpoint.CharacterToolbar);
            //LoadCameraControllerSettings(checkpoint);



            SeamlessClient.TryShow("LocalPlayerID: " + MySession.Static.LocalPlayerId);
            //checkpoint.Gps.Dictionary.TryGetValue(MySession.Static.LocalPlayerId, out MyObjectBuilder_Gps GPSCollection);
            //SeamlessClient.TryShow("You have " + GPSCollection.Entries.Count + " gps points!");



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

            Sync.Players.RespawnComponent.InitFromCheckpoint(checkpoint);
        }
        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);
                }
            }
        }