//Start new EVT from scratch private void newToolStripMenuItem_Click(object sender, EventArgs e) { //Re-initialize some things that may have changed if you already opened a PAK evtPath = ""; pakPath = ""; bmdPath = ""; bmd = ""; this.Text = "EVTEditor"; txt_MsgEditor.Enabled = false; evt = new EvtFile(); //Add field command to EVT to start with var command = new Command(); command.Type = "Fd__"; command.Time = trackBar.Value; command.DataSize = 64; command.Data = CommandDataFactory.Create(command.Type); evt.Commands.Add(command); //Add field object to EVT to start with var obj = new EvtObject(); obj.Type = EvtObjectType.Field; evt.Objects.Add(obj); //Enable controls AddCommandToolStripMenuItem.Visible = true; trackBar.Enabled = true; //Enable datagridviews EVTSetup(); }
//Get an EVT from a PAK and decompile event's referenced BMD private void ReadPAK(string path) { pakPath = path; using (var pak = new PAKFileSystem(FormatVersion.Version3BE)) { pak.Load(path); foreach (string file in pak.EnumerateFiles()) { var normalizedFilePath = file.Replace("../", ""); // Remove backwards relative path string filePath = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + normalizedFilePath; using (var stream = FileUtils.Create(filePath)) using (var inputStream = pak.OpenFile(file)) inputStream.CopyTo(stream); if (file.EndsWith("evt", StringComparison.InvariantCultureIgnoreCase)) { evtPath = filePath; evt = new EvtFile(evtPath); } else if (file.EndsWith("bmd", StringComparison.InvariantCultureIgnoreCase)) { bmdPath = filePath; DecompileBMD(); } } } }
//Open an EVT or Event PAK and enable controls private void openToolStripMenuItem_Click(object sender, EventArgs e) { CommonOpenFileDialog dialog = new CommonOpenFileDialog(); if (dialog.ShowDialog() == CommonFileDialogResult.Ok) { string path = dialog.FileName; if (path.EndsWith("evt", StringComparison.InvariantCultureIgnoreCase)) { evt = new EvtFile(path); } else if (path.EndsWith("pak", StringComparison.InvariantCultureIgnoreCase)) { ReadPAK(path); } else { return; } //If EVT successfully opened, enable controls this.Text = $"EVTEditor - {Path.GetFileName(path)}"; EVTSetup(); } }
//Assign new indices to Objects public EvtFile ReindexObjects(EvtFile evt) { listBox_Objects.Items.Clear(); int i = 0; foreach (EvtObject obj in evt.Objects) { listBox_Objects.Items.Add($"{obj.Type}[{i}]"); i++; } return(evt); }
//Reassign Time values and update Duration public static EvtFile ReindexCommands(EvtFile evt) { int previousValue = evt.Commands.OrderBy(x => x.Time).First().Time; int newTime = 1; foreach (var command in evt.Commands.OrderBy(x => x.Time)) { if (command.Time != previousValue) { ++newTime; previousValue = command.Time; } command.Time = newTime; } evt.Duration = newTime + 1; return(evt); }
//Update tabs and datagridview to reflect new values private void RefreshEVT() { //Save indices to try to restore location after refresh int oldTabIndex = tabControl.SelectedIndex; int oldTrackBarValue = trackBar.Value; int oldObjectSelection = listBox_Objects.SelectedIndex; //Reorder commands by time value before refreshing tabs evt = ReindexCommands(evt); //Make sure trackbar can be moved (needs a better solution later) if (evt.Duration >= 2) { trackBar.Maximum = evt.Duration; } else { trackBar.Maximum = 2; } trackBar.Minimum = 1; //Clear and refresh datagridviews/tabpages GridViewRefresh(dgv_EVTProperties); GridViewRefresh(dgv); GridViewRefresh(dgv2); GridViewRefresh(dgv_ObjectProperties); tabControl.TabPages.Clear(); tabControl.Refresh(); //Change tab index to force tabs to update, hacky workaround trackBar.Value = 2; trackBar.Value = 1; //Restore positions if possible if (trackBar.Maximum >= oldTrackBarValue && oldTrackBarValue > 0) { trackBar.Value = oldTrackBarValue; } if (tabControl.TabCount >= oldTabIndex && oldTabIndex > 0) { tabControl.SelectedIndex = oldTabIndex; } //Update EVT Properties dgv_EVTProperties.Rows.Add(new string[] { $"Version", $"{evt.Version}" }); dgv_EVTProperties.Rows.Add(new string[] { $"MajorId", $"{evt.MajorId}" }); dgv_EVTProperties.Rows.Add(new string[] { $"MinorId", $"{evt.MinorId}" }); dgv_EVTProperties.Rows.Add(new string[] { $"Duration", $"{evt.Duration}" }); //Reorder objects by Id value evt = ReindexObjects(evt); //Change selected index of objects list (needs a better solution later) if (evt.Objects.Count() >= 2) { listBox_Objects.SelectedIndex = 1; listBox_Objects.SelectedIndex = 0; } //Restore Object selection position if possible if (listBox_Objects.Items.Count >= oldObjectSelection && oldObjectSelection >= 0) { listBox_Objects.SelectedIndex = oldObjectSelection; } }