98 lines
3.2 KiB
C#
Raw Normal View History

using AssortGenerator.Common.Helpers;
2022-01-04 16:10:00 +00:00
using DumpCleaner;
using QuestValidator.Common;
using QuestValidator.Common.Helpers;
using QuestValidator.Helpers;
using System.Text.Json;
var inputPath = DiskHelpers.CreateWorkingFolders();
InputFileHelper.SetInputFiles(inputPath);
var locationParser = new LocationParser("locations");
2022-01-04 16:10:00 +00:00
foreach (var path in InputFileHelper.GetInputFilePaths())
2022-01-04 16:10:00 +00:00
{
var filename = Path.GetFileNameWithoutExtension(path);
var names = DumpFiles.filenames.Find(x => filename.StartsWith(x.InputName));
2022-01-04 16:10:00 +00:00
if (names == null)
{
LoggingHelpers.LogToConsole($"No mapping found for file: {filename} Skipping", ConsoleColor.Yellow);
continue;
}
var rawJson = File.ReadAllText(path);
var dumpFile = JsonSerializer.Deserialize<Dump>(rawJson);
2022-01-04 16:10:00 +00:00
if (dumpFile.data == null)
{
LoggingHelpers.LogWarning($"file: {filename} had no data in it, skipping");
continue;
}
// Special case, Do special tasks with it
if (names.SpecialCase)
{
HandleSpecialCase(names, dumpFile, rawJson);
}
else
{
JsonWriter.WriteJson(dumpFile.data, names.OutputFolder, Directory.GetCurrentDirectory(), names.OutputName);
LoggingHelpers.LogToConsole($"Found file: {filename} wrote file to output folder");
}
}
locationParser.CreateLocationFile();
void HandleSpecialCase(DumpData names, Dump dumpFile, string rawJson)
{
if (names.InputName == "resp.client.location.getLocalloot")
{
locationParser.AddLocalLootDump(dumpFile, rawJson);
}
if (names.InputName == "resp.client.trading.api.traderSettings")
{
HandleTraderSettingsFile(names, dumpFile);
}
2022-01-04 16:10:00 +00:00
}
void HandleLocationsFile(DumpData names, Dump dumpFile)
{
var locationsRoot = JsonSerializer.Deserialize<Dictionary<string, object>>(dumpFile.data.ToString());
var locations = JsonSerializer.Deserialize<Dictionary<string, object>>(locationsRoot.First().Value.ToString());
foreach (var location in locations)
{
var locationData = JsonSerializer.Deserialize<Location>(location.Value.ToString());
2022-01-04 16:10:00 +00:00
var mapName = locationData.Id.ToLower();
if (mapName == "lighthouse2")
{
continue;
}
2022-01-04 16:10:00 +00:00
2023-01-02 12:22:48 +00:00
if (new string[] { "bigmap", "interchange", "lighthouse", "rezervbase", "shoreline", "woods", "tarkovstreets" }.Contains(mapName))
{
// TODO: add back airdrop chance
}
2023-01-02 12:22:48 +00:00
JsonWriter.WriteJson(location.Value.ToString(), $"{names.OutputFolder}/{locationData.Id.ToLower()}", Directory.GetCurrentDirectory(), "base");
LoggingHelpers.LogToConsole($"Found map file: {locationData.Id} wrote file to output folder");
}
}
2022-01-04 16:10:00 +00:00
void HandleTraderSettingsFile(DumpData names, Dump dumpFile)
{
var traders = JsonSerializer.Deserialize<List<object>>(dumpFile.data.ToString());
foreach (var trader in traders)
{
var traderData = JsonSerializer.Deserialize<Trader>(trader.ToString());
traderData.sell_category = TraderSellCategories.GetCategoriesByTraderId(traderData._id);
JsonWriter.WriteJson(traderData, $"{names.OutputFolder}/{traderData._id}", Directory.GetCurrentDirectory(), "base");
LoggingHelpers.LogToConsole($"Found trader file: {traderData._id} wrote file to output folder");
}
}