mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-05-11 22:44:48 -05:00
large refactoring of script parsing logic. now uses ScriptParameter class and loads parameters right from database
This commit is contained in:
parent
84b2c1854a
commit
d4149bb5f1
|
|
@ -90,6 +90,9 @@ namespace DSPRE.Editors
|
|||
if (scriptEditorIsReady && !force) { return; }
|
||||
scriptEditorIsReady = true;
|
||||
this._parent = parent;
|
||||
ScriptDatabase.InitializePokemonNames();
|
||||
ScriptDatabase.InitializeItemNames();
|
||||
ScriptDatabase.InitializeMoveNames();
|
||||
SetupScriptEditorTextAreas();
|
||||
/* Extract essential NARCs sub-archives*/
|
||||
Helpers.statusLabelMessage("Setting up Script Editor...");
|
||||
|
|
@ -98,9 +101,6 @@ namespace DSPRE.Editors
|
|||
populate_selectScriptFileComboBox(0);
|
||||
UpdateScriptNumberCheckBox((NumberStyles)SettingsManager.Settings.scriptEditorFormatPreference);
|
||||
Helpers.statusLabelMessage();
|
||||
ScriptDatabase.InitializePokemonNames();
|
||||
ScriptDatabase.InitializeItemNames();
|
||||
ScriptDatabase.InitializeMoveNames();
|
||||
}
|
||||
public void OpenScriptEditor(MainProgram parent, int scriptFileID)
|
||||
{
|
||||
|
|
@ -122,6 +122,7 @@ namespace DSPRE.Editors
|
|||
" " + String.Join(" ", ScriptDatabase.pokemonNames.Values) +
|
||||
" " + String.Join(" ", ScriptDatabase.itemNames.Values) +
|
||||
" " + String.Join(" ", ScriptDatabase.moveNames.Values) +
|
||||
" " + String.Join(" ", ScriptDatabase.soundNames.Values) +
|
||||
" " + ScriptFile.ContainerTypes.Script.ToString() +
|
||||
" " + ScriptFile.ContainerTypes.Function.ToString() +
|
||||
" " + ScriptFile.ContainerTypes.Action.ToString() +
|
||||
|
|
|
|||
|
|
@ -8,534 +8,53 @@ using System.Windows.Forms;
|
|||
|
||||
namespace DSPRE.ROMFiles {
|
||||
public class ScriptCommand {
|
||||
enum ParamTypeEnum {
|
||||
INTEGER,
|
||||
VARIABLE,
|
||||
FLEX,
|
||||
OW_ID,
|
||||
OW_MOVEMENT_TYPE,
|
||||
OW_DIRECTION,
|
||||
FUNCTION_ID,
|
||||
ACTION_ID,
|
||||
CMD_NUMBER,
|
||||
POKEMON_NAME,
|
||||
ITEM_NAME,
|
||||
MOVE_NAME
|
||||
};
|
||||
|
||||
public ushort? id;
|
||||
public List<byte[]> cmdParams;
|
||||
public string name;
|
||||
|
||||
// CHANGE: Update the constructor to use ScriptParameter
|
||||
public ScriptCommand(ushort id, List<byte[]> parametersList)
|
||||
public ScriptCommand(ushort id, List<byte[]> parameterData)
|
||||
{
|
||||
if (parametersList is null)
|
||||
{
|
||||
this.id = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!RomInfo.ScriptCommandNamesDict.TryGetValue(id, out name)) {
|
||||
name = FormatNumber(id, ParamTypeEnum.CMD_NUMBER);
|
||||
}
|
||||
|
||||
switch (id) {
|
||||
case 0x0016: // Jump
|
||||
case 0x001A: // Call
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.FUNCTION_ID)}";
|
||||
break;
|
||||
case 0x0017: // JumpIfObjID
|
||||
case 0x0018: // JumpIfEventID
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1])}";
|
||||
break;
|
||||
case 0x0019: // JumpIfPlayerDir
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_DIRECTION)} {FormatNumber(parametersList[1], ParamTypeEnum.FUNCTION_ID)}";
|
||||
break;
|
||||
case 0x001C: // JumpIf
|
||||
case 0x001D: // CallIf
|
||||
{
|
||||
string number = FormatNumber(parametersList[1], ParamTypeEnum.FUNCTION_ID);
|
||||
|
||||
// Access the byte value from the parameter's raw data
|
||||
if (RomInfo.ScriptComparisonOperatorsDict.TryGetValue(parametersList[0][0], out string v)) {
|
||||
name += $" {v} {number}";
|
||||
} else {
|
||||
name += $" {parametersList[0][0]} {number}";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x005E: // Movement
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1], ParamTypeEnum.ACTION_ID)}";
|
||||
break;
|
||||
case 0x006A: // GetOverworldPosition
|
||||
name += FormatCmd_Overworld_TwoParams(parametersList);
|
||||
break;
|
||||
case 0x0062: // Lock
|
||||
case 0x0063: // Release
|
||||
case 0x0064: // AddOW
|
||||
case 0x0065: // RemoveOW
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)}";
|
||||
break;
|
||||
case 0x006D: // SetOverworldMovement
|
||||
name += FormatCmd_Overworld_Move(parametersList);
|
||||
break;
|
||||
|
||||
case 0x004C: // PlayCry
|
||||
name += FormatCmd_par0Pokemonpar1Generic(parametersList);
|
||||
break;
|
||||
|
||||
case 0x0083: // SetStarter [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.POKEMON_NAME)}";
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0089: // GivePokemon [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_GivePokemonHGSS(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00B0: // Warp [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Warp(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 0x008A: // GivePokemonEgg [HGSS]
|
||||
case 0x00F9: // WildBattle [HGSS]
|
||||
case 0x00FA: // WildBattleNoButtons [HGSS]
|
||||
case 0x01C4: // ShowPokemonPic [HGSS]
|
||||
case 0x0205: // CheckPokemonInParty [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_par0Pokemonpar1Generic(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0081: // CheckItemIsMachine [HGSS]
|
||||
case 0x0082: // GetItemPocket [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_par0Itempar1Generic(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x008B: // ReplaceMove [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_ReplaceMove(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x008C: // CheckPokemonHasMove [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_CheckPokemonHasMove(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x008D: // CheckMoveInParty [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_CheckMoveInParty(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00C2: // TextItem [HGSS]
|
||||
case 0x00C4: // TextMachineMove [HGSS]
|
||||
case 0x01B0: // CheckFossilPokemon [HGSS]
|
||||
case 0x034B: // TextItemLowercase [HGSS]
|
||||
case 0x034C: // TextItemPlural [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_par0Genericpar1Item(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00CA: // TextPokemon [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_TextPokemon(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0185: // CheckBornPokemonInParty [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_par0Genericpar1Pokemon(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0152: // SetOverworldDefaultPosition [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_TwoParams(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0153: // SetOverworldPosition [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_3Coords_Dir(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0154: // SetOverworldDefaultMovement [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_Move(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01B1: // CheckFossil [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_CheckFossil(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x024D: // WildBattleSp [HGSS]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_par0Pokemonpar1Genericpar2Generic(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x007E: // TakeItem [HGSS] or CheckItem [DPPt]
|
||||
case 0x007D: // GiveItem [HGSS] or CheckItemSpace [DPPt]
|
||||
name += FormatCmd_TakeItem(parametersList);
|
||||
break;
|
||||
|
||||
case 0x007F: // CheckItemSpace [HGSS] or CheckItemIsMachine [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_TakeItem(parametersList);
|
||||
} else if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_par0Itempar1Generic(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0080: // CheckItem [HGSS] or GetItemPocket [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_TakeItem(parametersList);
|
||||
} else if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_par0Itempar1Generic(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00D3: // GetSwarmInfo [HGSS] or TextMachineMove [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_par0Genericpar1Pokemon(parametersList);
|
||||
} else if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_par0Genericpar1Item(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x007B: // GiveItem [DPPt]
|
||||
case 0x007C: // TakeItem [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_TakeItem(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0155: // SetOverworldDefaultDirection [DPPt]
|
||||
case 0x0158: // SetOverworldDirection [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += FormatCmd_Overworld_Dir(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0097: // GivePokemonEgg [DPPt]
|
||||
case 0x0124: // WildBattle [DPPt]
|
||||
case 0x0208: // ShowPokemonPic [DPPt]
|
||||
case 0x0262: // CheckPokemonInParty [DPPt]
|
||||
case 0x02BD: // WildBattleSp [DPPt]
|
||||
case 0x02DD: // GetBornPokemonPartyPos [DPPt]
|
||||
case 0x0319: // GiratinaBattle [DPPt]
|
||||
case 0x0337: // CheckPokemonIsSeen [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_par0Pokemonpar1Generic(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0096: // GivePokemon [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_GivePokemonDPPt(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0099: // CheckMove [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_CheckMove(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x009A: // CheckMoveInParty [DPPt]
|
||||
case 0x00D4: // TextMove [DPPt]
|
||||
case 0x0224: // TeachMoveScreen [DPPt]
|
||||
case 0x02E7: // LearnMoveScreen [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_par0Genericpar1Move(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00BE: // Warp [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Warp(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00DA: // TextPokemon [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_TextPokemon(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00E3: // GetSwarmInfo [DPPt]
|
||||
case 0x01C0: // CheckBornPokemonInParty [DPPt]
|
||||
case 0x0217: // GetAmitySquareAccessory [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_par0Genericpar1Pokemon(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x00D1: // TextItem [DPPt]
|
||||
case 0x01F4: // CheckFossilPokemon [DPPt]
|
||||
case 0x033C: // TextItemLowercase [DPPt]
|
||||
case 0x033D: // TextItemPlural [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_par0Genericpar1Item(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x017B: // TextBerry [DPPt]
|
||||
case 0x01F5: // CheckFossil [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_CheckFossil(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0182: // SetBerryMulch [DPPt]
|
||||
case 0x0183: // SetBerrySpecies [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.HGSS)) {
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.ITEM_NAME)}";
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0186: // SetOverworldDefaultPosition [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_TwoParams(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0187: // SetOverworldPosition [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_3Coords_Dir(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0188: // SetOverworldDefaultMovement [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_Move(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0189: // SetOverworldDefaultDirection [DPPt]
|
||||
case 0x018C: // SetOverworldDirection [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_Overworld_Dir(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02E9: // ChangePartyPokemonMove [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_ChangePartyPokemonMove(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02EA: // CheckAffordMove [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.MOVE_NAME)} {FormatNumber(parametersList[1], ParamTypeEnum.MOVE_NAME)}";
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02EB: // PayTutorShards [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.MOVE_NAME)}";
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x02EC: // ShowMovePriceBoard [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += FormatCmd_ShowMovePriceBoard(parametersList);
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x031A: // RegisterSeenPokemon [DPPt]
|
||||
if (RomInfo.gameFamily.Equals(RomInfo.GameFamilies.DP) || RomInfo.gameFamily.Equals(RomInfo.GameFamilies.Plat)) {
|
||||
name += $" {FormatNumber(parametersList[0], ParamTypeEnum.POKEMON_NAME)}";
|
||||
} else {
|
||||
goto default;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
for (int i = 0; i < parametersList.Count; i++) {
|
||||
name += $" {FormatNumber(parametersList[i])}";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
this.cmdParams = parametersList;
|
||||
}
|
||||
cmdParams = parameterData;
|
||||
|
||||
private string FormatCmd_Warp(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])} {FormatNumber(parametersList[3])} {FormatNumber(parametersList[4], ParamTypeEnum.OW_DIRECTION)}";
|
||||
}
|
||||
// Get command name
|
||||
if (!RomInfo.ScriptCommandNamesDict.TryGetValue(id, out name))
|
||||
{
|
||||
name = $"CMD_{id:X3}";
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_TwoParams(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])}";
|
||||
}
|
||||
// Get parameter types
|
||||
List<ScriptParameter.ParameterType> paramTypes = null;
|
||||
switch (RomInfo.gameFamily)
|
||||
{
|
||||
case RomInfo.GameFamilies.DP:
|
||||
ScriptDatabase.DPScrCmdParameterTypes.TryGetValue(id, out paramTypes);
|
||||
break;
|
||||
case RomInfo.GameFamilies.Plat:
|
||||
ScriptDatabase.PlatScrCmdParameterTypes.TryGetValue(id, out paramTypes);
|
||||
break;
|
||||
case RomInfo.GameFamilies.HGSS:
|
||||
ScriptDatabase.HGSSScrCmdParameterTypes.TryGetValue(id, out paramTypes);
|
||||
break;
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_Move(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1], ParamTypeEnum.OW_MOVEMENT_TYPE)}";
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_3Coords_Dir(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])} {FormatNumber(parametersList[3])} {FormatNumber(parametersList[4], ParamTypeEnum.OW_DIRECTION)}";
|
||||
}
|
||||
|
||||
private string FormatCmd_Overworld_Dir(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.OW_ID)} {FormatNumber(parametersList[1], ParamTypeEnum.OW_DIRECTION)}";
|
||||
}
|
||||
// generic formatting command for playcry, showpokemonpic etc, first param is species, second param is a generic integer
|
||||
private string FormatCmd_par0Pokemonpar1Generic(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.POKEMON_NAME)} {FormatNumber(parametersList[1])}";
|
||||
}
|
||||
private string FormatCmd_par0Itempar1Generic(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.ITEM_NAME)} {FormatNumber(parametersList[1])}";
|
||||
}
|
||||
private string FormatCmd_par0Genericpar1Item(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.ITEM_NAME)}";
|
||||
}
|
||||
private string FormatCmd_par0Genericpar1Pokemon(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.POKEMON_NAME)}";
|
||||
}
|
||||
private string FormatCmd_par0Pokemonpar1Genericpar2Generic(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.POKEMON_NAME)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])}";
|
||||
}
|
||||
private string FormatCmd_TakeItem(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.ITEM_NAME)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2])}";
|
||||
}
|
||||
private string FormatCmd_ReplaceMove(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2], ParamTypeEnum.MOVE_NAME)}";
|
||||
}
|
||||
private string FormatCmd_CheckPokemonHasMove(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.MOVE_NAME)} {FormatNumber(parametersList[2])}";
|
||||
}
|
||||
private string FormatCmd_CheckMoveInParty(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.MOVE_NAME)}";
|
||||
}
|
||||
private string FormatCmd_TextPokemon(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.POKEMON_NAME)} {FormatNumber(parametersList[2])} {FormatNumber(parametersList[3])}";
|
||||
}
|
||||
private string FormatCmd_GivePokemonHGSS(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.POKEMON_NAME)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2], ParamTypeEnum.ITEM_NAME)} {FormatNumber(parametersList[3])} {FormatNumber(parametersList[4])} {FormatNumber(parametersList[5])}";
|
||||
}
|
||||
private string FormatCmd_GivePokemonDPPt(List<byte[]> parametersList) {
|
||||
return $" {FormatNumber(parametersList[0], ParamTypeEnum.POKEMON_NAME)} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2], ParamTypeEnum.ITEM_NAME)} {FormatNumber(parametersList[3])}";
|
||||
}
|
||||
private string FormatCmd_CheckFossil(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.ITEM_NAME)} {FormatNumber(parametersList[2])}";
|
||||
}
|
||||
private string FormatCmd_CheckMove(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.MOVE_NAME)} {FormatNumber(parametersList[2])}";
|
||||
}
|
||||
private string FormatCmd_par0Genericpar1Move(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1], ParamTypeEnum.MOVE_NAME)}";
|
||||
}
|
||||
private string FormatCmd_ChangePartyPokemonMove(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2], ParamTypeEnum.MOVE_NAME)}";
|
||||
}
|
||||
private string FormatCmd_ShowMovePriceBoard(List<byte[]> parametersList)
|
||||
{
|
||||
return $" {FormatNumber(parametersList[0])} {FormatNumber(parametersList[1])} {FormatNumber(parametersList[2], ParamTypeEnum.MOVE_NAME)} {FormatNumber(parametersList[3])}";
|
||||
// Format parameters based on their types
|
||||
if (paramTypes != null && parameterData != null)
|
||||
{
|
||||
for (int i = 0; i < Math.Min(paramTypes.Count, parameterData.Count); i++)
|
||||
{
|
||||
var param = new ScriptParameter(parameterData[i], paramTypes[i]);
|
||||
name += " " + param.DisplayValue;
|
||||
}
|
||||
}
|
||||
else if (parameterData != null)
|
||||
{
|
||||
foreach (var param in parameterData)
|
||||
{
|
||||
name += " " + new ScriptParameter(param, ScriptParameter.ParameterType.Integer).DisplayValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptCommand(string wholeLine, int lineNumber = 0) {
|
||||
|
|
@ -642,7 +161,9 @@ namespace DSPRE.ROMFiles {
|
|||
} else { //Not a comparison
|
||||
/* Convert strings of parameters to the correct datatypes */
|
||||
NumberStyles numStyle = nameParts[i + 1].GetNumberStyle();
|
||||
nameParts[i + 1] = nameParts[i + 1].PurgeSpecial(ScriptFile.specialChars);
|
||||
if (!nameParts[i + 1].StartsWith("SEQ_")) {
|
||||
nameParts[i + 1] = nameParts[i + 1].PurgeSpecial(ScriptFile.specialChars);
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
|
|
@ -690,10 +211,18 @@ namespace DSPRE.ROMFiles {
|
|||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"Argument {paramToCheck} couldn't be parsed as a valid Condition, Overworld ID, Direction ID, Pokemon ID, Item ID, Move ID, Script, Function or Action number.\n\n" +
|
||||
var sound = ScriptDatabase.soundNames.FirstOrDefault(x => x.Value.IgnoreCaseEquals(paramToCheck));
|
||||
if (!string.IsNullOrWhiteSpace(sound.Value))
|
||||
{
|
||||
result = sound.Key;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show($"Argument {paramToCheck} couldn't be parsed as a valid Condition, Overworld ID, Direction ID, Pokemon ID, Item ID, Move ID, Sound ID, Script, Function or Action number.\n\n" +
|
||||
$"Line {lineNumber}: {wholeLine}", "Invalid identifier", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
id = null;
|
||||
return;
|
||||
id = null;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -819,22 +348,24 @@ namespace DSPRE.ROMFiles {
|
|||
{
|
||||
return pokemon.Value;
|
||||
}
|
||||
|
||||
// Then check for Item names
|
||||
var item = ScriptDatabase.itemNames.FirstOrDefault(x =>
|
||||
x.Value.IgnoreCaseEquals(contentWithSpaces));
|
||||
if (!string.IsNullOrWhiteSpace(item.Value))
|
||||
{
|
||||
return item.Value;
|
||||
}
|
||||
|
||||
// Then check for Move names
|
||||
var move = ScriptDatabase.moveNames.FirstOrDefault(x =>
|
||||
x.Value.IgnoreCaseEquals(contentWithSpaces));
|
||||
if (!string.IsNullOrWhiteSpace(move.Value))
|
||||
{
|
||||
return move.Value;
|
||||
}
|
||||
var sound = ScriptDatabase.soundNames.FirstOrDefault(x =>
|
||||
x.Value.IgnoreCaseEquals(contentWithSpaces));
|
||||
if (!string.IsNullOrWhiteSpace(sound.Value))
|
||||
{
|
||||
return sound.Value;
|
||||
}
|
||||
|
||||
// If it's a number in brackets, provide suggestions
|
||||
if (int.TryParse(content, out int numericValue))
|
||||
|
|
@ -852,6 +383,10 @@ namespace DSPRE.ROMFiles {
|
|||
{
|
||||
suggestion = $"\nDid you mean [{moveName}]?";
|
||||
}
|
||||
else if (ScriptDatabase.soundNames.TryGetValue((ushort)numericValue, out string soundName))
|
||||
{
|
||||
suggestion = $"\nDid you mean [{soundName}]?";
|
||||
}
|
||||
throw new ArgumentException($"Invalid syntax: Numbers should not be wrapped in brackets: '{parameter}'{suggestion}");
|
||||
}
|
||||
|
||||
|
|
@ -860,172 +395,25 @@ namespace DSPRE.ROMFiles {
|
|||
{
|
||||
throw new ArgumentException($"'{parameter}' is not a valid Item name.\nDid you mean [{closestItem}]?");
|
||||
}
|
||||
|
||||
string closestPokemon = FindClosestMatch(contentWithSpaces, ScriptDatabase.pokemonNames.Values);
|
||||
if (!string.IsNullOrWhiteSpace(closestPokemon))
|
||||
{
|
||||
throw new ArgumentException($"'{parameter}' is not a valid Pokemon name.\nDid you mean [{closestPokemon}]?");
|
||||
}
|
||||
|
||||
string closestMove = FindClosestMatch(contentWithSpaces, ScriptDatabase.moveNames.Values);
|
||||
if (!string.IsNullOrWhiteSpace(closestMove))
|
||||
{
|
||||
throw new ArgumentException($"'{parameter}' is not a valid Move name.\nDid you mean [{closestMove}]?");
|
||||
}
|
||||
string closestSound = FindClosestMatch(contentWithSpaces, ScriptDatabase.soundNames.Values);
|
||||
if (!string.IsNullOrWhiteSpace(closestSound))
|
||||
{
|
||||
throw new ArgumentException($"'{parameter}' is not a valid Sound name.\nDid you mean [{closestSound}]?");
|
||||
}
|
||||
|
||||
return contentWithSpaces;
|
||||
}
|
||||
|
||||
|
||||
private string FormatNumber(byte[] par, ParamTypeEnum paramType = ParamTypeEnum.INTEGER) {
|
||||
//number acquisition
|
||||
uint num;
|
||||
if (par.Length == 0) {
|
||||
return "";
|
||||
} else if (par.Length == 1) {
|
||||
num = par[0];
|
||||
} else if (par.Length == 2) {
|
||||
num = BitConverter.ToUInt16(par, 0);
|
||||
} else if (par.Length == 4) {
|
||||
num = BitConverter.ToUInt32(par, 0);
|
||||
} else {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
return FormatNumber(num, paramType);
|
||||
}
|
||||
|
||||
private string FormatNumber(uint num, ParamTypeEnum paramType = ParamTypeEnum.INTEGER) {
|
||||
//differentiate depending on param type
|
||||
string formatOverride;
|
||||
string prefix;
|
||||
|
||||
if (SettingsManager.Settings.scriptEditorFormatPreference == (int)NumberStyles.HexNumber) {
|
||||
formatOverride = "X";
|
||||
prefix = "0x";
|
||||
} else { //(Properties.Settings.Default.scriptEditorFormatPreference == NumberStyles.Integer)
|
||||
formatOverride = "D";
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
string outp = "";
|
||||
|
||||
switch (paramType) {
|
||||
case ParamTypeEnum.CMD_NUMBER:
|
||||
return "CMD_" + prefix + num.ToString(formatOverride + '3');
|
||||
|
||||
case ParamTypeEnum.FUNCTION_ID:
|
||||
return ScriptFile.ContainerTypes.Function.ToString() + "#" + num;
|
||||
|
||||
case ParamTypeEnum.ACTION_ID:
|
||||
return ScriptFile.ContainerTypes.Action.ToString() + "#" + num;
|
||||
|
||||
case ParamTypeEnum.OW_MOVEMENT_TYPE:
|
||||
if (num < 4000) {
|
||||
outp += "Move.";
|
||||
}
|
||||
|
||||
goto default;
|
||||
|
||||
case ParamTypeEnum.OW_ID: {
|
||||
if (ScriptDatabase.specialOverworlds.TryGetValue((ushort)num, out string output)) {
|
||||
return output;
|
||||
} else {
|
||||
if (num < 4000) {
|
||||
outp += $"{Event.EventType.Overworld}.";
|
||||
}
|
||||
|
||||
goto default;
|
||||
}
|
||||
}
|
||||
case ParamTypeEnum.OW_DIRECTION: {
|
||||
if (ScriptDatabase.overworldDirections.TryGetValue((byte)num, out string output)) {
|
||||
return output;
|
||||
} else {
|
||||
if (num < 4000) {
|
||||
outp += $"Direction.";
|
||||
}
|
||||
|
||||
goto default;
|
||||
}
|
||||
}
|
||||
case ParamTypeEnum.POKEMON_NAME:
|
||||
{
|
||||
if (ScriptDatabase.pokemonNames.TryGetValue((ushort)num, out string output))
|
||||
{
|
||||
return $"[{output}]"; // Return the already-bracketed name directly
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num < 4000)
|
||||
{
|
||||
outp += $"Pokemon.";
|
||||
}
|
||||
goto default;
|
||||
}
|
||||
}
|
||||
case ParamTypeEnum.ITEM_NAME:
|
||||
{
|
||||
if (ScriptDatabase.itemNames.TryGetValue((ushort)num, out string output))
|
||||
{
|
||||
return $"[{output}]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num < 4000)
|
||||
{
|
||||
outp += $"Item.";
|
||||
}
|
||||
|
||||
goto default;
|
||||
}
|
||||
}
|
||||
case ParamTypeEnum.MOVE_NAME:
|
||||
{
|
||||
if (ScriptDatabase.moveNames.TryGetValue((ushort)num, out string output))
|
||||
{
|
||||
return $"[{output}]";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num < 4000)
|
||||
{
|
||||
outp += $"Move.";
|
||||
}
|
||||
|
||||
goto default;
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (SettingsManager.Settings.scriptEditorFormatPreference == (int)NumberStyles.None) {
|
||||
if (num >= 4000) {
|
||||
formatOverride = "X";
|
||||
prefix = "0x";
|
||||
}
|
||||
}
|
||||
|
||||
outp += prefix + num.ToString(formatOverride);
|
||||
break;
|
||||
}
|
||||
|
||||
return outp;
|
||||
}
|
||||
|
||||
private string FormatParameter(ScriptParameter param, ParamTypeEnum paramType = ParamTypeEnum.INTEGER) {
|
||||
// For jump-to-label parameters, return the label name
|
||||
if (param.Type == ScriptParameter.ParameterType.RelativeJump && !string.IsNullOrEmpty(param.TargetLabel)) {
|
||||
return param.TargetLabel;
|
||||
}
|
||||
|
||||
// Otherwise handle the numeric value
|
||||
return FormatNumber(param.RawData, paramType);
|
||||
}
|
||||
public override string ToString() {
|
||||
return name + " (" + ((ushort)id).ToString("X") + ")";
|
||||
}
|
||||
|
||||
private string FormatLabelReference(string labelName) {
|
||||
return labelName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
using DSPRE;
|
||||
using DSPRE.Resources;
|
||||
using DSPRE.ROMFiles;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using static DSPRE.RomInfo;
|
||||
|
||||
public static class ScriptDatabaseJsonLoader
|
||||
|
|
@ -59,6 +55,7 @@ public static class ScriptDatabaseJsonLoader
|
|||
|
||||
Dictionary<ushort, string> namesDict;
|
||||
Dictionary<ushort, byte[]> paramsDict;
|
||||
Dictionary<ushort, string> soundsDict = ScriptDatabase.soundNames;
|
||||
|
||||
switch (gameVersion)
|
||||
{
|
||||
|
|
@ -66,26 +63,23 @@ public static class ScriptDatabaseJsonLoader
|
|||
namesDict = ScriptDatabase.PlatScrCmdNames;
|
||||
paramsDict = ScriptDatabase.PlatScrCmdParameters;
|
||||
break;
|
||||
|
||||
case GameVersions.Diamond:
|
||||
case GameVersions.Pearl:
|
||||
namesDict = ScriptDatabase.DPScrCmdNames;
|
||||
paramsDict = ScriptDatabase.DPScrCmdParameters;
|
||||
break;
|
||||
|
||||
case GameVersions.HeartGold:
|
||||
case GameVersions.SoulSilver:
|
||||
namesDict = ScriptDatabase.HGSSScrCmdNames;
|
||||
paramsDict = ScriptDatabase.HGSSScrCmdParameters;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(gameVersion), gameVersion, "Unsupported game");
|
||||
}
|
||||
|
||||
JsonElement scrRoot;
|
||||
if (!root.TryGetProperty("scrcmd", out scrRoot))
|
||||
throw new InvalidOperationException("JSON is missing the \"scrcmd\" key");
|
||||
if (!root.TryGetProperty("scrcmd", out scrRoot))
|
||||
throw new InvalidOperationException("JSON is missing the \"scrcmd\" key");
|
||||
|
||||
Console.WriteLine("About to load scrcmd entries:");
|
||||
foreach (JsonProperty prop in scrRoot.EnumerateObject())
|
||||
|
|
@ -103,6 +97,91 @@ public static class ScriptDatabaseJsonLoader
|
|||
.ToArray();
|
||||
paramsDict[code] = bytes;
|
||||
}
|
||||
|
||||
JsonElement soundsRoot;
|
||||
if (!root.TryGetProperty("sounds", out soundsRoot))
|
||||
throw new InvalidOperationException("JSON is missing the \"sounds\" key");
|
||||
|
||||
foreach (JsonProperty prop in soundsRoot.EnumerateObject())
|
||||
{
|
||||
if (ushort.TryParse(prop.Name, out ushort id))
|
||||
{
|
||||
JsonElement entry = prop.Value;
|
||||
if (entry.TryGetProperty("name", out JsonElement nameElement))
|
||||
{
|
||||
string name = nameElement.GetString();
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
soundsDict[id] = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
doc.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadParameterTypes(string jsonPath, GameVersions gameVersion)
|
||||
{
|
||||
Dictionary<ushort, List<ScriptParameter.ParameterType>> paramtypesDict;
|
||||
switch (gameVersion)
|
||||
{
|
||||
case GameVersions.Platinum:
|
||||
paramtypesDict = ScriptDatabase.PlatScrCmdParameterTypes;
|
||||
break;
|
||||
case GameVersions.Diamond:
|
||||
case GameVersions.Pearl:
|
||||
paramtypesDict = ScriptDatabase.DPScrCmdParameterTypes;
|
||||
break;
|
||||
case GameVersions.HeartGold:
|
||||
case GameVersions.SoulSilver:
|
||||
paramtypesDict = ScriptDatabase.HGSSScrCmdParameterTypes;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(gameVersion));
|
||||
}
|
||||
|
||||
string text = File.ReadAllText(jsonPath);
|
||||
JsonDocument doc = JsonDocument.Parse(text);
|
||||
|
||||
try
|
||||
{
|
||||
JsonElement root = doc.RootElement;
|
||||
if (!root.TryGetProperty("scrcmd", out JsonElement scrRoot))
|
||||
{
|
||||
throw new InvalidOperationException("JSON is missing the \"scrcmd\" key");
|
||||
}
|
||||
|
||||
foreach (JsonProperty prop in scrRoot.EnumerateObject())
|
||||
{
|
||||
ushort code = Convert.ToUInt16(prop.Name.Substring(2), 16);
|
||||
JsonElement entry = prop.Value;
|
||||
|
||||
if (entry.TryGetProperty("parameter_types", out JsonElement paramTypesElement))
|
||||
{
|
||||
List<ScriptParameter.ParameterType> paramTypes = new List<ScriptParameter.ParameterType>();
|
||||
foreach (JsonElement typeElement in paramTypesElement.EnumerateArray())
|
||||
{
|
||||
string typeStr = typeElement.GetString();
|
||||
if (!string.IsNullOrEmpty(typeStr))
|
||||
{
|
||||
// Debug output to see what types we're getting
|
||||
Console.WriteLine($"Command 0x{code:X3} parameter type: {typeStr}");
|
||||
var paramType = ScriptParameter.ParseTypeString(typeStr);
|
||||
paramTypes.Add(paramType);
|
||||
}
|
||||
}
|
||||
|
||||
if (paramTypes.Count > 0)
|
||||
{
|
||||
paramtypesDict[code] = paramTypes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -113,55 +192,34 @@ public static class ScriptDatabaseJsonLoader
|
|||
|
||||
namespace DSPRE.Resources {
|
||||
public static class ScriptDatabase {
|
||||
public static Dictionary<ushort, string> comparisonOperatorsDict = new Dictionary<ushort, string>() {
|
||||
// Will be populated at runtime from json
|
||||
};
|
||||
public static Dictionary<ushort, string> comparisonOperatorsGenVappendix = new Dictionary<ushort, string>() {
|
||||
/* GEN V ONLY */
|
||||
[6] = "OR",
|
||||
[7] = "AND",
|
||||
[0xFF] = "TRUEUP"
|
||||
};
|
||||
public static Dictionary<ushort, string> specialOverworlds = new Dictionary<ushort, string>() {
|
||||
// will be populated at runtime from json
|
||||
};
|
||||
public static Dictionary<byte, string> overworldDirections = new Dictionary<byte, string>() {
|
||||
// Will be populated at runtime from json
|
||||
};
|
||||
public static Dictionary<ushort, string> pokemonNames = new Dictionary<ushort, string>()
|
||||
{
|
||||
// Will be populated at runtime from text archive
|
||||
};
|
||||
public static void InitializePokemonNames()
|
||||
{
|
||||
string[] names = RomInfo.GetPokemonNames();
|
||||
pokemonNames = names.Select((name, index) => new { name, index })
|
||||
.ToDictionary(x => (ushort)x.index, x => x.name);
|
||||
}
|
||||
|
||||
public static Dictionary<ushort, string> itemNames = new Dictionary<ushort, string>()
|
||||
{
|
||||
// Will be populated at runtime from text archive
|
||||
};
|
||||
public static void InitializeItemNames()
|
||||
{
|
||||
string[] names = RomInfo.GetItemNames();
|
||||
itemNames = names.Select((name, index) => new { name, index })
|
||||
.ToDictionary(x => (ushort)x.index, x => x.name);
|
||||
}
|
||||
// will all be populated from json at runtime
|
||||
public static Dictionary<ushort, string> comparisonOperatorsDict = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, string> specialOverworlds = new Dictionary<ushort, string>();
|
||||
public static Dictionary<byte, string> overworldDirections = new Dictionary<byte, string>();
|
||||
public static Dictionary<ushort, string> DPScrCmdNames = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, byte[]> DPScrCmdParameters = new Dictionary<ushort, byte[]>();
|
||||
public static Dictionary<ushort, List<ScriptParameter.ParameterType>> DPScrCmdParameterTypes = new Dictionary<ushort, List<ScriptParameter.ParameterType>>();
|
||||
public static Dictionary<ushort, string> PlatScrCmdNames = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, byte[]> PlatScrCmdParameters = new Dictionary<ushort, byte[]>();
|
||||
public static Dictionary<ushort, List<ScriptParameter.ParameterType>> PlatScrCmdParameterTypes = new Dictionary<ushort, List<ScriptParameter.ParameterType>>();
|
||||
public static Dictionary<ushort, string> HGSSScrCmdNames = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, byte[]> HGSSScrCmdParameters = new Dictionary<ushort, byte[]>();
|
||||
public static Dictionary<ushort, List<ScriptParameter.ParameterType>> HGSSScrCmdParameterTypes = new Dictionary<ushort, List<ScriptParameter.ParameterType>>();
|
||||
public static Dictionary<ushort, string> pokemonNames = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, string> itemNames = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, string> moveNames = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, string> soundNames = new Dictionary<ushort, string>();
|
||||
public static Dictionary<ushort, string> movementsDictIDName = new Dictionary<ushort, string>();
|
||||
|
||||
public static Dictionary<ushort, string> moveNames = new Dictionary<ushort, string>()
|
||||
public static Dictionary<ushort, int> commandsWithRelativeJump = new Dictionary<ushort, int>()
|
||||
{
|
||||
// Will be populated at runtime from text archive
|
||||
};
|
||||
public static void InitializeMoveNames()
|
||||
{
|
||||
string[] names = RomInfo.GetAttackNames();
|
||||
moveNames = names.Select((name, index) => new { name, index })
|
||||
.ToDictionary(x => (ushort)x.index, x => x.name);
|
||||
}
|
||||
|
||||
public static Dictionary<ushort, int> commandsWithRelativeJump = new Dictionary<ushort, int>() {
|
||||
//commandID, ID of parameter With Jump Address
|
||||
|
||||
[0x0016] = 0, //Jump
|
||||
|
|
@ -180,36 +238,28 @@ namespace DSPRE.Resources {
|
|||
0x1B
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, string> movementsDictIDName = new Dictionary<ushort, string>() {
|
||||
// Will be populated at runtime from json
|
||||
};
|
||||
|
||||
public static HashSet<ushort?> movementEndCodes = new HashSet<ushort?>() {
|
||||
0x00FE,
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, string> DPScrCmdNames = new Dictionary<ushort, string>() {
|
||||
// will be populated at runtime from json
|
||||
};
|
||||
public static void InitializePokemonNames()
|
||||
{
|
||||
string[] names = RomInfo.GetPokemonNames();
|
||||
pokemonNames = names.Select((name, index) => new { name, index })
|
||||
.ToDictionary(x => (ushort)x.index, x => x.name);
|
||||
}
|
||||
public static void InitializeItemNames()
|
||||
{
|
||||
string[] names = RomInfo.GetItemNames();
|
||||
itemNames = names.Select((name, index) => new { name, index })
|
||||
.ToDictionary(x => (ushort)x.index, x => x.name);
|
||||
}
|
||||
public static void InitializeMoveNames()
|
||||
{
|
||||
string[] names = RomInfo.GetAttackNames();
|
||||
moveNames = names.Select((name, index) => new { name, index })
|
||||
.ToDictionary(x => (ushort)x.index, x => x.name);
|
||||
}
|
||||
|
||||
public static Dictionary<ushort, byte[]> DPScrCmdParameters = new Dictionary<ushort, byte[]>() {
|
||||
// will be populated at runtime from json
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, string> PlatScrCmdNames = new Dictionary<ushort, string>() {
|
||||
// will be populated at runtime from json
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, byte[]> PlatScrCmdParameters = new Dictionary<ushort, byte[]>() {
|
||||
// will be populated at runtime from json
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, string> HGSSScrCmdNames = new Dictionary<ushort, string>() {
|
||||
// will be populated from json at runtime
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, byte[]> HGSSScrCmdParameters = new Dictionary<ushort, byte[]>() {
|
||||
// will be populated from json at runtime
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,6 @@ using System.Linq;
|
|||
using DSPRE.Resources;
|
||||
using System;
|
||||
using DSPRE.ROMFiles;
|
||||
using static DSPRE.RomInfo;
|
||||
using System.Windows.Shapes;
|
||||
using Path = System.IO.Path;
|
||||
|
||||
namespace DSPRE
|
||||
|
|
@ -241,10 +239,13 @@ namespace DSPRE
|
|||
|
||||
if (gameVersion == GameVersions.Platinum) {
|
||||
ScriptDatabaseJsonLoader.InitializeFromJson(Path.Combine(Program.DatabasePath, "platinum_scrcmd_database.json"), gameVersion);
|
||||
ScriptDatabaseJsonLoader.LoadParameterTypes(Path.Combine(Program.DatabasePath, "platinum_scrcmd_database.json"), gameVersion);
|
||||
} else if (gameFamily == GameFamilies.HGSS) {
|
||||
ScriptDatabaseJsonLoader.InitializeFromJson(Path.Combine(Program.DatabasePath, "hgss_scrcmd_database.json"), gameVersion);
|
||||
ScriptDatabaseJsonLoader.LoadParameterTypes(Path.Combine(Program.DatabasePath, "hgss_scrcmd_database.json"), gameVersion);
|
||||
} else if (gameFamily == GameFamilies.DP) {
|
||||
ScriptDatabaseJsonLoader.InitializeFromJson(Path.Combine(Program.DatabasePath, "diamond_pearl_scrcmd_database.json"), gameVersion);
|
||||
ScriptDatabaseJsonLoader.LoadParameterTypes(Path.Combine(Program.DatabasePath, "diamond_pearl_scrcmd_database.json"), gameVersion);
|
||||
}
|
||||
|
||||
/* System */
|
||||
|
|
|
|||
|
|
@ -1,30 +1,57 @@
|
|||
using System;
|
||||
using DSPRE;
|
||||
using DSPRE.Resources;
|
||||
using DSPRE.ROMFiles;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
public class ScriptParameter {
|
||||
public enum ParameterType {
|
||||
Integer,
|
||||
RelativeJump,
|
||||
Flex,
|
||||
Variable,
|
||||
Flex,
|
||||
Overworld,
|
||||
OwMovementType,
|
||||
OwMovementDirection,
|
||||
ComparisonOperator,
|
||||
Function,
|
||||
Action,
|
||||
CMDNumber,
|
||||
Pokemon,
|
||||
Item,
|
||||
Move
|
||||
Move,
|
||||
Sound
|
||||
}
|
||||
|
||||
public static ParameterType ParseTypeString(string typeStr)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (ParameterType)Enum.Parse(typeof(ParameterType), typeStr, true); // true = ignore case
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
Console.WriteLine($"Warning: Unknown parameter type '{typeStr}', defaulting to Integer");
|
||||
return ParameterType.Integer;
|
||||
}
|
||||
}
|
||||
|
||||
public ParameterType Type { get; set; } = ParameterType.Integer;
|
||||
public byte[] RawData { get; set; }
|
||||
public string DisplayValue { get; set; }
|
||||
public string TargetLabel { get; set; } // For RelativeJump type
|
||||
public int TargetOffset { get; set; } // For RelativeJump type
|
||||
|
||||
// Constructor for regular parameters
|
||||
public ScriptParameter(byte[] data) {
|
||||
Type = ParameterType.Integer;
|
||||
public ScriptParameter(byte[] data, ParameterType type)
|
||||
{
|
||||
RawData = data;
|
||||
Type = type;
|
||||
DisplayValue = FormatParameter(data, type);
|
||||
}
|
||||
|
||||
// Constructor for relative jumps
|
||||
public ScriptParameter(int targetOffset, string targetLabel) {
|
||||
Type = ParameterType.RelativeJump;
|
||||
Type = ParameterType.Function;
|
||||
TargetOffset = targetOffset;
|
||||
TargetLabel = targetLabel;
|
||||
// Store raw bytes only for display purposes
|
||||
|
|
@ -33,7 +60,7 @@ public class ScriptParameter {
|
|||
|
||||
// Get display representation
|
||||
public string GetFormattedValue() {
|
||||
if (Type == ParameterType.RelativeJump && !string.IsNullOrEmpty(TargetLabel)) {
|
||||
if (Type == ParameterType.Function && !string.IsNullOrEmpty(TargetLabel)) {
|
||||
return TargetLabel;
|
||||
}
|
||||
|
||||
|
|
@ -45,4 +72,80 @@ public class ScriptParameter {
|
|||
|
||||
return BitConverter.ToString(RawData);
|
||||
}
|
||||
private string FormatParameter(byte[] data, ParameterType type)
|
||||
{
|
||||
uint value;
|
||||
switch (data.Length)
|
||||
{
|
||||
case 1:
|
||||
value = data[0];
|
||||
break;
|
||||
case 2:
|
||||
value = BitConverter.ToUInt16(data, 0);
|
||||
break;
|
||||
case 4:
|
||||
value = BitConverter.ToUInt32(data, 0);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException($"Unexpected parameter data length: {data.Length}");
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ParameterType.Pokemon:
|
||||
if (ScriptDatabase.pokemonNames.TryGetValue((ushort)value, out string pokeName))
|
||||
return $"[{pokeName}]";
|
||||
break;
|
||||
case ParameterType.Item:
|
||||
if (ScriptDatabase.itemNames.TryGetValue((ushort)value, out string itemName))
|
||||
return $"[{itemName}]";
|
||||
break;
|
||||
case ParameterType.Move:
|
||||
if (ScriptDatabase.moveNames.TryGetValue((ushort)value, out string moveName))
|
||||
return $"[{moveName}]";
|
||||
break;
|
||||
case ParameterType.Function:
|
||||
return $"Function#{value}";
|
||||
//case ParameterType.Variable:
|
||||
// return $"VAR_{FormatHexNumber(value)}";
|
||||
case ParameterType.Action:
|
||||
return $"Action#{value}";
|
||||
case ParameterType.CMDNumber:
|
||||
return $"CMD_{value:X3}";
|
||||
case ParameterType.Overworld:
|
||||
if (ScriptDatabase.specialOverworlds.TryGetValue((ushort)value, out string owName))
|
||||
return owName;
|
||||
return value < 4000 ? $"{Event.EventType.Overworld}.{value}" : FormatHexNumber(value);
|
||||
case ParameterType.OwMovementType:
|
||||
return value < 4000 ? $"Move.{value}" : FormatHexNumber(value);
|
||||
case ParameterType.OwMovementDirection:
|
||||
if (ScriptDatabase.overworldDirections.TryGetValue((byte)value, out string dirName))
|
||||
return dirName;
|
||||
break;
|
||||
case ParameterType.ComparisonOperator:
|
||||
if (RomInfo.ScriptComparisonOperatorsDict.TryGetValue((byte)value, out string compName))
|
||||
return compName;
|
||||
break;
|
||||
case ParameterType.Sound:
|
||||
if (ScriptDatabase.soundNames.TryGetValue((ushort)value, out string PtsoundName))
|
||||
return PtsoundName;
|
||||
break;
|
||||
}
|
||||
|
||||
// Default number formatting based on settings
|
||||
return FormatHexNumber(value);
|
||||
}
|
||||
|
||||
private string FormatHexNumber(uint value)
|
||||
{
|
||||
if (SettingsManager.Settings.scriptEditorFormatPreference == (int)NumberStyles.HexNumber)
|
||||
{
|
||||
return $"0x{value:X}";
|
||||
}
|
||||
else if (SettingsManager.Settings.scriptEditorFormatPreference == (int)NumberStyles.None)
|
||||
{
|
||||
return value >= 4000 ? $"0x{value:X}" : value.ToString();
|
||||
}
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user