From d4c70b760c7911ceff8f46f7cd26f5a97bfc4e4b Mon Sep 17 00:00:00 2001 From: Kurt Date: Sat, 11 Mar 2017 10:52:18 -0800 Subject: [PATCH] Enhance record setting Use actual max record type 65535 is unused (no type=4), there's one 6 hidden in there :+1: I noticed there's some copying to Festa stats going on (see Savedata::AddRecord) 6 "Pokemon Caught" 8 "Eggs Hatched" 33 "Trades at the GTS" 100 "Champion Title Defense" 173 "Bubbling Spot Encounters/Items" 175 176 177 182 183 Looks like the setter increments data over at the Festa block if the active Mission is the recordID. --- PKHeX/Saves/SAV7.cs | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/PKHeX/Saves/SAV7.cs b/PKHeX/Saves/SAV7.cs index 4a7b734a2..bf177804b 100644 --- a/PKHeX/Saves/SAV7.cs +++ b/PKHeX/Saves/SAV7.cs @@ -618,18 +618,13 @@ public int getRecord(int recordID) public void setRecord(int recordID, int value) { int ofs = getRecordOffset(recordID); + int max = getRecordMax(recordID); + if (value > max) + value = max; if (recordID < 100) BitConverter.GetBytes(value).CopyTo(Data, ofs); if (recordID < 200) - BitConverter.GetBytes((short)value).CopyTo(Data, ofs); - } - public int getRecordMax(int recordID) - { - if (recordID < 100) - return int.MaxValue; - if (recordID < 200) - return short.MaxValue; - return 0; + BitConverter.GetBytes((ushort)value).CopyTo(Data, ofs); } public int getRecordOffset(int recordID) { @@ -640,6 +635,33 @@ public int getRecordOffset(int recordID) return -1; } + public int getRecordMax(int recordID) => recordID < 200 ? RecordMax[RecordMaxType[recordID]] : 0; + private static readonly int[] RecordMax = {999999999, 9999999, 999999, 99999, 65535, 9999, 999}; + private static readonly int[] RecordMaxType = + { + 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 2, 2, 2, 0, 0, 0, 2, 2, 0, + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 6, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + }; + public ushort PokeFinderCameraVersion { get { return BitConverter.ToUInt16(Data, PokeFinderSave + 0x00); }