From 6cc82976a1f40a0def8fffdb8bbe29b361a43340 Mon Sep 17 00:00:00 2001 From: Markus Isberg Date: Fri, 20 Oct 2023 18:05:28 +0300 Subject: [PATCH] Hotfix 1.1.18.1 --- ...lHighlightAction.cs => HighlightAction.cs} | 17 +++----- .../ClientSource/Items/Item.cs | 17 ++++++++ .../SinglePlayerCampaignSetupUI.cs | 4 +- .../BarotraumaClient/LinuxClient.csproj | 2 +- Barotrauma/BarotraumaClient/MacClient.csproj | 2 +- .../BarotraumaClient/WindowsClient.csproj | 2 +- .../BarotraumaServer/LinuxServer.csproj | 2 +- Barotrauma/BarotraumaServer/MacServer.csproj | 2 +- .../Events/EventActions/HighlightAction.cs | 24 +++++++++++ .../ServerSource/Items/Item.cs | 14 ++++++ .../ServerSource/Items/ItemEventData.cs | 21 ++++++++- .../BarotraumaServer/WindowsServer.csproj | 2 +- .../Events/EventActions/EventAction.cs | 6 ++- .../Events/EventActions/HighlightAction.cs | 43 +++++++++++++++++++ .../EventActions/TutorialHighlightAction.cs | 33 -------------- .../Extensions/IEnumerableExtensions.cs | 5 +++ .../SharedSource/Items/ItemEventData.cs | 3 +- .../SharedSource/Utils/SaveUtil.cs | 17 +++++--- Barotrauma/BarotraumaShared/changelog.txt | 6 +++ 19 files changed, 164 insertions(+), 58 deletions(-) rename Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/{TutorialHighlightAction.cs => HighlightAction.cs} (69%) create mode 100644 Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs create mode 100644 Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs delete mode 100644 Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs diff --git a/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/TutorialHighlightAction.cs b/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/HighlightAction.cs similarity index 69% rename from Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/TutorialHighlightAction.cs rename to Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/HighlightAction.cs index 732c1a480..cce9ce464 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/TutorialHighlightAction.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Events/EventActions/HighlightAction.cs @@ -1,22 +1,19 @@ +#nullable enable using Microsoft.Xna.Framework; +using System.Collections.Generic; +using System.Linq; namespace Barotrauma; -partial class TutorialHighlightAction : EventAction +partial class HighlightAction : EventAction { - private static readonly Color highlightColor = Color.Orange; - - partial void UpdateProjSpecific() + partial void SetHighlightProjSpecific(Entity entity, IEnumerable? targetCharacters) { - if (GameMain.GameSession?.GameMode is not TutorialMode) { return; } - foreach (var target in ParentEvent.GetTargets(TargetTag)) + if (targetCharacters != null && !targetCharacters.Contains(Character.Controlled)) { - SetHighlight(target); + return; } - } - private void SetHighlight(Entity entity) - { if (entity is Item i) { SetItemHighlight(i); diff --git a/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs b/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs index 0f42a313c..7706baa04 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Items/Item.cs @@ -1540,6 +1540,23 @@ namespace Barotrauma RemoveFromDroppedStack(allowClientExecute: true); } break; + case EventType.SetHighlight: + bool isTargetedForThisClient = msg.ReadBoolean(); + if (isTargetedForThisClient) + { + bool highlight = msg.ReadBoolean(); + ExternalHighlight = highlight; + if (highlight) + { + Color highlightColor = msg.ReadColorR8G8B8A8(); + HighlightColor = highlightColor; + } + else + { + HighlightColor = null; + } + } + break; default: throw new Exception($"Malformed incoming item event: unsupported event type {eventType}"); } diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/CampaignSetupUI/SinglePlayerCampaignSetupUI.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/CampaignSetupUI/SinglePlayerCampaignSetupUI.cs index 6f51a78d9..8400fab7d 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/CampaignSetupUI/SinglePlayerCampaignSetupUI.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/CampaignSetupUI/SinglePlayerCampaignSetupUI.cs @@ -583,7 +583,9 @@ namespace Barotrauma if (saveFiles == null) { - saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Singleplayer); + //we don't need to log errors at this point, + //if any file fails to load the error will get logged when we try to extract the root from the game session doc later in the method + saveFiles = SaveUtil.GetSaveFiles(SaveUtil.SaveType.Singleplayer, logLoadErrors: false); } var leftColumn = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), loadGameContainer.RectTransform), childAnchor: Anchor.TopCenter) diff --git a/Barotrauma/BarotraumaClient/LinuxClient.csproj b/Barotrauma/BarotraumaClient/LinuxClient.csproj index f853c1d3a..9a1fe727a 100644 --- a/Barotrauma/BarotraumaClient/LinuxClient.csproj +++ b/Barotrauma/BarotraumaClient/LinuxClient.csproj @@ -6,7 +6,7 @@ Barotrauma FakeFish, Undertow Games Barotrauma - 1.1.18.0 + 1.1.18.1 Copyright © FakeFish 2018-2023 AnyCPU;x64 Barotrauma diff --git a/Barotrauma/BarotraumaClient/MacClient.csproj b/Barotrauma/BarotraumaClient/MacClient.csproj index f716d66d3..7c9514990 100644 --- a/Barotrauma/BarotraumaClient/MacClient.csproj +++ b/Barotrauma/BarotraumaClient/MacClient.csproj @@ -6,7 +6,7 @@ Barotrauma FakeFish, Undertow Games Barotrauma - 1.1.18.0 + 1.1.18.1 Copyright © FakeFish 2018-2023 AnyCPU;x64 Barotrauma diff --git a/Barotrauma/BarotraumaClient/WindowsClient.csproj b/Barotrauma/BarotraumaClient/WindowsClient.csproj index 1086d7691..a388bc1f5 100644 --- a/Barotrauma/BarotraumaClient/WindowsClient.csproj +++ b/Barotrauma/BarotraumaClient/WindowsClient.csproj @@ -6,7 +6,7 @@ Barotrauma FakeFish, Undertow Games Barotrauma - 1.1.18.0 + 1.1.18.1 Copyright © FakeFish 2018-2023 AnyCPU;x64 Barotrauma diff --git a/Barotrauma/BarotraumaServer/LinuxServer.csproj b/Barotrauma/BarotraumaServer/LinuxServer.csproj index 120037a3d..7fd3c7774 100644 --- a/Barotrauma/BarotraumaServer/LinuxServer.csproj +++ b/Barotrauma/BarotraumaServer/LinuxServer.csproj @@ -6,7 +6,7 @@ Barotrauma FakeFish, Undertow Games Barotrauma Dedicated Server - 1.1.18.0 + 1.1.18.1 Copyright © FakeFish 2018-2023 AnyCPU;x64 DedicatedServer diff --git a/Barotrauma/BarotraumaServer/MacServer.csproj b/Barotrauma/BarotraumaServer/MacServer.csproj index 97b194970..1f5c8ac99 100644 --- a/Barotrauma/BarotraumaServer/MacServer.csproj +++ b/Barotrauma/BarotraumaServer/MacServer.csproj @@ -6,7 +6,7 @@ Barotrauma FakeFish, Undertow Games Barotrauma Dedicated Server - 1.1.18.0 + 1.1.18.1 Copyright © FakeFish 2018-2023 AnyCPU;x64 DedicatedServer diff --git a/Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs b/Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs new file mode 100644 index 000000000..98c06c3f9 --- /dev/null +++ b/Barotrauma/BarotraumaServer/ServerSource/Events/EventActions/HighlightAction.cs @@ -0,0 +1,24 @@ +#nullable enable +using Barotrauma.Networking; +using System.Collections.Generic; +using System.Linq; + +namespace Barotrauma; + +partial class HighlightAction : EventAction +{ + partial void SetHighlightProjSpecific(Entity entity, IEnumerable? targetCharacters) + { + if (entity is Item item && GameMain.Server != null) + { + IEnumerable? targetClients = null; + if (targetCharacters != null) + { + targetClients = targetCharacters + .Select(c => GameMain.Server.ConnectedClients.FirstOrDefault(client => client.Character == c)) + .Where(c => c != null)!; + } + GameMain.Server?.CreateEntityEvent(item, new Item.SetHighlightEventData(State, highlightColor, targetClients)); + } + } +} \ No newline at end of file diff --git a/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs b/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs index f59311120..62c2477a1 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Items/Item.cs @@ -161,6 +161,20 @@ namespace Barotrauma msg.WriteUInt16(droppedItem.ID); } break; + case SetHighlightEventData highlightEventData: + bool isTargetedForClient = + highlightEventData.TargetClients.IsEmpty || + highlightEventData.TargetClients.Contains(c); + msg.WriteBoolean(isTargetedForClient); + if (isTargetedForClient) + { + msg.WriteBoolean(highlightEventData.Highlighted); + if (highlightEventData.Highlighted) + { + msg.WriteColorR8G8B8A8(highlightEventData.Color); + } + } + break; default: throw error($"Unsupported event type {itemEventData.GetType().Name}"); } diff --git a/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs b/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs index b2a6b0dda..a37508ccf 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/Items/ItemEventData.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +#nullable enable +using Barotrauma.Networking; +using Microsoft.Xna.Framework; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; @@ -16,4 +19,20 @@ partial class Item Items = items.Distinct().ToImmutableArray(); } } + + public readonly struct SetHighlightEventData : IEventData + { + public EventType EventType => EventType.SetHighlight; + public readonly bool Highlighted; + public readonly Color Color; + + public readonly ImmutableArray TargetClients; + + public SetHighlightEventData(bool highlighted, Color color, IEnumerable? targetClients) + { + Highlighted = highlighted; + Color = color; + TargetClients = (targetClients ?? Enumerable.Empty()).ToImmutableArray(); + } + } } diff --git a/Barotrauma/BarotraumaServer/WindowsServer.csproj b/Barotrauma/BarotraumaServer/WindowsServer.csproj index d4b6c61d4..72495dd7f 100644 --- a/Barotrauma/BarotraumaServer/WindowsServer.csproj +++ b/Barotrauma/BarotraumaServer/WindowsServer.csproj @@ -6,7 +6,7 @@ Barotrauma FakeFish, Undertow Games Barotrauma Dedicated Server - 1.1.18.0 + 1.1.18.1 Copyright © FakeFish 2018-2023 AnyCPU;x64 DedicatedServer diff --git a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs index dd086ec74..fddeb4d54 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/EventAction.cs @@ -140,7 +140,11 @@ namespace Barotrauma Identifier typeName = element.Name.ToString().ToIdentifier(); if (typeName == "TutorialSegmentAction") { - typeName = "EventObjectiveAction".ToIdentifier(); + typeName = nameof(EventObjectiveAction).ToIdentifier(); + } + else if (typeName == "TutorialHighlightAction") + { + typeName = nameof(HighlightAction).ToIdentifier(); } actionType = Type.GetType("Barotrauma." + typeName, throwOnError: true, ignoreCase: true); if (actionType == null) { throw new NullReferenceException(); } diff --git a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs new file mode 100644 index 000000000..8900299ea --- /dev/null +++ b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/HighlightAction.cs @@ -0,0 +1,43 @@ +#nullable enable +using Microsoft.Xna.Framework; +using System.Collections.Generic; +using System.Linq; + +namespace Barotrauma; + +partial class HighlightAction : EventAction +{ + private static readonly Color highlightColor = Color.Orange; + + [Serialize("", IsPropertySaveable.Yes)] + public Identifier TargetTag { get; set; } + + [Serialize("", IsPropertySaveable.Yes, description: "Only the player controlling this character will see the highlight. If empty, all players will see it.")] + public Identifier TargetCharacter { get; set; } + + [Serialize(true, IsPropertySaveable.Yes)] + public bool State { get; set; } + + private bool isFinished; + + public HighlightAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) + { + } + + public override void Update(float deltaTime) + { + if (isFinished) { return; } + var targetCharacters = TargetCharacter.IsEmpty ? null : ParentEvent.GetTargets(TargetCharacter).OfType(); + foreach (var target in ParentEvent.GetTargets(TargetTag)) + { + SetHighlightProjSpecific(target, targetCharacters); + } + isFinished = true; + } + + partial void SetHighlightProjSpecific(Entity entity, IEnumerable? targetCharacters); + + public override bool IsFinished(ref string goToLabel) => isFinished; + + public override void Reset() => isFinished = false; +} \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs b/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs deleted file mode 100644 index 190f7fdc0..000000000 --- a/Barotrauma/BarotraumaShared/SharedSource/Events/EventActions/TutorialHighlightAction.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace Barotrauma; - -partial class TutorialHighlightAction : EventAction -{ - [Serialize("", IsPropertySaveable.Yes)] - public Identifier TargetTag { get; set; } - - [Serialize(true, IsPropertySaveable.Yes)] - public bool State { get; set; } - - private bool isFinished; - - public TutorialHighlightAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) - { - if (GameMain.NetworkMember != null) - { - DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": {nameof(TutorialHighlightAction)} is not supported in multiplayer."); - } - } - - public override void Update(float deltaTime) - { - if (isFinished) { return; } - UpdateProjSpecific(); - isFinished = true; - } - - partial void UpdateProjSpecific(); - - public override bool IsFinished(ref string goToLabel) => isFinished; - - public override void Reset() => isFinished = false; -} \ No newline at end of file diff --git a/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs b/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs index abbb65f70..6453c4d52 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Extensions/IEnumerableExtensions.cs @@ -294,6 +294,11 @@ namespace Barotrauma.Extensions .Where(nullable => nullable.HasValue) .Select(nullable => nullable.Value); + public static IEnumerable NotNull(this IEnumerable source) where T : class + => source + .Where(nullable => nullable != null) + .Select(nullable => nullable!); + public static IEnumerable NotNone(this IEnumerable> source) { foreach (var o in source) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs index fecfef994..e0bf2763e 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/ItemEventData.cs @@ -23,9 +23,10 @@ namespace Barotrauma Upgrade = 8, ItemStat = 9, DroppedStack = 10, + SetHighlight = 11, MinValue = 0, - MaxValue = 10 + MaxValue = 11 } public interface IEventData : NetEntityEvent.IData diff --git a/Barotrauma/BarotraumaShared/SharedSource/Utils/SaveUtil.cs b/Barotrauma/BarotraumaShared/SharedSource/Utils/SaveUtil.cs index dc80cf2f3..7d2a8d983 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Utils/SaveUtil.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Utils/SaveUtil.cs @@ -238,7 +238,7 @@ namespace Barotrauma return folder; } - public static IReadOnlyList GetSaveFiles(SaveType saveType, bool includeInCompatible = true) + public static IReadOnlyList GetSaveFiles(SaveType saveType, bool includeInCompatible = true, bool logLoadErrors = true) { string defaultFolder = saveType == SaveType.Singleplayer ? DefaultSaveFolder : DefaultMultiplayerSaveFolder; if (!Directory.Exists(defaultFolder)) @@ -273,7 +273,7 @@ namespace Barotrauma List saveInfos = new List(); foreach (string file in files) { - var docRoot = ExtractGameSessionRootElementFromSaveFile(file); + var docRoot = ExtractGameSessionRootElementFromSaveFile(file, logLoadErrors); if (!includeInCompatible && !IsSaveFileCompatible(docRoot)) { continue; @@ -561,7 +561,7 @@ namespace Barotrauma /// Extract *only* the root element of the gamesession.xml file in the given save. /// For performance reasons, none of its child elements are returned. /// - public static XElement? ExtractGameSessionRootElementFromSaveFile(string savePath) + public static XElement? ExtractGameSessionRootElementFromSaveFile(string savePath, bool logLoadErrors = true) { const int maxRetries = 4; for (int i = 0; i <= maxRetries; i++) @@ -617,12 +617,19 @@ namespace Barotrauma if (i >= maxRetries || !File.Exists(savePath)) { throw; } DebugConsole.NewMessage( - $"Failed to decompress file \"{savePath}\" for root extraction {{{e.Message}}}, retrying in 250 ms...", + $"Failed to decompress file \"{savePath}\" for root extraction ({e.Message}), retrying in 250 ms...", Color.Red); Thread.Sleep(250); } + catch (System.IO.InvalidDataException e) + { + if (logLoadErrors) + { + DebugConsole.ThrowError($"Failed to decompress file \"{savePath}\" for root extraction.", e); + } + return null; + } } - return null; } diff --git a/Barotrauma/BarotraumaShared/changelog.txt b/Barotrauma/BarotraumaShared/changelog.txt index abb1f6e48..ab028f246 100644 --- a/Barotrauma/BarotraumaShared/changelog.txt +++ b/Barotrauma/BarotraumaShared/changelog.txt @@ -1,3 +1,9 @@ +------------------------------------------------------------------------------------------------------------------------------------------------- +v1.1.18.1 +------------------------------------------------------------------------------------------------------------------------------------------------- + +- Fixed opening the "load game" menu crashing the game if you have any corrupted/unloadable saves in the save folder. In multiplayer, this would just prevent opening the campaign setup menu without any error messages. + ------------------------------------------------------------------------------------------------------------------------------------------------- v1.1.18.0 -------------------------------------------------------------------------------------------------------------------------------------------------