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

Restore 2.3.1 version check (part 2) #1828

Merged
merged 6 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 29 additions & 4 deletions UndertaleModLib/Models/UndertaleAnimationCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void Unserialize(UndertaleReader reader)
Name = reader.ReadUndertaleString();
Function = (FunctionType)reader.ReadUInt32();
Iterations = reader.ReadUInt32();

Points = reader.ReadUndertaleObject<UndertaleSimpleList<Point>>();
}

Expand All @@ -141,14 +142,38 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader)
{
reader.Position += 12;

// Read the number of points in the curve
uint pointCount = reader.ReadUInt32();

// This check is partly duplicated from UndertaleChunks.cs, but it's necessary to handle embedded curves
// (For example, those in SEQN in the TS!Underswap v1.0 demo; see issue #1414)
if (!reader.undertaleData.IsVersionAtLeast(2, 3, 1))
{
long returnPosition = reader.AbsPosition;
if (pointCount > 0)
{
reader.AbsPosition += 8;
if (reader.ReadUInt32() != 0) // In 2.3 an int with the value of 0 would be set here,
{ // It cannot be version 2.3 if this value isn't 0
reader.undertaleData.SetGMS2Version(2, 3, 1);
}
else
{
if (reader.ReadUInt32() == 0) // At all points (besides the first one)
reader.undertaleData.SetGMS2Version(2, 3, 1); // If BezierX0 equals to 0 (the above check)
// Then BezierY0 equals to 0 as well (the current check)
}
}
reader.AbsPosition = returnPosition;
}

// "Points"
uint count = reader.ReadUInt32();
if (reader.undertaleData.IsVersionAtLeast(2, 3, 1))
reader.Position += 24 * count;
reader.Position += 24 * pointCount;
else
reader.Position += 12 * count;
reader.Position += 12 * pointCount;

return 1 + count;
return 1 + pointCount;
}

/// <inheritdoc/>
Expand Down
8 changes: 5 additions & 3 deletions UndertaleModLib/UndertaleChunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,8 @@ public class UndertaleChunkACRV : UndertaleListChunk<UndertaleAnimationCurve>
public override string Name => "ACRV";

private static bool checkedForGMS2_3_1;

// See also a similar check in UndertaleAnimationCurve.cs, necessary for embedded animation curves.
private void CheckForGMS2_3_1(UndertaleReader reader)
{
if (reader.undertaleData.IsVersionAtLeast(2, 3, 1))
Expand All @@ -1522,11 +1524,11 @@ private void CheckForGMS2_3_1(UndertaleReader reader)
return;
}

reader.AbsPosition = reader.ReadUInt32(); // go to the first "Point"
reader.AbsPosition = reader.ReadUInt32(); // Go to the first "Point"
reader.Position += 8;

if (reader.ReadUInt32() != 0) // in 2.3 a int with the value of 0 would be set here,
{ // it cannot be version 2.3 if this value isn't 0
if (reader.ReadUInt32() != 0) // In 2.3 an int with the value of 0 would be set here,
{ // It cannot be version 2.3 if this value isn't 0
reader.undertaleData.SetGMS2Version(2, 3, 1);
}
else
Expand Down
Loading