mirror of
https://github.com/LNH-team/pico-loader.git
synced 2026-06-02 09:16:49 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
namespace PicoLoaderConverter.ApList;
|
||||
|
||||
sealed class ApList
|
||||
{
|
||||
public IReadOnlyList<ApListEntry> Entries { get; }
|
||||
|
||||
public ApList(IEnumerable<ApListEntry> entries)
|
||||
{
|
||||
Entries = entries.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace PicoLoaderConverter.ApList;
|
||||
|
||||
sealed record ApListEntry(
|
||||
uint GameCode,
|
||||
byte GameVersion,
|
||||
DSProtectVersion DSProtectVersion,
|
||||
byte DSProtectFunctionMask,
|
||||
ushort RegularOverlayId,
|
||||
ushort SOverlayId,
|
||||
uint RegularOffset,
|
||||
uint SOffset)
|
||||
{
|
||||
public const ushort OVERLAY_ID_STATIC_ARM9 = 0xFFFE;
|
||||
public const ushort OVERLAY_ID_INVALID = 0xFFFF;
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper;
|
||||
using System.Globalization;
|
||||
|
||||
namespace PicoLoaderConverter.ApList;
|
||||
|
||||
sealed class ApListFactory
|
||||
{
|
||||
private const int BINARY_AP_LIST_ENTRY_SIZE = 16;
|
||||
|
||||
public ApList FromBinary(byte[] data)
|
||||
{
|
||||
int entryCount = data.Length / BINARY_AP_LIST_ENTRY_SIZE;
|
||||
var entries = new ApListEntry[entryCount];
|
||||
using (var reader = new BinaryReader(new MemoryStream(data)))
|
||||
{
|
||||
for (int i = 0; i < entryCount; i++)
|
||||
{
|
||||
entries[i] = ReadBinaryApListEntry(reader);
|
||||
}
|
||||
}
|
||||
|
||||
return new ApList(entries);
|
||||
}
|
||||
|
||||
public byte[] ToBinary(ApList apList)
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
using var writer = new BinaryWriter(memoryStream);
|
||||
foreach (var entry in apList.Entries)
|
||||
{
|
||||
WriteBinaryApListEntry(writer, entry);
|
||||
}
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
public ApList FromCsv(string csv)
|
||||
{
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
Delimiter = ";"
|
||||
};
|
||||
using var reader = new StringReader(csv);
|
||||
using var csvReader = new CsvReader(reader, config);
|
||||
var csvEntries = csvReader
|
||||
.GetRecords<CsvApListEntry>()
|
||||
.Select(ConvertFromCvsApListEntry)
|
||||
.OrderBy(entry => entry.GameCode)
|
||||
.ThenBy(entry => entry.GameVersion)
|
||||
.ToArray();
|
||||
return new ApList(csvEntries);
|
||||
}
|
||||
|
||||
public string ToCsv(ApList apList)
|
||||
{
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
Delimiter = ";"
|
||||
};
|
||||
using var writer = new StringWriter();
|
||||
using var csvWriter = new CsvWriter(writer, config);
|
||||
csvWriter.WriteRecords(
|
||||
apList.Entries
|
||||
.Select(ConvertToCvsApListEntry)
|
||||
.OrderBy(entry => entry.GameCode)
|
||||
.ThenBy(entry => entry.GameVersion));
|
||||
return writer.ToString();
|
||||
}
|
||||
|
||||
private ApListEntry ReadBinaryApListEntry(BinaryReader reader)
|
||||
{
|
||||
uint gameCode = reader.ReadUInt32();
|
||||
ushort info = reader.ReadUInt16();
|
||||
byte gameVersion = (byte)(info & 0x1F);
|
||||
var dsProtectVersion = (DSProtectVersion)((info >> 5) & 0x1F);
|
||||
byte dsProtectFunctionMask = (byte)(info >> 10);
|
||||
ushort regularOverlayId = reader.ReadUInt16();
|
||||
ushort sOverlayId = reader.ReadUInt16();
|
||||
uint regularOffset = ReadUInt24(reader);
|
||||
uint sOffset = ReadUInt24(reader);
|
||||
return new ApListEntry(
|
||||
gameCode,
|
||||
gameVersion,
|
||||
dsProtectVersion,
|
||||
dsProtectFunctionMask,
|
||||
regularOverlayId,
|
||||
sOverlayId,
|
||||
regularOffset,
|
||||
sOffset);
|
||||
}
|
||||
|
||||
private uint ReadUInt24(BinaryReader reader)
|
||||
{
|
||||
var bytes = reader.ReadBytes(3);
|
||||
return (uint)(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16));
|
||||
}
|
||||
|
||||
public void WriteBinaryApListEntry(BinaryWriter writer, ApListEntry entry)
|
||||
{
|
||||
writer.Write(entry.GameCode);
|
||||
writer.Write((ushort)(entry.GameVersion | ((byte)entry.DSProtectVersion << 5) | (entry.DSProtectFunctionMask << 10)));
|
||||
writer.Write(entry.RegularOverlayId);
|
||||
writer.Write(entry.SOverlayId);
|
||||
writer.Write((byte)(entry.RegularOffset & 0xFF));
|
||||
writer.Write((byte)((entry.RegularOffset >> 8) & 0xFF));
|
||||
writer.Write((byte)((entry.RegularOffset >> 16) & 0xFF));
|
||||
writer.Write((byte)(entry.SOffset & 0xFF));
|
||||
writer.Write((byte)((entry.SOffset >> 8) & 0xFF));
|
||||
writer.Write((byte)((entry.SOffset >> 16) & 0xFF));
|
||||
}
|
||||
|
||||
private ApListEntry ConvertFromCvsApListEntry(CsvApListEntry csvApListEntry)
|
||||
{
|
||||
return new ApListEntry(
|
||||
GameCodeToUint(csvApListEntry.GameCode),
|
||||
(byte)csvApListEntry.GameVersion,
|
||||
ParseDSProtectVersion(csvApListEntry.DSProtectVersion),
|
||||
(byte)csvApListEntry.DSProtectFunctionMask,
|
||||
(ushort)csvApListEntry.RegularOverlayId,
|
||||
(ushort)csvApListEntry.SOverlayId,
|
||||
(uint)csvApListEntry.RegularOffset,
|
||||
(uint)csvApListEntry.SOffset);
|
||||
}
|
||||
|
||||
private CsvApListEntry ConvertToCvsApListEntry(ApListEntry apListEntry)
|
||||
{
|
||||
return new CsvApListEntry
|
||||
{
|
||||
GameCode = $"{(char)(apListEntry.GameCode & 0xFF)}{(char)((apListEntry.GameCode >> 8) & 0xFF)}" +
|
||||
$"{(char)((apListEntry.GameCode >> 16) & 0xFF)}{(char)(apListEntry.GameCode >> 24)}",
|
||||
GameVersion = apListEntry.GameVersion,
|
||||
DSProtectVersion = FormatDSProtectVersion(apListEntry.DSProtectVersion),
|
||||
DSProtectFunctionMask = apListEntry.DSProtectFunctionMask,
|
||||
RegularOverlayId = (short)apListEntry.RegularOverlayId,
|
||||
SOverlayId = (short)apListEntry.SOverlayId,
|
||||
RegularOffset = (int)apListEntry.RegularOffset,
|
||||
SOffset = (int)apListEntry.SOffset
|
||||
};
|
||||
}
|
||||
|
||||
private uint GameCodeToUint(string gameCode)
|
||||
{
|
||||
if (gameCode.Length != 4)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Game code '{gameCode}' is not valid. It must consist of exactly 4 characters.", nameof(gameCode));
|
||||
}
|
||||
return (uint)gameCode[0] | ((uint)gameCode[1] << 8) | ((uint)gameCode[2] << 16) | ((uint)gameCode[3] << 24);
|
||||
}
|
||||
|
||||
private DSProtectVersion ParseDSProtectVersion(string dsProtectVersion)
|
||||
{
|
||||
return dsProtectVersion switch
|
||||
{
|
||||
"1.05" => DSProtectVersion.V1_05,
|
||||
"1.06" => DSProtectVersion.V1_06,
|
||||
"1.08" => DSProtectVersion.V1_08,
|
||||
"1.10" => DSProtectVersion.V1_10,
|
||||
"1.20" => DSProtectVersion.V1_20,
|
||||
"1.22" => DSProtectVersion.V1_22,
|
||||
"1.23" => DSProtectVersion.V1_23,
|
||||
"1.23Z" => DSProtectVersion.V1_23Z,
|
||||
"1.25" => DSProtectVersion.V1_25,
|
||||
"1.26" => DSProtectVersion.V1_26,
|
||||
"1.27" => DSProtectVersion.V1_27,
|
||||
"1.28" => DSProtectVersion.V1_28,
|
||||
"2.00" => DSProtectVersion.V2_00,
|
||||
"2.01" => DSProtectVersion.V2_01,
|
||||
"2.03" => DSProtectVersion.V2_03,
|
||||
"2.05" => DSProtectVersion.V2_05,
|
||||
"2.00s" => DSProtectVersion.V2_00s,
|
||||
"2.01s" => DSProtectVersion.V2_01s,
|
||||
"2.03s" => DSProtectVersion.V2_03s,
|
||||
"2.05s" => DSProtectVersion.V2_05s,
|
||||
_ => throw new ArgumentException(
|
||||
$"DS Protect Version '{dsProtectVersion}' could not be parsed.", nameof(dsProtectVersion))
|
||||
};
|
||||
}
|
||||
|
||||
private string FormatDSProtectVersion(DSProtectVersion dsProtectVersion)
|
||||
{
|
||||
return dsProtectVersion switch
|
||||
{
|
||||
DSProtectVersion.V1_05 => "1.05",
|
||||
DSProtectVersion.V1_06 => "1.06",
|
||||
DSProtectVersion.V1_08 => "1.08",
|
||||
DSProtectVersion.V1_10 => "1.10",
|
||||
DSProtectVersion.V1_20 => "1.20",
|
||||
DSProtectVersion.V1_22 => "1.22",
|
||||
DSProtectVersion.V1_23 => "1.23",
|
||||
DSProtectVersion.V1_23Z => "1.23Z",
|
||||
DSProtectVersion.V1_25 => "1.25",
|
||||
DSProtectVersion.V1_26 => "1.26",
|
||||
DSProtectVersion.V1_27 => "1.27",
|
||||
DSProtectVersion.V1_28 => "1.28",
|
||||
DSProtectVersion.V2_00 => "2.00",
|
||||
DSProtectVersion.V2_01 => "2.01",
|
||||
DSProtectVersion.V2_03 => "2.03",
|
||||
DSProtectVersion.V2_05 => "2.05",
|
||||
DSProtectVersion.V2_00s => "2.00s",
|
||||
DSProtectVersion.V2_01s => "2.01s",
|
||||
DSProtectVersion.V2_03s => "2.03s",
|
||||
DSProtectVersion.V2_05s => "2.05s",
|
||||
_ => throw new ArgumentException("Invalid DS Protect Version.", nameof(dsProtectVersion))
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using CsvHelper.Configuration.Attributes;
|
||||
using PicoLoaderConverter.Csv;
|
||||
|
||||
namespace PicoLoaderConverter.ApList;
|
||||
|
||||
sealed class CsvApListEntry
|
||||
{
|
||||
[Name("gameCode")]
|
||||
public string GameCode { get; set; } = string.Empty;
|
||||
|
||||
[Name("gameVersion")]
|
||||
public int GameVersion { get; set; }
|
||||
|
||||
[Name("dsprotVersion")]
|
||||
public string DSProtectVersion { get; set; } = string.Empty;
|
||||
|
||||
[Name("dsprotFuncMask")]
|
||||
[TypeConverter(typeof(BinaryNumberConverter))]
|
||||
public int DSProtectFunctionMask { get; set; }
|
||||
|
||||
[Name("regularOvlId")]
|
||||
public int RegularOverlayId { get; set; }
|
||||
|
||||
[Name("regularOffset")]
|
||||
[TypeConverter(typeof(HexNumberConverter))]
|
||||
public int RegularOffset { get; set; }
|
||||
|
||||
[Name("sOvlId")]
|
||||
public int SOverlayId { get; set; }
|
||||
|
||||
[Name("sOffset")]
|
||||
[TypeConverter(typeof(HexNumberConverter))]
|
||||
public int SOffset { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace PicoLoaderConverter.ApList;
|
||||
|
||||
enum DSProtectVersion
|
||||
{
|
||||
V1_06,
|
||||
V1_05,
|
||||
V1_08,
|
||||
V1_10,
|
||||
V1_20,
|
||||
V1_22,
|
||||
V1_23,
|
||||
V1_23Z,
|
||||
V1_25,
|
||||
V1_26,
|
||||
V1_27,
|
||||
V1_28,
|
||||
V2_00,
|
||||
V2_01,
|
||||
V2_03,
|
||||
V2_05,
|
||||
V2_00s,
|
||||
V2_01s,
|
||||
V2_03s,
|
||||
V2_05s
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper.TypeConversion;
|
||||
|
||||
namespace PicoLoaderConverter.Csv;
|
||||
|
||||
sealed class BinaryNumberConverter : DefaultTypeConverter
|
||||
{
|
||||
public override object? ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData)
|
||||
{
|
||||
if (text?.StartsWith("0b") is true)
|
||||
{
|
||||
text = text[2..];
|
||||
}
|
||||
return Convert.ToInt32(text, 2);
|
||||
}
|
||||
|
||||
public override string? ConvertToString(object? value, IWriterRow row, MemberMapData memberMapData)
|
||||
{
|
||||
return Convert.ToString(Convert.ToInt32(value), 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CsvHelper;
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper.TypeConversion;
|
||||
|
||||
namespace PicoLoaderConverter.Csv;
|
||||
|
||||
sealed class HexNumberConverter : DefaultTypeConverter
|
||||
{
|
||||
public override object? ConvertFromString(string? text, IReaderRow row, MemberMapData memberMapData)
|
||||
{
|
||||
if (text?.StartsWith("0x") is true)
|
||||
{
|
||||
text = text[2..];
|
||||
}
|
||||
return Convert.ToInt32(text, 16);
|
||||
}
|
||||
|
||||
public override string? ConvertToString(object? value, IWriterRow row, MemberMapData memberMapData)
|
||||
{
|
||||
return "0x" + Convert.ToString(Convert.ToInt32(value), 16);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||
<PackageReference Include="CsvHelper" Version="33.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
24
tools/PicoLoaderConverter/PicoLoaderConverter/Program.cs
Normal file
24
tools/PicoLoaderConverter/PicoLoaderConverter/Program.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using CommandLine;
|
||||
using PicoLoaderConverter.Verbs;
|
||||
|
||||
namespace PicoLoaderConverter;
|
||||
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// List of verbs supported by the Pico Loader Converter.
|
||||
/// To make a new verb, create a class implementing <see cref="IConverterVerb"/> and
|
||||
/// add it to this list.
|
||||
/// </summary>
|
||||
private static readonly Type[] sVerbs = [
|
||||
typeof(ApListConverterVerb),
|
||||
typeof(SaveListConverterVerb)
|
||||
];
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Parser.Default
|
||||
.ParseArguments(args, sVerbs)
|
||||
.WithParsed<IConverterVerb>(o => o.Run());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace PicoLoaderConverter.SaveList;
|
||||
|
||||
enum CardSaveType
|
||||
{
|
||||
None = 0,
|
||||
Eeprom = 1,
|
||||
Flash = 2,
|
||||
Nand = 3
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CsvHelper.Configuration.Attributes;
|
||||
using PicoLoaderConverter.Csv;
|
||||
|
||||
namespace PicoLoaderConverter.SaveList;
|
||||
|
||||
sealed class CsvSaveListEntry
|
||||
{
|
||||
[Name("gameCode")]
|
||||
public string GameCode { get; set; } = string.Empty;
|
||||
|
||||
[Name("saveType")]
|
||||
public string SaveType { get; set; } = string.Empty;
|
||||
|
||||
[Name("saveSize")]
|
||||
[TypeConverter(typeof(HexNumberConverter))]
|
||||
public int SaveSize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace PicoLoaderConverter.SaveList;
|
||||
|
||||
sealed class SaveList
|
||||
{
|
||||
public IReadOnlyList<SaveListEntry> Entries { get; }
|
||||
|
||||
public SaveList(IEnumerable<SaveListEntry> entries)
|
||||
{
|
||||
Entries = entries.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace PicoLoaderConverter.SaveList;
|
||||
|
||||
sealed record SaveListEntry(
|
||||
uint GameCode,
|
||||
CardSaveType SaveType,
|
||||
byte SaveSize);
|
||||
@@ -0,0 +1,150 @@
|
||||
using CsvHelper.Configuration;
|
||||
using CsvHelper;
|
||||
using System.Globalization;
|
||||
using System.Numerics;
|
||||
|
||||
namespace PicoLoaderConverter.SaveList;
|
||||
|
||||
sealed class SaveListFactory
|
||||
{
|
||||
private const int BINARY_SAVE_LIST_ENTRY_SIZE = 8;
|
||||
|
||||
public SaveList FromBinary(byte[] data)
|
||||
{
|
||||
int entryCount = data.Length / BINARY_SAVE_LIST_ENTRY_SIZE;
|
||||
var entries = new SaveListEntry[entryCount];
|
||||
using (var reader = new BinaryReader(new MemoryStream(data)))
|
||||
{
|
||||
for (int i = 0; i < entryCount; i++)
|
||||
{
|
||||
entries[i] = ReadBinarySaveListEntry(reader);
|
||||
}
|
||||
}
|
||||
|
||||
return new SaveList(entries);
|
||||
}
|
||||
|
||||
public byte[] ToBinary(SaveList saveList)
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
using var writer = new BinaryWriter(memoryStream);
|
||||
foreach (var entry in saveList.Entries)
|
||||
{
|
||||
WriteBinarySaveListEntry(writer, entry);
|
||||
}
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
public SaveList FromCsv(string csv)
|
||||
{
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
Delimiter = ";"
|
||||
};
|
||||
using var reader = new StringReader(csv);
|
||||
using var csvReader = new CsvReader(reader, config);
|
||||
var csvEntries = csvReader
|
||||
.GetRecords<CsvSaveListEntry>()
|
||||
.Select(ConvertFromCvsSaveListEntry)
|
||||
.OrderBy(entry => entry.GameCode)
|
||||
.ToArray();
|
||||
return new SaveList(csvEntries);
|
||||
}
|
||||
|
||||
public string ToCsv(SaveList saveList)
|
||||
{
|
||||
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
|
||||
{
|
||||
Delimiter = ";"
|
||||
};
|
||||
using var writer = new StringWriter();
|
||||
using var csvWriter = new CsvWriter(writer, config);
|
||||
csvWriter.WriteRecords(
|
||||
saveList.Entries
|
||||
.Select(ConvertToCvsSaveListEntry)
|
||||
.OrderBy(entry => entry.GameCode));
|
||||
return writer.ToString();
|
||||
}
|
||||
|
||||
private SaveListEntry ReadBinarySaveListEntry(BinaryReader reader)
|
||||
{
|
||||
uint gameCode = reader.ReadUInt32();
|
||||
var saveType = (CardSaveType)reader.ReadByte();
|
||||
byte saveSize = reader.ReadByte();
|
||||
reader.ReadUInt16();
|
||||
return new SaveListEntry(
|
||||
gameCode,
|
||||
saveType,
|
||||
saveSize);
|
||||
}
|
||||
|
||||
public void WriteBinarySaveListEntry(BinaryWriter writer, SaveListEntry entry)
|
||||
{
|
||||
writer.Write(entry.GameCode);
|
||||
writer.Write((byte)entry.SaveType);
|
||||
writer.Write(entry.SaveSize);
|
||||
writer.Write((ushort)0);
|
||||
}
|
||||
|
||||
private SaveListEntry ConvertFromCvsSaveListEntry(CsvSaveListEntry csvSaveListEntry)
|
||||
{
|
||||
if (csvSaveListEntry.SaveSize < 0 ||
|
||||
(csvSaveListEntry.SaveSize > 0 && !BitOperations.IsPow2(csvSaveListEntry.SaveSize)))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Save size 0x{csvSaveListEntry.SaveSize:X} is not supported. It must be a power of two.",
|
||||
nameof(csvSaveListEntry));
|
||||
}
|
||||
|
||||
return new SaveListEntry(
|
||||
GameCodeToUint(csvSaveListEntry.GameCode),
|
||||
ParseSaveType(csvSaveListEntry.SaveType),
|
||||
(byte)(csvSaveListEntry.SaveSize == 0 ? 0 : BitOperations.Log2((uint)csvSaveListEntry.SaveSize)));
|
||||
}
|
||||
|
||||
private CsvSaveListEntry ConvertToCvsSaveListEntry(SaveListEntry saveListEntry)
|
||||
{
|
||||
return new CsvSaveListEntry
|
||||
{
|
||||
GameCode = $"{(char)(saveListEntry.GameCode & 0xFF)}{(char)(saveListEntry.GameCode >> 8 & 0xFF)}" +
|
||||
$"{(char)(saveListEntry.GameCode >> 16 & 0xFF)}{(char)(saveListEntry.GameCode >> 24)}",
|
||||
SaveType = FormatSaveType(saveListEntry.SaveType),
|
||||
SaveSize = saveListEntry.SaveSize == 0 ? 0 : (1 << saveListEntry.SaveSize)
|
||||
};
|
||||
}
|
||||
|
||||
private uint GameCodeToUint(string gameCode)
|
||||
{
|
||||
if (gameCode.Length != 4)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
$"Game code '{gameCode}' is not valid. It must consist of exactly 4 characters.", nameof(gameCode));
|
||||
}
|
||||
return gameCode[0] | (uint)gameCode[1] << 8 | (uint)gameCode[2] << 16 | (uint)gameCode[3] << 24;
|
||||
}
|
||||
|
||||
private CardSaveType ParseSaveType(string saveType)
|
||||
{
|
||||
return saveType.ToLowerInvariant() switch
|
||||
{
|
||||
"none" => CardSaveType.None,
|
||||
"eeprom" => CardSaveType.Eeprom,
|
||||
"flash" => CardSaveType.Flash,
|
||||
"nand" => CardSaveType.Nand,
|
||||
_ => throw new ArgumentException(
|
||||
$"Save type '{saveType}' could not be parsed.", nameof(saveType))
|
||||
};
|
||||
}
|
||||
|
||||
private string FormatSaveType(CardSaveType saveType)
|
||||
{
|
||||
return saveType switch
|
||||
{
|
||||
CardSaveType.None => "none",
|
||||
CardSaveType.Eeprom => "eeprom",
|
||||
CardSaveType.Flash => "flash",
|
||||
CardSaveType.Nand => "nand",
|
||||
_ => throw new ArgumentException("Invalid card save type.", nameof(saveType))
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using CommandLine;
|
||||
using PicoLoaderConverter.ApList;
|
||||
|
||||
namespace PicoLoaderConverter.Verbs;
|
||||
|
||||
[Verb("aplist", HelpText = "Convert ap list from csv to bin.")]
|
||||
sealed class ApListConverterVerb : IConverterVerb
|
||||
{
|
||||
[Option('i', Required = true, HelpText = "Input .csv file.")]
|
||||
public required string InputFile { get; init; }
|
||||
|
||||
[Option('o', Required = true, HelpText = "Output .bin file.")]
|
||||
public required string OutputFile { get; init; }
|
||||
|
||||
public void Run()
|
||||
{
|
||||
// Convert ap list from csv to bin
|
||||
var factory = new ApListFactory();
|
||||
var apList = factory.FromCsv(File.ReadAllText(InputFile));
|
||||
var binaryList = factory.ToBinary(apList);
|
||||
File.WriteAllBytes(OutputFile, binaryList);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace PicoLoaderConverter.Verbs;
|
||||
|
||||
/// <summary>
|
||||
/// Interface representing a verb supported by the Splatoon DS Converter.
|
||||
/// </summary>
|
||||
interface IConverterVerb
|
||||
{
|
||||
/// <summary>
|
||||
/// Runs the verb action.
|
||||
/// </summary>
|
||||
void Run();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using CommandLine;
|
||||
using PicoLoaderConverter.SaveList;
|
||||
|
||||
namespace PicoLoaderConverter.Verbs;
|
||||
|
||||
[Verb("savelist", HelpText = "Convert save list from csv to bin.")]
|
||||
sealed class SaveListConverterVerb : IConverterVerb
|
||||
{
|
||||
[Option('i', Required = true, HelpText = "Input .csv file.")]
|
||||
public required string InputFile { get; init; }
|
||||
|
||||
[Option('o', Required = true, HelpText = "Output .bin file.")]
|
||||
public required string OutputFile { get; init; }
|
||||
|
||||
public void Run()
|
||||
{
|
||||
// Convert save list from csv to bin
|
||||
var factory = new SaveListFactory();
|
||||
var apList = factory.FromCsv(File.ReadAllText(InputFile));
|
||||
var binaryList = factory.ToBinary(apList);
|
||||
File.WriteAllBytes(OutputFile, binaryList);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user