From 1405ca6c094721d565c7e15dbca8a42648e0a496 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Sun, 21 Apr 2024 21:00:34 -0400 Subject: [PATCH 1/6] Add Branch enum to GeneralInfo, apply to PSEM --- .../Models/UndertaleGeneralInfo.cs | 36 +++++++++++++------ UndertaleModLib/Models/UndertaleRoom.cs | 12 +++---- .../Models/UndertaleTextureGroupInfo.cs | 12 +++---- UndertaleModLib/UndertaleChunks.cs | 13 ++++--- UndertaleModLib/UndertaleData.cs | 34 ++++++++++++++++++ .../Editors/UndertaleRoomEditor.xaml.cs | 2 +- 6 files changed, 81 insertions(+), 28 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleGeneralInfo.cs b/UndertaleModLib/Models/UndertaleGeneralInfo.cs index 770657f1f..11c93de06 100644 --- a/UndertaleModLib/Models/UndertaleGeneralInfo.cs +++ b/UndertaleModLib/Models/UndertaleGeneralInfo.cs @@ -205,6 +205,20 @@ public enum FunctionClassification : ulong /// public UndertaleString Name { get; set; } + /// + /// Different GameMaker release branches. LTS has some but not all features of equivalent newer versions. + /// + public enum BranchType + { + LTS, + NonLTS + } + + /// + /// The GameMaker release branch of the data file. May be set to "NonLTS" when features exempted from LTS are detected. + /// + public BranchType Branch = BranchType.LTS; + /// /// The major version of the data file. /// If greater than 1, serialization produces "2.0.0.0" due to the flag no longer updating in data.win @@ -309,22 +323,22 @@ public enum FunctionClassification : ulong /// public bool InfoTimestampOffset { get; set; } = true; - public static (uint, uint, uint, uint) TestForCommonGMSVersions(UndertaleReader reader, - (uint, uint, uint, uint) readVersion) + public static (uint, uint, uint, uint, BranchType) TestForCommonGMSVersions(UndertaleReader reader, + (uint, uint, uint, uint, BranchType) readVersion) { - (uint Major, uint Minor, uint Release, uint Build) detectedVer = readVersion; + (uint Major, uint Minor, uint Release, uint Build, BranchType Branch) detectedVer = readVersion; // Some GMS2+ version detection. The rest is spread around, mostly in UndertaleChunks.cs - if (reader.AllChunkNames.Contains("PSEM")) // 2023.2 - detectedVer = (2023, 2, 0, 0); + if (reader.AllChunkNames.Contains("PSEM")) // 2023.2, not present on LTS + detectedVer = (2023, 2, 0, 0, BranchType.NonLTS); else if (reader.AllChunkNames.Contains("FEAT")) // 2022.8 - detectedVer = (2022, 8, 0, 0); + detectedVer = (2022, 8, 0, 0, BranchType.LTS); else if (reader.AllChunkNames.Contains("FEDS")) // 2.3.6 - detectedVer = (2, 3, 6, 0); + detectedVer = (2, 3, 6, 0, BranchType.LTS); else if (reader.AllChunkNames.Contains("SEQN")) // 2.3 - detectedVer = (2, 3, 0, 0); + detectedVer = (2, 3, 0, 0, BranchType.LTS); else if (reader.AllChunkNames.Contains("TGIN")) // 2.2.1 - detectedVer = (2, 2, 1, 0); + detectedVer = (2, 2, 1, 0, BranchType.LTS); if (detectedVer.Major > 2 || (detectedVer.Major == 2 && detectedVer.Minor >= 3)) { @@ -466,8 +480,8 @@ public void Unserialize(UndertaleReader reader) if (reader.ReadOnlyGEN8) return; - var detectedVer = TestForCommonGMSVersions(reader, (Major, Minor, Release, Build)); - (Major, Minor, Release, Build) = detectedVer; + var detectedVer = TestForCommonGMSVersions(reader, (Major, Minor, Release, Build, Branch)); + (Major, Minor, Release, Build, Branch) = detectedVer; if (reader.undertaleData.GeneralInfo is not null) { diff --git a/UndertaleModLib/Models/UndertaleRoom.cs b/UndertaleModLib/Models/UndertaleRoom.cs index e460ff316..981617250 100644 --- a/UndertaleModLib/Models/UndertaleRoom.cs +++ b/UndertaleModLib/Models/UndertaleRoom.cs @@ -1810,7 +1810,7 @@ public void Serialize(UndertaleWriter writer) writer.WriteUndertaleObjectPointer(Sequences); if (!writer.undertaleData.IsVersionAtLeast(2, 3, 2)) writer.WriteUndertaleObjectPointer(NineSlices); - if (writer.undertaleData.IsVersionAtLeast(2023, 2)) + if (writer.undertaleData.IsNonLTSVersionAtLeast(2023, 2)) writer.WriteUndertaleObjectPointer(ParticleSystems); } writer.WriteUndertaleObject(LegacyTiles); @@ -1820,7 +1820,7 @@ public void Serialize(UndertaleWriter writer) writer.WriteUndertaleObject(Sequences); if (!writer.undertaleData.IsVersionAtLeast(2, 3, 2)) writer.WriteUndertaleObject(NineSlices); - if (writer.undertaleData.IsVersionAtLeast(2023, 2)) + if (writer.undertaleData.IsNonLTSVersionAtLeast(2023, 2)) writer.WriteUndertaleObject(ParticleSystems); } } @@ -1835,7 +1835,7 @@ public void Unserialize(UndertaleReader reader) Sequences = reader.ReadUndertaleObjectPointer>(); if (!reader.undertaleData.IsVersionAtLeast(2, 3, 2)) NineSlices = reader.ReadUndertaleObjectPointer>(); - if (reader.undertaleData.IsVersionAtLeast(2023, 2)) + if (reader.undertaleData.IsNonLTSVersionAtLeast(2023, 2)) ParticleSystems = reader.ReadUndertaleObjectPointer>(); } reader.ReadUndertaleObject(LegacyTiles); @@ -1845,7 +1845,7 @@ public void Unserialize(UndertaleReader reader) reader.ReadUndertaleObject(Sequences); if (!reader.undertaleData.IsVersionAtLeast(2, 3, 2)) reader.ReadUndertaleObject(NineSlices); - if (reader.undertaleData.IsVersionAtLeast(2023, 2)) + if (reader.undertaleData.IsNonLTSVersionAtLeast(2023, 2)) reader.ReadUndertaleObject(ParticleSystems); } } @@ -1865,7 +1865,7 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) sequencesPtr = reader.ReadUInt32(); if (!reader.undertaleData.IsVersionAtLeast(2, 3, 2)) nineSlicesPtr = reader.ReadUInt32(); - if (reader.undertaleData.IsVersionAtLeast(2023, 2)) + if (reader.undertaleData.IsNonLTSVersionAtLeast(2023, 2)) partSystemsPtr = reader.ReadUInt32(); } @@ -1882,7 +1882,7 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) reader.AbsPosition = nineSlicesPtr; count += 1 + UndertalePointerList.UnserializeChildObjectCount(reader); } - if (reader.undertaleData.IsVersionAtLeast(2023, 2)) + if (reader.undertaleData.IsNonLTSVersionAtLeast(2023, 2)) { reader.AbsPosition = partSystemsPtr; count += 1 + UndertalePointerList.UnserializeChildObjectCount(reader); diff --git a/UndertaleModLib/Models/UndertaleTextureGroupInfo.cs b/UndertaleModLib/Models/UndertaleTextureGroupInfo.cs index 1f020523c..0ec43c716 100644 --- a/UndertaleModLib/Models/UndertaleTextureGroupInfo.cs +++ b/UndertaleModLib/Models/UndertaleTextureGroupInfo.cs @@ -133,14 +133,14 @@ public void Serialize(UndertaleWriter writer) writer.WriteUndertaleObjectPointer(TexturePages); writer.WriteUndertaleObjectPointer(Sprites); - if (!writer.undertaleData.IsVersionAtLeast(2023, 1)) + if (!writer.undertaleData.IsNonLTSVersionAtLeast(2023, 1)) writer.WriteUndertaleObjectPointer(SpineSprites); writer.WriteUndertaleObjectPointer(Fonts); writer.WriteUndertaleObjectPointer(Tilesets); writer.WriteUndertaleObject(TexturePages); writer.WriteUndertaleObject(Sprites); - if (!writer.undertaleData.IsVersionAtLeast(2023, 1)) + if (!writer.undertaleData.IsNonLTSVersionAtLeast(2023, 1)) writer.WriteUndertaleObject(SpineSprites); writer.WriteUndertaleObject(Fonts); writer.WriteUndertaleObject(Tilesets); @@ -161,7 +161,7 @@ public void Unserialize(UndertaleReader reader) // Read the pointers TexturePages = reader.ReadUndertaleObjectPointer>(); Sprites = reader.ReadUndertaleObjectPointer>(); - if (!reader.undertaleData.IsVersionAtLeast(2023, 1)) + if (!reader.undertaleData.IsNonLTSVersionAtLeast(2023, 1)) SpineSprites = reader.ReadUndertaleObjectPointer>(); Fonts = reader.ReadUndertaleObjectPointer>(); Tilesets = reader.ReadUndertaleObjectPointer>(); @@ -169,7 +169,7 @@ public void Unserialize(UndertaleReader reader) // Read the objects, throwing an error if the pointers are invalid reader.ReadUndertaleObject(TexturePages); reader.ReadUndertaleObject(Sprites); - if (!reader.undertaleData.IsVersionAtLeast(2023, 1)) + if (!reader.undertaleData.IsNonLTSVersionAtLeast(2023, 1)) reader.ReadUndertaleObject(SpineSprites); reader.ReadUndertaleObject(Fonts); reader.ReadUndertaleObject(Tilesets); @@ -188,7 +188,7 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) uint texPagesPtr = reader.ReadUInt32(); uint spritesPtr = reader.ReadUInt32(); uint spineSpritesPtr = 0; - if (!reader.undertaleData.IsVersionAtLeast(2023, 1)) + if (!reader.undertaleData.IsNonLTSVersionAtLeast(2023, 1)) spineSpritesPtr = reader.ReadUInt32(); uint fontsPtr = reader.ReadUInt32(); uint tilesetsPtr = reader.ReadUInt32(); @@ -201,7 +201,7 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) count += 1 + UndertaleSimpleResourcesList .UnserializeChildObjectCount(reader); - if (!reader.undertaleData.IsVersionAtLeast(2023, 1)) + if (!reader.undertaleData.IsNonLTSVersionAtLeast(2023, 1)) { reader.AbsPosition = spineSpritesPtr; count += 1 + UndertaleSimpleResourcesList diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index 3708f52f7..ab7c8308b 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -164,9 +164,9 @@ public void UnserializeGeneralData(UndertaleReader reader) Object.Release = reader.ReadUInt32(); Object.Build = reader.ReadUInt32(); - var readVer = (Object.Major, Object.Minor, Object.Release, Object.Build); + var readVer = (Object.Major, Object.Minor, Object.Release, Object.Build, Object.Branch); var detectedVer = UndertaleGeneralInfo.TestForCommonGMSVersions(reader, readVer); - (Object.Major, Object.Minor, Object.Release, Object.Build) = detectedVer; + (Object.Major, Object.Minor, Object.Release, Object.Build, Object.Branch) = detectedVer; } } @@ -515,6 +515,7 @@ private void CheckForGM2023_6(UndertaleReader reader) // This is basically the same as the 2022.2 check, but adapted for the LineHeight value instead of Ascender. // We already know whether the version is more or less than 2023.2 due to PSEM. Checking a shorter range narrows possibility of error. + // TODO: Does this hold with LTS? if (!reader.undertaleData.IsVersionAtLeast(2023, 2) || reader.undertaleData.IsVersionAtLeast(2023, 6)) { checkedFor2023_6 = true; @@ -1406,7 +1407,7 @@ public class UndertaleChunkTGIN : UndertaleListChunk private void CheckFor2022_9And2023(UndertaleReader reader) { if (!reader.undertaleData.IsVersionAtLeast(2, 3) - || reader.undertaleData.IsVersionAtLeast(2022, 9)) + || reader.undertaleData.IsNonLTSVersionAtLeast(2023, 1)) { checkedFor2022_9 = true; return; @@ -1429,7 +1430,8 @@ private void CheckFor2022_9And2023(UndertaleReader reader) if (ptr < tginPtr || ptr >= secondTginPtr) { isGM2022_9 = true; - reader.undertaleData.SetGMS2Version(2022, 9); + if (!reader.undertaleData.IsVersionAtLeast(2022, 9)) + reader.undertaleData.SetGMS2Version(2022, 9); } } @@ -1450,7 +1452,10 @@ private void CheckFor2022_9And2023(UndertaleReader reader) // The count can't be greater than the pointer. // (the list could be either "Tilesets" or "Fonts"). if (reader.ReadUInt32() <= fourthPtr) + { reader.undertaleData.SetGMS2Version(2023, 1); + reader.undertaleData.SetLTS(false); + } } reader.AbsPosition = returnPosition; diff --git a/UndertaleModLib/UndertaleData.cs b/UndertaleModLib/UndertaleData.cs index b1013f55e..7b012bca0 100644 --- a/UndertaleModLib/UndertaleData.cs +++ b/UndertaleModLib/UndertaleData.cs @@ -509,6 +509,40 @@ public bool IsVersionAtLeast(uint major, uint minor = 0, uint release = 0, uint return true; // The version is exactly what supplied. } + /// + /// Sets the branch type in GeneralInfo to LTS. (true for LTS, false for non-LTS.) + /// + /// true for LTS, false for non-LTS. + public void SetLTS(bool isLTS) + { + if (isLTS) + GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.LTS; + else + GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.NonLTS; + } + + /// + /// Reports whether the version of the data file is the same or higher than a specified version, and off the LTS branch that lacks some features. + /// + /// The major version. + /// The minor version. + /// The release version. + /// The build version. + /// Whether the version of the data file is the same or higher than a specified version. Always false for LTS. + public bool IsNonLTSVersionAtLeast(uint major, uint minor = 0, uint release = 0, uint build = 0) + { + if (GeneralInfo is null) + { + Debug.WriteLine("\"UndertaleData.IsNonLTSVersionAtLeast()\" error - \"GeneralInfo\" is null."); + return false; + } + + if (GeneralInfo.Branch == UndertaleGeneralInfo.BranchType.LTS) + return false; + + return IsVersionAtLeast(major, minor, release, build); + } + /// /// TODO: needs to be documented on what this does. /// diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs index 6a3cd5c53..571667644 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml.cs @@ -1364,7 +1364,7 @@ public void Command_Paste(object sender, ExecutedRoutedEventArgs e) if (!data.IsVersionAtLeast(2, 3, 2)) layer.AssetsData.NineSlices ??= new UndertalePointerList(); // likewise - if (data.IsVersionAtLeast(2023, 2)) + if (data.IsNonLTSVersionAtLeast(2023, 2)) layer.AssetsData.ParticleSystems ??= new UndertalePointerList(); } else if (layer.LayerType == LayerType.Tiles) From 215a2d256747022cd5dd475335c2103fc0023b3c Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Mon, 22 Apr 2024 12:32:17 -0400 Subject: [PATCH 2/6] Adjust FONT search bounds (#1703) --- UndertaleModLib/UndertaleChunks.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index ab7c8308b..0552cba20 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -514,9 +514,9 @@ private void CheckForGM2023_6(UndertaleReader reader) { // This is basically the same as the 2022.2 check, but adapted for the LineHeight value instead of Ascender. - // We already know whether the version is more or less than 2023.2 due to PSEM. Checking a shorter range narrows possibility of error. - // TODO: Does this hold with LTS? - if (!reader.undertaleData.IsVersionAtLeast(2023, 2) || reader.undertaleData.IsVersionAtLeast(2023, 6)) + // We already know whether the version is more or less than 2022.8 due to FEAT. Checking a shorter range narrows possibility of error. + // PSEM (2023.2) is not used, as it would return a false negative on LTS (2022.9+ equivalent with no particles). + if (!reader.undertaleData.IsVersionAtLeast(2022, 8) || reader.undertaleData.IsVersionAtLeast(2023, 6)) { checkedFor2023_6 = true; return; From df80873a0a1656bcf27d3aea6a2e9442631d17e6 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Wed, 5 Jun 2024 23:35:22 -0400 Subject: [PATCH 3/6] Rename branch enum vals, add to display --- .../Models/UndertaleGeneralInfo.cs | 30 ++++++++++++------- UndertaleModLib/UndertaleChunks.cs | 6 ++++ UndertaleModLib/UndertaleData.cs | 6 ++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleGeneralInfo.cs b/UndertaleModLib/Models/UndertaleGeneralInfo.cs index 11c93de06..cbb3afecf 100644 --- a/UndertaleModLib/Models/UndertaleGeneralInfo.cs +++ b/UndertaleModLib/Models/UndertaleGeneralInfo.cs @@ -210,14 +210,15 @@ public enum FunctionClassification : ulong /// public enum BranchType { - LTS, - NonLTS + Unknown, + LTS2022_0, + Post2022_0 } /// /// The GameMaker release branch of the data file. May be set to "NonLTS" when features exempted from LTS are detected. /// - public BranchType Branch = BranchType.LTS; + public BranchType Branch = BranchType.Unknown; /// /// The major version of the data file. @@ -330,15 +331,15 @@ public static (uint, uint, uint, uint, BranchType) TestForCommonGMSVersions(Unde // Some GMS2+ version detection. The rest is spread around, mostly in UndertaleChunks.cs if (reader.AllChunkNames.Contains("PSEM")) // 2023.2, not present on LTS - detectedVer = (2023, 2, 0, 0, BranchType.NonLTS); + detectedVer = (2023, 2, 0, 0, BranchType.Post2022_0); else if (reader.AllChunkNames.Contains("FEAT")) // 2022.8 - detectedVer = (2022, 8, 0, 0, BranchType.LTS); + detectedVer = (2022, 8, 0, 0, BranchType.Unknown); else if (reader.AllChunkNames.Contains("FEDS")) // 2.3.6 - detectedVer = (2, 3, 6, 0, BranchType.LTS); + detectedVer = (2, 3, 6, 0, BranchType.Unknown); else if (reader.AllChunkNames.Contains("SEQN")) // 2.3 - detectedVer = (2, 3, 0, 0, BranchType.LTS); + detectedVer = (2, 3, 0, 0, BranchType.Unknown); else if (reader.AllChunkNames.Contains("TGIN")) // 2.2.1 - detectedVer = (2, 2, 1, 0, BranchType.LTS); + detectedVer = (2, 2, 1, 0, BranchType.Unknown); if (detectedVer.Major > 2 || (detectedVer.Major == 2 && detectedVer.Minor >= 3)) { @@ -604,9 +605,16 @@ public override string ToString() sb.Append(" (GMS "); else sb.Append(" (GM "); - sb.Append(Major); - sb.Append('.'); - sb.Append(Minor); + if (Branch == BranchType.LTS2022_0) + { + sb.Append("2022.0"); + } + else + { + sb.Append(Major); + sb.Append('.'); + sb.Append(Minor); + } if (Release != 0) { sb.Append('.'); diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index 9272a1680..f8984fce9 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -108,6 +108,12 @@ internal override void UnserializeChunk(UndertaleReader reader) return; } } + + if (reader.undertaleData.IsVersionAtLeast(2023, 1) && + reader.undertaleData.GeneralInfo.Branch == UndertaleGeneralInfo.BranchType.Unknown) + { + reader.undertaleData.SetLTS(true); + } } internal override uint UnserializeObjectCount(UndertaleReader reader) diff --git a/UndertaleModLib/UndertaleData.cs b/UndertaleModLib/UndertaleData.cs index efc2bf7ba..a3dee1ece 100644 --- a/UndertaleModLib/UndertaleData.cs +++ b/UndertaleModLib/UndertaleData.cs @@ -516,9 +516,9 @@ public bool IsVersionAtLeast(uint major, uint minor = 0, uint release = 0, uint public void SetLTS(bool isLTS) { if (isLTS) - GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.LTS; + GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.LTS2022_0; else - GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.NonLTS; + GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.Post2022_0; } /// @@ -537,7 +537,7 @@ public bool IsNonLTSVersionAtLeast(uint major, uint minor = 0, uint release = 0, return false; } - if (GeneralInfo.Branch == UndertaleGeneralInfo.BranchType.LTS) + if (GeneralInfo.Branch < UndertaleGeneralInfo.BranchType.Post2022_0) return false; return IsVersionAtLeast(major, minor, release, build); From 2791f2a59e3e265302165442efb54ef88305d824 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Tue, 25 Jun 2024 17:28:23 -0400 Subject: [PATCH 4/6] Address review: merge SetLTS with SetGMS2Version --- UndertaleModLib/UndertaleChunks.cs | 5 ++--- UndertaleModLib/UndertaleData.cs | 30 +++++++++++++----------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index f8984fce9..4d098a3d9 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -112,7 +112,7 @@ internal override void UnserializeChunk(UndertaleReader reader) if (reader.undertaleData.IsVersionAtLeast(2023, 1) && reader.undertaleData.GeneralInfo.Branch == UndertaleGeneralInfo.BranchType.Unknown) { - reader.undertaleData.SetLTS(true); + reader.undertaleData.SetGMS2Version(isLTS: true); } } @@ -1563,8 +1563,7 @@ private void CheckFor2022_9And2023(UndertaleReader reader) // (the list could be either "Tilesets" or "Fonts"). if (reader.ReadUInt32() <= fourthPtr) { - reader.undertaleData.SetGMS2Version(2023, 1); - reader.undertaleData.SetLTS(false); + reader.undertaleData.SetGMS2Version(2023, 1, 0, 0, false); } } diff --git a/UndertaleModLib/UndertaleData.cs b/UndertaleModLib/UndertaleData.cs index 0d68ee1d0..bc4c03141 100644 --- a/UndertaleModLib/UndertaleData.cs +++ b/UndertaleModLib/UndertaleData.cs @@ -467,15 +467,23 @@ private bool TestGMS1Version(uint stableBuild, uint betaBuild, bool allowGMS2 = /// The minor version. /// The release version. /// The build version. - public void SetGMS2Version(uint major, uint minor = 0, uint release = 0, uint build = 0) + /// If included, alter the data branch between LTS and non-LTS. + public void SetGMS2Version(uint? major = null, uint minor = 0, uint release = 0, uint build = 0, bool? isLTS = null) { if (major != 2 && major != 2022 && major != 2023 && major != 2024) throw new NotSupportedException("Attempted to set a version of GameMaker " + major + " using SetGMS2Version"); - GeneralInfo.Major = major; - GeneralInfo.Minor = minor; - GeneralInfo.Release = release; - GeneralInfo.Build = build; + if (major is not null) + { + GeneralInfo.Major = (uint)major; + GeneralInfo.Minor = minor; + GeneralInfo.Release = release; + GeneralInfo.Build = build; + } + if (isLTS is not null) + { + GeneralInfo.Branch = (bool)isLTS ? UndertaleGeneralInfo.BranchType.LTS2022_0 : UndertaleGeneralInfo.BranchType.Post2022_0; + } } /// @@ -509,18 +517,6 @@ public bool IsVersionAtLeast(uint major, uint minor = 0, uint release = 0, uint return true; // The version is exactly what supplied. } - /// - /// Sets the branch type in GeneralInfo to LTS. (true for LTS, false for non-LTS.) - /// - /// true for LTS, false for non-LTS. - public void SetLTS(bool isLTS) - { - if (isLTS) - GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.LTS2022_0; - else - GeneralInfo.Branch = UndertaleGeneralInfo.BranchType.Post2022_0; - } - /// /// Reports whether the version of the data file is the same or higher than a specified version, and off the LTS branch that lacks some features. /// From ab9ecf98043d40ddaef5f0b057687c0bad1bcec9 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Sun, 30 Jun 2024 15:56:14 -0400 Subject: [PATCH 5/6] More flexible compromise fix --- UndertaleModLib/UndertaleChunks.cs | 2 +- UndertaleModLib/UndertaleData.cs | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index 4d098a3d9..14086d2ea 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -112,7 +112,7 @@ internal override void UnserializeChunk(UndertaleReader reader) if (reader.undertaleData.IsVersionAtLeast(2023, 1) && reader.undertaleData.GeneralInfo.Branch == UndertaleGeneralInfo.BranchType.Unknown) { - reader.undertaleData.SetGMS2Version(isLTS: true); + reader.undertaleData.SetLTS(true); } } diff --git a/UndertaleModLib/UndertaleData.cs b/UndertaleModLib/UndertaleData.cs index bc4c03141..0a44ad7dc 100644 --- a/UndertaleModLib/UndertaleData.cs +++ b/UndertaleModLib/UndertaleData.cs @@ -468,24 +468,32 @@ private bool TestGMS1Version(uint stableBuild, uint betaBuild, bool allowGMS2 = /// The release version. /// The build version. /// If included, alter the data branch between LTS and non-LTS. - public void SetGMS2Version(uint? major = null, uint minor = 0, uint release = 0, uint build = 0, bool? isLTS = null) + public void SetGMS2Version(uint major, uint minor = 0, uint release = 0, uint build = 0, bool? isLTS = null) { if (major != 2 && major != 2022 && major != 2023 && major != 2024) throw new NotSupportedException("Attempted to set a version of GameMaker " + major + " using SetGMS2Version"); - if (major is not null) - { - GeneralInfo.Major = (uint)major; - GeneralInfo.Minor = minor; - GeneralInfo.Release = release; - GeneralInfo.Build = build; - } + GeneralInfo.Major = (uint)major; + GeneralInfo.Minor = minor; + GeneralInfo.Release = release; + GeneralInfo.Build = build; + if (isLTS is not null) { - GeneralInfo.Branch = (bool)isLTS ? UndertaleGeneralInfo.BranchType.LTS2022_0 : UndertaleGeneralInfo.BranchType.Post2022_0; + SetLTS((bool)isLTS); } } + /// + /// Sets the branch type in GeneralInfo to the appropriate LTS or non-LTS version based on + /// + /// If included, alter the data branch between LTS and non-LTS. + public void SetLTS(bool isLTS) + { + // Insert additional logic as needed for new branches using IsVersionAtLeast + GeneralInfo.Branch = isLTS ? UndertaleGeneralInfo.BranchType.LTS2022_0 : UndertaleGeneralInfo.BranchType.Post2022_0; + } + /// /// Reports whether the version of the data file is the same or higher than a specified version. /// From 43e145a731ff292e5cd993c0515221fc95e1bb2e Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Mon, 8 Jul 2024 22:14:07 -0400 Subject: [PATCH 6/6] Address reviews --- UndertaleModLib/Models/UndertaleGeneralInfo.cs | 16 ++++++++-------- UndertaleModLib/UndertaleChunks.cs | 2 +- UndertaleModLib/UndertaleData.cs | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleGeneralInfo.cs b/UndertaleModLib/Models/UndertaleGeneralInfo.cs index cbb3afecf..9327528ec 100644 --- a/UndertaleModLib/Models/UndertaleGeneralInfo.cs +++ b/UndertaleModLib/Models/UndertaleGeneralInfo.cs @@ -210,15 +210,15 @@ public enum FunctionClassification : ulong /// public enum BranchType { - Unknown, + Pre2022_0, LTS2022_0, Post2022_0 } /// - /// The GameMaker release branch of the data file. May be set to "NonLTS" when features exempted from LTS are detected. + /// The GameMaker release branch of the data file. May be set to when features exempted from LTS are detected. /// - public BranchType Branch = BranchType.Unknown; + public BranchType Branch = BranchType.Pre2022_0; /// /// The major version of the data file. @@ -333,13 +333,13 @@ public static (uint, uint, uint, uint, BranchType) TestForCommonGMSVersions(Unde if (reader.AllChunkNames.Contains("PSEM")) // 2023.2, not present on LTS detectedVer = (2023, 2, 0, 0, BranchType.Post2022_0); else if (reader.AllChunkNames.Contains("FEAT")) // 2022.8 - detectedVer = (2022, 8, 0, 0, BranchType.Unknown); + detectedVer = (2022, 8, 0, 0, BranchType.Pre2022_0); else if (reader.AllChunkNames.Contains("FEDS")) // 2.3.6 - detectedVer = (2, 3, 6, 0, BranchType.Unknown); + detectedVer = (2, 3, 6, 0, BranchType.Pre2022_0); else if (reader.AllChunkNames.Contains("SEQN")) // 2.3 - detectedVer = (2, 3, 0, 0, BranchType.Unknown); + detectedVer = (2, 3, 0, 0, BranchType.Pre2022_0); else if (reader.AllChunkNames.Contains("TGIN")) // 2.2.1 - detectedVer = (2, 2, 1, 0, BranchType.Unknown); + detectedVer = (2, 2, 1, 0, BranchType.Pre2022_0); if (detectedVer.Major > 2 || (detectedVer.Major == 2 && detectedVer.Minor >= 3)) { @@ -605,7 +605,7 @@ public override string ToString() sb.Append(" (GMS "); else sb.Append(" (GM "); - if (Branch == BranchType.LTS2022_0) + if (Branch == BranchType.LTS2022_0) // TODO: Is there some way to dynamically get this from the enum? { sb.Append("2022.0"); } diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index 14086d2ea..9c3610227 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -110,7 +110,7 @@ internal override void UnserializeChunk(UndertaleReader reader) } if (reader.undertaleData.IsVersionAtLeast(2023, 1) && - reader.undertaleData.GeneralInfo.Branch == UndertaleGeneralInfo.BranchType.Unknown) + reader.undertaleData.GeneralInfo.Branch == UndertaleGeneralInfo.BranchType.Pre2022_0) { reader.undertaleData.SetLTS(true); } diff --git a/UndertaleModLib/UndertaleData.cs b/UndertaleModLib/UndertaleData.cs index 0a44ad7dc..104f5d68a 100644 --- a/UndertaleModLib/UndertaleData.cs +++ b/UndertaleModLib/UndertaleData.cs @@ -473,7 +473,7 @@ public void SetGMS2Version(uint major, uint minor = 0, uint release = 0, uint bu if (major != 2 && major != 2022 && major != 2023 && major != 2024) throw new NotSupportedException("Attempted to set a version of GameMaker " + major + " using SetGMS2Version"); - GeneralInfo.Major = (uint)major; + GeneralInfo.Major = major; GeneralInfo.Minor = minor; GeneralInfo.Release = release; GeneralInfo.Build = build;