public void Int32ReadWrite()
        {
            Int32 value;
            Int32 result;

            value = 20;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);


            //Multiple bytes

            value = 300000000;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);

            //Negative Values

            value = -30;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);

            //Max Values

            value = 2147483647;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);

            //Min Values

            value = -2147483648;

            ResetPosition();
            _writer.WriteInt32(value);
            ResetPosition();
            result = _reader.ReadInt32();

            Assert.AreEqual(value, result);
        }
Exemplo n.º 2
0
        public void WriteBLMAP(string FilePath)
        {
            FileName = FilePath;
            BigEndianWriter Writer = new BigEndianWriter(File.Open(FilePath, FileMode.Create));
            BLMAP           BLMAP  = lmapComponent1.ReturnData();

            Writer.WriteChars("LMAP".ToCharArray(), 0, 4);
            Writer.WriteUInt32(0);
            Writer.WriteUInt32(BLMAP.Unknown1);
            Writer.WriteUInt32(BLMAP.Unknown2);
            Writer.WriteUInt16(Convert.ToUInt16(treeView1.Nodes[0].Nodes[1].Nodes.Count));
            Writer.WriteUInt16(BLMAP.Unknown3);
            Writer.WriteUInt32(BLMAP.Unknown4);
            Writer.WriteUInt32(BLMAP.Unknown5);
            Writer.WriteUInt32(BLMAP.Unknown6);
            int FileSize = 0x20;

            for (int i = 0; i < listLTEX.Count; i++)
            {
                BLMAPLTEX LTEX = ltexComponent1.ReturnData();
                LTEX.Entries           = ReturnLTEX();
                listLTEX[SelectedNode] = LTEX;

                FileSize += 0x3C + listLTEX[i].Entries.Count * 8;
                Writer.WriteChars("LTEX".ToCharArray(), 0, 4);
                Writer.WriteInt32(0x3C + listLTEX[i].Entries.Count * 8);
                Writer.WriteUInt32(listLTEX[i].Padding);
                Writer.WriteUInt32(listLTEX[i].Unknown);
                Writer.WriteUInt16(Convert.ToUInt16(listLTEX[i].Entries.Count));
                Writer.WriteUInt16(listLTEX[i].Unknown1);
                Writer.WriteChars(listLTEX[i].Texture.ToCharArray(), 0, 4);
                Writer.WriteUInt32(listLTEX[i].Unknown2);
                Writer.WriteUInt32(listLTEX[i].Unknown3);
                Writer.WriteUInt32(listLTEX[i].Unknown4);
                Writer.WriteUInt32(listLTEX[i].Unknown5);
                Writer.WriteUInt32(listLTEX[i].Unknown6);
                Writer.WriteUInt32(listLTEX[i].Unknown7);
                Writer.WriteUInt32(listLTEX[i].Unknown8);
                Writer.WriteUInt32(listLTEX[i].Unknown9);
                Writer.WriteInt32(listLTEX[i].Entries.Count * 8);
                for (int j = 0; j < listLTEX[i].Entries.Count; j++)
                {
                    Writer.WriteSingle(listLTEX[i].Entries[j].Unknown1);
                    Writer.WriteUInt32(listLTEX[i].Entries[j].Unknown2);
                }
            }
            Writer.BaseStream.Position = 4;
            Writer.WriteInt32(FileSize);
            Writer.Close();
            treeView1.Nodes[0].Text = Path.GetFileName(FilePath);
        }
Exemplo n.º 3
0
        public VHDFooter(byte[] buffer)
        {
            Cookie             = ByteReader.ReadAnsiString(buffer, 0x00, 8);
            Features           = BigEndianConverter.ToUInt32(buffer, 0x08);
            FileFormatVersion  = BigEndianConverter.ToUInt32(buffer, 0x0C);
            DataOffset         = BigEndianConverter.ToUInt64(buffer, 0x10);
            TimeStamp          = BigEndianConverter.ToUInt32(buffer, 0x18);
            CreatorApplication = ByteReader.ReadAnsiString(buffer, 0x1C, 4);
            CreatorVersion     = BigEndianConverter.ToUInt32(buffer, 0x20);
            CreatorHostOS      = BigEndianConverter.ToUInt32(buffer, 0x24);
            OriginalSize       = BigEndianConverter.ToUInt64(buffer, 0x28);
            CurrentSize        = BigEndianConverter.ToUInt64(buffer, 0x30);
            DiskGeometry       = BigEndianConverter.ToUInt32(buffer, 0x38);
            DiskType           = (VirtualHardDiskType)BigEndianConverter.ToUInt32(buffer, 0x3C);
            uint checksum = BigEndianConverter.ToUInt32(buffer, 0x40);

            UniqueId   = BigEndianConverter.ToGuid(buffer, 0x44);
            SavedState = ByteReader.ReadByte(buffer, 0x54);

            byte[] temp = (byte[])buffer.Clone();
            BigEndianWriter.WriteInt32(temp, 0x40, 0);
            uint expectedChecksum = CalculateChecksum(temp);

            m_isValid = String.Equals(Cookie, VirtualHardDiskCookie) && (checksum == expectedChecksum) && (FileFormatVersion == 0x00010000);
        }
        public DynamicDiskHeader(byte[] buffer)
        {
            Cookie          = ByteReader.ReadAnsiString(buffer, 0x00, 8);
            DataOffset      = BigEndianConverter.ToUInt64(buffer, 0x08);
            TableOffset     = BigEndianConverter.ToUInt64(buffer, 0x10);
            HeaderVersion   = BigEndianConverter.ToUInt32(buffer, 0x18);
            MaxTableEntries = BigEndianConverter.ToUInt32(buffer, 0x1C);
            BlockSize       = BigEndianConverter.ToUInt32(buffer, 0x20);
            uint checksum = BigEndianConverter.ToUInt32(buffer, 0x24);

            ParentUniqueID      = BigEndianConverter.ToGuid(buffer, 0x28);
            ParentTimeStamp     = BigEndianConverter.ToUInt32(buffer, 0x38);
            Reserved            = BigEndianConverter.ToUInt32(buffer, 0x3C);
            ParentUnicodeName   = ByteReader.ReadUTF16String(buffer, 0x40, 256).TrimEnd('\0');
            ParentLocatorEntry1 = new ParentLocatorEntry(buffer, 0x240);
            ParentLocatorEntry2 = new ParentLocatorEntry(buffer, 0x258);
            ParentLocatorEntry3 = new ParentLocatorEntry(buffer, 0x270);
            ParentLocatorEntry4 = new ParentLocatorEntry(buffer, 0x288);
            ParentLocatorEntry5 = new ParentLocatorEntry(buffer, 0x2A0);
            ParentLocatorEntry6 = new ParentLocatorEntry(buffer, 0x2B8);
            ParentLocatorEntry7 = new ParentLocatorEntry(buffer, 0x2D0);
            ParentLocatorEntry8 = new ParentLocatorEntry(buffer, 0x2E8);

            byte[] temp = (byte[])buffer.Clone();
            BigEndianWriter.WriteInt32(temp, 0x24, 0);
            uint expectedChecksum = VHDFooter.CalculateChecksum(temp);

            m_isValid = String.Equals(Cookie, DynamidDiskHeaderCookie) && (checksum == expectedChecksum) && (HeaderVersion == 0x00010000);
        }
Exemplo n.º 5
0
        private void ExportLTEX_Click(object sender, EventArgs e)
        {
            SaveFileDialog s = new SaveFileDialog();

            s.Filter = "Binary Light Texture (*bltex)|*.bltex";
            if (s.ShowDialog() == DialogResult.OK)
            {
                BLMAPLTEX LTEX = ltexComponent1.ReturnData();
                LTEX.Entries           = ReturnLTEX();
                listLTEX[SelectedNode] = LTEX;

                BigEndianWriter Writer = new BigEndianWriter(File.Open(s.FileName, FileMode.Create));
                Writer.WriteChars("LTEX".ToCharArray(), 0, 4);
                Writer.WriteInt32(0x3C + LTEX.Entries.Count * 8);
                Writer.WriteUInt32(LTEX.Padding);
                Writer.WriteUInt32(LTEX.Unknown);
                Writer.WriteUInt16(Convert.ToUInt16(LTEX.Entries.Count));
                Writer.WriteUInt16(LTEX.Unknown1);
                Writer.WriteChars(LTEX.Texture.ToCharArray(), 0, 4);
                Writer.WriteUInt32(LTEX.Unknown2);
                Writer.WriteUInt32(LTEX.Unknown3);
                Writer.WriteUInt32(LTEX.Unknown4);
                Writer.WriteUInt32(LTEX.Unknown5);
                Writer.WriteUInt32(LTEX.Unknown6);
                Writer.WriteUInt32(LTEX.Unknown7);
                Writer.WriteUInt32(LTEX.Unknown8);
                Writer.WriteUInt32(LTEX.Unknown9);
                Writer.WriteInt32(LTEX.Entries.Count * 8);
                for (int j = 0; j < LTEX.Entries.Count; j++)
                {
                    Writer.WriteSingle(LTEX.Entries[j].Unknown1);
                    Writer.WriteUInt32(LTEX.Entries[j].Unknown2);
                }
                Writer.Close();
            }
        }