From 166ed5eacde37f4a07c308290fcd055be6f3bc56 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Sat, 24 Feb 2024 23:40:39 -0500 Subject: [PATCH 1/6] Re-add 2.3.1 check for embedded curves --- .../Models/UndertaleAnimationCurve.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/UndertaleModLib/Models/UndertaleAnimationCurve.cs b/UndertaleModLib/Models/UndertaleAnimationCurve.cs index 35ee81f81..9a9bce448 100644 --- a/UndertaleModLib/Models/UndertaleAnimationCurve.cs +++ b/UndertaleModLib/Models/UndertaleAnimationCurve.cs @@ -133,6 +133,29 @@ public void Unserialize(UndertaleReader reader) Name = reader.ReadUndertaleString(); Function = (FunctionType)reader.ReadUInt32(); Iterations = 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; + uint numPoints = reader.ReadUInt32(); + if (numPoints > 0) + { + reader.AbsPosition += 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 + 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 = reader.ReadUndertaleObject>(); } From f8794a256be8b469273d53031a9bfee6312e2ae5 Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Sat, 24 Feb 2024 23:42:23 -0500 Subject: [PATCH 2/6] [m] Spacing --- UndertaleModLib/Models/UndertaleAnimationCurve.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UndertaleModLib/Models/UndertaleAnimationCurve.cs b/UndertaleModLib/Models/UndertaleAnimationCurve.cs index 9a9bce448..a04b0c3ea 100644 --- a/UndertaleModLib/Models/UndertaleAnimationCurve.cs +++ b/UndertaleModLib/Models/UndertaleAnimationCurve.cs @@ -133,6 +133,7 @@ public void Unserialize(UndertaleReader reader) Name = reader.ReadUndertaleString(); Function = (FunctionType)reader.ReadUInt32(); Iterations = 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)) @@ -156,6 +157,7 @@ public void Unserialize(UndertaleReader reader) reader.AbsPosition = returnPosition; } + Points = reader.ReadUndertaleObject>(); } From 4e93fbc9685b485cd60b28811e8ca5c259e4e0aa Mon Sep 17 00:00:00 2001 From: Jacky720 <32578221+Jacky720@users.noreply.github.com> Date: Sat, 24 Feb 2024 23:53:03 -0500 Subject: [PATCH 3/6] [m] Comments --- UndertaleModLib/Models/UndertaleAnimationCurve.cs | 4 ++-- UndertaleModLib/UndertaleChunks.cs | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleAnimationCurve.cs b/UndertaleModLib/Models/UndertaleAnimationCurve.cs index a04b0c3ea..df9ef4bf2 100644 --- a/UndertaleModLib/Models/UndertaleAnimationCurve.cs +++ b/UndertaleModLib/Models/UndertaleAnimationCurve.cs @@ -135,7 +135,7 @@ public void Unserialize(UndertaleReader reader) Iterations = 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) + // (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; @@ -143,7 +143,7 @@ public void Unserialize(UndertaleReader reader) if (numPoints > 0) { reader.AbsPosition += 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, { // it cannot be version 2.3 if this value isn't 0 reader.undertaleData.SetGMS2Version(2, 3, 1); } diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index 3708f52f7..441fcd187 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -1504,6 +1504,8 @@ public class UndertaleChunkACRV : UndertaleListChunk 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)) @@ -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, { // it cannot be version 2.3 if this value isn't 0 reader.undertaleData.SetGMS2Version(2, 3, 1); } From 31da3be96802962dd5147466e55fb49cd15d2079 Mon Sep 17 00:00:00 2001 From: colinator27 <17358554+colinator27@users.noreply.github.com> Date: Wed, 10 Jul 2024 18:16:26 -0400 Subject: [PATCH 4/6] Move 2.3.1 check to object counting stage --- .../Models/UndertaleAnimationCurve.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleAnimationCurve.cs b/UndertaleModLib/Models/UndertaleAnimationCurve.cs index df9ef4bf2..023bba1f2 100644 --- a/UndertaleModLib/Models/UndertaleAnimationCurve.cs +++ b/UndertaleModLib/Models/UndertaleAnimationCurve.cs @@ -134,6 +134,14 @@ public void Unserialize(UndertaleReader reader) Function = (FunctionType)reader.ReadUInt32(); Iterations = reader.ReadUInt32(); + Points = reader.ReadUndertaleObject>(); + } + + /// + 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)) @@ -158,14 +166,6 @@ public void Unserialize(UndertaleReader reader) reader.AbsPosition = returnPosition; } - Points = reader.ReadUndertaleObject>(); - } - - /// - public static uint UnserializeChildObjectCount(UndertaleReader reader) - { - reader.Position += 12; - // "Points" uint count = reader.ReadUInt32(); if (reader.undertaleData.IsVersionAtLeast(2, 3, 1)) From fcd24e8bb6d56235d369d01226184ff77c1cd9f2 Mon Sep 17 00:00:00 2001 From: colinator27 <17358554+colinator27@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:45:24 -0400 Subject: [PATCH 5/6] Apply grammar fixes from code review Co-authored-by: Miepee <38186597+Miepee@users.noreply.github.com> --- UndertaleModLib/Models/UndertaleAnimationCurve.cs | 8 ++++---- UndertaleModLib/UndertaleChunks.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleAnimationCurve.cs b/UndertaleModLib/Models/UndertaleAnimationCurve.cs index 023bba1f2..7f588ed8a 100644 --- a/UndertaleModLib/Models/UndertaleAnimationCurve.cs +++ b/UndertaleModLib/Models/UndertaleAnimationCurve.cs @@ -151,15 +151,15 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) if (numPoints > 0) { reader.AbsPosition += 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 { 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.undertaleData.SetGMS2Version(2, 3, 1); // If BezierX0 equals to 0 (the above check) + // Then BezierY0 equals to 0 as well (the current check) } } diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs index 441fcd187..3556844cf 100644 --- a/UndertaleModLib/UndertaleChunks.cs +++ b/UndertaleModLib/UndertaleChunks.cs @@ -1527,8 +1527,8 @@ private void CheckForGMS2_3_1(UndertaleReader reader) 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 From 3e0230b184294bc0ff0c9b669853b3ea8bed10cd Mon Sep 17 00:00:00 2001 From: colinator27 <17358554+colinator27@users.noreply.github.com> Date: Sat, 13 Jul 2024 13:16:33 -0400 Subject: [PATCH 6/6] Slight refactor to address review --- UndertaleModLib/Models/UndertaleAnimationCurve.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/UndertaleModLib/Models/UndertaleAnimationCurve.cs b/UndertaleModLib/Models/UndertaleAnimationCurve.cs index 7f588ed8a..0c8222570 100644 --- a/UndertaleModLib/Models/UndertaleAnimationCurve.cs +++ b/UndertaleModLib/Models/UndertaleAnimationCurve.cs @@ -142,13 +142,15 @@ 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; - uint numPoints = reader.ReadUInt32(); - if (numPoints > 0) + if (pointCount > 0) { reader.AbsPosition += 8; if (reader.ReadUInt32() != 0) // In 2.3 an int with the value of 0 would be set here, @@ -162,18 +164,16 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader) // 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; } ///