示例#1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (SelectedCourse == null)
            {
                return;
            }

            //Take the blocks, and export them
            byte[] displayListBlock = new byte[SelectedCourse.DisplayListBlockEnd - SelectedCourse.DisplayListBlockStart];
            Array.Copy(_romData, SelectedCourse.DisplayListBlockStart,
                       displayListBlock, 0, displayListBlock.Length);
            int vertexEndPackedDLStartOffset = SelectedCourse.DisplayListOffset & 0x00FFFFFF;

            byte[] vertexBlock = new byte[vertexEndPackedDLStartOffset];
            Array.Copy(_romData, SelectedCourse.VertexBlockStart,
                       vertexBlock, 0, vertexBlock.Length);
            byte[] packedBlock = new byte[(SelectedCourse.VertexBlockEnd - SelectedCourse.VertexBlockStart) - vertexEndPackedDLStartOffset];
            Array.Copy(_romData, SelectedCourse.VertexBlockStart + vertexEndPackedDLStartOffset,
                       packedBlock, 0, packedBlock.Length);
            byte[] textureBlock = new byte[SelectedCourse.TextureBlockEnd - SelectedCourse.TextureBlockStart];
            Array.Copy(_romData, SelectedCourse.TextureBlockStart,
                       textureBlock, 0, textureBlock.Length);

            string path = Path.GetDirectoryName(openFileDialog.FileName);

            string filePath = Path.Combine(path, "rawdisplaylists.bin");

            File.WriteAllBytes(filePath, displayListBlock);

            filePath = Path.Combine(path, "rawvertices.bin");
            File.WriteAllBytes(filePath, vertexBlock);

            filePath = Path.Combine(path, "rawpacked.bin");
            File.WriteAllBytes(filePath, packedBlock);

            filePath = Path.Combine(path, "rawtextures.bin");
            File.WriteAllBytes(filePath, textureBlock);

            filePath = Path.Combine(path, "displaylists.bin");
            File.WriteAllBytes(filePath, Cereal64.Common.Utils.Encoding.MIO0.Decode(displayListBlock));

            filePath = Path.Combine(path, "vertices.bin");
            File.WriteAllBytes(filePath, Cereal64.Common.Utils.Encoding.MIO0.Decode(vertexBlock));

            //filePath = Path.Combine(path, "textures.bin");
            //File.WriteAllBytes(filePath, Cereal64.Common.Utils.Encoding.MIO0.Decode(textureBlock));

            List <F3DEXCommand> commands = F3DEXPacker.BytesToCommands(packedBlock.ToList());

            byte[] bytes  = new byte[commands.Sum(c => c.RawDataSize)];
            int    offset = 0;

            foreach (F3DEXCommand command in commands)
            {
                Array.Copy(command.RawData, 0, bytes, offset, command.RawDataSize);
                offset += command.RawDataSize;
            }
            filePath = Path.Combine(path, "packed.bin");
            File.WriteAllBytes(filePath, bytes);
        }
示例#2
0
        private void btnRender_Click(object sender, EventArgs e)
        {
            if (SelectedCourse == null)
            {
                return;
            }

            for (; RomProject.Instance.Files.Count > 0;)
            {
                RomProject.Instance.RemoveRomFile(RomProject.Instance.Files[0]);
            }

            for (; RomProject.Instance.DMAProfiles.Count > 0;)
            {
                RomProject.Instance.RemoveDmaProfile(RomProject.Instance.DMAProfiles[0]);
            }

            //Take the blocks, and export them
            byte[] displayListBlock = new byte[SelectedCourse.DisplayListBlockEnd - SelectedCourse.DisplayListBlockStart];
            Array.Copy(_romData, SelectedCourse.DisplayListBlockStart,
                       displayListBlock, 0, displayListBlock.Length);
            int vertexEndPackedDLStartOffset = SelectedCourse.DisplayListOffset & 0x00FFFFFF;

            byte[] vertexBlock = new byte[vertexEndPackedDLStartOffset];
            Array.Copy(_romData, SelectedCourse.VertexBlockStart,
                       vertexBlock, 0, vertexBlock.Length);
            byte[] packedBlock = new byte[(SelectedCourse.VertexBlockEnd - SelectedCourse.VertexBlockStart) - vertexEndPackedDLStartOffset];
            Array.Copy(_romData, SelectedCourse.VertexBlockStart + vertexEndPackedDLStartOffset,
                       packedBlock, 0, packedBlock.Length);
            byte[] textureBlock = new byte[SelectedCourse.TextureBlockEnd - SelectedCourse.TextureBlockStart];
            Array.Copy(_romData, SelectedCourse.TextureBlockStart,
                       textureBlock, 0, textureBlock.Length);



            byte[] decodedDLData = Cereal64.Common.Utils.Encoding.MIO0.Decode(displayListBlock);

            List <Vertex>    vertices       = VertexPacker.BytesToVertices(Cereal64.Common.Utils.Encoding.MIO0.Decode(vertexBlock).ToList());
            VertexCollection vertCollection = new VertexCollection(0x00, vertices);

            byte[] vertsData = vertCollection.RawData;

            List <F3DEXCommand>    commands    = F3DEXPacker.BytesToCommands(packedBlock.ToList());
            F3DEXCommandCollection commandColl = new F3DEXCommandCollection(0x00, commands);

            byte[] commandsData = commandColl.RawData;

            List <TextureMIORef> textureSegPointers = ReadTextureBank(textureBlock);

            byte[] textureSegData = new byte[textureSegPointers.Sum(t => t.DecompressedSize)];
            int    bytePointer    = 0;

            for (int i = 0; i < textureSegPointers.Count; i++)
            {
                byte[] tempHolder = new byte[textureSegPointers[i].CompressedSize];
                Array.Copy(_romData, (textureSegPointers[i].RomOffset & 0x00FFFFFF) + MK64_TEXTURE_BANK_OFFSET,
                           tempHolder, 0, textureSegPointers[i].CompressedSize);
                byte[] decompressed = Cereal64.Common.Utils.Encoding.MIO0.Decode(tempHolder);
                Array.Copy(decompressed, 0, textureSegData, bytePointer, decompressed.Length);
                bytePointer += decompressed.Length;
            }

            //Use the F3DEXReader here
            RomProject.Instance.AddRomFile(new RomFile("Verts", 1, new Cereal64.Common.DataElements.UnknownData(0x00, vertsData)));
            RomProject.Instance.Files[0].FileLength = vertsData.Length;
            RomProject.Instance.AddRomFile(new RomFile("PackedDLs", 2, new Cereal64.Common.DataElements.UnknownData(0x00, commandsData)));
            RomProject.Instance.Files[1].FileLength = commandsData.Length;
            RomProject.Instance.AddRomFile(new RomFile("Textures", 3, new Cereal64.Common.DataElements.UnknownData(0x00, textureSegData)));
            RomProject.Instance.Files[2].FileLength = textureSegData.Length;

            DmaProfile profile = new DmaProfile("Levelviewer");
            DmaSegment segment = new DmaSegment();

            segment.File            = RomProject.Instance.Files[0];
            segment.RamSegment      = 0x04;
            segment.RamStartOffset  = 0x00;
            segment.FileStartOffset = 0x00;
            segment.FileEndOffset   = segment.File.FileLength;
            segment.TagInfo         = "Vertices";
            profile.AddDmaSegment(0x04, segment);
            segment                 = new DmaSegment();
            segment.File            = RomProject.Instance.Files[1];
            segment.RamSegment      = 0x07;
            segment.RamStartOffset  = 0x00;
            segment.FileStartOffset = 0x00;
            segment.FileEndOffset   = segment.File.FileLength;
            segment.TagInfo         = "PackedDLs";
            profile.AddDmaSegment(0x07, segment);
            segment                 = new DmaSegment();
            segment.File            = RomProject.Instance.Files[2];
            segment.RamSegment      = 0x05;
            segment.RamStartOffset  = 0x00;
            segment.FileStartOffset = 0x00;
            segment.FileEndOffset   = segment.File.FileLength;
            segment.TagInfo         = "Textures";
            profile.AddDmaSegment(0x05, segment);
            RomProject.Instance.AddDmaProfile(profile);
            DmaManager.Instance.AddNewDmaProfile(profile);

            F3DEXReaderPackage package    = F3DEXReader.ReadF3DEXAt(RomProject.Instance.Files[1], 0x00);
            F3DEXReaderPackage newPackage = package;

            newPackage = null;

            if (package.Elements[RomProject.Instance.Files[1]][0] is F3DEXCommandCollection)
            {
                OpenGLForm glForm = new OpenGLForm();
                glForm.Show();
                glForm.SetCommands((F3DEXCommandCollection)package.Elements[RomProject.Instance.Files[1]][0]);
            }
        }