Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix YYSWF parsing on 2022.1 and beyond #1352

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions UndertaleModLib/Models/UndertaleSprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,17 @@ public class UndertaleYYSWFGradientFillData : UndertaleObject
public UndertaleYYSWFGradientFillType GradientFillType { get; set; }
public UndertaleYYSWFMatrix33 TransformationMatrix { get; set; }
public UndertaleSimpleList<UndertaleYYSWFGradientRecord> Records { get; set; }
/// <summary>
/// Unknown purpose. Probably to accomodate for new texture formats.
/// </summary>
public int? TPEIndex { get; set; }
nkrapivin marked this conversation as resolved.
Show resolved Hide resolved

/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
{
writer.Write((int)GradientFillType);
if (TPEIndex is not null)
writer.Write(TPEIndex.Value);
writer.WriteUndertaleObject(TransformationMatrix);
writer.WriteUndertaleObject(Records);
}
Expand All @@ -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<UndertaleYYSWFMatrix33>();
Records = new UndertaleSimpleList<UndertaleYYSWFGradientRecord>();
int count = reader.ReadInt32();
Expand Down Expand Up @@ -1651,6 +1661,10 @@ public class UndertaleYYSWFBitmapData : UndertaleObject
public UndertaleYYSWFBitmapType Type { get; set; }
public int Width { get; set; }
public int Height { get; set; }
/// <summary>
/// Unknown purpose. Probably to accomodate for new texture formats.
/// </summary>
public int? TPEIndex { get; set; }
nkrapivin marked this conversation as resolved.
Show resolved Hide resolved
public byte[] ImageData { get; set; }
public byte[] AlphaData { get; set; }
public byte[] ColorPaletteData { get; set; }
Expand All @@ -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);
}
}

/// <inheritdoc />
Expand All @@ -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);
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion UndertaleModLib/UndertaleIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
nkrapivin marked this conversation as resolved.
Show resolved Hide resolved
}

return false;
Expand Down