public void ParseMeshes() { int modelType = this.t4.binary.ReadInt(0, true); /* Normal = 3 || Shadow = 4 */ int bonesCount = this.t4.binary.ReadShort(0x10, true); int skeletonOffset = this.t4.binary.ReadShort(0x14, true); int skeletonDefinitonsOffset = this.t4.binary.ReadShort(0x18, true); int meshCount = this.t4.binary.ReadInt(0x1C, true); if (modelType == 3) { byte[] skeletonBytes = new byte[bonesCount * 0x40]; Array.Copy(this.t4.binary.Buffer, this.t4.binary.Pointer + skeletonOffset, skeletonBytes, 0, skeletonBytes.Length); this.binarySkeleton = new SrkBinary(ref skeletonBytes); this.Skeleton = new Skeleton(this); this.Skeleton.Bones = new Bone[bonesCount]; this.Skeleton.BonesMatrices = new Matrix[bonesCount]; this.Skeleton.BonesReMatrices = new Matrix[bonesCount]; for (int i = 0; i < bonesCount; i++) { short id = this.binarySkeleton.ReadShort(i * 0x40, false); short parentId = this.binarySkeleton.ReadShort(i * 0x40 + 4, false); float scaleX = this.binarySkeleton.ReadFloat(i * 0x40 + 0x10, false); float scaleY = this.binarySkeleton.ReadFloat(i * 0x40 + 0x14, false); float scaleZ = this.binarySkeleton.ReadFloat(i * 0x40 + 0x18, false); float rotateX = this.binarySkeleton.ReadFloat(i * 0x40 + 0x20, false); float rotateY = this.binarySkeleton.ReadFloat(i * 0x40 + 0x24, false); float rotateZ = this.binarySkeleton.ReadFloat(i * 0x40 + 0x28, false); float translateX = this.binarySkeleton.ReadFloat(i * 0x40 + 0x30, false); float translateY = this.binarySkeleton.ReadFloat(i * 0x40 + 0x34, false); float translateZ = this.binarySkeleton.ReadFloat(i * 0x40 + 0x38, false); this.Skeleton.Bones[i] = new Bone(id); this.Skeleton.Bones[i].ParentID = parentId; this.Skeleton.Bones[i].ScaleX = scaleX; this.Skeleton.Bones[i].ScaleY = scaleY; this.Skeleton.Bones[i].ScaleZ = scaleZ; this.Skeleton.Bones[i].RotateX = rotateX; this.Skeleton.Bones[i].RotateY = rotateY; this.Skeleton.Bones[i].RotateZ = rotateZ; this.Skeleton.Bones[i].TranslateX = translateX; this.Skeleton.Bones[i].TranslateY = translateY; this.Skeleton.Bones[i].TranslateZ = translateZ; } //Bone.outpt = ""; GetMatrices(); ComputeMatrices(); //File.WriteAllText("matsXNA.txt", Bone.outpt); byte[] skeletonDefinitionsBytes = new byte[0x110]; Array.Copy(this.t4.binary.Buffer, this.t4.binary.Pointer + skeletonDefinitonsOffset, skeletonDefinitionsBytes, 0, skeletonDefinitionsBytes.Length); this.binarySkeletonDefinitons = new SrkBinary(ref skeletonBytes); } for (int currMeshIndex = 0; currMeshIndex < meshCount; currMeshIndex++) { int dmaOffset = this.t4.binary.ReadInt(0x20 + currMeshIndex * 0x20 + 0x10, true); int meshStartOffset = this.t4.binary.ReadInt(dmaOffset + 4, true); int matiOffset = this.t4.binary.ReadInt(0x20 + currMeshIndex * 0x20 + 0x14, true); int matiCount = this.t4.binary.ReadInt(matiOffset, true); int meshEndOffset = matiOffset + matiCount * 4; SrkBinary.Align16(ref meshEndOffset); int meshSize = meshEndOffset - meshStartOffset; byte[] meshBytes = new byte[0x20 + meshSize]; Array.Copy(this.t4.binary.Buffer, this.t4.binary.Pointer + 0x20 + currMeshIndex * 0x20, meshBytes, 0, 0x20); Array.Copy(this.t4.binary.Buffer, this.t4.binary.Pointer + meshStartOffset, meshBytes, 0x20, meshSize); Mesh currMesh = new Mesh(meshBytes); currMesh.Objet = this; currMesh.Binary = new SrkBinary(ref meshBytes); int dmaOffsetLocal = dmaOffset - meshStartOffset; int matiOffsetLocal = matiOffset - meshStartOffset; currMesh.Binary.WriteInt(0x10, dmaOffsetLocal, false); currMesh.Binary.WriteInt(0x14, matiOffsetLocal, false); currMesh.Binary.Pointer = 0x20; int dmaPosition = dmaOffsetLocal; bool readDMAs = true; while (readDMAs) { int currVifOffset = currMesh.Binary.ReadInt(dmaPosition + 4, true) - meshStartOffset; currMesh.Binary.WriteInt(dmaPosition + 4, currVifOffset, true); /* local dans fichier de sortie */ currVifOffset += 8; /* skip 01 01 00 01 00 80 04 6C */ int type = currMesh.Binary.ReadInt(currVifOffset, true); int matCountPerVert_count = currMesh.Binary.ReadInt(currVifOffset + ((type == 2) ? 0x2C : 0x3C), true); currMesh.DMA_Pointers.Add(dmaPosition); dmaPosition += matCountPerVert_count * 0x10 + 0x20; if (currMesh.Binary.ReadUInt(dmaPosition + 0x18, true) != 0x01000101) { readDMAs = false; } } //File.WriteAllBytes("mesh" + currMeshIndex.ToString("d3") + ".bin", meshBytes); currMesh.GetData(); if (modelType == 3) { this.meshes.Add(currMesh); } else { this.shadowMeshes.Add(currMesh); } } }