From ef0349b3bd10cff8a90e4ebf8ed227610e67b1e4 Mon Sep 17 00:00:00 2001 From: AdAstra-LD Date: Thu, 11 Feb 2021 00:00:24 +0100 Subject: [PATCH] Fixed DP weathers [almost fixed Pt too] --- DS_Map/Main Window.cs | 49 +++++++------ DS_Map/ROMFiles/MapHeader.cs | 30 +------- DS_Map/Resources/PokeDatabase.cs | 115 +++++++++++++++++-------------- 3 files changed, 89 insertions(+), 105 deletions(-) diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 7c78c6e..949d79d 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -1325,9 +1325,9 @@ namespace DSPRE { return; disableHandlers = true; + ushort updValue = (ushort)((NumericUpDown)sender).Value; + currentHeader.musicDayID = updValue; try { - ushort updValue = (ushort)((NumericUpDown)sender).Value; - currentHeader.musicDayID = updValue; switch (RomInfo.gameVersion) { case "D": case "P": @@ -1350,9 +1350,9 @@ namespace DSPRE { return; disableHandlers = true; + ushort updValue = (ushort)((NumericUpDown)sender).Value; + currentHeader.musicNightID = updValue; try { - ushort updValue = (ushort)((NumericUpDown)sender).Value; - currentHeader.musicNightID = updValue; switch (RomInfo.gameVersion) { case "D": case "P": @@ -1407,28 +1407,30 @@ namespace DSPRE { /* Update Weather Picture */ try { - string imageName = null; + Dictionary dict; switch (RomInfo.gameVersion) { case "D": case "P": - imageName = PokeDatabase.System.WeatherPics.dpWeatherImageDict[weatherComboBox.SelectedIndex]; + dict = PokeDatabase.System.WeatherPics.dpWeatherImageDict; break; case "Plat": - imageName = PokeDatabase.System.WeatherPics.ptWeatherImageDict[weatherComboBox.SelectedIndex]; + dict = PokeDatabase.System.WeatherPics.ptWeatherImageDict; break; default: - foreach (KeyValuePair, string> entry in PokeDatabase.System.WeatherPics.hgssweatherImageDict) { - if (entry.Key.Contains(weatherComboBox.SelectedIndex)) { - imageName = entry.Value; - break; - } - } - if (imageName == null) - throw new KeyNotFoundException(); + dict = PokeDatabase.System.WeatherPics.hgssweatherImageDict; break; } - weatherPictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject(imageName); + bool found = false; + foreach (KeyValuePair dictEntry in dict) { + if (Array.IndexOf(dictEntry.Key, (byte)weatherUpDown.Value) >= 0) { + weatherPictureBox.Image = (Image)Properties.Resources.ResourceManager.GetObject(dictEntry.Value); + found = true; + break; + } + } + if (!found) + throw new KeyNotFoundException(); } catch (KeyNotFoundException) { weatherPictureBox.Image = null; } @@ -1484,7 +1486,6 @@ namespace DSPRE { centerEventviewOnEntities(); eventMatrixXUpDown_ValueChanged(null, null); } - private void openMatrixButton_Click(object sender, EventArgs e) { if (!matrixEditorIsReady) { SetupMatrixEditor(); @@ -1513,7 +1514,6 @@ namespace DSPRE { headerListBox.Focus(); disableHandlers = false; } - private void updateCurrentInternalName() { /* Update internal name according to internalNameBox text*/ using (BinaryWriter writer = new BinaryWriter(File.OpenWrite(romInfo.InternalNamesLocation))) { @@ -1531,7 +1531,6 @@ namespace DSPRE { disableHandlers = false; } - private void resetButton_Click(object sender, EventArgs e) { searchLocationTextBox.Clear(); HeaderSearch.HeaderSearchReset(headerListBox, internalNames); @@ -3892,15 +3891,13 @@ namespace DSPRE { return (Bitmap)Properties.Resources.ResourceManager.GetObject(imageName); } - uint btxID; - try { - btxID = RomInfo.OverworldTable[entryIDOfEventFile].spriteID; - }catch (KeyNotFoundException) { + (uint spriteID, ushort properties) result; + if (!RomInfo.OverworldTable.TryGetValue(entryIDOfEventFile, out result)) { // try loading image from dictionary return (Bitmap)Properties.Resources.ResourceManager.GetObject("overworld"); //if there's no match, load bounding box } try { - FileStream stream = new FileStream(RomInfo.OWSpriteDirPath + "\\" + btxID.ToString("D4"), FileMode.Open); + FileStream stream = new FileStream(RomInfo.OWSpriteDirPath + "\\" + result.spriteID.ToString("D4"), FileMode.Open); NSMBe4.NSBMD.NSBTX_File nsbtx = new NSMBe4.NSBMD.NSBTX_File(stream); if (nsbtx.TexInfo.num_objs <= 1) { @@ -4592,7 +4589,9 @@ namespace DSPRE { owSightRangeUpDown.Value = currentEvFile.overworlds[index].sightRange; owXRangeUpDown.Value = currentEvFile.overworlds[index].xRange; owYRangeUpDown.Value = currentEvFile.overworlds[index].yRange; - spriteIDlabel.Text = "Sprite ID: " + RomInfo.OverworldTable[currentEvFile.overworlds[overworldsListBox.SelectedIndex].overlayTableEntry].spriteID.ToString("D3"); + try { + spriteIDlabel.Text = "Sprite ID: " + RomInfo.OverworldTable[currentEvFile.overworlds[overworldsListBox.SelectedIndex].overlayTableEntry].spriteID.ToString("D3"); + } catch { } DisplayActiveEvents(); } catch (ArgumentOutOfRangeException) { String errorMsg = "There was a problem loading the overworld events of this Event file."; diff --git a/DS_Map/ROMFiles/MapHeader.cs b/DS_Map/ROMFiles/MapHeader.cs index 6ffcfda..850307e 100644 --- a/DS_Map/ROMFiles/MapHeader.cs +++ b/DS_Map/ROMFiles/MapHeader.cs @@ -159,7 +159,7 @@ namespace DSPRE.ROMFiles { wildPokémon = reader.ReadUInt16(); eventFileID = reader.ReadUInt16(); locationName = reader.ReadUInt16(); - weatherID = StandardizeWeather(reader.ReadByte()); + weatherID = reader.ReadByte(); cameraAngleID = reader.ReadByte(); showName = reader.ReadByte(); @@ -196,34 +196,6 @@ namespace DSPRE.ROMFiles { } return newData.ToArray(); } - public byte StandardizeWeather(byte weather) - { - /* This function was written to avoid having to account - for duplicate weather values , since many share the same - weather conditions */ - - switch (weather) - { - case 8: - case 13: - case 18: - case 19: - case 20: - case 23: - case 25: - return 0; // Normal weather - case 21: - case 26: - case 27: - return 6; // D snow - case 28: - return 5; // Snowfall - case 24: - return 4; // Thunderstorm - default: - return weather; - } - } #endregion } diff --git a/DS_Map/Resources/PokeDatabase.cs b/DS_Map/Resources/PokeDatabase.cs index 2560c3e..533e5c4 100644 --- a/DS_Map/Resources/PokeDatabase.cs +++ b/DS_Map/Resources/PokeDatabase.cs @@ -73,7 +73,7 @@ namespace DSPRE.Resources { }; } public static class Weather { - public static Dictionary DPWeatherDict = new Dictionary { + public static Dictionary DPWeatherDict = new Dictionary { [00] = "Normal", [01] = "Normal, somewhat dark", [02] = "Rain", @@ -82,15 +82,27 @@ namespace DSPRE.Resources { [05] = "Snowfall, slow", [06] = "Diamond dust", [07] = "Blizzard", + [08] = "Normal [08]", [09] = "Volcanic ash fall, slow", [10] = "Sand storm", [11] = "Hail", [12] = "Rocks ascending (?)", + [13] = "Normal [13]", [14] = "Fog", [15] = "Deep fog", [16] = "Dark, Flash usable", [17] = "Lightning, no rain", - [22] = "Volcanic ash fall, steady", + [18] = "Normal [18]", + [19] = "Normal [19]", + [20] = "Normal [20]", + [21] = "Diamond dust [21]", + [22] = "Volcanic ash storm", + [23] = "Normal [23]", + [24] = "Thunderstorm [24]", + [25] = "Normal [25]", + [26] = "Diamond dust [26]", + [27] = "Diamond dust [27]", + [28] = "Snowfall, slow [28]", }; public static Dictionary PtWeatherDict = new Dictionary { [00] = "Normal", @@ -146,6 +158,7 @@ namespace DSPRE.Resources { [23] = "Darkness [23]", [24] = "Darkness after flash", [25] = "Darkness after flash [25]", + [26] = "Low Light (Battle Arcade)" }; } @@ -3630,57 +3643,57 @@ namespace DSPRE.Resources { }; } public static class WeatherPics { - public static Dictionary dpWeatherImageDict = new Dictionary() { - [0] = "dpnormal", - [1] = "dpcloudy", - [2] = "dprain", - [3] = "dpheavyrain", - [4] = "dpthunderstorm", - [5] = "dpsnowslow", - [6] = "dpdiamondsnow", - [7] = "dpblizzard", - [8] = "dpsandfall", - [9] = "dpsandstorm", - [10] = "dphail", - [11] = "dprocksascending", - [12] = "dpfog", - [13] = "dpfog", - [14] = "dpdark", - [15] = "dplightning", - [16] = "dplightsandstorm" + public static Dictionary dpWeatherImageDict = new Dictionary() { + [new byte[] { 0, 8, 13, 18, 19, 20, 23, 25 }] = "dpnormal", + [new byte[] { 1 }] = "dpcloudy", + [new byte[] { 2 }] = "dprain", + [new byte[] { 3 }] = "dpheavyrain", + [new byte[] { 4, 24}] = "dpthunderstorm", + [new byte[] { 5, 28 }] = "dpsnowslow", + [new byte[] { 6, 21, 26, 27 }] = "dpdiamondsnow", + [new byte[] { 7 }] = "dpblizzard", + [new byte[] { 9 }] = "dpsandfall", + [new byte[] { 10 }] = "dpsandstorm", + [new byte[] { 11 }] = "dphail", + [new byte[] { 12 }] = "dprocksascending", + [new byte[] { 14 }] = "dpfog", + [new byte[] { 15 }] = "dpfog", //deep fog + [new byte[] { 16 }] = "dpdark", + [new byte[] { 17 }] = "dplightning", + [new byte[] { 22 }] = "dplightsandstorm" }; - public static Dictionary ptWeatherImageDict = new Dictionary() { - [0] = "ptnormal", - [1] = "ptcloudy", - [2] = "ptrain", - [3] = "ptheavyrain", - [4] = "ptthunderstorm", - [5] = "ptsnowslow", - [6] = "ptDsnow", - [7] = "ptblizzard", - [8] = "ptsandfall", - [9] = "ptsandstorm", - [10] = "pthail", - [11] = "ptrocksascending", - [12] = "ptfog", - [13] = "ptfog", - [14] = "ptdark", - [15] = "ptlightning", - [16] = "ptlightsandstorm", - [17] = "ptforestweather", - [18] = "ptspotlight", - [19] = "ptspotlight" + public static Dictionary ptWeatherImageDict = new Dictionary() { + [new byte[] { 0 } ] = "ptnormal", + [new byte[] { 1 } ] = "ptcloudy", + [new byte[] { 2 } ] = "ptrain", + [new byte[] { 3 } ] = "ptheavyrain", + [new byte[] { 4 } ] = "ptthunderstorm", + [new byte[] { 5 } ] = "ptsnowslow", + [new byte[] { 6 } ] = "ptDsnow", + [new byte[] { 7 } ] = "ptblizzard", + [new byte[] { 8 } ] = "ptsandfall", + [new byte[] { 9 } ] = "ptsandstorm", + [new byte[] { 10 } ] = "pthail", + [new byte[] { 11 } ] = "ptrocksascending", + [new byte[] { 12 } ] = "ptfog", + [new byte[] { 13 } ] = "ptfog", + [new byte[] { 14 } ] = "ptdark", + [new byte[] { 15 } ] = "ptlightning", + [new byte[] { 16 } ] = "ptlightsandstorm", + [new byte[] { 17 } ] = "ptforestweather", + [new byte[] { 18 } ] = "ptspotlight", + [new byte[] { 19 } ] = "ptspotlight" }; - public static Dictionary, string> hgssweatherImageDict = new Dictionary, string>() { - [new List { 0, 1 }] = "hgssnormal", - [new List { 2, 3, 4, 5, 6, 7, 8 }] = "hgssrain", - [new List { 9, 10, 11, 12, 13, 15 }] = "hgsssnow", - [new List { 14 }] = "hgssnormal", //sandstorm in battle only - [new List { 16, 17 }] = "hgssdiamond", - [new List { 18, 19, 20, 21 }] = "hgssfog", - [new List { 22, 23 }] = "hgssdark", - [new List { 24, 25 }] = "hgssdark2", - [new List { 26 }] = "hgssArcade" + public static Dictionary hgssweatherImageDict = new Dictionary() { + [new byte[] { 0, 1 }] = "hgssnormal", + [new byte[] { 2, 3, 4, 5, 6, 7, 8 }] = "hgssrain", + [new byte[] { 9, 10, 11, 12, 13, 15 }] = "hgsssnow", + [new byte[] { 14 }] = "hgssnormal", //sandstorm in battle only + [new byte[] { 16, 17 }] = "hgssdiamond", + [new byte[] { 18, 19, 20, 21 }] = "hgssfog", + [new byte[] { 22, 23 }] = "hgssdark", + [new byte[] { 24, 25 }] = "hgssdark2", + [new byte[] { 26 }] = "hgssArcade" }; } }