2019-03-15 19:35:55 +00:00
|
|
|
|
using System;
|
2020-12-05 14:09:33 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-03-15 19:35:55 +00:00
|
|
|
|
using System.Linq;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2016-11-10 16:14:54 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-11-10 16:14:54 +00:00
|
|
|
|
{
|
2019-10-04 02:09:02 +00:00
|
|
|
|
public sealed class BV7 : BattleVideo
|
2016-11-10 16:14:54 +00:00
|
|
|
|
{
|
|
|
|
|
internal const int SIZE = 0x2BC0;
|
2020-12-05 14:09:33 +00:00
|
|
|
|
private const string NPC = "NPC";
|
|
|
|
|
private const int PlayerCount = 4;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public override int Generation => 7;
|
|
|
|
|
private readonly byte[] Data;
|
2016-11-10 16:14:54 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public override IReadOnlyList<PKM> BattlePKMs => PlayerTeams.SelectMany(t => t).ToArray();
|
2022-01-03 05:35:59 +00:00
|
|
|
|
internal new static bool IsValid(ReadOnlySpan<byte> data) => data.Length == SIZE;
|
2016-11-10 16:14:54 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public BV7(byte[] data) => Data = (byte[])data.Clone();
|
|
|
|
|
|
|
|
|
|
private static readonly int[] offsets = { 0xE41, 0x145E, 0x1A7B, 0x2098 };
|
2016-11-10 16:14:54 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public IReadOnlyList<PKM[]> PlayerTeams
|
2016-11-10 16:14:54 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-12-05 14:09:33 +00:00
|
|
|
|
var Teams = new PKM[PlayerCount][];
|
|
|
|
|
for (int t = 0; t < PlayerCount; t++)
|
|
|
|
|
Teams[t] = GetTeam(t);
|
2016-11-10 16:14:54 +00:00
|
|
|
|
return Teams;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2020-12-05 14:09:33 +00:00
|
|
|
|
for (int t = 0; t < PlayerCount; t++)
|
|
|
|
|
SetTeam(value[t], t);
|
2016-11-10 16:14:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-12 06:29:30 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public PKM[] GetTeam(int teamIndex)
|
|
|
|
|
{
|
|
|
|
|
var team = new PKM[6];
|
|
|
|
|
var ofs = offsets[teamIndex];
|
|
|
|
|
for (int p = 0; p < 6; p++)
|
|
|
|
|
{
|
|
|
|
|
int offset = ofs + (PokeCrypto.SIZE_6PARTY * p);
|
Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately (#3222)
* Track a PKM's Box,Slot,StorageFlags,Identifier metadata separately
Don't store within the object, track the slot origin data separately.
Batch editing now pre-filters if using Box/Slot/Identifier logic; split up mods/filters as they're starting to get pretty hefty.
- Requesting a Box Data report now shows all slots in the save file (party, misc)
- Can now exclude backup saves from database search via toggle (separate from settings preventing load entirely)
- Replace some linq usages with direct code
* Remove WasLink virtual in PKM
Inline any logic, since we now have encounter objects to indicate matching, rather than the proto-legality logic checking properties of a PKM.
* Use Fateful to directly check gen5 mysterygift origins
No other encounter types in gen5 apply Fateful
* Simplify double ball comparison
Used to be separate for deferral cases, now no longer needed to be separate.
* Grab move/relearn reference and update locally
Fix relearn move identifier
* Inline defog HM transfer preference check
HasMove is faster than getting moves & checking contains. Skips allocation by setting values directly.
* Extract more met location metadata checks: WasBredEgg
* Replace Console.Write* with Debug.Write*
There's no console output UI, so don't include them in release builds.
* Inline WasGiftEgg, WasEvent, and WasEventEgg logic
Adios legality tags that aren't entirely correct for the specific format. Just put the computations in EncounterFinder.
2021-06-23 03:23:48 +00:00
|
|
|
|
team[p] = new PK7(Data.Slice(offset, PokeCrypto.SIZE_6STORED));
|
2020-12-05 14:09:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return team;
|
|
|
|
|
}
|
2019-03-15 19:35:55 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public void SetTeam(IReadOnlyList<PKM> team, int teamIndex)
|
2019-03-15 19:35:55 +00:00
|
|
|
|
{
|
2020-12-05 14:09:33 +00:00
|
|
|
|
var ofs = offsets[teamIndex];
|
|
|
|
|
for (int p = 0; p < 6; p++)
|
2019-03-15 19:35:55 +00:00
|
|
|
|
{
|
2020-12-05 14:09:33 +00:00
|
|
|
|
int offset = ofs + (PokeCrypto.SIZE_6PARTY * p);
|
|
|
|
|
team[p].EncryptedPartyData.CopyTo(Data, offset);
|
2019-03-15 19:35:55 +00:00
|
|
|
|
}
|
2020-12-05 14:09:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetPlayerNames()
|
|
|
|
|
{
|
|
|
|
|
string[] trainers = new string[PlayerCount];
|
|
|
|
|
for (int i = 0; i < PlayerCount; i++)
|
2019-03-15 19:35:55 +00:00
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
var span = Data.AsSpan(0x12C + +(0x1A * i), 0x1A);
|
|
|
|
|
var str = StringConverter7.GetString(span);
|
2021-01-15 06:50:13 +00:00
|
|
|
|
trainers[i] = string.IsNullOrWhiteSpace(trainers[i]) ? NPC : str;
|
2020-12-05 14:09:33 +00:00
|
|
|
|
}
|
|
|
|
|
return trainers;
|
|
|
|
|
}
|
2019-03-15 19:35:55 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public void SetPlayerNames(IReadOnlyList<string> value)
|
|
|
|
|
{
|
|
|
|
|
if (value.Count != PlayerCount)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < PlayerCount; i++)
|
|
|
|
|
{
|
|
|
|
|
string tr = value[i] == NPC ? string.Empty : value[i];
|
2022-01-03 05:35:59 +00:00
|
|
|
|
var span = Data.AsSpan(0x12C + +(0x1A * i), 0x1A);
|
|
|
|
|
StringConverter7.SetString(span, tr.AsSpan(), 12, 0, StringConverterOption.ClearZero);
|
2019-03-15 19:35:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private int MatchYear { get => ReadUInt16LittleEndian(Data.AsSpan(0x2BB0)); set => WriteUInt16LittleEndian(Data.AsSpan(0x2BB0), (ushort)value); }
|
2019-03-15 19:35:55 +00:00
|
|
|
|
private int MatchDay { get => Data[0x2BB3]; set => Data[0x2BB3] = (byte)value; }
|
|
|
|
|
private int MatchMonth { get => Data[0x2BB2]; set => Data[0x2BB2] = (byte)value; }
|
|
|
|
|
private int MatchHour { get => Data[0x2BB4]; set => Data[0x2BB4] = (byte)value; }
|
|
|
|
|
private int MatchMinute { get => Data[0x2BB5]; set => Data[0x2BB5] = (byte)value; }
|
|
|
|
|
private int MatchSecond { get => Data[0x2BB6]; set => Data[0x2BB6] = (byte)value; }
|
|
|
|
|
|
|
|
|
|
public DateTime? MatchStamp
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2021-05-14 23:46:48 +00:00
|
|
|
|
if (!DateUtil.IsDateValid(MatchYear, MatchMonth, MatchDay))
|
2019-03-15 19:35:55 +00:00
|
|
|
|
return null;
|
|
|
|
|
return new DateTime(MatchYear, MatchMonth, MatchDay, MatchHour, MatchMinute, MatchSecond);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
{
|
|
|
|
|
MatchYear = value.Value.Year;
|
|
|
|
|
MatchDay = value.Value.Day;
|
|
|
|
|
MatchMonth = value.Value.Month;
|
|
|
|
|
MatchHour = value.Value.Hour;
|
|
|
|
|
MatchMinute = value.Value.Minute;
|
|
|
|
|
MatchSecond = value.Value.Second;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MatchYear = MatchDay = MatchMonth = MatchHour = MatchMinute = MatchSecond = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public int MusicID { get => Data[0x21C]; set => Data[0x21C] = (byte)value; }
|
|
|
|
|
public bool SilentBGM { get => MusicID == 0xFF; set => MusicID = (byte)(value ? 0xFF : MusicID); }
|
2016-11-10 16:14:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|