public void AddDmaProfile(DmaProfile profile) { _dmaProfiles.Add(profile); if (_dmaProfileIndex == -1) _dmaProfileIndex = 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]); } }
public void RemoveDmaProfile(DmaProfile profile) { if (_dmaProfiles.Contains(profile)) { if(_dmaProfileIndex >= _dmaProfiles.IndexOf(profile)) _dmaProfileIndex--; //Will bring it to -1 when _dmaProfiles is emptied _dmaProfiles.Remove(profile); } }