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
This commit is contained in:
Kurt
2017-05-23 21:38:15 -07:00
parent 5f94a2e0f4
commit be80a6b9da
3 changed files with 21 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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;