PKHeX/PKHeX.Core/Legality/Data.cs

37 lines
1.3 KiB
C#
Raw Normal View History

using System;
namespace PKHeX.Core
{
public static class Data
2016-04-19 01:21:50 +00:00
{
/// <summary>
/// Unpacks a BinLinkerAccessor generated file container into individual arrays.
/// </summary>
/// <param name="fileData">Packed data</param>
/// <param name="identifier">Signature expected in the first two bytes (ASCII)</param>
/// <returns>Unpacked array containing all files that were packed.</returns>
public static byte[][] UnpackMini(byte[] fileData, string identifier)
2016-04-19 01:21:50 +00:00
{
2016-10-24 04:57:43 +00:00
if (fileData == null || fileData.Length < 4)
return null;
if (identifier[0] != fileData[0] || identifier[1] != fileData[1])
return null;
2018-05-12 15:13:39 +00:00
int count = BitConverter.ToUInt16(fileData, 2); int ctr = 4;
int start = BitConverter.ToInt32(fileData, ctr); ctr += 4;
byte[][] returnData = new byte[count][];
for (int i = 0; i < count; i++)
2016-04-19 01:21:50 +00:00
{
int end = BitConverter.ToInt32(fileData, ctr); ctr += 4;
int len = end - start;
byte[] data = new byte[len];
Buffer.BlockCopy(fileData, start, data, 0, len);
returnData[i] = data;
start = end;
2016-04-19 01:21:50 +00:00
}
return returnData;
2016-04-19 01:21:50 +00:00
}
}
}