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 EventLayer(BinaryReaderEx br, GameType game) { br.AssertInt32(2); Mask = br.ReadUInt32(); if (game == GameType.DS1) { br.AssertInt32(0); br.AssertInt32(-1); br.AssertInt32(1); } else { br.AssertInt64(0); br.AssertInt64(-1); br.AssertInt64(1); } }
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)); } }
private static ESDMetadata InnerReadFromBinary(string binFileName) { var meta = new ESDMetadata(); using (var fileStream = System.IO.File.Open(binFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { var br = new BinaryReaderEx(bigEndian: false, stream: fileStream); br.AssertASCII("ESD_META"); br.AssertInt64(CURRENT_BINARY_VERSION); meta.ESDHash = br.ReadASCII(); int stateGroupCount = br.ReadInt32(); for (int i = 0; i < stateGroupCount; i++) { long stateGroupID = br.ReadInt64(); string stateGroupName = br.ReadShiftJIS(); meta.StateGroupNames.Add(stateGroupID, stateGroupName); meta.StateMetadatas.Add(stateGroupID, new Dictionary <long, StateMetadata>()); int stateCount = br.ReadInt32(); for (int j = 0; j < stateCount; j++) { long stateID = br.ReadInt64(); string stateName = br.ReadShiftJIS(); string stateEntryScript = br.ReadShiftJIS(); string stateExitScript = br.ReadShiftJIS(); string stateWhileScript = br.ReadShiftJIS(); meta.StateMetadatas[stateGroupID].Add(stateID, new StateMetadata() { Name = stateName, EntryScript = stateEntryScript, ExitScript = stateExitScript, WhileScript = stateWhileScript, }); } } int conditionCount = br.ReadInt32(); for (int i = 0; i < conditionCount; i++) { long conditionID = br.ReadInt64(); string conditionName = br.ReadShiftJIS(); string conditionEvaluator = br.ReadShiftJIS(); string conditionPassScript = br.ReadShiftJIS(); meta.ConditionMetadatas.Add(conditionID, new ConditionMetadata() { Name = conditionName, Evaluator = conditionEvaluator, PassScript = conditionPassScript, }); } } return(meta); }
internal Command(BinaryReaderEx br, Offsets offsets) { CommandClass = br.ReadInt32(); CommandIndex = br.ReadInt32(); long argumentsLength = br.ReadInt64(); long argumentsOffset = br.ReadInt64(); long eventLayerOffset = br.ReadInt64(); Arguments = br.GetBytes(offsets.Arguments + argumentsOffset, (int)argumentsLength); if (eventLayerOffset != -1) { br.StepIn(offsets.EventLayers + eventLayerOffset); { br.AssertInt32(2); EventLayer = br.ReadInt32(); br.AssertInt64(0); br.AssertInt64(-1); br.AssertInt64(1); } br.StepOut(); } }
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()}"); } }
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. }