public TXPEntry(DhBinaryReader br, ushort frameCount) { //Ensure that Uknown 1 is 1 if (br.ReadU16() != 1) { throw new Exception("Unknown1 wasn't 1!"); } //Read material index MaterialIndex = br.ReadS16(); if (br.ReadU32() != 0) { throw new Exception("Unknown2 wasn't 0!"); } //Read the frame data offset for this uint frameDataOffset = br.ReadU32(); TexObjIndicies = new short[frameCount]; //Save reader's current position and seek to the frame data br.SaveOffset(0); br.Goto(frameDataOffset); //Fill TexObjIndicies for each frame for (int frame = 0; frame < frameCount; frame++) { TexObjIndicies[frame] = br.ReadS16(); } br.LoadOffset(0); }
/// <summary> /// Read a single material from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public BinMaterial(DhBinaryReader br) { // Read Index. Index = br.ReadS16(); // Read Unknown 1. (Unused index?) Unknown1 = br.ReadS16(); // Read U-Wrapping. WrapU = br.Read(); // Read V-Wrapping. WrapV = br.Read(); // Read Unknown 2. (Flags?) Unknown2 = br.ReadS16(); // Define a array to hold the unknown 3 values. Unknown3 = new int[3]; // Loop through the unknown 3 values. for (int i = 0; i < Unknown3.Length; i++) { // Write the current unknown value. Unknown3[i] = br.ReadS32(); } }
public MDLDrawElement(DhBinaryReader br, List <MDLMaterial> materials, List <MDLShape> shapes) { MaterialIndex = br.ReadS16(); ShapeIndex = br.ReadS16(); Material = materials[MaterialIndex]; Shape = shapes[ShapeIndex]; }
public BinGraphObjectPart(DhBinaryReader br) { // Read shader index. ShaderIndex = br.ReadS16(); // Read batch index. BatchIndex = br.ReadS16(); }
/// <summary> /// Read a single primitive vertex from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public BinPrimitiveVertex(DhBinaryReader br, byte useNBT, int uvCount, BinBatchAttributes attributes) { // Read Matrix Index. MatrixIndex = br.ReadS16(); // Check position attribute. if (attributes.HasFlag(BinBatchAttributes.Position)) { // Read Position Index. PositionIndex = br.ReadS16(); } // Check normal attribute. if (attributes.HasFlag(BinBatchAttributes.Normal)) { // Read Normal Index. NormalIndex = br.ReadS16(); // Check UseNBT flag. if (useNBT == 1) { // Read BiNormal Index. BiNormalIndex = br.ReadS16(); // Read Tangent Index. TangentIndex = br.ReadS16(); } } // Define ColorIndex array to hold ColorIndex values. ColorIndex = new short[2]; // Check color2 attribute. if (attributes.HasFlag(BinBatchAttributes.Color0)) { // Read the Color1 value. ColorIndex[0] = br.ReadS16(); } // Check color1 attribute. if (attributes.HasFlag(BinBatchAttributes.Color1)) { // Read the Color1 value. ColorIndex[1] = br.ReadS16(); } // Define UVIndex array to hold UVIndex values. UVIndex = new short[8]; // Loop through texCoords. for (int i = 0; i < uvCount; i++) { // Check texCoordX attribute. if (attributes.HasFlag((BinBatchAttributes)(1 << (13 + i)))) { // Read the current UVIndex value. UVIndex[i] = br.ReadS16(); } } }
/// <summary> /// Read a single vertex. /// </summary> /// <param name="br">The binaryreader to read with.</param> public Vertex(DhBinaryReader br, Attributes attributes, bool useNbt) { // Each vertex will always hold 26 indices. (Null = unused) Indices = new short?[26]; // Get all the attributes from GX attributes. var indices = Enum.GetValues(typeof(Attributes)); // Loop through GX attributes. for (int i = 0; i < indices.Length; i++) { // Make sure this attribute is present. if (attributes.HasFlag((Attributes)(1 << i))) { // Read the current index. Indices[i] = br.ReadS16(); // Check if we're reading normals and nbt is enabled. if (i == 10 && useNbt) { // Set bitangent/tangent indices. (TODO - Fix the indices here...) //Indices[24] = br.ReadS16(); //Indices[25] = br.ReadS16(); br.Skip(4); // Thanks to Astral-C for the tip of just throwing these away. (Until support is added) } } } }
/// <summary> /// Read a PrmEntry from PRM. /// </summary> /// <param name="br">Binary Reader to use.</param> public PrmEntry(DhBinaryReader br) { // Read Hash. Hash = br.ReadU16(); // Read NameLength. NameLength = br.ReadU16(); // Read Name. Name = br.ReadStr(NameLength); // Read ValueLength. ValueLength = br.ReadU32(); // Resolve Type from Hash. Type = PRMUtils.HashToType(Hash); // Check Type. switch (Type) { case PrmType.BYTE: // Read Value as a byte. Value = br.Read(); break; case PrmType.SHORT: // Read Value as a short. Value = br.ReadS16(); break; case PrmType.INT: // Read Value as a int. Value = br.ReadS32(); break; case PrmType.FLOAT: // Read Value as a float. Value = br.ReadF32(); break; case PrmType.RGBA: // Read Value as a Clr4. Value = br.ReadClr4(); break; case PrmType.VECTOR3: // Read Value as a Vector3. Value = br.ReadVec3(); break; default: throw new NotImplementedException("PRM parameter entry type is unknown!"); } }
public MDLHeader(DhBinaryReader br) { // magic Magic = br.ReadU32(); // counts FaceCount = br.ReadU16(); Padding = br.ReadS16(); NodeCount = br.ReadU16(); PacketCount = br.ReadU16(); WeightCount = br.ReadU16(); JointCount = br.ReadU16(); PositionCount = br.ReadU16(); NormalCount = br.ReadU16(); ColorCount = br.ReadU16(); TextureCoordinateCount = br.ReadU16(); Padding2 = br.ReadS64(); TextureCount = br.ReadU16(); Padding3 = br.ReadS16(); SamplerCount = br.ReadU16(); DrawElementCount = br.ReadU16(); MaterialCount = br.ReadU16(); ShapeCount = br.ReadU16(); Padding4 = br.ReadS32(); // offsets NodeOffset = br.ReadU32(); PacketOffset = br.ReadU32(); MatricesOffset = br.ReadU32(); WeightOffset = br.ReadU32(); JointOffset = br.ReadU32(); WeightCountTableOffset = br.ReadU32(); PositionOffset = br.ReadU32(); NormalOffset = br.ReadU32(); ColorOffset = br.ReadU32(); TextureCoordinateOffset = br.ReadU32(); Padding5 = br.ReadS64(); TextureLocationOffset = br.ReadU32(); Padding6 = br.ReadS32(); MaterialOffset = br.ReadU32(); SamplerOffset = br.ReadU32(); ShapeOffset = br.ReadU32(); DrawElementOffset = br.ReadU32(); Padding7 = br.ReadS64(); }
/// <summary> /// Read a single batch from BIN. /// </summary> /// <param name="br">The binaryreader to write with.</param> /// <param name="batchesOffset">Offset to batches.</param> public Batch(DhBinaryReader br, long batchesOffset) { // Read face count. FaceCount = br.ReadU16(); // Read primitive list size. ListSize = br.ReadS16(); // Read vertex attributes. VertexAttributes = (Attributes)br.ReadU32(); // Read UseNormals flag. UseNormals = br.ReadBool8(); // Read Position Winding. Positions = br.Read(); // Read UV Count. UvCount = br.Read(); // Read UseNBT flag. UseNBT = br.ReadBool8(); // Read Primitive offset. PrimitiveOffset = br.ReadU32(); // Read Unknown 1. (Padding?) Unknown1 = br.ReadS32s(2); // Save the current position. long currentPosition = br.Position(); // Go to the batch's primitive offset offset. br.Goto(batchesOffset + PrimitiveOffset); // Define list to hold batch's primitives. Primitives = new List <Primitive>(); // Define int to keep track of the amount of faces read. int readFaces = 0; // Read primitives until batch's face count has been reached. while ((readFaces < FaceCount) && (br.Position() < (batchesOffset + PrimitiveOffset + (ListSize << 5)))) { // Read primitive. Primitive binPrimitive = new Primitive(br, VertexAttributes, UseNBT); // Add the primitive to the batch's primitives. Primitives.Add(binPrimitive); // Add primitive's face count to the read faces counter. readFaces += binPrimitive.FaceCount; } // Go to the previously saved offset. br.Goto(currentPosition); }
public MDLShapePacket(DhBinaryReader br) { DataOffset = br.ReadU32(); DataSize = br.ReadU32(); Unknown = br.ReadS16(); MatrixCount = br.ReadU16(); MatrixIndices = br.ReadU16s(10); PacketData = new List <ShapePacketData>(); Data = br.ReadAt(DataOffset, (int)DataSize); }
/// <summary> /// Read a single material from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public Material(DhBinaryReader br) { // Read Index. Index = br.ReadS16(); // Read Unknown 1. (Unused index?) Unknown1 = br.ReadS16(); // Read U-Wrapping. WrapU = (WrapMode)br.Read(); // Read V-Wrapping. WrapV = (WrapMode)br.Read(); // Read Unknown 2. (Flags?) Unknown2 = br.ReadS16(); // Read Unknown 3. Unknown3 = br.ReadS32s(3); }
public MDLNode(DhBinaryReader br, List <MDLDrawElement> drawElements) { MatrixIndex = br.ReadU16(); ChildIndex = br.ReadU16(); SiblingIndex = br.ReadU16(); Padding1 = br.ReadS16(); DrawElementCount = br.ReadU16(); DrawElementBeginIndex = br.ReadU16(); Padding2 = br.ReadS32(); DrawElements = drawElements.GetRange(DrawElementBeginIndex, DrawElementCount); }
/// <summary> /// Read a GSprite from GEB. /// </summary> /// <param name="br">Binary Reader to use.</param> public GSprite(DhBinaryReader br) { // Read GSprite's Unknown 1. Unknown1 = br.ReadS16(); // Read GSprite's Unknown 2. Unknown2 = br.ReadS16(); // Read GSprite's RGBA. RGBA = br.ReadS32(); // Define a new list to hold the GSprite's points. Points = new List <SpritePoint>(); // Loop through GSprite's points. for (int i = 0; i < 4; i++) { // Read point and add it to the spritepoint list. Points.Add(new SpritePoint(br)); } // Define a array to hold the unknown values. Unknown3 = new int[10]; // Loop through the unknown values. for (int i = 0; i < Unknown3.Length; i++) { // Read the current unknown value. Unknown3[i] = br.ReadS32(); } // Read GSprite's Unknown 4. Unknown4 = br.ReadF32(); // Read GSprite's Unknown 5. Unknown5 = br.ReadF32(); // Read GSprite's Unknown 6. Unknown6 = br.ReadS32(); }
public MDLMaterial(DhBinaryReader br, List <MDLSampler> samplers) { DiffuseColor = br.ReadClr4(); Unknown1 = br.ReadS16(); AlphaFlag = br.ReadU8(); TevStageCount = br.ReadU8(); Unknown2 = br.ReadU8(); br.Skip(23); TevStages = new List <MDLTevStage>(); for (int i = 0; i < 8; i++) { TevStages.Add(new MDLTevStage(br)); } }
/// <summary> /// Read a single shader from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public BinShader(DhBinaryReader br) { // Read Unknown 1. Unknown1 = br.Read(); // Read Unknown 2. Unknown2 = br.Read(); // Read Unknown 3. Unknown3 = br.Read(); // Read Tint. Tint = br.ReadS32(); // Read Unknown 4. (Padding) Unknown4 = br.Read(); // Define a new array to hold the Material Indices. MaterialIndices = new short[8]; // Loop through Material Indices. for (int i = 0; i < 8; i++) { // Read a material index and store it in Material Indices array. MaterialIndices[i] = br.ReadS16(); } // Define a new array to hold Unknown 5. (Indices?) Unknown5 = new short[8]; // Loop through Unknown 5. for (int i = 0; i < 8; i++) { // Read a Unknown 5 value and store it in Unknown5 array. Unknown5[i] = br.ReadS16(); } }
/// <summary> /// Read a single entry in TXP. /// </summary> /// <param name="br">The binaryreader to read with.</param> /// <param name="keyFrameCount">The amount of keyframes in each entry.</param> public TxpEntry(DhBinaryReader br, ushort keyFrameCount) { // Read Unknown 1. Unknown1 = br.ReadS16(); //Read Material Index. MaterialIndex = br.ReadU16(); // Read Unknown 2. Unknown2 = br.ReadS32(); // Read Indices Offset. IndicesOffset = br.ReadU32(); // Read Indices. Indices = br.ReadU16sAt(IndicesOffset, keyFrameCount).ToList(); }
/// <summary> /// Read a single primitive from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public BinPrimitive(DhBinaryReader br, byte useNBT, int uvCount, BinBatchAttributes attributes) { // Read Primitive Type. Type = br.Read(); // Read number of vertices. VerticeCount = br.ReadS16(); // Define ColorIndex array to hold primitive vertices. Vertices = new List <BinPrimitiveVertex>(); // Loop through primitive vertices. for (int i = 0; i < VerticeCount; i++) { // Read a primitive vertex and add it to the list. Vertices.Add(new BinPrimitiveVertex(br, useNBT, uvCount, attributes)); } }
/// <summary> /// Read a single primitive from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public Primitive(DhBinaryReader br, Attributes attributes, bool useNbt) { // Read Primitive Type. Type = (PrimitiveType)br.ReadU8(); // Read number of vertices. VerticeCount = br.ReadS16(); // Define new list to hold primitive vertices. Vertices = new List <Vertex>(); // Loop through primitive vertices. for (int i = 0; i < VerticeCount; i++) { // Read a primitive vertex and add it to the list. Vertices.Add(new Vertex(br, attributes, useNbt)); } }
/// <summary> /// Reads ANM from a data stream. /// </summary> /// <param name="stream">The stream containing the ANM data.</param> public ANM(Stream stream) { // Define a binary reader to read with. DhBinaryReader br = new DhBinaryReader(stream, DhEndian.Big); // Reader ANM's Header. Version = br.ReadU8(); Loop = br.ReadBool8(); Unknown1 = br.ReadS16(); KeyFrameCount = br.ReadU32(); KeyFrameOffset = br.ReadU32(); Unknown2 = br.ReadS32(); Unknown3 = br.ReadS32(); Unknown4 = br.ReadS32(); /* * Keyframes - Interpolation type list: * https://ia800802.us.archive.org/9/items/GCN_SDK_Documentation/Game%20Engine%20Programming.pdf */ }
/// <summary> /// Read a single triangle data entry from MP. /// </summary> /// <param name="br">Binary Reader to use.</param> public MpTriangleData(DhBinaryReader br) { // Define a new array to hold vertex indices. VertexIndices = new short[3]; // Loop through Vertex indices. for (int i = 0; i < 3; i++) { // Read Vertex index and store it in the VertexIndices array. VertexIndices[i] = br.ReadS16(); } // Read Normal Index. NormalIndex = br.ReadS16(); // Define a new array to hold edge tangent indices. EdgeTangentIndices = new short[3]; // Loop through Edge Tangent indices. for (int i = 0; i < 3; i++) { // Read Edge Tangent index and store it in the EdgeTangentIndices array. EdgeTangentIndices[i] = br.ReadS16(); } // Read Unknown 1. Unknown1 = br.ReadS16(); // Read Unknown 2. Unknown2 = br.ReadF32(); // Read Unknown 3. Unknown3 = br.ReadS16(); // Read Unknown 4. Unknown4 = br.ReadS16(); }
/// <summary> /// Read a single graph object from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> /// <param name="graphObjectOffset">Offset to the graph objects.</param> public GraphObject(DhBinaryReader br, uint graphObjectOffset) // 112 bytes long { // Read Parent Index. ParentIndex = br.ReadS16(); // Read Child Index. ChildIndex = br.ReadS16(); // Read Next Index. NextIndex = br.ReadS16(); // Read Previous Index. PreviousIndex = br.ReadS16(); // Read Render Flags. RenderFlags = (GraphObjectRenderFlags)br.ReadU16(); // Unknown 1. (Padding?) Unknown1 = br.ReadU16(); // Read Scale. Scale = br.ReadVec3(); // Read Rotation. Rotation = br.ReadVec3(); // Read Position Position = br.ReadVec3(); // Read Bounding Box Minimum. BoundingBoxMinimum = br.ReadVec3(); // Read Bounding Box Maximum. BoundingBoxMaximum = br.ReadVec3(); // Read Bounding Sphere Radius. BoundingSphereRadius = br.ReadF32(); // Read Parent Index. PartCount = br.ReadS16(); // Unknown 3. (Padding?) Unknown3 = br.ReadU16(); // Read Parent Index. PartOffset = br.ReadS32(); // Unknown 4. (Padding?) Unknown4 = br.ReadU32s(7); // Initialize a new list to hold parts. Parts = new List <BinGraphObjectPart>(); // Offset to continue reading from. long currentPosition = br.Position(); // Goto graphobject's parts. br.Goto(graphObjectOffset + PartOffset); // Loop through parts. for (int i = 0; i < PartCount; i++) { // Read part and add it to the list of parts. Parts.Add(new BinGraphObjectPart(br)); } // Go back to return offset we saved earlier. br.Goto(currentPosition); }
/// <summary> /// Read a single batch from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> /// <param name="batchesOffset">Offset to batches.</param> public BinBatch(DhBinaryReader br, long batchesOffset) { // Read face count. FaceCount = br.ReadU16(); // Read primitive list size. ListSize = (ushort)(br.ReadS16() << 5); // Read vertex attributes. VertexAttributes = (BinBatchAttributes)br.ReadU32(); // Read UseNormals flag. UseNormals = br.Read(); // Read Position Winding. Positions = br.Read(); // Read UV Count. UvCount = br.Read(); // Read UseNBT flag. UseNBT = br.Read(); // Read Primitive offset. PrimitiveOffset = br.ReadU32(); // Define array to hold Unknown 1 values. Unknown1 = new int[2]; // Loop through Unknown 1 values. for (int i = 0; i < 2; i++) { // Read current Unknown 1 value. Unknown1[i] = br.ReadS32(); } // Save the current position. long currentPosition = br.Position(); // Go to the bin batches offset. br.Goto(batchesOffset); // Sail to the batches's primitive offset. br.Sail(PrimitiveOffset); // Define list to hold batch's primitives. Primitives = new List <BinPrimitive>(); // Define int to hold amount of faces read. int readFaces = 0; // Read primitives until batch's face count has been reached. while (readFaces < FaceCount && br.Position() < (batchesOffset + PrimitiveOffset + ListSize)) { // Read primitive. BinPrimitive binPrimitive = new BinPrimitive(br, UseNBT, UvCount, VertexAttributes); // Add the primitive to the batch's primitives. Primitives.Add(binPrimitive); // Add primitive's face count to the read faces counter. readFaces += binPrimitive.FaceCount; } // Go to the previously saved offset. br.Goto(currentPosition); }
/// <summary> /// Read a single primitive vertex from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public UnusedVertex(DhBinaryReader br, int uvCount, Attributes attributes) { // Check position attribute. if (attributes.HasFlag(Attributes.PosNormMatrix)) { // Read Matrix Index. MatrixIndex = br.ReadS16(); } // Check Position attribute. if (attributes.HasFlag(Attributes.Position)) { // Read Position Index. PositionIndex = br.ReadS16(); } // Check Normal attribute. if (attributes.HasFlag(Attributes.Normal)) { // Read Normal Index. NormalIndex = br.ReadS16(); // Check if UseNBT flag is true. if (attributes.HasFlag(Attributes.NormalBinormalTangent)) { // Read BiNormal Index. BiNormalIndex = br.ReadS16(); // Read Tangent Index. TangentIndex = br.ReadS16(); } } // Define ColorIndex array to hold ColorIndex values. ColorIndex = new short[2]; // Check Color0 attribute. if (attributes.HasFlag(Attributes.Color0)) { // Read the Color0 value. ColorIndex[0] = br.ReadS16(); } // Check Color1 attribute. if (attributes.HasFlag(Attributes.Color1)) { // Read the Color1 value. ColorIndex[1] = br.ReadS16(); } // Define UVIndex array to hold UVIndex values. UVIndex = new short[8]; // Loop through texCoords. for (int i = 0; i < uvCount; i++) { // Check texCoordX attribute. if (attributes.HasFlag((Attributes)(1 << (13 + i)))) { // Read the current UVIndex value. UVIndex[i] = br.ReadS16(); } } }
public MDLTevStage(DhBinaryReader br) { Unknown1 = br.ReadS16(); SamplerIndex = br.ReadS16(); Unknown2 = br.ReadF32s(7); }