PKHeX/PKHeX.Core/Saves/Substructures/Gen8/TrainerCard8.cs
Kurt 9b0b0cb1a6 Add misc value r/w for trainer8
Closes #2639
casting object to generic T : struct isn't valid, so just cast the get/set appropriately
2020-01-17 23:25:02 -08:00

49 lines
No EOL
1.4 KiB
C#

using System;
using System.Text;
namespace PKHeX.Core
{
public sealed class TrainerCard8 : SaveBlock
{
public TrainerCard8(SAV8SWSH sav, SCBlock block) : base (sav, block.Data) { }
public string OT
{
get => SAV.GetString(Data, 0x00, 0x1A);
set => SAV.SetData(Data, SAV.SetString(value, SAV.OTLength), 0x00);
}
public int TrainerID
{
get => BitConverter.ToInt32(Data, 0x1C);
set => SAV.SetData(Data, BitConverter.GetBytes(value), 0x1C);
}
public const int RotoRallyScoreMax = 99_999;
public int RotoRallyScore
{
get => BitConverter.ToInt32(Data, 0x28);
set
{
if (value > RotoRallyScoreMax)
value = RotoRallyScoreMax;
var data = BitConverter.GetBytes(value);
SAV.SetData(Data, data, 0x28);
// set to the other block since it doesn't have an accessor
((SAV8SWSH)SAV).SetValue(SaveBlockAccessorSWSH.KRotoRally, (uint)value);
}
}
public string Number
{
get => Encoding.ASCII.GetString(Data, 0x39, 3);
set
{
for (int i = 0; i < 3; i++)
Data[0x39 + i] = (byte) (value.Length > i ? value[i] : '\0');
SAV.Edited = true;
}
}
}
}