diff --git a/DS_Map/DSUtils.cs b/DS_Map/DSUtils.cs index 270a47b..4f446e8 100644 --- a/DS_Map/DSUtils.cs +++ b/DS_Map/DSUtils.cs @@ -1,4 +1,6 @@ -using System; +using NarcAPI; +using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Windows.Forms; @@ -127,5 +129,54 @@ namespace DSPRE { writer.Write(bytesToWrite, 0, bytesToWrite.Length); } } + + public static void UnpackNarcs(List IDs, int progress) { + string[] narcPaths = RomInfo.narcPaths; + string[] extractedNarcDirs = RomInfo.extractedNarcDirs; + + foreach (int id in IDs) { + var tuple = Tuple.Create(narcPaths[id], extractedNarcDirs[id]); + DirectoryInfo di = new DirectoryInfo(tuple.Item2); + if (!di.Exists || di.GetFiles().Length == 0) { + NarcAPI.Narc.Open(workDir + tuple.Item1).ExtractToFolder(tuple.Item2); + } + + if (progress != null) + try { + progress++; + } catch (ArgumentOutOfRangeException) { } + } + } + public static void ForceUnpackNarcs(List IDs, int progress) { + string[] narcPaths = RomInfo.narcPaths; + string[] extractedNarcDirs = RomInfo.extractedNarcDirs; + + foreach (int id in IDs) { + var tuple = Tuple.Create(narcPaths[id], extractedNarcDirs[id]); + Narc.Open(workDir + tuple.Item1).ExtractToFolder(tuple.Item2); + + if (progress != null) + try { + progress++; + } catch (ArgumentOutOfRangeException) { } + } + } + public static void UnpackNarc(int id) { + string[] narcPaths = RomInfo.narcPaths; + string[] extractedNarcDirs = RomInfo.extractedNarcDirs; + + var tuple = Tuple.Create(narcPaths[id], extractedNarcDirs[id]); + DirectoryInfo di = new DirectoryInfo(tuple.Item2); + if (!di.Exists || di.GetFiles().Length == 0) { + NarcAPI.Narc.Open(workDir + tuple.Item1).ExtractToFolder(tuple.Item2); + } + } + public static void ForceUnpackNarc(int id) { + string[] narcPaths = RomInfo.narcPaths; + string[] extractedNarcDirs = RomInfo.extractedNarcDirs; + + var tuple = Tuple.Create(narcPaths[id], extractedNarcDirs[id]); + Narc.Open(workDir + tuple.Item1).ExtractToFolder(tuple.Item2); + } } } diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 51ab190..586c289 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -42,7 +42,6 @@ namespace DSPRE { public bool textEditorIsReady { get; private set; } = false; public bool tilesetEditorIsReady { get; private set; } = false; - /* ROM Information */ public static string gameCode; public static byte europeByte; @@ -253,7 +252,7 @@ namespace DSPRE { } private void DeleteTempFolders() { - foreach (var tuple in romInfo.narcPaths.Zip(romInfo.extractedNarcDirs, Tuple.Create)) { + foreach (var tuple in RomInfo.narcPaths.Zip(RomInfo.extractedNarcDirs, Tuple.Create)) { Directory.Delete(tuple.Item2, true); // Delete folder } } @@ -286,9 +285,9 @@ namespace DSPRE { toolStripProgressBar.Value = 0; Update(); - UnpackNarcs(new List { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }); + DSUtils.UnpackNarcs(new List { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, toolStripProgressBar.Value); if (romInfo.gameVersion == "HG" || romInfo.gameVersion == "SS") { - UnpackNarcs(new List { romInfo.narcPaths.Length - 1 }); + DSUtils.UnpackNarc(RomInfo.narcPaths.Length - 1); } @@ -335,8 +334,15 @@ namespace DSPRE { owTrainerComboBox.Items.AddRange(trainerNames); /* Add item list to ow item box */ - int count = LoadScriptFile(romInfo.GetItemScriptFileNumber()).scripts.Count - 1; - owItemComboBox.Items.AddRange(GetItemNames(0, count)); + int itemScriptId = romInfo.GetItemScriptFileNumber(); + try { + int count = LoadScriptFile(itemScriptId).scripts.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); + } /* Add ow movement list to box */ owMovementComboBox.Items.AddRange(PokeDatabase.ScriptMovements.moveArray); @@ -402,7 +408,7 @@ namespace DSPRE { statusLabel.Text = "Attempting to unpack Header Editor NARCs... Please wait."; Update(); - UnpackNarcs(new List { 0, 1 }); + DSUtils.UnpackNarcs(new List { 0, 1 }, toolStripProgressBar.Value); statusLabel.Text = "Reading internal names... Please wait."; Update(); @@ -469,14 +475,14 @@ namespace DSPRE { private void SetupMapEditor() { /* Extract essential NARCs sub-archives*/ toolStripProgressBar.Visible = true; - toolStripProgressBar.Maximum = 15; + toolStripProgressBar.Maximum = 14; toolStripProgressBar.Value = 0; statusLabel.Text = "Attempting to unpack Map Editor NARCs... Please wait."; Update(); - UnpackNarcs(new List { 3, 4, 5, 6, 7, 8 }); + DSUtils.UnpackNarcs(new List { 3, 4, 5, 6, 7, 8 }, toolStripProgressBar.Value); if (romInfo.gameVersion == "HG" || romInfo.gameVersion == "SS") { - UnpackNarcs(new List { romInfo.narcPaths.Length - 1 }); + DSUtils.UnpackNarc(RomInfo.narcPaths.Length - 1 ); } disableHandlers = true; @@ -675,7 +681,7 @@ namespace DSPRE { statusLabel.Text = "Setting up Matrix Editor..."; Update(); - UnpackNarcs(new List { 2 }); // 2 = matrixDir + DSUtils.UnpackNarc( 2 ); // 2 = matrixDir disableHandlers = true; @@ -687,12 +693,12 @@ namespace DSPRE { disableHandlers = false; selectMatrixComboBox.SelectedIndex = 0; } - private void SetupScriptEditor() { + public void SetupScriptEditor() { /* Extract essential NARCs sub-archives*/ statusLabel.Text = "Setting up Script Editor..."; Update(); - UnpackNarcs(new List { 12 }); //12 = scripts Narc Dir + DSUtils.UnpackNarc(12); //12 = scripts Narc Dir int scriptCount = Directory.GetFiles(romInfo.scriptDirPath).Length; for (int i = 0; i < scriptCount; i++) @@ -705,10 +711,10 @@ namespace DSPRE { selectScriptFileComboBox.SelectedIndex = 0; } private void SetupTextEditor() { - string[] narcPaths = romInfo.narcPaths; - string[] extractedNarcDirs = romInfo.extractedNarcDirs; + string[] narcPaths = RomInfo.narcPaths; + string[] extractedNarcDirs = RomInfo.extractedNarcDirs; - UnpackNarcs(new List { 1 }); + DSUtils.UnpackNarc( 1 ); statusLabel.Text = "Setting up Text Editor..."; Update(); @@ -722,7 +728,7 @@ namespace DSPRE { statusLabel.Text = "Attempting to unpack Tileset Editor NARCs... Please wait."; Update(); - UnpackNarcs(new List { 6, 7, 8 }); + DSUtils.UnpackNarcs(new List { 6, 7, 8 }, toolStripProgressBar.Value); /* Fill Tileset ListBox */ FillTilesetBox(); @@ -827,31 +833,14 @@ namespace DSPRE { toolStripProgressBar.Value = 0; Update(); - UnpackNarcs(new List { 4, 5, 6 }); + DSUtils.UnpackNarcs(new List { 4, 5, 6 }, toolStripProgressBar.Value); if (romInfo.gameVersion == "HG" || romInfo.gameVersion == "SS") - UnpackNarcs(new List { romInfo.narcPaths.Length - 1 });// Last = interior buildings dir + DSUtils.UnpackNarc(RomInfo.narcPaths.Length - 1 );// Last = interior buildings dir toolStripProgressBar.Value = 0; toolStripProgressBar.Visible = false; } - private void UnpackNarcs(List IDs) { - string[] narcPaths = romInfo.narcPaths; - string[] extractedNarcDirs = romInfo.extractedNarcDirs; - - foreach (int id in IDs) { - var tuple = Tuple.Create(narcPaths[id], extractedNarcDirs[id]); - DirectoryInfo di = new DirectoryInfo(tuple.Item2); - if (!di.Exists || di.GetFiles().Length == 0) { - Narc.Open(romInfo.workDir + tuple.Item1).ExtractToFolder(tuple.Item2); - } - - try { - toolStripProgressBar.Value++; - } catch (ArgumentOutOfRangeException) { } - } - } - private void ForceUnpackBuildingEditorNARCs() { toolStripProgressBar.Visible = true; @@ -861,25 +850,15 @@ namespace DSPRE { toolStripProgressBar.Value = 0; Update(); - forceUnpackNarcs(new List { 4, 5, 6 }); + DSUtils.ForceUnpackNarcs(new List { 4, 5, 6 }, toolStripProgressBar.Value); if (romInfo.gameVersion == "HG" || romInfo.gameVersion == "SS") - forceUnpackNarcs(new List { romInfo.narcPaths.Length - 1 });// Last = interior buildings dir + DSUtils.ForceUnpackNarcs(new List { RomInfo.narcPaths.Length - 1 }, toolStripProgressBar.Value);// Last = interior buildings dir toolStripProgressBar.Value = 0; toolStripProgressBar.Visible = false; } - private void forceUnpackNarcs(List IDs) { - string[] narcPaths = romInfo.narcPaths; - string[] extractedNarcDirs = romInfo.extractedNarcDirs; - - foreach (int id in IDs) { - var tuple = Tuple.Create(narcPaths[id], extractedNarcDirs[id]); - Narc.Open(romInfo.workDir + tuple.Item1).ExtractToFolder(tuple.Item2); - toolStripProgressBar.Value++; - } - - } + private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) { string message = "DS Pokémon Rom Editor by Nømura (Unofficial Branch)" + Environment.NewLine + "version 1.0.7b" + Environment.NewLine @@ -960,7 +939,7 @@ namespace DSPRE { statusLabel.Text = "Attempting to unpack NARCs from folder..."; Update(); - /*foreach (Tuple tuple in romInfo.narcPaths.Zip(romInfo.extractedNarcDirs, Tuple.Create)) + /*foreach (Tuple tuple in RomInfo.narcPaths.Zip(RomInfo.extractedNarcDirs, Tuple.Create)) Narc.Open(romInfo.workDir + tuple.Item1).ExtractToFolder(tuple.Item2);*/ switch (romInfo.gameVersion) { @@ -1007,7 +986,7 @@ namespace DSPRE { Update(); // Repack NARCs - foreach (var tuple in romInfo.narcPaths.Zip(romInfo.extractedNarcDirs, Tuple.Create)) { + foreach (var tuple in RomInfo.narcPaths.Zip(RomInfo.extractedNarcDirs, Tuple.Create)) { DirectoryInfo di = new DirectoryInfo(tuple.Item2); if (di.Exists) { Narc.FromFolder(tuple.Item2).Save(romInfo.workDir + tuple.Item1); // Make new NARC from folder @@ -1041,12 +1020,12 @@ namespace DSPRE { MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (d == DialogResult.Yes) { - toolStripProgressBar.Maximum = romInfo.narcPaths.Length; + toolStripProgressBar.Maximum = RomInfo.narcPaths.Length; toolStripProgressBar.Visible = true; toolStripProgressBar.Value = 0; statusLabel.Text = "Attempting to unpack all NARCs... Be patient. This might take a while..."; Update(); - foreach (var tuple in romInfo.narcPaths.Zip(romInfo.extractedNarcDirs, Tuple.Create)) { + foreach (var tuple in RomInfo.narcPaths.Zip(RomInfo.extractedNarcDirs, Tuple.Create)) { Narc.Open(romInfo.workDir + tuple.Item1).ExtractToFolder(tuple.Item2); toolStripProgressBar.Value++; } @@ -1130,8 +1109,8 @@ namespace DSPRE { statusLabel.Text = "Attempting to extract Wild Encounters NARC..."; Update(); - string[] narcPaths = romInfo.narcPaths; - string[] extractedNarcDirs = romInfo.extractedNarcDirs; + string[] narcPaths = RomInfo.narcPaths; + string[] extractedNarcDirs = RomInfo.extractedNarcDirs; Tuple t; if (romInfo.gameVersion == "HG" || romInfo.gameVersion == "SS") { @@ -2470,7 +2449,6 @@ namespace DSPRE { string[] fileTableContent = File.ReadAllLines(of.FileName); - string mapKeyword = "[Maplist]"; string colorKeyword = "[Color]"; string textColorKeyword = "[TextColor]"; @@ -5141,10 +5119,6 @@ namespace DSPRE { selectScriptFileComboBox.Items.RemoveAt(lastIndex); } private void saveScriptFileButton_Click(object sender, EventArgs e) { - currentScriptFile.scripts.Clear(); - currentScriptFile.functions.Clear(); - currentScriptFile.movements.Clear(); - /* Create new script objects */ List scriptCommands = new List(); populateScriptCommands(scriptCommands); @@ -5155,6 +5129,10 @@ namespace DSPRE { List movementCommands = new List(); populateMovementCommands(movementCommands); + currentScriptFile.scripts.Clear(); + currentScriptFile.functions.Clear(); + currentScriptFile.movements.Clear(); + /* Write new scripts to file */ SaveScriptFile(selectScriptFileComboBox.SelectedIndex); } diff --git a/DS_Map/PokeDatabase.cs b/DS_Map/PokeDatabase.cs index 1c2228a..f966cd6 100644 --- a/DS_Map/PokeDatabase.cs +++ b/DS_Map/PokeDatabase.cs @@ -550,6 +550,394 @@ namespace DSPRE { }; } public static class System { + public static class Scripts { + public static Dictionary byteToComparisonOperatorDict = new Dictionary() { + [0x0] = "LOWER", + [0x1] = "EQUAL", + [0x2] = "LARGER", + [0x3] = "LOWER/EQUAL", + [0x4] = "LARGER/EQUAL", + [0x5] = "DIFFERENT", + [0x6] = "OR", + [0x7] = "AND", + [0xFF] = "TRUEUP" + }; + public static Dictionary stringToComparisonOperatorDict = new Dictionary() { + ["LOWER"] = 0x0, + ["EQUAL"] = 0x1, + ["LARGER"] = 0x2, + ["LOWER/EQUAL"] = 0x3, + ["LARGER/EQUAL"] = 0x4, + ["DIFFERENT"] = 0x5, + ["OR"] = 0x6, + ["AND"] = 0x7, + ["TRUEUP"] = 0xFF + }; + public static Dictionary commandsDictDPPt = new Dictionary() { + ["Nop"] = 0x0000, + ["Dummy"] = 0x0001, + ["End"] = 0x0002, + ["TimeWait"] = 0x0003, + ["CompareVarValue"] = 0x0011, + ["CompareVars"] = 0x0012, + ["CommonScript"] = 0x0014, + ["Jump"] = 0x0016, + ["Call"] = 0x001A, + ["Return"] = 0x001B, + ["Jump-If"] = 0x001C, + ["Call-If"] = 0x001D, + ["SetFlag"] = 0x001E, + ["ClearFlag"] = 0x001F, + ["CheckFlag"] = 0x0020, + ["SetValue"] = 0x0023, + ["CompareVarsToByte"] = 0x0026, + ["SetVar"] = 0x0028, + ["CopyVar"] = 0x0029, + ["Message"] = 0x002C, + ["Message2"] = 0x002D, + ["Message3"] = 0x002F, + ["WaitButton"] = 0x0031, + ["CloseMessage"] = 0x0034, + ["FreezeMessageBox"] = 0x0035, + ["CallMessageBox"] = 0x0036, + ["ColorMessageBox"] = 0x0037, + ["TypeMessageBox"] = 0x0038, + ["NoMapMessageBox"] = 0x0039, + ["CallMessageBoxText"] = 0x003A, + ["Menu"] = 0x003C, + ["YesNoBox"] = 0x003E, + ["WaitFor"] = 0x003F, + ["Multi"] = 0x0040, + ["Multi2"] = 0x0041, + ["TextScriptMulti"] = 0x0042, + ["CloseMulti"] = 0x0043, + ["Multi3"] = 0x0044, + ["TextMessageScript"] = 0x0046, + ["MultiRow"] = 0x0048, + ["PlayFanfare"] = 0x0049, + ["PlayFanfare2"] = 0x004A, + ["WaitFanfare"] = 0x004B, + ["PlayCry"] = 0x004C, + ["WaitCry"] = 0x004D, + ["PlaySound"] = 0x004E, + ["FadeDefaultMusic"] = 0x004F, + ["PlayMusic"] = 0x0050, + ["StopMusic"] = 0x0051, + ["RestartMusic"] = 0x0052, + ["SwitchMusic"] = 0x0054, + ["SwitchMusic2"] = 0x005A, + ["ApplyMovement"] = 0x005E, + ["WaitMovement"] = 0x005F, + ["LockAll"] = 0x0060, + ["ReleaseAll"] = 0x0061, + ["Lock"] = 0x0062, + ["Release"] = 0x0063, + ["AddOW"] = 0x0064, + ["RemoveOW"] = 0x0065, + ["LockCam"] = 0x0066, + ["FacePlayer"] = 0x0068, + ["CheckSpritePosition"] = 0x0069, + ["CheckPersonPosition"] = 0x006B, + ["ContinueFollow"] = 0x006C, + ["FollowHero"] = 0x006D, + ["StopFollowHero"] = 0x006E, + ["GiveMoney"] = 0x006F, + ["TakeMoney"] = 0x0070, + ["CheckMoney"] = 0x0071, + ["ShowMoney"] = 0x0072, + ["HideMoney"] = 0x0073, + ["UpdateMoney"] = 0x0074, + ["ShowCoins"] = 0x0075, + ["HideCoins"] = 0x0076, + ["UpdateCoins"] = 0x0077, + ["CheckCoins"] = 0x0078, + ["GiveCoins"] = 0x0079, + ["TakeCoins"] = 0x007A, + ["TakeItem"] = 0x007B, + ["CheckStoreItem"] = 0x007C, + ["CheckItem"] = 0x007D, + ["CheckUndergroundPCStatus"] = 0x0085, + ["CheckPokémonParty"] = 0x0093, + ["StorePokémonParty"] = 0x0094, + ["SetPokémonPartyStored"] = 0x0095, + ["GivePokémon"] = 0x0096, + ["GiveEgg"] = 0x0097, + ["CheckMove"] = 0x0099, + ["CheckPlaceStored"] = 0x009A, + ["CallEnd"] = 0x00A1, + ["WFC"] = 0x00A3, + ["Interview"] = 0x00A5, + ["DressPokémon"] = 0x00A6, + ["DisplayDressedPokémon"] = 0x00A7, + ["DisplayContestPokémon"] = 0x00A8, + ["CapsuleEditor"] = 0x00A9, + ["SinnohMaps"] = 0x00AA, + ["BoxPokémon"] = 0x00AB, + ["DrawUnion"] = 0x00AC, + ["TrainerCaseUnion"] = 0x00AD, + ["TradeUnion"] = 0x00AE, + ["RecordMixingUnion"] = 0x00AF, + ["EndGame"] = 0x00B0, + ["HallOfFameData"] = 0x00B1, + ["WFC1"] = 0x00B3, + ["ChooseStarter"] = 0x00B4, + ["ChoosePlayerName"] = 0x00BA, + ["ChoosePokémonName"] = 0x00BB, + ["FadeScreen"] = 0x00BC, + ["ResetScreen"] = 0x00BD, + ["Warp"] = 0x00BE, + ["RockClimbAnimation"] = 0x00BF, + ["SurfAnimation"] = 0x00C0, + ["WaterfallAnimation"] = 0x00C1, + ["FlyAnimation"] = 0x00C2, + ["Tuxedo"] = 0x00C6, + ["CheckBike"] = 0x00C7, + ["RideBike"] = 0x00C8, + ["BerryHeroAnimation"] = 0x00CB, + ["StopBerryHeroAnimation"] = 0x00CC, + ["SetVariableHero"] = 0x00CD, + ["SetVariableRival"] = 0x00CE, + ["SetVariableAlter"] = 0x00CF, + ["SetVariablePokémon"] = 0x00D0, + ["SetVariableItem"] = 0x00D1, + ["SetVariableAttackItem"] = 0x00D3, + ["SetVariableAttack"] = 0x00D4, + ["SetVariableNumber"] = 0x00D5, + ["SetVariableNickname"] = 0x00D6, + ["SetVariableObject"] = 0x00D7, + ["SetVariableTrainer"] = 0x00D8, + ["SetVarPokémonStored"] = 0x00DA, + ["SetVarHeroStored"] = 0x00DB, + ["SetVarRivalStored"] = 0x00DC, + ["SetVarAlterStored"] = 0x00DD, + ["StoreStarter"] = 0x00DE, + ["TrainerBattle"] = 0x00E5, + ["EndTrainerBattle"] = 0x00E6, + ["ActLeagueBattlers"] = 0x00EA, + ["LostGoToPokémonCenter"] = 0x00EB, + ["CheckLost"] = 0x00EC, + ["ChooseFriend"] = 0x00F2, + ["WirelessBattleWait"] = 0x00F3, + ["PokémonContest"] = 0x00F7, + ["FlashContest"] = 0x0111, + ["EndFlash"] = 0x0112, + ["ShowLinkCountRecord"] = 0x0116, + ["WarpMapElevator"] = 0x011B, + ["CheckFloor"] = 0x011C, + ["SetPositionAfterShip"] = 0x0120, + ["WildBattle"] = 0x0124, + ["StarterBattle"] = 0x0125, + ["ExplanationBattle"] = 0x0126, + ["HoneyTreeBattle"] = 0x0127, + ["RandomBattle"] = 0x0129, + ["WriteAutograph"] = 0x012B, + ["CheckDress"] = 0x012E, + ["GivePokétch"] = 0x0131, + ["ActivatePokétchApp"] = 0x0133, + ["StorePokétchApp"] = 0x0134, + ["ExpectDecisionOther"] = 0x0143, + ["PokéMart"] = 0x0147, + ["PokéMart1"] = 0x0148, + ["PokéMart2"] = 0x0149, + ["PokéMart3"] = 0x014A, + ["DefeatGoToPokéCenter"] = 0x014B, + ["CheckGender"] = 0x014D, + ["HealPokémon"] = 0x014E, + ["UnionRoom"] = 0x0153, + ["ActivatePokédex"] = 0x0158, + ["GiveRunningShoes"] = 0x015A, + ["CheckBadge"] = 0x015B, + ["EnableBadge"] = 0x015C, + ["DisableBadge"] = 0x015D, + ["PrepareDoorAnimation"] = 0x0168, + ["WaitAction"] = 0x0169, + ["WaitClose"] = 0x016A, + ["OpenDoor"] = 0x016B, + ["CloseDoor"] = 0x016C, + ["CheckPartyNumber"] = 0x0177, + ["OpenBerryPouch"] = 0x0178, + ["SetOverworldPosition"] = 0x0186, + ["SetOverworldMovement"] = 0x0188, + ["ReleaseOverworld"] = 0x0189, + ["SetDoorPassable"] = 0x018A, + ["SetDoorLocked"] = 0x018B, + ["ShowSavingClock"] = 0x018D, + ["HideSavingClock"] = 0x018E, + ["ChoosePokémonMenu"] = 0x0191, + ["ChoosePokémonMenu2"] = 0x0192, + ["StorePokémonMenu2"] = 0x0193, + ["PokémonInfo"] = 0x0195, + ["StorePokémonNumber"] = 0x0198, + ["CheckPartyNumber2"] = 0x019A, + ["EggAnimation"] = 0x01AC, + ["MailBox"] = 0x01B3, + ["RecordList"] = 0x01B5, + ["CheckHappiness"] = 0x01B9, + ["CheckPosition"] = 0x01BD, + ["CheckPokémonParty2"] = 0x01C0, + ["CopyPokémonHeight"] = 0x01C1, + ["SetVariablePokémonHeight"] = 0x01C2, + ["ComparePokémonHeight"] = 0x01C3, + ["CheckPokémonHeight"] = 0x01C4, + ["MoveInfo"] = 0x01C6, + ["StoreMove"] = 0x01C7, + ["DeleteMove"] = 0x01C9, + ["BerryPoffin"] = 0x01D7, + ["BattleRoomResult"] = 0x01D9, + ["CheckSinnohPokédex"] = 0x01E8, + ["CheckNationalPokédex"] = 0x01E9, + ["ShowSinnohCertificate"] = 0x01EA, + ["ShowNationalCertificate"] = 0x01EB, + ["CheckFossil"] = 0x01F1, + ["CheckPokémonLevel"] = 0x01F6, + ["WarpLastElevator"] = 0x0204, + ["GeoNet"] = 0x0205, + ["GreatMarshBinoculars"] = 0x0206, + ["PokémonPicture"] = 0x0208, + ["HidePicture"] = 0x0209, + ["RememberMove"] = 0x0221, + ["TeachMove"] = 0x0224, + ["CheckTeachMove"] = 0x0225, + ["CheckPokémonTrade"] = 0x0228, + ["TradeChosenPokémon"] = 0x0229, + ["StopTrade"] = 0x022A, + ["DecideRules"] = 0x0239, + ["HealPokémonAnimation"] = 0x023B, + ["ShipAnimation"] = 0x023D, + ["PhraseBox1W"] = 0x0243, + ["PhraseBox2W"] = 0x0244, + ["CheckPhraseBoxInput"] = 0x0249, + ["PreparePcAnimation"] = 0x024B, + ["OpenPcAnimation"] = 0x024C, + ["ClosePcAnimation"] = 0x024D, + ["CheckLotteryNumber"] = 0x024E, + ["CompareLotteryNumber"] = 0x024F, + ["CheckBoxesNumber"] = 0x0252, + ["SprtSave"] = 0x0257, + ["RetSprtSave"] = 0x0258, + ["ElevLgAnimation"] = 0x0259, + ["CheckAccessories"] = 0x0261, + ["PokéCasino"] = 0x0267, + ["UnownMessageBox"] = 0x026D, + ["ThankNameInsert"] = 0x0271, + ["LeagueCastleView"] = 0x027A, + ["PokémonPartyPicture"] = 0x028C, + ["CheckFirstTimeChampion"] = 0x028F, + ["ShowBattlePointsBox"] = 0x0294, + ["HideBattlePointsBox"] = 0x0295, + ["ChoiceMulti"] = 0x029D, + ["HiddenMachineEffect"] = 0x029E, + ["CameraBumpEffect"] = 0x029F, + ["DoubleBattle"] = 0x02A0, + ["ApplyMovement2"] = 0x02A1, + ["ChooseTradePokémon"] = 0x02A5, + ["ComparePhraseBoxInput"] = 0x02AA, + ["ActivateMysteryGift"] = 0x02AC, + ["CheckWildBattle2"] = 0x02BC, + ["WildBattle2"] = 0x02BD, + ["BikeRide"] = 0x02BF, + ["ShowSaveBox"] = 0x02C1, + ["HideSaveBox"] = 0x02C2, + ["SpinTradeUnion"] = 0x02C6, + ["CheckGameVersion"] = 0x02C7, + ["FloralClockAnimation"] = 0x02CA, + ["PortalEffect"] = 0x0328, + ["DisplayFloor"] = 0x0347 + }; + public static Dictionary movementsDictDPPtHGSS = new Dictionary() { + ["LookUp"] = 0x0000, + ["LookDown"] = 0x0001, + ["LookLeft"] = 0x0002, + ["LookRight"] = 0x0003, + ["WalkUpSlow"] = 0x0004, + ["WalkDownSlow"] = 0x0005, + ["WalkLeftSlow"] = 0x0006, + ["WalkRightSlow"] = 0x0007, + ["WalkUp"] = 0x0008, + ["WalkDown"] = 0x0009, + ["WalkLeft"] = 0x000A, + ["WalkRight"] = 0x000B, + ["WalkUpFast"] = 0x000C, + ["WalkDownFast"] = 0x000D, + ["WalkLeftFast"] = 0x000E, + ["WalkRightFast"] = 0x000F, + ["WalkUpVeryFast"] = 0x0010, + ["WalkDownVeryFast"] = 0x0011, + ["WalkLeftVeryFast"] = 0x0012, + ["WalkRightVeryFast"] = 0x0013, + ["RunUp"] = 0x0014, + ["RunDown"] = 0x0015, + ["RunLeft"] = 0x0016, + ["RunRight"] = 0x0017, + ["WalkUpSlowSite"] = 0x0018, + ["WalkDownSlowSite"] = 0x0019, + ["WalkLeftSlowSite"] = 0x001A, + ["WalkRightSlowSite"] = 0x001B, + ["WalkUpSite"] = 0x001C, + ["WalkDownSite"] = 0x001D, + ["WalkLeftSite"] = 0x001E, + ["WalkRightSite"] = 0x001F, + ["WalkUpFastSite"] = 0x0020, + ["WalkDownFastSite"] = 0x0021, + ["WalkLeftFastSite"] = 0x0022, + ["WalkRightFastSite"] = 0x0023, + ["WalkUpVeryFastSite"] = 0x0024, + ["WalkDownVeryFastSite"] = 0x0025, + ["WalkLeftVeryFastSite"] = 0x0026, + ["WalkRightVeryFastSite"] = 0x0027, + ["RunUpSite"] = 0x0028, + ["RunDownSite"] = 0x0029, + ["RunLeftSite"] = 0x002A, + ["RunRightSite"] = 0x002B, + ["JumpUpSlow"] = 0x002C, + ["JumpDownSlow"] = 0x002D, + ["JumpLeftSlow"] = 0x002E, + ["JumpRightSlow"] = 0x002F, + ["JumpUpSite"] = 0x0030, + ["JumpDownSite"] = 0x0031, + ["JumpLeftSite"] = 0x0032, + ["JumpRightSite"] = 0x0033, + ["JumpUp"] = 0x0034, + ["JumpDown"] = 0x0035, + ["JumpLeft"] = 0x0036, + ["JumpRight"] = 0x0037, + ["JumpUp2"] = 0x0038, + ["JumpDown2"] = 0x0039, + ["JumpLeft2"] = 0x003A, + ["JumpRight2"] = 0x003B, + ["DelayShort"] = 0x003F, + ["Delay"] = 0x0042, + ["WaitDisappear"] = 0x0045, + ["LockDirection"] = 0x0047, + ["ReleaseDirection"] = 0x0048, + ["Exclamation"] = 0x004B, + ["WaitWalkUpSlow"] = 0x004C, + ["WaitWalkDownSlow"] = 0x004D, + ["WaitWalkLeftSlow"] = 0x004E, + ["WaitWalkRightSlow"] = 0x004F, + ["WaitWalkUp"] = 0x0050, + ["WaitWalkDown"] = 0x0051, + ["WaitWalkLeft"] = 0x0052, + ["WaitWalkRight"] = 0x0053, + ["WaitMoveUp"] = 0x0054, + ["WaitMoveDown"] = 0x0055, + ["WaitMoveLeft"] = 0x0056, + ["WaitMoveRight"] = 0x0057, + ["WaitWalkBackUp"] = 0x0058, + ["WaitWalkBackDown"] = 0x0059, + ["WaitWalkBackLeft"] = 0x005A, + ["WaitWalkBackRight"] = 0x005B, + ["WaitJumpLeft1"] = 0x005C, + ["WaitJumpRight1"] = 0x005D, + ["WaitJumpLeft2"] = 0x005E, + ["WaitJumpRight2"] = 0x005F, + ["WaitMoveSite"] = 0x0064, + ["WaitJumpSite"] = 0x0065, + ["WaitDoubleExclamation"] = 0x0067, + ["WaitMoveForever"] = 0x0068, + ["End"] = 0x00FE + }; + } public static Dictionary headerOffsetsDict = new Dictionary() { ["ADAE"] = 0xEEDBC, ["APAE"] = 0xEEDBC, diff --git a/DS_Map/ROMToolboxDialog.cs b/DS_Map/ROMToolboxDialog.cs index b28ec99..2c104a1 100644 --- a/DS_Map/ROMToolboxDialog.cs +++ b/DS_Map/ROMToolboxDialog.cs @@ -1,5 +1,6 @@ using NarcAPI; using System; +using System.Collections.Generic; using System.IO; using System.Reflection; using System.Resources; @@ -19,19 +20,40 @@ namespace DSPRE this.romInfo = romInfo; } - private void applyItemStandardizeButton_Click(object sender, EventArgs e) - { - string path = romInfo.scriptDirPath + "\\" + romInfo.GetItemScriptFileNumber().ToString("D4"); + private void applyItemStandardizeButton_Click(object sender, EventArgs e) { + try { + if (standardizedItems == true) { + throw new ApplicationException(); + } + DSUtils.UnpackNarc(12); + string itemScriptPath = romInfo.scriptDirPath + "\\" + romInfo.GetItemScriptFileNumber().ToString("D4"); + ScriptFile itemScript = new ScriptFile(new FileStream(itemScriptPath, FileMode.Open), romInfo.gameVersion); - ScriptFile file = new ScriptFile(new FileStream(path, FileMode.Open), romInfo.gameVersion); - for (int i = 0; i < file.scripts.Count - 1; i++) - { - file.scripts[i].commands[0].parameters[1] = BitConverter.GetBytes((ushort)i); // Fix item index - file.scripts[i].commands[1].parameters[1] = BitConverter.GetBytes((ushort)1); // Fix item quantity + bool errorFlag = false; + for (int i = 0; i < itemScript.scripts.Count - 1; i++) { + if (itemScript.scripts[i].commands[0].parameters[1] != BitConverter.GetBytes((ushort)i) || itemScript.scripts[i].commands[1].parameters[1] != BitConverter.GetBytes((ushort)1)) { + errorFlag = true; + break; + } + } + + if (errorFlag) { + for (int i = 0; i < itemScript.scripts.Count - 1; i++) { + itemScript.scripts[i].commands[0].parameters[1] = BitConverter.GetBytes((ushort)i); // Fix item index + itemScript.scripts[i].commands[1].parameters[1] = BitConverter.GetBytes((ushort)1); // Fix item quantity + } + using (BinaryWriter writer = new BinaryWriter(new FileStream(itemScriptPath, FileMode.Create))) + writer.Write(itemScript.Save()); + + MessageBox.Show("Operation successful.", "Process completed.", MessageBoxButtons.OK, MessageBoxIcon.Information); + } else { + standardizedItems = true; + throw new ApplicationException(); + } + } catch (ApplicationException) { + MessageBox.Show("This patch has already been applied.", "Can't reapply patch", MessageBoxButtons.OK, MessageBoxIcon.Information); + return; } - using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create))) writer.Write(file.Save()); - - standardizedItems = true; } private void applyARM9ExpansionButton_Click(object sender, EventArgs e) { @@ -57,7 +79,7 @@ namespace DSPRE branchCodeString = arm9DB.GetString("branchCode" + "D" + lang); branchOffset = 0x02000C80; switch (lang) { - case "USA": + case "ENG": initOffset = 0x021064EC; break; case "ESP": @@ -73,7 +95,7 @@ namespace DSPRE branchCodeString = arm9DB.GetString("branchCode" + version + lang); branchOffset = 0x02000CB4; switch (lang) { - case "USA": + case "ENG": initOffset = 0x02100E20; break; case "ESP": @@ -90,7 +112,7 @@ namespace DSPRE branchCodeString = arm9DB.GetString("branchCode" + "HG" + lang); branchOffset = 0x02000CD0; switch (lang) { - case "USA": + case "ENG": initOffset = 0x02110334; break; case "ESP": @@ -193,9 +215,8 @@ namespace DSPRE BinaryWriter f = new BinaryWriter(File.Create(fullFilePath)); for (int i = 0; i < 0x16000; i++) f.Write((byte)0x00); - f.Close(); - + f.Close(); return true; } @@ -224,13 +245,13 @@ namespace DSPRE } private void unsupportedROM() { - MessageBox.Show("This operation is currently impossible to carry out on any Pokémon " + romInfo.gameVersion + "romInfo.", + MessageBox.Show("This operation is currently impossible to carry out on any Pokémon " + romInfo.gameVersion + "rom.", "Unsupported ROM", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void unsupportedROMLanguage() { MessageBox.Show("This operation is currently impossible to carry out on the " + romInfo.gameLanguage + - " version of this romInfo.", "Unsupported language", MessageBoxButtons.OK, MessageBoxIcon.Information); + " version of this rom.", "Unsupported language", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } diff --git a/DS_Map/RomInfo.cs b/DS_Map/RomInfo.cs index c7a0c24..d9fc8a2 100644 --- a/DS_Map/RomInfo.cs +++ b/DS_Map/RomInfo.cs @@ -36,8 +36,8 @@ namespace DSPRE { public string textArchivesPath { get; private set; } public string encounterDirPath { get; private set; } public string trainerDataDirPath { get; private set; } - public string[] narcPaths { get; private set; } - public string[] extractedNarcDirs { get; private set; } + public static string[] narcPaths { get; private set; } + public static string[] extractedNarcDirs { get; private set; } public int nullEncounterID { get; private set; } public int attackNamesTextNumber { get; private set; } diff --git a/DS_Map/ScriptFile.cs b/DS_Map/ScriptFile.cs index bbf0420..9442c6e 100644 --- a/DS_Map/ScriptFile.cs +++ b/DS_Map/ScriptFile.cs @@ -27,19 +27,19 @@ namespace DSPRE { List movementOffsets = new List(); ushort[] endCodes = new ushort[] { 0x2, 0x16, 0x1B }; - using (BinaryReader scriptFileReader = new BinaryReader(fs)) { + using (BinaryReader scrReader = new BinaryReader(fs)) { /* Read script offsets from the header */ try { - while (scriptFileReader.ReadUInt16() != 0xFD13) { - scriptFileReader.BaseStream.Position -= 0x2; - uint value = scriptFileReader.ReadUInt32(); + while (scrReader.ReadUInt16() != 0xFD13) { + scrReader.BaseStream.Position -= 0x2; + uint value = scrReader.ReadUInt32(); if (value == 0) { isLevelScript = true; return; } else { - uint offset = value + (uint)scriptFileReader.BaseStream.Position; - scriptOffsets.Add(offset); // Don't change order of addition + uint offsetFromStart = value + (uint)scrReader.BaseStream.Position; + scriptOffsets.Add(offsetFromStart); // Don't change order of addition } } } catch (EndOfStreamException) { @@ -52,14 +52,16 @@ namespace DSPRE { if (duplicateIndex != i) scripts.Add(new Script(duplicateIndex)); else { - scriptFileReader.BaseStream.Position = scriptOffsets[i]; + scrReader.BaseStream.Position = scriptOffsets[i]; List commandsList = new List(); bool endScript = new bool(); while (!endScript) { - Command command = Read_Command(scriptFileReader, ref functionOffsets, ref movementOffsets, gameVersion); + Command command = Read_Command(scrReader, ref functionOffsets, ref movementOffsets, gameVersion); commandsList.Add(command); - if (endCodes.Contains(command.id)) endScript = true; + + if (endCodes.Contains(command.id)) + endScript = true; } this.scripts.Add(new Script(commandsList)); } @@ -67,14 +69,15 @@ namespace DSPRE { /* Read functions */ for (int i = 0; i < functionOffsets.Count; i++) { - scriptFileReader.BaseStream.Position = functionOffsets[i]; + scrReader.BaseStream.Position = functionOffsets[i]; List commandsList = new List(); bool endFunction = new bool(); while (!endFunction) { - Command command = Read_Command(scriptFileReader, ref functionOffsets, ref movementOffsets, gameVersion); + Command command = Read_Command(scrReader, ref functionOffsets, ref movementOffsets, gameVersion); commandsList.Add(command); - if (endCodes.Contains(command.id)) endFunction = true; + if (endCodes.Contains(command.id)) + endFunction = true; } this.functions.Add(new Script(commandsList)); @@ -82,18 +85,20 @@ namespace DSPRE { /* Read movements */ for (int i = 0; i < movementOffsets.Count; i++) { - scriptFileReader.BaseStream.Position = movementOffsets[i]; + scrReader.BaseStream.Position = movementOffsets[i]; List commandsList = new List(); bool endMovement = new bool(); while (!endMovement) { - ushort id = scriptFileReader.ReadUInt16(); + ushort id = scrReader.ReadUInt16(); List parameters = new List(); - if (id != 0xFE) parameters.Add(scriptFileReader.ReadBytes(2)); + if (id != 0xFE) + parameters.Add(scrReader.ReadBytes(2)); Command command = new Command(id, parameters, gameVersion, true); commandsList.Add(command); - if (command.id == 0xFE) endMovement = true; + if (command.id == 0xFE) + endMovement = true; } this.movements.Add(new Script(commandsList)); @@ -308,13 +313,20 @@ namespace DSPRE { goto default; break; default: - Console.WriteLine("Loaded command id : " + id.ToString("X4")); - string[] indexes = paramDatabase.GetString(id.ToString("X4")).Split(' '); - for (int i = 1; i < indexes.Length; i++) { - int length = Convert.ToInt32(indexes[i]); - parameters.Add(dataReader.ReadBytes(length)); + Console.WriteLine("Loaded command id: " + id.ToString("X4")); + try { + string[] databaseResult = paramDatabase.GetString(id.ToString("X4")).Split(' '); + int numberOfParameters = Int32.Parse(databaseResult[0]); + + for (int i = 1; i <= numberOfParameters; i++) { + int parameterSize = Int32.Parse(databaseResult[i]); + parameters.Add(dataReader.ReadBytes(parameterSize)); + } + break; + } catch (NullReferenceException) { + MessageBox.Show("Unrecognized script command " + id, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return null; } - break; } return new Command(id, parameters, gameVersion, false); @@ -451,32 +463,22 @@ namespace DSPRE { #region Constructors (2) public Command(ushort id, List parameters, string gameVersion, bool isMovement) { - Dictionary operatorsDict = new Dictionary() { - [0x0] = "LOWER", - [0x1] = "EQUAL", - [0x2] = "LARGER", - [0x3] = "LOWER/EQUAL", - [0x4] = "LARGER/EQUAL", - [0x5] = "DIFFERENT", - [0x6] = "OR", - [0x7] = "AND", - [0xFF] = "TRUEUP" - }; - ResourceManager commandDatabase; + ResourceManager commandNamesDatabase; if (isMovement) { - commandDatabase = new ResourceManager("DSPRE.Resources.MovementNames", Assembly.GetExecutingAssembly()); + commandNamesDatabase = new ResourceManager("DSPRE.Resources.MovementNames", Assembly.GetExecutingAssembly()); } else { if (gameVersion == "D" || gameVersion == "P" || gameVersion == "Plat") - commandDatabase = new ResourceManager("DSPRE.Resources.ScriptNamesDP", Assembly.GetExecutingAssembly()); + commandNamesDatabase = new ResourceManager("DSPRE.Resources.ScriptNamesDP", Assembly.GetExecutingAssembly()); else - commandDatabase = new ResourceManager("DSPRE.Resources.ScriptNamesHGSS", Assembly.GetExecutingAssembly()); + commandNamesDatabase = new ResourceManager("DSPRE.Resources.ScriptNamesHGSS", Assembly.GetExecutingAssembly()); } + this.id = id; + this.isMovement = isMovement; this.parameters = parameters; - this.cmdName = commandDatabase.GetString(id.ToString("X4")); + this.cmdName = commandNamesDatabase.GetString(id.ToString("X4")); if (cmdName == null) cmdName = id.ToString("X4"); - this.isMovement = isMovement; for (int i = 0; i < parameters.Count; i++) { if (parameters[i].Length < 4) { @@ -494,7 +496,7 @@ namespace DSPRE { case 0x1C: // CompareLastResultJump case 0x1D: // CompareLastResultCall byte opcode = parameters[0][0]; - this.cmdName += " " + operatorsDict[opcode] + " " + "Function_#" + (1 + (BitConverter.ToInt32(parameters[1], 0))).ToString("D"); + this.cmdName += " " + PokeDatabase.System.Scripts.byteToComparisonOperatorDict[opcode] + " " + "Function_#" + (1 + (BitConverter.ToInt32(parameters[1], 0))).ToString("D"); break; case 0x5E: // ApplyMovement this.cmdName += " " + "Overworld_#" + (BitConverter.ToInt16(parameters[0], 0)).ToString("D") + " " + "Movement_#" + (1 + (BitConverter.ToInt32(parameters[1], 0))).ToString("D"); @@ -537,370 +539,7 @@ namespace DSPRE { Console.WriteLine(String.Join(",", words)); Console.WriteLine(gameVersion); /* Get command id, which is always first in the description */ - Dictionary commandsDictDPPt = new Dictionary() { - ["Nop"] = 0x0000, - ["Dummy"] = 0x0001, - ["End"] = 0x0002, - ["TimeWait"] = 0x0003, - ["CompareVarValue"] = 0x0011, - ["CompareVars"] = 0x0012, - ["CommonScript"] = 0x0014, - ["Jump"] = 0x0016, - ["Call"] = 0x001A, - ["Return"] = 0x001B, - ["Jump-If"] = 0x001C, - ["Call-If"] = 0x001D, - ["SetFlag"] = 0x001E, - ["ClearFlag"] = 0x001F, - ["CheckFlag"] = 0x0020, - ["SetValue"] = 0x0023, - ["CompareVarsToByte"] = 0x0026, - ["SetVar"] = 0x0028, - ["CopyVar"] = 0x0029, - ["Message"] = 0x002C, - ["Message2"] = 0x002D, - ["Message3"] = 0x002F, - ["WaitButton"] = 0x0031, - ["CloseMessage"] = 0x0034, - ["FreezeMessageBox"] = 0x0035, - ["CallMessageBox"] = 0x0036, - ["ColorMessageBox"] = 0x0037, - ["TypeMessageBox"] = 0x0038, - ["NoMapMessageBox"] = 0x0039, - ["CallMessageBoxText"] = 0x003A, - ["Menu"] = 0x003C, - ["YesNoBox"] = 0x003E, - ["WaitFor"] = 0x003F, - ["Multi"] = 0x0040, - ["Multi2"] = 0x0041, - ["TextScriptMulti"] = 0x0042, - ["CloseMulti"] = 0x0043, - ["Multi3"] = 0x0044, - ["TextMessageScript"] = 0x0046, - ["MultiRow"] = 0x0048, - ["PlayFanfare"] = 0x0049, - ["PlayFanfare2"] = 0x004A, - ["WaitFanfare"] = 0x004B, - ["PlayCry"] = 0x004C, - ["WaitCry"] = 0x004D, - ["PlaySound"] = 0x004E, - ["FadeDefaultMusic"] = 0x004F, - ["PlayMusic"] = 0x0050, - ["StopMusic"] = 0x0051, - ["RestartMusic"] = 0x0052, - ["SwitchMusic"] = 0x0054, - ["SwitchMusic2"] = 0x005A, - ["ApplyMovement"] = 0x005E, - ["WaitMovement"] = 0x005F, - ["LockAll"] = 0x0060, - ["ReleaseAll"] = 0x0061, - ["Lock"] = 0x0062, - ["Release"] = 0x0063, - ["AddOW"] = 0x0064, - ["RemoveOW"] = 0x0065, - ["LockCam"] = 0x0066, - ["FacePlayer"] = 0x0068, - ["CheckSpritePosition"] = 0x0069, - ["CheckPersonPosition"] = 0x006B, - ["ContinueFollow"] = 0x006C, - ["FollowHero"] = 0x006D, - ["StopFollowHero"] = 0x006E, - ["GiveMoney"] = 0x006F, - ["TakeMoney"] = 0x0070, - ["CheckMoney"] = 0x0071, - ["ShowMoney"] = 0x0072, - ["HideMoney"] = 0x0073, - ["UpdateMoney"] = 0x0074, - ["ShowCoins"] = 0x0075, - ["HideCoins"] = 0x0076, - ["UpdateCoins"] = 0x0077, - ["CheckCoins"] = 0x0078, - ["GiveCoins"] = 0x0079, - ["TakeCoins"] = 0x007A, - ["TakeItem"] = 0x007B, - ["CheckStoreItem"] = 0x007C, - ["CheckItem"] = 0x007D, - ["CheckUndergroundPCStatus"] = 0x0085, - ["CheckPokémonParty"] = 0x0093, - ["StorePokémonParty"] = 0x0094, - ["SetPokémonPartyStored"] = 0x0095, - ["GivePokémon"] = 0x0096, - ["GiveEgg"] = 0x0097, - ["CheckMove"] = 0x0099, - ["CheckPlaceStored"] = 0x009A, - ["CallEnd"] = 0x00A1, - ["WFC"] = 0x00A3, - ["Interview"] = 0x00A5, - ["DressPokémon"] = 0x00A6, - ["DisplayDressedPokémon"] = 0x00A7, - ["DisplayContestPokémon"] = 0x00A8, - ["CapsuleEditor"] = 0x00A9, - ["SinnohMaps"] = 0x00AA, - ["BoxPokémon"] = 0x00AB, - ["DrawUnion"] = 0x00AC, - ["TrainerCaseUnion"] = 0x00AD, - ["TradeUnion"] = 0x00AE, - ["RecordMixingUnion"] = 0x00AF, - ["EndGame"] = 0x00B0, - ["HallOfFameData"] = 0x00B1, - ["WFC1"] = 0x00B3, - ["ChooseStarter"] = 0x00B4, - ["ChoosePlayerName"] = 0x00BA, - ["ChoosePokémonName"] = 0x00BB, - ["FadeScreen"] = 0x00BC, - ["ResetScreen"] = 0x00BD, - ["Warp"] = 0x00BE, - ["RockClimbAnimation"] = 0x00BF, - ["SurfAnimation"] = 0x00C0, - ["WaterfallAnimation"] = 0x00C1, - ["FlyAnimation"] = 0x00C2, - ["Tuxedo"] = 0x00C6, - ["CheckBike"] = 0x00C7, - ["RideBike"] = 0x00C8, - ["BerryHeroAnimation"] = 0x00CB, - ["StopBerryHeroAnimation"] = 0x00CC, - ["SetVariableHero"] = 0x00CD, - ["SetVariableRival"] = 0x00CE, - ["SetVariableAlter"] = 0x00CF, - ["SetVariablePokémon"] = 0x00D0, - ["SetVariableItem"] = 0x00D1, - ["SetVariableAttackItem"] = 0x00D3, - ["SetVariableAttack"] = 0x00D4, - ["SetVariableNumber"] = 0x00D5, - ["SetVariableNickname"] = 0x00D6, - ["SetVariableObject"] = 0x00D7, - ["SetVariableTrainer"] = 0x00D8, - ["SetVarPokémonStored"] = 0x00DA, - ["SetVarHeroStored"] = 0x00DB, - ["SetVarRivalStored"] = 0x00DC, - ["SetVarAlterStored"] = 0x00DD, - ["StoreStarter"] = 0x00DE, - ["TrainerBattle"] = 0x00E5, - ["EndTrainerBattle"] = 0x00E6, - ["ActLeagueBattlers"] = 0x00EA, - ["LostGoToPokémonCenter"] = 0x00EB, - ["CheckLost"] = 0x00EC, - ["ChooseFriend"] = 0x00F2, - ["WirelessBattleWait"] = 0x00F3, - ["PokémonContest"] = 0x00F7, - ["FlashContest"] = 0x0111, - ["EndFlash"] = 0x0112, - ["ShowLinkCountRecord"] = 0x0116, - ["WarpMapElevator"] = 0x011B, - ["CheckFloor"] = 0x011C, - ["SetPositionAfterShip"] = 0x0120, - ["WildBattle"] = 0x0124, - ["StarterBattle"] = 0x0125, - ["ExplanationBattle"] = 0x0126, - ["HoneyTreeBattle"] = 0x0127, - ["RandomBattle"] = 0x0129, - ["WriteAutograph"] = 0x012B, - ["CheckDress"] = 0x012E, - ["GivePokétch"] = 0x0131, - ["ActivatePokétchApp"] = 0x0133, - ["StorePokétchApp"] = 0x0134, - ["ExpectDecisionOther"] = 0x0143, - ["PokéMart"] = 0x0147, - ["PokéMart1"] = 0x0148, - ["PokéMart2"] = 0x0149, - ["PokéMart3"] = 0x014A, - ["DefeatGoToPokéCenter"] = 0x014B, - ["CheckGender"] = 0x014D, - ["HealPokémon"] = 0x014E, - ["UnionRoom"] = 0x0153, - ["ActivatePokédex"] = 0x0158, - ["GiveRunningShoes"] = 0x015A, - ["CheckBadge"] = 0x015B, - ["EnableBadge"] = 0x015C, - ["DisableBadge"] = 0x015D, - ["PrepareDoorAnimation"] = 0x0168, - ["WaitAction"] = 0x0169, - ["WaitClose"] = 0x016A, - ["OpenDoor"] = 0x016B, - ["CloseDoor"] = 0x016C, - ["CheckPartyNumber"] = 0x0177, - ["OpenBerryPouch"] = 0x0178, - ["SetOverworldPosition"] = 0x0186, - ["SetOverworldMovement"] = 0x0188, - ["ReleaseOverworld"] = 0x0189, - ["SetDoorPassable"] = 0x018A, - ["SetDoorLocked"] = 0x018B, - ["ShowSavingClock"] = 0x018D, - ["HideSavingClock"] = 0x018E, - ["ChoosePokémonMenu"] = 0x0191, - ["ChoosePokémonMenu2"] = 0x0192, - ["StorePokémonMenu2"] = 0x0193, - ["PokémonInfo"] = 0x0195, - ["StorePokémonNumber"] = 0x0198, - ["CheckPartyNumber2"] = 0x019A, - ["EggAnimation"] = 0x01AC, - ["MailBox"] = 0x01B3, - ["RecordList"] = 0x01B5, - ["CheckHappiness"] = 0x01B9, - ["CheckPosition"] = 0x01BD, - ["CheckPokémonParty2"] = 0x01C0, - ["CopyPokémonHeight"] = 0x01C1, - ["SetVariablePokémonHeight"] = 0x01C2, - ["ComparePokémonHeight"] = 0x01C3, - ["CheckPokémonHeight"] = 0x01C4, - ["MoveInfo"] = 0x01C6, - ["StoreMove"] = 0x01C7, - ["DeleteMove"] = 0x01C9, - ["BerryPoffin"] = 0x01D7, - ["BattleRoomResult"] = 0x01D9, - ["CheckSinnohPokédex"] = 0x01E8, - ["CheckNationalPokédex"] = 0x01E9, - ["ShowSinnohCertificate"] = 0x01EA, - ["ShowNationalCertificate"] = 0x01EB, - ["CheckFossil"] = 0x01F1, - ["CheckPokémonLevel"] = 0x01F6, - ["WarpLastElevator"] = 0x0204, - ["GeoNet"] = 0x0205, - ["GreatMarshBinoculars"] = 0x0206, - ["PokémonPicture"] = 0x0208, - ["HidePicture"] = 0x0209, - ["RememberMove"] = 0x0221, - ["TeachMove"] = 0x0224, - ["CheckTeachMove"] = 0x0225, - ["CheckPokémonTrade"] = 0x0228, - ["TradeChosenPokémon"] = 0x0229, - ["StopTrade"] = 0x022A, - ["DecideRules"] = 0x0239, - ["HealPokémonAnimation"] = 0x023B, - ["ShipAnimation"] = 0x023D, - ["PhraseBox1W"] = 0x0243, - ["PhraseBox2W"] = 0x0244, - ["CheckPhraseBoxInput"] = 0x0249, - ["PreparePcAnimation"] = 0x024B, - ["OpenPcAnimation"] = 0x024C, - ["ClosePcAnimation"] = 0x024D, - ["CheckLotteryNumber"] = 0x024E, - ["CompareLotteryNumber"] = 0x024F, - ["CheckBoxesNumber"] = 0x0252, - ["SprtSave"] = 0x0257, - ["RetSprtSave"] = 0x0258, - ["ElevLgAnimation"] = 0x0259, - ["CheckAccessories"] = 0x0261, - ["PokéCasino"] = 0x0267, - ["UnownMessageBox"] = 0x026D, - ["ThankNameInsert"] = 0x0271, - ["LeagueCastleView"] = 0x027A, - ["PokémonPartyPicture"] = 0x028C, - ["CheckFirstTimeChampion"] = 0x028F, - ["ShowBattlePointsBox"] = 0x0294, - ["HideBattlePointsBox"] = 0x0295, - ["ChoiceMulti"] = 0x029D, - ["HiddenMachineEffect"] = 0x029E, - ["CameraBumpEffect"] = 0x029F, - ["DoubleBattle"] = 0x02A0, - ["ApplyMovement2"] = 0x02A1, - ["ChooseTradePokémon"] = 0x02A5, - ["ComparePhraseBoxInput"] = 0x02AA, - ["ActivateMysteryGift"] = 0x02AC, - ["CheckWildBattle2"] = 0x02BC, - ["WildBattle2"] = 0x02BD, - ["BikeRide"] = 0x02BF, - ["ShowSaveBox"] = 0x02C1, - ["HideSaveBox"] = 0x02C2, - ["SpinTradeUnion"] = 0x02C6, - ["CheckGameVersion"] = 0x02C7, - ["FloralClockAnimation"] = 0x02CA, - ["PortalEffect"] = 0x0328, - ["DisplayFloor"] = 0x0347 - }; - Dictionary movementsDictDPPtHGSS = new Dictionary() { - ["LookUp"] = 0x0000, - ["LookDown"] = 0x0001, - ["LookLeft"] = 0x0002, - ["LookRight"] = 0x0003, - ["WalkUpSlow"] = 0x0004, - ["WalkDownSlow"] = 0x0005, - ["WalkLeftSlow"] = 0x0006, - ["WalkRightSlow"] = 0x0007, - ["WalkUp"] = 0x0008, - ["WalkDown"] = 0x0009, - ["WalkLeft"] = 0x000A, - ["WalkRight"] = 0x000B, - ["WalkUpFast"] = 0x000C, - ["WalkDownFast"] = 0x000D, - ["WalkLeftFast"] = 0x000E, - ["WalkRightFast"] = 0x000F, - ["WalkUpVeryFast"] = 0x0010, - ["WalkDownVeryFast"] = 0x0011, - ["WalkLeftVeryFast"] = 0x0012, - ["WalkRightVeryFast"] = 0x0013, - ["RunUp"] = 0x0014, - ["RunDown"] = 0x0015, - ["RunLeft"] = 0x0016, - ["RunRight"] = 0x0017, - ["WalkUpSlowSite"] = 0x0018, - ["WalkDownSlowSite"] = 0x0019, - ["WalkLeftSlowSite"] = 0x001A, - ["WalkRightSlowSite"] = 0x001B, - ["WalkUpSite"] = 0x001C, - ["WalkDownSite"] = 0x001D, - ["WalkLeftSite"] = 0x001E, - ["WalkRightSite"] = 0x001F, - ["WalkUpFastSite"] = 0x0020, - ["WalkDownFastSite"] = 0x0021, - ["WalkLeftFastSite"] = 0x0022, - ["WalkRightFastSite"] = 0x0023, - ["WalkUpVeryFastSite"] = 0x0024, - ["WalkDownVeryFastSite"] = 0x0025, - ["WalkLeftVeryFastSite"] = 0x0026, - ["WalkRightVeryFastSite"] = 0x0027, - ["RunUpSite"] = 0x0028, - ["RunDownSite"] = 0x0029, - ["RunLeftSite"] = 0x002A, - ["RunRightSite"] = 0x002B, - ["JumpUpSlow"] = 0x002C, - ["JumpDownSlow"] = 0x002D, - ["JumpLeftSlow"] = 0x002E, - ["JumpRightSlow"] = 0x002F, - ["JumpUpSite"] = 0x0030, - ["JumpDownSite"] = 0x0031, - ["JumpLeftSite"] = 0x0032, - ["JumpRightSite"] = 0x0033, - ["JumpUp"] = 0x0034, - ["JumpDown"] = 0x0035, - ["JumpLeft"] = 0x0036, - ["JumpRight"] = 0x0037, - ["JumpUp2"] = 0x0038, - ["JumpDown2"] = 0x0039, - ["JumpLeft2"] = 0x003A, - ["JumpRight2"] = 0x003B, - ["DelayShort"] = 0x003F, - ["Delay"] = 0x0042, - ["WaitDisappear"] = 0x0045, - ["LockDirection"] = 0x0047, - ["ReleaseDirection"] = 0x0048, - ["Exclamation"] = 0x004B, - ["WaitWalkUpSlow"] = 0x004C, - ["WaitWalkDownSlow"] = 0x004D, - ["WaitWalkLeftSlow"] = 0x004E, - ["WaitWalkRightSlow"] = 0x004F, - ["WaitWalkUp"] = 0x0050, - ["WaitWalkDown"] = 0x0051, - ["WaitWalkLeft"] = 0x0052, - ["WaitWalkRight"] = 0x0053, - ["WaitMoveUp"] = 0x0054, - ["WaitMoveDown"] = 0x0055, - ["WaitMoveLeft"] = 0x0056, - ["WaitMoveRight"] = 0x0057, - ["WaitWalkBackUp"] = 0x0058, - ["WaitWalkBackDown"] = 0x0059, - ["WaitWalkBackLeft"] = 0x005A, - ["WaitWalkBackRight"] = 0x005B, - ["WaitJumpLeft1"] = 0x005C, - ["WaitJumpRight1"] = 0x005D, - ["WaitJumpLeft2"] = 0x005E, - ["WaitJumpRight2"] = 0x005F, - ["WaitMoveSite"] = 0x0064, - ["WaitJumpSite"] = 0x0065, - ["WaitDoubleExclamation"] = 0x0067, - ["WaitMoveForever"] = 0x0068, - ["End"] = 0x00FE - }; + ResourceManager commandDatabase; // Load the resource file containing information on parameters for each command switch (gameVersion) { case "D": @@ -914,12 +553,12 @@ namespace DSPRE { } if (isMovement) { - if (movementsDictDPPtHGSS.ContainsKey(words[0])) - this.id = movementsDictDPPtHGSS[words[0]]; + if (PokeDatabase.System.Scripts.movementsDictDPPtHGSS.ContainsKey(words[0])) + this.id = PokeDatabase.System.Scripts.movementsDictDPPtHGSS[words[0]]; else UInt16.TryParse(words[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out this.id); } else { - Console.WriteLine("Command name : " + words[0]); + Console.WriteLine("Command name: " + words[0]); Object cmd = GetResxNameByValue(words[0], commandDatabase); if (cmd != null) { @@ -946,17 +585,6 @@ namespace DSPRE { parameters.Add(BitConverter.GetBytes(Int16.Parse(words[1].Substring(2), NumberStyles.HexNumber))); } } else { - Dictionary operatorsDict = new Dictionary() { - ["LOWER"] = 0x0, - ["EQUAL"] = 0x1, - ["GREATER"] = 0x2, - ["LOWER/EQUAL"] = 0x3, - ["GREATER/EQUAL"] = 0x4, - ["DIFFERENT"] = 0x5, - ["OR"] = 0x6, - ["AND"] = 0x7, - ["TRUEUP"] = 0xFF - }; ResourceManager paramDatabase; // Load the resource file containing information on parameters for each command switch (gameVersion) { case "D": @@ -973,8 +601,8 @@ namespace DSPRE { for (int i = 1; i < indices.Length; i++) { Console.WriteLine("Index : " + i.ToString()); Console.WriteLine("Started word : " + words[i]); - if (operatorsDict.ContainsKey(words[i])) { - parameters.Add(new byte[] { operatorsDict[words[i]] }); + if (PokeDatabase.System.Scripts.stringToComparisonOperatorDict.ContainsKey(words[i])) { + parameters.Add(new byte[] { PokeDatabase.System.Scripts.stringToComparisonOperatorDict[words[i]] }); } else { int index = 1 + words[i].IndexOfAny(new char[] { 'x', '#' });