Skip to content

Commit 9b59f06

Browse files
committed
IconCache
1 parent 0b7d2b1 commit 9b59f06

File tree

4 files changed

+54
-48
lines changed

4 files changed

+54
-48
lines changed

Diff for: kg_LastEpoch_Improvements.sln.DotSettings.user

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ALootFilterUI_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FKilling_0020God_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F960c6514eb514391852fc8fede18aa04228f000_003Fc5_003Fad013d5c_003FLootFilterUI_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
322322
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AMelonPreferences_005FCategory_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FKilling_0020God_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fa8f6c33fa12646d38264c39c3694d5f3c0e00_003F45_003F9e306759_003FMelonPreferences_005FCategory_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
323323
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARuleUI_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FUsers_003FKilling_0020God_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F960c6514eb514391852fc8fede18aa04228f000_003Fd4_003Fdd1eb0f5_003FRuleUI_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
324-
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">ERROR</s:String>
324+
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/ActualSeverity/@EntryValue">INFO</s:String>
325325
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/FiltersState/=CodeStyle/@EntryIndexedValue">Off</s:String>
326326
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/FiltersState/=NamingFilter/@EntryIndexedValue">Off</s:String>
327327
<s:String x:Key="/Default/CodeInspection/PencilsConfiguration/FiltersState/=SpellingFilter/@EntryIndexedValue">Off</s:String>

Diff for: kg_LastEpoch_Improvements/CustomDropSounds.cs

+33-20
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace kg_LastEpoch_Improvements;
1010

1111
public static class CustomDropSounds
1212
{
13-
public static string CustomSoundMapperPath = Path.Combine(MelonEnvironment.UserDataDirectory, "CustomDropSounds", "CustomSoundMapper.json");
14-
public static Dictionary<string, string> RuleToSound = [];
15-
public static Dictionary<string, AudioSource> Sounds = [];
13+
private static readonly string CustomSoundMapperPath = Path.Combine(MelonEnvironment.UserDataDirectory, "CustomDropSounds", "CustomSoundMapper.json");
14+
private static Dictionary<string, string> RuleToSound = [];
15+
private static readonly Dictionary<string, AudioSource> Sounds = [];
1616
private static AudioSource CreateAudioSource(AudioClip clip)
1717
{
1818
GameObject audioSource = new GameObject("kg_AudioSource") { hideFlags = HideFlags.HideAndDontSave };
@@ -66,8 +66,8 @@ private static IEnumerator LoadCustomDropSounds(string path)
6666
}
6767
public static bool TryPlaySoundDelayed(string name, float delay, float volume)
6868
{
69-
if (Sounds.Count == 0 || !Sounds.ContainsKey(name)) return false;
70-
MelonCoroutines.Start(DelaySound(Sounds[name], delay, volume));
69+
if (Sounds.Count == 0 || !Sounds.TryGetValue(name, out var sound)) return false;
70+
MelonCoroutines.Start(DelaySound(sound, delay, volume));
7171
return true;
7272
}
7373
private static IEnumerator DelaySound(AudioSource source, float delay, float volume)
@@ -76,16 +76,23 @@ private static IEnumerator DelaySound(AudioSource source, float delay, float vol
7676
source.PlayOneShot(source.clip, volume);
7777
}
7878
public static void Load()
79-
{
79+
{
80+
fastJSON.JSON.Parameters = new fastJSON.JSONParameters
81+
{
82+
UseExtensions = false,
83+
SerializeNullValues = false,
84+
UseOptimizedDatasetSchema = true,
85+
UseValuesOfEnums = true,
86+
};
8087
LoadSoundsSync();
81-
if (File.Exists(CustomDropSounds.CustomSoundMapperPath))
88+
if (File.Exists(CustomSoundMapperPath))
8289
{
8390
try
8491
{
85-
string json = File.ReadAllText(CustomDropSounds.CustomSoundMapperPath);
86-
CustomDropSounds.RuleToSound = fastJSON.JSON.ToObject<Dictionary<string, string>>(json);
92+
string json = File.ReadAllText(CustomSoundMapperPath);
93+
RuleToSound = fastJSON.JSON.ToObject<Dictionary<string, string>>(json);
8794
}
88-
catch (Exception) { CustomDropSounds.RuleToSound = []; }
95+
catch (Exception) { RuleToSound = []; }
8996
}
9097
}
9198
[HarmonyPatch(typeof(RuleUI),nameof(RuleUI.Awake))]
@@ -98,19 +105,19 @@ private static void Postfix(RuleUI __instance)
98105
if (Utils.CopyFrom_Dropdown)
99106
{
100107
Transform targetParent = __instance.transform.Find("Content/LeftRulePanel");
101-
GameObject copyFromDropdown = UnityEngine.Object.Instantiate(Utils.CopyFrom_Dropdown, targetParent);
108+
GameObject copyFromDropdown = Object.Instantiate(Utils.CopyFrom_Dropdown, targetParent);
102109
copyFromDropdown.name = "CopyFromDropdown";
103110
copyFromDropdown.transform.SetAsLastSibling();
104-
UnityEngine.Object.DestroyImmediate(copyFromDropdown.transform.GetChild(2).gameObject);
105-
UnityEngine.Object.DestroyImmediate(copyFromDropdown.transform.GetChild(0).gameObject);
111+
Object.DestroyImmediate(copyFromDropdown.transform.GetChild(2).gameObject);
112+
Object.DestroyImmediate(copyFromDropdown.transform.GetChild(0).gameObject);
106113
ColoredIconDropdown dropdown = copyFromDropdown.transform.GetChild(1).GetComponent<ColoredIconDropdown>();
107114
dropdown.onValueChanged.RemoveAllListeners();
108115
dropdown.ClearOptions();
109116

110117
RectTransform rect = copyFromDropdown.GetComponent<RectTransform>();
111118
rect.anchorMin = new Vector2(0, 0);
112119
rect.anchorMax = new Vector2(0, 0);
113-
rect.pivot = new Vector2(0, 0);
120+
rect.pivot = new Vector2(0, 0);
114121
rect.anchoredPosition = new Vector2(10f, -80f);
115122
rect.GetComponent<VerticalLayoutGroup>().spacing = -10f;
116123
copyFromDropdown.transform.GetChild(0).GetComponent<TMP_Text>().fontSize = 16;
@@ -134,16 +141,21 @@ private static void Postfix(RuleUI __instance)
134141
[HarmonyPatch(typeof(RuleUI),nameof(RuleUI.Init))]
135142
private static class RuleUI_Init_Patch
136143
{
137-
private static void Postfix(LootFilterUI __instance, Rule rule, RuleUI.PanelMode mode)
144+
private static void Postfix(Rule rule)
138145
{
139146
if (rule == null) return;
140147
if (!RuleUI_Awake_Patch.Dropdown.Value) return;
148+
if (Sounds.Count == 0)
149+
{
150+
RuleUI_Awake_Patch.Dropdown.Key.SetActive(false);
151+
return;
152+
}
153+
RuleUI_Awake_Patch.Dropdown.Key.SetActive(true);
141154
ColoredIconDropdown dropdown = RuleUI_Awake_Patch.Dropdown.Value;
142155
if (RuleHasCustomSound(rule, out string sName))
143156
{
144157
int index = RuleUI_Awake_Patch.LastOrdered.IndexOf(sName);
145-
if (index != -1) dropdown.value = index;
146-
else dropdown.value = 0;
158+
dropdown.value = index != -1 ? index : 0;
147159
}
148160
else dropdown.value = 0;
149161
}
@@ -156,15 +168,16 @@ private static void Prefix(RuleUI __instance)
156168
if (__instance.rule == null || !RuleUI_Awake_Patch.Dropdown.Value) return;
157169
string ruleName = __instance.rule.nameOverride.Trim();
158170
if (string.IsNullOrWhiteSpace(ruleName)) return;
171+
int index = RuleUI_Awake_Patch.Dropdown.Value.value;
172+
if (index < 0 || index >= RuleUI_Awake_Patch.LastOrdered.Count) return;
159173
if (RuleUI_Awake_Patch.Dropdown.Value.value == 0)
160174
{
161175
if (RuleToSound.ContainsKey(ruleName)) RuleToSound.Remove(ruleName);
162176
}
163177
else
164178
{
165-
string soundName = RuleUI_Awake_Patch.LastOrdered[RuleUI_Awake_Patch.Dropdown.Value.value];
166-
if (RuleToSound.ContainsKey(ruleName)) RuleToSound[ruleName] = soundName;
167-
else RuleToSound.Add(ruleName, soundName);
179+
string soundName = RuleUI_Awake_Patch.LastOrdered[index];
180+
RuleToSound[ruleName] = soundName;
168181
}
169182
string json = fastJSON.JSON.ToNiceJSON(RuleToSound);
170183
try

Diff for: kg_LastEpoch_Improvements/Utils.cs

+1
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,5 @@ public static void CreateNewOption_EnumDropdown<T>(this SettingsPanelTabNavigabl
9595
dropdown.value = (int)(object)option.Value;
9696
dropdown.onValueChanged.AddListener(new Action<int>(_ => a(dropdown.value)));
9797
}
98+
public static int CharToIntFast(this char c) => c - '0';
9899
}

Diff for: kg_LastEpoch_Improvements/kg_LastEpoch_Improvements.cs

+19-27
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
#define FOGCAMERAVERSION
1+
//#define FOGCAMERAVERSION
22
using Il2CppDMM;
3-
using Il2CppInterop.Common;
43
using Il2CppInterop.Runtime.Injection;
54
using Il2CppItemFiltering;
6-
using Il2CppLE.Telemetry;
7-
using Il2CppLE.UI;
8-
using Il2CppSystem.Net;
9-
using Il2CppTMPro;
105
using MelonLoader;
11-
using MelonLoader.Utils;
12-
using UnityEngine.Networking;
136
using Object = UnityEngine.Object;
147

158
[assembly: MelonInfo(typeof(kg_LastEpoch_Improvements.kg_LastEpoch_Improvements), "kg.LastEpoch.Improvements", "1.3.7", "KG", "https://www.nexusmods.com/lastepoch/mods/8")]
@@ -18,7 +11,6 @@ namespace kg_LastEpoch_Improvements;
1811

1912
public class kg_LastEpoch_Improvements : MelonMod
2013
{
21-
private static kg_LastEpoch_Improvements _thistype;
2214
private static MelonPreferences_Category ImprovementsModCategory;
2315
private static MelonPreferences_Entry<bool> ShowAll;
2416
private static MelonPreferences_Entry<DisplayAffixType> AffixShowRoll;
@@ -64,11 +56,10 @@ private void CreateCustomMapIcon()
6456

6557
public override void OnInitializeMelon()
6658
{
67-
_thistype = this;
6859
ImprovementsModCategory = MelonPreferences.CreateCategory("kg_Improvements");
6960
ShowAll = ImprovementsModCategory.CreateEntry("Show Override", false, "Show Override", "Show each filter rule on map");
70-
AffixShowRoll = ImprovementsModCategory.CreateEntry("Show Affix Roll New", DisplayAffixType.None, "Show Affix Roll New", "Show each affix roll on item");
71-
ShowAffixOnLabel = ImprovementsModCategory.CreateEntry("Show Affix On Label", DisplayAffixType_GroundLabel.None, "Show Affix On Label Type", "Show each affix roll on item label (ground)");
61+
AffixShowRoll = ImprovementsModCategory.CreateEntry("Item Tooltip Style", DisplayAffixType.New_Style, "Show Affix Roll New", "Show each affix roll on item");
62+
ShowAffixOnLabel = ImprovementsModCategory.CreateEntry("Item Ground Label Style", DisplayAffixType_GroundLabel.With_Tier_Filter_Only, "Show Affix On Label Type", "Show each affix roll on item label (ground)");
7263
AutoStoreCraftMaterials = ImprovementsModCategory.CreateEntry("AutoStoreCraftMaterials", false, "Auto storage craft materials", "Automatic storage of craft materials from the inventory");
7364
#if FOGCAMERAVERSION
7465
FogOfWar = ImprovementsModCategory.CreateEntry("Fog of war", false, "Clear fog on map on start", "Clear fog of war when you 1th enter on map");
@@ -105,7 +96,7 @@ private static void Postfix(ItemDataUnpacked item, ItemAffix affix, ref string _
10596
_ => __result
10697
};
10798
}
108-
}
99+
}
109100

110101
[HarmonyPatch(typeof(TooltipItemManager), nameof(TooltipItemManager.UniqueBasicModFormatter))]
111102
private static class TooltipItemManager_FormatUniqueModAffixString_Patch
@@ -126,7 +117,7 @@ private static void Postfix(ItemDataUnpacked item, ref string __result, int uniq
126117
[HarmonyPatch(typeof(TooltipItemManager),nameof(TooltipItemManager.ImplicitFormatter))]
127118
private static class TooltipItemManager_FormatMod_Patch
128119
{
129-
private static void Postfix(ItemDataUnpacked item, int implicitNumber, ref string __result, bool isComparsionItem)
120+
private static void Postfix(ItemDataUnpacked item, int implicitNumber, ref string __result)
130121
{
131122
if (item == null || AffixShowRoll.Value is DisplayAffixType.None || item.isSet()) return;
132123
__result = AffixShowRoll.Value switch
@@ -150,19 +141,18 @@ private static void Postfix(Rule __instance, ItemDataUnpacked data, ref bool __r
150141
if (string.IsNullOrWhiteSpace(ruleNameToLower)) return;
151142
int indexOf = ruleNameToLower.IndexOf("lpmin:", StringComparison.Ordinal);
152143
if (indexOf == -1) return;
153-
char number = ruleNameToLower[indexOf + 6];
154-
if (int.TryParse(number.ToString(), out int lpmin)) __result &= data.legendaryPotential >= lpmin;
144+
__result &= data.legendaryPotential >= ruleNameToLower[indexOf + 6].CharToIntFast();
155145
}
156146
}
157147

158148
[HarmonyPatch(typeof(GroundItemVisuals), nameof(GroundItemVisuals.initialise), typeof(ItemDataUnpacked), typeof(uint), typeof(GroundItemLabel), typeof(GroundItemRarityVisuals), typeof(bool))]
159149
private static class GroundItemVisuals_initialise_Patch
160150
{
151+
private static readonly Dictionary<string, Sprite> IconCache = [];
161152
private static bool ShouldShow(Rule rule)
162153
{
163154
if (!rule.isEnabled || rule.type is Rule.RuleOutcome.HIDE) return false;
164-
if (ShowAll.Value) return true;
165-
return rule.emphasized;
155+
return rule.emphasized || ShowAll.Value;
166156
}
167157

168158
private static void Prefix(GroundItemVisuals __instance, ItemDataUnpacked itemData, GroundItemLabel label, GroundItemRarityVisuals groundItemRarityVisuals)
@@ -196,8 +186,13 @@ private static void Prefix(GroundItemVisuals __instance, ItemDataUnpacked itemDa
196186
itemName = entry.name.Replace(" ", "_");
197187
}
198188
}
199-
200-
Sprite icon = Resources.Load<Sprite>($"gear/{path}/{itemName}");
189+
string fullPath = $"gear/{path}/{itemName}";
190+
if (!IconCache.TryGetValue(fullPath, out var icon))
191+
{
192+
MelonLogger.Msg($"Couldn't find icon for {itemName} ({path}), loading from resources");
193+
icon = Resources.Load<Sprite>(fullPath);
194+
IconCache[fullPath] = icon;
195+
}else MelonLogger.Msg($"Found icon for {itemName} ({path}) in cache");
201196
customMapIcon.GetComponent<Image>().sprite = ItemList.instance.defaultItemBackgroundSprite;
202197
customMapIcon.GetComponent<Image>().color = GetColorForItemRarity(itemData);
203198
customMapIcon.transform.GetChild(0).GetComponent<Image>().sprite = icon;
@@ -214,11 +209,8 @@ private class CustomIconProcessor : MonoBehaviour
214209
private Text _text;
215210
private RectTransform thisTransform;
216211
private GroundItemLabel _label;
217-
218-
private void Awake()
219-
{
220-
_text = transform.GetChild(1).GetComponent<Text>();
221-
}
212+
213+
private void Awake() => _text = transform.GetChild(1).GetComponent<Text>();
222214

223215
public void Init(GameObject toTrack, GroundItemLabel label)
224216
{
@@ -250,7 +242,7 @@ private void PointerEnter()
250242
}
251243

252244
private void PointerExit()
253-
{
245+
{
254246
if (_label != null && _label && _label.tooltipItem) _label.tooltipItem.OnPointerExit(null);
255247
}
256248

@@ -388,7 +380,7 @@ private static void Postfix(CameraManager __instance)
388380
private static class InventoryPanelUI_Awake_Patch
389381
{
390382
public static int AwakeFrame;
391-
private static void Postfix(InventoryPanelUI __instance) => AwakeFrame = Time.frameCount;
383+
private static void Postfix() => AwakeFrame = Time.frameCount;
392384
}
393385
[HarmonyPatch(typeof(InventoryPanelUI), nameof(InventoryPanelUI.OpenInventoryPanel))]
394386
private static class InventoryPanelUI_OpenInventoryPanel_Patch

0 commit comments

Comments
 (0)