Exemplo n.º 1
0
        private void btnCreatePatch_Click(object sender, RoutedEventArgs e)
        {
            string romPath   = tbROM_c.Text;
            string patchPath = tbPatch_c.Text;

            if (File.Exists(romPath))
            {
                try
                {
                    int fileSize;
                    using (FileStream fs = new FileStream(romPath, FileMode.Open))
                    {
                        fileSize = (int)Math.Truncate((double)(fs.Length / 1000000));
                    }

                    bool valid = Patch.CheckROMBigEndian(romPath);

                    if (valid)
                    {
                        if (fileSize < 16)
                        {
                            MessageBox.Show("Are you sure this is a valid character mod?\nKeep in mind 8MB (Vanilla/Decomp) ROMs are not supported.");
                        }
                        else
                        {
                            using (FileStream fs = new FileStream(romPath, FileMode.Open, FileAccess.Read))
                            {
                                Patch.CreatePatchFile(fs, patchPath);
                                MessageBox.Show("Success", "Patch creation complete", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("The ROM doesn't appear to be a valid ROM. Please make sure to use a valid SM64 ROM (Big-Endian).", "Invalid file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while writing to the files.\n" + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("We cannot access the ROM. Please make sure it is still at its original location and try again.", "Files missing", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        private void btnPatch_Click(object sender, RoutedEventArgs e)
        {
            string romPath     = tbROM.Text;
            string patchPath   = tbPatch.Text;
            string saveRomPath = tbSaveAs.Text;

            if (File.Exists(romPath) && File.Exists(patchPath))
            {
                try
                {
                    int  fileSize;
                    bool usingTemp = false;
                    using (FileStream fs = new FileStream(romPath, FileMode.Open))
                    {
                        fileSize = (int)Math.Truncate((double)(fs.Length / 1000000));
                    }

                    bool valid = Patch.CheckROMBigEndian(romPath);

                    using (FileStream cmfs = new FileStream(patchPath, FileMode.Open, FileAccess.Read))
                    {
                        PatchInformation _pI = Patch.ReadPatchFile(cmfs);
                        if (_pI.versionMinor > 1)
                        {
                            MessageBox.Show("This CMTP file's version is not supported by this version of the patcher. You may need to update your patcher or contact GlitchyPSI.");
                            return;
                        }
                    }

                    if (valid)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            UpdateProgress(0);
                            tcMain.IsEnabled = false;
                        });

                        if (fileSize == 8)
                        {
                            MessageBoxResult _dresult = MessageBox.Show("This ROM is a 8MB ROM.\nThis patching process does NOT work with Decomp ROMs!\nAre you sure you wish to continue?", "ROM is small!", MessageBoxButton.YesNo, MessageBoxImage.Question);
                            if (_dresult == MessageBoxResult.Yes)
                            {
                                Dispatcher.Invoke(() => pbProgress.IsIndeterminate = true);
                                usingTemp = true;
                                Task prepareROM = Task.Run(async() =>
                                {
                                    try
                                    {
                                        romPath = await Task.Run(() => PrepareVanillaROM(romPath));
                                        pbProgress.Dispatcher.Invoke(() => pbProgress.IsIndeterminate = false);
                                        patchFile();
                                    }
                                    catch
                                    {
                                        MessageBox.Show("Failed to patch the ROM. You're sure this is a good ROM?", "Oh no", MessageBoxButton.OK, MessageBoxImage.Error);
                                    }
                                });
                            }
                            else
                            {
                                Dispatcher.Invoke(() =>
                                {
                                    tcMain.IsEnabled = true;
                                });
                                return;
                            }
                        }
                        if (fileSize > 8 && fileSize < 64)
                        {
                            MessageBox.Show("This ROM appears to be an older SM64 hack. This is not supported right now.", "Invalid ROM size", MessageBoxButton.OK, MessageBoxImage.Error);
                            Dispatcher.Invoke(() =>
                            {
                                tcMain.IsEnabled = true;
                            });
                            return;
                        }
                        if (fileSize > 65)
                        {
                            patchFile();
                        }
                    }
                    else
                    {
                        MessageBox.Show("The ROM doesn't appear to be a valid ROM. Please make sure to use a valid SM64 ROM.", "Invalid file", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }

                    void patchFile()
                    {
                        Dispatcher.Invoke(() =>
                        {
                            Task.Run(() =>
                            {
                                IProgress <float> progress = new Progress <float>((i) => UpdateProgress(i));
                                using (FileStream cmtp = new FileStream(patchPath, FileMode.Open, FileAccess.Read))
                                {
                                    Patch.PatchROM(romPath, cmtp, saveRomPath, progress);
                                    if (usingTemp)
                                    {
                                        File.Delete(romPath);
                                        Directory.Delete($"{AppDomain.CurrentDomain.BaseDirectory}\\temp", true);
                                    }
                                }
                                MessageBox.Show("Success", "Patching complete", MessageBoxButton.OK, MessageBoxImage.Information);
                            });
                            tcMain.IsEnabled = true;
                            UpdateProgress(4);
                        });
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while writing to the files.\n" + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("We cannot access either the ROM or the patch. Please make sure these are still at their original location and try again.", "Files missing", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }