2016-02-22 22:52:48 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
2017-01-07 23:54:09 -08:00
|
|
|
|
namespace PKHeX.Core
|
2016-02-22 22:52:48 -08:00
|
|
|
|
{
|
2017-01-07 23:54:09 -08:00
|
|
|
|
public static class Data
|
2016-04-18 18:21:50 -07:00
|
|
|
|
{
|
2018-08-08 21:27:14 -07: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>
|
2017-06-17 18:37:19 -07:00
|
|
|
|
public static byte[][] UnpackMini(byte[] fileData, string identifier)
|
2016-04-18 18:21:50 -07:00
|
|
|
|
{
|
2016-10-23 21:57:43 -07:00
|
|
|
|
if (fileData == null || fileData.Length < 4)
|
|
|
|
|
return null;
|
|
|
|
|
|
2017-03-16 23:16:11 -07:00
|
|
|
|
if (identifier[0] != fileData[0] || identifier[1] != fileData[1])
|
|
|
|
|
return null;
|
2018-05-12 08:13:39 -07:00
|
|
|
|
|
2017-03-16 23:16:11 -07: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-18 18:21:50 -07:00
|
|
|
|
{
|
2017-03-16 23:16:11 -07: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-18 18:21:50 -07:00
|
|
|
|
}
|
2017-03-16 23:16:11 -07:00
|
|
|
|
return returnData;
|
2016-04-18 18:21:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-22 22:52:48 -08:00
|
|
|
|
}
|