pkNX/pkNX.Structures/Learnset/Learnset8.cs
Kurt 2578ba073c Refactoring
File scoped namespaces for all lib projects
netstandard2.0 => net6; now uniform. bye netframework!
2022-10-01 17:08:17 -07:00

67 lines
1.6 KiB
C#

using System;
using System.IO;
namespace pkNX.Structures;
public class Learnset8 : Learnset
{
private const int SIZE = 0x104;
public Learnset8(byte[] data)
{
// scan for count
int count = 0;
for (; count < SIZE / 4; count++)
{
if (data[(count * 4) + 3] == 0xFF) // check 3rd byte of each u16/u16 tuple, level is never > 255
break;
}
Count = count;
if (Count == 0)
{
Levels = Moves = Array.Empty<int>();
return;
}
Moves = new int[Count];
Levels = new int[Count];
using var ms = new MemoryStream(data);
using var br = new BinaryReader(ms);
for (int i = 0; i < Count; i++)
{
Moves[i] = br.ReadInt16();
Levels[i] = br.ReadInt16();
}
}
public override byte[] Write()
{
Count = (ushort)Moves.Length;
using MemoryStream ms = new MemoryStream();
using BinaryWriter bw = new BinaryWriter(ms);
for (int i = 0; i < Count; i++)
{
bw.Write((short)Moves[i]);
bw.Write((short)Levels[i]);
}
while (bw.BaseStream.Length != SIZE)
bw.Write(-1);
return ms.ToArray();
}
public byte[] WriteAsLearn6()
{
using var ms = new MemoryStream();
using var br = new BinaryWriter(ms);
for (int j = 0; j < Moves.Length; j++)
{
br.Write((ushort)Moves[j]);
br.Write((ushort)Levels[j]);
}
br.Write(-1);
return ms.ToArray();
}
}