public static HKX Read(byte[] data, HKXVariation variation, bool deserializeObjects = true) { BinaryReaderEx br = new BinaryReaderEx(false, data); HKX file = new HKX(); file.Variation = variation; file.DeserializeObjects = deserializeObjects; br = Util.GetDecompressedBR(br, out file.Compression); file.Read(br); return(file); }
public void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation, uint elementCount) { SectionOffset = (uint)br.Position; Elements = new List <T>(); for (int i = 0; i < elementCount; i++) { var elem = new T(); elem.Read(hkx, section, this, br, variation); Elements.Add(elem); } DataSize = (uint)br.Position - SectionOffset; }
// Should be used on a data section after initial reading for object deserialization internal void ReadDataObjects(HKX hkx, HKXVariation variation, bool deserializeObjects) { BinaryReaderEx br = new BinaryReaderEx((hkx.Header.Endian == 0) ? true : false, SectionData); // Virtual fixup table defines the hkx class instances for (int i = 0; i < VirtualFixups.Count; i++) { var reference = new HKXVirtualReference(); reference.DestSection = hkx.ClassSection; // A bit of an assumption that better hold reference.ClassName = ((HKXClassNames)hkx.ClassSection.Objects[0]).Lookup(VirtualFixups[i].NameOffset); br.Position = VirtualFixups[i].Src; var length = (i + 1 < VirtualFixups.Count) ? VirtualFixups[i + 1].Src - VirtualFixups[i].Src : LocalFixupsOffset - VirtualFixups[i].Src; HKXObject hkobject; if (deserializeObjects) { if (reference.ClassName.ClassName == "fsnpCustomParamCompressedMeshShape") { hkobject = new FSNPCustomParamCompressedMeshShape(); hkobject.Read(hkx, this, br, variation); } else if (reference.ClassName.ClassName == "hknpCompressedMeshShapeData") { hkobject = new HKNPCompressedMeshShapeData(); hkobject.Read(hkx, this, br, variation); } else if (reference.ClassName.ClassName == "hkpStorageExtendedMeshShapeMeshSubpartStorage") { hkobject = new HKPStorageExtendedMeshShapeMeshSubpartStorage(); hkobject.Read(hkx, this, br, variation); } else if (reference.ClassName.ClassName == "hknpPhysicsSystemData") { hkobject = new HKNPPhysicsSystemData(); hkobject.Read(hkx, this, br, variation); } else { hkobject = new HKXGenericObject(); ((HKXGenericObject)hkobject).Read(hkx, this, br, length, variation); } } else { hkobject = new HKXGenericObject(); ((HKXGenericObject)hkobject).Read(hkx, this, br, length, variation); } Objects.Add(hkobject); reference.SourceObject = hkobject; VirtualReferences.Add(reference); } }
public static HKX Read(string path, HKXVariation variation, bool deserializeObjects = true) { using (FileStream stream = File.OpenRead(path)) { BinaryReaderEx br = new BinaryReaderEx(false, stream); HKX file = new HKX(); file.Variation = variation; file.DeserializeObjects = deserializeObjects; br = Util.GetDecompressedBR(br, out file.Compression); file.Read(br); return(file); } }
public void WriteData(BinaryWriterEx bw, HKX hkx, HKXVariation variation) { uint absoluteOffset = (uint)bw.Position; bw.FillUInt32("absoffset" + SectionID, absoluteOffset); foreach (var obj in Objects) { obj.Write(hkx, this, bw, absoluteOffset, variation); } // Local fixups bw.FillUInt32("locoffset" + SectionID, (uint)bw.Position - absoluteOffset); foreach (var loc in LocalReferences) { loc.Write(bw); } while ((bw.Position % 16) != 0) { bw.WriteByte(0xFF); // 16 byte align } // Global fixups bw.FillUInt32("globoffset" + SectionID, (uint)bw.Position - absoluteOffset); foreach (var glob in GlobalReferences) { glob.Write(bw); } while ((bw.Position % 16) != 0) { bw.WriteByte(0xFF); // 16 byte align } // Virtual fixups bw.FillUInt32("virtoffset" + SectionID, (uint)bw.Position - absoluteOffset); foreach (var virt in VirtualReferences) { virt.Write(bw); } while ((bw.Position % 16) != 0) { bw.WriteByte(0xFF); // 16 byte align } bw.FillUInt32("expoffset" + SectionID, (uint)bw.Position - absoluteOffset); bw.FillUInt32("impoffset" + SectionID, (uint)bw.Position - absoluteOffset); bw.FillUInt32("endoffset" + SectionID, (uint)bw.Position - absoluteOffset); }
public void WriteHeader(BinaryWriterEx bw, HKXVariation variation) { bw.WriteFixStr(SectionTag, 19); bw.WriteByte(0xFF); bw.ReserveUInt32("absoffset" + SectionID); bw.ReserveUInt32("locoffset" + SectionID); bw.ReserveUInt32("globoffset" + SectionID); bw.ReserveUInt32("virtoffset" + SectionID); bw.ReserveUInt32("expoffset" + SectionID); bw.ReserveUInt32("impoffset" + SectionID); bw.ReserveUInt32("endoffset" + SectionID); if (variation == HKXVariation.HKXBloodBorne || variation == HKXVariation.HKXDS3) { bw.WriteUInt32(0xFFFFFFFF); bw.WriteUInt32(0xFFFFFFFF); bw.WriteUInt32(0xFFFFFFFF); bw.WriteUInt32(0xFFFFFFFF); } }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { throw new NotImplementedException(); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { SectionOffset = (uint)bw.Position - sectionBaseOffset; DataSize = (uint)bw.Position - sectionBaseOffset - SectionOffset; }
public override void Read(HKX hkx, HKXSection section, HKXObject source, BinaryReaderEx br, HKXVariation variation) { Cost = br.ReadUInt16(); Flags = br.ReadUInt16(); TargetNode = br.ReadUInt32(); }
public override void Read(HKX hkx, HKXSection section, HKXObject source, BinaryReaderEx br, HKXVariation variation) { StartEdgeIndex = br.ReadInt32(); StartUserEdgeIndex = br.ReadInt32(); NumEdges = br.ReadInt16(); NumUserEdges = br.ReadInt16(); ClusterIndex = br.ReadInt16(); br.ReadInt16(); // Padding }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { bw.WriteByte(BBX); bw.WriteByte(BBY); bw.WriteByte(BBZ); bw.WriteByte(IDX0); bw.WriteByte(IDX1); bw.WriteByte(IDX2); }
public override void Read(HKX hkx, HKXSection section, HKXObject source, BinaryReaderEx br, HKXVariation variation) { //AssertPointer(hkx, br); //br.ReadUInt64s(1); // blah Name = new HKCString(hkx, section, source, br, variation); LockTranslation = br.ReadInt32(); if (variation != HKXVariation.HKXDS1) { br.ReadInt32(); // Padding? } }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { // By no means complete but currently quickly extracts most meshes SectionOffset = (uint)br.Position; // vtable stuff AssertPointer(hkx, br); AssertPointer(hkx, br); Vertices = new HKArray <HKVector4>(hkx, section, this, br, variation); if (variation != HKXVariation.HKSDeS) { // Supposed to be 8-bit indices for collision, but doesn't seem to be used much if at all, so implement later AssertPointer(hkx, br); br.ReadUInt64(); } Indices16 = new HKArray <HKUShort>(hkx, section, this, br, variation); // More stuff to implement (seemingly unused) DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { SectionOffset = (uint)bw.Position - sectionBaseOffset; WriteEmptyPointer(hkx, bw); WriteEmptyPointer(hkx, bw); CompressedBVH.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteVector4(BoundingBoxMin); bw.WriteVector4(BoundingBoxMax); bw.WriteUInt32(Unk40); bw.WriteUInt32(Unk44); bw.WriteUInt32(Unk48); bw.WriteUInt32(Unk4C); Chunks.Write(hkx, section, bw, sectionBaseOffset, variation); MeshIndices.Write(hkx, section, bw, sectionBaseOffset, variation); VertexIndices.Write(hkx, section, bw, sectionBaseOffset, variation); SmallVertices.Write(hkx, section, bw, sectionBaseOffset, variation); LargeVertices.Write(hkx, section, bw, sectionBaseOffset, variation); UnkA0.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteUInt64(UnkB0); UnkB8.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteUInt64(UnkC8); DataSize = (uint)bw.Position - sectionBaseOffset - SectionOffset; CompressedBVH.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); Chunks.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); MeshIndices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); VertexIndices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); SmallVertices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); LargeVertices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); UnkA0.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); UnkB8.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); AssertPointer(hkx, br); CompressedBVH = new HKArray <CompressedMeshBVHNode>(hkx, section, this, br, variation); BoundingBoxMin = br.ReadVector4(); BoundingBoxMax = br.ReadVector4(); Unk40 = br.ReadUInt32(); Unk44 = br.ReadUInt32(); Unk48 = br.ReadUInt32(); Unk4C = br.ReadUInt32(); Chunks = new HKArray <CollisionMeshChunk>(hkx, section, this, br, variation); MeshIndices = new HKArray <MeshPrimitive>(hkx, section, this, br, variation); VertexIndices = new HKArray <HKUShort>(hkx, section, this, br, variation); SmallVertices = new HKArray <SmallCompressedVertex>(hkx, section, this, br, variation); LargeVertices = new HKArray <LargeCompressedVertex>(hkx, section, this, br, variation); UnkA0 = new HKArray <HKUInt>(hkx, section, this, br, variation); UnkB0 = br.ReadUInt64(); UnkB8 = new HKArray <UnknownStructure2>(hkx, section, this, br, variation); UnkC8 = br.AssertUInt64(0); DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); AssertPointer(hkx, br); if (variation != HKXVariation.HKXBloodBorne) { AssertPointer(hkx, br); AssertPointer(hkx, br); } Up.X = br.ReadSingle(); Up.Y = br.ReadSingle(); Up.Z = br.ReadSingle(); Up.W = br.ReadSingle(); Forward.X = br.ReadSingle(); Forward.Y = br.ReadSingle(); Forward.Z = br.ReadSingle(); Forward.W = br.ReadSingle(); Duration = br.ReadSingle(); if (variation != HKXVariation.HKXDS1) { br.AssertInt32(0); // probably padding } ReferenceFrameSamples = new HKArray <HKVector4>(hkx, section, this, br, variation); br.Pad(16); // probably DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, HKXObject source, BinaryReaderEx br, HKXVariation variation) { Position = new HKVector4(); Position.Read(hkx, section, source, br, variation); Rotation = new HKVector4(); Rotation.Read(hkx, section, source, br, variation); Scale = new HKVector4(); Scale.Read(hkx, section, source, br, variation); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { SectionOffset = (uint)bw.Position - sectionBaseOffset; WriteEmptyPointer(hkx, bw); WriteEmptyPointer(hkx, bw); Vertices.Write(hkx, section, bw, sectionBaseOffset, variation); if (variation != HKXVariation.HKSDeS) { WriteEmptyPointer(hkx, bw); bw.WriteUInt32(0); bw.WriteUInt32(0x80000000); } Indices16.Write(hkx, section, bw, sectionBaseOffset, variation); // Bunch of empty arrays WriteEmptyPointer(hkx, bw); bw.WriteUInt32(0); bw.WriteUInt32(0x80000000); WriteEmptyPointer(hkx, bw); bw.WriteUInt32(0); bw.WriteUInt32(0x80000000); WriteEmptyPointer(hkx, bw); bw.WriteUInt32(0); bw.WriteUInt32(0x80000000); WriteEmptyPointer(hkx, bw); bw.WriteUInt32(0); bw.WriteUInt32(0x80000000); WriteEmptyPointer(hkx, bw); bw.WriteUInt32(0); bw.WriteUInt32(0x80000000); bw.WriteUInt32(0); bw.WriteUInt32(0); DataSize = (uint)bw.Position - sectionBaseOffset - SectionOffset; Vertices.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); Indices16.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); }
public override void Read(HKX hkx, HKXSection section, HKXObject source, BinaryReaderEx br, HKXVariation variation) { BBX = br.ReadByte(); BBY = br.ReadByte(); BBZ = br.ReadByte(); IDX0 = br.ReadByte(); IDX1 = br.ReadByte(); IDX2 = br.ReadByte(); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; // vtable stuff AssertPointer(hkx, br); AssertPointer(hkx, br); AssertPointer(hkx, br); AssertPointer(hkx, br); Unk10 = br.ReadSingle(); Unk14 = br.ReadSingle(); Unk18 = br.ReadSingle(); Unk1C = br.ReadSingle(); MoppCode = new HKArray <HKByte>(hkx, section, this, br, variation); br.AssertUInt32(0); DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; CompressedTree = new HKArray <StaticAABBNode>(hkx, section, this, br, variation); AABBMin = br.ReadVector4(); AABBMax = br.ReadVector4(); DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Write(HKX hkx, HKXSection section, BinaryWriterEx bw, uint sectionBaseOffset, HKXVariation variation) { SectionOffset = (uint)bw.Position - sectionBaseOffset; WriteEmptyPointer(hkx, bw); WriteEmptyPointer(hkx, bw); WriteEmptyPointer(hkx, bw); WriteEmptyPointer(hkx, bw); bw.WriteSingle(Unk10); bw.WriteSingle(Unk14); bw.WriteSingle(Unk18); bw.WriteSingle(Unk1C); MoppCode.Write(hkx, section, bw, sectionBaseOffset, variation); bw.WriteUInt32(0); DataSize = (uint)bw.Position - sectionBaseOffset - SectionOffset; MoppCode.WriteReferenceData(hkx, section, bw, sectionBaseOffset, variation); }
public override void Read(HKX hkx, HKXSection section, HKXObject source, BinaryReaderEx br, HKXVariation variation) { StartEdgeIndex = br.ReadInt32(); NumEdges = br.ReadInt32(); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); AssertPointer(hkx, br); //br.ReadUInt64s(1); // Name Name = new HKCString(hkx, section, this, br, variation); ParentIndices = new HKArray <HKShort>(hkx, section, this, br, variation); Bones = new HKArray <Bone>(hkx, section, this, br, variation); Transforms = new HKArray <Transform>(hkx, section, this, br, variation); ReferenceFloats = new HKArray <HKFloat>(hkx, section, this, br, variation); br.ReadUInt64s(2); // unused array br.ReadUInt64s(2); // unused array br.ReadUInt64s(2); // unused array br.ReadUInt64s(2); // unused array br.ReadUInt64s(1); // padding DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); AssertPointer(hkx, br); Positions = new HKArray <HKVector4>(hkx, section, this, br, variation); Nodes = new HKArray <CostGraphNode>(hkx, section, this, br, variation); Edges = new HKArray <CostGraphEdge>(hkx, section, this, br, variation); br.ReadUInt64s(2); // unused array br.ReadUInt64s(2); // unused array br.ReadUInt64s(4); // padding DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); if (variation == HKXVariation.HKXBloodBorne) { br.AssertInt32(0); } else { AssertPointer(hkx, br); } AnimationType = br.ReadEnum32 <AnimationType>(); Duration = br.ReadSingle(); TransformTrackCount = br.ReadInt32(); FloatTrackCount = br.ReadInt32(); if (variation == HKXVariation.HKXBloodBorne) { br.Pad(16); } if (variation == HKXVariation.HKXDS1) { br.ReadInt64s(2); // Annotations FrameCount = br.ReadInt32(); BlockCount = br.ReadInt32(); FramesPerBlock = br.ReadInt32(); MaskAndQuantization = br.ReadUInt32(); BlockDuration = br.ReadSingle(); InverseBlockDuration = br.ReadSingle(); FrameDuration = br.ReadSingle(); } else { br.ReadInt64s(3); // Annotations FrameCount = br.ReadInt32(); BlockCount = br.ReadInt32(); FramesPerBlock = br.ReadInt32(); MaskAndQuantization = br.ReadUInt32(); BlockDuration = br.ReadSingle(); InverseBlockDuration = br.ReadSingle(); FrameDuration = br.ReadSingle(); br.ReadUInt32(); // padding? } BlockOffsets = new HKArray <HKUInt>(hkx, section, this, br, variation); FloatBlockOffsets = new HKArray <HKUInt>(hkx, section, this, br, variation); TransformBlockOffsets = new HKArray <HKUInt>(hkx, section, this, br, variation); FloatOffsets = new HKArray <HKUInt>(hkx, section, this, br, variation); Data = new HKArray <HKByte>(hkx, section, this, br, variation); Endian = br.ReadInt32(); DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, HKXObject source, BinaryReaderEx br, HKXVariation variation) { A = br.ReadInt32(); B = br.ReadInt32(); OppositeEdge = br.ReadUInt32(); OppositeFace = br.ReadUInt32(); Flags = br.ReadByte(); br.ReadByte(); // Padding UserEdgeCost = br.ReadInt16(); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); if (variation == HKXVariation.HKXBloodBorne) { br.AssertInt32(0); } else { AssertPointer(hkx, br); } AnimationType = br.ReadEnum32 <AnimationType>(); Duration = br.ReadSingle(); TransformTrackCount = br.ReadInt32(); FloatTrackCount = br.ReadInt32(); if (variation == HKXVariation.HKXBloodBorne) { br.Pad(16); } if (variation == HKXVariation.HKXDS1) { br.ReadInt64s(2); // Annotations } else { // Literally guessing here br.ReadInt64s(3); // Annotations //br.ReadUInt32(); // padding? } Transforms = new HKArray <Transform>(hkx, section, this, br, variation); Floats = new HKArray <HKFloat>(hkx, section, this, br, variation); DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); AssertPointer(hkx, br); Faces = new HKArray <NVMFace>(hkx, section, this, br, variation); Edges = new HKArray <NVMEdge>(hkx, section, this, br, variation); Vertices = new HKArray <HKVector4>(hkx, section, this, br, variation); br.ReadUInt64s(2); // hkaiStreamingSet seems unused FaceData = new HKArray <HKUInt>(hkx, section, this, br, variation); EdgeData = new HKArray <HKUInt>(hkx, section, this, br, variation); FaceDataStriding = br.ReadInt32(); EdgeDataStriding = br.ReadInt32(); Flags = br.ReadByte(); br.AssertByte(0); // Padding br.AssertUInt16(0); // Padding AABBMin = br.ReadVector4(); AABBMax = br.ReadVector4(); ErosionRadius = br.ReadSingle(); UserData = br.ReadUInt64(); br.ReadUInt64(); // Padding DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }
public override void Read(HKX hkx, HKXSection section, BinaryReaderEx br, HKXVariation variation) { SectionOffset = (uint)br.Position; AssertPointer(hkx, br); AssertPointer(hkx, br); AssertPointer(hkx, br); AssertPointer(hkx, br); TransformTrackToBoneIndices = new HKArray <HKShort>(hkx, section, this, br, variation); FloatTrackToFloatSlotIndices = new HKArray <HKShort>(hkx, section, this, br, variation); if (variation != HKXVariation.HKXDS1) { //PartitionIndices = new HKArray<HKShort>(hkx, section, this, br, variation); PartitionIndices = new HKArray <HKShort>(hkx, section, this, br, variation); BlendHint = br.ReadEnum32 <AnimationBlendHint>(); } else { // I'm so sorry. if (variation == HKXVariation.HKXDS1 && hkx.IsDS1RAnimHotfix) { br.Position += 12; } BlendHint = br.ReadEnum32 <AnimationBlendHint>(); OriginalSkeletonName = br.ReadShiftJIS(); br.Pad(16); } br.Pad(16); DataSize = (uint)br.Position - SectionOffset; ResolveDestinations(hkx, section); }