using System.IO;
namespace NHSE.Core
{
///
/// Logic for dumping decrypted game files.
///
///
public static class GameFileDumper
{
///
/// Dumps a copy of the 's files in their decrypted state to the requested .
///
/// Save Data to dump
/// Path to dump to
public static void Dump(this HorizonSave sav, string path)
{
sav.Main.Dump(path);
foreach (var p in sav.Players)
{
var dir = Path.Combine(path, p.DirectoryName);
p.Dump(dir);
}
}
///
/// Dumps a copy of the 's files in their decrypted state to the requested .
///
/// Save Data to dump
/// Path to dump to
public static void Dump(this Player player, string path)
{
foreach (var pair in player)
pair.Dump(path);
}
///
/// Dumps a copy of the 's files in their decrypted state to the requested .
///
/// Save Data to dump
/// Path to dump to
public static void Dump(this EncryptedFilePair pair, string path)
{
Dump(path, pair.Data, pair.NameData);
}
private static void Dump(string path, byte[] data, string name)
{
Directory.CreateDirectory(path);
var file = Path.Combine(path, name);
File.WriteAllBytes(file, data);
}
///
/// Dumps all villagers in their decrypted state to the requested .
///
/// Save Data to dump from
/// Path to dump to
public static void DumpVillagers(this MainSave sav, string path)
{
for (int i = 0; i < 10; i++)
{
var v = sav.GetVillager(i);
var name = GameInfo.Strings.GetVillager(v.InternalName);
var dest = Path.Combine(path, $"{name}.nhv");
File.WriteAllBytes(dest, v.Data);
}
}
///
/// Dumps all villagers in their decrypted state to the requested .
///
/// Save Data to dump from
/// Path to dump to
public static void DumpDesigns(this MainSave sav, string path)
{
for (int i = 0; i < 50; i++)
{
var dp = sav.GetDesign(i);
var name = dp.DesignName;
var fn = StringUtil.CleanFileName($"{name}.nhd");
var dest = Path.Combine(path, fn);
File.WriteAllBytes(dest, dp.Data);
}
}
}
}