From 824a63f4c726cd281949ba3c9cc22117eb64aa6d Mon Sep 17 00:00:00 2001 From: HungDK <> Date: Sat, 10 Jan 2026 09:48:04 +0700 Subject: [PATCH] Fix wrong asset source read --- .../Scripts/Managers/EC_IvtrEquip.cs | 125 +++++++++++------- 1 file changed, 75 insertions(+), 50 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/Managers/EC_IvtrEquip.cs b/Assets/PerfectWorld/Scripts/Managers/EC_IvtrEquip.cs index b834389bf0..95ae58a93d 100644 --- a/Assets/PerfectWorld/Scripts/Managers/EC_IvtrEquip.cs +++ b/Assets/PerfectWorld/Scripts/Managers/EC_IvtrEquip.cs @@ -13,6 +13,7 @@ using System.Text.RegularExpressions; using System.Reflection; using BrewMonster.Scripts.Managers; using BrewMonster.Scripts; +using UnityEngine.AddressableAssets; namespace PerfectWorld.Scripts.Managers { @@ -1132,71 +1133,95 @@ namespace PerfectWorld.Scripts.Managers try { - // Parse configs/item_ext_prop.txt to learn valid property type ids - string path = Path.Combine(UnityEngine.Application.streamingAssetsPath, "configs/item_ext_prop.txt"); - if (File.Exists(path)) + // Load item_ext_prop.txt from Addressables + // Address must match the Addressables "Address" configured in Assets/AddressableAssetsData/... + const string address = "Assets/Addressable/item_ext_prop.txt"; + + // Initialize Addressables if not already initialized + Addressables.InitializeAsync().WaitForCompletion(); + + // Load the TextAsset synchronously (since GetPropertyType is called synchronously) + var textAsset = Addressables.LoadAssetAsync(address).WaitForCompletion(); + + if (textAsset != null && !string.IsNullOrEmpty(textAsset.text)) { + // Parse the text content int currentType = -1; bool inTypeBlock = false; bool inBlockComment = false; - foreach (var rawLine in File.ReadLines(path)) + + using (var reader = new StringReader(textAsset.text)) { - string src = rawLine; - if (string.IsNullOrEmpty(src)) continue; - - // strip block comments /* ... */ possibly spanning lines - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - int i = 0; - while (i < src.Length) + string rawLine; + while ((rawLine = reader.ReadLine()) != null) { - if (inBlockComment) - { - int end = src.IndexOf("*/", i, StringComparison.Ordinal); - if (end < 0) { i = src.Length; break; } - inBlockComment = false; i = end + 2; continue; - } - int start = src.IndexOf("/*", i, StringComparison.Ordinal); - if (start < 0) - { - sb.Append(src, i, src.Length - i); - break; - } - sb.Append(src, i, start - i); - int end2 = src.IndexOf("*/", start + 2, StringComparison.Ordinal); - if (end2 < 0) { inBlockComment = true; break; } - i = end2 + 2; - } - string line = sb.ToString().Trim(); - if (line.Length == 0) continue; - if (line.StartsWith("//")) continue; + string src = rawLine; + if (string.IsNullOrEmpty(src)) continue; - // Detect a new type section: e.g., "type: 45" - var typeMatch = Regex.Match(line, "^type:\\s*(?\\d+)"); - if (typeMatch.Success) - { - if (int.TryParse(typeMatch.Groups["type"].Value, out int t)) currentType = t; - inTypeBlock = line.Contains("{"); - if (line.Contains("}")) { inTypeBlock = false; currentType = -1; } - continue; - } - - if (line.Contains("{")) inTypeBlock = true; - if (line.Contains("}")) { inTypeBlock = false; currentType = -1; } - - if (inTypeBlock && currentType >= 0) - { - foreach (Match m in Regex.Matches(line, "\\b(?\\d{1,6})\\b")) + // strip block comments /* ... */ possibly spanning lines + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + int i = 0; + while (i < src.Length) { - if (int.TryParse(m.Groups["id"].Value, out int id)) + if (inBlockComment) { - if (!s_propIdToType.ContainsKey(id)) s_propIdToType[id] = (byte)Mathf.Clamp(currentType, 0, 255); + int end = src.IndexOf("*/", i, StringComparison.Ordinal); + if (end < 0) { i = src.Length; break; } + inBlockComment = false; i = end + 2; continue; + } + int start = src.IndexOf("/*", i, StringComparison.Ordinal); + if (start < 0) + { + sb.Append(src, i, src.Length - i); + break; + } + sb.Append(src, i, start - i); + int end2 = src.IndexOf("*/", start + 2, StringComparison.Ordinal); + if (end2 < 0) { inBlockComment = true; break; } + i = end2 + 2; + } + string line = sb.ToString().Trim(); + if (line.Length == 0) continue; + if (line.StartsWith("//")) continue; + + // Detect a new type section: e.g., "type: 45" + var typeMatch = Regex.Match(line, "^type:\\s*(?\\d+)"); + if (typeMatch.Success) + { + if (int.TryParse(typeMatch.Groups["type"].Value, out int t)) currentType = t; + inTypeBlock = line.Contains("{"); + if (line.Contains("}")) { inTypeBlock = false; currentType = -1; } + continue; + } + + if (line.Contains("{")) inTypeBlock = true; + if (line.Contains("}")) { inTypeBlock = false; currentType = -1; } + + if (inTypeBlock && currentType >= 0) + { + foreach (Match m in Regex.Matches(line, "\\b(?\\d{1,6})\\b")) + { + if (int.TryParse(m.Groups["id"].Value, out int id)) + { + if (!s_propIdToType.ContainsKey(id)) s_propIdToType[id] = (byte)Mathf.Clamp(currentType, 0, 255); + } } } } } + + Debug.Log($"[EC_IvtrEquip] Loaded {s_propIdToType.Count} property mappings from Addressables"); + } + else + { + Debug.LogWarning($"[EC_IvtrEquip] Failed to load item_ext_prop.txt from Addressables (address: {address})"); } } - catch { /* ignore parse errors; fallback below will handle */ } + catch (Exception ex) + { + Debug.LogError($"[EC_IvtrEquip] Exception loading item_ext_prop.txt from Addressables: {ex.Message}"); + // ignore parse errors; fallback below will handle unknown properties + } s_propMapLoaded = true; }