public static void ResolveUnreferencedPointers(List <Repoint> unreferenced) { Tuple <string, Pointer, int>[] pointers = new Tuple <string, Pointer, int> [unreferenced.Count]; string[] pointer_names = new string[unreferenced.Count]; for (int i = 0; i < unreferenced.Count; i++) { pointers[i] = Tuple.Create(unreferenced[i].AssetName, new Pointer(), (int)unreferenced[i].DefaultAddress); pointer_names[i] = unreferenced[i].AssetName; } FormRepoint Dialog = new FormRepoint("Unreferenced pointers to resolve", (unreferenced.Count == 1 ? "An important pointer " : ("A total of " + unreferenced.Count + " important pointers ")) + " have 0 references in this ROM - " + (unreferenced.Count == 1 ? "it" : "they") + " must have been repointed." + "\n" + "If you know the new value" + (unreferenced.Count == 1 ? " for this pointer" : "s for these pointers") + ", you can enter that in the numerical input boxes below, and click 'Repoint'." + "\n" + "Otherwise, you can click 'Cancel' to allow Emblem Magic to find the new pointer value" + (unreferenced.Count == 1 ? "s" : "") + " on its own." + "\n" + "If there are any numerical boxes left empty when clicking 'Repoint', Emblem Magic will find the value for those on its own.", pointers, 500); DialogResult answer = Dialog.ShowDialog(); Pointer address = new GBA.Pointer(); for (int i = 0; i < unreferenced.Count; i++) { if (answer == DialogResult.Cancel || Dialog.Boxes[i].Value == 0) { try { DataManager rom = new DataManager(); rom.OpenFile(Core.Path_CleanROM); address = Core.ReadPointer(rom.Find(unreferenced[i].DefaultAddress.ToBytes(), 4)); } catch (Exception ex) { Program.ShowError("Error while searching for the " + unreferenced[i].AssetName + " pointer.", ex); } } else if (answer == DialogResult.Yes) { address = Dialog.Boxes[i].Value; } unreferenced[i].CurrentAddress = address; unreferenced[i].UpdateReferences(); } }
/// <summary> /// Shows a multiple-entry repoint prompt /// </summary> /// <param name="sender">The Editor that should write the repoints</param> /// <param name="caption">The title of the prompt window</param> /// <param name="text">The text displayed in the repoint prompt window</param> /// <param name="writePrefix">The common prefix the write descriptions should have</param> /// <param name="repoints">the actual repoints, tuple is: Name, CurrentAddress, DataLength</param> /// <param name="addresses">the addresses at which to write the new pointers, if null does find+replace</param> /// <returns>'true' if the operation was cancelled</returns> public static bool ShowRepointDialog(Editor sender, string caption, string text, string writePrefix, Tuple <string, Pointer, int>[] repoints, Pointer[] addresses = null) { if (Settings.Default.WriteToFreeSpace) { int length = 0; for (int i = 0; i < repoints.Length; i++) { length += repoints[i].Item3; } Pointer[] pointers = new Pointer[repoints.Length]; pointers[0] = Core.GetFreeSpace(length); length = repoints[0].Item3; for (int i = 1; i < repoints.Length; i++) { pointers[i] = pointers[0] + length; length += repoints[i].Item3; } if (addresses == null) { for (int i = 0; i < repoints.Length; i++) { Core.Repoint(sender, repoints[i].Item2, pointers[i], writePrefix + repoints[i].Item1 + " repoint"); } } else { for (int i = 0; i < repoints.Length; i++) { Core.WritePointer(sender, addresses[i], pointers[i], writePrefix + repoints[i].Item1 + " repoint"); } } } else if (Settings.Default.PromptRepoints) { FormRepoint Dialog = new FormRepoint(caption, text, repoints); if (Dialog.ShowDialog() == DialogResult.OK) { if (addresses == null) { for (int i = 0; i < Dialog.Boxes.Length; i++) { if (Dialog.Boxes[i].Value != repoints[i].Item2) { Core.Repoint(sender, repoints[i].Item2, Dialog.Boxes[i].Value, writePrefix + repoints[i].Item1 + " repoint"); } } } else { for (int i = 0; i < Dialog.Boxes.Length; i++) { if (Dialog.Boxes[i].Value != Core.ReadPointer(addresses[i])) { Core.WritePointer(sender, addresses[i], Dialog.Boxes[i].Value, writePrefix + repoints[i].Item1 + " repoint"); } } } return(false); } else { return(true); } } return(false); }