Enhance record setting

Use actual max record type
65535 is unused (no type=4), there's one 6 hidden in there 👍

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.
This commit is contained in:
Kurt 2017-03-11 10:52:18 -08:00
parent ff2dc1356b
commit d4c70b760c

View File

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