public static bool initalize(App app) { GlobalAppData.patchInformation = null; GlobalAppData.app = app; settingsPath = getUserProfilePath(); if (settings == null) { String f = settingsFile; String d = settingsPath; if (!Directory.Exists(settingsPath)) { DirectoryInfo dInfo = Directory.CreateDirectory(settingsPath); if (!dInfo.Exists) { MessageBox.Show("Failed to create profile directory: " + settingsPath); return false; } } loadSettings(); return true; } return true; }
public static PatchInformation ReadPatchFile(Stream PatchStream) { PatchInformation pI = new PatchInformation(); byte[] magicNumber = new byte[4]; byte[] versionMajor = new byte[1]; byte[] versionMinor = new byte[1]; byte[] features = new byte[2]; PatchStream.Read(magicNumber, 0, 4); PatchStream.Read(versionMajor, 0, 1); PatchStream.Read(versionMinor, 0, 1); PatchStream.Read(features, 0, 2); if (ASCII.GetString(magicNumber) != "CMTP") { throw new ArgumentException("File provided is not a valid CometCHAR Patch."); } byte[] lenCompressed04 = new byte[4]; byte[] lenCompressedGL = new byte[4]; byte[] StartMargin = new byte[4]; byte[] len04 = new byte[4]; byte[] lenGL = new byte[4]; byte[] segAddr = new byte[4]; PatchStream.Read(lenCompressed04, 0, 4); PatchStream.Read(lenCompressedGL, 0, 4); PatchStream.Read(StartMargin, 0, 4); PatchStream.Read(len04, 0, 4); PatchStream.Read(lenGL, 0, 4); PatchStream.Read(segAddr, 0, 4); pI.versionMajor = versionMajor[0]; pI.versionMinor = versionMinor[0]; pI.Features = BitConverter.ToUInt16(features, 0); pI.compSegment04Length = BitConverter.ToUInt32(lenCompressed04, 0); pI.compGeoLayoutLength = BitConverter.ToUInt32(lenCompressedGL, 0); pI.GeoLayoutStartMargin = BitConverter.ToUInt32(StartMargin, 0); pI.Segment04Length = BitConverter.ToUInt32(len04, 0); pI.GeoLayoutLength = BitConverter.ToUInt32(lenGL, 0); pI.GeoLayoutSegOffset = BitConverter.ToUInt32(segAddr, 0); return(pI); }
public Patcher(PatchInformation patchInformation, Settings settings) { this.patchInformation = patchInformation; this.settings = settings; }
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); } }