public void ClearElements() { Karts.Clear(); Array.Clear(SelectedKarts, 0, SelectedKarts.Length); TurnKartPaletteBlocks.Clear(); SpinKartPaletteBlocks.Clear(); //Tracks.Clear(); //Array.Clear(SelectedTracks, 0, SelectedTracks.Length); KartGraphicsBlock = null; TextureHub.ClearTextureData(); }
private MarioKart64ElementHub() { Karts = new List <KartInfo>(); SelectedKarts = new KartInfo[8]; TurnKartPaletteBlocks = new List <KartPaletteBlock>(); SpinKartPaletteBlocks = new List <KartPaletteBlock>(); //Tracks = new List<TrackData>(); //SelectedTracks = new TrackData[MarioKartRomInfo.TrackCount]; TextureHub = new TextureHub(); NewElementOffset = BASE_FILE_END_OFFSET; }
public MarioKart64ElementHub(XElement xml) { Karts = new List <KartInfo>(); SelectedKarts = new KartInfo[8]; TurnKartPaletteBlocks = new List <KartPaletteBlock>(); SpinKartPaletteBlocks = new List <KartPaletteBlock>(); //Tracks = new List<TrackData>(); //SelectedTracks = new TrackData[MarioKartRomInfo.TrackCount]; TextureHub = new TextureHub(); _instance = this; _loadedXml = xml; //Actually load the xml data at a later date (WRONG) LoadFromXML(); }
public override XElement GetAsXML() { XElement xml = base.GetAsXML(); xml.Add(new XAttribute(NEW_ELEMENT_OFFSET, NewElementOffset)); //KartReference - Only use the names of the karts selected //MIOBlocks/TKMK00Bocks - Offsets for each one //Karts - Full listing of information XElement newElement = new XElement(TURN_PALETTE_BLOCK); foreach (KartPaletteBlock block in TurnKartPaletteBlocks) { newElement.Add(new XElement(OFFSET, block.FileOffset.ToString())); } xml.Add(newElement); newElement = new XElement(SPIN_PALETTE_BLOCK); foreach (KartPaletteBlock block in SpinKartPaletteBlocks) { newElement.Add(new XElement(OFFSET, block.FileOffset.ToString())); } xml.Add(newElement); //And finally, the selected karts newElement = new XElement(SELECTED_KARTS); foreach (KartInfo kart in SelectedKarts) { newElement.Add(new XElement(kart.KartName)); } xml.Add(newElement); //Kart graphics reference newElement = new XElement(KARTS_GRAPHICS_REFERENCE_BLOCK); newElement.Value = KartGraphicsBlock.FileOffset.ToString(); xml.Add(newElement); //Kart portraits reference newElement = new XElement(KARTS_PORTRAITS_REFERENCE_TABLE); newElement.Value = KartPortraitsTable.FileOffset.ToString(); xml.Add(newElement); xml.Add(TextureHub.GetAsXML()); return(xml); }
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++; } }