Skip to content

Commit

Permalink
Write dummy preview + move preview sections to top of file also for TS
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Mar 10, 2024
1 parent 45d8067 commit da0dca6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/TSMapEditor/Config/Constants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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|*.*"
Expand Down
2 changes: 2 additions & 0 deletions src/TSMapEditor/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 4 additions & 10 deletions src/TSMapEditor/Initialization/MapWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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");
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/TSMapEditor/Models/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit da0dca6

Please sign in to comment.