Skip to content

Commit

Permalink
Add save/load for FEAT chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
colinator27 committed Sep 8, 2022
1 parent 4ceb929 commit 856041c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
36 changes: 36 additions & 0 deletions UndertaleModLib/Models/UndertaleFeatureFlags.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace UndertaleModLib.Models;

/// <summary>
/// List of feature flag entries in a GameMaker data file, version 2022.8 and above.
/// </summary>
[PropertyChanged.AddINotifyPropertyChangedInterface]
public class UndertaleFeatureFlags : UndertaleObject, IDisposable
{
public UndertaleSimpleListString List { get; set; }


/// <inheritdoc />
public void Serialize(UndertaleWriter writer)
{
List.Serialize(writer);
}

/// <inheritdoc />
public void Unserialize(UndertaleReader reader)
{
List = new UndertaleSimpleListString();
List.Unserialize(reader);
}

/// <inheritdoc/>
public void Dispose()
{
GC.SuppressFinalize(this);

List = null;
}
}
31 changes: 31 additions & 0 deletions UndertaleModLib/UndertaleChunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class UndertaleChunkFORM : UndertaleChunk
public UndertaleChunkACRV ACRV => Chunks.GetValueOrDefault("ACRV") as UndertaleChunkACRV;
public UndertaleChunkSEQN SEQN => Chunks.GetValueOrDefault("SEQN") as UndertaleChunkSEQN;
public UndertaleChunkTAGS TAGS => Chunks.GetValueOrDefault("TAGS") as UndertaleChunkTAGS;
public UndertaleChunkFEAT FEAT => Chunks.GetValueOrDefault("FEAT") as UndertaleChunkFEAT;

internal override void SerializeChunk(UndertaleWriter writer)
{
Expand Down Expand Up @@ -1054,4 +1055,34 @@ internal override void UnserializeChunk(UndertaleReader reader)
base.UnserializeChunk(reader);
}
}

// GMS2022.8+ only
public class UndertaleChunkFEAT : UndertaleSingleChunk<UndertaleFeatureFlags>
{
public override string Name => "FEAT";

internal override void SerializeChunk(UndertaleWriter writer)
{
if (writer.undertaleData.GeneralInfo.Major < 2)
throw new InvalidOperationException();

while (writer.Position % 4 != 0)
writer.Write((byte)0);

base.SerializeChunk(writer);
}

internal override void UnserializeChunk(UndertaleReader reader)
{
if (reader.undertaleData.GeneralInfo.Major < 2)
throw new InvalidOperationException();

// Padding
while (reader.Position % 4 != 0)
if (reader.ReadByte() != 0)
throw new IOException("Padding error!");

base.UnserializeChunk(reader);
}
}
}
5 changes: 5 additions & 0 deletions UndertaleModLib/UndertaleData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ public object this[Type resourceType]
/// </summary>
public IList<UndertaleSequence> Sequences => FORM.SEQN?.List;

/// <summary>
/// The feature flags stored in the data file.
/// </summary>
public UndertaleFeatureFlags FeatureFlags => FORM.FEAT?.Object;

/// <summary>
/// Whether this is an unsupported bytecode version.
/// </summary>
Expand Down

0 comments on commit 856041c

Please sign in to comment.