internal Struct1(BinaryReaderEx br) { Unk00 = br.ReadSingle(); Unk04 = br.ReadSingle(); Unk08 = br.ReadSingle(); Unk0C = br.ReadByte(); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); }
internal override void Read(BinaryReaderEx br) { br.BigEndian = true; br.AssertASCII("BND3"); Version = br.ReadASCII(8); br.AssertByte(0xE4); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); int fileCount = br.AssertInt32(1); br.AssertInt32(0); br.AssertInt32(0); br.AssertInt32(0); br.AssertByte(0xC0); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); int compressedSize = br.ReadInt32(); int dataOffset = br.ReadInt32(); br.AssertInt32(0); int nameOffset = br.ReadInt32(); int uncompressedSize = br.ReadInt32(); Name = br.GetShiftJIS(nameOffset); br.Position = dataOffset; Data = Util.ReadZlib(br, compressedSize); }
internal HKXClassName(BinaryReaderEx br) { Signature = br.ReadUInt32(); br.AssertByte(0x09); // Seems random but ok SectionOffset = (uint)br.Position; ClassName = br.ReadASCII(); }
private long[] ReadStateGroup(BinaryReaderEx br, bool longFormat, long dataStart, long stateSize) { long statesOffset = ReadVarint(br, longFormat); long stateCount = ReadVarint(br, longFormat); AssertVarint(br, longFormat, statesOffset); var stateOffsets = new long[stateCount]; for (int i = 0; i < stateCount; i++) { stateOffsets[i] = statesOffset + i * stateSize; } // Every state group with more than one state has a dummy state after the end // that's identical to the first state, for some reason if (stateCount > 1) { byte[] state0Bytes = br.GetBytes(dataStart + statesOffset, (int)stateSize); br.StepIn(dataStart + statesOffset + stateSize * stateCount); { for (int i = 0; i < stateSize; i++) { br.AssertByte(state0Bytes[i]); } } br.StepOut(); } return(stateOffsets); }
public static string ReadLuaString(BinaryReaderEx br, LuaVersion version, bool sizeminusone = true) { ulong length; if (version == LuaVersion.Lua53Smash) { length = br.ReadByte(); if (!sizeminusone) { length++; } } else { length = br.ReadUInt64(); } if (length > 0) { string ret; if (version == LuaVersion.Lua50) { ret = br.ReadShiftJIS((int)length - 1); } else { ret = br.ReadUTF8((int)length - 1); } if (version != LuaVersion.Lua53Smash) { br.AssertByte(0); // Eat null terminator } return(ret); } return(null); }
internal BDF4(BinaryReaderEx br) { br.AssertASCII("BDF4"); Flag1 = br.ReadBoolean(); Flag2 = br.ReadBoolean(); br.AssertByte(0); br.AssertByte(0); BigEndian = br.AssertInt32(0x00010000, 0x00000100) == 0x00000100; br.BigEndian = BigEndian; br.AssertInt32(0); // I thought this was data start, but it's 0x40 in ds2 network test gamedata.bdt, so I don't know Unk1 = br.AssertInt64(0x30, 0x40); Timestamp = br.ReadFixStr(8); br.AssertInt64(0); br.AssertInt64(0); }
internal Mesh(BinaryReaderEx br) { MaterialIndex = br.ReadByte(); Unk01 = br.AssertByte(0, 1, 2); VertexCount = br.ReadInt16(); IndexCount = br.ReadInt32(); StartVertex = br.ReadInt32(); StartIndex = br.ReadInt32(); }
internal Mesh(BinaryReaderEx br, int dataStart, int version) { VertexFormat = br.AssertByte(0, 1, 2); MaterialIndex = br.ReadByte(); Unk02 = br.ReadBoolean(); Unk03 = br.ReadBoolean(); ushort vertexIndexCount = br.ReadUInt16(); Unk08 = br.ReadInt16(); BoneIndices = br.ReadInt16s(28); int vertexIndicesSize = br.ReadInt32(); int vertexIndicesOffset = br.ReadInt32(); int bufferSize = br.ReadInt32(); int bufferOffset = br.ReadInt32(); if (VertexFormat == 2) { UnkFormat2 = br.ReadInt32s(0x20); } VertexIndices = br.GetUInt16s(dataStart + vertexIndicesOffset, vertexIndexCount); br.StepIn(dataStart + bufferOffset); { int vertexSize = 0; if (version == 0x40001) { if (VertexFormat == 0) { vertexSize = 0x40; } else if (VertexFormat == 1) { vertexSize = 0x54; } else if (VertexFormat == 2) { vertexSize = 0x3C; } } else if (version == 0x40002) { if (VertexFormat == 0) { vertexSize = 0x28; } } int vertexCount = bufferSize / vertexSize; Vertices = new List <Vertex>(vertexCount); for (int i = 0; i < vertexCount; i++) { Vertices.Add(new Vertex(br, version, VertexFormat)); } } br.StepOut(); }
public FileHeader(BinaryReaderEx br, bool unicode, Binder.Format format) { Flags = br.ReadEnum8 <Binder.FileFlags>(); br.AssertByte(0); br.AssertByte(0); br.AssertByte(0); br.AssertInt32(-1); CompressedSize = br.ReadInt64(); if (Binder.HasUncompressedSize(format)) { UncompressedSize = br.ReadInt64(); } if (Binder.HasLongOffsets(format)) { Offset = br.ReadInt64(); } else { Offset = br.ReadUInt32(); } if (Binder.HasID(format)) { ID = br.ReadInt32(); } else { ID = -1; } uint nameOffset = br.ReadUInt32(); if (unicode) { Name = br.GetUTF16(nameOffset); } else { Name = br.GetShiftJIS(nameOffset); } }
public Header(BinaryReaderEx br) { br.ReadUInt32(); // Magic Version = br.ReadByte(); if (Version == 0x50) { LuaVersion = LuaVersion.Lua50; } else if (Version == 0x51) { byte format = br.AssertByte(0x0E); // HKS LuaVersion = LuaVersion.Lua51HKS; } else if (Version == 0x53) { LuaVersion = LuaVersion.Lua53Smash; br.ReadBytes(7); //unk } if (LuaVersion == LuaVersion.Lua53Smash) { Endianess = 0; } else { Endianess = br.ReadByte(); } IntSize = br.ReadByte(); LongSize = br.ReadByte(); InstructionSize = br.ReadByte(); if (LuaVersion == LuaVersion.Lua50) { OpSize = br.ReadByte(); ASize = br.ReadByte(); BSize = br.ReadByte(); CSize = br.ReadByte(); } LuaNumberSize = br.ReadByte(); if (LuaVersion == LuaVersion.Lua53Smash) { FloatSize = br.ReadByte(); } if (LuaVersion == LuaVersion.Lua50) { br.ReadDouble(); // test number } else if (LuaVersion == LuaVersion.Lua53Smash) { br.ReadUInt64(); // test int br.ReadSingle(); // test number } else { br.ReadByte(); // Isintegral } }
internal override void Read(BinaryReaderEx br) { br.BigEndian = false; br.AssertASCII("EVD\0"); br.AssertByte(0); br.AssertByte(0xFF); br.AssertByte(1); br.AssertByte(0xFF); br.AssertInt32(0xCD); br.ReadInt32(); // File size Offsets offsets; long eventCount = br.ReadInt64(); offsets.Events = br.ReadInt64(); br.ReadInt64(); // Command count offsets.Commands = br.ReadInt64(); br.AssertInt64(0); br.ReadInt64(); // Unused offset br.ReadInt64(); // Event layer count offsets.EventLayers = br.ReadInt64(); br.ReadInt64(); // Parameter count offsets.Parameters = br.ReadInt64(); long linkedFileCount = br.ReadInt64(); offsets.LinkedFiles = br.ReadInt64(); br.ReadInt64(); // Arguments length offsets.Arguments = br.ReadInt64(); long stringLength = br.ReadInt64(); offsets.Strings = br.ReadInt64(); br.Position = offsets.Events; Events = new List <Event>((int)eventCount); for (int i = 0; i < eventCount; i++) { Events.Add(new Event(br, offsets)); } LinkedFileOffsets = new List <long>(br.GetInt64s(offsets.LinkedFiles, (int)linkedFileCount)); Strings = br.GetBytes(offsets.Strings, (int)stringLength); }
internal void AssertValue(BinaryReaderEx br) { switch (Type) { case ParamType.aob: var assertAob = (byte[])ValueToAssert; for (int i = 0; i < AobLength; i++) { br.AssertByte(assertAob[i]); } break; case ParamType.b: br.AssertBoolean((bool)ValueToAssert); break; case ParamType.u8: case ParamType.x8: br.AssertByte((byte)ValueToAssert); break; case ParamType.s8: br.AssertSByte((sbyte)ValueToAssert); break; case ParamType.u16: case ParamType.x16: br.AssertUInt16((ushort)ValueToAssert); break; case ParamType.s16: br.AssertInt16((short)ValueToAssert); break; case ParamType.u32: case ParamType.x32: br.AssertUInt32((uint)ValueToAssert); break; case ParamType.s32: br.AssertInt32((int)ValueToAssert); break; case ParamType.u64: case ParamType.x64: br.AssertUInt64((ulong)ValueToAssert); break; case ParamType.s64: br.AssertInt64((long)ValueToAssert); break; case ParamType.f32: br.AssertSingle((float)ValueToAssert); break; case ParamType.f64: br.AssertDouble((double)ValueToAssert); break; default: throw new Exception($"Invalid ParamTemplate ParamType: {Type.ToString()}"); } }
internal BHF4(BinaryReaderEx br) { br.AssertASCII("BHF4"); Flag1 = br.ReadBoolean(); Flag2 = br.ReadBoolean(); br.AssertByte(0); br.AssertByte(0); BigEndian = br.AssertInt32(0x00010000, 0x00000100) == 0x00000100; br.BigEndian = BigEndian; int fileCount = br.ReadInt32(); // File headers start br.AssertInt64(0x40); Timestamp = br.ReadFixStr(8); long fileHeaderSize = br.ReadInt64(); // Would be data start in BND4 br.AssertInt64(0); Unicode = br.ReadBoolean(); Format = br.ReadEnum8 <Binder.Format>(); Extended = br.AssertByte(0, 4); br.AssertByte(0); if (fileHeaderSize != Binder.FileHeaderSize(Format)) { throw new FormatException($"File header size 0x{fileHeaderSize} unexpected for format {Format}"); } br.AssertInt32(0); long hashGroupsOffset = br.ReadInt64(); FileHeaders = new List <FileHeader>(fileCount); for (int i = 0; i < fileCount; i++) { FileHeaders.Add(new FileHeader(br, Unicode, Format)); } }
internal override void Read(BinaryReaderEx br) { br.BigEndian = false; br.AssertByte(0x00); br.AssertByte(0x80); br.AssertByte(0x04); br.AssertByte(0x1E); int fileCount = br.ReadInt32(); for (int i = 0; i < 0x38; i++) { br.AssertByte(0); } Files = new List <File>(fileCount); for (int i = 0; i < fileCount; i++) { Files.Add(new File(br)); } }
/// <summary> /// Reads BND0 data from a BinaryReaderEx. /// </summary> protected override void Read(BinaryReaderEx br) { br.BigEndian = false; br.AssertASCII("BND\0"); // File size in non-lite format Lite = br.GetInt32(0xC) == 0; int fileSize, fileCount; if (Lite) { fileSize = br.ReadInt32(); fileCount = br.ReadInt32(); br.AssertInt32(0); } else { br.AssertInt32(0xF7FF); br.AssertInt32(0xD3); fileSize = br.ReadInt32(); fileCount = br.ReadInt32(); br.AssertInt32(0); Flag1 = br.AssertByte(0, 0x20); Flag2 = br.AssertByte(0, 0x08); br.AssertByte(3); br.AssertByte(0); br.AssertInt32(0); br.AssertInt32(0); } Files = new List <File>(fileCount); for (int i = 0; i < fileCount; i++) { Files.Add(new File(br, Lite)); } }
protected override void Read(BinaryReaderEx br) { br.BigEndian = false; br.VarintLong = false; br.AssertASCII("TAE "); bool isBigEndian = br.AssertByte(0, 1) == 1; br.BigEndian = isBigEndian; br.AssertByte(0); br.AssertByte(0); bool is64Bit = br.AssertByte(0, 0xFF) == 0xFF; br.VarintLong = is64Bit; // 0x1000B: DeS, DS1(R) // 0x1000C: DS2, DS2 SOTFS, BB, DS3 // 0x1000D: SDT int version = br.AssertInt32(0x1000B, 0x1000C, 0x1000D); if (version == 0x1000B && !is64Bit) { Format = TAEFormat.DS1; } else if (version == 0x1000C && !is64Bit) { throw new NotImplementedException("Dark Souls II 32-Bit original release not supported. Only Scholar of the First Sin."); } else if (version == 0x1000C && is64Bit) { Format = TAEFormat.DS3; } else if (version == 0x1000D) { Format = TAEFormat.SDT; } else { throw new System.IO.InvalidDataException("Invalid combination of TAE header values: " + $"IsBigEndian={isBigEndian}, Is64Bit={is64Bit}, Version={version}"); } br.ReadInt32(); // File size br.AssertVarint(0x40); br.AssertVarint(1); br.AssertVarint(0x50); if (is64Bit) { br.AssertVarint(0x80); } else { br.AssertVarint(0x70); } if (Format == TAEFormat.DS1) { br.AssertInt16(2); br.AssertInt16(1); } else { EventBank = br.ReadVarint(); } br.AssertVarint(0); if (Format == TAEFormat.DS1) { br.AssertInt64(0); br.AssertInt64(0); br.AssertInt64(0); } Flags = br.ReadBytes(8); var unkFlagA = br.ReadBoolean(); var unkFlagB = br.ReadBoolean(); if (!unkFlagA && unkFlagB) { Format = TAEFormat.SOTFS; } else if ((unkFlagA && unkFlagB) || (!unkFlagA && !unkFlagB)) { throw new System.IO.InvalidDataException("Invalid unknown flags at 0x48."); } for (int i = 0; i < 6; i++) { br.AssertByte(0); } ID = br.ReadInt32(); int animCount = br.ReadInt32(); long animsOffset = br.ReadVarint(); br.ReadVarint(); // Anim groups offset br.AssertVarint(Format == TAEFormat.DS1 ? 0x90 : 0xA0); br.AssertVarint(animCount); br.ReadVarint(); // First anim offset if (Format == TAEFormat.DS1) { br.AssertInt32(0); } br.AssertVarint(1); br.AssertVarint(Format == TAEFormat.DS1 ? 0x80 : 0x90); if (Format == TAEFormat.DS1) { br.AssertInt64(0); } br.AssertInt32(ID); br.AssertInt32(ID); br.AssertVarint(0x50); br.AssertInt64(0); br.AssertVarint(Format == TAEFormat.DS1 ? 0x98 : 0xB0); long skeletonNameOffset = br.ReadVarint(); long sibNameOffset = br.ReadVarint(); if (Format != TAEFormat.SOTFS) { br.AssertVarint(0); br.AssertVarint(0); } if (Format != TAEFormat.SOTFS) { SkeletonName = br.GetUTF16(skeletonNameOffset); SibName = br.GetUTF16(sibNameOffset); } br.StepIn(animsOffset); { Animations = new List <Animation>(animCount); bool previousAnimNeedsParamGen = false; long previousAnimParamStart = 0; for (int i = 0; i < animCount; i++) { Animations.Add(new Animation(br, Format, out bool lastEventNeedsParamGen, out long animFileOffset, out long lastEventParamOffset)); if (previousAnimNeedsParamGen) { br.StepIn(previousAnimParamStart); Animations[i - 1].Events[Animations[i - 1].Events.Count - 1].ReadParameters(br, (int)(animFileOffset - previousAnimParamStart)); br.StepOut(); } previousAnimNeedsParamGen = lastEventNeedsParamGen; previousAnimParamStart = lastEventParamOffset; } // Read from very last anim's very last event's parameters offset to end of file lul if (previousAnimNeedsParamGen) { br.StepIn(previousAnimParamStart); Animations[Animations.Count - 1].Events[Animations[Animations.Count - 1].Events.Count - 1].ReadParameters(br, (int)(br.Length - previousAnimParamStart)); br.StepOut(); } } br.StepOut(); // Don't bother reading anim groups. }
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); }
internal HKXSection(BinaryReaderEx br, HKXVariation variation) { SectionTag = br.ReadFixStr(19); br.AssertByte(0xFF); var AbsoluteDataStart = br.ReadUInt32(); var LocalFixupsOffset = br.ReadUInt32(); var GlobalFixupsOffset = br.ReadUInt32(); var VirtualFixupsOffset = br.ReadUInt32(); var ExportsOffset = br.ReadUInt32(); var ImportsOffset = br.ReadUInt32(); var EndOffset = br.ReadUInt32(); // Read Data br.StepIn(AbsoluteDataStart); SectionData = br.ReadBytes((int)LocalFixupsOffset); br.StepOut(); // Local fixups LocalFixups = new List <LocalFixup>(); br.StepIn(AbsoluteDataStart + LocalFixupsOffset); for (int i = 0; i < (GlobalFixupsOffset - LocalFixupsOffset) / 8; i++) { if (br.ReadUInt32() != 0xFFFFFFFF) { br.Position -= 4; var f = new LocalFixup(br); _localMap.Add(f.Src, f); LocalFixups.Add(f); } } br.StepOut(); // Global fixups GlobalFixups = new List <GlobalFixup>(); br.StepIn(AbsoluteDataStart + GlobalFixupsOffset); for (int i = 0; i < (VirtualFixupsOffset - GlobalFixupsOffset) / 12; i++) { if (br.ReadUInt32() != 0xFFFFFFFF) { br.Position -= 4; var f = new GlobalFixup(br); _globalMap.Add(f.Src, f); GlobalFixups.Add(f); } } br.StepOut(); // Virtual fixups VirtualFixups = new List <VirtualFixup>(); br.StepIn(AbsoluteDataStart + VirtualFixupsOffset); for (int i = 0; i < (ExportsOffset - VirtualFixupsOffset) / 12; i++) { if (br.ReadUInt32() != 0xFFFFFFFF) { br.Position -= 4; var f = new VirtualFixup(br); _virtualMap.Add(f.Src, f); VirtualFixups.Add(f); } } br.StepOut(); if (variation == HKXVariation.HKXBloodBorne || variation == HKXVariation.HKXDS3) { br.AssertUInt32(0xFFFFFFFF); br.AssertUInt32(0xFFFFFFFF); br.AssertUInt32(0xFFFFFFFF); br.AssertUInt32(0xFFFFFFFF); } }