2021-03-28 06:22:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2021-03-28 06:22:56 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public sealed class BV3 : BattleVideo
|
|
|
|
|
{
|
|
|
|
|
internal const int SIZE = 0xF80;
|
|
|
|
|
public override int Generation => 3;
|
|
|
|
|
|
|
|
|
|
public override IReadOnlyList<PKM> BattlePKMs => PlayerTeams.SelectMany(z => z).ToArray();
|
|
|
|
|
|
|
|
|
|
public readonly byte[] Data;
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
internal new static bool IsValid(ReadOnlySpan<byte> data)
|
2021-03-28 06:22:56 +00:00
|
|
|
|
{
|
|
|
|
|
if (data.Length != SIZE)
|
|
|
|
|
return false;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
var chk = ReadUInt32LittleEndian(data[(SIZE-4)..]);
|
2021-03-28 06:22:56 +00:00
|
|
|
|
if (chk > 0xF7080)
|
|
|
|
|
return false; // max if all are FF
|
|
|
|
|
var expect = GetChecksum8(data);
|
|
|
|
|
return chk == expect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BV3(byte[] data) => Data = (byte[])data.Clone();
|
|
|
|
|
public BV3() : this(new byte[SIZE]) { }
|
|
|
|
|
|
|
|
|
|
public IReadOnlyList<PK3[]> PlayerTeams
|
|
|
|
|
{
|
|
|
|
|
get => new[]
|
|
|
|
|
{
|
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
|
|
|
|
GetTeam(0),
|
|
|
|
|
GetTeam(1),
|
2021-03-28 06:22:56 +00:00
|
|
|
|
};
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetTeam(value[0], 0);
|
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
|
|
|
|
SetTeam(value[1], 1);
|
2021-03-28 06:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
public PK3[] GetTeam(int teamIndex)
|
2021-03-28 06:22:56 +00:00
|
|
|
|
{
|
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
|
|
|
|
if ((uint)teamIndex > 2)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(teamIndex));
|
|
|
|
|
|
|
|
|
|
var ofs = (6 * PokeCrypto.SIZE_3PARTY) * teamIndex;
|
2021-03-28 06:22:56 +00:00
|
|
|
|
var team = new PK3[6];
|
|
|
|
|
for (int p = 0; p < 6; p++)
|
|
|
|
|
{
|
|
|
|
|
int offset = ofs + (PokeCrypto.SIZE_3PARTY * 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 PK3(Data.Slice(offset, PokeCrypto.SIZE_3PARTY));
|
2021-03-28 06:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return team;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
public void SetTeam(IReadOnlyList<PK3> team, int teamIndex)
|
2021-03-28 06:22:56 +00:00
|
|
|
|
{
|
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
|
|
|
|
var ofs = (6 * PokeCrypto.SIZE_3PARTY) * teamIndex;
|
2021-03-28 06:22:56 +00:00
|
|
|
|
for (int p = 0; p < 6; p++)
|
|
|
|
|
{
|
|
|
|
|
int offset = ofs + (PokeCrypto.SIZE_3PARTY * p);
|
|
|
|
|
team[p].EncryptedPartyData.CopyTo(Data, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 0x4B0 - string3[4][8] Trainer Names
|
|
|
|
|
// 0x4D0 - u8[4] Trainer Genders
|
|
|
|
|
// 0x4D4 - u32[4] Trainer IDs
|
|
|
|
|
// 0x4E4 - u8[4] Trainer Languages
|
|
|
|
|
|
|
|
|
|
public uint Seed
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt32LittleEndian(Data.AsSpan(0x4E8));
|
|
|
|
|
set => WriteUInt32LittleEndian(Data.AsSpan(0x4E8), value);
|
2021-03-28 06:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint Mode
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt32LittleEndian(Data.AsSpan(0x4EC));
|
|
|
|
|
set => WriteUInt32LittleEndian(Data.AsSpan(0x4EC), value);
|
2021-03-28 06:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
public uint Checksum
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt32LittleEndian(Data.AsSpan(SIZE - 4));
|
|
|
|
|
set => WriteUInt32LittleEndian(Data.AsSpan(SIZE - 4), value);
|
2021-03-28 06:22:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsChecksumValid() => Checksum == GetChecksum8(Data);
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
public static uint GetChecksum8(ReadOnlySpan<byte> data)
|
2021-03-28 06:22:56 +00:00
|
|
|
|
{
|
|
|
|
|
uint result = 0;
|
|
|
|
|
for (int i = 0; i < data.Length - 4; i++)
|
|
|
|
|
result += data[i];
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|