2016-10-16 04:28:14 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-10-16 04:28:14 +00:00
|
|
|
|
{
|
2016-11-10 16:14:54 +00:00
|
|
|
|
public class BV6 : BattleVideo
|
2016-10-16 04:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
internal const int SIZE = 0x2E60;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
internal new static bool IsValid(byte[] data)
|
2016-10-16 04:28:14 +00:00
|
|
|
|
{
|
2016-11-10 16:14:54 +00:00
|
|
|
|
if (data.Length != SIZE)
|
|
|
|
|
return false;
|
2016-10-16 04:28:14 +00:00
|
|
|
|
return BitConverter.ToUInt64(data, 0xE18) != 0 && BitConverter.ToUInt16(data, 0xE12) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BV6(byte[] data)
|
|
|
|
|
{
|
|
|
|
|
Data = (byte[])data.Clone();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly byte[] Data;
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private int Mode { get => Data[0x00]; set => Data[0x00] = (byte)value; }
|
2018-05-12 19:28:48 +00:00
|
|
|
|
private static readonly string[] BVmode =
|
2016-10-16 04:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
"Link", "Maison", "Super Maison", "Battle Spot - Free", "Battle Spot - Rating",
|
|
|
|
|
"Battle Spot - Special", "UNUSED", "JP-1", "JP-2", "BROKEN",
|
|
|
|
|
};
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private int Style { get => Data[0x01]; set => Data[0x01] = (byte)value; }
|
2018-05-12 19:28:48 +00:00
|
|
|
|
private static readonly string[] BVstyle = { "Single", "Double", "Triple", "Rotation", "Multi", };
|
2016-10-16 04:28:14 +00:00
|
|
|
|
private string Debug1
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x6, 24));
|
|
|
|
|
set => Encoding.Unicode.GetBytes(value.PadRight(12, '\0')).CopyTo(Data, 0x6);
|
2016-10-16 04:28:14 +00:00
|
|
|
|
}
|
|
|
|
|
private string Debug2
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0x50, 24));
|
|
|
|
|
set => Encoding.Unicode.GetBytes(value.PadRight(12, '\0')).CopyTo(Data, 0x50);
|
2016-10-16 04:28:14 +00:00
|
|
|
|
}
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private ulong RNGConst1 { get => BitConverter.ToUInt64(Data, 0x1A0); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1A0); }
|
|
|
|
|
private ulong RNGConst2 { get => BitConverter.ToUInt64(Data, 0x1A4); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1A4); }
|
|
|
|
|
private ulong RNGSeed1 { get => BitConverter.ToUInt64(Data, 0x1A8); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1A8); }
|
|
|
|
|
private ulong RNGSeed2 { get => BitConverter.ToUInt64(Data, 0x1B0); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1B0); }
|
2016-10-16 04:28:14 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private int Background { get => BitConverter.ToInt32(Data, 0x1BC); set => BitConverter.GetBytes(value).CopyTo(Data, 0x1BC); }
|
|
|
|
|
private int _1CE { get => BitConverter.ToUInt16(Data, 0x1CE); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1CE); }
|
|
|
|
|
private int IntroID { get => BitConverter.ToUInt16(Data, 0x1E4); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1E4); }
|
|
|
|
|
private int MusicID { get => BitConverter.ToUInt16(Data, 0x1F0); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x1F0); }
|
2016-10-16 04:28:14 +00:00
|
|
|
|
|
2016-11-10 16:14:54 +00:00
|
|
|
|
public override PKM[] BattlePKMs => PlayerTeams.SelectMany(t => t).ToArray();
|
|
|
|
|
public override int Generation => 6;
|
2016-10-16 04:28:14 +00:00
|
|
|
|
|
|
|
|
|
private const string NPC = "NPC";
|
|
|
|
|
private string[] PlayerNames
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
string[] trainers = new string[4];
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
trainers[i] = Util.TrimFromZero(Encoding.Unicode.GetString(Data, 0xEC + 0x1A*i, 0x1A));
|
|
|
|
|
if (string.IsNullOrWhiteSpace(trainers[i]))
|
|
|
|
|
trainers[i] = NPC;
|
|
|
|
|
}
|
|
|
|
|
return trainers;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value?.Length != 4)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
|
{
|
|
|
|
|
string tr = value[i] == NPC ? "" : value[i];
|
|
|
|
|
Encoding.Unicode.GetBytes(tr.PadRight(0x1A/2)).CopyTo(Data, 0xEC + 0x1A*i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private PKM[][] PlayerTeams
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var Teams = new PKM[4][];
|
|
|
|
|
const int start = 0xE18;
|
|
|
|
|
for (int t = 0; t < 4; t++)
|
|
|
|
|
{
|
|
|
|
|
Teams[t] = new PKM[6];
|
|
|
|
|
for (int p = 0; p < 6; p++)
|
|
|
|
|
{
|
|
|
|
|
int offset = start + PKX.SIZE_6PARTY*(t*6 + p);
|
|
|
|
|
offset += 8*((t*6 + p)/6); // 8 bytes padding between teams
|
|
|
|
|
Teams[t][p] = new PK6(Data.Skip(offset).Take(PKX.SIZE_6PARTY).ToArray(), $"Team {t}, Slot {p}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Teams;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
var Teams = value;
|
|
|
|
|
const int start = 0xE18;
|
|
|
|
|
for (int t = 0; t < 4; t++)
|
|
|
|
|
{
|
|
|
|
|
for (int p = 0; p < 6; p++)
|
|
|
|
|
{
|
|
|
|
|
int offset = start + PKX.SIZE_6PARTY*(t*6 + p);
|
|
|
|
|
offset += 8*((t*6 + p)/6); // 8 bytes padding between teams
|
|
|
|
|
Teams[t][p].EncryptedPartyData.CopyTo(Data, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private int MatchYear { get => BitConverter.ToUInt16(Data, 0x2E50); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E50); }
|
|
|
|
|
private int MatchDay { get => Data[0x2E52]; set => Data[0x2E52] = (byte)value; }
|
|
|
|
|
private int MatchMonth { get => Data[0x2E53]; set => Data[0x2E53] = (byte)value; }
|
|
|
|
|
private int MatchHour { get => Data[0x2E54]; set => Data[0x2E54] = (byte)value; }
|
|
|
|
|
private int MatchMinute { get => Data[0x2E55]; set => Data[0x2E55] = (byte)value; }
|
|
|
|
|
private int MatchSecond { get => Data[0x2E56]; set => Data[0x2E56] = (byte)value; }
|
|
|
|
|
private int MatchFlags { get => Data[0x2E57]; set => Data[0x2E57] = (byte)value; }
|
2016-10-16 04:28:14 +00:00
|
|
|
|
public DateTime MatchStamp
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new DateTime(MatchYear, MatchMonth, MatchDay, MatchHour, MatchMinute, MatchSecond);
|
2016-10-16 04:28:14 +00:00
|
|
|
|
set { MatchYear = value.Year; MatchDay = value.Day; MatchMonth = value.Month; MatchHour = value.Hour; MatchMinute = value.Minute; MatchSecond = value.Second; }
|
|
|
|
|
}
|
2017-05-13 03:32:36 +00:00
|
|
|
|
private int UploadYear { get => BitConverter.ToUInt16(Data, 0x2E58); set => BitConverter.GetBytes((ushort)value).CopyTo(Data, 0x2E58); }
|
|
|
|
|
private int UploadDay { get => Data[0x2E5A]; set => Data[0x2E5A] = (byte)value; }
|
|
|
|
|
private int UploadMonth { get => Data[0x2E5B]; set => Data[0x2E5B] = (byte)value; }
|
|
|
|
|
private int UploadHour { get => Data[0x2E5C]; set => Data[0x2E5C] = (byte)value; }
|
|
|
|
|
private int UploadMinute { get => Data[0x2E5D]; set => Data[0x2E5D] = (byte)value; }
|
|
|
|
|
private int UploadSecond { get => Data[0x2E5E]; set => Data[0x2E5E] = (byte)value; }
|
|
|
|
|
private int UploadFlags { get => Data[0x2E5F]; set => Data[0x2E5F] = (byte)value; }
|
2016-10-16 04:28:14 +00:00
|
|
|
|
public DateTime UploadStamp
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new DateTime(UploadYear, UploadMonth, UploadDay, UploadHour, UploadMinute, UploadSecond);
|
2016-10-16 04:28:14 +00:00
|
|
|
|
set { UploadYear = value.Year; UploadDay = value.Day; UploadMonth = value.Month; UploadHour = value.Hour; UploadMinute = value.Minute; UploadSecond = value.Second; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Battle Instruction Parsing
|
2018-05-12 19:28:48 +00:00
|
|
|
|
private static readonly string[] Action = { "0", "Fight", "2", "Switch", "Run", "5", "Rotate", "7", "MegaEvolve" };
|
|
|
|
|
private static readonly string[] Target =
|
2016-10-16 04:28:14 +00:00
|
|
|
|
{
|
|
|
|
|
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "Opposite Enemy", "B", "C", "D",
|
|
|
|
|
"All except User", "Everyone"
|
|
|
|
|
};
|
2018-05-12 19:28:48 +00:00
|
|
|
|
private static readonly string[] Rotate = { "0", "Right", "Left", "3" };
|
2016-10-16 04:28:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|