private static Model ReadModel(uint pointer) { bool bSpecial = false; pbs.Seek(pointer, System.IO.SeekOrigin.Begin); uint header = MakiExtended.UintLittleEndian(pbs.ReadUInt()); if (header != 0x01000100) { Console.WriteLine("WARNING- THIS STAGE IS DIFFERENT! It has weird object section. INTERESTING, TO REVERSE!"); bSpecial = true; } ushort verticesCount = pbs.ReadUShort(); Vertex[] vertices = new Vertex[verticesCount]; for (int i = 0; i < verticesCount; i++) { vertices[i] = ReadVertex(); } if (bSpecial && Memory.encounters[Memory.battle_encounter].bScenario == 20) { return(new Model()); } pbs.Seek((pbs.Tell() % 4) + 4, System.IO.SeekOrigin.Current); ushort trianglesCount = pbs.ReadUShort(); ushort quadsCount = pbs.ReadUShort(); pbs.Seek(4, System.IO.SeekOrigin.Current); Triangle[] triangles = new Triangle[trianglesCount]; Quad[] quads = new Quad[quadsCount]; if (trianglesCount > 0) { for (int i = 0; i < trianglesCount; i++) { triangles[i] = ReadTriangle(); } } if (quadsCount > 0) { for (int i = 0; i < quadsCount; i++) { quads[i] = ReadQuad(); } } return(new Model() { vertices = vertices, triangles = triangles, quads = quads }); }
private void ReadSkeleton() { ms.Seek(pBase + pBones, SeekOrigin.Begin); if (ms.Position > ms.Length) { return; //error handler } bones = new Bone[cSkeletonBones]; for (int i = 0; i < cSkeletonBones; i++) { bones[i] = MakiExtended.ByteArrayToStructure <Bone>(br.ReadBytes(64)); } return; }
public ArchiveWorker(string path) { _path = MakiExtended.GetUnixFullPath(path); string root = Path.GetDirectoryName(_path); string file = Path.GetFileNameWithoutExtension(_path); string fi = MakiExtended.GetUnixFullPath($"{Path.Combine(root, file)}{Memory.Archives.B_FileIndex}"); string fl = MakiExtended.GetUnixFullPath($"{Path.Combine(root, file)}{Memory.Archives.B_FileList}"); if (!File.Exists(fi)) { throw new Exception($"There is no {file}.fi file!\nExiting..."); } if (!File.Exists(fl)) { throw new Exception($"There is no {file}.fl file!\nExiting..."); } FileList = ProduceFileLists(); }
private void ReadGeometry() { ms.Seek(pBase + pVertices, SeekOrigin.Begin); if (ms.Position > ms.Length || pVertices + ms.Position > ms.Length) //pvert error handler { return; //error handler } vertices = new Vector4[cVertices]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vector4(br.ReadInt16(), br.ReadInt16(), br.ReadInt16(), br.ReadInt16()); } ms.Seek(pBase + pFaces, SeekOrigin.Begin); List <Face> face = new List <Face>(); for (int i = 0; i < cFaces; i++) { face.Add(MakiExtended.ByteArrayToStructure <Face>(br.ReadBytes(64))); } faces = face.ToArray(); return; }
public static byte[] GetBinaryFile(string archiveName, string fileName) { byte[] isComp = GetBin(MakiExtended.GetUnixFullPath(archiveName), fileName); return(isComp == null ? null : _compressed?LZSS.DecompressAll(isComp, (uint)isComp.Length, (int)_unpackedFileSize) : isComp); }
private static byte GetClutId(ushort clut) { ushort bb = MakiExtended.UshortLittleEndian(clut); return((byte)(((bb >> 14) & 0x03) | (bb << 2) & 0x0C)); }