forked from TehCheat/IconsBuilder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
IconsBuilder.cs
273 lines (233 loc) · 10.1 KB
/
IconsBuilder.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ExileCore;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared;
using ExileCore.Shared.Abstract;
using ExileCore.Shared.Enums;
using IconsBuilder.Icons;
using JM.LinqFaster;
using SharpDX;
namespace IconsBuilder
{
public class IconsBuilder : BaseSettingsPlugin<IconsBuilderSettings>
{
private const string ALERT_CONFIG = "config\\new_mod_alerts.txt";
private const string IGNORE_FILE = "IgnoredEntities.txt";
private List<string> IgnoredSum;
private readonly EntityType[] Chests =
{
EntityType.Chest, EntityType.SmallChest
};
private readonly List<string> ignoreEntites = new List<string>
{
"Metadata/Monsters/Frog/FrogGod/SilverPool",
"Metadata/MiscellaneousObjects/WorldItem",
"Metadata/Pet/Weta/Basic",
"Metadata/Monsters/Daemon/SilverPoolChillDaemon",
"Metadata/Monsters/Daemon",
"Metadata/Monsters/Frog/FrogGod/SilverOrbFromMonsters",
"Metadata/Terrain/Labyrinth/Objects/Puzzle_Parts/TimerGears",
"Metadata/Chests/DelveChests/DelveAzuriteVeinEncounter",
"Metadata/Chests/DelveChests/DelveAzuriteVeinEncounterNoDrops",
//delirium Ignores
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionCorpseDegen",
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionDemonColdDegenUnique",
"Metadata/Monsters/AtlasExiles/CrusaderInfluenceMonsters/CrusaderArcaneRune"
};
private readonly Dictionary<string, Size2> modIcons = new Dictionary<string, Size2>();
private readonly EntityType[] SkippedEntity =
{
EntityType.WorldItem, EntityType.HideoutDecoration, EntityType.Effect, EntityType.Light, EntityType.ServerObject
};
private Queue<Entity> _addedIcon = new Queue<Entity>(128);
private int rnd = 1000;
private void LoadConfig()
{
var readAllLines = File.ReadAllLines(ALERT_CONFIG);
foreach (var readAllLine in readAllLines)
{
if (readAllLine.StartsWith("#")) continue;
var s = readAllLine.Split(';');
var sz = s[2].Trim().Split(',');
modIcons[s[0]] = new Size2(int.Parse(sz[0]), int.Parse(sz[1]));
}
}
private void CreateIgnoreFile()
{
var path = $"{DirectoryFullName}\\{IGNORE_FILE}";
if (File.Exists(path)) return;
var defaultConfig =
#region default Config
"#default ignores\n" +
"Metadata/Monsters/Frog/FrogGod/SilverPool\n" +
"Metadata/MiscellaneousObjects/WorldItem\n" +
"Metadata/Pet/Weta/Basic\n" +
"Metadata/Monsters/Daemon/SilverPoolChillDaemon\n" +
"Metadata/Monsters/Daemon\n" +
"Metadata/Monsters/Frog/FrogGod/SilverOrbFromMonsters\n" +
"Metadata/Terrain/Labyrinth/Objects/Puzzle_Parts/TimerGears\n" +
"Metadata/Chests/DelveChests/DelveAzuriteVeinEncounter\n" +
"Metadata/Chests/DelveChests/DelveAzuriteVeinEncounterNoDrops\n" +
"#Delirium Ignores\n" +
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionCorpseDegen\n" +
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionDemonColdDegenUnique\n" +
"Metadata/Monsters/AtlasExiles/CrusaderInfluenceMonsters/CrusaderArcaneRune";
#endregion
using (var streamWriter = new StreamWriter(path, true))
{
streamWriter.Write(defaultConfig);
streamWriter.Close();
}
}
private void ReadIgnoreFile()
{
var path = $"{DirectoryFullName}\\{IGNORE_FILE}";
if (File.Exists(path))
{
var text = File.ReadAllLines(path).Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")).ToList();
IgnoredSum = ignoreEntites.Concat(text).ToList();
}
else
CreateIgnoreFile();
}
public override void OnLoad()
{
Graphics.InitImage("sprites.png");
}
public override void EntityIgnored(Entity Entity)
{
if (!Settings.Enable.Value) return;
}
public override void EntityRemoved(Entity Entity)
{
if (!Settings.Enable.Value) return;
if (Entity.Type == EntityType.Effect) return;
}
public override void EntityAdded(Entity Entity)
{
if (!Settings.Enable.Value) return;
if (SkippedEntity.Any(x => x == Entity.Type)) return;
_addedIcon.Enqueue(Entity);
}
//Probably now outdated, need more tests
private IEnumerator FixIcons()
{
yield return new WaitTime(1000);
_addedIcon = new Queue<Entity>(GameController.Entities.Where(x => x.IsValid));
}
public override void AreaChange(AreaInstance area)
{
Core.MainRunner.Run(new Coroutine(FixIcons(), this, "Fix map icons"));
ReadIgnoreFile();
}
public override bool Initialise()
{
LoadConfig();
Settings.Reparse.OnPressed += () =>
{
foreach (var entity in GameController.EntityListWrapper.Entities)
{
if (!entity.IsValid) continue;
EntityAdded(entity);
}
};
ReadIgnoreFile();
return true;
}
public override Job Tick()
{
if (!Settings.Enable.Value) return null;
if (Settings.MultiThreading && _addedIcon.Count >= Settings.MultiThreadingWhenEntityMoreThan)
return GameController.MultiThreadManager.AddJob(TickLogic, nameof(IconsBuilder));
TickLogic();
return null;
}
private void TickLogic()
{
while (_addedIcon.Count > 0)
{
try
{
var dequeue = _addedIcon.Dequeue();
var entityAddedLogic = EntityAddedLogic(dequeue);
if (entityAddedLogic != null)
dequeue.SetHudComponent(entityAddedLogic);
}
catch (Exception ex)
{
DebugWindow.LogError($"{nameof(IconsBuilder)} -> {ex}", 3);
}
}
}
private bool SkipEntity(Entity entity)
{
if (entity.Type == EntityType.Daemon) return true;
if (ignoreEntites.AnyF(x => entity.Path.Contains(x))) return true;
return false;
}
private BaseIcon EntityAddedLogic(Entity entity)
{
if (SkipEntity(entity)) return null;
if (Settings.UseReplacementsForGameIconsWhenOutOfRange &&
entity.TryGetComponent<MinimapIcon>(out var minimapIconComponent) &&
!minimapIconComponent.IsHide)
{
var name = minimapIconComponent.Name;
if (!string.IsNullOrEmpty(name))
{
return new IngameIconReplacerIcon(entity, Settings);
}
}
//Monsters
if (entity.Type == EntityType.Monster)
{
if (!entity.IsAlive) return null;
if (entity.League == LeagueType.Legion)
return new LegionIcon(entity, GameController, Settings, modIcons);
if (entity.League == LeagueType.Delirium)
return new DeliriumIcon(entity, GameController, Settings, modIcons);
return new MonsterIcon(entity, GameController, Settings, modIcons);
}
//NPC
if (entity.Type == EntityType.Npc)
return new NpcIcon(entity, GameController, Settings);
//Player
if (entity.Type == EntityType.Player)
{
if (!entity.IsValid) return null;
if (GameController.IngameState.Data.LocalPlayer.GetComponent<Player>().PlayerName == entity.GetComponent<Player>().PlayerName)
return new SelfIcon(entity, GameController, Settings, modIcons);
else
return new PlayerIcon(entity, GameController, Settings, modIcons);
}
//Chests
if (Chests.AnyF(x => x == entity.Type) && !entity.IsOpened)
return new ChestIcon(entity, GameController, Settings);
//Area transition
if (entity.Type == EntityType.AreaTransition)
return new MiscIcon(entity, GameController, Settings);
//Shrine
if (entity.HasComponent<Shrine>())
return new ShrineIcon(entity, GameController, Settings);
if (entity.HasComponent<Transitionable>() && entity.HasComponent<MinimapIcon>())
{
//Mission marker
if (entity.Path.Equals("Metadata/MiscellaneousObjects/MissionMarker", StringComparison.Ordinal) ||
entity.GetComponent<MinimapIcon>().Name.Equals("MissionTarget", StringComparison.Ordinal))
return new MissionMarkerIcon(entity, GameController, Settings);
return new MiscIcon(entity, GameController, Settings);
}
if (entity.HasComponent<MinimapIcon>() && entity.HasComponent<Targetable>() && entity.League != LeagueType.Heist ||
entity.Path.Contains("Metadata/Terrain/Leagues/Delve/Objects/EncounterControlObjects/AzuriteEncounterController") ||
entity.Type == EntityType.LegionMonolith ||
entity.Path is "Metadata/Terrain/Leagues/Sanctum/Objects/SanctumMote")
return new MiscIcon(entity, GameController, Settings);
return null;
}
}
}