Пример #1
0
        private void StartNewSandbox()
        {
            MyLog.Default.WriteLine("StartNewSandbox - Start");

            GetSettingsFromControls();
            if (!MySteamWorkshop.CheckLocalModsAllowed(m_mods, m_settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MySpaceTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            MySteamWorkshop.DownloadModsAsync(m_mods, delegate(bool success)
            {
                if (success || (m_settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(m_mods))
                {
                    MyScreenManager.RemoveAllScreensExcept(null);

                    if (AsteroidAmount < 0)
                    {
                        MyWorldGenerator.SetProceduralSettings(AsteroidAmount, m_settings);
                        m_asteroidAmount = 0;
                    }

                    MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                    MyGuiScreenGamePlay.StartLoading(delegate
                    {
                        MySession.Start(
                            m_nameTextbox.Text,
                            GetDescription(),
                            GetPassword(),
                            m_settings,
                            m_mods,
                            new MyWorldGenerator.Args()
                        {
                            AsteroidAmount = this.AsteroidAmount,
                            Scenario       = (m_scenarioTypesGroup.SelectedButton as MyGuiControlScenarioButton).Scenario
                        }
                            );
                    });
                }
                else
                {
                    MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                               messageCaption: MyTexts.Get(MySpaceTexts.MessageBoxCaptionError),
                                               messageText: MyTexts.Get(MySpaceTexts.DialogTextDownloadModsFailed),
                                               buttonType: MyMessageBoxButtonsType.OK));
                }
                MyLog.Default.WriteLine("StartNewSandbox - End");
            });
        }
Пример #2
0
        // Start game with some default values
        public static void QuickstartSandbox(MyObjectBuilder_SessionSettings quickstartSettings, MyWorldGenerator.Args?quickstartArgs)
        {
            MyLog.Default.WriteLine("QuickstartSandbox - START");

            MyScreenManager.RemoveAllScreensExcept(null);

            MyGuiScreenGamePlay.StartLoading(delegate
            {
                var settings = (quickstartSettings != null) ? quickstartSettings : CreateBasicQuickStartSettings();
                var args     = (quickstartArgs != null) ? quickstartArgs.Value : CreateBasicQuickstartArgs();
                var mods     = new List <MyObjectBuilder_Checkpoint.ModItem>(0);
                MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Quickstart);
                MySession.Start("Created " + DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "", "", settings, mods, args);
            });

            MyLog.Default.WriteLine("QuickstartSandbox - END");
        }
Пример #3
0
        public static void LoadSingleplayerSession(MyObjectBuilder_Checkpoint checkpoint, string sessionPath, ulong checkpointSizeInBytes)
        {
            if (!MySession.IsCompatibleVersion(checkpoint))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.DialogTextIncompatibleWorldVersion),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            if (!MySteamWorkshop.CheckLocalModsAllowed(checkpoint.Mods, checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer).ToString());
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }


            MySteamWorkshop.DownloadModsAsync(checkpoint.Mods, delegate(bool success)
            {
                if (success || (checkpoint.Settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(checkpoint.Mods))
                {
                    //Sandbox.Audio.MyAudio.Static.Mute = true;

                    MyScreenManager.CloseAllScreensNowExcept(null);
                    MyGuiSandbox.Update(VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_MILLISECONDS);

                    // May be called from gameplay, so we must make sure we unload the current game
                    if (MySession.Static != null)
                    {
                        MySession.Static.Unload();
                        MySession.Static = null;
                    }
                    MyGuiScreenGamePlay.StartLoading(delegate
                    {
                        MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Load);
                        MySession.Load(sessionPath, checkpoint, checkpointSizeInBytes);
                    });
                }
                else
                {
                    MyLog.Default.WriteLine(MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed).ToString());

                    if (MySteam.IsOnline)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption : MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText : MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed),
                                                   buttonType : MyMessageBoxButtonsType.OK, callback : delegate(MyGuiScreenMessageBox.ResultEnum result)
                        {
                            if (MyFakes.QUICK_LAUNCH != null)
                            {
                                MyGuiScreenMainMenu.ReturnToMainMenu();
                            }
                        }));
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline),
                                                   buttonType: MyMessageBoxButtonsType.OK));
                    }
                }
                MyLog.Default.WriteLine("LoadSession() - End");
            });
        }
Пример #4
0
        /// <summary>
        /// Starts new session and unloads outdated if theres any.
        /// </summary>
        /// <param name="sessionName">Created session name.</param>
        /// <param name="settings">Session settings OB.</param>
        /// <param name="mods">Mod selection.</param>
        /// <param name="scenarioDefinition">World generator argument.</param>
        /// <param name="asteroidAmount">Hostility settings.</param>
        /// <param name="description">Session description.</param>
        /// <param name="passwd">Session password.</param>
        public static void StartNewSession(string sessionName,
                                           MyObjectBuilder_SessionSettings settings,
                                           List <MyObjectBuilder_Checkpoint.ModItem> mods,
                                           MyScenarioDefinition scenarioDefinition = null,
                                           int asteroidAmount = 0,
                                           string description = "",
                                           string passwd      = "")
        {
            MyLog.Default.WriteLine("StartNewSandbox - Start");

            if (!MySteamWorkshop.CheckLocalModsAllowed(mods, settings.OnlineMode == MyOnlineModeEnum.OFFLINE))
            {
                MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                           messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                           messageText: MyTexts.Get(MyCommonTexts.DialogTextLocalModsDisabledInMultiplayer),
                                           buttonType: MyMessageBoxButtonsType.OK));
                MyLog.Default.WriteLine("LoadSession() - End");
                return;
            }

            MySteamWorkshop.DownloadModsAsync(mods, delegate(bool success, string mismatchMods)
            {
                if (success || (settings.OnlineMode == MyOnlineModeEnum.OFFLINE) && MySteamWorkshop.CanRunOffline(mods))
                {
                    CheckMismatchmods(mismatchMods, callback : delegate(ResultEnum val)
                    {
                        MyScreenManager.RemoveAllScreensExcept(null);

                        if (asteroidAmount < 0)
                        {
                            MyWorldGenerator.SetProceduralSettings(asteroidAmount, settings);
                            asteroidAmount = 0;
                        }

                        MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                        StartLoading(delegate
                        {
                            MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Custom);

                            MySession.Start(
                                sessionName,
                                description,
                                passwd,
                                settings,
                                mods,
                                new MyWorldGenerator.Args()
                            {
                                AsteroidAmount = asteroidAmount,
                                Scenario       = scenarioDefinition
                            }
                                );
                        });
                    });
                }
                else
                {
                    if (MySteam.IsOnline)
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailed),
                                                   buttonType: MyMessageBoxButtonsType.OK));
                    }
                    else
                    {
                        MyGuiSandbox.AddScreen(MyGuiSandbox.CreateMessageBox(
                                                   messageCaption: MyTexts.Get(MyCommonTexts.MessageBoxCaptionError),
                                                   messageText: MyTexts.Get(MyCommonTexts.DialogTextDownloadModsFailedSteamOffline),
                                                   buttonType: MyMessageBoxButtonsType.OK));
                    }
                }
                MyLog.Default.WriteLine("StartNewSandbox - End");
            });
        }
Пример #5
0
        public static void JoinGame(GameServerItem server)
        {
            MyAnalyticsHelper.SetEntry(MyGameEntryEnum.Join);
            if (server.ServerVersion != MyFinalBuildConstants.APP_VERSION)
            {
                var sb = new StringBuilder();
                sb.AppendFormat(MyTexts.GetString(MySpaceTexts.MultiplayerError_IncorrectVersion), MyFinalBuildConstants.APP_VERSION, server.ServerVersion);
                MyGuiSandbox.Show(sb, MySpaceTexts.MessageBoxCaptionError);
                return;
            }
            if (MyFakes.ENABLE_MP_DATA_HASHES)
            {
                var serverHash = server.GetGameTagByPrefix("datahash");
                if (serverHash != "" && serverHash != MyDataIntegrityChecker.GetHashBase64())
                {
                    MyGuiSandbox.Show(MySpaceTexts.MultiplayerError_DifferentData);
                    MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + serverHash);
                    return;
                }
            }

            UInt32 unixTimestamp = (UInt32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            SteamAPI.Instance.AddFavoriteGame(server.AppID, System.Net.IPAddressExtensions.ToIPv4NetworkOrder(server.NetAdr.Address), (UInt16)server.NetAdr.Port, (UInt16)server.NetAdr.Port, FavoriteEnum.History, unixTimestamp);

            MyMultiplayerClient multiplayer = new MyMultiplayerClient(server, new MySyncLayer(new MyTransportLayer(MyMultiplayer.GameEventChannel)));

            MyMultiplayer.Static = multiplayer;
            MyMultiplayer.Static.SyncLayer.AutoRegisterGameEvents = false;
            MyMultiplayer.Static.SyncLayer.RegisterGameEvents();

            multiplayer.SendPlayerData(MySteam.UserName);

            string gamemode = server.GetGameTagByPrefix("gamemode");

            if (MyFakes.ENABLE_BATTLE_SYSTEM && gamemode == "B")
            {
                StringBuilder text = new StringBuilder();// MyTexts.Get(MySpaceTexts.DialogTextJoiningBattleLobby);

                MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel);
                MyGuiSandbox.AddScreen(progress);
                progress.ProgressCancelled += () =>
                {
                    multiplayer.Dispose();
                    MyGuiScreenMainMenu.ReturnToMainMenu();
                };

                multiplayer.OnJoin += delegate
                {
                    MyJoinGameHelper.OnJoinBattle(progress, SteamSDK.Result.OK, new LobbyEnterInfo()
                    {
                        EnterState = LobbyEnterResponseEnum.Success
                    }, multiplayer);
                };
            }
            else
            {
                StringBuilder text = MyTexts.Get(MySpaceTexts.DialogTextJoiningWorld);

                MyGuiScreenProgress progress = new MyGuiScreenProgress(text, MySpaceTexts.Cancel);
                MyGuiSandbox.AddScreen(progress);
                progress.ProgressCancelled += () =>
                {
                    multiplayer.Dispose();
                    MyGuiScreenMainMenu.ReturnToMainMenu();
                };

                multiplayer.OnJoin += delegate
                {
                    MyJoinGameHelper.OnJoin(progress, SteamSDK.Result.OK, new LobbyEnterInfo()
                    {
                        EnterState = LobbyEnterResponseEnum.Success
                    }, multiplayer);
                };
            }
        }