summaryrefslogtreecommitdiff
path: root/NW4RTools/OutputStream.cs
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2011-03-03 04:53:56 +0100
committerTreeki <treeki@gmail.com>2011-03-03 04:53:56 +0100
commitab340fe4dc87086336643b6b616df6efdfac796b (patch)
treeaa01265000e80c8348631f3ae67cc6ded16d90bb /NW4RTools/OutputStream.cs
parent6b14bc71cb699b72ca6cf164b7b800add414dec6 (diff)
downloadnw4rtools-ab340fe4dc87086336643b6b616df6efdfac796b.tar.gz
nw4rtools-ab340fe4dc87086336643b6b616df6efdfac796b.zip
working (but not 100% tested) model and texture writing. a few other fixes, etc
Diffstat (limited to 'NW4RTools/OutputStream.cs')
-rw-r--r--NW4RTools/OutputStream.cs30
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);
}
}