diff --git a/PKGTool/Dread/FileFormats/PKG.cs b/PKGTool/Dread/FileFormats/PKG.cs index 97a9334..2c99ceb 100644 --- a/PKGTool/Dread/FileFormats/PKG.cs +++ b/PKGTool/Dread/FileFormats/PKG.cs @@ -54,7 +54,7 @@ namespace Dread.FileFormats List IDs = new List(); List Offsets = new List(); - var reader = new BinaryReader(stream); + var reader = new BinaryReaderLE(stream); Int32 header_size = reader.ReadInt32(); Int32 data_section_size = reader.ReadInt32(); Int32 file_count = reader.ReadInt32(); @@ -95,7 +95,7 @@ namespace Dread.FileFormats Int32 i, header_size, data_section_start, data_section_size; Int32[,] offsets = GenerateFileOffsets(); - var writer = new BinaryWriter(stream); + var writer = new BinaryWriterLE(stream); stream.Position += 8; writer.Write(Files.Count); for(i=0;i base.BaseStream; + + public override void Close() + { + base.Close(); + } + + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + public override int PeekChar() + { + return base.PeekChar(); + } + + public override int Read() + { + return base.Read(); + } + + public override int Read(char[] buffer, int index, int count) + { + return base.Read(buffer, index, count); + } + + public override int Read(byte[] buffer, int index, int count) + { + return base.Read(buffer, index, count); + } + + public override bool ReadBoolean() + { + return base.ReadBoolean(); + } + + public override byte[] ReadBytes(int count) + { + return base.ReadBytes(count); + } + + public override char ReadChar() + { + return (char)ReadByte(); + } + + public char ReadWChar() + { + return Encoding.Unicode.GetString(ReadBytes(2)).First(); + } + + public override char[] ReadChars(int count) + { + String str = ""; + for (int i = 0; i < count; i++) str += ReadChar(); + return str.ToCharArray(); + } + + public char[] ReadWChars(int count) + { + String str = ""; + for (int i = 0; i < count; i++) str += ReadWChar(); + return str.ToCharArray(); + } + + public override decimal ReadDecimal() + { + throw new NotImplementedException(); + } + + public override sbyte ReadSByte() + { + return base.ReadSByte(); + } + + public override short ReadInt16() + { + return base.ReadInt16(); + } + + public override int ReadInt32() + { + return base.ReadInt32(); + } + + public override long ReadInt64() + { + return base.ReadInt64(); + } + + public override byte ReadByte() + { + return base.ReadByte(); + } + + public override ushort ReadUInt16() + { + return base.ReadUInt16(); + } + + public override uint ReadUInt32() + { + return base.ReadUInt32(); + } + + public override ulong ReadUInt64() + { + return base.ReadUInt64(); + } + + public override float ReadSingle() + { + return base.ReadSingle(); + } + + public override double ReadDouble() + { + return base.ReadDouble(); + } + + public override string ReadString() + { + char c = '\0'; + String str = ""; + while ((c = ReadChar()) != 0) str += c; + return str; + } + + public string ReadWString() + { + char c = '\0'; + String str = ""; + while ((c = ReadWChar()) != 0) str += c; + return str; + } + + public override string ToString() + { + return base.ToString(); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + } + + protected override void FillBuffer(int numBytes) + { + base.FillBuffer(numBytes); + } + } +} diff --git a/PKGTool/Misc/BinaryWriterLE.cs b/PKGTool/Misc/BinaryWriterLE.cs new file mode 100644 index 0000000..6aac1b1 --- /dev/null +++ b/PKGTool/Misc/BinaryWriterLE.cs @@ -0,0 +1,142 @@ +using System.Linq; +using System.Text; + +namespace System.IO +{ + public class BinaryWriterLE : BinaryWriter + { + public BinaryWriterLE(Stream input) : base(input) + { + } + + public BinaryWriterLE(Stream input, Encoding encoding) : base(input, encoding) + { + } + + public BinaryWriterLE(Stream input, Encoding encoding, bool leaveOpen) : base(input, encoding, leaveOpen) + { + } + + public override Stream BaseStream => base.BaseStream; + + public override void Close() + { + base.Close(); + } + + public override bool Equals(object obj) + { + return base.Equals(obj); + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + + public override void Write(Char c) + { + Write(c, false); + } + + public void Write(Char c, bool isUnicode) + { + if(isUnicode) + Write((UInt16)c); + else + Write((Byte)c); + } + + public override void Write(Char[] ch) + { + Write(ch, false); + } + + public void Write(Char[] ch, bool isUnicode) + { + for (int i = 0; i < ch.Length; i++) + { + if (isUnicode) + Write(i < ch.Length ? ch[i] : (char)0, true); + else + Write(i < ch.Length ? ch[i] : (char)0); + } + } + + public override void Write(decimal d) + { + base.Write(d); + } + + public override void Write(SByte v) + { + base.Write(v); + } + + public override void Write(Int16 v) + { + base.Write(v); + } + + public override void Write(Int32 v) + { + base.Write(v); + } + + public override void Write(Int64 v) + { + base.Write(v); + } + + public override void Write(UInt16 v) + { + Write(v); + } + + public override void Write(UInt32 v) + { + Write(v); + } + + public override void Write(UInt64 v) + { + Write(v); + } + + public override void Write(Single v) + { + base.Write(v); + } + + public override void Write(Double v) + { + base.Write(v); + } + + public override void Write(String str) + { + Write(str, false); + } + + public void Write(String str, bool isUnicode) + { + foreach (var c in str) + { + if (isUnicode) + Write(c, true); + else + Write(c); + } + } + + public override string ToString() + { + return base.ToString(); + } + + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + } + } +}