// Only use for a classnames structure after preliminary deserialization internal HKXClassNames ReadClassnames(PackFileDeserializer hkx) { BinaryReaderEx br = new BinaryReaderEx(false, SectionData); var classnames = new HKXClassNames(); classnames.Read(hkx, this, br, HKX.HKXVariation.HKXDS3); return(classnames); }
public IHavokObject Deserialize(BinaryReaderEx br) { br.BigEndian = false; // Peek ahead and read the endian byte br.StepIn(0x11); br.BigEndian = (br.ReadByte() == 0x0) ? true : false; br.StepOut(); // Read header _header = new HKXHeader(); _header.Magic0 = br.AssertUInt32(0x57E0E057); _header.Magic1 = br.AssertUInt32(0x10C0C010); //Header.UserTag = br.AssertInt32(0); _header.UserTag = br.ReadInt32(); _header.Version = br.AssertInt32(0x05, 0x08, 0x0B); if (_header.Version == 0x05) { _variation = HKXVariation.HKXDeS; } else if (_header.Version == 0x08) { _variation = HKXVariation.HKXDS1; } else { _variation = HKXVariation.HKXDS3; } _header.PointerSize = br.AssertByte(4, 8); _header.Endian = br.AssertByte(0, 1); _header.PaddingOption = br.AssertByte(0, 1); _header.BaseClass = br.AssertByte(1); // ? _header.SectionCount = br.AssertInt32(3); // Always 3 sections pretty sure _header.ContentsSectionIndex = br.ReadInt32(); _header.ContentsSectionOffset = br.ReadInt32(); _header.ContentsClassNameSectionIndex = br.ReadInt32(); _header.ContentsClassNameSectionOffset = br.ReadInt32(); _header.ContentsVersionString = br.ReadFixStr(16); // Should be hk_2014.1.0-r1 _header.Flags = br.ReadInt32(); // Later versions of Havok have an extended header if (_header.Version >= 0x0B) { _header.Unk3C = br.ReadInt16(); _header.SectionOffset = br.ReadInt16(); if (_header.SectionOffset > 0) { _header.Unk40 = br.ReadUInt32(); _header.Unk44 = br.ReadUInt32(); _header.Unk48 = br.ReadUInt32(); _header.Unk4C = br.ReadUInt32(); } // Read the 3 sections in the file br.Position = _header.SectionOffset + 0x40; } else { // Just padding br.AssertUInt32(0xFFFFFFFF); } _classSection = new HKXSection(br, _variation); _classSection.SectionID = 0; _typeSection = new HKXSection(br, _variation); _typeSection.SectionID = 1; _dataSection = new HKXSection(br, _variation); _dataSection.SectionID = 2; // Process the class names _classnames = _classSection.ReadClassnames(this); // Deserialize the objects _deserializedObjects = new Dictionary <uint, IHavokObject>(); BinaryReaderEx br2 = new BinaryReaderEx((_header.Endian == 0) ? true : false, _dataSection.SectionData); var root = ConstructVirtualClass(br2, 0); return(root); }