Skip to content

Commit

Permalink
Merge pull request #1828 from UnderminersTeam/version-check-fix
Browse files Browse the repository at this point in the history
Restore 2.3.1 version check (part 2)
  • Loading branch information
Miepee authored Jul 13, 2024
2 parents f7f2e7a + 3e0230b commit 9b2eca6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
33 changes: 29 additions & 4 deletions UndertaleModLib/Models/UndertaleAnimationCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public void Unserialize(UndertaleReader reader)
Name = reader.ReadUndertaleString();
Curve = (CurveType)reader.ReadUInt32();
Iterations = reader.ReadUInt32();

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

Expand All @@ -178,14 +179,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 @@ -1618,6 +1618,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 @@ -1636,11 +1638,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

0 comments on commit 9b2eca6

Please sign in to comment.