From db6469cfd5198d7d76fa76d30d966b39d265b856 Mon Sep 17 00:00:00 2001 From: Nikita Krapivin Date: Tue, 25 Apr 2023 23:57:36 +0500 Subject: [PATCH 1/4] Fix YYSWF parsing on 2022.1 and beyond --- UndertaleModLib/Models/UndertaleSprite.cs | 68 ++++++++++++++++------- UndertaleModLib/UndertaleIO.cs | 4 +- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleSprite.cs b/UndertaleModLib/Models/UndertaleSprite.cs index 1ceddbe8f..9852391b8 100644 --- a/UndertaleModLib/Models/UndertaleSprite.cs +++ b/UndertaleModLib/Models/UndertaleSprite.cs @@ -1174,11 +1174,17 @@ public class UndertaleYYSWFGradientFillData : UndertaleObject public UndertaleYYSWFGradientFillType GradientFillType { get; set; } public UndertaleYYSWFMatrix33 TransformationMatrix { get; set; } public UndertaleSimpleList Records { get; set; } + /// + /// Unknown purpose. Probably to accomodate for new texture formats. + /// + public int? TPEIndex { get; set; } /// public void Serialize(UndertaleWriter writer) { writer.Write((int)GradientFillType); + if (TPEIndex is not null) + writer.Write(TPEIndex.Value); writer.WriteUndertaleObject(TransformationMatrix); writer.WriteUndertaleObject(Records); } @@ -1187,6 +1193,10 @@ public void Serialize(UndertaleWriter writer) public void Unserialize(UndertaleReader reader) { GradientFillType = (UndertaleYYSWFGradientFillType)reader.ReadInt32(); + if (reader.undertaleData.IsVersionAtLeast(2022, 1)) + { + TPEIndex = reader.ReadInt32(); + } TransformationMatrix = reader.ReadUndertaleObject(); Records = new UndertaleSimpleList(); int count = reader.ReadInt32(); @@ -1651,6 +1661,10 @@ public class UndertaleYYSWFBitmapData : UndertaleObject public UndertaleYYSWFBitmapType Type { get; set; } public int Width { get; set; } public int Height { get; set; } + /// + /// Unknown purpose. Probably to accomodate for new texture formats. + /// + public int? TPEIndex { get; set; } public byte[] ImageData { get; set; } public byte[] AlphaData { get; set; } public byte[] ColorPaletteData { get; set; } @@ -1663,18 +1677,25 @@ public void Serialize(UndertaleWriter writer) writer.Write(Width); writer.Write(Height); - writer.Write(ImageData is null ? 0 : ImageData.Length); - writer.Write(AlphaData is null ? 0 : AlphaData.Length); - writer.Write(ColorPaletteData is null ? 0 : ColorPaletteData.Length); + if (TPEIndex is null) + { + writer.Write(ImageData is null ? 0 : ImageData.Length); + writer.Write(AlphaData is null ? 0 : AlphaData.Length); + writer.Write(ColorPaletteData is null ? 0 : ColorPaletteData.Length); - if (ImageData != null) - writer.Write(ImageData); - if (AlphaData != null) - writer.Write(AlphaData); - if (ColorPaletteData != null) - writer.Write(ColorPaletteData); + if (ImageData != null) + writer.Write(ImageData); + if (AlphaData != null) + writer.Write(AlphaData); + if (ColorPaletteData != null) + writer.Write(ColorPaletteData); - writer.Align(4); + writer.Align(4); + } + else + { + writer.Write(TPEIndex.Value); + } } /// @@ -1684,18 +1705,25 @@ public void Unserialize(UndertaleReader reader) Width = reader.ReadInt32(); Height = reader.ReadInt32(); - int iL = reader.ReadInt32(); - int aL = reader.ReadInt32(); - int cL = reader.ReadInt32(); + if (reader.undertaleData.IsVersionAtLeast(2022, 1)) + { + TPEIndex = reader.ReadInt32(); + } + else + { + int iL = reader.ReadInt32(); + int aL = reader.ReadInt32(); + int cL = reader.ReadInt32(); - if (iL > 0) - ImageData = reader.ReadBytes(iL); - if (aL > 0) - AlphaData = reader.ReadBytes(aL); - if (cL > 0) - ColorPaletteData = reader.ReadBytes(cL); + if (iL > 0) + ImageData = reader.ReadBytes(iL); + if (aL > 0) + AlphaData = reader.ReadBytes(aL); + if (cL > 0) + ColorPaletteData = reader.ReadBytes(cL); - reader.Align(4); + reader.Align(4); + } } } diff --git a/UndertaleModLib/UndertaleIO.cs b/UndertaleModLib/UndertaleIO.cs index cabbd6667..e1f29eea9 100644 --- a/UndertaleModLib/UndertaleIO.cs +++ b/UndertaleModLib/UndertaleIO.cs @@ -344,7 +344,9 @@ private bool ProcessCountExc(uint poolSize = 0) if (poolSize != 0 && poolSize != objectPool.Count) { SubmitWarning("Warning - the estimated object pool size differs from the actual size.\n" + - "Please report this on UndertaleModTool GitHub."); + "Please report this on UndertaleModTool GitHub.\n" + + "Unless you have a .win with SWF sprites,\n" + + "since YYSWF objects are not pooled due to overlapping."); } return false; From e199332b31d13f1a405eceb0307f7e6137842181 Mon Sep 17 00:00:00 2001 From: Nikita Krapivin Date: Thu, 4 May 2023 21:02:00 +0500 Subject: [PATCH 2/4] Update UndertaleModLib/Models/UndertaleSprite.cs Co-authored-by: VladiStep --- UndertaleModLib/Models/UndertaleSprite.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UndertaleModLib/Models/UndertaleSprite.cs b/UndertaleModLib/Models/UndertaleSprite.cs index 9852391b8..5fd9c1954 100644 --- a/UndertaleModLib/Models/UndertaleSprite.cs +++ b/UndertaleModLib/Models/UndertaleSprite.cs @@ -1177,6 +1177,9 @@ public class UndertaleYYSWFGradientFillData : UndertaleObject /// /// Unknown purpose. Probably to accomodate for new texture formats. /// + /// + /// Presumably present in GM 2022.1+. + /// public int? TPEIndex { get; set; } /// From 3f75742ca47f9d9d871e8867b6429689e7bab01e Mon Sep 17 00:00:00 2001 From: Nikita Krapivin Date: Sun, 7 May 2023 22:23:11 +0500 Subject: [PATCH 3/4] Update UndertaleModLib/Models/UndertaleSprite.cs Co-authored-by: VladiStep --- UndertaleModLib/Models/UndertaleSprite.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/UndertaleModLib/Models/UndertaleSprite.cs b/UndertaleModLib/Models/UndertaleSprite.cs index 5fd9c1954..682f46c96 100644 --- a/UndertaleModLib/Models/UndertaleSprite.cs +++ b/UndertaleModLib/Models/UndertaleSprite.cs @@ -1667,6 +1667,9 @@ public class UndertaleYYSWFBitmapData : UndertaleObject /// /// Unknown purpose. Probably to accomodate for new texture formats. /// + /// + /// Presumably present in GM 2022.1+. + /// public int? TPEIndex { get; set; } public byte[] ImageData { get; set; } public byte[] AlphaData { get; set; } From b9637533060cd9717e27c97cf2ae01e946b398a5 Mon Sep 17 00:00:00 2001 From: Nikita Krapivin Date: Tue, 31 Oct 2023 21:52:36 +0500 Subject: [PATCH 4/4] Update UndertaleIO.cs --- UndertaleModLib/UndertaleIO.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/UndertaleModLib/UndertaleIO.cs b/UndertaleModLib/UndertaleIO.cs index e1f29eea9..cabbd6667 100644 --- a/UndertaleModLib/UndertaleIO.cs +++ b/UndertaleModLib/UndertaleIO.cs @@ -344,9 +344,7 @@ private bool ProcessCountExc(uint poolSize = 0) if (poolSize != 0 && poolSize != objectPool.Count) { SubmitWarning("Warning - the estimated object pool size differs from the actual size.\n" + - "Please report this on UndertaleModTool GitHub.\n" + - "Unless you have a .win with SWF sprites,\n" + - "since YYSWF objects are not pooled due to overlapping."); + "Please report this on UndertaleModTool GitHub."); } return false;