public void ReloadFile(int index, ASMEncodingUtility asmUtility) { PatchFile patchFile = FilePatches[index]; IList <AsmPatch> tryPatches; List <Color> fileColorList = new List <Color>(); Color normalColor = Color.White; Color errorColor = Color.FromArgb(225, 125, 125); patchFile.Patches.Clear(); if (PatchXmlReader.TryGetPatches(File.ReadAllText(patchFile.Filename, Encoding.UTF8), patchFile.Filename, asmUtility, out tryPatches)) { foreach (AsmPatch patch in tryPatches) { if (!patch.IsHidden) { Color bgColor = string.IsNullOrEmpty(patch.ErrorText) ? normalColor : errorColor; patchFile.Patches.Add(patch); fileColorList.Add(bgColor); } } LoadedCorrectly[index] = true; } else { LoadedCorrectly[index] = false; } BackgroundColors[index + 1] = fileColorList.ToArray(); FileOrdinalMaps[index] = GetFileOrdinalMap(index); }
public PatchList(string[] files, ASMEncodingUtility asmUtility) { FilePatches = new PatchFile[files.Length]; LoadedCorrectly = new bool[files.Length]; IList <AsmPatch> tryPatches; int i = 0; foreach (string file in files) { if (PatchXmlReader.TryGetPatches(File.ReadAllText(file, Encoding.UTF8), file, asmUtility, out tryPatches)) { AllPatches.AddRange(tryPatches); FilePatches[i] = new PatchFile(tryPatches.Count); FilePatches[i].filename = file; FilePatches[i].Patches.AddRange(tryPatches); LoadedCorrectly[i] = true; } else { LoadedCorrectly[i] = false; //MessageBox.Show(file.Substring(file.LastIndexOf("\\")) + " Did not load correctly"); } i++; } AllCheckStates = new CheckState[AllPatches.Count]; for (int j = 0; j < AllCheckStates.Length; j++) { AllCheckStates[j] = new CheckState(); AllCheckStates[j] = CheckState.Unchecked; } }
private void SavePatchXML() { List <AsmPatch> patches = GetAllSelectedPatches(); foreach (AsmPatch patch in patches) { patch.Update(AsmUtility); } FreeSpaceMode mode = FreeSpace.GetMode(AsmUtility); string xml = PatchXmlReader.CreatePatchXML(patches, mode); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XML file (*.xml)|*.xml"; saveFileDialog.FileName = string.Empty; saveFileDialog.CheckFileExists = false; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { btn_SavePatchXML.Enabled = false; System.IO.File.WriteAllText(saveFileDialog.FileName, xml, Encoding.UTF8); PatcherLib.MyMessageBox.Show(this, "Complete!", "Complete!", MessageBoxButtons.OK); Close(); } }
public PatchData(string[] files, ASMEncodingUtility asmUtility) { FilePatches = new PatchFile[files.Length]; LoadedCorrectly = new bool[files.Length]; IList <AsmPatch> tryPatches; List <Color> allColorList = new List <Color>(); Color normalColor = Color.White; Color errorColor = Color.FromArgb(225, 125, 125); BackgroundColors = new Color[files.Length + 1][]; for (int index = 0; index < files.Length; index++) { string file = files[index]; List <Color> fileColorList = new List <Color>(); FilePatches[index] = new PatchFile(file); if (PatchXmlReader.TryGetPatches(File.ReadAllText(file, Encoding.UTF8), file, asmUtility, out tryPatches)) { foreach (AsmPatch patch in tryPatches) { if (!patch.IsHidden) { Color bgColor = string.IsNullOrEmpty(patch.ErrorText) ? normalColor : errorColor; FilePatches[index].Patches.Add(patch); fileColorList.Add(bgColor); AllPatches.Add(patch); if (!patch.HideInDefault) { AllShownPatches.Add(patch); allColorList.Add(bgColor); } } } LoadedCorrectly[index] = true; } else { LoadedCorrectly[index] = false; } BackgroundColors[index + 1] = fileColorList.ToArray(); } BackgroundColors[0] = allColorList.ToArray(); BuildOrdinalMaps(); }
void reloadButton_Click(object sender, EventArgs e) { List <AsmPatch> result = new List <AsmPatch>(); string[] files = Directory.GetFiles(Application.StartupPath, "*.xml", SearchOption.TopDirectoryOnly); foreach (string file in files) { IList <AsmPatch> tryPatches; if (PatchXmlReader.TryGetPatches(File.ReadAllText(file, Encoding.UTF8), out tryPatches)) { result.AddRange(tryPatches); } } LoadPatches(result); }
/* * private void ModifyPatch(AsmPatch patch) * { * UpdateReferenceVariableValues(patch); * foreach (PatchedByteArray patchedByteArray in patch) * { * if (patchedByteArray.IsAsm) * { * string encodeContent = patchedByteArray.AsmText; * string strPrefix = ""; * IList<VariableType> variables = patch.Variables; * * foreach (PatchedByteArray currentPatchedByteArray in patch) * { * if (!string.IsNullOrEmpty(currentPatchedByteArray.Label)) * strPrefix += String.Format(".label @{0}, {1}\r\n", currentPatchedByteArray.Label, currentPatchedByteArray.RamOffset); * } * foreach (VariableType variable in variables) * { * strPrefix += String.Format(".eqv %{0}, {1}\r\n", ASMStringHelper.RemoveSpaces(variable.name).Replace(",", ""), AsmPatch.GetUnsignedByteArrayValue_LittleEndian(variable.byteArray)); * } * * encodeContent = strPrefix + patchedByteArray.AsmText; * //patchedByteArray.SetBytes(asmUtility.EncodeASM(encodeContent, (uint)patchedByteArray.RamOffset).EncodedBytes); * * byte[] bytes = asmUtility.EncodeASM(encodeContent, (uint)patchedByteArray.RamOffset).EncodedBytes; * * if ((!patchedByteArray.IsMoveSimple) && (patch.blockMoveList.Count > 0)) * { * bytes = asmUtility.UpdateBlockReferences(bytes, (uint)patchedByteArray.RamOffset, true, patch.blockMoveList); * } * * patchedByteArray.SetBytes(bytes); * } * } * } */ private void SavePatchXML() { string xml = PatchXmlReader.CreatePatchXML(GetCurrentFileSelectedPatches()); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XML file (*.xml)|*.xml"; saveFileDialog.FileName = string.Empty; saveFileDialog.CheckFileExists = false; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { File.WriteAllText(saveFileDialog.FileName, xml, Encoding.UTF8); PatcherLib.MyMessageBox.Show(this, "Complete!", "Complete!", MessageBoxButtons.OK); } }
private void LoadFiles(IList <string> files) { List <AsmPatch> result = new List <AsmPatch>(); foreach (string file in files) { IList <AsmPatch> tryPatches; if (PatchXmlReader.TryGetPatches(File.ReadAllText(file, Encoding.UTF8), file, asmUtility, out tryPatches)) { result.AddRange(tryPatches); } else { // MessageBox.Show(file.Substring(file.LastIndexOf("\\")) + " Did not load correctly"); } } LoadPatches(result); }
public MainForm() { InitializeComponent(); versionLabel.Text = string.Format("v0.{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString()); XmlDocument doc = new XmlDocument(); reloadButton_Click(reloadButton, EventArgs.Empty); if (patches == null || patches.Length == 0) { IList <AsmPatch> temp; if (PatchXmlReader.TryGetPatches(FFTorgASM.Properties.Resources.DefaultHacks, out temp)) { LoadPatches(temp); } } patchButton.Click += new EventHandler(patchButton_Click); reloadButton.Click += new EventHandler(reloadButton_Click); checkedListBox1.ItemCheck += new ItemCheckEventHandler(checkedListBox1_ItemCheck); patchButton.Enabled = false; checkedListBox1.SelectedIndexChanged += new EventHandler(checkedListBox1_SelectedIndexChanged); variableSpinner.ValueChanged += new EventHandler(variableSpinner_ValueChanged); variableComboBox.SelectedIndexChanged += new EventHandler(variableComboBox_SelectedIndexChanged); }