-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoBlink.cs
272 lines (216 loc) · 9.01 KB
/
AutoBlink.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
using ExileCore2;
using ExileCore2.PoEMemory.Components;
using ExileCore2.PoEMemory.MemoryObjects;
using ExileCore2.Shared.Cache;
using ExileCore2.Shared.Helpers;
using ExileCore2.Shared.Nodes;
using static ExileCore2.Shared.Nodes.HotkeyNodeV2;
using Graphics = ExileCore2.Graphics;
using System.Threading.Tasks;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
namespace AutoBlink;
public class AutoBlink : BaseSettingsPlugin<AutoBlinkSettings>
{
private bool _isActive = false;
private readonly string _blinkSkillName = "BlinkPlayer";
private Helpers helpers;
private Camera Camera => GameController.IngameState.Camera;
private bool passiveTreeOpen = false;
private IngameUIElements IngameUi => GameController.IngameState.IngameUi;
ActorSkill blinkSkill = null;
private bool initialised = false;
private bool runPlugin =>
Settings.Enable
&& initialised
&& Settings.IgnoreUIElements
|| (!IngameUi.TreePanel.IsVisible
&& !IngameUi.ChatTitlePanel.IsVisible);
private int safetyDelay => Settings.SafetyDelay;
private int longestCastDelay => Settings.LongestCastDelay;
private int blinkAnimationDelay => Settings.BlinkAnimationDelay;
private int targetWeaponSet => Settings.WeaponSet == "2" ? 1 : 0;
private float blinkCooldown = 1000;
private readonly Stopwatch _blinkCooldownStopWatch = Stopwatch.StartNew();
private bool blinkInCooldown => _blinkCooldownStopWatch.ElapsedMilliseconds <= blinkCooldown;
private HotkeyNode keyBlink => Settings.KeyAutoBlink;
private HotkeyNodeValue keyWeaponSwap => Settings.KeyWeaponSwap.Value;
private HotkeyNodeValue keyDodgeRoll => Settings.KeyDodgeRoll.Value;
private int sourceWeaponSet = 0;
private bool weaponSetChanged = false;
private string imageFilename = "blink.png";
private const string imagePath = "images\\blink.png";
private IntPtr imageId;
public override bool Initialise()
{
initialised = true;
return base.Initialise();
}
public override void Tick()
{
if (!runPlugin) return;
if (!LoadBlinkSkill()) return;
RestoreSourceWeaponSet();
RunAutoBlink();
}
public override void Render()
{
if (!runPlugin) return;
if (!LoadBlinkSkill()) return;
RenderTextBlink();
RenderTextWeaponSet();
RenderImageBlink();
}
public override void AreaChange(AreaInstance area)
{
base.AreaChange(area);
GameController.PluginBridge.SaveMethod("AutoBlink.IsActive", () => _isActive); // Fixed capitalization
LogMessage("AutoBlink.IsActive registered in PluginBridge (via AreaChange)"); // Fixed log message too
}
private void RenderTextWeaponSet()
{
if (!Settings.Render.WeaponSet.Text.Enabled
|| !Settings.Render.WeaponSet.Text.ShowInTown && GameController.Area.CurrentArea.IsTown
|| !Settings.Render.WeaponSet.Text.ShowInHideout && GameController.Area.CurrentArea.IsHideout)
{
return;
}
int activeWeaponSet = GetActiveWeaponSet();
if (activeWeaponSet != targetWeaponSet && !Settings.Render.WeaponSet.Text.AlwaysShow) return;
var text = activeWeaponSet == 0
? Settings.Render.WeaponSet.Text.WeaponSet1Text
: Settings.Render.WeaponSet.Text.WeaponSet2Text;
var color = activeWeaponSet == 0
? Settings.Render.WeaponSet.Text.WeaponSet1Color
: Settings.Render.WeaponSet.Text.WeaponSet2Color;
if (Settings.Render.WeaponSet.Text.Background)
{
float bgPositionLeft = Settings.Render.WeaponSet.Text.PositionX;
float bgPositionTop = Settings.Render.WeaponSet.Text.PositionY;
ColorNode bgColor = Settings.Render.WeaponSet.Text.BackgroundColor;
helpers.DrawBackgroundRectangle(Graphics, text, bgColor, bgPositionLeft, bgPositionTop);
}
float positionX = Settings.Render.WeaponSet.Text.PositionX;
float positionY = Settings.Render.WeaponSet.Text.PositionY;
helpers.DrawText(Graphics, text, color, positionX, positionY);
}
private void RenderTextBlink()
{
if (!Settings.Render.Blink.Text.Enabled
|| !Settings.Render.Blink.Text.ShowInTown && GameController.Area.CurrentArea.IsTown
|| !Settings.Render.Blink.Text.ShowInHideout && GameController.Area.CurrentArea.IsHideout)
{
return;
}
bool isBlinkInCooldown = helpers.IsBlinkInCooldown(GameController);
if (isBlinkInCooldown && !Settings.Render.Blink.Text.AlwaysShow) return;
var text = Settings.Render.Blink.Text.AvailableText;
var color = Settings.Render.Blink.Text.AvailableColor;
if (Settings.Render.Blink.Text.AlwaysShow)
{
text = isBlinkInCooldown
? Settings.Render.Blink.Text.UnavailableText
: Settings.Render.Blink.Text.AvailableText;
color = isBlinkInCooldown
? Settings.Render.Blink.Text.UnavailableColor
: Settings.Render.Blink.Text.AvailableColor;
}
if (Settings.Render.Blink.Text.Background)
{
float bgPositionLeft = Settings.Render.Blink.Text.PositionX;
float bgPositionTop = Settings.Render.Blink.Text.PositionY;
ColorNode bgColor = Settings.Render.Blink.Text.BackgroundColor;
helpers.DrawBackgroundRectangle(Graphics, text, bgColor, bgPositionLeft, bgPositionTop);
}
float textPositionX = Settings.Render.Blink.Text.PositionX;
float textPositionY = Settings.Render.Blink.Text.PositionY;
helpers.DrawText(Graphics, text, color, textPositionX, textPositionY);
}
private void RenderImageBlink()
{
if (!Settings.Render.Blink.Image.Enabled
|| !Settings.Render.Blink.Image.ShowInTown && GameController.Area.CurrentArea.IsTown
|| !Settings.Render.Blink.Image.ShowInHideout && GameController.Area.CurrentArea.IsHideout)
{
return;
}
bool isBlinkInCooldown = helpers.IsBlinkInCooldown(GameController);
var imgColor = isBlinkInCooldown
? Settings.Render.Blink.Image.ColorCooldown
: Settings.Render.Blink.Image.ColorAvailable;
float imgPosX = Settings.Render.Blink.Image.PositionX;
float imgPosY = Settings.Render.Blink.Image.PositionY;
float imgSizeX = Settings.Render.Blink.Image.SizeX;
float imgSizeY = Settings.Render.Blink.Image.SizeY;
helpers.DrawImage(Graphics, DirectoryFullName, imagePath, imageFilename, imgPosX, imgPosY, imgSizeX, imgSizeY, imgColor);
}
private async void RunAutoBlink()
{
bool autoBlinkHotkeyPressed = Input.IsKeyDown(keyBlink);
if (autoBlinkHotkeyPressed)
{
if (!blinkInCooldown && blinkSkill.CanBeUsed)
{
try
{
_isActive = true;
LogMessage($"AutoBlink active state START: {_isActive}");
sourceWeaponSet = GetActiveWeaponSet();
await Task.Delay(longestCastDelay);
if (targetWeaponSet != sourceWeaponSet)
{
PressKey(keyWeaponSwap);
weaponSetChanged = true;
}
// use Blink Skill by pressing dodge roll key
PressKey(keyDodgeRoll);
// Add a safety delay in between key presses
await Task.Delay(blinkAnimationDelay);
_blinkCooldownStopWatch.Restart();
_isActive = false;
LogMessage($"AutoBlink active state END: {_isActive}");
}
catch (Exception ex)
{
DebugWindow.LogError($"{ex.Message}");
_isActive = false;
LogMessage($"AutoBlink active state ERROR: {_isActive}");
}
}
}
}
private async Task PressKey(HotkeyNodeValue key)
{
InputHelper.SendInputPress(key);
await Task.Delay(safetyDelay);
}
private int GetActiveWeaponSet()
{
Stats stats = GameController.Player.GetComponent<Stats>();
return stats?.ActiveWeaponSetIndex ?? 0;
}
public async void RestoreSourceWeaponSet()
{
if (weaponSetChanged)
{
int activeWeaponSet = GetActiveWeaponSet();
if (activeWeaponSet != sourceWeaponSet)
{
PressKey(keyWeaponSwap);
}
weaponSetChanged = false;
}
}
public bool LoadBlinkSkill()
{
if (!GameController.Player.HasComponent<Actor>()) return false;
helpers = new Helpers(_blinkSkillName);
blinkSkill = helpers.FetchBlinkSkill(GameController);
if (blinkSkill == null) return false;
blinkCooldown = blinkSkill.Cooldown;
return true;
}
}