-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathAutoOpen.cs
More file actions
349 lines (303 loc) · 14.1 KB
/
AutoOpen.cs
File metadata and controls
349 lines (303 loc) · 14.1 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using AutoOpen.Utils;
using ExileCore;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Enums;
using ExileCore.Shared.Helpers;
using SharpDX;
namespace AutoOpen
{
public class AutoOpen : BaseSettingsPlugin<Settings>
{
private IngameState ingameState;
private readonly Dictionary<long, int> clickedEntities = new Dictionary<long, int>();
private Vector2 windowOffset;
private List<string> doorBlacklist;
private List<string> switchBlacklist;
private List<string> chestWhitelist;
public override bool Initialise()
{
base.Initialise();
Name = "AutoOpen";
ingameState = GameController.Game.IngameState;
windowOffset = GameController.Window.GetWindowRectangle().TopLeft;
loadDoorBlacklist();
loadSwitchBlacklist();
loadChestWhitelist();
return true;
}
public override void Render()
{
if (!Settings.Enable) return;
open();
}
private void open()
{
var camera = ingameState.Camera;
var playerPos = GameController.Player.Pos;
var prevMousePosition = Mouse.GetCursorPosition();
var entities = GameController.Entities
.Where(entity => entity.HasComponent<Render>() &&
entity.Address != GameController.Player.Address &&
entity.IsValid &&
entity.IsTargetable &&
(entity.HasComponent<TriggerableBlockage>() ||
entity.HasComponent<Transitionable>() ||
entity.HasComponent<Chest>() ||
entity.HasComponent<Shrine>() ||
entity.Path.ToLower().Contains("darkshrine")));
foreach (var entity in entities)
{
var entityPos = entity.Pos;
var entityScreenPos = camera.WorldToScreen(entityPos.Translate(0, 0, 0));
var entityDistanceToPlayer =
Math.Sqrt(Math.Pow(playerPos.X - entityPos.X, 2) + Math.Pow(playerPos.Y - entityPos.Y, 2));
var isTargetable = entity.GetComponent<Targetable>().isTargetable;
var isTargeted = entity.GetComponent<Targetable>().isTargeted;
//Doors
if (Settings.doors)
{
var isBlacklisted = doorBlacklist != null && doorBlacklist.Contains(entity.Path);
if (entity.HasComponent<TriggerableBlockage>() && entity.HasComponent<Targetable>() &&
entity.Path.ToLower().Contains("door"))
{
var isClosed = entity.GetComponent<TriggerableBlockage>().IsClosed;
var s = isClosed ? "closed" : "opened";
var c = isClosed ? Color.Red : Color.Green;
if (!isBlacklisted) Graphics.DrawText(s, entityScreenPos, c, FontAlign.Center);
if (isTargeted)
if (Keyboard.IsKeyPressed((int) Settings.toggleEntityKey.Value))
toggleDoorBlacklistItem(entity.Path);
if (Control.MouseButtons == MouseButtons.Left)
{
var clickCount = getEntityClickedCount(entity);
if (!isBlacklisted && entityDistanceToPlayer <= Settings.doorDistance && isClosed &&
clickCount <= 15)
{
open(entityScreenPos, prevMousePosition);
clickedEntities[entity.Address] = clickCount + 1;
if (Settings.BlockInput) Mouse.blockInput(true);
}
else if (!isBlacklisted && entityDistanceToPlayer >= Settings.doorDistance &&
isClosed && clickCount >= 15)
{
clickedEntities.Clear();
}
if (Settings.BlockInput) Mouse.blockInput(false);
}
}
}
//Switches
if (Settings.switches)
{
var isBlacklisted = switchBlacklist != null && switchBlacklist.Contains(entity.Path);
if (entity.HasComponent<Transitionable>() && entity.HasComponent<Targetable>() &&
!entity.HasComponent<TriggerableBlockage>() && entity.Path.ToLower().Contains("switch"))
{
var switchState = entity.GetComponent<Transitionable>().Flag1;
var switched = switchState != 1;
var s = isTargeted ? "targeted" : "not targeted";
var c = isTargeted ? Color.Green : Color.Red;
if (!isBlacklisted)
{
var count = 1;
Graphics.DrawText(s, entityScreenPos.Translate(0, count * 16), c, FontAlign.Center);
count++;
var s2 = switched ? "switched" : "not switched";
var c2 = switched ? Color.Green : Color.Red;
Graphics.DrawText(s2 + ":" + switchState, entityScreenPos.Translate(0, count * 16), c2,
FontAlign.Center);
count++;
}
if (isTargeted)
if (Keyboard.IsKeyPressed((int) Settings.toggleEntityKey.Value))
toggleSwitchBlacklistItem(entity.Path);
if (Control.MouseButtons == MouseButtons.Left)
{
var clickCount = getEntityClickedCount(entity);
if (!isBlacklisted && entityDistanceToPlayer <= Settings.switchDistance && !switched &&
clickCount <= 15)
{
open(entityScreenPos, prevMousePosition);
clickedEntities[entity.Address] = clickCount + 1;
if (Settings.BlockInput) Mouse.blockInput(true);
}
else if (!isBlacklisted && entityDistanceToPlayer >= Settings.switchDistance &&
!switched && clickCount >= 15)
{
clickedEntities.Clear();
}
if (Settings.BlockInput) Mouse.blockInput(false);
}
}
}
//Chests
if (Settings.chests)
if (entity.HasComponent<Chest>() || entity.Path.ToLower().Contains("chest"))
{
var isOpened = entity.GetComponent<Chest>().IsOpened;
var whitelisted = chestWhitelist != null && chestWhitelist.Contains(entity.Path);
if (isTargetable && !isOpened && whitelisted)
Graphics.DrawText("Open me!", entityScreenPos, Color.LimeGreen, FontAlign.Center);
if (isTargeted)
if (Keyboard.IsKeyPressed((int) Settings.toggleEntityKey.Value))
toggleChestWhitelistItem(entity.Path);
if (Control.MouseButtons == MouseButtons.Left)
{
var clickCount = getEntityClickedCount(entity);
if (isTargetable && whitelisted && entityDistanceToPlayer <= Settings.chestDistance &&
!isOpened && clickCount <= 15)
{
open(entityScreenPos, prevMousePosition);
clickedEntities[entity.Address] = clickCount + 1;
if (Settings.BlockInput) Mouse.blockInput(true);
}
else if (isTargetable && whitelisted &&
entityDistanceToPlayer >= Settings.chestDistance && !isOpened &&
clickCount >= 15)
{
clickedEntities.Clear();
}
if (Settings.BlockInput) Mouse.blockInput(false);
}
}
//Shrines
if (Settings.shrines)
if (entity.HasComponent<Shrine>() || entity.Path.ToLower().Contains("darkshrine"))
{
var isAvailable = entity.GetComponent<Shrine>().IsAvailable;
var whitelisted = chestWhitelist.Contains(entity.Path);
if (isTargetable)
Graphics.DrawText("Get me!", entityScreenPos, Color.LimeGreen, FontAlign.Center);
if (Control.MouseButtons == MouseButtons.Left)
{
var clickCount = getEntityClickedCount(entity);
if (isTargetable && entityDistanceToPlayer <= Settings.shrineDistance &&
clickCount <= 15)
{
open(entityScreenPos, prevMousePosition);
clickedEntities[entity.Address] = clickCount + 1;
if (Settings.BlockInput) Mouse.blockInput(true);
}
else if (isTargetable && entityDistanceToPlayer >= Settings.shrineDistance &&
clickCount >= 15)
{
clickedEntities.Clear();
}
if (Settings.BlockInput) Mouse.blockInput(false);
}
}
}
}
private int getEntityClickedCount(Entity entity)
{
var clickCount = 0;
if (clickedEntities.ContainsKey(entity.Address))
clickCount = clickedEntities[entity.Address];
else
clickedEntities.Add(entity.Address, clickCount);
if (clickCount >= 15) LogMessage(entity.Path + " clicked too often!", 3);
return clickCount;
}
private void open(Vector2 entityScreenPos, Vector2 prevMousePosition)
{
entityScreenPos += windowOffset;
Mouse.moveMouse(entityScreenPos);
Mouse.LeftUp(0);
Mouse.LeftDown(0);
Mouse.LeftUp(0);
Mouse.moveMouse(prevMousePosition);
Mouse.LeftDown(0);
Thread.Sleep(Settings.Speed);
}
private void loadDoorBlacklist()
{
try
{
doorBlacklist = File.ReadAllLines(DirectoryFullName + "\\doorBlacklist.txt").ToList();
}
catch (Exception)
{
File.Create(DirectoryFullName + "\\doorBlacklist.txt");
loadDoorBlacklist();
}
}
private void loadSwitchBlacklist()
{
try
{
switchBlacklist = File.ReadAllLines(DirectoryFullName + "\\switchBlacklist.txt").ToList();
}
catch (Exception)
{
File.Create(DirectoryFullName + "\\switchBlacklist.txt");
loadSwitchBlacklist();
}
}
private void loadChestWhitelist()
{
try
{
chestWhitelist = File.ReadAllLines(DirectoryFullName + "\\chestWhitelist.txt").ToList();
}
catch (Exception)
{
File.Create(DirectoryFullName + "\\chestWhitelist.txt");
loadChestWhitelist();
}
}
private void toggleDoorBlacklistItem(string name)
{
if (doorBlacklist.Contains(name))
{
doorBlacklist.Remove(name);
LogMessage(name + " will now be opened", 5, Color.Green);
}
else
{
doorBlacklist.Add(name);
LogMessage(name + " will now be ignored", 5, Color.Red);
}
File.WriteAllLines(DirectoryFullName + "\\doorBlacklist.txt", doorBlacklist);
}
private void toggleSwitchBlacklistItem(string name)
{
if (switchBlacklist.Contains(name))
{
switchBlacklist.Remove(name);
LogMessage(name + " will now be opened", 5, Color.Green);
}
else
{
switchBlacklist.Add(name);
LogMessage(name + " will now be ignored", 5, Color.Red);
}
File.WriteAllLines(DirectoryFullName + "\\switchBlacklist.txt", switchBlacklist);
}
private void toggleChestWhitelistItem(string name)
{
if (chestWhitelist.Contains(name))
{
chestWhitelist.Remove(name);
LogMessage(name + " will now be ignored", 5, Color.Red);
}
else
{
chestWhitelist.Add(name);
LogMessage(name + " will now be opened", 5, Color.Green);
}
File.WriteAllLines(DirectoryFullName + "\\chestWhitelist.txt", chestWhitelist);
}
public override void AreaChange(AreaInstance area)
{
clickedEntities.Clear();
base.AreaChange(area);
}
}
}