From be80a6b9da2b5d3c9a5339e006960afcca4e061d Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 23 May 2017 21:38:15 -0700 Subject: [PATCH] Fix HGSS wallpaper get/set & editing the special wallpaper values are +0x10 (ie 0x20, 0x21... instead of 0x10, 0x11) from the contiguous sequence of regular box wallpaper IDs (anti cheat probing?). Xor tweak allows for single invert method; use this invert with the base implementation's method. Range check for setting the box wallpaper (just in case). The underlying error was fixed; the 255 val was reading from the wrong offset (now fixed). Thanks Scarfy! https://projectpokemon.org/forums/files/file/1-pkhex/?do=findComment&comment=344 --- PKHeX.Core/Saves/SAV4.cs | 20 ++++++++++++++++++- PKHeX.Core/Saves/SaveFile.cs | 2 +- .../Save Editors/Gen6/SAV_BoxLayout.cs | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/PKHeX.Core/Saves/SAV4.cs b/PKHeX.Core/Saves/SAV4.cs index a95b342f7..17ba862b2 100644 --- a/PKHeX.Core/Saves/SAV4.cs +++ b/PKHeX.Core/Saves/SAV4.cs @@ -510,11 +510,29 @@ public override int CurrentBox get => Data[Version == GameVersion.HGSS ? getBoxOffset(BoxCount) : Box - 4]; set => Data[Version == GameVersion.HGSS ? getBoxOffset(BoxCount) : Box - 4] = (byte)value; } + private static int InvertHGSSBoxWallpaperAlias(int value) + { + // HG/SS Special Wallpapers 1-8 (Primo Phrases) are shifted by +0x10; swap 0x2_ and 0x1_ by xoring with 0x30 + if (value >= 0x10) + return value ^ 0x30; + return value; + } + public override int getBoxWallpaper(int box) + { + int value = base.getBoxWallpaper(box); + return Version == GameVersion.HGSS ? InvertHGSSBoxWallpaperAlias(value) : value; + } + public override void setBoxWallpaper(int box, int value) + { + if (Version == GameVersion.HGSS) + value = InvertHGSSBoxWallpaperAlias(value); + base.setBoxWallpaper(box, value); + } protected override int getBoxWallpaperOffset(int box) { // Box Wallpaper is directly after the Box Names int offset = getBoxOffset(BoxCount); - if (Version == GameVersion.HGSS) offset += 0x18; + if (Version == GameVersion.HGSS) offset += 0x8; offset += BoxCount*0x28 + box; return offset; } diff --git a/PKHeX.Core/Saves/SaveFile.cs b/PKHeX.Core/Saves/SaveFile.cs index 8ce5c6cd4..795181f79 100644 --- a/PKHeX.Core/Saves/SaveFile.cs +++ b/PKHeX.Core/Saves/SaveFile.cs @@ -446,7 +446,7 @@ public bool SwapBox(int box1, int box2) } protected virtual int getBoxWallpaperOffset(int box) { return -1; } - public int getBoxWallpaper(int box) + public virtual int getBoxWallpaper(int box) { int offset = getBoxWallpaperOffset(box); if (offset < 0 || box > BoxCount) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs index 16ddccba7..adcc92106 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen6/SAV_BoxLayout.cs @@ -95,7 +95,7 @@ private void changeBox(object sender, EventArgs e) return; editing = true; - CB_BG.SelectedIndex = SAV.getBoxWallpaper(LB_BoxSelect.SelectedIndex); + CB_BG.SelectedIndex = Math.Min(CB_BG.Items.Count - 1, SAV.getBoxWallpaper(LB_BoxSelect.SelectedIndex)); TB_BoxName.Text = SAV.getBoxName(LB_BoxSelect.SelectedIndex); editing = false;