private void WriteArrayBase <T>(BinaryWriterEx bw, IList <T> l, Action <T> perElement, bool pad = false) { uint size = (l != null) ? (uint)l.Count : 0; bw.WriteUInt64(0); bw.WriteUInt32(size); bw.WriteUInt32(size | (((uint)0x80) << 24)); if (size > 0) { LocalFixup lfu = new LocalFixup(); lfu.Src = (uint)bw.Position - 16; _localFixups.Add(lfu); _localWriteQueues[_currWriteQueue].Enqueue(() => { lfu.Dst = (uint)bw.Position; // This ensures any writes the array elements may have are top priority PushWriteQueue(); for (int i = 0; i < size; i++) { perElement.Invoke(l[i]); } PopWriteQueue(bw); }); if (pad) { //PushWriteQueue(); _localWriteQueues[_currWriteQueue].Enqueue(() => { bw.Pad(16); }); //PopWriteQueue(bw); } } }
public void WriteStringPointer(BinaryWriterEx bw, string d) { bw.WriteUInt64(0); if (d != null) { var lfu = new LocalFixup(); lfu.Src = (uint)bw.Position - 8; _localFixups.Add(lfu); _localWriteQueues[_currWriteQueue].Enqueue(() => { lfu.Dst = (uint)bw.Position; bw.WriteASCII(d, true); bw.Pad(16); }); } }
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); } }