From 17707fcd683d3adc91d12bd50e8d2ac32a23a9de Mon Sep 17 00:00:00 2001 From: AdAstra-LD Date: Mon, 8 Feb 2021 14:32:15 +0100 Subject: [PATCH] Fixed command entries [ID typos] and section marker detection (----- @Script_# -----) commands are now case insensitive --- DS_Map/GivePokémonDialog.cs | 2 +- DS_Map/Main Window.cs | 2 +- DS_Map/ROMFiles/ScriptAction.cs | 6 +++--- DS_Map/ROMFiles/ScriptCommand.cs | 16 +++++++--------- DS_Map/ROMFiles/ScriptFile.cs | 12 +++++------- DS_Map/Resources/PokeDatabase.cs | 8 ++++---- 6 files changed, 21 insertions(+), 25 deletions(-) diff --git a/DS_Map/GivePokémonDialog.cs b/DS_Map/GivePokémonDialog.cs index 1ceb536..02f7a8f 100644 --- a/DS_Map/GivePokémonDialog.cs +++ b/DS_Map/GivePokémonDialog.cs @@ -4,7 +4,7 @@ namespace DSPRE { public partial class GivePokémonDialog : Form { - public string command = "\nGivePokémon "; + public string command = "\nGivePokemon "; public bool okSelected; public GivePokémonDialog(string[] pokémonNames, string[] itemNames, string[] moveNames) { diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 04ab62d..97b49b9 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -5566,7 +5566,7 @@ namespace DSPRE { if (f.okSelected) { string firstLine = "SetVar 0x8004 0x" + f.itemComboBox.SelectedIndex.ToString("X"); string secondLine = "SetVar 0x8005 0x" + ((int)f.quantityNumericUpDown.Value).ToString("X"); - string thirdLine = "CallStandard 0x7FC"; + string thirdLine = "CommonScript 0x7FC"; currentScriptBox.Text = currentScriptBox.Text.Insert(currentScriptBox.SelectionStart, firstLine + "\r" + secondLine + "\r" + thirdLine); updateCurrentBoxLineNumbers(null, null); diff --git a/DS_Map/ROMFiles/ScriptAction.cs b/DS_Map/ROMFiles/ScriptAction.cs index 20b1c0b..7d86ddc 100644 --- a/DS_Map/ROMFiles/ScriptAction.cs +++ b/DS_Map/ROMFiles/ScriptAction.cs @@ -47,14 +47,14 @@ namespace DSPRE.ROMFiles { /* Get command id, which is always first in the description */ try { - id = PokeDatabase.ScriptEditor.movementsDictIDName.First(x => x.Value == nameParts[0]).Key; + id = PokeDatabase.ScriptEditor.movementsDictIDName.First(x => x.Value.Equals(nameParts[0], StringComparison.InvariantCultureIgnoreCase)).Key; } catch (InvalidOperationException) { try { id = UInt16.Parse(nameParts[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture); } catch (FormatException) { string details; - if (wholeLine.Contains('@')) { - details = "Perhaps you forgot to End the Action above it...?"; + if (wholeLine.Contains('@') && wholeLine.Contains('#')) { + details = "This probably means you forgot to \"End\" the Action above it."; } else { details = "Are you sure it's a proper Action Command?"; } diff --git a/DS_Map/ROMFiles/ScriptCommand.cs b/DS_Map/ROMFiles/ScriptCommand.cs index 8895da3..c413653 100644 --- a/DS_Map/ROMFiles/ScriptCommand.cs +++ b/DS_Map/ROMFiles/ScriptCommand.cs @@ -31,11 +31,8 @@ namespace DSPRE.ROMFiles { this.id = id; this.commandParameters = commandParameters; - Dictionary commandNamesDatabase; - commandNamesDatabase = RomInfo.scriptCommandNamesDict; - try { - name = commandNamesDatabase[id]; + name = RomInfo.scriptCommandNamesDict[id]; } catch (KeyNotFoundException) { name = id.ToString("X4"); } @@ -53,7 +50,7 @@ namespace DSPRE.ROMFiles { case 0x1C: // CompareLastResultJump case 0x1D: // CompareLastResultCall byte opcode = commandParameters[0][0]; - this.name += " " + PokeDatabase.ScriptEditor.comparisonOperators[opcode] + " " + "Function_#" + (1 + (BitConverter.ToInt32(commandParameters[1], 0))).ToString("D"); + this.name += " " + PokeDatabase.ScriptEditor.comparisonOperatorsDict[opcode] + " " + "Function_#" + (1 + (BitConverter.ToInt32(commandParameters[1], 0))).ToString("D"); break; case 0x5E: // ApplyMovement ushort flexID = BitConverter.ToUInt16(commandParameters[0], 0); @@ -88,14 +85,15 @@ namespace DSPRE.ROMFiles { /* Get command id, which is always first in the description */ try { - id = RomInfo.scriptCommandNamesDict.First(x => x.Value == nameParts[0]).Key; + id = RomInfo.scriptCommandNamesDict.First(x => x.Value.Equals(nameParts[0], StringComparison.InvariantCultureIgnoreCase)).Key; } catch (InvalidOperationException) { try { id = UInt16.Parse(nameParts[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture); } catch (FormatException) { string details; - if (wholeLine.Contains('@')) { - details = "Perhaps you forgot to End the Script or Function above it...?"; + if (wholeLine.Contains('@') && wholeLine.Contains('#')) { + details = "This probably means you forgot to \"End\" the Script or Function above it."; + details += Environment.NewLine + "Please, also note that only Functions can be terminated\nwith \"Return\"."; } else { details = "Are you sure it's a proper Script Command?"; } @@ -123,7 +121,7 @@ namespace DSPRE.ROMFiles { for (int i = 0; i < paramLength; i++) { Console.WriteLine("Parameter #" + i.ToString() + ": " + nameParts[i + 1]); try { - ushort comparisonOperator = PokeDatabase.ScriptEditor.comparisonOperators.First(x => x.Value == nameParts[i + 1]).Key; + ushort comparisonOperator = PokeDatabase.ScriptEditor.comparisonOperatorsDict.First(x => x.Value.Equals(nameParts[i + 1], StringComparison.InvariantCultureIgnoreCase)).Key; commandParameters.Add(new byte[] { (byte)comparisonOperator }); } catch { //Not a comparison int indexOfSpecialCharacter = nameParts[i + 1].IndexOfAny(new char[] { 'x', '#' }); diff --git a/DS_Map/ROMFiles/ScriptFile.cs b/DS_Map/ROMFiles/ScriptFile.cs index 2c41279..d196cd3 100644 --- a/DS_Map/ROMFiles/ScriptFile.cs +++ b/DS_Map/ROMFiles/ScriptFile.cs @@ -650,15 +650,15 @@ namespace DSPRE.ROMFiles { List ls = new List(); for (int i = 0; i < lineSource.Length; i++) { - if (lineSource[i].Contains('@')) { // Move on until script header is found - int positionOfScriptNumber = lineSource[i].IndexOf('#'); + int positionOfScriptNumber = lineSource[i].IndexOf('#'); + if (lineSource[i].Contains('@') && positionOfScriptNumber >= 0) { // Move on until script header is found int scriptNumber = Int32.Parse(lineSource[i].Substring(positionOfScriptNumber + 1).Split()[0].Replace("-", "")); i++; while (lineSource[i].Length <= 0) i++; //Skip all empty lines - if (lineSource[i].Contains("UseScript")) { + if (lineSource[i].IndexOf("UseScript", StringComparison.InvariantCultureIgnoreCase) >= 0) { int useScriptNumber = Int16.Parse(lineSource[i].Substring(1 + lineSource[i].IndexOf('#'))); ls.Add(new CommandContainer(scriptNumber, useScriptNumber)); } else { @@ -684,9 +684,8 @@ namespace DSPRE.ROMFiles { List ls = new List(); for (int i = 0; i < lineSource.Length; i++) { - - if (lineSource[i].Contains('@')) { // Move on until script header is found - int positionOfActionNumber = lineSource[i].IndexOf('#'); + int positionOfActionNumber = lineSource[i].IndexOf('#'); + if (lineSource[i].Contains('@') && positionOfActionNumber >= 0) { // Move on until script header is found int actionNumber = Int32.Parse(lineSource[i].Substring(positionOfActionNumber + 1).Split()[0].Replace("-", "")); i++; @@ -710,7 +709,6 @@ namespace DSPRE.ROMFiles { } return ls; } - public static string OverworldFlexDecode(ushort flexID) { if (flexID > 255) { return " " + "0x" + flexID.ToString("X4"); diff --git a/DS_Map/Resources/PokeDatabase.cs b/DS_Map/Resources/PokeDatabase.cs index c2ff021..ea1a623 100644 --- a/DS_Map/Resources/PokeDatabase.cs +++ b/DS_Map/Resources/PokeDatabase.cs @@ -658,7 +658,7 @@ namespace DSPRE.Resources { [0x0068] = "WaitMoveForever", [0x00FE] = "End" }; - public static Dictionary comparisonOperators = new Dictionary() { + public static Dictionary comparisonOperatorsDict = new Dictionary() { [0] = "LOWER", [1] = "EQUAL", [2] = "GREATER", @@ -906,9 +906,9 @@ namespace DSPRE.Resources { [0x011A] = "CheckPokemonGender", [0x011C] = "CheckElevatorFloor", - [0x001D] = "ElevatorBox", - [0x001E] = "SinnohDexSeen", - [0x001F] = "SinnohDexObtained", + [0x011D] = "ElevatorBox", + [0x011E] = "SinnohDexSeen", + [0x011F] = "SinnohDexObtained", [0x0120] = "NationalDexSeen", [0x0121] = "NationalDexObtained", [0x0122] = "DummyNationalDexCheck",