From ab340fe4dc87086336643b6b616df6efdfac796b Mon Sep 17 00:00:00 2001 From: Treeki Date: Thu, 3 Mar 2011 04:53:56 +0100 Subject: working (but not 100% tested) model and texture writing. a few other fixes, etc --- NW4RTools/OutputStream.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'NW4RTools/OutputStream.cs') 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); } } -- cgit v1.2.3