// MiniRemoteState.cs — What the Mini Remote's universal tabs remember per character: the Pets // tab (roster view, healing / cosmetic pets, the refill path) and the Quests tab (filter, // favorites, the favorites HUD), plus the VTank .usd importer's last file. // // Lives in \miniremote.json. These settings were part of the ILT Hub's // ilt-hub.json (SilentKelpie's ILT Hub, which RynthAi hosted until 2026-10-13). The ILT Hub went // to the RynthILT plugin; the universal tabs stayed. On the first load without miniremote.json // the Pets / Quests / import parts of ilt-hub.json are read (field names unchanged, so the old // file deserializes straight into these classes); ilt-hub.json itself is never written again (it // is RynthILT's to copy, IltMigration). Serialized with the source-generated RynthAiJsonContext // (IncludeFields = true), so plain public fields are used throughout. using System; using System.Collections.Generic; using System.IO; using System.Text.Json; namespace RynthCore.Plugin.RynthAi.MiniRemote; public sealed class MiniRemoteState { public int SchemaVersion = 1; public PetTabState Pet = new(); public QuestsTabState Quests = new(); /// The Crafting tab (tinker benches); the ILT Hub's Crafting before. public CraftingTabState Crafting = new(); /// Last VTank .usd file the importer read (the ILT Hub's Gear.LastUsdPath before). public string LastUsdPath = string.Empty; } /// The Crafting tab: one settings block per tinker bench, plus per-server custom salvage. public sealed class CraftingTabState { /// Bench settings keyed by the bench name (TinkerBench: Armor, Melee, Missile, Caster, Jewelry, Items, Trinkets). public Dictionary Benches = new(); /// The player's extra salvage rows, keyed by world name (custom shards' own recipes). public Dictionary> CustomByWorld = new(); /// Answer the server's craft-chance dialog for the runner (engine API v85). public bool AnswerCraftDialog = true; /// Items per scan (UB-IT's 20). public int BatchSize = 20; /// Apply even in combat mode (servers with allow_combat_mode_crafting). public bool AllowInCombat; /// When a batch finishes, scan the next one (items finished this session are left out). public bool AutoNextBatch; /// ...and start it without asking again. public bool AutoStartNextBatch; /// Prepared salvage tier: 0 Minor, 1 Moderate, 2 Major (TinkerCatalog.TrinketTiers). public int TrinketTier; /// Prepare a raw bag on the tier's Ammunition when no prepared bag is carried. public bool TrinketPrep; /// Kits sub-tab ("Make kits"): never try a combine whose chance is under this percent (0 = any). public int KitMinChancePercent = Crafting.KitPlanner.DefaultFloorPercent; /// Kits sub-tab: how many kits one run makes (0 = as many as the pack makes). public int KitMakeCount; // "RingRuns" (the Rings chain, now left to RynthILT) may still be in older files: it is ignored. } /// One tinker bench's choices. public sealed class TinkerBenchSettings { /// Row key (TinkerCatalog.Key: r/p/c + material id) to how many times (imbues and flags: 0 or 1). public Dictionary Counts = new(); /// Skip a step whose chance is under this percent (0 = any chance). public int MinChancePercent; /// Only items with at most this many tinks. public int MaxTinks = 9; /// Only items with at least this many free tink slots (0 = no filter). public int MinFreeTinks; public bool SkipImbued; /// Slash/pierce weapons take the pierce rend (Black Garnet) instead of slash (Imperial Topaz). public bool PierceForCombo; /// The damage-type rend goes after every other step (UB-IT's "Foolproof rend last"). public bool RendLast; } /// A salvage row the player added for one server. public sealed class CustomTinker { /// TinkerBench as an int. public int Bench; /// MaterialType of the salvage. public int Material; public bool Imbue; /// Once per item (a flag-style recipe) rather than a repeatable tink. public bool Once; public bool UsesTinkSlot = true; /// The bag's name must contain this (bags that share another salvage's material id). public string NameMatch = string.Empty; public string Note = string.Empty; } /// The Pets tab's settings (the ILT Hub's IltPetState, without the ILT /pets and /shinies logs). public sealed class PetTabState { // Healing-pet automation (UB "HealingBuddy" subset). public bool HealingEnabled; /// Exact name of the heal-pet essence to use; empty = auto-detect (Healing Buddy / Dule box). public string HealPetName = string.Empty; public int HealthThresholdPercent = 80; /// Do not summon when current HP is below this (summoning mid-death wastes the use). 0 = off. public int MinHealthPoints = 100; public bool AutoDespawnAfterHeal = true; public int RespawnDelaySeconds = 2; public int PetTimeoutSeconds = 30; /// /// Obsolete since 2026-10-20 (unused here, kept so miniremote.json still loads): the "summon from /// empty essences" opt-in of ACECustom's refill charm. It is RynthILT's now, which copied this /// value once (IltMigration.ImportRynthAiSettings). /// public bool UsePyrealRefillPath; /// Roster type shown in the Pet tab (PetKind: 0 Combat, 1 Healing, 2 Cosmetic). public int RosterKind; /// Roster sort (PetSort: 0 Priority, 1 Bond, 2 Potency, 3 Breed ready, 4 Level, 5 Uses, 6 Name). public int RosterSort; /// User type overrides by essence name; essences not listed are auto-classified. public List Assignments = new(); /// Essence name of the chosen cosmetic (display) pet; empty = none. public string CosmeticPetName = string.Empty; /// Keep the cosmetic pet summoned while in peace mode; it is dismissed when a combat pet is needed. public bool KeepCosmeticOut; /// Seconds to wait before re-summoning the cosmetic pet after it despawns. public int CosmeticRespawnSeconds = 15; // Obsolete since 2026-10-20, as UsePyrealRefillPath: ACECustom's siphon auto-capture moved to // RynthILT (IltPetAutomation), which copied these once. Unused here; kept so old files load. /// Obsolete: auto-capture's switch (RynthILT's now). public bool AutoCaptureEnabled; /// Obsolete: auto-capture's lens (RynthILT's now). public int CaptureLensIndex; } /// A user's choice of summon type for one essence (matched by name, case-insensitive). public sealed class PetAssignment { public string Name = string.Empty; /// PetKind as int (0 Combat, 1 Healing, 2 Cosmetic). public int Kind; } /// /// The retired Quests tab's settings (the quest fields of the ILT Hub's IltCharacterState). The tab /// moved to RynthOracle on 2026-10-13 (tracking and rewards live in its per-character quest book); /// the fields stay so existing miniremote.json files load and keep what they recorded. /// public sealed class QuestsTabState { /// Quest Tracker search box contents. public string QuestFilter = string.Empty; /// Starred quest flag keys (lowercase), shown on the floating favorites HUD. public List QuestFavorites = new(); /// Quest tracker lists starred quests only. public bool QuestFavoritesOnly; /// Floating quest favorites HUD is shown. public bool ShowQuestFavoritesHud; public bool QuestFavoritesHudLocked; } /// The parts of an old ilt-hub.json the universal tabs take over (first load only). public sealed class LegacyHubFile { public PetTabState? Pet; /// The ILT Hub's IltCharacterState: its quest fields have QuestsTabState's names. public QuestsTabState? Character; public LegacyHubGear? Gear; /// The ILT Hub's Crafting tab (build-comp-10-11 hosted it in RynthAi): same field names. public CraftingTabState? Crafting; } public sealed class LegacyHubGear { public string? LastUsdPath; } /// Loads and saves (dirty-checked like the ILT Hub's store was). internal sealed class MiniRemoteStore { public const string FileName = "miniremote.json"; public const string LegacyFileName = "ilt-hub.json"; private readonly string _charFolder; private string _lastJson = string.Empty; public MiniRemoteStore(string charFolder) => _charFolder = charFolder ?? string.Empty; private string StatePath => Path.Combine(_charFolder, FileName); /// The saved state; on the first load the universal parts of ilt-hub.json; else defaults. public MiniRemoteState Load() { try { if (_charFolder.Length > 0 && File.Exists(StatePath)) { string json = File.ReadAllText(StatePath); var s = JsonSerializer.Deserialize(json, RynthAiJsonContext.Default.MiniRemoteState); if (s != null) { Normalize(s); _lastJson = json; return s; } } string legacy = Path.Combine(_charFolder, LegacyFileName); if (_charFolder.Length > 0 && File.Exists(legacy)) { var old = JsonSerializer.Deserialize(File.ReadAllText(legacy), RynthAiJsonContext.Default.LegacyHubFile); if (old != null) { var s = FromLegacy(old); RynthLog.Write(LogCat.General, $"[MiniRemote] Pets / Quests tab settings read from {LegacyFileName} (the ILT Hub went to RynthILT; saved in {FileName} from now on)."); return s; // _lastJson stays empty: the first save writes miniremote.json } } } catch (Exception ex) { RynthLog.Exception(LogCat.General, ex, $"[MiniRemote] load {StatePath}"); } return new MiniRemoteState(); } /// The universal parts of an old ilt-hub.json as a fresh state. internal static MiniRemoteState FromLegacy(LegacyHubFile old) { var s = new MiniRemoteState { Pet = old.Pet ?? new PetTabState(), Quests = old.Character ?? new QuestsTabState(), Crafting = old.Crafting ?? new CraftingTabState(), LastUsdPath = old.Gear?.LastUsdPath ?? string.Empty, }; Normalize(s); return s; } /// Writes the state only when its JSON differs from the last write. public void SaveIfDirty(MiniRemoteState state) { if (_charFolder.Length == 0) return; try { string json = JsonSerializer.Serialize(state, RynthAiJsonContext.Default.MiniRemoteState); if (json == _lastJson) return; Directory.CreateDirectory(_charFolder); string tmp = StatePath + ".tmp"; File.WriteAllText(tmp, json); File.Move(tmp, StatePath, overwrite: true); _lastJson = json; } catch (Exception ex) { RynthLog.Exception(LogCat.General, ex, $"[MiniRemote] save {StatePath}"); } } /// Repairs null collections / out-of-range values after deserialization. internal static void Normalize(MiniRemoteState s) { s.Pet ??= new PetTabState(); s.Pet.Assignments ??= new(); s.Pet.Assignments.RemoveAll(a => a == null || string.IsNullOrWhiteSpace(a.Name)); s.Pet.HealPetName ??= string.Empty; s.Pet.CosmeticPetName ??= string.Empty; s.Pet.RosterKind = Math.Clamp(s.Pet.RosterKind, 0, 2); s.Pet.RosterSort = Math.Clamp(s.Pet.RosterSort, 0, 6); s.Pet.CosmeticRespawnSeconds = Math.Clamp(s.Pet.CosmeticRespawnSeconds, 5, 600); s.Quests ??= new QuestsTabState(); s.Quests.QuestFilter ??= string.Empty; s.Quests.QuestFavorites ??= new(); s.Quests.QuestFavorites.RemoveAll(string.IsNullOrWhiteSpace); s.Crafting ??= new CraftingTabState(); s.Crafting.Benches ??= new(); s.Crafting.CustomByWorld ??= new(); s.Crafting.BatchSize = Math.Clamp(s.Crafting.BatchSize, 1, 200); s.Crafting.TrinketTier = Math.Clamp(s.Crafting.TrinketTier, 0, 2); s.LastUsdPath ??= string.Empty; } }