From f0c422aa8fa9f2ea619580963d142cca48fe2016 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Wed, 3 Jun 2026 09:11:13 -0400 Subject: [PATCH] feat(loader): file-backed per-instance identity store --- SVSimLoader/InstanceIdentityStore.cs | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 SVSimLoader/InstanceIdentityStore.cs diff --git a/SVSimLoader/InstanceIdentityStore.cs b/SVSimLoader/InstanceIdentityStore.cs new file mode 100644 index 0000000..219fa9c --- /dev/null +++ b/SVSimLoader/InstanceIdentityStore.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.IO; + +namespace SVSimLoader +{ + /// + /// File-backed store for the three account-identity PlayerPrefs keys (UDID, VIEWER_ID, + /// SHORT_UDID), so a second client instance on the same machine gets its own identity + /// instead of sharing the per-Windows-user registry store. Only these three keys are + /// redirected; everything else (RES_VER, language, asset cache) stays in the shared store. + /// Persisted as dependency-free key=value lines — the values are a GUID and two integers, + /// which never contain '=' or newlines. + /// + public static class InstanceIdentityStore + { + public static readonly string[] Keys = { "UDID", "VIEWER_ID", "SHORT_UDID" }; + + private static string _path; + private static readonly Dictionary _values = new Dictionary(); + + public static void Initialize(string path) + { + _path = path; + _values.Clear(); + if (!File.Exists(_path)) return; + foreach (var line in File.ReadAllLines(_path)) + { + int eq = line.IndexOf('='); + if (eq <= 0) continue; + string key = line.Substring(0, eq); + string val = line.Substring(eq + 1); + if (System.Array.IndexOf(Keys, key) >= 0) _values[key] = val; + } + } + + public static bool TryGet(string key, out string value) => _values.TryGetValue(key, out value); + + public static void Set(string key, string value) + { + _values[key] = value; + Save(); + } + + private static void Save() + { + var lines = new List(); + foreach (var kv in _values) lines.Add(kv.Key + "=" + kv.Value); + File.WriteAllLines(_path, lines.ToArray()); + } + } +}