forked from Arecurius0/UniqueLootHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueLootHelperCore.cs
More file actions
808 lines (683 loc) · 27.4 KB
/
UniqueLootHelperCore.cs
File metadata and controls
808 lines (683 loc) · 27.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
using ExileCore;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.Elements;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Cache;
using ExileCore.Shared.Enums;
using ImGuiNET;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Windows.Forms;
using UniqueLootHelper.Managers;
using Vector2 = System.Numerics.Vector2;
namespace UniqueLootHelper;
public record UniqueItemInfo(string Name, string Art, string Tier, string Base, string Grouping, string League);
public class UniqueItemSettings
{
public string ArtPath = "",
Label = "";
public bool LineDrawWorld,
DrawLabelInBox = true,
DrawLabelOutline = true,
LineDrawMap,
DrawLabelName = true,
DrawIsCorrupted = true,
PlayValuableSound;
}
public class UniqueLootHelperCore : BaseSettingsPlugin<Settings>
{
private readonly CachedValue<List<CustomItemData>> _groundItems;
private readonly Stopwatch _profilerDrawing;
private readonly Stopwatch _profilerFiltering;
// Profiler fields
private readonly Stopwatch _profilerGetItems;
private readonly Stopwatch _profilerTotal;
private ConfigurationManager _configurationManager;
private ImportExportService _importExportService;
private string _importExportText = string.Empty;
private ItemDrawingManager _itemDrawingManager;
private bool _showProfilerWindow;
private SoundManager _soundManager;
private UniqueItemsListManager _uniqueItemsListManager;
private StatisticsManager _statisticsManager;
private UniqueItemSettings _tempUniqueItemSettings = new();
// Statistics UI state
private bool _showStatisticsWindow;
// UI state for item selection
private string _searchTerm = string.Empty;
private string _uniqueListSearchTerm = string.Empty;
private string _selectedItemName = string.Empty;
private bool _usePresetMode = false;
private readonly List<CustomItemData> _result = [];
private readonly Dictionary<(long, long), CustomItemData> _prevDict = [];
private readonly List<string> _countList = [];
private readonly HashSet<(long, long)> _currentItemIds = [];
public UniqueLootHelperCore()
{
_groundItems = new FrameCache<List<CustomItemData>>(
CacheUtils.RememberLastValue(GetItemsOnGround, new List<CustomItemData>())
);
// Initialize profiler stopwatches
_profilerGetItems = new Stopwatch();
_profilerFiltering = new Stopwatch();
_profilerDrawing = new Stopwatch();
_profilerTotal = new Stopwatch();
}
public override bool Initialise()
{
Name = "UniqueLootHelper";
// Initialize managers
_configurationManager = new ConfigurationManager(ConfigDirectory, LogMessage, LogError);
_soundManager = new SoundManager(
ConfigDirectory,
LogMessage,
LogError,
(path, volume) => { GameController.SoundController.PlaySound(path, volume); return true; }
);
_itemDrawingManager = new ItemDrawingManager(() => Graphics, () => Settings);
_importExportService = new ImportExportService(LogMessage, LogError);
_uniqueItemsListManager = new UniqueItemsListManager(DirectoryFullName, LogMessage, LogError);
_statisticsManager = new StatisticsManager(ConfigDirectory, LogMessage, LogError, _uniqueItemsListManager);
// Initialize area state in case plugin loaded while already in a map
if (GameController?.Area?.CurrentArea != null) _statisticsManager.AreaChange(GameController.Area.CurrentArea);
// Setup event handlers
Settings.SoundNotificationSettings.ResetEntityNotificationFlags.OnPressed += () => _soundManager.ClearCache();
Settings.SoundNotificationSettings.OpenConfigDirectory.OnPressed += () => Process.Start("explorer.exe", ConfigDirectory);
Settings.SoundNotificationSettings.ReloadSoundList.OnPressed += () => _soundManager.ReloadSoundList();
Settings.ProfilerSettings.ShowProfilerWindow.OnPressed += () => _showProfilerWindow = !_showProfilerWindow;
Settings.StatisticsSettings.ShowStatisticsWindow.OnPressed += () => _showStatisticsWindow = !_showStatisticsWindow;
GameController.EntityListWrapper.EntityAdded += EntityAdd;
return base.Initialise();
}
public override void OnUnload()
{
_configurationManager.SaveUniqueArtToFile();
_statisticsManager?.SaveStatistics();
base.OnUnload();
}
public override void OnClose()
{
_configurationManager.SaveUniqueArtToFile();
_statisticsManager?.SaveStatistics();
base.OnClose();
}
public override void DrawSettings()
{
if (ImGui.Button("Open Config Folder"))
{
Process.Start("explorer.exe", ConfigDirectory);
}
ImGui.Spacing();
ImGui.Separator();
ImGui.Spacing();
ImGui.Text("Import/Export Configuration:");
ImGui.InputText("##ImportExportText", ref _importExportText, 100000);
if (ImGui.Button("Paste from Clipboard##PasteImport"))
{
try
{
string clipboardText = Clipboard.GetClipboardText();
if (!string.IsNullOrEmpty(clipboardText))
{
_importExportText = clipboardText;
LogMessage("UniqueLootHelper: Pasted text from clipboard");
}
}
catch (Exception ex)
{
LogError($"UniqueLootHelper: Failed to paste from clipboard: {ex.Message}");
}
}
ImGui.SameLine();
if (ImGui.Button("Import (Merge)##ImportMerge"))
{
Import(merge: true);
}
ImGui.SameLine();
if (ImGui.Button("Import (Replace)##ImportReplace"))
{
Import(merge: false);
}
ImGui.SameLine();
if (ImGui.Button("Export##ExportState"))
{
Export();
}
ImGui.SameLine();
if (ImGui.Button("Clear##ClearImportExport"))
{
_importExportText = string.Empty;
}
ImGui.TextColored(new Vector4(0.7f, 0.7f, 0.7f, 1.0f),
"Merge: Add to existing items | Replace: Clear all and import");
ImGui.Dummy(new Vector2(0, 20));
base.DrawSettings();
ImGui.Spacing();
ImGui.Separator();
ImGui.Spacing();
ImGui.Spacing();
ImGui.Text("Add new unique to list");
// Mode toggle
if (ImGui.Checkbox("Use Preset Item", ref _usePresetMode))
{
_tempUniqueItemSettings = new UniqueItemSettings();
_selectedItemName = string.Empty;
}
ImGui.Spacing();
if (_usePresetMode)
{
DrawPresetItemSelection();
}
else
{
DrawCustomItemInput();
}
ImGui.Spacing();
// Common settings
ImGui.Checkbox("Draw line on map", ref _tempUniqueItemSettings.LineDrawMap);
ImGui.SameLine();
ImGui.Checkbox("Draw line on world", ref _tempUniqueItemSettings.LineDrawWorld);
ImGui.SameLine();
ImGui.Checkbox("Draw outline", ref _tempUniqueItemSettings.DrawLabelOutline);
ImGui.SameLine();
ImGui.Checkbox("Draw Label name", ref _tempUniqueItemSettings.DrawLabelName);
ImGui.SameLine();
ImGui.Checkbox("Draw label in box", ref _tempUniqueItemSettings.DrawLabelInBox);
ImGui.SameLine();
ImGui.Checkbox("Draw is corrupted", ref _tempUniqueItemSettings.DrawIsCorrupted);
ImGui.SameLine();
ImGui.Checkbox("Play valuable sound", ref _tempUniqueItemSettings.PlayValuableSound);
if (ImGui.Button("Add Unique"))
{
if (_configurationManager.AddOrUpdateUniqueItem(_tempUniqueItemSettings.ArtPath, _tempUniqueItemSettings))
{
_tempUniqueItemSettings = new UniqueItemSettings();
_selectedItemName = string.Empty;
_searchTerm = string.Empty;
}
}
ImGui.Spacing();
ImGui.Separator();
ImGui.Spacing();
ImGui.Text("Uniques list:");
// Search bar for uniques list
ImGui.InputTextWithHint("##SearchUniquesList", "Search in list...", ref _uniqueListSearchTerm, 256);
// Filter items based on search term
IEnumerable<KeyValuePair<string, UniqueItemSettings>> filteredItems = _configurationManager.UniqueArtWork;
if (!string.IsNullOrWhiteSpace(_uniqueListSearchTerm))
{
string searchLower = _uniqueListSearchTerm.ToLowerInvariant();
filteredItems = filteredItems.Where(item =>
item.Key.ToLowerInvariant().Contains(searchLower) ||
(item.Value.Label ?? "").ToLowerInvariant().Contains(searchLower)
);
}
var itemsList = filteredItems.ToList();
ImGui.TextColored(
new Vector4(0.7f, 0.7f, 0.7f, 1.0f),
$"Showing {itemsList.Count} of {_configurationManager.UniqueArtWork.Count} items"
);
ImGui.Spacing();
// Display as table
if (ImGui.BeginTable("##UniquesTable", 4,
ImGuiTableFlags.Borders |
ImGuiTableFlags.RowBg |
ImGuiTableFlags.ScrollY |
ImGuiTableFlags.Resizable,
new Vector2(0, 400)))
{
// Setup columns
ImGui.TableSetupColumn("Art Path", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("Label", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("Edit", ImGuiTableColumnFlags.WidthFixed, 60);
ImGui.TableSetupColumn("Delete", ImGuiTableColumnFlags.WidthFixed, 60);
ImGui.TableSetupScrollFreeze(0, 1);
ImGui.TableHeadersRow();
// Display rows
foreach (KeyValuePair<string, UniqueItemSettings> uniqueArtItem in itemsList)
{
ImGui.TableNextRow();
// Art Path column
ImGui.TableNextColumn();
ImGui.TextWrapped(uniqueArtItem.Key);
// Label column
ImGui.TableNextColumn();
ImGui.TextWrapped(uniqueArtItem.Value.Label ?? "");
// Edit button column
ImGui.TableNextColumn();
if (ImGui.Button($"Edit##{uniqueArtItem.Key}"))
{
_tempUniqueItemSettings = uniqueArtItem.Value;
_usePresetMode = false;
LogMessage($"UniqueLootHelper: Editing {uniqueArtItem.Key} from unique list");
}
// Delete button column
ImGui.TableNextColumn();
if (ImGui.Button($"Delete##{uniqueArtItem.Key}"))
{
_configurationManager.RemoveUniqueItem(uniqueArtItem.Key);
}
}
ImGui.EndTable();
}
}
private void DrawPresetItemSelection()
{
ImGui.Text("Search for unique item (regex supported):");
ImGui.InputText("##SearchUniqueItem", ref _searchTerm, 256);
ImGui.Spacing();
if (!string.IsNullOrWhiteSpace(_searchTerm))
{
List<UniqueItemInfo> searchResults = _uniqueItemsListManager.SearchItems(_searchTerm);
ImGui.TextColored(
new Vector4(0.7f, 0.7f, 0.7f, 1.0f),
searchResults.Count == 0
? "No matching items found"
: $"Found {searchResults.Count} matching items (max 50 shown)"
);
ImGui.Spacing();
// Display as table
if (ImGui.BeginTable("##SearchTable", 7,
ImGuiTableFlags.Borders |
ImGuiTableFlags.RowBg |
ImGuiTableFlags.ScrollY |
ImGuiTableFlags.Resizable,
new Vector2(0, 400)))
{
// Setup columns
ImGui.TableSetupColumn("Tier", ImGuiTableColumnFlags.WidthFixed, 50);
ImGui.TableSetupColumn("Name", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("Base", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableSetupColumn("Grouping", ImGuiTableColumnFlags.WidthFixed, 100);
ImGui.TableSetupColumn("League", ImGuiTableColumnFlags.WidthFixed, 100);
ImGui.TableSetupColumn("CountInBase", ImGuiTableColumnFlags.WidthFixed, 100);
ImGui.TableSetupColumn("Action", ImGuiTableColumnFlags.WidthFixed, 80);
ImGui.TableSetupScrollFreeze(0, 1);
ImGui.TableHeadersRow();
// Display rows
foreach (UniqueItemInfo item in searchResults)
{
bool isAlreadyAdded = _configurationManager.UniqueArtWork.ContainsKey(item.Art);
ImGui.TableNextRow();
// Tier column
ImGui.TableNextColumn();
ImGui.Text(item.Tier ?? "");
// Name column
ImGui.TableNextColumn();
ImGui.TextWrapped(item.Name ?? "");
// Base column
ImGui.TableNextColumn();
ImGui.TextWrapped(item.Base ?? "");
// Grouping column
ImGui.TableNextColumn();
ImGui.Text(item.Grouping ?? "");
// League column
ImGui.TableNextColumn();
ImGui.Text(item.League ?? "");
// CountInBase column
ImGui.TableNextColumn();
_uniqueItemsListManager.BaseCounts.TryGetValue(item.Base ?? "", out int countInBase);
ImGui.Text(countInBase.ToString());
// Action column
ImGui.TableNextColumn();
if (isAlreadyAdded)
{
ImGui.TextDisabled("Added");
}
else
{
if (ImGui.Button($"Add##{item.Art}"))
{
_tempUniqueItemSettings.ArtPath = item.Art;
_tempUniqueItemSettings.Label = item.Name;
_selectedItemName = item.Name;
}
}
}
ImGui.EndTable();
}
}
else
{
ImGui.TextColored(
new Vector4(0.7f, 0.7f, 0.7f, 1.0f),
"Enter search term to find unique items..."
);
}
ImGui.Spacing();
if (!string.IsNullOrEmpty(_selectedItemName))
{
ImGui.Separator();
ImGui.TextColored(
new Vector4(0.0f, 1.0f, 0.0f, 1.0f),
$"Selected: {_selectedItemName}"
);
ImGui.Text($"Art Path: {_tempUniqueItemSettings.ArtPath}");
ImGui.Spacing();
}
ImGui.InputText(
"Custom Label (optional)",
ref _tempUniqueItemSettings.Label,
1024,
ImGuiInputTextFlags.EnterReturnsTrue
);
}
private void DrawCustomItemInput()
{
ImGui.InputText(
"Unique art path",
ref _tempUniqueItemSettings.ArtPath,
1024,
ImGuiInputTextFlags.EnterReturnsTrue
);
ImGui.InputText(
"Unique label",
ref _tempUniqueItemSettings.Label,
1024,
ImGuiInputTextFlags.EnterReturnsTrue
);
}
private void DrawProfilerWindow()
{
if (!Settings.ProfilerSettings.Enabled)
{
return;
}
Profiler.ShowProfilerWindow(ref _showProfilerWindow);
}
private void DrawStatisticsWindow()
{
StatisticsUI.ShowStatisticsWindow(ref _showStatisticsWindow, _statisticsManager);
}
private void Import(bool merge)
{
Dictionary<string, UniqueItemSettings>? imported = _importExportService.Import(
_importExportText
);
if (imported != null && _importExportService.ValidateConfiguration(imported))
{
if (merge)
{
_configurationManager.MergeConfiguration(imported);
LogMessage($"UniqueLootHelper: Merged {imported.Count} items with existing configuration");
}
else
{
_configurationManager.ReplaceConfiguration(imported);
LogMessage($"UniqueLootHelper: Replaced configuration with {imported.Count} items");
}
}
}
public void Export()
{
_importExportText = _importExportService.Export(
_configurationManager.GetAllConfigurations()
);
// Also copy to system clipboard for convenience
try
{
Clipboard.SetClipboardText(_importExportText);
LogMessage("UniqueLootHelper: Configuration exported and copied to clipboard");
}
catch (Exception ex)
{
LogError($"UniqueLootHelper: Failed to copy to clipboard: {ex.Message}");
}
}
public override void Render()
{
// Start total profiler at the VERY beginning to measure everything
if (Settings.ProfilerSettings.Enabled)
{
_profilerTotal.Restart();
}
if (GameController == null || GameController.Game == null || GameController.IngameState == null)
{
return;
}
try
{
DrawProfilerWindow();
DrawStatisticsWindow();
if (Input.IsKeyDown(Keys.F7))
{
var hoverItem =
GameController.Game.IngameState.UIHover.AsObject<HoverItemIcon>();
if (hoverItem == null)
{
return;
}
var renderItem = hoverItem.Item.GetComponent<RenderItem>();
if (renderItem == null)
{
return;
}
ImGui.SetClipboardText(renderItem.ResourcePath);
LogMessage($"UniqueLootHelper: Copied {renderItem.ResourcePath} to clipboard");
}
var inGameUi = GameController.Game.IngameState.IngameUi;
// Optimization: avoid Any() with predicate - use direct iteration to avoid delegate allocation
if (!Settings.IgnoreFullscreenPanels)
{
var hasVisiblePanel = false;
foreach (var panel in inGameUi.FullscreenPanels)
{
if (panel.IsVisible)
{
hasVisiblePanel = true;
break;
}
}
if (hasVisiblePanel)
{
return;
}
}
if (!Settings.IgnoreRightPanels && inGameUi.OpenRightPanel.IsVisible)
{
return;
}
var player = GameController?.Player;
if (player is null) return;
ImGui.Begin(
"lmao",
ImGuiWindowFlags.NoDecoration
| ImGuiWindowFlags.NoBackground
| ImGuiWindowFlags.NoInputs
| ImGuiWindowFlags.NoFocusOnAppearing
| ImGuiWindowFlags.NoNav
);
// Profile: Getting ground items
if (Settings.ProfilerSettings.Enabled)
{
_profilerGetItems.Restart();
}
var groundItems = _groundItems.Value;
if (Settings.ProfilerSettings.Enabled)
{
_profilerGetItems.Stop();
_profilerFiltering.Restart();
}
_countList.Clear();
_currentItemIds.Clear();
// List<string> countList = new(groundItems.Count / 2);
// var currentItemIds = new HashSet<uint>(groundItems.Count);
// Optimization: Cache dictionary reference to avoid repeated property access
var uniqueArtWork = _configurationManager.UniqueArtWork;
var drawMapLines = Settings.MapDrawingSettings.EnableMapDrawing && GameController.IngameState.IngameUi.Map.LargeMap.IsVisible;
bool drawWorldLines = Settings.MapDrawingSettings.WorldMapDrawing;
var playerMapPos = Vector2.Zero;
var playerWorldPos = Vector2.Zero;
if (drawMapLines)
{
playerMapPos = GameController.IngameState.Data.GetGridMapScreenPosition(player.GridPosNum);
}
if (drawWorldLines)
{
playerWorldPos = GameController.IngameState.Data.GetGridScreenPosition(player.GridPosNum);
}
foreach (var item in groundItems)
{
_currentItemIds.Add((item.WorldItem.Address, item.Element.Address));
var normalizedPath = item.NormalizedResourcePath;
if (string.IsNullOrEmpty(normalizedPath)) continue;
if (!uniqueArtWork.TryGetValue(normalizedPath, out var uniqueSettings))
{
continue;
}
if (!uniqueSettings.DrawIsCorrupted && item.IsCorrupted)
{
continue;
}
var rect = !item.ClientRect.IsEmpty ? item.ClientRect : item.Element.GetClientRect();
if (uniqueSettings.DrawLabelInBox)
{
var label = string.IsNullOrEmpty(uniqueSettings.Label)
? item.Entity?.RenderName ?? "Unknown Item"
: uniqueSettings.Label;
_countList.Add(label);
}
if (
Settings.SoundNotificationSettings.Enabled
&& uniqueSettings.PlayValuableSound
)
{
_soundManager.TryPlaySound(
(item.WorldItem.Address, item.Element.Address),
uniqueSettings.Label,
Settings.SoundNotificationSettings.Volume
);
}
// Profile: Drawing operations
if (Settings.ProfilerSettings.Enabled)
{
_profilerDrawing.Start();
}
if (uniqueSettings.LineDrawMap && drawMapLines)
{
var itemMapPos = GameController?.IngameState.Data.GetGridMapScreenPosition(item.Location);
if (itemMapPos == null) continue;
_itemDrawingManager.DrawMapLine((Vector2)itemMapPos, playerMapPos);
}
if (drawWorldLines && uniqueSettings.LineDrawWorld)
{
var itemWorldPos = GameController?.IngameState.Data.GetGridScreenPosition(item.Location);
if (itemWorldPos == null) continue;
_itemDrawingManager.DrawWorldLine((Vector2)itemWorldPos, playerWorldPos);
}
_itemDrawingManager.DrawLabelOutline(rect, uniqueSettings);
if (!item.IsIdentified)
{
var labelText = uniqueSettings.Label ?? item.Entity?.RenderName ?? "Unknown Item";
_itemDrawingManager.DrawLabelName(rect, labelText, item.IsIdentified, uniqueSettings);
}
if (Settings.ProfilerSettings.Enabled)
{
_profilerDrawing.Stop();
}
}
// Cleanup caches using the IDs we saw this frame
_soundManager.CleanupCache(_currentItemIds);
if (Settings.ProfilerSettings.Enabled)
{
_profilerFiltering.Stop();
}
ImGui.End();
// Draw total uniques count box (separate box above the main one)
int currentMapUniques = _statisticsManager.GetCurrentMapUniqueCount();
if (Settings.BoxSettings.EnableBoxCountDrawing && currentMapUniques > 0)
{
_itemDrawingManager.DrawTotalUniquesBox(currentMapUniques);
}
// Draw tracked items box (original behavior)
if (_countList.Count > 0)
{
_itemDrawingManager.DrawItemCountBox(_countList);
}
// Record profiler metrics
if (Settings.ProfilerSettings.Enabled)
{
_profilerTotal.Stop();
// Record metrics for window display
Profiler.RecordMetrics(
_profilerGetItems,
_profilerFiltering,
_profilerDrawing,
_profilerTotal
);
// Reset profilers for next frame
_profilerGetItems.Reset();
_profilerFiltering.Reset();
_profilerDrawing.Reset();
_profilerTotal.Reset();
}
}
catch (Exception ex)
{
LogError($"UniqueLootHelper: Error in Render: {ex.Message}");
}
}
public override void AreaChange(AreaInstance area)
{
_soundManager.ClearCache();
if (area == null)
{
// Logout detected - finalize current map session and save statistics
_statisticsManager.HandleLogout();
return;
}
_statisticsManager.AreaChange(area);
}
private void EntityAdd(Entity entity)
{
if (entity == null || !entity.IsValid) return;
if (entity.Type != EntityType.WorldItem) return;
if (!entity.TryGetComponent<WorldItem>(out var worldItem)) return;
var itemEntity = worldItem.ItemEntity;
if (itemEntity == null || !itemEntity.IsValid) return;
_statisticsManager.TrackItemDrop(entity.Id, itemEntity);
}
private List<CustomItemData> GetItemsOnGround(List<CustomItemData> previousValue)
{
var labelsOnGround =
GameController
.IngameState
.IngameUi
.ItemsOnGroundLabelElement
.VisibleGroundItemLabels;
_result.Clear();
_prevDict.Clear();
foreach (CustomItemData item in previousValue)
{
if (item.Element != null && item.Entity != null)
{
_prevDict[(item.WorldItem.Address, item.Element.Address)] = item;
}
}
foreach (var description in labelsOnGround)
{
if (description.Entity == null) continue;
if (!description.Entity.TryGetComponent(out WorldItem worldItem)) continue;
var groundItemEntity = worldItem.ItemEntity;
if (groundItemEntity == null || !groundItemEntity.IsValid) continue;
var key = (worldItem.Address, description.Label.Address);
if (_prevDict.TryGetValue(key, out var cachedItem))
{
cachedItem.ClientRect = description.ClientRect;
_result.Add(cachedItem);
}
else
{
_result.Add(new(worldItem, description.Label, description.Entity.GridPosNum, description.ClientRect));
}
}
foreach (var unusedItem in _prevDict.Values)
{
_soundManager.ClearCacheEntry((unusedItem.WorldItem.Address, unusedItem.Element.Address));
}
return _result;
}
}