From 1c1fe3a16118f8829682b992dc805543e90dac48 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sun, 2 Dec 2018 17:41:21 +0200 Subject: [PATCH] Verify that the launched exe belongs to the selected content package, and if not, ask if the player wants to relaunch with the correct exe. Closes #955 --- .../BarotraumaClient/Source/GameMain.cs | 24 +++++++++++++++++++ .../BarotraumaServer/Source/GameMain.cs | 24 +++++++++++++++++++ Barotrauma/BarotraumaShared/Content/Texts.xml | 1 + .../Data/ContentPackages/Vanilla 0.8.xml | 1 + .../BarotraumaShared/Source/ContentPackage.cs | 5 ++-- 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameMain.cs b/Barotrauma/BarotraumaClient/Source/GameMain.cs index 1a175363b..61bb9fe4a 100644 --- a/Barotrauma/BarotraumaClient/Source/GameMain.cs +++ b/Barotrauma/BarotraumaClient/Source/GameMain.cs @@ -11,6 +11,7 @@ using System.Diagnostics; using System.Reflection; using GameAnalyticsSDK.Net; using System.Threading; +using System.IO; namespace Barotrauma { @@ -386,6 +387,8 @@ namespace Barotrauma LocationType.Init(); MainMenuScreen.Select(); + CheckContentPackage(); + TitleScreen.LoadState = 100.0f; hasLoaded = true; if (GameSettings.VerboseLogging) @@ -396,6 +399,27 @@ namespace Barotrauma } + private void CheckContentPackage() + { + var exePaths = Config.SelectedContentPackage.GetFilesOfType(ContentType.Executable); + if (exePaths.Count > 0 && AppDomain.CurrentDomain.FriendlyName != exePaths[0]) + { + var msgBox = new GUIMessageBox(TextManager.Get("Error"), + TextManager.Get("IncorrectExe") + .Replace("[selectedpackage]", Config.SelectedContentPackage.Name) + .Replace("[exename]", exePaths[0]), + new string[] { TextManager.Get("Yes"), TextManager.Get("No") }); + msgBox.Buttons[0].OnClicked += (_, userdata) => + { + string fullPath = Path.GetFullPath(exePaths[0]); + Process.Start(fullPath); + Exit(); + return true; + }; + msgBox.Buttons[1].OnClicked = msgBox.Close; + } + } + /// /// UnloadContent will be called once per game and is the place to unload /// all content. diff --git a/Barotrauma/BarotraumaServer/Source/GameMain.cs b/Barotrauma/BarotraumaServer/Source/GameMain.cs index 15f52d864..7f9e53b1f 100644 --- a/Barotrauma/BarotraumaServer/Source/GameMain.cs +++ b/Barotrauma/BarotraumaServer/Source/GameMain.cs @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Reflection; using System.Threading; using System.Xml.Linq; @@ -101,6 +102,29 @@ namespace Barotrauma Screen.SelectNull(); NetLobbyScreen = new NetLobbyScreen(); + + CheckContentPackage(); + } + + + private void CheckContentPackage() + { + var exePaths = Config.SelectedContentPackage.GetFilesOfType(ContentType.ServerExecutable); + if (exePaths.Count > 0 && AppDomain.CurrentDomain.FriendlyName != exePaths[0]) + { + DebugConsole.ShowQuestionPrompt(TextManager.Get("IncorrectExe") + .Replace("[selectedpackage]", Config.SelectedContentPackage.Name) + .Replace("[exename]", exePaths[0]), + (option) => + { + if (option.ToLower() == "y" || option.ToLower() == "yes") + { + string fullPath = Path.GetFullPath(exePaths[0]); + Process.Start(fullPath); + ShouldRun = false; + } + }); + } } public void StartServer() diff --git a/Barotrauma/BarotraumaShared/Content/Texts.xml b/Barotrauma/BarotraumaShared/Content/Texts.xml index 8d3aebd46..247100894 100644 --- a/Barotrauma/BarotraumaShared/Content/Texts.xml +++ b/Barotrauma/BarotraumaShared/Content/Texts.xml @@ -44,6 +44,7 @@ Discard Restart required You need to restart the game for the resolution changes to take effect. + The executable you've launched is not present in the content package [selectedpackage]. Do you want to launch [exename]? [sub] has made its way to [location]. diff --git a/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml b/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml index a2f81245b..dbf6e168f 100644 --- a/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml +++ b/Barotrauma/BarotraumaShared/Data/ContentPackages/Vanilla 0.8.xml @@ -57,4 +57,5 @@ + diff --git a/Barotrauma/BarotraumaShared/Source/ContentPackage.cs b/Barotrauma/BarotraumaShared/Source/ContentPackage.cs index 4fd515497..498ce2edd 100644 --- a/Barotrauma/BarotraumaShared/Source/ContentPackage.cs +++ b/Barotrauma/BarotraumaShared/Source/ContentPackage.cs @@ -13,7 +13,8 @@ namespace Barotrauma Item, Character, Structure, - Executable, + Executable, + ServerExecutable, LocationTypes, LevelGenerationParameters, RandomEvents, @@ -144,7 +145,7 @@ namespace Barotrauma var md5 = MD5.Create(); foreach (ContentFile file in files) { - if (file.type == ContentType.Executable) continue; + if (file.type == ContentType.Executable || file.type == ContentType.ServerExecutable) continue; try {