From 37ec68039ddc25a08aaff6c740e5d9e9a3ccc5cb Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 15 Sep 2016 20:25:46 -0700 Subject: [PATCH] Show Gen2 item sprites Add gen2->4 item translation table, Recreate the gen3->4 item translation table, Fix string accessors for items for past gen games, would throw exceptions for invalid (65535) gen3 items. Use an unused invalid-item index instead. --- PKHeX/MainWindow/MainPK2.cs | 4 +- PKHeX/PKM/PK2.cs | 3 +- PKHeX/PKM/PKX.cs | 114 +++++++++++++++++++++++------------- 3 files changed, 78 insertions(+), 43 deletions(-) diff --git a/PKHeX/MainWindow/MainPK2.cs b/PKHeX/MainWindow/MainPK2.cs index ce3b719bd..903abcd06 100644 --- a/PKHeX/MainWindow/MainPK2.cs +++ b/PKHeX/MainWindow/MainPK2.cs @@ -19,7 +19,7 @@ namespace PKHeX CB_Species.SelectedValue = pk2.Species; TB_Level.Text = pk2.Stat_Level.ToString(); TB_EXP.Text = pk2.EXP.ToString(); - CB_HeldItem.SelectedValue = pk2.HeldItem; + CB_HeldItem.SelectedValue = pk2.G2Item; CB_Form.SelectedIndex = pk2.AltForm; CHK_IsEgg.Checked = pk2.IsEgg; TB_Friendship.Text = pk2.CurrentFriendship.ToString(); @@ -83,7 +83,7 @@ namespace PKHeX pk2.Species = Util.getIndex(CB_Species); pk2.TID = Util.ToInt32(TB_TID.Text); pk2.EXP = Util.ToUInt32(TB_EXP.Text); - pk2.HeldItem = Util.getIndex(CB_HeldItem); + pk2.G2Item = Util.getIndex(CB_HeldItem); pk2.IsEgg = CHK_IsEgg.Checked; pk2.CurrentFriendship = Util.ToInt32(TB_Friendship.Text); pk2.Met_Level = Util.ToInt32(TB_MetLevel.Text); diff --git a/PKHeX/PKM/PK2.cs b/PKHeX/PKM/PK2.cs index af1e0e366..bc3ab8d22 100644 --- a/PKHeX/PKM/PK2.cs +++ b/PKHeX/PKM/PK2.cs @@ -133,7 +133,8 @@ namespace PKHeX Data[0] = (byte)value; } } - public override int HeldItem { get { return Data[0x1]; } set { Data[0x1] = (byte)value; } } + public override int HeldItem { get { return PKX.getG4Item((byte) G2Item); } set { } } + public int G2Item { get { return Data[0x1]; } set { Data[0x1] = (byte)value; } } public override int Move1 { get { return Data[2]; } set { Data[2] = (byte) value; } } public override int Move2 { get { return Data[3]; } set { Data[3] = (byte)value; } } public override int Move3 { get { return Data[4]; } set { Data[4] = (byte)value; } } diff --git a/PKHeX/PKM/PKX.cs b/PKHeX/PKM/PKX.cs index 27efe9661..0b2429315 100644 --- a/PKHeX/PKM/PKX.cs +++ b/PKHeX/PKM/PKX.cs @@ -534,10 +534,8 @@ namespace PKHeX if (item > 0) { Image itemimg = (Image)Resources.ResourceManager.GetObject("item_" + item) ?? Resources.helditem; - if ((generation == 3 || generation == 4) && 328 <= item && item <= 419) // gen3/4 TM + if (generation >= 2 && generation <= 4 && 328 <= item && item <= 419) // gen2/3/4 TM itemimg = Resources.item_tm; - if (generation == 2) - itemimg = Resources.helditem; // Don't even try // Redraw baseImage = Util.LayerImage(baseImage, itemimg, 22 + (15 - itemimg.Width) / 2, 15 + (15 - itemimg.Height), 1); @@ -1605,49 +1603,85 @@ namespace PKHeX return ekm; } + private const ushort ITEM_UNK = 128; // unused item, placeholder for sprite finding + public static ushort getG4Item(byte g2val) + { + ushort[] arr = + { + 00000, 00001, 00002, 00213, 00003, 00004, 65535, 00450, 00081, 00018, + 00019, 00020, 00021, 00022, 00023, 00024, 00025, 00026, 00017, 00078, + 00079, 00041, 00082, 00083, 00084, 65535, 00045, 00046, 00047, 00048, + 00256, 00049, 00050, 00060, 00085, 00257, 00092, 00063, 00027, 00028, + 00029, 00055, 00076, 00077, 00056, 65535, 00030, 00031, 00032, 00057, + 65535, 00058, 00059, 00061, 00444, 65535, 65535, 00216, 00445, 00446, + 65535, 00447, 00051, 00038, 00039, 00040, 00478, 00464, 00456, 00484, + 65535, 00482, 00033, 00217, 65535, 65535, 00237, 00244, 65535, 65535, + 65535, 00245, 00221, 65535, 65535, 00485, 00086, 00087, 00222, 00487, + 65535, 00223, 00486, 00488, 00224, 00243, 00248, 00490, 00241, 00491, + 65535, 00489, 00240, 00473, 65535, 00259, 00228, 00246, 00242, 65535, + 00088, 00089, 00229, 00247, 00504, 65535, 65535, 00239, 00258, 00230, + 65535, 00034, 00035, 00036, 00037, 00238, 00231, 00475, 00481, 65535, + 65535, 00090, 00091, 00476, 00480, 65535, 65535, 65535, 00249, 00043, + 00232, 65535, 65535, 00233, 00250, 65535, 00234, 65535, 65535, 65535, + 65535, 00235, 65535, 65535, 65535, 65535, 00044, 00495, 65535, 00493, + 65535, 00492, 65535, 00236, 00497, 00498, 00496, 65535, 65535, 00080, + 65535, 65535, 00252, 65535, 65535, 00477, 65535, 00500, 00483, 65535, + 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, 65535, + 65535, 00328, 00329, 00330, 00331, 00331, 00332, 00333, 00334, 00335, + 00336, 00337, 00338, 00339, 00340, 00341, 00342, 00343, 00344, 00345, + 00346, 00347, 00348, 00349, 00350, 00351, 00352, 00353, 00354, 00355, + 00355, 00356, 00357, 00358, 00359, 00360, 00361, 00362, 00363, 00364, + 00365, 00366, 00367, 00368, 00369, 00370, 00371, 00372, 00373, 00374, + 00375, 00376, 00377, 00420, 00421, 00422, 00423, 00424, 00425, 00426, + 00427, 65535, 65535, 65535, 65535, 65535, + }; + + ushort val = g2val > arr.Length ? ushort.MaxValue : arr[g2val]; + return val == ushort.MaxValue ? ITEM_UNK : val; + } public static ushort getG4Item(ushort g3val) { ushort[] arr = { - 0,1,2,3,4,5,6,7,8,9, - 10,11,12,17,18,19,20,21,22,23, - 24,25,26,27,28,29,30,31,32,33, - 34,35,36,37,38,39,40,41,42,65, - 66,67,68,69,43,44,70,71,72,73, - 74,75,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,45,46,47,48,49,50,51, - 52,53,0xFFFF,55,56,57,58,59,60,61, - 63,64,0xFFFF,76,77,78,79,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,80,81,82,83,84,85,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,86,87,0xFFFF,88,89,90,91, - 92,93,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,149,150,151,152,153,154,155, - 156,157,158,159,160,161,162,163,164,165, - 166,167,168,169,170,171,172,173,174,175, - 176,177,178,179,180,181,182,183,201,202, - 203,204,205,206,207,208,0xFFFF,0xFFFF,0xFFFF,213, - 214,215,216,217,218,219,220,221,222,223, - 224,225,226,227,228,229,230,231,232,233, - 234,235,236,237,238,239,240,241,242,243, - 244,245,246,247,248,249,250,251,252,253, - 254,255,256,257,258,259,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,260,261,262,263,264, + 00000,00001,00002,00003,00004,00005,00006,00007,00008,00009, + 00010,00011,00012,00017,00018,00019,00020,00021,00022,00023, + 00024,00025,00026,00027,00028,00029,00030,00031,00032,00033, + 00034,00035,00036,00037,00038,00039,00040,00041,00042,00065, + 00066,00067,00068,00069,00043,00044,00070,00071,00072,00073, + 00074,00075,65535,65535,65535,65535,65535,65535,65535,65535, + 65535,65535,65535,00045,00046,00047,00048,00049,00050,00051, + 00052,00053,65535,00055,00056,00057,00058,00059,00060,00061, + 00063,00064,65535,00076,00077,00078,00079,65535,65535,65535, + 65535,65535,65535,00080,00081,00082,00083,00084,00085,65535, + 65535,65535,65535,00086,00087,65535,00088,00089,00090,00091, + 00092,00093,65535,65535,65535,65535,65535,65535,65535,65535, + 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, + 65535,65535,65535,00149,00150,00151,00152,00153,00154,00155, + 00156,00157,00158,00159,00160,00161,00162,00163,00164,00165, + 00166,00167,00168,00169,00170,00171,00172,00173,00174,00175, + 00176,00177,00178,00179,00180,00181,00182,00183,00201,00202, + 00203,00204,00205,00206,00207,00208,65535,65535,65535,00213, + 00214,00215,00216,00217,00218,00219,00220,00221,00222,00223, + 00224,00225,00226,00227,00228,00229,00230,00231,00232,00233, + 00234,00235,00236,00237,00238,00239,00240,00241,00242,00243, + 00244,00245,00246,00247,00248,00249,00250,00251,00252,00253, + 00254,00255,00256,00257,00258,00259,65535,65535,65535,65535, + 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, + 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, + 65535,65535,65535,65535,00260,00261,00262,00263,00264, - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF, - 328,329,330,331,332,333,334,335,336,337, - 338,339,340,341,342,343,344,345,346,347, - 348,349,350,351,352,353,354,355,356,357, - 358,359,360,361,362,363,364,365,366,367, - 368,369,370,371,372,373,374,375,376,377, + 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, + 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, + 65535,65535,65535,65535,65535,65535,65535,65535,65535,65535, + 00328,00329,00330,00331,00332,00333,00334,00335,00336,00337, + 00338,00339,00340,00341,00342,00343,00344,00345,00346,00347, + 00348,00349,00350,00351,00352,00353,00354,00355,00356,00357, + 00358,00359,00360,00361,00362,00363,00364,00365,00366,00367, + 00368,00369,00370,00371,00372,00373,00374,00375,00376,00377, }; - if (g3val > arr.Length) - return 0xFFFF; - return arr[g3val]; + + ushort val = g3val > arr.Length ? ushort.MaxValue : arr[g3val]; + return val == ushort.MaxValue ? ITEM_UNK : val; } #region Gen 1 Character Tables