mysimulation/server/tso.files/Formats/IFF/Chunks/BCON.cs
Tony Bark 8fec258215 Added FSO.Files for use with the API server
Don't ask me. FreeSO is the prime example of dependency hell.
2024-05-01 04:38:12 -04:00

50 lines
1.5 KiB
C#
Executable file

using System.IO;
using FSO.Files.Utils;
namespace FSO.Files.Formats.IFF.Chunks
{
/// <summary>
/// This chunk type holds a number of constants that behavior code can refer to.
/// Labels may be provided for them in a TRCN chunk with the same ID.
/// </summary>
public class BCON : IffChunk
{
public byte Flags;
public ushort[] Constants = new ushort[0];
/// <summary>
/// Reads a BCON chunk from a stream.
/// </summary>
/// <param name="iff">An Iff instance.</param>
/// <param name="stream">A Stream instance holding a BCON.</param>
public override void Read(IffFile iff, Stream stream)
{
using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
{
var num = io.ReadByte();
Flags = io.ReadByte();
Constants = new ushort[num];
for (var i = 0; i < num; i++)
{
Constants[i] = io.ReadUInt16();
}
}
}
public override bool Write(IffFile iff, Stream stream)
{
using (var io = IoWriter.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
{
io.WriteByte((byte)Constants.Length);
io.WriteByte(Flags);
foreach (var c in Constants)
{
io.WriteUInt16(c);
}
return true;
}
}
}
}