mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-09-08 03:05:58 -05:00
Minor bugfix + refactor and new script actions
This commit is contained in:
@@ -5624,10 +5624,14 @@ namespace DSPRE {
|
||||
private List<string> SearchInScripts(int fileID, List<CommandContainer> cmdList, string entryType, Func<string, bool> criteria) {
|
||||
List<string> results = new List<string>();
|
||||
|
||||
for (int j = 0; j < cmdList.Count; j++) {
|
||||
for (int j = 0; j < cmdList.Count; j++) {
|
||||
if (cmdList[j].commands is null) {
|
||||
continue;
|
||||
}
|
||||
foreach (ScriptCommand cur in cmdList[j].commands) {
|
||||
if (criteria(cur.name))
|
||||
if (criteria(cur.name)) {
|
||||
results.Add("File " + fileID + " - " + entryType + " " + (j + 1) + ": " + cur.name + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
||||
@@ -37,14 +37,14 @@ namespace DSPRE.ROMFiles {
|
||||
#endregion
|
||||
|
||||
#region Constructors (2)
|
||||
public ScriptCommand(ushort id, List<byte[]> commandParameters) {
|
||||
if (commandParameters is null) {
|
||||
public ScriptCommand(ushort id, List<byte[]> parametersList) {
|
||||
if (parametersList is null) {
|
||||
this.id = null;
|
||||
return;
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
this.cmdParams = commandParameters;
|
||||
this.cmdParams = parametersList;
|
||||
|
||||
if (!RomInfo.ScriptCommandNamesDict.TryGetValue(id, out name))
|
||||
name = id.ToString("X4");
|
||||
@@ -52,39 +52,43 @@ namespace DSPRE.ROMFiles {
|
||||
switch (id) {
|
||||
case 0x16: // Jump
|
||||
case 0x1A: // Call
|
||||
name += " " + "Function_#" + (BitConverter.ToInt32(commandParameters[0], 0)).ToString("D");
|
||||
name += " " + "Function_#" + (BitConverter.ToInt32(parametersList[0], 0)).ToString("D");
|
||||
break;
|
||||
case 0x17: // JumpIfObjID
|
||||
case 0x18: // JumpIfBgID
|
||||
case 0x19: // JumpIfPlayerDir
|
||||
byte param = commandParameters[0][0];
|
||||
name += " " + param.ToString("X") + " " + "Function_#" + BitConverter.ToInt32(commandParameters[1], 0).ToString("D");
|
||||
byte param = parametersList[0][0];
|
||||
name += " " + param.ToString("X") + " " + "Function_#" + BitConverter.ToInt32(parametersList[1], 0).ToString("D");
|
||||
break;
|
||||
case 0x1C: // Jump-If
|
||||
case 0x1D: // Call-If
|
||||
byte opcode = commandParameters[0][0];
|
||||
name += " " + PokeDatabase.ScriptEditor.comparisonOperatorsDict[opcode] + " " + "Function_#" + BitConverter.ToInt32(commandParameters[1], 0).ToString("D");
|
||||
byte opcode = parametersList[0][0];
|
||||
name += " " + PokeDatabase.ScriptEditor.comparisonOperatorsDict[opcode] + " " + "Function_#" + BitConverter.ToInt32(parametersList[1], 0).ToString("D");
|
||||
break;
|
||||
case 0x5E: // ApplyMovement
|
||||
ushort flexID = BitConverter.ToUInt16(commandParameters[0], 0);
|
||||
this.name += ScriptFile.OverworldFlexDecode(flexID);
|
||||
name += " " + "Action_#" + BitConverter.ToInt32(commandParameters[1], 0).ToString("D");
|
||||
case 0x5E: // Movement
|
||||
ushort flexID = BitConverter.ToUInt16(parametersList[0], 0);
|
||||
name += ScriptFile.OverworldFlexDecode(flexID);
|
||||
name += " " + "Action_#" + BitConverter.ToInt32(parametersList[1], 0).ToString("D");
|
||||
break;
|
||||
case 0x6A: // CheckOverworldPosition
|
||||
flexID = BitConverter.ToUInt16(parametersList[0], 0);
|
||||
name += ScriptFile.OverworldFlexDecode(flexID) + " " + "0x" + BitConverter.ToInt16(parametersList[1], 0).ToString("X") + " " + "0x" + BitConverter.ToInt16(parametersList[2], 0).ToString("X");
|
||||
break;
|
||||
case 0x62: // Lock
|
||||
case 0x63: // Release
|
||||
case 0x64: // AddPeople
|
||||
case 0x64: // AddOW
|
||||
case 0x65: // RemoveOW
|
||||
flexID = BitConverter.ToUInt16(commandParameters[0], 0);
|
||||
flexID = BitConverter.ToUInt16(parametersList[0], 0);
|
||||
name += ScriptFile.OverworldFlexDecode(flexID);
|
||||
break;
|
||||
default:
|
||||
for (int i = 0; i < commandParameters.Count; i++) {
|
||||
if (commandParameters[i].Length == 1)
|
||||
this.name += " " + "0x" + (commandParameters[i][0]).ToString("X1");
|
||||
else if (commandParameters[i].Length == 2)
|
||||
this.name += " " + "0x" + (BitConverter.ToInt16(commandParameters[i], 0)).ToString("X1");
|
||||
else if (commandParameters[i].Length == 4)
|
||||
this.name += " " + "0x" + (BitConverter.ToInt32(commandParameters[i], 0)).ToString("X1");
|
||||
for (int i = 0; i < parametersList.Count; i++) {
|
||||
if (parametersList[i].Length == 1)
|
||||
this.name += " " + "0x" + (parametersList[i][0]).ToString("X1");
|
||||
else if (parametersList[i].Length == 2)
|
||||
this.name += " " + "0x" + BitConverter.ToInt16(parametersList[i], 0).ToString("X1");
|
||||
else if (parametersList[i].Length == 4)
|
||||
this.name += " " + "0x" + BitConverter.ToInt32(parametersList[i], 0).ToString("X1");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -341,8 +341,9 @@ namespace DSPRE.ROMFiles {
|
||||
{
|
||||
byte parameter1 = dataReader.ReadByte();
|
||||
parameterList.Add(new byte[] { parameter1 });
|
||||
if (parameter1 == 0x2)
|
||||
if (parameter1 == 0x2) {
|
||||
parameterList.Add(dataReader.ReadBytes(2));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x1D1: // Number of parameters differ depending on the first parameter value
|
||||
@@ -424,8 +425,9 @@ namespace DSPRE.ROMFiles {
|
||||
private void addParametersToList(ref List<byte[]> parameterList, ushort id, BinaryReader dataReader) {
|
||||
Console.WriteLine("Loaded command id: " + id.ToString("X4"));
|
||||
try {
|
||||
foreach (int bytesToRead in RomInfo.CommandParametersDict[id])
|
||||
foreach (int bytesToRead in RomInfo.CommandParametersDict[id]) {
|
||||
parameterList.Add(dataReader.ReadBytes(bytesToRead));
|
||||
}
|
||||
} catch (NullReferenceException) {
|
||||
MessageBox.Show("Script command " + id + "can't be handled for now." +
|
||||
Environment.NewLine + "Reference offset 0x" + dataReader.BaseStream.Position.ToString("X"), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
@@ -639,6 +639,13 @@ namespace DSPRE.Resources {
|
||||
[0x0039] = "JumpDown2",
|
||||
[0x003A] = "JumpLeft2",
|
||||
[0x003B] = "JumpRight2",
|
||||
[0x003C] = "Freeze1",
|
||||
[0x003D] = "Freeze2",
|
||||
[0x003E] = "Freeze4",
|
||||
[0x003F] = "Freeze8",
|
||||
[0x0040] = "Freeze15",
|
||||
[0x0041] = "Freeze16",
|
||||
[0x0042] = "Freeze32",
|
||||
[0x0045] = "WaitDisappear",
|
||||
[0x0047] = "LockDir",
|
||||
[0x0048] = "ReleaseDir",
|
||||
@@ -669,6 +676,7 @@ namespace DSPRE.Resources {
|
||||
[0x0068] = "WaitMoveForever",
|
||||
[0x00FE] = "End"
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, string> comparisonOperatorsDict = new Dictionary<ushort, string>() {
|
||||
[0] = "LESS",
|
||||
[1] = "EQUAL",
|
||||
@@ -695,6 +703,7 @@ namespace DSPRE.Resources {
|
||||
[0x001D] = 1, //Call-If
|
||||
[0x005E] = 1, //Movement
|
||||
};
|
||||
|
||||
public static HashSet<ushort?> endCodes = new HashSet<ushort?>() {
|
||||
0x2,
|
||||
0x16,
|
||||
@@ -802,8 +811,8 @@ namespace DSPRE.Resources {
|
||||
[0x0063] = "Release",
|
||||
[0x0064] = "AddOW",
|
||||
[0x0065] = "RemoveOW",
|
||||
[0x0066] = "LockCam",
|
||||
[0x0067] = "ReleaseCam",
|
||||
[0x0066] = "LockCamera",
|
||||
[0x0067] = "ReleaseCamera",
|
||||
[0x0068] = "FacePlayer",
|
||||
[0x0069] = "CheckPlayerPosition",
|
||||
[0x006A] = "CheckOverworldPosition",
|
||||
@@ -1150,6 +1159,7 @@ namespace DSPRE.Resources {
|
||||
[0x02C2] = "HideSaveBox",
|
||||
[0x02C3] = "ScopeMode"
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, byte[]> DPPtScrCmdParameters = new Dictionary<ushort, byte[]>() {
|
||||
[0x0000] = new byte[1] { 0 },
|
||||
[0x0001] = new byte[1] { 0 },
|
||||
|
||||
Reference in New Issue
Block a user