From ffcc59ff61ac8759f20e5d8c35c4aa7dc3e6e84a Mon Sep 17 00:00:00 2001 From: AdAstra-LD Date: Tue, 16 Feb 2021 19:00:25 +0100 Subject: [PATCH] Improved Standardize Items Patch now every item is available and can be found on the ground --- DS_Map/Main Window.cs | 11 ++--------- DS_Map/ROMFiles/ScriptCommand.cs | 8 +++++++- DS_Map/ROMToolboxDialog.cs | 18 +++++++++++++++--- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 1723253..749c022 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -276,15 +276,8 @@ namespace DSPRE { owTrainerComboBox.Items.AddRange(trainerNames); /* Add item list to ow item box */ - int itemScriptId = RomInfo.itemScriptFileNumber; - try { - int count = new ScriptFile(itemScriptId).allScripts.Count - 1; - owItemComboBox.Items.AddRange(GetItemNames(0, count)); - } catch { - MessageBox.Show("There was a problem reading Script File #" + itemScriptId + ".\n" + - "It is strongly adviced that you restore this file from a clean backup.", "Item script couldn't be loaded", - MessageBoxButtons.OK, MessageBoxIcon.Error); - } + owItemComboBox.Items.AddRange(GetItemNames(0, new TextArchive(RomInfo.itemNamesTextNumber).messages.Count-1)); + /* Add ow movement list to box */ owMovementComboBox.Items.AddRange(PokeDatabase.EventEditor.Overworlds.movementsArray); diff --git a/DS_Map/ROMFiles/ScriptCommand.cs b/DS_Map/ROMFiles/ScriptCommand.cs index e08d756..12541e9 100644 --- a/DS_Map/ROMFiles/ScriptCommand.cs +++ b/DS_Map/ROMFiles/ScriptCommand.cs @@ -20,6 +20,12 @@ namespace DSPRE.ROMFiles { this.containerType = containerType; commands = commandList; } + public CommandContainer(uint newID, CommandContainer toCopy) { + manualUserID = newID; + useScript = toCopy.useScript; + containerType = toCopy.containerType; + commands = new List(toCopy.commands); //command parameters need to be copied recursively + } #endregion } public class ScriptCommand { @@ -77,7 +83,7 @@ namespace DSPRE.ROMFiles { } } - public ScriptCommand(string wholeLine, int lineNumber) { + public ScriptCommand(string wholeLine, int lineNumber = 0) { name = wholeLine; cmdParams = new List(); diff --git a/DS_Map/ROMToolboxDialog.cs b/DS_Map/ROMToolboxDialog.cs index 1dfea9b..e1254a2 100644 --- a/DS_Map/ROMToolboxDialog.cs +++ b/DS_Map/ROMToolboxDialog.cs @@ -5,6 +5,7 @@ using System.Resources; using System.Windows.Forms; using System.Linq; using DSPRE.ROMFiles; +using System.Collections.Generic; namespace DSPRE { public partial class ROMToolboxDialog : Form { @@ -415,10 +416,21 @@ namespace DSPRE { } else { ScriptFile itemScript = new ScriptFile(RomInfo.itemScriptFileNumber); - for (ushort i = 0; i < itemScript.allScripts.Count - 1; i++) { - itemScript.allScripts[i].commands[0].cmdParams[1] = BitConverter.GetBytes(i); // Fix item index - itemScript.allScripts[i].commands[1].cmdParams[1] = BitConverter.GetBytes((ushort)1); // Fix item quantity + int itemCount = new TextArchive(RomInfo.itemNamesTextNumber).messages.Count; + CommandContainer executeGive = new CommandContainer((uint)itemCount, itemScript.allScripts[itemScript.allScripts.Count-1]); + itemScript.allScripts.Clear(); + + for (ushort i = 0; i < itemCount; i++) { + List cmdList = new List(); + cmdList.Add(new ScriptCommand("SetVar 0x8008 " + i)); + cmdList.Add(new ScriptCommand("SetVar 0x8009 0x1")); + cmdList.Add(new ScriptCommand("Jump Function_#1")); + + itemScript.allScripts.Add(new CommandContainer((ushort)(i + 1), ScriptFile.containerTypes.SCRIPT, commandList: cmdList)); } + itemScript.allScripts.Add(executeGive); + //itemScript.allFunctions[1].commands[0].cmdParams[] + itemScript.SaveToFileDefaultDir(RomInfo.itemScriptFileNumber, showSuccessMessage: false); MessageBox.Show("Operation successful.", "Process completed.", MessageBoxButtons.OK, MessageBoxIcon.Information);