From 4e24e1101ca0effa9ac0e6e4cce0b02b19d1a9ae Mon Sep 17 00:00:00 2001 From: VDH Date: Wed, 18 Mar 2026 17:35:52 +0700 Subject: [PATCH] cheat --- .../Resources/DebugCmdHistory.json | 12 +++ .../Resources/DebugCmdHistory.json.meta | 7 ++ .../DebugCommandMenu/DebugCmdHistoryStore.cs | 99 +++++++++++++++---- .../Scripts/DebugCommandMenu/DlgConsole.cs | 1 + .../Editor/DebugCmdHistoryExporter.cs | 38 +++++++ .../Editor/DebugCmdHistoryExporter.cs.meta | 2 + 6 files changed, 138 insertions(+), 21 deletions(-) create mode 100644 Assets/PerfectWorld/Resources/DebugCmdHistory.json create mode 100644 Assets/PerfectWorld/Resources/DebugCmdHistory.json.meta create mode 100644 Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs create mode 100644 Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs.meta diff --git a/Assets/PerfectWorld/Resources/DebugCmdHistory.json b/Assets/PerfectWorld/Resources/DebugCmdHistory.json new file mode 100644 index 0000000000..eb2468996e --- /dev/null +++ b/Assets/PerfectWorld/Resources/DebugCmdHistory.json @@ -0,0 +1,12 @@ +{ + "items": [ + { + "header": 8903, + "param": 73125, + "hasParam": true, + "describe": "NoCooldown", + "lastUsedUtcTicks": 0 + } + ] +} + diff --git a/Assets/PerfectWorld/Resources/DebugCmdHistory.json.meta b/Assets/PerfectWorld/Resources/DebugCmdHistory.json.meta new file mode 100644 index 0000000000..930a44a9cf --- /dev/null +++ b/Assets/PerfectWorld/Resources/DebugCmdHistory.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: fc90bfe3efec4e14994c2393235e4877 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PerfectWorld/Scripts/DebugCommandMenu/DebugCmdHistoryStore.cs b/Assets/PerfectWorld/Scripts/DebugCommandMenu/DebugCmdHistoryStore.cs index 99cd8cf8fa..d9fae9c7df 100644 --- a/Assets/PerfectWorld/Scripts/DebugCommandMenu/DebugCmdHistoryStore.cs +++ b/Assets/PerfectWorld/Scripts/DebugCommandMenu/DebugCmdHistoryStore.cs @@ -6,7 +6,9 @@ namespace BrewMonster.Scripts { public static class DebugCmdHistoryStore { - private const string PlayerPrefsKey = "DebugCmdHistory_v1"; + private const string ResourcesJsonPathNoExt = "DebugCmdHistory"; + private const string PlayerPrefsJsonKey = "DebugCmdHistory_v1"; + private const string PlayerPrefsInitedKey = "DebugCmdHistory_inited_v1"; private const int MaxEntries = 200; [Serializable] @@ -29,31 +31,21 @@ namespace BrewMonster.Scripts public static List Load() { - string json = PlayerPrefs.GetString(PlayerPrefsKey, string.Empty); - if (string.IsNullOrWhiteSpace(json)) - return new List(); - - try + // First-run: seed from Resources into PlayerPrefs so runtime can modify via PlayerPrefs. + if (!IsInited()) { - var wrapper = JsonUtility.FromJson(json); - if (wrapper == null || wrapper.items == null) - return new List(); + var seed = LoadFromResources(); + SaveToPlayerPrefs(seed); + SetInited(); + return seed; + } - wrapper.items.RemoveAll(e => e == null); - return wrapper.items; - } - catch - { - return new List(); - } + return LoadFromPlayerPrefs(); } public static void Save(List entries) { - var wrapper = new EntryListWrapper { items = entries ?? new List() }; - string json = JsonUtility.ToJson(wrapper); - PlayerPrefs.SetString(PlayerPrefsKey, json); - PlayerPrefs.Save(); + SaveToPlayerPrefs(entries); } public static bool Upsert(List entries, int header, int param, bool hasParam, string describe) @@ -111,7 +103,8 @@ namespace BrewMonster.Scripts public static void Clear() { - PlayerPrefs.DeleteKey(PlayerPrefsKey); + PlayerPrefs.DeleteKey(PlayerPrefsJsonKey); + PlayerPrefs.DeleteKey(PlayerPrefsInitedKey); PlayerPrefs.Save(); } @@ -128,6 +121,70 @@ namespace BrewMonster.Scripts return true; } + private static List LoadFromResources() + { + try + { + var asset = Resources.Load(ResourcesJsonPathNoExt); + if (asset == null || string.IsNullOrWhiteSpace(asset.text)) + return new List(); + + var wrapper = JsonUtility.FromJson(asset.text); + if (wrapper == null || wrapper.items == null) + return new List(); + + wrapper.items.RemoveAll(e => e == null); + return wrapper.items; + } + catch + { + return new List(); + } + } + + private static List LoadFromPlayerPrefs() + { + string json = PlayerPrefs.GetString(PlayerPrefsJsonKey, string.Empty); + if (string.IsNullOrWhiteSpace(json)) + return new List(); + + try + { + var wrapper = JsonUtility.FromJson(json); + if (wrapper == null || wrapper.items == null) + return new List(); + + wrapper.items.RemoveAll(e => e == null); + return wrapper.items; + } + catch + { + return new List(); + } + } + + private static void SaveToPlayerPrefs(List entries) + { + try + { + var wrapper = new EntryListWrapper { items = entries ?? new List() }; + string json = JsonUtility.ToJson(wrapper); + PlayerPrefs.SetString(PlayerPrefsJsonKey, json); + PlayerPrefs.Save(); + } + catch (Exception ex) + { + Debug.LogWarning($"[DebugCmdHistoryStore] Save failed: {ex.Message}"); + } + } + + private static bool IsInited() => PlayerPrefs.GetInt(PlayerPrefsInitedKey, 0) == 1; + private static void SetInited() + { + PlayerPrefs.SetInt(PlayerPrefsInitedKey, 1); + PlayerPrefs.Save(); + } + private static int FindIndex(List entries, int header, int param, bool hasParam) { for (int i = 0; i < entries.Count; i++) diff --git a/Assets/PerfectWorld/Scripts/DebugCommandMenu/DlgConsole.cs b/Assets/PerfectWorld/Scripts/DebugCommandMenu/DlgConsole.cs index 57e9c33f77..d6cbcefac5 100644 --- a/Assets/PerfectWorld/Scripts/DebugCommandMenu/DlgConsole.cs +++ b/Assets/PerfectWorld/Scripts/DebugCommandMenu/DlgConsole.cs @@ -155,6 +155,7 @@ namespace BrewMonster.Scripts private void SendCmdDebug(int header, int param, bool hasParam) { + BMLogger.LogError($"[DlgConsole] Sending Debug Cmd: {(hasParam ? $"{header} {param}" : $"{header}")}"); if (hasParam) UnityGameSession.c2s_CmdDebug((ushort)header, param); else diff --git a/Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs b/Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs new file mode 100644 index 0000000000..0a5953e6ad --- /dev/null +++ b/Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace BrewMonster.Scripts.Editor +{ + public static class DebugCmdHistoryExporter + { + private const string OutputAssetPath = "Assets/PerfectWorld/Resources/DebugCmdHistory.json"; + + [MenuItem("Tools/DebugCmd/Export History (User -> Resources)")] + public static void ExportUserHistoryToResources() + { + var entries = DebugCmdHistoryStore.Load(); + var json = WrapToJson(entries); + + Directory.CreateDirectory(Path.GetDirectoryName(OutputAssetPath)); + File.WriteAllText(OutputAssetPath, json); + AssetDatabase.ImportAsset(OutputAssetPath); + Debug.Log($"[DebugCmdHistoryExporter] Exported {entries.Count} entries to {OutputAssetPath}"); + } + + private static string WrapToJson(List entries) + { + // Mirror EntryListWrapper shape: { "items": [...] } + var wrapper = new Wrapper { items = entries ?? new List() }; + return JsonUtility.ToJson(wrapper, true); + } + + [System.Serializable] + private class Wrapper + { + public List items; + } + } +} + diff --git a/Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs.meta b/Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs.meta new file mode 100644 index 0000000000..805c267ae0 --- /dev/null +++ b/Assets/PerfectWorld/Scripts/DebugCommandMenu/Editor/DebugCmdHistoryExporter.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 7e0f54d86164c2e4c86036e4aadacd04 \ No newline at end of file