public byte[] Write() { List <byte> bytes = new List <byte>(); SortEntries(); //Header bytes.AddRange(BitConverter.GetBytes((uint)1279348771)); //Signature "#PAL" bytes.AddRange(BitConverter.GetBytes((ushort)65534)); //Endianess bytes.AddRange(BitConverter.GetBytes((ushort)I_06)); //Unknown... but probably file version bytes.AddRange(BitConverter.GetBytes((uint)PalEntries?.Count)); bytes.AddRange(BitConverter.GetBytes((uint)16)); //Info entries bytes.AddRange(PalEntry.WriteAll(PalEntries)); //Equipment entries foreach (var entry in PalEntries) { bytes.AddRange(entry.Equipment.Write()); } //Stat entries foreach (var entry in PalEntries) { bytes.AddRange(entry.Stats.Write()); } return(bytes.ToArray()); }
public static PAL_File Parse(byte[] bytes) { PAL_File palFile = new PAL_File(); palFile.I_06 = BitConverter.ToUInt16(bytes, 6); int count = BitConverter.ToInt32(bytes, 8); int offset = BitConverter.ToInt32(bytes, 12); palFile.PalEntries = PalEntry.ReadAll(bytes, offset, count); List <Equipment> equipments = Equipment.ReadAll(bytes, offset + (10 * count), count); List <Stats> stats = Stats.ReadAll(bytes, offset + (10 * count) + (78 * count), count); for (int i = 0; i < palFile.PalEntries.Count; i++) { palFile.PalEntries[i].Equipment = equipments[i]; palFile.PalEntries[i].Stats = stats[i]; } return(palFile); }