2017-12-03 03:12:04 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
|
|
|
public class Mail2 : Mail
|
|
|
|
{
|
|
|
|
private readonly bool US;
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
public Mail2(SAV2 sav, int index)
|
|
|
|
{
|
|
|
|
US = !sav.Japanese && !sav.Korean;
|
2018-08-10 04:53:39 +00:00
|
|
|
DataOffset = index < 6 ? (index * 0x2F) + 0x600 : ((index - 6) * 0x2F) + 0x835;
|
2017-12-03 03:12:04 +00:00
|
|
|
Data = sav.GetData(DataOffset, 0x2F);
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2019-03-21 04:50:44 +00:00
|
|
|
public override string GetMessage(bool isLastLine) => US ? StringConverter12.GetString1(Data, isLastLine ? 0x11 : 0, 0x10, false) : string.Empty;
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
public override void SetMessage(string line1, string line2)
|
|
|
|
{
|
|
|
|
if (US)
|
|
|
|
{
|
2019-03-21 04:50:44 +00:00
|
|
|
StringConverter12.SetString1(line2, 0x10, false, 0x10, 0x50).CopyTo(Data, 0x11);
|
|
|
|
StringConverter12.SetString1(line1, 0x10, false, 0x10, (ushort)(Data.Skip(0x11).Take(0x10).All(v => v == 0x50) ? 0x50 : 0x7F)).CopyTo(Data, 0);
|
2017-12-03 03:12:04 +00:00
|
|
|
Data[0x10] = 0x4E;
|
|
|
|
}
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
public override string AuthorName
|
|
|
|
{
|
2019-03-21 04:50:44 +00:00
|
|
|
get => US ? StringConverter12.GetString1(Data, 0x21, 7, false) : string.Empty;
|
2017-12-03 03:12:04 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
if (US)
|
|
|
|
{
|
2019-03-21 04:50:44 +00:00
|
|
|
StringConverter12.SetString1(value, 7, false, 8, 0x50).CopyTo(Data, 0x21);
|
2017-12-03 03:12:04 +00:00
|
|
|
Data[0x29] = Data[0x2A] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
public override ushort AuthorTID
|
|
|
|
{
|
|
|
|
get => (ushort)(Data[0x2B] << 8 | Data[0x2C]);
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Data[0x2B] = (byte)(value >> 8);
|
|
|
|
Data[0x2C] = (byte)(value & 0xFF);
|
|
|
|
}
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
public override int AppearPKM { get => Data[0x2D]; set => Data[0x2D] = (byte)value; }
|
|
|
|
public override int MailType { get => Data[0x2E]; set => Data[0x2E] = (byte)value; }
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
public override bool? IsEmpty
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (MailType == 0) return true;
|
|
|
|
else if (MailType == 0x9E || (MailType >= 0xB5 && MailType <= 0xBD)) return false;
|
|
|
|
else return null;
|
|
|
|
}
|
|
|
|
}
|
2018-08-10 04:53:39 +00:00
|
|
|
|
2017-12-03 03:12:04 +00:00
|
|
|
public override void SetBlank() => (new byte[0x2F]).CopyTo(Data, 0);
|
|
|
|
}
|
|
|
|
}
|