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 4 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
25 changes: 25 additions & 0 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,6 +142,30 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader)
{
reader.Position += 12;

// 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;
uint numPoints = reader.ReadUInt32();
colinator27 marked this conversation as resolved.
Show resolved Hide resolved
if (numPoints > 0)
{
reader.AbsPosition += 8;
if (reader.ReadUInt32() != 0) // In 2.3 a int with the value of 0 would be set here,
colinator27 marked this conversation as resolved.
Show resolved Hide resolved
{ // it cannot be version 2.3 if this value isn't 0
colinator27 marked this conversation as resolved.
Show resolved Hide resolved
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)
colinator27 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
reader.undertaleData.SetGMS2Version(2, 3, 1); // if BezierX0 equals to 0 (the above check)
reader.undertaleData.SetGMS2Version(2, 3, 1); // If BezierX0 equals to 0 (the above check)

// then BezierY0 equals to 0 as well (the current check)
colinator27 marked this conversation as resolved.
Show resolved Hide resolved
}
}

reader.AbsPosition = returnPosition;
}

// "Points"
uint count = reader.ReadUInt32();
if (reader.undertaleData.IsVersionAtLeast(2, 3, 1))
Expand Down
6 changes: 4 additions & 2 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,10 +1524,10 @@ 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,
if (reader.ReadUInt32() != 0) // In 2.3 a int with the value of 0 would be set here,
colinator27 marked this conversation as resolved.
Show resolved Hide resolved
{ // it cannot be version 2.3 if this value isn't 0
colinator27 marked this conversation as resolved.
Show resolved Hide resolved
reader.undertaleData.SetGMS2Version(2, 3, 1);
}
Expand Down
Loading