From 43195b1553d07acda97e8129359c8040fb4da972 Mon Sep 17 00:00:00 2001
From: Jacky720 <32578221+Jacky720@users.noreply.github.com>
Date: Sat, 5 Aug 2023 11:42:09 -0400
Subject: [PATCH 1/2] Add LineHeight as a 2023.6 font attribute.
---
UndertaleModLib/Models/UndertaleFont.cs | 11 ++++
UndertaleModLib/UndertaleChunks.cs | 57 +++++++++++++++++++
.../Converters/IsVersionAtLeastConverter.cs | 2 +-
.../UndertaleFontEditor.xaml | 5 ++
4 files changed, 74 insertions(+), 1 deletion(-)
diff --git a/UndertaleModLib/Models/UndertaleFont.cs b/UndertaleModLib/Models/UndertaleFont.cs
index 6a2b3fdf1..73be58a73 100644
--- a/UndertaleModLib/Models/UndertaleFont.cs
+++ b/UndertaleModLib/Models/UndertaleFont.cs
@@ -92,6 +92,11 @@ public class UndertaleFont : UndertaleNamedResource, IDisposable
/// 0 if SDF is disabled for this font.
public uint SDFSpread { get; set; }
+ ///
+ /// Was introduced in GM 2023.6.
+ ///
+ public uint LineHeight { get; set; }
+
///
/// The glyphs that this font uses.
///
@@ -292,6 +297,8 @@ public void Serialize(UndertaleWriter writer)
writer.Write(Ascender);
if (writer.undertaleData.IsVersionAtLeast(2023, 2))
writer.Write(SDFSpread);
+ if (writer.undertaleData.IsVersionAtLeast(2023, 6))
+ writer.Write(LineHeight);
writer.WriteUndertaleObject(Glyphs);
}
@@ -326,6 +333,8 @@ public void Unserialize(UndertaleReader reader)
Ascender = reader.ReadUInt32();
if (reader.undertaleData.IsVersionAtLeast(2023, 2))
SDFSpread = reader.ReadUInt32();
+ if (reader.undertaleData.IsVersionAtLeast(2023, 6))
+ LineHeight = reader.ReadUInt32();
Glyphs = reader.ReadUndertaleObject>();
}
@@ -339,6 +348,8 @@ public static uint UnserializeChildObjectCount(UndertaleReader reader)
skipSize += 4; // Ascender
if (reader.undertaleData.IsVersionAtLeast(2023, 2))
skipSize += 4; // SDFSpread
+ if (reader.undertaleData.IsVersionAtLeast(2023, 6))
+ skipSize += 4; // LineHeight
reader.Position += skipSize;
diff --git a/UndertaleModLib/UndertaleChunks.cs b/UndertaleModLib/UndertaleChunks.cs
index 4cb010604..7f54c965f 100644
--- a/UndertaleModLib/UndertaleChunks.cs
+++ b/UndertaleModLib/UndertaleChunks.cs
@@ -451,6 +451,7 @@ public class UndertaleChunkFONT : UndertaleListChunk
public byte[] Padding;
private static bool checkedFor2022_2;
+ private static bool checkedFor2023_6;
private void CheckForGM2022_2(UndertaleReader reader)
{
/* This code performs four checks to identify GM2022.2.
@@ -509,6 +510,57 @@ private void CheckForGM2022_2(UndertaleReader reader)
checkedFor2022_2 = true;
}
+ private void CheckForGM2023_6(UndertaleReader reader)
+ {
+ // This is basically the same as the 2022.2 check, but adapted for the LineHeight value instead of Ascender.
+
+ // We already know whether the version is more or less than 2023.2 due to PSEM. Checking a shorter range narrows possibility of error.
+ if (!reader.undertaleData.IsVersionAtLeast(2023, 2) || reader.undertaleData.IsVersionAtLeast(2023, 6))
+ {
+ checkedFor2023_6 = true;
+ return;
+ }
+
+ long positionToReturn = reader.Position;
+ bool GMS2023_6 = false;
+
+ if (reader.ReadUInt32() > 0) // Font count
+ {
+ uint firstFontPointer = reader.ReadUInt32();
+ reader.AbsPosition = firstFontPointer + 56; // Two more values: SDFSpread and LineHeight. 48 + 4 + 4 = 56.
+ uint glyphsLength = reader.ReadUInt32();
+ GMS2023_6 = true;
+ if ((glyphsLength * 4) > this.Length)
+ {
+ GMS2023_6 = false;
+ }
+ else if (glyphsLength != 0)
+ {
+ List glyphPointers = new List((int)glyphsLength);
+ for (uint i = 0; i < glyphsLength; i++)
+ glyphPointers.Add(reader.ReadUInt32());
+ foreach (uint pointer in glyphPointers)
+ {
+ if (reader.AbsPosition != pointer)
+ {
+ GMS2023_6 = false;
+ break;
+ }
+
+ reader.Position += 14;
+ ushort kerningLength = reader.ReadUInt16();
+ reader.Position += (uint)4 * kerningLength; // combining read/write would apparently break
+ }
+ }
+
+ }
+ if (GMS2023_6)
+ reader.undertaleData.SetGMS2Version(2023, 6);
+ reader.Position = positionToReturn;
+
+ checkedFor2023_6 = true;
+ }
+
internal override void SerializeChunk(UndertaleWriter writer)
{
base.SerializeChunk(writer);
@@ -528,6 +580,9 @@ internal override void UnserializeChunk(UndertaleReader reader)
if (!checkedFor2022_2)
CheckForGM2022_2(reader);
+ if (!checkedFor2023_6)
+ CheckForGM2023_6(reader);
+
base.UnserializeChunk(reader);
Padding = reader.ReadBytes(512);
@@ -536,8 +591,10 @@ internal override void UnserializeChunk(UndertaleReader reader)
internal override uint UnserializeObjectCount(UndertaleReader reader)
{
checkedFor2022_2 = false;
+ checkedFor2023_6 = false;
CheckForGM2022_2(reader);
+ CheckForGM2023_6(reader);
return base.UnserializeObjectCount(reader);
}
diff --git a/UndertaleModTool/Converters/IsVersionAtLeastConverter.cs b/UndertaleModTool/Converters/IsVersionAtLeastConverter.cs
index e0c546240..f957c4dfa 100644
--- a/UndertaleModTool/Converters/IsVersionAtLeastConverter.cs
+++ b/UndertaleModTool/Converters/IsVersionAtLeastConverter.cs
@@ -33,7 +33,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
if (ver.Groups[3].Value != "")
release = uint.Parse(ver.Groups[3].Value);
if (ver.Groups[4].Value != "")
- release = uint.Parse(ver.Groups[4].Value);
+ build = uint.Parse(ver.Groups[4].Value);
if (mainWindow.Data.IsVersionAtLeast(major, minor, release, build))
return Visibility.Visible;
diff --git a/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml b/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml
index 250f78c6b..904d250de 100644
--- a/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml
+++ b/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml
@@ -116,6 +116,11 @@
+
+
+
Hint: You can click on any glyph here to highlight it in the "Glyphs".
From 4ee5fd5ba1137e53ff0e904c63c4a8245d7e5973 Mon Sep 17 00:00:00 2001
From: Jacky720 <32578221+Jacky720@users.noreply.github.com>
Date: Sat, 5 Aug 2023 11:56:49 -0400
Subject: [PATCH 2/2] fix font rows in GUI
---
.../UndertaleFontEditor.xaml | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml b/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml
index 904d250de..9bd05cd80 100644
--- a/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml
+++ b/UndertaleModTool/Editors/UndertaleFontEditor/UndertaleFontEditor.xaml
@@ -121,10 +121,10 @@
-
+
Hint: You can click on any glyph here to highlight it in the "Glyphs".
-
+
@@ -204,7 +204,7 @@
-
+