diff options
Diffstat (limited to '')
-rw-r--r-- | NW4RTools/OutputStream.cs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/NW4RTools/OutputStream.cs b/NW4RTools/OutputStream.cs index 3f250a2..e934158 100644 --- a/NW4RTools/OutputStream.cs +++ b/NW4RTools/OutputStream.cs @@ -39,6 +39,25 @@ namespace NW4RTools { BaseStream.Position = pos; } + public void AlignTo(int num) { + if ((Position & (num - 1)) == 0) + return; + + for (int i = (num - (Position & (num - 1))); i != 0; i--) { + WriteByte(0); + } + } + + public void AddPadding(int count) { + if (count == 0) + return; + else if (count == 1) + WriteByte(0); + else + for (int i = count; i != 0; i--) + WriteByte(0); + } + public void WriteBytes(byte[] data) { BaseStream.Write(data, 0, data.Length); } @@ -82,6 +101,11 @@ namespace NW4RTools { WriteReversedBytes(BitConverter.GetBytes(val)); } + public void WriteBool(bool val) { + // TODO: ReadBool in InputStream + WriteByte(val ? (byte)1 : (byte)0); + } + public void WriteColor(Color col) { WriteByte(col.r); WriteByte(col.g); @@ -119,9 +143,11 @@ namespace NW4RTools { byte[] encoded = System.Text.Encoding.GetEncoding("Shift_JIS").GetBytes(name); WriteInt32(encoded.Length); WriteBytes(encoded); + WriteByte(0); - if ((encoded.Length & 3) != 0) { - for (int i = 4 - (encoded.Length & 3); i > 0; i--) { + // add 1 to the length to include the zero byte + if (((encoded.Length + 1) & 3) != 0) { + for (int i = 4 - ((encoded.Length + 1) & 3); i > 0; i--) { WriteByte(0); } } |