public static void ReadRom(BackgroundWorker worker, byte[] rawData, MarioKart64ReaderResults finalResults) { CourseReaderResults results = new CourseReaderResults(); CourseDataReferenceBlock courseBlock; if (!RomProject.Instance.Files[0].HasElementExactlyAt(MarioKartRomInfo.CourseReferenceDataTableLocation)) { ProgressService.SetMessage("Loading Course Resources"); byte[] refBlock = new byte[0x13 * 0x30]; Array.Copy(rawData, MarioKartRomInfo.CourseReferenceDataTableLocation, refBlock, 0, 0x13 * 0x30); courseBlock = new CourseDataReferenceBlock(MarioKartRomInfo.CourseReferenceDataTableLocation, refBlock); //RomProject.Instance.Files[0].AddElement(block); results.NewElements.Add(courseBlock); } else { courseBlock = (CourseDataReferenceBlock)RomProject.Instance.Files[0].GetElementAt(MarioKartRomInfo.CourseReferenceDataTableLocation); } results.CourseDataBlock = courseBlock; //MarioKart64ElementHub.Instance.CourseDataBlock = courseBlock; finalResults.CourseResults = results; }
public static void ApplyResults(object sender, DoWorkEventArgs args) { MarioKart64ReaderResults results = (MarioKart64ReaderResults)args.Argument; //To-do: add an error report for any sort of exceptions during saving? ProgressService.SetMessage("Splicing data elements into Rom object"); foreach (N64DataElement element in results.NewElements) { RomProject.Instance.Files[0].AddElement(element); } if (results.KartResults != null) { ProgressService.SetMessage("Splicing kart data into Rom object"); KartReader.ApplyResults(results.KartResults); } // if (results.TrackResults != null) // { // ProgressService.SetMessage("Splicing track data into Rom object"); //TrackReader.ApplyResults(results.TrackResults); // } if (results.TextBank != null) { ProgressService.SetMessage("Splicing text data into Rom object"); MarioKart64ElementHub.Instance.TextBank = results.TextBank; } if (results.TextureResults != null) { ProgressService.SetMessage("Splicing texture data into Rom object"); TextureReader.ApplyResults(results.TextureResults); } //Does this really belong here? if (!RomProject.Instance.Items.Contains(MarioKart64ElementHub.Instance)) { RomProject.Instance.AddRomItem(MarioKart64ElementHub.Instance); } ProgressService.SetMessage("Finished!"); }
public static void ReadRom(BackgroundWorker worker, byte[] rawData, MarioKart64ReaderResults finalResults) { TextureReaderResults results = new TextureReaderResults(); //Here, load in the texture stuff ProgressService.SetMessage("Loading Textures and Palettes"); foreach (MarioKartRomInfo.MK64ImageInfo imageInfo in MarioKartRomInfo.ImageLocations) { MK64Image image = new MK64Image(imageInfo, rawData); if (image.IsValidImage) { results.AddImage(image); } else { throw new Exception(); } } ProgressService.SetMessage("Loading Kart Images"); foreach (MarioKartRomInfo.MK64ImageInfo imageInfo in KartImageInfo.ImageLocations) { MK64Image image = new MK64Image(imageInfo, rawData); if (image.IsValidImage) { results.AddKartImage(image); } else { throw new Exception(); } } finalResults.TextureResults = results; }
public void LoadFromXML() { //TextBank/TextReferences - Only use the offset currently being used //KartReference - Only use the names of the karts selected //MIOBlocks/TKMK00Bocks - Offsets for each one //Karts - Full listing of information //Elements should already have been cleared //ClearElements(); NewElementOffset = int.Parse(_loadedXml.Attribute(NEW_ELEMENT_OFFSET).Value); //Before we start, load up all saved karts and tracks ProgressService.SetMessage("Loading Kart Resources"); foreach (RomItem item in RomProject.Instance.Items) { //If the same name kart hasn't been loaded yet if (item is KartInfo && Karts.FirstOrDefault(k => k.KartName == ((KartInfo)item).KartName) == null) { this.Karts.Add((KartInfo)item); } //else if is trackinfo } //Also the text bank is all elements, so we don't need an xml in here for it ProgressService.SetMessage("Loading Text Blocks"); N64DataElement textRefEl, textBlockEl; if (RomProject.Instance.Files[0].HasElementExactlyAt(TextReferenceBlock.TEXT_REFERENCE_SECTION_1, out textRefEl) && RomProject.Instance.Files[0].HasElementExactlyAt(TextBankBlock.TEXT_BLOCK_START, out textBlockEl)) { TextReferenceBlock refBlock = (TextReferenceBlock)textRefEl; TextBankBlock bankBlock = (TextBankBlock)textBlockEl; TextBank = new TextBank(bankBlock, refBlock, true); } int offset; int count = 0; int fullCount = _loadedXml.Elements().Count(); N64DataElement n64Element; foreach (XElement element in _loadedXml.Elements()) { ProgressService.SetMessage(string.Format("Storing Special Elements {0:0.0}%", (double)count / fullCount)); switch (element.Name.ToString()) { case TURN_PALETTE_BLOCK: foreach (XElement el in element.Elements()) { offset = int.Parse(el.Value); if (RomProject.Instance.Files[0].HasElementExactlyAt(offset, out n64Element)) { int paletteOffset = offset; List <Palette> palettes = new List <Palette>(); palettes.Add((Palette)n64Element); paletteOffset += 0x40 * 2; for (int i = 1; i < 84; i++) //Make not hardcoded later { if (!RomProject.Instance.Files[0].HasElementAt(paletteOffset, out n64Element)) { throw new Exception(); } palettes.Add((Palette)n64Element); paletteOffset += 0x40 * 2; } KartPaletteBlock block = new KartPaletteBlock(offset, palettes); TurnKartPaletteBlocks.Add(block); } } break; case SPIN_PALETTE_BLOCK: foreach (XElement el in element.Elements()) { offset = int.Parse(el.Value); if (RomProject.Instance.Files[0].HasElementExactlyAt(offset, out n64Element)) { int paletteOffset = offset; List <Palette> palettes = new List <Palette>(); palettes.Add((Palette)n64Element); paletteOffset += 0x40 * 2; for (int i = 1; i < 80; i++) //Make not hardcoded later { if (!RomProject.Instance.Files[0].HasElementAt(paletteOffset, out n64Element)) { throw new Exception(); } palettes.Add((Palette)n64Element); paletteOffset += 0x40 * 2; } KartPaletteBlock block = new KartPaletteBlock(offset, palettes); SpinKartPaletteBlocks.Add(block); } } break; case KARTS_GRAPHICS_REFERENCE_BLOCK: offset = int.Parse(element.Value); if (RomProject.Instance.Files[0].HasElementExactlyAt(offset, out n64Element)) { if (n64Element is KartGraphicsReferenceBlock) { KartGraphicsBlock = (KartGraphicsReferenceBlock)n64Element; //KartReader.LoadKartGraphicDmaReferences(KartGraphicsBlock); } } break; case KARTS_PORTRAITS_REFERENCE_TABLE: offset = int.Parse(element.Value); if (RomProject.Instance.Files[0].HasElementExactlyAt(offset, out n64Element)) { if (n64Element is KartPortraitTable) { KartPortraitsTable = (KartPortraitTable)n64Element; //KartReader.LoadKartPortraitDmaReferences(KartPortraitsTable); } } break; case SELECTED_KARTS: int kartIndex = 0; foreach (XElement selKart in element.Elements()) { KartInfo selectedKart = Karts.SingleOrDefault(k => k.KartName == selKart.Name); if (selectedKart != null) { SelectedKarts[kartIndex] = selectedKart; } kartIndex++; } break; case TextureHub.TEXTURE_HUB: TextureHub.LoadReferencesFromXML(element); break; } count++; } }
public static void ReadRom(BackgroundWorker worker, byte[] rawData, MarioKart64ReaderResults finalResults) { KartReaderResults results = new KartReaderResults(); //Portraits first KartPortraitTable portraits; N64DataElement element; if (!RomProject.Instance.Files[0].HasElementExactlyAt(MarioKartRomInfo.CharacterFaceTableOffset, out element)) { byte[] portraitBlock = new byte[MarioKartRomInfo.CharacterFaceTableLength]; Array.Copy(rawData, MarioKartRomInfo.CharacterFaceTableOffset, portraitBlock, 0, MarioKartRomInfo.CharacterFaceTableLength); portraits = new KartPortraitTable(MarioKartRomInfo.CharacterFaceTableOffset, portraitBlock); //RomProject.Instance.Files[0].AddElement(portraits); results.NewElements.Add(portraits); } else { portraits = (KartPortraitTable)element; } //Add to hub here? KartGraphicsReferenceBlock block; N64DataElement elBlock; if (!RomProject.Instance.Files[0].HasElementExactlyAt(KartGraphicsReferenceBlock.DefaultKartGraphicsReferenceBlock0Location, out elBlock)) { byte[] refBlock = new byte[KartGraphicsReferenceBlock.DefaultKartGraphicsReferenceLength]; Array.Copy(rawData, KartGraphicsReferenceBlock.DefaultKartGraphicsReferenceBlock0Location, refBlock, 0, KartGraphicsReferenceBlock.DefaultKartGraphicsReferenceLength); block = new KartGraphicsReferenceBlock(KartGraphicsReferenceBlock.DefaultKartGraphicsReferenceBlock0Location, refBlock); results.NewElements.Add(block); //RomProject.Instance.Files[0].AddElement(block); } else { block = (KartGraphicsReferenceBlock)elBlock; } //NOTE: ALL PALETTE AND TEXTURE INFORMATION WILL ALREADY BE LOADED HERE. NO NEED TO CREATE ANYTHING. //FIXED!! ProgressService.SetMessage("Organizing Kart Images"); LoadKartGraphicDmaReferences(block, rawData, results, worker); //FIXED!! ProgressService.SetMessage("Loading Kart Portraits"); LoadKartPortraitDmaReferences(portraits, rawData, finalResults.TextureResults, results, worker); //FIXED!! if (MarioKart64ElementHub.Instance.Karts.Count == 0) //Has not been initialized { LoadKartInfo(block, portraits, worker, rawData, finalResults.TextureResults, results); } results.KartGraphicsBlock = block; results.KartPortraitsTable = portraits; finalResults.KartResults = results; }