From 05a5df344aea5ad2cbc98d77cd1d4d39823108be Mon Sep 17 00:00:00 2001 From: AdAstra-LD Date: Fri, 12 Feb 2021 04:48:28 +0100 Subject: [PATCH] Last-minute script editor fix --- DS_Map/Main Window.cs | 1 - DS_Map/ROMFiles/ScriptFile.cs | 98 ++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 48 deletions(-) diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 41d6893..acff255 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -3632,7 +3632,6 @@ namespace DSPRE { MessageBox.Show("BackGround Sound data imported successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); BGSSizeTXT.Text = currentMapFile.bgs.Length.ToString() + " B"; } - private void soundPlatesExportButton_Click(object sender, EventArgs e) { SaveFileDialog eb = new SaveFileDialog(); eb.Filter = "BackGround Sound File (*.bgs)|*.bgs"; diff --git a/DS_Map/ROMFiles/ScriptFile.cs b/DS_Map/ROMFiles/ScriptFile.cs index ff5b4f7..ffc7d99 100644 --- a/DS_Map/ROMFiles/ScriptFile.cs +++ b/DS_Map/ROMFiles/ScriptFile.cs @@ -142,13 +142,13 @@ namespace DSPRE.ROMFiles { //once it's done, this Predicate below will be the only one needed, since there will be no distinction between //a script and a function Func functionEndCondition = - (source, x) => !source[x].TrimEnd().Equals(RomInfo.ScriptCommandNamesDict[0x0002]) //End - && !source[x].Contains(RomInfo.ScriptCommandNamesDict[0x0016] + " Function") //Jump Function_# - && !source[x].TrimEnd().Equals(RomInfo.ScriptCommandNamesDict[0x001B]); //Return + (source, x) => source[x].TrimEnd().Equals(RomInfo.ScriptCommandNamesDict[0x0002], StringComparison.InvariantCultureIgnoreCase) //End + || source[x].IndexOf(RomInfo.ScriptCommandNamesDict[0x0016] + " Function", StringComparison.InvariantCultureIgnoreCase) >= 0 //Jump Function_# + || source[x].TrimEnd().Equals(RomInfo.ScriptCommandNamesDict[0x001B], StringComparison.InvariantCultureIgnoreCase); //Return Func scriptEndCondition = - (source, x) => !source[x].TrimEnd().Equals(RomInfo.ScriptCommandNamesDict[0x0002]) //End - && !source[x].Contains(RomInfo.ScriptCommandNamesDict[0x0016] + " Function"); //Jump Function_# + (source, x) => source[x].TrimEnd().Equals(RomInfo.ScriptCommandNamesDict[0x0002], StringComparison.InvariantCultureIgnoreCase) //End + || source[x].IndexOf(RomInfo.ScriptCommandNamesDict[0x0016] + " Function") >= 0; //Jump Function_# allScripts = readCommandsFromLines(scriptLines, containerTypes.SCRIPT, scriptEndCondition); //Jump + whitespace if (allScripts == null) @@ -715,64 +715,68 @@ namespace DSPRE.ROMFiles { private List readCommandsFromLines(string[] lineSource, containerTypes containerType, Func endConditions) { List ls = new List(); - for (int i = 0; i < lineSource.Length; i++) { - int positionOfScriptNumber = lineSource[i].IndexOf('#'); - if (lineSource[i].Contains('@') && positionOfScriptNumber >= 0) { // Move on until script header is found - uint scriptNumber = uint.Parse(lineSource[i].Substring(positionOfScriptNumber + 1).Split()[0].Replace("-", "")); + try { + for (int i = 0; i < lineSource.Length; i++) { + int positionOfScriptNumber = lineSource[i].IndexOf('#'); + if (lineSource[i].Contains('@') && positionOfScriptNumber >= 0) { // Move on until script header is found + uint scriptNumber = uint.Parse(lineSource[i].Substring(positionOfScriptNumber + 1).Split()[0].Replace("-", "")); - i++; - while (lineSource[i].Length <= 0) - i++; //Skip all empty lines + i++; + while (lineSource[i].Length <= 0) + i++; //Skip all empty lines - if (lineSource[i].IndexOf("UseScript", StringComparison.InvariantCultureIgnoreCase) >= 0) { - int useScriptNumber = Int16.Parse(lineSource[i].Substring(1 + lineSource[i].IndexOf('#'))); - ls.Add(new CommandContainer(scriptNumber, containerType, useScriptNumber)); - } else { + if (lineSource[i].IndexOf("UseScript", StringComparison.InvariantCultureIgnoreCase) >= 0) { + int useScriptNumber = Int16.Parse(lineSource[i].Substring(1 + lineSource[i].IndexOf('#'))); + ls.Add(new CommandContainer(scriptNumber, containerType, useScriptNumber)); + } else { - /* Read script commands */ - List cmdList = new List(); - while (endConditions(lineSource, i)) { - ScriptCommand toAdd = new ScriptCommand(lineSource[i], i+1); - if (toAdd.id == ushort.MaxValue) - return null; + /* Read script commands */ + List cmdList = new List(); + while (!endConditions(lineSource, i)) { + ScriptCommand toAdd = new ScriptCommand(lineSource[i], i + 1); + if (toAdd.id == ushort.MaxValue) + return null; - cmdList.Add(toAdd); - i++; + cmdList.Add(toAdd); + i++; + } + cmdList.Add(new ScriptCommand(lineSource[i], i + 1)); // Add end or jump/call command + ls.Add(new CommandContainer(scriptNumber, containerType, commandList: cmdList)); } - cmdList.Add(new ScriptCommand(lineSource[i], i+1)); // Add end or jump/call command - ls.Add(new CommandContainer(scriptNumber, containerType, commandList: cmdList)); } } - } + } catch (IndexOutOfRangeException) { } return ls; } private List readActionsFromLines(string[] lineSource) { List ls = new List(); - for (int i = 0; i < lineSource.Length; i++) { - int positionOfActionNumber = lineSource[i].IndexOf('#'); - if (lineSource[i].Contains('@') && positionOfActionNumber >= 0) { // Move on until script header is found - uint actionNumber = uint.Parse(lineSource[i].Substring(positionOfActionNumber + 1).Split()[0].Replace("-", "")); + try { + for (int i = 0; i < lineSource.Length; i++) { + int positionOfActionNumber = lineSource[i].IndexOf('#'); + if (lineSource[i].Contains('@') && positionOfActionNumber >= 0) { // Move on until script header is found + uint actionNumber = uint.Parse(lineSource[i].Substring(positionOfActionNumber + 1).Split()[0].Replace("-", "")); - i++; - while (lineSource[i].Length <= 0) - i++; //Skip all empty lines - - List cmdList = new List(); - /* Read script commands */ - while (!lineSource[i].Equals(PokeDatabase.ScriptEditor.movementsDictIDName[0x00FE])) { //End - ScriptAction toAdd = new ScriptAction(lineSource[i], i+1); - if (toAdd.id == UInt16.MaxValue) - return null; - - cmdList.Add(toAdd); i++; - } - cmdList.Add(new ScriptAction(lineSource[i], i+1)); // Read and add end command + while (lineSource[i].Length <= 0) + i++; //Skip all empty lines - ls.Add(new ActionContainer(actionNumber, actionCommandsList: cmdList)); + List cmdList = new List(); + /* Read script commands */ + while (!lineSource[i].Equals(PokeDatabase.ScriptEditor.movementsDictIDName[0x00FE], StringComparison.InvariantCultureIgnoreCase)) { //End + ScriptAction toAdd = new ScriptAction(lineSource[i], i + 1); + if (toAdd.id == UInt16.MaxValue) + return null; + + cmdList.Add(toAdd); + i++; + } + cmdList.Add(new ScriptAction(lineSource[i], i + 1)); // Read and add end command + + ls.Add(new ActionContainer(actionNumber, actionCommandsList: cmdList)); + } } - } + } catch (IndexOutOfRangeException) { } return ls; } public static string OverworldFlexDecode(ushort flexID) {