2018-07-07 18:20:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public static class PSS6
|
|
|
|
|
{
|
|
|
|
|
private const string Header = "PSS List";
|
2021-03-14 23:16:55 +00:00
|
|
|
|
private static readonly string[] headers = { "PSS Data - Friends", "PSS Data - Acquaintances", "PSS Data - Passerby" };
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
public static List<string> GetPSSParse(SAV6 SAV)
|
|
|
|
|
{
|
|
|
|
|
var result = new List<string> {Header};
|
|
|
|
|
int offset = SAV.PSS;
|
|
|
|
|
var data = SAV.Data;
|
|
|
|
|
for (int g = 0; g < 3; g++)
|
|
|
|
|
{
|
|
|
|
|
result.Add("----");
|
|
|
|
|
result.Add(headers[g]);
|
|
|
|
|
result.Add("----");
|
2022-01-03 05:35:59 +00:00
|
|
|
|
// uint count = ReadUInt32LittleEndian(data.AsSpan(offset + 0x4E20));
|
2018-07-07 18:20:05 +00:00
|
|
|
|
ReadTrainers(result, data, offset, 100);
|
|
|
|
|
offset += 0x5000; // Advance to next block
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ReadTrainers(ICollection<string> result, byte[] data, int offset, int count)
|
|
|
|
|
{
|
|
|
|
|
int r_offset = offset;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
const int size = 0xC8;
|
2018-07-07 18:20:05 +00:00
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
if (!ReadTrainer(result, data.AsSpan(r_offset, size)))
|
2018-07-07 18:20:05 +00:00
|
|
|
|
break; // No data present here
|
|
|
|
|
|
|
|
|
|
if (i > 0)
|
2019-02-08 05:40:20 +00:00
|
|
|
|
result.Add(string.Empty);
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
r_offset += size; // Advance to next entry
|
2018-07-07 18:20:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private static bool ReadTrainer(ICollection<string> result, ReadOnlySpan<byte> data)
|
2018-07-07 18:20:05 +00:00
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
ulong pssID = ReadUInt64LittleEndian(data);
|
2018-07-07 18:20:05 +00:00
|
|
|
|
if (pssID == 0)
|
|
|
|
|
return false; // no data
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
string otname = StringConverter6.GetString(data.Slice(0x08, 0x1A));
|
|
|
|
|
string message = StringConverter6.GetString(data.Slice(0x22, 0x22));
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
// Trim terminated
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
// uint unk1 = ReadUInt32LittleEndian(data[0x44..]);
|
|
|
|
|
// ulong unk2 = ReadUInt64LittleEndian(data[0x48..]);
|
|
|
|
|
// uint unk3 = ReadUInt32LittleEndian(data[0x50..]);
|
|
|
|
|
// uint unk4 = ReadUInt16LittleEndian(data[0x54..]);
|
|
|
|
|
byte regionID = data[0x56];
|
|
|
|
|
byte countryID = data[0x57];
|
|
|
|
|
byte game = data[0x5A];
|
|
|
|
|
// ulong outfit = ReadUInt64LittleEndian(data.AsSpan(ofs + 0x5C));
|
|
|
|
|
int favpkm = ReadUInt16LittleEndian(data[0x9C..]) & 0x7FF;
|
2018-07-07 18:20:05 +00:00
|
|
|
|
|
|
|
|
|
string gamename = GetGameName(game);
|
2021-05-18 20:29:55 +00:00
|
|
|
|
var (country, region) = GeoLocation.GetCountryRegionText(countryID, regionID, GameInfo.CurrentLanguage);
|
2018-07-07 18:20:05 +00:00
|
|
|
|
result.Add($"OT: {otname}");
|
|
|
|
|
result.Add($"Message: {message}");
|
|
|
|
|
result.Add($"Game: {gamename}");
|
2021-05-18 20:29:55 +00:00
|
|
|
|
result.Add($"Country: {country}");
|
|
|
|
|
result.Add($"Region: {region}");
|
2018-07-07 18:20:05 +00:00
|
|
|
|
result.Add($"Favorite: {GameInfo.Strings.specieslist[favpkm]}");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetGameName(int game)
|
|
|
|
|
{
|
|
|
|
|
const string unk = "UNKNOWN GAME";
|
|
|
|
|
if (game < 0)
|
|
|
|
|
return unk;
|
|
|
|
|
var list = GameInfo.Strings.gamelist;
|
|
|
|
|
if (game >= list.Length)
|
|
|
|
|
return unk;
|
|
|
|
|
return list[game];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|