Fix Misc7 wormhole shiny property r/w

Redirect reader to r/w the Misc block property rather than the buffer directly
This commit is contained in:
Kurt 2024-09-30 23:54:54 -05:00
parent ee00a21f90
commit b187633ec6
2 changed files with 21 additions and 9 deletions

View file

@ -27,6 +27,11 @@ public sealed class Misc7(SAV7 sav, Memory<byte> raw) : SaveBlock<SAV7>(sav, raw
} }
} }
// 0x00C: 0x100 bytes of bitflags
// 0x10C: u32
// 0x110: u32
// 0x114: 8 bytes of bitflags
public uint BP public uint BP
{ {
get => ReadUInt32LittleEndian(Data[0x11C..]); get => ReadUInt32LittleEndian(Data[0x11C..]);
@ -38,6 +43,10 @@ public sealed class Misc7(SAV7 sav, Memory<byte> raw) : SaveBlock<SAV7>(sav, raw
} }
} }
// 0x120: byte
// 0x121: byte
// 0x122: byte
public int DaysFromRefreshed public int DaysFromRefreshed
{ {
get => Data[0x123]; get => Data[0x123];
@ -50,23 +59,25 @@ public sealed class Misc7(SAV7 sav, Memory<byte> raw) : SaveBlock<SAV7>(sav, raw
set => Data[0x130] = (byte)((Data[0x130] & ~0x1F) | (value & 0x1F)); set => Data[0x130] = (byte)((Data[0x130] & ~0x1F) | (value & 0x1F));
} }
// 0x134: byte
public bool IsWormholeShiny public bool IsWormholeShiny
{ {
get => Data[0x136] == 1; get => Data[0x135] == 1;
set => Data[0x136] = (byte)(value ? 1 : 0); set => Data[0x135] = (byte)(value ? 1 : 0);
} }
// 0x136-0x137: alignment
public int GetSurfScore(int recordID) public int GetSurfScore(int recordID)
{ {
if ((uint)recordID >= 4) ArgumentOutOfRangeException.ThrowIfGreaterThan((uint)recordID, 3u);
recordID = 0;
return ReadInt32LittleEndian(Data[(0x138 + (4 * recordID))..]); return ReadInt32LittleEndian(Data[(0x138 + (4 * recordID))..]);
} }
public void SetSurfScore(int recordID, int score) public void SetSurfScore(int recordID, int score)
{ {
if ((uint)recordID >= 4) ArgumentOutOfRangeException.ThrowIfGreaterThan((uint)recordID, 3u);
recordID = 0;
WriteInt32LittleEndian(Data[(0x138 + (4 * recordID))..], score); WriteInt32LittleEndian(Data[(0x138 + (4 * recordID))..], score);
} }

View file

@ -10,10 +10,11 @@ public sealed class WormholeInfoReader(SAV7 SAV)
// https://projectpokemon.org/home/forums/topic/39433-gen-7-save-research-thread/?page=3&tab=comments#comment-239090 // https://projectpokemon.org/home/forums/topic/39433-gen-7-save-research-thread/?page=3&tab=comments#comment-239090
public bool WormholeShininess // 0x4535 = Misc (0x4400 in US/UM) + 0x0135 public bool WormholeShininess // 0x4535 = Misc (0x4400 in US/UM) + 0x0135
{ {
get => SAV.Misc.Data[0x0135] == 1; get => SAV.Misc.IsWormholeShiny;
set => SAV.Misc.Data[0x0135] = value ? (byte)1 : (byte)0; set => SAV.Misc.IsWormholeShiny = value;
} }
/// <summary> Inclusive maximum </summary>
public const int WormholeSlotMax = 15; public const int WormholeSlotMax = 15;
// Slots currently use digits 1 through 15 inclusively. // Slots currently use digits 1 through 15 inclusively.
@ -128,7 +129,7 @@ public sealed class WormholeInfoReader(SAV7 SAV)
public static ushort WormholeSlotToPokemon(int mapid, int slot) public static ushort WormholeSlotToPokemon(int mapid, int slot)
{ {
if (slot is < 1 or > WormholeSlotMax) if ((uint)slot > WormholeSlotMax)
return 0; return 0;
return mapid switch return mapid switch