private void ApplyPatch(Stream data, string patchPath) { Stream s = new FileStream(patchPath, FileMode.Open); IpsFile patch = new IpsFile(s); s.Close(); foreach (IpsRecord record in patch) { record.Apply(data); } }
private void btnPatchCreate_Click(object sender, EventArgs e) { byte[] rom = LoadFileData(lblRomPath.Text); byte[] compare = LoadFileData(lblComparePath.Text); IpsFile ips = new IpsFile(); int size = Math.Min(rom.Length, compare.Length); compareState state = compareState.LookingForDifference; int differenceStart = 0; int differenceLength; for (int i = 0; i < size; i++) { switch (state) { case compareState.LookingForDifference: if (rom[i] != compare[i]) { differenceStart = i; state = compareState.ScanningDifference; } break; case compareState.ScanningDifference: if (rom[i] == compare[i]) { differenceLength = i - differenceStart; state = compareState.LookingForDifference; byte[] data = new byte[differenceLength]; Array.Copy(rom, differenceStart, data, 0, differenceLength); ips.AddRecord(new IpsRecord(data, differenceStart)); } break; } } if (PatchSaver.ShowDialog() == DialogResult.OK) { using (FileStream fs = new FileStream(PatchSaver.FileName, FileMode.Create)){ ips.Save(fs); } lblPatchPath.Text = PatchSaver.FileName; picIps.Image = Resources.Patch; } grpPatch.ForeColor = SystemColors.WindowText; EnableApplyButtons(); }