diff --git a/DumpCleaner/DumpFiles.cs b/DumpCleaner/DumpFiles.cs index 01b9d05..44a2920 100644 --- a/DumpCleaner/DumpFiles.cs +++ b/DumpCleaner/DumpFiles.cs @@ -42,6 +42,8 @@ namespace DumpCleaner new DumpData{InputName = "resp.client.locations", OutputName = "locations", OutputFolder = "locations", SpecialCase = true}, + new DumpData{InputName = "resp.client.location.getLocalloot", OutputName = "locations", OutputFolder = "locations", SpecialCase = true}, + new DumpData{InputName = "resp.client.trading.api.traderSettings", OutputName = "traders", OutputFolder = "traders", SpecialCase = true}, new DumpData{InputName= "usec.resp.client.trading.customization", OutputName= "usecsuits", OutputFolder = "traders/5ac3b934156ae10c4430e83c"}, diff --git a/DumpCleaner/LocationParser.cs b/DumpCleaner/LocationParser.cs new file mode 100644 index 0000000..6363d21 --- /dev/null +++ b/DumpCleaner/LocationParser.cs @@ -0,0 +1,47 @@ +using DumpCleaner; +using QuestValidator.Common; +using QuestValidator.Common.Helpers; +using System.Text.Json; + +public class LocationParser +{ + private readonly Dictionary locations = new(); + private readonly string outputPath; + + public LocationParser(string outputPath) + { + this.outputPath = outputPath; + } + + internal void AddLocalLootDump(Dump dumpFile) + { + var locationData = JsonSerializer.Deserialize(dumpFile.data.ToString()); + var locationName = locationData.Id; + + // already parsed, skip + if (locations.ContainsKey(locationName)) + { + return; + } + + // remove loot as not needed for base.json + locationData.Loot?.Clear(); + + locations.Add(locationName, locationData); + } + + internal void CreateLocationFile() + { + foreach (var location in locations) + { + + if (string.Equals(location.Value.Id, "lighthouse2", StringComparison.CurrentCultureIgnoreCase)) + { + continue; + } + + JsonWriter.WriteJson(location.Value, $"{outputPath}/{location.Value.Id.ToLower()}", Directory.GetCurrentDirectory(), "base"); + LoggingHelpers.LogToConsole($"Found map file: {location.Value.Id} wrote file to output folder"); + } + } +} \ No newline at end of file diff --git a/DumpCleaner/Program.cs b/DumpCleaner/Program.cs index e59abbd..b6caf18 100644 --- a/DumpCleaner/Program.cs +++ b/DumpCleaner/Program.cs @@ -7,11 +7,12 @@ using System.Text.Json; var inputPath = DiskHelpers.CreateWorkingFolders(); InputFileHelper.SetInputFiles(inputPath); +var locationParser = new LocationParser("locations"); foreach (var path in InputFileHelper.GetInputFilePaths()) { var filename = Path.GetFileNameWithoutExtension(path); - var names = DumpFiles.filenames.FirstOrDefault(x => filename.StartsWith(x.InputName)); + var names = DumpFiles.filenames.Find(x => filename.StartsWith(x.InputName)); if (names == null) { @@ -19,8 +20,8 @@ foreach (var path in InputFileHelper.GetInputFilePaths()) continue; } - var questDataJson = File.ReadAllText(path); - var dumpFile = JsonSerializer.Deserialize(questDataJson); + var rawJson = File.ReadAllText(path); + var dumpFile = JsonSerializer.Deserialize(rawJson); if (dumpFile.data == null) { @@ -40,11 +41,14 @@ foreach (var path in InputFileHelper.GetInputFilePaths()) } } +locationParser.CreateLocationFile(); + + void HandleSpecialCase(DumpData names, Dump dumpFile) { - if (names.InputName == "resp.client.locations") + if (names.InputName == "resp.client.location.getLocalloot") { - HandleLocationsFile(names, dumpFile); + locationParser.AddLocalLootDump(dumpFile); } if (names.InputName == "resp.client.trading.api.traderSettings")