private void btnOpenBCA_Click(object sender, EventArgs e) { bool wasRunning = m_Running; using (var form = new ROMFileSelect("Please select an animation (BCA) file to open.")) { var result = form.ShowDialog(); if (result == DialogResult.OK) { StopTimer(); m_BCA = new BCA(Program.m_ROM.GetFileFromName(form.m_SelectedFile)); txtBCAName.Text = m_BCA.m_FileName; m_AnimationFrameNumber = 0; m_AnimationNumFrames = m_BCA.m_NumFrames; txtCurrentFrameNum.Text = "" + m_AnimationFrameNumber; txtNumFrames.Text = "" + (m_BCA.m_NumFrames - 1); if (wasRunning) { StartTimer(); } } } }
private void btnSelectInternal_Click(object sender, EventArgs e) { ROMFileSelect r = new ROMFileSelect(); r.ShowDialog(); txtInput.Text = r.m_SelectedFile; }
public void RenameDir(string dirname, string newName, TreeNode root) { int index1 = (int)this.GetDirIDFromName(dirname) - 61440; if (dirname.StartsWith("ARCHIVE")) { int num = (int)MessageBox.Show("Manipulation of archives not supported", "Sorry,"); } else { int length = dirname.LastIndexOf('/') + 1; string newFullName = dirname.Substring(0, length) + newName; this.m_DirEntries[index1].Name = newName; for (int index2 = 0; index2 < this.m_DirEntries.Length; ++index2) { if (this.m_DirEntries[index2].FullName.StartsWith(dirname)) { this.m_DirEntries[index2].FullName = newFullName + this.m_DirEntries[index2].FullName.Substring(dirname.Length); } } for (int index2 = 0; index2 < this.m_FileEntries.Length; ++index2) { if (this.m_FileEntries[index2].FullName.StartsWith(dirname)) { this.m_FileEntries[index2].FullName = newFullName + this.m_FileEntries[index2].FullName.Substring(dirname.Length); } } TreeNode fileOrDir = ROMFileSelect.GetFileOrDir(dirname, root); fileOrDir.Name = fileOrDir.Text = newName; this.RenameNode(dirname, newFullName, fileOrDir); } }
public void RemoveDir(string dirname, TreeNode root) { if (dirname.StartsWith("ARCHIVE")) { int num = (int)MessageBox.Show("Manipulation of archives not supported", "Sorry,"); } else { List <int> fileIDs = new List <int>(); List <int> dirIDs = new List <int>(); for (int index = 0; index < this.m_FileEntries.Length; ++index) { if (this.m_FileEntries[index].FullName.StartsWith(dirname)) { fileIDs.Add(index); } } for (int index = 0; index < this.m_DirEntries.Length; ++index) { if (this.m_DirEntries[index].FullName.StartsWith(dirname)) { dirIDs.Add(index); } } this.RemoveFileEntriesAndCorrectIDs(fileIDs); this.RemoveDirEntriesAndCorrectIDs(dirIDs); ROMFileSelect.GetFileOrDir(dirname, root).Remove(); } }
public void RenameFile(string filename, string newName, TreeNode root) { int fileIdFromName = (int)this.GetFileIDFromName(filename); if (fileIdFromName == (int)ushort.MaxValue) { int num1 = (int)MessageBox.Show("This is a bug and shouldn't happen.", "Sorry,"); } else if (fileIdFromName >= 32768) { int num2 = (int)MessageBox.Show("Manipulation of archives not supported", "Sorry,"); } else { int length = filename.LastIndexOf('/') + 1; string str1 = filename.Substring(0, length) + newName; this.m_FileEntries[fileIdFromName].Name = newName; this.m_FileEntries[fileIdFromName].FullName = str1; TreeNode fileOrDir = ROMFileSelect.GetFileOrDir(filename, root); string str2; string str3 = str2 = newName; fileOrDir.Text = str2; fileOrDir.Name = str3; fileOrDir.Tag = (object)str1; } }
private void bMDKLCEditorToolStripMenuItem_Click(object sender, EventArgs e) { ROMFileSelect rfs = new ROMFileSelect("Select a BMD or KLC file", new string[] { ".bmd", ".klc" }); if (rfs.ShowDialog(this) == DialogResult.OK) { new BMD_KLC_Editor(rfs.m_SelectedFile).Show(); } }
private void btnSelectFile_Click(object sender, EventArgs e) { using (var form = new ROMFileSelect("Please select a file to open.")) { var result = form.ShowDialog(); if (result == DialogResult.OK) { txtApplyToFile.Text = form.m_SelectedFile; } } }
private void btnSelNSC_Click(object sender, EventArgs e) { using (var form = new ROMFileSelect("Please select a Tile (NSC) file.")) { var result = form.ShowDialog(); if (result == DialogResult.OK) { txtSelNSC.Text = form.m_SelectedFile; } } }
private void btnLoadBTP_Click(object sender, EventArgs e) { using (var form = new ROMFileSelect("Please select a BTP file to load.")) { var result = form.ShowDialog(); if (result == DialogResult.OK) { ClearBTPTextBoxes(); LoadBTP(form.m_SelectedFile); } } }
public FilesystemEditorForm(MainForm main) { this.InitializeComponent(); this.Text = "Josh65536's File System Editor"; Icon = main.Icon; this.m_ROM = Program.m_ROM; ROMFileSelect.LoadFileList(this.tvFiles); this.DialogResult = DialogResult.Ignore; if (this.m_ROM.StartFilesystemEdit()) { return; } this.Close(); }
private void btnOpen_Click(object sender, EventArgs e) { using (var form = new ROMFileSelect("Please select a collision map (KCL) file to open.")) { var result = form.ShowDialog(); if (result == DialogResult.OK) { LoadKCL((Program.m_ROM.GetFileFromName(form.m_SelectedFile))); RenderKCLMesh(); GL.DeleteLists(m_KCLMeshDLists[3], 1); m_KCLMeshDLists[3] = 0; glModelView.Refresh(); } } }
private void btnOpenBMD_Click(object sender, EventArgs e) { using (var form = new ROMFileSelect("Please select a model (BMD) file to open.")) { var result = form.ShowDialog(); if (result == DialogResult.OK) { StopTimer(); m_BMD = new BMD(Program.m_ROM.GetFileFromName(form.m_SelectedFile)); txtBMDName.Text = m_BMD.m_FileName; PrerenderModel(); } } }
/// <summary> /// Open KPS. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void openToolStripMenuItem_Click(object sender, EventArgs e) { ROMFileSelect r = new ROMFileSelect(); r.ShowDialog(); string file = r.m_SelectedFile; if (file != null && file != "") { nf = new NitroFile(Program.m_ROM, Program.m_ROM.GetFileIDFromName(file)); MemoryStream src = new MemoryStream(nf.m_Data); BinaryReader br = new BinaryReader(src); if (src.Length >= 0x10) { UInt32 magic1 = br.ReadUInt32(); UInt32 magic2 = br.ReadUInt32(); if (magic1 == 0x00100001) { if (magic2 == 0x00140018) { OpenDkl(nf.m_Data, false); } else if (magic2 == 0x0018001C) { OpenDkl(nf.m_Data, true); } else { OpenBin(nf.m_Data); } } else { OpenBin(nf.m_Data); } } else { OpenBin(nf.m_Data); } } }
public void AddSPA(List <string> filenames, List <string> fullNames, TreeNode root) { string path = "data"; this.AddFileEntriesAndCorrectIDs(path, filenames, fullNames); TreeNode fileOrDir = ROMFileSelect.GetFileOrDir(path.TrimEnd('/'), root); for (int index = 0; index < filenames.Count; ++index) { TreeNode treeNode = fileOrDir.Nodes.Add(filenames[index], filenames[index]); treeNode.Tag = (object)(path + filenames[index]); if (index == filenames.Count - 1) { treeNode.EnsureVisible(); treeNode.TreeView.SelectedNode = treeNode; } } }
public void AddFile( string path, List <string> filenames, List <string> fullNames, TreeNode root) { if (path.StartsWith("ARCHIVE")) { int num1 = (int)MessageBox.Show("Manipulation of archives not supported", "Sorry,"); } else { try { for (int index = 0; index < filenames.Count; ++index) { if (filenames[index].Length >= 128) { throw new InvalidDataException("File name \"" + filenames[index] + "\" is too long.\nMake it less than 128 letters long."); } using (FileStream fileStream = File.OpenRead(fullNames[index])) { if (fileStream.Length == 0L) { throw new InvalidDataException("The file \"" + fullNames[index] + "\" is empty."); } } } } catch (Exception ex) { int num2 = (int)MessageBox.Show(ex.Message, "File cannot be read"); return; } this.AddFileEntriesAndCorrectIDs(path, filenames, fullNames); TreeNode fileOrDir = ROMFileSelect.GetFileOrDir(path.TrimEnd('/'), root); for (int index = 0; index < filenames.Count; ++index) { TreeNode treeNode = fileOrDir.Nodes.Add(filenames[index], filenames[index]); treeNode.Tag = (object)(path + filenames[index]); if (index == filenames.Count - 1) { treeNode.EnsureVisible(); treeNode.TreeView.SelectedNode = treeNode; } } } }
public void RemoveFile(string filename, TreeNode root) { int fileIdFromName = (int)this.GetFileIDFromName(filename); if (fileIdFromName == (int)ushort.MaxValue) { int num1 = (int)MessageBox.Show("This is a bug and shouldn't happen.", "Sorry,"); } else if (fileIdFromName >= 32768) { int num2 = (int)MessageBox.Show("Manipulation of archives not supported", "Sorry,"); } else { this.AllowEmptySpaceInOv0(); this.RemoveFileEntriesAndCorrectIDs(new List <int>() { fileIdFromName }); ROMFileSelect.GetFileOrDir(filename, root).Remove(); } }
public void AddDir(string path, string newName, TreeNode root) { if (path.StartsWith("ARCHIVE")) { int num = (int)MessageBox.Show("Manipulation of archives not supported", "Sorry,"); } else { ushort dirIdFromName = this.GetDirIDFromName(path.TrimEnd('/')); Array.Resize <NitroROM.DirEntry>(ref this.m_DirEntries, this.m_DirEntries.Length + 1); NitroROM.DirEntry dirEntry; dirEntry.ID = (ushort)(this.m_DirEntries.Length - 1 + 61440); dirEntry.ParentID = dirIdFromName; dirEntry.Name = newName; dirEntry.FullName = path + newName; this.m_DirEntries[this.m_DirEntries.Length - 1] = dirEntry; TreeNode treeNode = ROMFileSelect.GetFileOrDir(path.TrimEnd('/'), root).Nodes.Add(newName, newName); treeNode.Tag = (object)(path + newName + "/"); treeNode.EnsureVisible(); treeNode.TreeView.SelectedNode = treeNode; } }
private void LoadROM(string filename) { if (!File.Exists(filename)) { MessageBox.Show("The specified file doesn't exist.", Program.AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (Program.m_ROMPath != "") { while (Program.m_LevelEditors.Count > 0) { Program.m_LevelEditors[0].Close(); } lbxLevels.Items.Clear(); Program.m_ROM.EndRW(); } Program.m_ROMPath = filename; try { Program.m_ROM = new NitroROM(Program.m_ROMPath); } catch (Exception ex) { string msg; if (ex is IOException) { msg = "The ROM couldn't be opened. Close any program that may be using it and try again."; } else { msg = "The following error occured while loading the ROM:\n" + ex.Message; } MessageBox.Show(msg, Program.AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); if (Program.m_ROM != null) { Program.m_ROM.EndRW(); } Program.m_ROMPath = ""; return; } Program.m_ROM.BeginRW(); if (Program.m_ROM.NeedsPatch()) { DialogResult res = MessageBox.Show( "This ROM needs to be patched before the editor can work with it.\n\n" + "Do you want to first make a backup of it in case the patching\n" + "operation goes wrong somehow?", Program.AppTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (res == DialogResult.Yes) { sfdSaveFile.FileName = Program.m_ROMPath.Substring(0, Program.m_ROMPath.Length - 4) + "_bak.nds"; if (sfdSaveFile.ShowDialog(this) == DialogResult.OK) { Program.m_ROM.EndRW(); File.Copy(Program.m_ROMPath, sfdSaveFile.FileName, true); } } else if (res == DialogResult.Cancel) { Program.m_ROM.EndRW(); Program.m_ROMPath = ""; return; } // switch to buffered RW mode (faster for patching) Program.m_ROM.EndRW(); Program.m_ROM.BeginRW(true); try { Program.m_ROM.Patch(); } catch (Exception ex) { MessageBox.Show( "An error occured while patching your ROM.\n" + "No changes have been made to your ROM.\n" + "Try using a different ROM. If the error persists, report it to Mega-Mario, with the details below:\n\n" + ex.Message + "\n" + ex.StackTrace, Program.AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(ex.StackTrace); Program.m_ROM.EndRW(false); Program.m_ROMPath = ""; return; } } Program.m_ROM.LoadTables(); Program.m_ROM.EndRW(); // Program.m_ShaderCache = new ShaderCache(); lbxLevels.Items.AddRange(Strings.LevelNames); this.tvFileList.Nodes.Clear(); ROMFileSelect.LoadFileList(this.tvFileList); this.tvARM9Overlays.Nodes.Clear(); ROMFileSelect.LoadOverlayList(this.tvARM9Overlays); btnASMHacking.Enabled = true; btnTools.Enabled = true; btnMore.Enabled = true; }
private void importPatchToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog o = new OpenFileDialog(); o.Filter = "SM64DSe Patch|*.sp"; o.RestoreDirectory = true; if (o.ShowDialog() == DialogResult.OK) { //Each line. var s = File.ReadAllLines(o.FileName); string basePath = Path.GetDirectoryName(o.FileName) + "/"; foreach (var l in s) { //Get parameters. string t = l; if (t.Contains("#")) { t = t.Substring(0, t.IndexOf('#')); } var p = t.Split(' '); if (p.Length == 0) { continue; } //Switch command. switch (p[0].ToLower()) { //Replace file. case "replace": if (ushort.TryParse(p[1], NumberStyles.HexNumber, CultureInfo.CurrentCulture, out _)) { Program.m_ROM.ReinsertFile(Program.m_ROM.GetFileIDFromInternalID(ushort.Parse(p[1], NumberStyles.HexNumber, CultureInfo.CurrentCulture)), File.ReadAllBytes(basePath + p[2])); } else { Program.m_ROM.ReinsertFile(Program.m_ROM.GetFileIDFromName(p[1]), File.ReadAllBytes(basePath + p[2])); } break; //Replace ARM9. case "replace_arm9": var r = Program.m_ROM; r.BeginRW(true); uint arm9addr = r.Read32(0x20); uint arm9size = r.Read32(0x2C); byte[] newArm9 = File.ReadAllBytes(basePath + p[1]); if (newArm9.Length > arm9size) { r.MakeRoom(arm9addr + arm9size, (uint)(newArm9.Length - arm9size)); r.AutoFix(0xFFFF, arm9addr + arm9size, (int)(newArm9.Length - arm9size)); } r.Write32(0x2C, (uint)newArm9.Length); r.WriteBlock(arm9addr, newArm9); r.EndRW(true); r.LoadROM(r.m_Path); break; //Replace overlay. case "replace_overlay": NitroOverlay n2 = new NitroOverlay(Program.m_ROM, uint.Parse(p[1])); n2.m_Data = File.ReadAllBytes(basePath + p[2]); n2.SaveChanges(); break; //Rename file. case "rename": if (Program.m_ROM.m_Version != NitroROM.Version.EUR) { MessageBox.Show("This is for EUR ROMs only!"); continue; } Program.m_ROM.StartFilesystemEdit(); ushort fileIdFromName; if (ushort.TryParse(p[1], NumberStyles.HexNumber, CultureInfo.CurrentCulture, out _)) { fileIdFromName = Program.m_ROM.GetFileIDFromInternalID(ushort.Parse(p[1], NumberStyles.HexNumber, CultureInfo.CurrentCulture)); } else { fileIdFromName = Program.m_ROM.GetFileIDFromName(p[1]); } string filename = Program.m_ROM.m_FileEntries[fileIdFromName].FullName; string newName = p[2]; int length = filename.LastIndexOf('/') + 1; string str1 = filename.Substring(0, length) + newName; Program.m_ROM.m_FileEntries[fileIdFromName].Name = newName; Program.m_ROM.m_FileEntries[fileIdFromName].FullName = str1; Program.m_ROM.SaveFilesystem(); this.tvFileList.Nodes.Clear(); ROMFileSelect.LoadFileList(this.tvFileList); this.tvARM9Overlays.Nodes.Clear(); ROMFileSelect.LoadOverlayList(this.tvARM9Overlays); break; //Import level XML. case "import_xml": Level lv = new Level(int.Parse(p[1])); try { LevelDataXML_Importer.ImportLevel(lv, basePath + p[2], true); } catch (InvalidDataException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { new ExceptionMessageBox("Error parsing level, changes have not been saved", ex).ShowDialog(); } Program.m_ROM.LoadROM(Program.m_ROM.m_Path); break; //Add overlay. case "add_overlay": if (Program.m_ROM.m_Version != NitroROM.Version.EUR) { MessageBox.Show("This is for EUR ROMs only!"); continue; } OverlayEditor oe = new OverlayEditor(); oe.AddOverlay(oe.Overlays.Count); var ov = oe.Overlays[oe.Overlays.Count - 1]; var overlayFile = File.ReadAllBytes(basePath + p[6]); ov.ID = (uint)(oe.Overlays.Count - 1); ov.RAMAddress = uint.Parse(p[1], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov.RAMSize = (uint)overlayFile.Length; ov.BSSSize = uint.Parse(p[4], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov.StaticInitStart = uint.Parse(p[2], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov.StaticInitEnd = uint.Parse(p[3], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov.Flags = uint.Parse(p[5], NumberStyles.HexNumber, CultureInfo.CurrentCulture); oe.Overlays[oe.Overlays.Count - 1] = ov; oe.saveChangesButton_Click(null, new EventArgs()); oe.closeButton_Click(null, new EventArgs()); NitroOverlay n = new NitroOverlay(Program.m_ROM, (uint)(oe.Overlays.Count - 1)); n.m_Data = overlayFile; n.SaveChanges(); this.tvFileList.Nodes.Clear(); ROMFileSelect.LoadFileList(this.tvFileList); this.tvARM9Overlays.Nodes.Clear(); ROMFileSelect.LoadOverlayList(this.tvARM9Overlays); break; //Edit overlay. case "edit_overlay": if (Program.m_ROM.m_Version != NitroROM.Version.EUR) { MessageBox.Show("This is for EUR ROMs only!"); continue; } Program.m_ROM.StartFilesystemEdit(); var ov2 = Program.m_ROM.m_OverlayEntries[int.Parse(p[1])]; ov2.RAMAddress = uint.Parse(p[2], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov2.BSSSize = uint.Parse(p[5], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov2.StaticInitStart = uint.Parse(p[3], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov2.StaticInitEnd = uint.Parse(p[4], NumberStyles.HexNumber, CultureInfo.CurrentCulture); ov2.Flags = uint.Parse(p[6], NumberStyles.HexNumber, CultureInfo.CurrentCulture); Program.m_ROM.m_OverlayEntries[int.Parse(p[1])] = ov2; Program.m_ROM.SaveFilesystem(); break; //Delete overlay. case "delete_overlay": if (Program.m_ROM.m_Version != NitroROM.Version.EUR) { MessageBox.Show("This is for EUR ROMs only!"); continue; } OverlayEditor oe2 = new OverlayEditor(); oe2.DeleteOverlay(int.Parse(p[1])); oe2.saveChangesButton_Click(null, new EventArgs()); oe2.closeButton_Click(null, new EventArgs()); break; } } } }