Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        public static void ApplyResultsAsync(MarioKart64ReaderResults results)
        {
            _worker = new BackgroundWorker();
            _worker.WorkerSupportsCancellation = true;

            _worker.DoWork             += new DoWorkEventHandler(ApplyResults);
            _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(FinishedApplyResults);

            _worker.RunWorkerAsync(results);
        }
Ejemplo n.º 3
0
        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!");
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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;
        }
Ejemplo n.º 6
0
        private static void ReadRomPayload(object sender, DoWorkEventArgs args)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            MarioKart64ReaderResults results = new MarioKart64ReaderResults();

            //The rom should be loaded as the first file in the rom project
            byte[] rawData = RomProject.Instance.Files[0].GetAsBytes();

            //NOTE: THIS IS HOW YOU DO A CANCELLATION
            //if ((worker.CancellationPending == true))
            //{
            //    args.Cancel = true;
            //    return;
            //}

            /*ProgressService.SetMessage("Reading TKMK00 Textures");
             *
             * N64DataElement preExistingElement;
             *
             * //Now read the different data bits here, if they haven't been read in yet
             * for (int i = 0; i < MarioKartRomInfo.TKMK00TextureLocations.Length; i++)
             * {
             *  preExistingElement = RomProject.Instance.Files[0].GetElementAt(MarioKartRomInfo.TKMK00TextureLocations[i].RomOffset);
             *  if (preExistingElement != null && preExistingElement.GetType() == typeof(UnknownData))
             *  {
             *      ushort alpha = MarioKartRomInfo.TKMK00TextureLocations[i].AlphaColor;
             *      int offset = MarioKartRomInfo.TKMK00TextureLocations[i].RomOffset;
             *      int length = MarioKartRomInfo.TKMK00TextureLocations[i].Length;
             *
             *      TKMK00Block tkmk;
             *
             *      byte[] bytes = new byte[length];
             *      Array.Copy(rawData, offset, bytes, 0, length);
             *
             *      tkmk = new TKMK00Block(offset, bytes, alpha);
             *
             *      if (MarioKart64ElementHub.Instance.OriginalTKMK00Blocks.SingleOrDefault(t => t.FileOffset == tkmk.FileOffset) == null)
             *      {
             *          results.NewElements.Add(tkmk);
             *          results.OriginalTKMK00Blocks.Add(tkmk);
             *      }
             *  }
             *  else if (preExistingElement is TKMK00Block &&
             *      MarioKart64ElementHub.Instance.OriginalTKMK00Blocks.SingleOrDefault(t => t.FileOffset == preExistingElement.FileOffset) == null)
             *  {
             *      results.OriginalTKMK00Blocks.Add((TKMK00Block)preExistingElement);
             *  }
             * }
             */
            //Text bank!
            TextBankBlock      textBankBlock      = null;
            TextReferenceBlock textReferenceBlock = null;
            bool previouslyLoadedText             = false;

            //To do: add a function to automate this pre-existing check, like
            //        bool hasExistingElement<T:N64DataElement> (offset, out T)
            N64DataElement preExistingElement;

            if (RomProject.Instance.Files[0].HasElementAt(TextBankBlock.TEXT_BLOCK_START, out preExistingElement) &&
                preExistingElement.GetType() == typeof(UnknownData))
            {
                byte[] bytes = new byte[TextBankBlock.TEXT_BLOCK_LENGTH];
                Array.Copy(rawData, TextBankBlock.TEXT_BLOCK_START, bytes, 0, bytes.Length);

                textBankBlock = new TextBankBlock(TextBankBlock.TEXT_BLOCK_START, bytes);
                results.NewElements.Add(textBankBlock);
            }
            else if (preExistingElement.GetType() == typeof(TextBankBlock))
            {
                previouslyLoadedText = true;
                textBankBlock        = (TextBankBlock)preExistingElement;
            }

            if (RomProject.Instance.Files[0].HasElementAt(TextReferenceBlock.TEXT_REFERENCE_SECTION_1, out preExistingElement) &&
                preExistingElement.GetType() == typeof(UnknownData))
            {
                byte[] bytes = new byte[TextReferenceBlock.TEXT_REFERENCE_END - TextReferenceBlock.TEXT_REFERENCE_SECTION_1];
                Array.Copy(rawData, TextReferenceBlock.TEXT_REFERENCE_SECTION_1, bytes, 0, bytes.Length);

                textReferenceBlock = new TextReferenceBlock(TextReferenceBlock.TEXT_REFERENCE_SECTION_1, bytes);
                results.NewElements.Add(textReferenceBlock);
            }
            else if (preExistingElement.GetType() == typeof(TextReferenceBlock))
            {
                previouslyLoadedText = true;
                textReferenceBlock   = (TextReferenceBlock)preExistingElement;
            }

            if (textBankBlock != null && textReferenceBlock != null)
            {
                TextBank textBank = new TextBank(textBankBlock, textReferenceBlock, !previouslyLoadedText);
                results.TextBank = textBank;
            }

            TextureReader.ReadRom(worker, rawData, results);

            KartReader.ReadRom(worker, rawData, results);

            args.Result = results;
        }