mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-09-11 12:45:18 -05:00
Some fixes and code readability improvements
- changed some var names to more intuitive ones - fixed worldmap coordinates not updating
This commit is contained in:
@@ -836,9 +836,6 @@ namespace DSPRE {
|
||||
statusLabel.Text = "Attempting to unpack NARCs from folder...";
|
||||
Update();
|
||||
|
||||
/*foreach (Tuple<string, string> tuple in RomInfo.narcPaths.Zip(RomInfo.extractedNarcDirs, Tuple.Create))
|
||||
Narc.Open(romInfo.workDir + tuple.Item1).ExtractToFolder(tuple.Item2);*/
|
||||
|
||||
switch (RomInfo.gameVersion) {
|
||||
case "D":
|
||||
case "P":
|
||||
@@ -1025,12 +1022,12 @@ namespace DSPRE {
|
||||
|
||||
string[] narcPaths = RomInfo.narcPaths;
|
||||
string[] extractedNarcDirs = RomInfo.extractedNarcDirs;
|
||||
Tuple<string, string> t;
|
||||
(string wildPokeNarcPath, string wildPokeUnpackedPath) t;
|
||||
|
||||
if (RomInfo.gameVersion == "HG" || RomInfo.gameVersion == "SS") {
|
||||
t = Tuple.Create(narcPaths[narcPaths.Length - 2], extractedNarcDirs[extractedNarcDirs.Length - 2]);
|
||||
t = (narcPaths[narcPaths.Length - 2], extractedNarcDirs[extractedNarcDirs.Length - 2]);
|
||||
} else {
|
||||
t = Tuple.Create(narcPaths[narcPaths.Length - 1], extractedNarcDirs[extractedNarcDirs.Length - 2]);
|
||||
t = (narcPaths[narcPaths.Length - 1], extractedNarcDirs[extractedNarcDirs.Length - 2]);
|
||||
}
|
||||
|
||||
DirectoryInfo di = new DirectoryInfo(t.Item2);
|
||||
@@ -1969,12 +1966,12 @@ namespace DSPRE {
|
||||
matrixTabControl.TabPages.Remove(headersTabPage);
|
||||
matrixTabControl.TabPages.Remove(heightsTabPage);
|
||||
}
|
||||
private Tuple<Color, Color> FormatMapCell(uint cellValue) {
|
||||
foreach (KeyValuePair<List<uint>, Tuple<Color, Color>> entry in romInfo.mapCellsColorDictionary) {
|
||||
private (Color background, Color foreground) FormatMapCell(uint cellValue) {
|
||||
foreach (KeyValuePair<List<uint>, (Color background, Color foreground)> entry in romInfo.mapCellsColorDictionary) {
|
||||
if (entry.Key.Contains(cellValue))
|
||||
return entry.Value;
|
||||
}
|
||||
return Tuple.Create(Color.White, Color.Black);
|
||||
return (Color.White, Color.Black);
|
||||
}
|
||||
private void GenerateMatrixTables() {
|
||||
/* Generate table columns */
|
||||
@@ -2085,9 +2082,9 @@ namespace DSPRE {
|
||||
ushort colorValue;
|
||||
if (!UInt16.TryParse(mapFilesGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), out colorValue)) colorValue = Matrix.EMPTY;
|
||||
|
||||
Tuple<Color, Color> cellColors = FormatMapCell(colorValue);
|
||||
e.CellStyle.BackColor = cellColors.Item1;
|
||||
e.CellStyle.ForeColor = cellColors.Item2;
|
||||
(Color back, Color fore) cellColors = FormatMapCell(colorValue);
|
||||
e.CellStyle.BackColor = cellColors.back;
|
||||
e.CellStyle.ForeColor = cellColors.fore;
|
||||
|
||||
/* If invalid input is entered, show 00 */
|
||||
ushort cellValue;
|
||||
@@ -2193,9 +2190,9 @@ namespace DSPRE {
|
||||
if (!UInt16.TryParse(mapFilesGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), out colorValue))
|
||||
colorValue = Matrix.EMPTY;
|
||||
|
||||
Tuple<Color, Color> cellColors = FormatMapCell(colorValue);
|
||||
e.CellStyle.BackColor = cellColors.Item1;
|
||||
e.CellStyle.ForeColor = cellColors.Item2;
|
||||
(Color back, Color fore) cellColors = FormatMapCell(colorValue);
|
||||
e.CellStyle.BackColor = cellColors.fore;
|
||||
e.CellStyle.ForeColor = cellColors.back;
|
||||
|
||||
/* If invalid input is entered, show 00 */
|
||||
byte cellValue;
|
||||
@@ -2309,9 +2306,9 @@ namespace DSPRE {
|
||||
colorValue = UInt16.Parse(mapFilesGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
|
||||
} catch { }
|
||||
|
||||
Tuple<Color, Color> cellColors = FormatMapCell(colorValue);
|
||||
e.CellStyle.BackColor = cellColors.Item1;
|
||||
e.CellStyle.ForeColor = cellColors.Item2;
|
||||
(Color backColor, Color foreColor) cellColors = FormatMapCell(colorValue);
|
||||
e.CellStyle.BackColor = cellColors.backColor;
|
||||
e.CellStyle.ForeColor = cellColors.foreColor;
|
||||
|
||||
if (colorValue == Matrix.EMPTY)
|
||||
e.Value = '-';
|
||||
@@ -2383,7 +2380,7 @@ namespace DSPRE {
|
||||
string dashSeparator = "-";
|
||||
string problematicSegment = "incomplete line";
|
||||
|
||||
Dictionary<List<uint>, Tuple<Color, Color>> colorsDict = new Dictionary<List<uint>, Tuple<Color, Color>>();
|
||||
Dictionary<List<uint>, (Color background, Color foreground)> colorsDict = new Dictionary<List<uint>, (Color background, Color foreground)>();
|
||||
List<string> linesWithErrors = new List<string>();
|
||||
|
||||
for (int i = 0; i < fileTableContent.Length; i++) {
|
||||
@@ -2448,14 +2445,14 @@ namespace DSPRE {
|
||||
}
|
||||
j++;
|
||||
|
||||
colorsDict.Add( mapList, Tuple.Create( Color.FromArgb(r, g, b), Color.FromName(lineParts[j++]) ) );
|
||||
colorsDict.Add( mapList, ( Color.FromArgb(r, g, b), Color.FromName(lineParts[j++]) ) );
|
||||
} catch {
|
||||
linesWithErrors.Add(i + 1 + " (err. " + problematicSegment + ")\n");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
colorsDict.Add(new List<uint> { Matrix.EMPTY }, Tuple.Create(Color.Black, Color.White));
|
||||
colorsDict.Add(new List<uint> { Matrix.EMPTY }, (Color.Black, Color.White));
|
||||
|
||||
string errorMsg = "";
|
||||
MessageBoxIcon iconType = MessageBoxIcon.Information;
|
||||
@@ -4508,7 +4505,7 @@ namespace DSPRE {
|
||||
ScriptFile itemScript = new ScriptFile(RomInfo.itemScriptFileNumber);
|
||||
|
||||
for (ushort i = 0; i < itemScript.allScripts.Count - 1; i++) {
|
||||
if (BitConverter.ToUInt16(itemScript.allScripts[i].commands[0].commandParameters[1], 0) != i || BitConverter.ToUInt16(itemScript.allScripts[i].commands[1].commandParameters[1], 0) != 1) {
|
||||
if (BitConverter.ToUInt16(itemScript.allScripts[i].commands[0].cmdParams[1], 0) != i || BitConverter.ToUInt16(itemScript.allScripts[i].commands[1].cmdParams[1], 0) != 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -5319,8 +5316,8 @@ namespace DSPRE {
|
||||
string movHeader = "----- " + "@Action_#" + (i + 1) + " -----" + Environment.NewLine;
|
||||
buffer += movHeader;
|
||||
buffer += Environment.NewLine;
|
||||
for (int j = 0; j < currentAction.actions.Count; j++)
|
||||
buffer += currentAction.actions[j].name + Environment.NewLine;
|
||||
for (int j = 0; j < currentAction.actionCommandsList.Count; j++)
|
||||
buffer += currentAction.actionCommandsList[j].name + Environment.NewLine;
|
||||
}
|
||||
movementTextBox.AppendText(buffer + Environment.NewLine, Color.FromArgb(192, 40, 40));
|
||||
buffer = "";
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace DSPRE.ROMFiles {
|
||||
writer.Write((byte)wildPok<EFBFBD>mon);
|
||||
writer.Write(areaDataID);
|
||||
|
||||
ushort worldMapCoordinates = (ushort) ( unknown0 & 0b_1111 + ((worldmapX & 0b_1111_11) << 4) + ((worldmapY & 0b_1111_11) << 10) );
|
||||
ushort worldMapCoordinates = (ushort) ( (unknown0 & 0b_1111) + ((worldmapX & 0b_1111_11) << 4) + ((worldmapY & 0b_1111_11) << 10) );
|
||||
writer.Write(worldMapCoordinates);
|
||||
|
||||
writer.Write(matrixID);
|
||||
|
||||
@@ -9,13 +9,13 @@ using System.Windows.Forms;
|
||||
|
||||
namespace DSPRE.ROMFiles {
|
||||
public class ActionContainer {
|
||||
public List<ScriptAction> actions;
|
||||
public List<ScriptAction> actionCommandsList;
|
||||
public int manualUserID;
|
||||
|
||||
#region Constructors (2)
|
||||
public ActionContainer(int actionNumber, List<ScriptAction> actionList = null) {
|
||||
public ActionContainer(int actionNumber, List<ScriptAction> actionCommandsList = null) {
|
||||
manualUserID = actionNumber;
|
||||
actions = actionList;
|
||||
this.actionCommandsList = actionCommandsList;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace DSPRE.ROMFiles {
|
||||
public class ScriptCommand {
|
||||
#region Fields (4)
|
||||
public ushort id;
|
||||
public List<byte[]> commandParameters;
|
||||
public List<byte[]> cmdParams;
|
||||
public string name;
|
||||
#endregion
|
||||
|
||||
#region Constructors (2)
|
||||
public ScriptCommand(ushort id, List<byte[]> commandParameters) {
|
||||
this.id = id;
|
||||
this.commandParameters = commandParameters;
|
||||
this.cmdParams = commandParameters;
|
||||
|
||||
try {
|
||||
name = RomInfo.scriptCommandNamesDict[id];
|
||||
@@ -79,7 +79,7 @@ namespace DSPRE.ROMFiles {
|
||||
}
|
||||
public ScriptCommand(string wholeLine, int lineNumber) {
|
||||
name = wholeLine;
|
||||
commandParameters = new List<byte[]>();
|
||||
cmdParams = new List<byte[]>();
|
||||
|
||||
string[] nameParts = wholeLine.Split(' '); // Separate command code from parameters
|
||||
/* Get command id, which is always first in the description */
|
||||
@@ -108,13 +108,13 @@ namespace DSPRE.ROMFiles {
|
||||
/* Read parameters from remainder of the description */
|
||||
Console.WriteLine("ID = " + id.ToString("X4"));
|
||||
|
||||
byte[] parametersArr = RomInfo.commandParametersDict[id];
|
||||
byte[] parametersSizeArr = RomInfo.commandParametersDict[id];
|
||||
|
||||
int paramLength = 0;
|
||||
if (parametersArr.Length == 1 && parametersArr.First() == 0) {
|
||||
if (parametersSizeArr.Length == 1 && parametersSizeArr.First() == 0) {
|
||||
paramLength = 0;
|
||||
} else {
|
||||
paramLength = parametersArr.Length;
|
||||
paramLength = parametersSizeArr.Length;
|
||||
}
|
||||
|
||||
if (nameParts.Length - 1 == paramLength) {
|
||||
@@ -122,7 +122,7 @@ namespace DSPRE.ROMFiles {
|
||||
Console.WriteLine("Parameter #" + i.ToString() + ": " + nameParts[i + 1]);
|
||||
try {
|
||||
ushort comparisonOperator = PokeDatabase.ScriptEditor.comparisonOperatorsDict.First(x => x.Value.Equals(nameParts[i + 1], StringComparison.InvariantCultureIgnoreCase)).Key;
|
||||
commandParameters.Add(new byte[] { (byte)comparisonOperator });
|
||||
cmdParams.Add(new byte[] { (byte)comparisonOperator });
|
||||
} catch { //Not a comparison
|
||||
int indexOfSpecialCharacter = nameParts[i + 1].IndexOfAny(new char[] { 'x', '#' });
|
||||
|
||||
@@ -134,28 +134,28 @@ namespace DSPRE.ROMFiles {
|
||||
style = NumberStyles.Integer;
|
||||
|
||||
/* Convert strings of parameters to the correct datatypes */
|
||||
switch (parametersArr[i]) {
|
||||
switch (parametersSizeArr[i]) {
|
||||
case 1:
|
||||
commandParameters.Add(new byte[] { Byte.Parse(nameParts[i + 1].Substring(indexOfSpecialCharacter + 1), style) });
|
||||
cmdParams.Add(new byte[] { Byte.Parse(nameParts[i + 1].Substring(indexOfSpecialCharacter + 1), style) });
|
||||
break;
|
||||
case 2:
|
||||
switch (nameParts[i + 1]) {
|
||||
case "Player":
|
||||
commandParameters.Add(BitConverter.GetBytes((ushort)255));
|
||||
cmdParams.Add(BitConverter.GetBytes((ushort)255));
|
||||
break;
|
||||
case "Following":
|
||||
commandParameters.Add(BitConverter.GetBytes((ushort)253));
|
||||
cmdParams.Add(BitConverter.GetBytes((ushort)253));
|
||||
break;
|
||||
case "Cam":
|
||||
commandParameters.Add(BitConverter.GetBytes((ushort)241));
|
||||
cmdParams.Add(BitConverter.GetBytes((ushort)241));
|
||||
break;
|
||||
default:
|
||||
commandParameters.Add(BitConverter.GetBytes(Int16.Parse(nameParts[i + 1].Substring(indexOfSpecialCharacter + 1), style)));
|
||||
cmdParams.Add(BitConverter.GetBytes(Int16.Parse(nameParts[i + 1].Substring(indexOfSpecialCharacter + 1), style)));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
commandParameters.Add(BitConverter.GetBytes(Int32.Parse(nameParts[i + 1].Substring(indexOfSpecialCharacter + 1), style)));
|
||||
cmdParams.Add(BitConverter.GetBytes(Int32.Parse(nameParts[i + 1].Substring(indexOfSpecialCharacter + 1), style)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace DSPRE.ROMFiles {
|
||||
/// Class to store script file data in Pok<6F>mon NDS games
|
||||
/// </summary>
|
||||
public class ScriptFile {
|
||||
#region Constants
|
||||
//this enum doesn't really make much sense now but it will, once scripts can be called and jumped to
|
||||
public enum typeInvoked { REFTYPE_FUNCTION, REFTYPE_MOVEMENT, REFTYPE_SCRIPT };
|
||||
#endregion
|
||||
#region<EFBFBD>Fields<EFBFBD>(3)
|
||||
public List<CommandContainer> allScripts = new List<CommandContainer>();
|
||||
public List<CommandContainer> allFunctions = new List<CommandContainer>();
|
||||
@@ -67,7 +71,7 @@ namespace DSPRE.ROMFiles {
|
||||
bool endScript = new bool();
|
||||
while (!endScript) {
|
||||
ScriptCommand cmd = ReadCommand(scrReader, ref functionOffsets, ref movementOffsets);
|
||||
if (cmd.commandParameters == null)
|
||||
if (cmd.cmdParams == null)
|
||||
return;
|
||||
|
||||
cmdList.Add(cmd);
|
||||
@@ -92,7 +96,7 @@ namespace DSPRE.ROMFiles {
|
||||
bool endFunction = new bool();
|
||||
while (!endFunction) {
|
||||
ScriptCommand command = ReadCommand(scrReader, ref functionOffsets, ref movementOffsets);
|
||||
if (command.commandParameters == null)
|
||||
if (command.cmdParams == null)
|
||||
return;
|
||||
|
||||
cmdList.Add(command);
|
||||
@@ -120,7 +124,7 @@ namespace DSPRE.ROMFiles {
|
||||
cmdList.Add(new ScriptAction(id, scrReader.ReadUInt16()));
|
||||
}
|
||||
}
|
||||
allActions.Add(new ActionContainer(i, actionList: cmdList));
|
||||
allActions.Add(new ActionContainer(i, actionCommandsList: cmdList));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,17 +139,24 @@ namespace DSPRE.ROMFiles {
|
||||
isLevelScript = false;
|
||||
}
|
||||
public ScriptFile(string[] scriptLines, string[] functionLines, string[] actionLines, int ID = -1) {
|
||||
allScripts = readCommandsFromLines(scriptLines,
|
||||
(source, x) => x < source.Length - 1
|
||||
&& !source[x].Equals(RomInfo.scriptCommandNamesDict[0x0002]) //End
|
||||
&& !source[x].Contains(RomInfo.scriptCommandNamesDict[0x0016] + " Function")); //Jump
|
||||
//TODO: give user the possibility to jump to/call a script
|
||||
//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<string[], int, bool> functionEndCondition =
|
||||
(source, x) => !source[x].Equals(RomInfo.scriptCommandNamesDict[0x0002]) //End
|
||||
&& !source[x].Contains(RomInfo.scriptCommandNamesDict[0x001B]) //Return
|
||||
&& !source[x].Contains(RomInfo.scriptCommandNamesDict[0x0016] + " Function"); //Jump Function_#
|
||||
|
||||
|
||||
Func<string[], int, bool> scriptEndCondition =
|
||||
(source, x) => !source[x].Equals(RomInfo.scriptCommandNamesDict[0x0002]) //End
|
||||
&& !source[x].Contains(RomInfo.scriptCommandNamesDict[0x0016] + " Function"); //Jump Function_#
|
||||
|
||||
allScripts = readCommandsFromLines(scriptLines, scriptEndCondition); //Jump + whitespace
|
||||
if (allScripts == null)
|
||||
return;
|
||||
|
||||
allFunctions = readCommandsFromLines(functionLines,
|
||||
(source, x) => !source[x].Equals(RomInfo.scriptCommandNamesDict[0x0002]) //End
|
||||
&& !source[x].Contains(RomInfo.scriptCommandNamesDict[0x001B]) //Return
|
||||
&& !source[x].Contains(RomInfo.scriptCommandNamesDict[0x0016] + " Function")); //Jump
|
||||
allFunctions = readCommandsFromLines(functionLines, functionEndCondition); //Jump + whitespace
|
||||
if (allFunctions == null)
|
||||
return;
|
||||
|
||||
@@ -438,11 +449,11 @@ namespace DSPRE.ROMFiles {
|
||||
public byte[] ToByteArray() {
|
||||
MemoryStream newData = new MemoryStream();
|
||||
using (BinaryWriter writer = new BinaryWriter(newData)) {
|
||||
List<(uint offset, int ID)> scriptOffsets = new List<(uint, int)>(); //uint OFFSET, int Function/Script/Action ID
|
||||
List<(uint offset, int ID)> functionOffsets = new List<(uint, int)>();
|
||||
List<(uint offset, int ID)> actionOffsets = new List<(uint, int)>();
|
||||
List<(int scriptID, uint offsetInFile)> scriptOffsets = new List<(int, uint)>(); //uint OFFSET, int Function/Script/Action ID
|
||||
List<(int functionID, uint offsetInFile)> functionOffsets = new List<(int, uint)>();
|
||||
List<(int actionID, uint offsetInFile)> actionOffsets = new List<(int, uint)>();
|
||||
|
||||
List<(int address, int destID, bool isMovement, int manualUserID)> references = new List<(int, int, bool, int)>();
|
||||
List<(int offsetAddress, int destID, int typeInvoked, int manualUserID)> references = new List<(int, int, int, int)>();
|
||||
|
||||
/* Allocate enough space for script pointers, which we do not know yet */
|
||||
try {
|
||||
@@ -450,52 +461,61 @@ namespace DSPRE.ROMFiles {
|
||||
writer.Write((ushort)0xFD13); // Signal the end of header section
|
||||
|
||||
/* Write scripts */
|
||||
for (int i = 0; i < allScripts.Count; i++) {
|
||||
if (allScripts[i].useScript == -1) {
|
||||
scriptOffsets.Add(((uint)writer.BaseStream.Position, i));
|
||||
foreach (CommandContainer currentScript in allScripts) {
|
||||
if (currentScript.useScript == -1) {
|
||||
scriptOffsets.Add((currentScript.manualUserID, (uint)writer.BaseStream.Position));
|
||||
|
||||
for (int j = 0; j < allScripts[i].commands.Count; j++) {
|
||||
ushort commandID = allScripts[i].commands[j].id;
|
||||
foreach (ScriptCommand currentCmd in currentScript.commands) {
|
||||
ushort commandID = currentCmd.id;
|
||||
writer.Write(commandID);
|
||||
//System.Diagnostics.Debug.Write(BitConverter.ToString(BitConverter.GetBytes(commandID)) + " ");
|
||||
|
||||
/* Get command parameters */
|
||||
List<byte[]> parameterList = allScripts[i].commands[j].commandParameters;
|
||||
List<byte[]> parameterList = currentCmd.cmdParams;
|
||||
for (int k = 0; k < parameterList.Count; k++) {
|
||||
writer.Write(parameterList[k]);
|
||||
//System.Diagnostics.Debug.WriteLine(BitConverter.ToString(parameterList[k]) + " ");
|
||||
}
|
||||
|
||||
/* If command calls a function/movement, store reference position */
|
||||
AddReference(ref references, commandID, parameterList, (int)writer.BaseStream.Position, i);
|
||||
AddReference(ref references, commandID, parameterList, (int)writer.BaseStream.Position, currentScript.manualUserID);
|
||||
}
|
||||
} else {
|
||||
scriptOffsets.Add(scriptOffsets[allScripts[i].useScript - 1]); // If script has UseScript, copy offset
|
||||
scriptOffsets.Add(scriptOffsets[currentScript.useScript - 1]); // If script has UseScript, copy offset
|
||||
}
|
||||
}
|
||||
|
||||
/* Write functions */
|
||||
for (int i = 0; i < allFunctions.Count; i++) {
|
||||
if (allFunctions[i].useScript == -1) {
|
||||
functionOffsets.Add(((uint)writer.BaseStream.Position, allFunctions[i].manualUserID));
|
||||
foreach (CommandContainer currentFunction in allFunctions) {
|
||||
if (currentFunction.useScript == -1) {
|
||||
functionOffsets.Add((currentFunction.manualUserID, (uint)writer.BaseStream.Position));
|
||||
|
||||
for (int j = 0; j < allFunctions[i].commands.Count; j++) {
|
||||
ushort commandID = allFunctions[i].commands[j].id;
|
||||
foreach (ScriptCommand currentCmd in currentFunction.commands) {
|
||||
ushort commandID = currentCmd.id;
|
||||
writer.Write(commandID);
|
||||
//System.Diagnostics.Debug.Write(BitConverter.ToString(BitConverter.GetBytes(commandID)) + " ");
|
||||
|
||||
/* Write command parameters */
|
||||
List<byte[]> parameterList = allFunctions[i].commands[j].commandParameters;
|
||||
List<byte[]> parameterList = currentCmd.cmdParams;
|
||||
for (int k = 0; k < parameterList.Count; k++) {
|
||||
writer.Write(parameterList[k]);
|
||||
//System.Diagnostics.Debug.Write(BitConverter.ToString(parameterList[k]) + " ");
|
||||
}
|
||||
|
||||
/* If command calls a function/movement, store reference position */
|
||||
AddReference(ref references, commandID, parameterList, (int)writer.BaseStream.Position, i);
|
||||
try {
|
||||
int parameterWithRelativeJump = PokeDatabase.ScriptEditor.commandsWithRelativeJump[commandID];
|
||||
int destinationID = BitConverter.ToInt32(parameterList[parameterWithRelativeJump], 0); // Jump, Call
|
||||
|
||||
int type = (int)typeInvoked.REFTYPE_FUNCTION;
|
||||
if (commandID == 0x005E)
|
||||
type = (int)typeInvoked.REFTYPE_MOVEMENT;
|
||||
|
||||
references.Add(((int)writer.BaseStream.Position - 4, destinationID, type, currentFunction.manualUserID));
|
||||
} catch (KeyNotFoundException) { }
|
||||
}
|
||||
} else {
|
||||
functionOffsets.Add((scriptOffsets[allFunctions[i].useScript - 1].offset, allFunctions[i].manualUserID));
|
||||
functionOffsets.Add((currentFunction.manualUserID, scriptOffsets[currentFunction.useScript - 1].offsetInFile));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -505,23 +525,23 @@ namespace DSPRE.ROMFiles {
|
||||
}
|
||||
|
||||
/* Write movements */
|
||||
for (int i = 0; i < allActions.Count; i++) {
|
||||
actionOffsets.Add(((uint)writer.BaseStream.Position, allActions[i].manualUserID));
|
||||
foreach (ActionContainer currentAction in allActions) {
|
||||
actionOffsets.Add((currentAction.manualUserID, (uint)writer.BaseStream.Position));
|
||||
|
||||
for (int j = 0; j < allActions[i].actions.Count; j++) {
|
||||
foreach (ScriptAction currentCmd in currentAction.actionCommandsList) {
|
||||
/* Write movement command id */
|
||||
writer.Write(allActions[i].actions[j].id);
|
||||
writer.Write(currentCmd.id);
|
||||
|
||||
/* Write movement command parameters */
|
||||
if (allActions[i].actions[j].id != 0x00FE)
|
||||
writer.Write(allActions[i].actions[j].repetitionCount);
|
||||
if (currentCmd.id != 0x00FE)
|
||||
writer.Write(currentCmd.repetitionCount);
|
||||
}
|
||||
}
|
||||
|
||||
/* Write script offsets to header */
|
||||
writer.BaseStream.Position = 0x0;
|
||||
for (int i = 0; i < scriptOffsets.Count; i++)
|
||||
writer.Write(scriptOffsets[i].Item1 - (uint)writer.BaseStream.Position - 0x4);
|
||||
writer.Write(scriptOffsets[i].offsetInFile - (uint)writer.BaseStream.Position - 0x4);
|
||||
|
||||
/* Fix references to functions and movements */
|
||||
List<int> undeclaredFuncs = new List<int>();
|
||||
@@ -531,24 +551,24 @@ namespace DSPRE.ROMFiles {
|
||||
List<int> unreferencedActions = new List<int>(allActions.Select(x => x.manualUserID).ToArray());
|
||||
|
||||
while (references.Count > 0) {
|
||||
writer.BaseStream.Position = references[0].address; //place seek head on parameter that is supposed to store the jump address
|
||||
writer.BaseStream.Position = references[0].offsetAddress; //place seek head on parameter that is supposed to store the jump address
|
||||
|
||||
if (references[0].typeInvoked == (int)typeInvoked.REFTYPE_MOVEMENT) { //isApplyMovement
|
||||
(int actionID, uint offsetInFile) result = actionOffsets.Find(x => x.actionID == references[0].destID);
|
||||
|
||||
if (references[0].isMovement) { //isApplyMovement
|
||||
(uint offset, int id) result = actionOffsets.Find(x => x.ID == references[0].destID);
|
||||
|
||||
if (result == (0, 0))
|
||||
undeclaredActions.Add(references[0].destID);
|
||||
else {
|
||||
writer.Write((uint)(result.offset - references[0].address - 4)); ////////////////BROKEN
|
||||
unreferencedActions.Remove(references[0].destID);
|
||||
else {
|
||||
writer.Write((uint)(result.offsetInFile - references[0].offsetAddress - 4));
|
||||
unreferencedActions.Remove(references[0].destID);
|
||||
}
|
||||
} else {
|
||||
(uint offset, int id) result = functionOffsets.Find(x => x.ID == references[0].destID);
|
||||
|
||||
(int functionID, uint offsetInFile) result = functionOffsets.Find(x => x.functionID == references[0].destID);
|
||||
|
||||
if (result == (0, 0))
|
||||
undeclaredFuncs.Add(references[0].destID);
|
||||
else {
|
||||
writer.Write((uint)(result.offset - references[0].address - 4));
|
||||
else {
|
||||
writer.Write((uint)(result.offsetInFile - references[0].offsetAddress - 4));
|
||||
uninvokedFuncs.Remove(references[0].destID);
|
||||
}
|
||||
}
|
||||
@@ -595,18 +615,16 @@ namespace DSPRE.ROMFiles {
|
||||
return newData.ToArray();
|
||||
|
||||
}
|
||||
private void AddReference(ref List<(int, int, bool, int)> references, ushort commandID, List<byte[]> parameterList, int pos, int callerID) {
|
||||
private void AddReference(ref List<(int offset, int destID, int typeInvoked, int callerID)> references, ushort commandID, List<byte[]> parameterList, int pos, int callerID) {
|
||||
try {
|
||||
if (Resources.PokeDatabase.ScriptEditor.commandsWithRelativeJump[commandID] == true) {
|
||||
byte[] parameterWithReferenceID;
|
||||
if (commandID == 0x16 || commandID == 0x1A)
|
||||
parameterWithReferenceID = parameterList[0]; // Jump, Call
|
||||
else
|
||||
parameterWithReferenceID = parameterList[1];
|
||||
int parameterWithRelativeJump = PokeDatabase.ScriptEditor.commandsWithRelativeJump[commandID];
|
||||
int destinationID = BitConverter.ToInt32(parameterList[parameterWithRelativeJump], 0); // Jump, Call
|
||||
|
||||
int referenceID = BitConverter.ToInt32(parameterWithReferenceID, 0);
|
||||
references.Add((pos - 4, referenceID, commandID == 0x5E, callerID));
|
||||
}
|
||||
int type = (int)typeInvoked.REFTYPE_FUNCTION;
|
||||
if (commandID == 0x005E)
|
||||
type = (int)typeInvoked.REFTYPE_MOVEMENT;
|
||||
|
||||
references.Add((pos, destinationID, type, callerID));
|
||||
} catch (KeyNotFoundException) { }
|
||||
}
|
||||
private void SaveToFile(string path) {
|
||||
@@ -702,9 +720,9 @@ namespace DSPRE.ROMFiles {
|
||||
cmdList.Add(toAdd);
|
||||
i++;
|
||||
}
|
||||
cmdList.Add(new ScriptAction(lineSource[i], i+1)); // Add end command
|
||||
cmdList.Add(new ScriptAction(lineSource[i], i+1)); // Read and add end command
|
||||
|
||||
ls.Add(new ActionContainer(actionNumber, actionList: cmdList));
|
||||
ls.Add(new ActionContainer(actionNumber, actionCommandsList: cmdList));
|
||||
}
|
||||
}
|
||||
return ls;
|
||||
|
||||
@@ -404,8 +404,8 @@ namespace DSPRE {
|
||||
} else {
|
||||
ScriptFile itemScript = new ScriptFile(RomInfo.itemScriptFileNumber);
|
||||
for (int i = 0; i < itemScript.allScripts.Count - 1; i++) {
|
||||
itemScript.allScripts[i].commands[0].commandParameters[1] = BitConverter.GetBytes((ushort)i); // Fix item index
|
||||
itemScript.allScripts[i].commands[1].commandParameters[1] = BitConverter.GetBytes((ushort)1); // Fix item quantity
|
||||
itemScript.allScripts[i].commands[0].cmdParams[1] = BitConverter.GetBytes((ushort)i); // Fix item index
|
||||
itemScript.allScripts[i].commands[1].cmdParams[1] = BitConverter.GetBytes((ushort)1); // Fix item quantity
|
||||
}
|
||||
itemScript.SaveToFileDefaultDir(RomInfo.itemScriptFileNumber);
|
||||
MessageBox.Show("Operation successful.", "Process completed.", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
@@ -471,8 +471,7 @@ namespace DSPRE {
|
||||
MessageBox.Show("No changes have been made.", "Operation canceled", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Mikelan's custom commands
|
||||
private void applyCustomCommands(object sender, EventArgs e) {
|
||||
if (new FileInfo(romInfo.syntheticOverlayPath + "\\0000").Length < 0x16000) {// ARM9 expansion hasn't been done in this ROM
|
||||
MessageBox.Show("The ARM9 Expansion patch must be applied before using this feature", "ARM9 expansion needed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
@@ -620,6 +619,7 @@ namespace DSPRE {
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Utilities
|
||||
|
||||
@@ -670,12 +670,14 @@ namespace DSPRE.Resources {
|
||||
[0xFF] = "TRUEUP"
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, bool> commandsWithRelativeJump = new Dictionary<ushort, bool>() {
|
||||
[0x0016] = true,
|
||||
[0x001A] = true,
|
||||
[0x001C] = true,
|
||||
[0x001D] = true,
|
||||
[0x005E] = true
|
||||
public static Dictionary<ushort, int> commandsWithRelativeJump = new Dictionary<ushort, int>() {
|
||||
//commandID, ID of parameter With Jump Address
|
||||
|
||||
[0x0016] = 0, //Jump
|
||||
[0x001A] = 0, //Call
|
||||
[0x001C] = 1, //Jump-If
|
||||
[0x001D] = 1, //Call-If
|
||||
[0x005E] = 1, //Movement
|
||||
};
|
||||
|
||||
public static Dictionary<ushort, string> DPPtScrCmdNames = new Dictionary<ushort, string>() {
|
||||
@@ -3586,26 +3588,26 @@ namespace DSPRE.Resources {
|
||||
|
||||
public static class MatrixCellColors {
|
||||
/* Initialize dictionary of colors corresponding to border maps in the matrix editor */
|
||||
public static Dictionary<List<uint>, Tuple<Color, Color>> DPPtmatrixColorsDict = new Dictionary<List<uint>, Tuple<Color, Color>> {
|
||||
[new List<uint> { 173, 176, 177, 179 }] = Tuple.Create(Color.ForestGreen, Color.White),
|
||||
[new List<uint> { 174 }] = Tuple.Create(Color.SteelBlue, Color.White),
|
||||
[new List<uint> { 175 }] = Tuple.Create(Color.Sienna, Color.White),
|
||||
[new List<uint> { 178 }] = Tuple.Create(Color.PowderBlue, Color.Black),
|
||||
[new List<uint> { Matrix.EMPTY }] = Tuple.Create(Color.Black, Color.White)
|
||||
public static Dictionary<List<uint>, (Color back, Color fore)> DPPtmatrixColorsDict = new Dictionary<List<uint>, (Color back, Color fore)> {
|
||||
[new List<uint> { 173, 176, 177, 179 }] = (Color.ForestGreen, Color.White),
|
||||
[new List<uint> { 174 }] = (Color.SteelBlue, Color.White),
|
||||
[new List<uint> { 175 }] = (Color.Sienna, Color.White),
|
||||
[new List<uint> { 178 }] = (Color.PowderBlue, Color.Black),
|
||||
[new List<uint> { Matrix.EMPTY }] = (Color.Black, Color.White)
|
||||
};
|
||||
public static Dictionary<List<uint>, Tuple<Color, Color>> HGSSmatrixColorsDict = new Dictionary<List<uint>, Tuple<Color, Color>> {
|
||||
[new List<uint> { 208 }] = Tuple.Create(Color.ForestGreen, Color.White),
|
||||
[new List<uint> { 209 }] = Tuple.Create(Color.SteelBlue, Color.White),
|
||||
[new List<uint> { 210 }] = Tuple.Create(Color.Sienna, Color.White),
|
||||
[new List<uint> { Matrix.EMPTY }] = Tuple.Create(Color.Black, Color.White)
|
||||
public static Dictionary<List<uint>, (Color back, Color fore)> HGSSmatrixColorsDict = new Dictionary<List<uint>, (Color back, Color fore)> {
|
||||
[new List<uint> { 208 }] = (Color.ForestGreen, Color.White),
|
||||
[new List<uint> { 209 }] = (Color.SteelBlue, Color.White),
|
||||
[new List<uint> { 210 }] = (Color.Sienna, Color.White),
|
||||
[new List<uint> { Matrix.EMPTY }] = (Color.Black, Color.White)
|
||||
};
|
||||
public static Dictionary<List<uint>, Tuple<Color, Color>> GenericMatrixColorsDict = new Dictionary<List<uint>, Tuple<Color, Color>> {
|
||||
[new List<uint> { 203 }] = Tuple.Create(Color.FromArgb(80, 200, 16), Color.White),
|
||||
[new List<uint> { 204, 209 }] = Tuple.Create(Color.SteelBlue, Color.White),
|
||||
[new List<uint> { 205, 206 }] = Tuple.Create(Color.DarkGreen, Color.White),
|
||||
[new List<uint> { 207, 208 }] = Tuple.Create(Color.ForestGreen, Color.White),
|
||||
[new List<uint> { 210 }] = Tuple.Create(Color.Sienna, Color.White),
|
||||
[new List<uint> { Matrix.EMPTY }] = Tuple.Create(Color.Black, Color.White)
|
||||
public static Dictionary<List<uint>, (Color back, Color fore)> GenericMatrixColorsDict = new Dictionary<List<uint>, (Color back, Color fore)> {
|
||||
[new List<uint> { 203 }] = (Color.FromArgb(80, 200, 16), Color.White),
|
||||
[new List<uint> { 204, 209 }] = (Color.SteelBlue, Color.White),
|
||||
[new List<uint> { 205, 206 }] = (Color.DarkGreen, Color.White),
|
||||
[new List<uint> { 207, 208 }] = (Color.ForestGreen, Color.White),
|
||||
[new List<uint> { 210 }] = (Color.Sienna, Color.White),
|
||||
[new List<uint> { Matrix.EMPTY }] = (Color.Black, Color.White)
|
||||
};
|
||||
}
|
||||
public static class AreaPics {
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace DSPRE {
|
||||
|
||||
public static readonly byte internalNameLength = 16;
|
||||
public string internalNamesLocation { get; private set; }
|
||||
public Dictionary<List<uint>, Tuple<Color, Color>> mapCellsColorDictionary { get; private set; }
|
||||
public Dictionary<List<uint>, (Color background, Color foreground)> mapCellsColorDictionary { get; private set; }
|
||||
public static Dictionary<ushort, string> scriptCommandNamesDict { get; private set; }
|
||||
public static Dictionary<ushort, byte[]> commandParametersDict { get; private set; }
|
||||
|
||||
@@ -532,7 +532,7 @@ namespace DSPRE {
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void SetMapCellsColorDictionary(Dictionary<List<uint>, Tuple<Color, Color>> dict) {
|
||||
public void SetMapCellsColorDictionary(Dictionary<List<uint>, (Color background, Color foreground)> dict) {
|
||||
mapCellsColorDictionary = dict;
|
||||
}
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user