using System; using System.Collections.Generic; using System.IO; using System.Linq; using EFT.UI; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace stupid.solutions.Utils; public class ItemPresetManager { public Dictionary itemParameters; public ItemPresetManager() { itemParameters = new Dictionary(); } public void SaveToJson(string filePath) { try { string text = (itemParameters.ContainsKey("ItemId") ? itemParameters["ItemId"].ToString() : ""); if (string.IsNullOrEmpty(text)) { ConsoleScreen.Log("Log: No main item ID found. Cannot save."); return; } Dictionary dictionary = new Dictionary(); foreach (string key in itemParameters.Keys) { if (itemParameters[key] is Dictionary dictionary2) { dictionary[key] = new Dictionary { { "SlotID", dictionary2["SlotID"] }, { "SlotName", dictionary2["SlotName"] }, { "ItemId", dictionary2["ItemId"] } }; } } string contents = JsonConvert.SerializeObject(new Dictionary { { text, new Dictionary { { "StackMaxSize", itemParameters.ContainsKey("StackMaxSize") ? itemParameters["StackMaxSize"] : ((object)1) }, { "QuestItem", itemParameters.ContainsKey("QuestItem") ? itemParameters["QuestItem"] : ((object)false) }, { "Slots", dictionary } } } }, Formatting.Indented); File.WriteAllText(filePath, contents); ConsoleScreen.Log("Log: Item preset saved successfully to " + filePath); } catch (Exception ex) { ConsoleScreen.Log("Log: Error saving preset: " + ex.Message); } } public Dictionary> LoadFromJson(string filePath, out string mainItemId) { mainItemId = null; try { if (!File.Exists(filePath)) { ConsoleScreen.Log("Log: JSON file not found at " + filePath); return null; } Dictionary dictionary = JsonConvert.DeserializeObject>(File.ReadAllText(filePath)); mainItemId = dictionary.Keys.FirstOrDefault(); if (string.IsNullOrEmpty(mainItemId)) { ConsoleScreen.Log("Log: No main item ID found in the JSON."); return null; } Dictionary dictionary2 = new Dictionary(); if (dictionary[mainItemId] is JObject jObject && jObject.TryGetValue("Slots", out JToken value) && value is JObject jObject2) { foreach (JProperty item in jObject2.Properties()) { if (item.Value is JObject jObject3) { string key = jObject3["SlotID"].ToString(); string value2 = jObject3["ItemId"].ToString(); dictionary2[key] = value2; } } } return new Dictionary> { { "Slots", dictionary2 } }; } catch (Exception ex) { ConsoleScreen.Log("Log: Error loading preset: " + ex.Message); return null; } } public void Clear() { itemParameters.Clear(); ConsoleScreen.Log("Log: Item parameters cleared."); } }