2
0
Fork 0
mirror of https://github.com/kwsch/PKHeX synced 2024-12-22 10:23:09 +00:00
PKHeX/PKHeX.Core/Saves/Substructures/Gen8/RentalTeam8.cs

73 lines
2.3 KiB
C#
Raw Normal View History

2020-02-08 01:23:26 +00:00
using System;
using System.Collections.Generic;
namespace PKHeX.Core
{
/// <summary>
/// Container block for Generation 8 saved Rental Teams
/// </summary>
public sealed class RentalTeam8 : IRentalTeam<PK8>
2020-02-08 01:23:26 +00:00
{
private const int LEN_META = 0x56;
private const int LEN_STORED = PokeCrypto.SIZE_8STORED; // 0x148
private const int LEN_POKE = PokeCrypto.SIZE_8PARTY; // 0x158
private const int LEN_PARTYSTAT = LEN_POKE - PokeCrypto.SIZE_8STORED; // 0x10
2020-02-08 01:23:26 +00:00
private const int COUNT_POKE = 6;
private const int OFS_META = 0;
private const int OFS_1 = OFS_META + LEN_META;
private const int OFS_2 = OFS_1 + LEN_POKE;
private const int OFS_3 = OFS_2 + LEN_POKE;
private const int OFS_4 = OFS_3 + LEN_POKE;
private const int OFS_5 = OFS_4 + LEN_POKE;
private const int OFS_6 = OFS_5 + LEN_POKE;
private const int POST_META = OFS_6 + LEN_POKE;
private readonly byte[] Data;
public RentalTeam8(byte[] data) => Data = data;
public PK8 GetSlot(int slot)
{
var ofs = GetSlotOffset(slot);
var data = Data.Slice(ofs, LEN_POKE);
var pk8 = new PK8(data);
pk8.ResetPartyStats();
return pk8;
}
public void SetSlot(int slot, PK8 pkm)
{
var ofs = GetSlotOffset(slot);
var data = pkm.EncryptedPartyData;
// Wipe Party Stats
Array.Clear(data, LEN_STORED, LEN_PARTYSTAT);
2020-02-08 01:23:26 +00:00
data.CopyTo(Data, ofs);
}
public PK8[] GetTeam()
{
var team = new PK8[COUNT_POKE];
for (int i = 0; i < team.Length; i++)
team[i] = GetSlot(i);
return team;
}
public void SetTeam(IReadOnlyList<PK8> team)
{
for (int i = 0; i < team.Count; i++)
SetSlot(i, team[i]);
}
public static int GetSlotOffset(int slot)
{
if ((uint)slot >= COUNT_POKE)
throw new ArgumentOutOfRangeException(nameof(slot));
return OFS_1 + (LEN_POKE * slot);
}
public byte[] GetMetadataStart() => Data.Slice(OFS_META, LEN_META);
public byte[] GetMetadataEnd() => Data.SliceEnd(POST_META);
}
}