diff --git a/patches/tModLoader/Terraria/Main.cs.patch b/patches/tModLoader/Terraria/Main.cs.patch index d2b6d07c538..09b6f9c7f81 100644 --- a/patches/tModLoader/Terraria/Main.cs.patch +++ b/patches/tModLoader/Terraria/Main.cs.patch @@ -6063,6 +6063,30 @@ } num30++; +@@ -41523,6 +_,7 @@ + array9[1 + num39] = Lang.menu[88].Value; + array9[2 + num39] = Lang.menu[5].Value; + if (selectedMenu == 0) { ++ // Join Via IP Multiplayer Menu Open + LoadPlayers(); + menuMultiplayer = true; + SoundEngine.PlaySound(10); +@@ -41530,6 +_,7 @@ + menuMode = 1; + } + else if (selectedMenu == 1 + num39) { ++ // Host & Play Multiplayer Menu Open + LoadPlayers(); + SoundEngine.PlaySound(10); + ClearPendingPlayerSelectCallbacks(); +@@ -41538,6 +_,7 @@ + menuServer = true; + } + else if (selectedMenu == 1) { ++ // Join via Steam Multiplayer Menu Open + SoundEngine.PlaySound(10); + SocialAPI.Friends.OpenJoinInterface(); + } @@ -41829,7 +_,11 @@ } } diff --git a/patches/tModLoader/Terraria/ModLoader/ModLoader.cs b/patches/tModLoader/Terraria/ModLoader/ModLoader.cs index 1124e5fd70c..f3aa4eeba5d 100644 --- a/patches/tModLoader/Terraria/ModLoader/ModLoader.cs +++ b/patches/tModLoader/Terraria/ModLoader/ModLoader.cs @@ -383,6 +383,7 @@ internal static void SaveConfiguration() Main.Configuration.Put(nameof(LatestNewsTimestamp), LatestNewsTimestamp); Main.Configuration.Put(nameof(WarnedFamilyShareDontShowAgain), WarnedFamilyShareDontShowAgain); Main.Configuration.Put(nameof(ModsMenuSortMode), Enum.GetName(typeof(ModsMenuSortMode), Interface.modsMenu.sortMode)); + Main.Configuration.Put(nameof(ModNet.trustedServerIds), ModNet.trustedServerIds); Main.Configuration.Put("LiquidSlopeFix", LiquidEdgeRenderer.Enabled); } @@ -416,6 +417,8 @@ internal static void LoadConfiguration() if (Enum.TryParse(Main.Configuration.Get(nameof(ModsMenuSortMode), ModsMenuSortMode.RecentlyUpdated.ToString()), out var modsMenuSortMode)) Interface.modsMenu.sortMode = modsMenuSortMode; + Main.Configuration.Get(nameof(ModNet.trustedServerIds), ModNet.trustedServerIds); + Main.Configuration.Get("LiquidSlopeFix", ref LiquidEdgeRenderer.Enabled); } diff --git a/patches/tModLoader/Terraria/ModLoader/ModNet.cs b/patches/tModLoader/Terraria/ModLoader/ModNet.cs index b3889fffa3c..470498f0d16 100644 --- a/patches/tModLoader/Terraria/ModLoader/ModNet.cs +++ b/patches/tModLoader/Terraria/ModLoader/ModNet.cs @@ -57,6 +57,7 @@ public NetConfig(string modname, string configname, string json) [Obsolete("No longer supported")] public static bool AllowVanillaClients { get; internal set; } internal static bool downloadModsFromServers = true; + internal static List trustedServerIds = new List(); internal static bool[] isModdedClient = new bool[256]; diff --git a/patches/tModLoader/Terraria/ModLoader/UI/UIServerModsDifferMessage.cs b/patches/tModLoader/Terraria/ModLoader/UI/UIServerModsDifferMessage.cs index c916ecd4698..1daba8fd3df 100644 --- a/patches/tModLoader/Terraria/ModLoader/UI/UIServerModsDifferMessage.cs +++ b/patches/tModLoader/Terraria/ModLoader/UI/UIServerModsDifferMessage.cs @@ -4,7 +4,9 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; +using Steamworks; using Terraria.Audio; +using Terraria.GameContent; using Terraria.GameContent.UI.Elements; using Terraria.ID; using Terraria.Localization; @@ -59,6 +61,14 @@ internal class UIServerModsDifferMessage : UIState, IHaveBackButtonCommand private const int WarningMessagePanelHeight = 70; + // Confirmation Dialog + private UIImage _blockInput; + private UIPanel _activeDialog; + private UIAutoScaleTextTextPanel _confirmDialogYesButton; + private Action _dialogYesAction; + private UIAutoScaleTextTextPanel _confirmDialogNoButton; + private UIText _confirmDialogText; + public UIState PreviousUIState { get; set; } public override void OnInitialize() @@ -300,11 +310,13 @@ internal void Show(string message, int gotoMenu, UIState gotoState = null, strin return; } + bool riskyModsPresent = reloadRequiredExplanationEntries.Where(e => e.riskState != DownloadModRiskState.AvailableOnWorkshop).Any(); + _message = message; _gotoMenu = gotoMenu; _gotoState = gotoState; - _continueButtonText = continueButtonText; - _continueButtonAction = continueButtonAction; + _continueButtonText = riskyModsPresent ? Language.GetTextValue("ConfirmDownloadAndContinue") : continueButtonText; + _continueButtonAction = () => ConfirmTrustHost(continueButtonAction, riskyModsPresent); _backText = backButtonText; _backAction = backButtonAction; this.reloadRequiredExplanationEntries = reloadRequiredExplanationEntries?.OrderBy(x => x.typeOrder).ThenBy(x => x.riskState).ThenBy(x => x.mod).ToList(); @@ -321,6 +333,11 @@ private void BackClick(UIMouseEvent evt, UIElement listeningElement) public void HandleBackButtonUsage() { + if (_blockInput != null && HasChild(_blockInput)) { + CloseConfirmDialog(null, null); + return; + } + SoundEngine.PlaySound(SoundID.MenuOpen); Main.menuMode = _gotoMenu; if (_gotoState != null) @@ -338,4 +355,121 @@ protected override void DrawSelf(SpriteBatch spriteBatch) base.DrawSelf(spriteBatch); UILinkPointNavigator.Shortcuts.BackButtonCommand = 7; } + + // This is a moderately modified version of the confirmDelete dialog in UIModItem.cs. Possibly refactor this and related in to an interface with default methods in future - Solxan + private void ConfirmTrustHost(Action continueWithDownload, bool riskyModsPresent) + { + if (!riskyModsPresent) { + continueWithDownload(); + return; + } + + bool isSteamHosted = false; + string trustId = null; + + //TOOD: The below code is theoretical; assumes that either Steam lobby join has progressed to the point where Owner is set OR NetPlay has similaryl progressed + // Requires Testing - Solxan + if (SteamedWraps.SteamClient) { + CSteamID owner = (Social.SocialAPI.Network as Terraria.Social.Steam.NetSocialModule)._lobby.Owner; + if (owner != CSteamID.Nil) { + isSteamHosted = true; + trustId = owner.ToString(); + } + } + + if (!isSteamHosted) + trustId = Netplay.ServerIPText; + + // Risky mods are present, check if this is a trusted host + bool trustedHost = ModNet.trustedServerIds.Contains(trustId); + string confirmationText = Language.GetTextValue(trustedHost ? "tModLoader.UntrustedConfirmSync" : "tModLoader.TrustedConfirmSync"); + + _dialogYesAction = () => { + if (!trustedHost) + ModNet.trustedServerIds.Add(trustId); + + continueWithDownload(); + }; + + /* TODO: Is there a developer mode flag that mod developers can use to silence the prompt? Such as being on a non-Stable build of tml? + if (trustedHost && developerMode) { + continueWithDownload(); + return; + } + */ + + // Everything from here down is reasonably generic? - Solxan + + SoundEngine.PlaySound(10, -1, -1, 1); + var _confirmDownloadDialog = new UIPanel() { + Width = { Percent = .30f }, + Height = { Percent = .30f }, + HAlign = .5f, + VAlign = .5f, + BackgroundColor = trustedHost ? new Color(63, 82, 151) : Color.OrangeRed, + BorderColor = Color.Black + }; + _confirmDownloadDialog.SetPadding(6f); + Interface.serverModsDifferMessage.ShowConfirmDialog(_confirmDownloadDialog); + + _confirmDialogYesButton = new UIAutoScaleTextTextPanel(Language.GetTextValue("LegacyMenu.104")) { + TextColor = Color.White, + Width = new StyleDimension(-10f, 1f / 3f), + Height = { Pixels = 40 }, + VAlign = .85f, + HAlign = .15f + }.WithFadedMouseOver(); + _confirmDialogYesButton.OnLeftClick += DialogYesAction; + _confirmDownloadDialog.Append(_confirmDialogYesButton); + + _confirmDialogNoButton = new UIAutoScaleTextTextPanel(Language.GetTextValue("LegacyMenu.105")) { + TextColor = Color.White, + Width = new StyleDimension(-10f, 1f / 3f), + Height = { Pixels = 40 }, + VAlign = .85f, + HAlign = .85f + }.WithFadedMouseOver(); + _confirmDialogNoButton.OnLeftClick += Interface.modsMenu.CloseConfirmDialog; + _confirmDownloadDialog.Append(_confirmDialogNoButton); + + _confirmDialogText = new UIText(confirmationText) { + Width = { Percent = .75f }, + HAlign = .5f, + VAlign = .3f, + IsWrapped = true + }; + _confirmDownloadDialog.Append(_confirmDialogText); + + Interface.serverModsDifferMessage.Recalculate(); + } + + private void DialogYesAction(UIMouseEvent evt, UIElement listeningElement) + { + _dialogYesAction(); + } + + // This is duplicated from UIMods.cs + private void ShowConfirmDialog(UIPanel dialog) + { + _blockInput = new UIImage(TextureAssets.Extra[190]) { + Width = { Percent = 1 }, + Height = { Percent = 1 }, + Color = Color.Black * 0.5f, + ScaleToFit = true + }; + _blockInput.Width = StyleDimension.Fill; + _blockInput.Height = StyleDimension.Fill; + _blockInput.OnLeftMouseDown += CloseConfirmDialog; + Append(_blockInput); + + Append(_activeDialog = dialog); + } + + // This is duplicated from UIMods.cs + internal void CloseConfirmDialog(UIMouseEvent evt, UIElement listeningElement) + { + SoundEngine.PlaySound(SoundID.MenuClose); + _blockInput?.Remove(); + _activeDialog?.Remove(); + } } diff --git a/patches/tModLoader/Terraria/Social/Steam/NetSocialModule.cs.patch b/patches/tModLoader/Terraria/Social/Steam/NetSocialModule.cs.patch new file mode 100644 index 00000000000..0c54a4bca98 --- /dev/null +++ b/patches/tModLoader/Terraria/Social/Steam/NetSocialModule.cs.patch @@ -0,0 +1,11 @@ +--- src/TerrariaNetCore/Terraria/Social/Steam/NetSocialModule.cs ++++ src/tModLoader/Terraria/Social/Steam/NetSocialModule.cs +@@ -37,7 +_,7 @@ + }; + protected SteamP2PReader _reader; + protected SteamP2PWriter _writer; +- protected Lobby _lobby = new Lobby(); ++ internal Lobby _lobby { get; protected private set; } = new Lobby(); + protected ConcurrentDictionary _connectionStateMap = new ConcurrentDictionary(); + protected object _steamLock = new object(); + private Callback _lobbyChatMessage;