-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSAVFormat.cs
39 lines (37 loc) · 1.33 KB
/
SAVFormat.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace DeltaruneSaveConverter
{
class SAVFormat
{
public static void Extract(string SAVFile, string OutputDir)
{
string contents = File.ReadAllText(SAVFile);
contents = contents.Split('\0')[0]; // remove any null bytes
Dictionary<string, string> json = JsonSerializer.Deserialize<Dictionary<string, string>>(contents);
foreach (string file in json.Keys)
{
if (file == "default") continue;
File.WriteAllText($"{OutputDir}/{file}", json[file]);
}
}
public static void Pack(string SAVFile, string InputDir)
{
Dictionary<string, string> json = new();
json.Add("default", "");
foreach (string file in Directory.GetFiles(InputDir))
{
if (Path.GetFileName(file).ToLower() == "desktop.ini") return;
json.Add(Path.GetFileName(file), File.ReadAllText(file));
}
string serialized = JsonSerializer.Serialize(json);
serialized = serialized.Replace(@"\u0022", @"\""");
File.WriteAllText(SAVFile, serialized);
}
}
}