private void buttonPatchFov_Click(object sender, EventArgs e) { PatchInfo fovPatch = VersionInfo.GetVersion(comboBoxVersion.SelectedIndex).FovPatch; bool success = Patcher.Patch(this, textBoxBin.Text, fovPatch, (float)numericUpDownDesiredFov.Value); if (success) { textBoxCurrentFov.Text = numericUpDownDesiredFov.Value.ToString(); Log("{0} patched successfully", fovPatch.Filename); } }
private void buttonScanFov_Click(object sender, EventArgs e) { PatchInfo fovPatch = VersionInfo.GetVersion(comboBoxVersion.SelectedIndex).FovPatch; float? result = Patcher.Scan(this, textBoxBin.Text, fovPatch); if (result != null) { textBoxCurrentFov.Text = result.ToString(); buttonPatchFov.Enabled = true; Log("{0} scanned successfully", fovPatch.Filename); } }
private void buttonRestoreHudFov_Click(object sender, EventArgs e) { PatchInfo hudFovPatch = VersionInfo.GetVersion(comboBoxVersion.SelectedIndex).HudFovPatch; bool success = Patcher.Restore(this, textBoxBin.Text, hudFovPatch); if (success) { textBoxCurrentHudFov.Clear(); buttonPatchHudFov.Enabled = false; Log("{0} backup restored successfully", hudFovPatch.Filename); } }
public static float?Scan(MainForm mainForm, string binPath, PatchInfo patchInfo) { string filePath = binPath + @"\" + patchInfo.Filename; if (File.Exists(filePath)) { byte[] bytes = File.ReadAllBytes(filePath); if (bytes.Length != patchInfo.Size) { mainForm.Log("Unexpected dll size; expected {0} bytes, got {1} bytes\r\nMake sure you have the correct version selected, and are not using modified dlls", patchInfo.Size, bytes.Length); return(null); } float currentHFov = BitConverter.ToSingle(bytes, patchInfo.Offset); return(currentHFov); } else { mainForm.Log("File not found: {0}", filePath); return(null); } }
public static bool Restore(MainForm mainForm, string binPath, PatchInfo patchInfo) { string filePath = binPath + @"\" + patchInfo.Filename; string bakPath = filePath + ".bak"; if (File.Exists(bakPath)) { if (File.Exists(filePath)) { try { File.Delete(filePath); } catch (UnauthorizedAccessException) { mainForm.Log("Access denied; could not delete {0}", patchInfo.Filename); return(false); } } try { File.Move(bakPath, filePath); } catch (UnauthorizedAccessException) { mainForm.Log("Access denied; could not restore {0}", patchInfo.Filename + ".bak"); return(false); } return(true); } else { mainForm.Log("There is no backup to restore"); return(false); } }
public static bool Patch(MainForm mainForm, string binPath, PatchInfo patchInfo, float desiredValue) { string filePath = binPath + @"\" + patchInfo.Filename; string bakPath = filePath + ".bak"; if (!File.Exists(bakPath)) { try { File.Copy(filePath, bakPath); } catch (UnauthorizedAccessException) { mainForm.Log("Access denied; could not backup xrGame.dll"); return(false); } } using (BinaryWriter writer = new BinaryWriter(File.Open(filePath, FileMode.Open))) { writer.Seek(patchInfo.Offset, SeekOrigin.Begin); writer.Write(desiredValue); } return(true); }
private VersionInfo(string name, PatchInfo fovPatch, PatchInfo hudFovPatch) { Name = name; FovPatch = fovPatch; HudFovPatch = hudFovPatch; }
private void buttonDefaultHudFov_Click(object sender, EventArgs e) { PatchInfo hudFovPatch = VersionInfo.GetVersion(comboBoxVersion.SelectedIndex).HudFovPatch; numericUpDownDesiredHudFov.Value = (decimal)hudFovPatch.Default; }