From da0dca6e0945e950c61229e74fc5cacb667f04d6 Mon Sep 17 00:00:00 2001 From: Rampastring Date: Mon, 11 Mar 2024 01:09:01 +0200 Subject: [PATCH] Write dummy preview + move preview sections to top of file also for TS --- src/TSMapEditor/Config/Constants.ini | 4 ++++ src/TSMapEditor/Constants.cs | 2 ++ src/TSMapEditor/Initialization/MapWriter.cs | 14 ++++---------- src/TSMapEditor/Models/Map.cs | 3 ++- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/TSMapEditor/Config/Constants.ini b/src/TSMapEditor/Config/Constants.ini index 49bb4f79..563a0d21 100644 --- a/src/TSMapEditor/Config/Constants.ini +++ b/src/TSMapEditor/Config/Constants.ini @@ -58,6 +58,10 @@ GameRegistryInstallPath=SOFTWARE\DawnOfTheTiberiumAge ; part of the registry instead of the "Current User" part of the registry. InstallPathAtHKLM=false +; If set to yes, WAE will always write a dummy preview to a map file that does not have a preview. +; This is required by vanilla games (both TS as well as RA2/YR) as they crash if a map has no preview. +DefaultPreview=false + ; Specifies the file filter string used in OpenFileDialog (Windows) ; For multiple file formats, list them with : (instead of ;) ; Example config with multiple file extensions: "YR maps|*.map:*.mpr:*.yrm|All files|*.*" diff --git a/src/TSMapEditor/Constants.cs b/src/TSMapEditor/Constants.cs index 077ea426..46b09222 100644 --- a/src/TSMapEditor/Constants.cs +++ b/src/TSMapEditor/Constants.cs @@ -24,6 +24,7 @@ public static class Constants public static bool DrawBuildingAnimationShadows = false; public static bool UseCountries = false; public static bool WarnOfTooManyTriggerActions = true; + public static bool DefaultPreview = false; public static string ExpectedClientExecutableName = "DTA.exe"; public static string GameRegistryInstallPath = "SOFTWARE\\DawnOfTheTiberiumAge"; @@ -126,6 +127,7 @@ public static void Init() DrawBuildingAnimationShadows = constantsIni.GetBooleanValue(ConstantsSectionName, nameof(DrawBuildingAnimationShadows), DrawBuildingAnimationShadows); UseCountries = constantsIni.GetBooleanValue(ConstantsSectionName, nameof(UseCountries), UseCountries); WarnOfTooManyTriggerActions = constantsIni.GetBooleanValue(ConstantsSectionName, nameof(WarnOfTooManyTriggerActions), WarnOfTooManyTriggerActions); + DefaultPreview = constantsIni.GetBooleanValue(ConstantsSectionName, nameof(DefaultPreview), DefaultPreview); ExpectedClientExecutableName = constantsIni.GetStringValue(ConstantsSectionName, nameof(ExpectedClientExecutableName), ExpectedClientExecutableName); GameRegistryInstallPath = constantsIni.GetStringValue(ConstantsSectionName, nameof(GameRegistryInstallPath), GameRegistryInstallPath); diff --git a/src/TSMapEditor/Initialization/MapWriter.cs b/src/TSMapEditor/Initialization/MapWriter.cs index 4072edb6..b2d9142e 100644 --- a/src/TSMapEditor/Initialization/MapWriter.cs +++ b/src/TSMapEditor/Initialization/MapWriter.cs @@ -615,10 +615,7 @@ public static void WriteTubes(IMap map, IniFile mapIni) public static void WriteDummyPreview(IMap map, IniFile mapIni) { - if (!Constants.UseCountries) - return; - - // RA2/YR will crash if the map has no preview. + // Vanilla (Steam) TS as well as RA2/YR will crash if the map has no preview. // And the preview sections need to be the first sections in the INI file. // We write a dummy preview to the file if necessary. if (!mapIni.SectionExists("Preview") || !mapIni.SectionExists("PreviewPack")) @@ -660,12 +657,9 @@ public static void WriteActualPreview(Texture2D texture, IniFile mapIni) mapIni.AddSection(section); WriteBase64ToSection(GenerateLZOBlocksFromData(buffer), section); - if (Constants.UseCountries) - { - // RA2/YR expects these sections to be the first in the map file - mapIni.MoveSectionToFirst("PreviewPack"); - mapIni.MoveSectionToFirst("Preview"); - } + // Original games (TS and YR) expect these sections to be the first in the map file + mapIni.MoveSectionToFirst("PreviewPack"); + mapIni.MoveSectionToFirst("Preview"); } /// diff --git a/src/TSMapEditor/Models/Map.cs b/src/TSMapEditor/Models/Map.cs index 852be0d4..f80e4d87 100644 --- a/src/TSMapEditor/Models/Map.cs +++ b/src/TSMapEditor/Models/Map.cs @@ -361,7 +361,8 @@ private void Write(string filePath = null) MapWriter.WriteInfantry(this, LoadedINI); MapWriter.WriteBuildings(this, LoadedINI); - MapWriter.WriteDummyPreview(this, LoadedINI); + if (Constants.DefaultPreview) + MapWriter.WriteDummyPreview(this, LoadedINI); string savePath = filePath ?? LoadedINI.FileName;