Skip to content

Commit

Permalink
2022.6 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacky720 committed Sep 9, 2022
1 parent 1af6629 commit 1e1d464
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions UndertaleModLib/Models/UndertaleExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void Serialize(UndertaleWriter writer)
writer.WriteUndertaleString(FolderName);
writer.WriteUndertaleString(Name);
writer.WriteUndertaleString(ClassName);
if (writer.undertaleData.GM2022_6)
if (writer.undertaleData.IsVersionAtLeast(2022, 6))
{
writer.WriteUndertaleObjectPointer(Files);
writer.WriteUndertaleObjectPointer(Options);
Expand All @@ -332,7 +332,7 @@ public void Unserialize(UndertaleReader reader)
FolderName = reader.ReadUndertaleString();
Name = reader.ReadUndertaleString();
ClassName = reader.ReadUndertaleString();
if (reader.undertaleData.GM2022_6)
if (reader.undertaleData.IsVersionAtLeast(2022, 6))
{
Files = reader.ReadUndertaleObjectPointer<UndertalePointerList<UndertaleExtensionFile>>();
Options = reader.ReadUndertaleObjectPointer<UndertalePointerList<UndertaleExtensionOption>>();
Expand Down
6 changes: 5 additions & 1 deletion UndertaleModLib/Models/UndertaleGeneralInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,11 @@ public enum GMSVersions
/// <summary>
/// Whether the data file is from version GM2022.5
/// </summary>
GM2022_5
GM2022_5,
/// <summary>
/// Whether the data file is from version GM2022.6
/// </summary>
GM2022_6
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion UndertaleModLib/Models/UndertaleRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ public void Unserialize(UndertaleReader reader)
case LayerType.Effect:
// Because effect data is empty in 2022.1+, it would erroneously read the next object.
Data =
reader.undertaleData.GMS2022_1
reader.undertaleData.IsVersionAtLeast(2022, 1)
? new LayerEffectData() { EffectType = EffectType, Properties = EffectProperties }
: reader.ReadUndertaleObject<LayerEffectData>();
break;
Expand Down
21 changes: 12 additions & 9 deletions UndertaleModLib/UndertaleChunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public class UndertaleChunkEXTN : UndertaleListChunk<UndertaleExtension>

internal override void UnserializeChunk(UndertaleReader reader)
{
if (reader.undertaleData.GMS2_3)
if (reader.undertaleData.IsVersionAtLeast(2, 3) && !reader.undertaleData.IsVersionAtLeast(2022, 6))
{
// Check for 2022.6, if possible
bool definitely2022_6 = true;
Expand Down Expand Up @@ -189,7 +189,7 @@ internal override void UnserializeChunk(UndertaleReader reader)
reader.Position = returnPosition;

if (definitely2022_6)
reader.undertaleData.GM2022_6 = true;
reader.undertaleData.SetGMS2Version(2022, 6);
}

base.UnserializeChunk(reader);
Expand Down Expand Up @@ -795,7 +795,7 @@ internal override void UnserializeChunk(UndertaleReader reader)
reader.undertaleData.SetGMS2Version(2022, 3);
}

if (reader.undertaleData.GM2022_3)
if (reader.undertaleData.IsVersionAtLeast(2022, 3))
{
// Also check for 2022.5 format
reader.Position = positionToReturn + 4;
Expand All @@ -809,23 +809,26 @@ internal override void UnserializeChunk(UndertaleReader reader)
if (header.SequenceEqual(UndertaleEmbeddedTexture.TexData.QOIAndBZip2Header))
{
reader.Position += 4; // skip width/height

bool is2022_5 = false;
// Now check the actual BZ2 headers
if (reader.ReadByte() != (byte)'B')
reader.undertaleData.GM2022_5 = true;
is2022_5 = true;
else if (reader.ReadByte() != (byte)'Z')
reader.undertaleData.GM2022_5 = true;
is2022_5 = true;
else if (reader.ReadByte() != (byte)'h')
reader.undertaleData.GM2022_5 = true;
is2022_5 = true;
else
{
reader.ReadByte();
if (reader.ReadUInt24() != 0x594131) // digits of pi... (block header)
reader.undertaleData.GM2022_5 = true;
is2022_5 = true;
else if (reader.ReadUInt24() != 0x595326)
reader.undertaleData.GM2022_5 = true;
is2022_5 = true;
}

if (is2022_5)
reader.undertaleData.SetGMS2Version(2022, 5);

// Checked one QOI+BZ2 texture. No need to check any more
break;
}
Expand Down
5 changes: 4 additions & 1 deletion UndertaleModLib/UndertaleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ public void SetGMS2Version(uint major, uint minor = 0, uint release = 0, uint bu
{
if (major == 2022)
{
if (minor >= 5)
if (minor >= 6)
GeneralInfo.GMS2Version = UndertaleGeneralInfo.GMSVersions.GM2022_6;
else if (minor >= 5)
GeneralInfo.GMS2Version = UndertaleGeneralInfo.GMSVersions.GM2022_5;
else if (minor >= 3)
GeneralInfo.GMS2Version = UndertaleGeneralInfo.GMSVersions.GM2022_3;
Expand Down Expand Up @@ -506,6 +508,7 @@ public bool IsVersionAtLeast(uint major, uint minor = 0, uint release = 0, uint
case UndertaleGeneralInfo.GMSVersions.GMS2022_2: gameMajor = 2022; gameMinor = 2; break;
case UndertaleGeneralInfo.GMSVersions.GM2022_3: gameMajor = 2022; gameMinor = 3; break;
case UndertaleGeneralInfo.GMSVersions.GM2022_5: gameMajor = 2022; gameMinor = 5; break;
case UndertaleGeneralInfo.GMSVersions.GM2022_6: gameMajor = 2022; gameMinor = 6; break;
}

if (gameMajor != major)
Expand Down

0 comments on commit 1e1d464

Please sign in to comment.