-
Notifications
You must be signed in to change notification settings - Fork 14
/
pHelper.cs
147 lines (117 loc) · 5.36 KB
/
pHelper.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
namespace Turbo.Plugins.Patrick
{
using System.Linq;
using System.Threading;
using Default;
using forms;
using plugins.patrick.skills;
using plugins.patrick.util.config;
using plugins.patrick.util.diablo;
using plugins.patrick.util.input;
using plugins.patrick.util.thud;
public class pHelper : BasePlugin, IInGameTopPainter, IKeyEventHandler, IAfterCollectHandler, INewAreaHandler
{
private IFont watermarkEnabled, watermarkDisabled, version;
private IBrush activeSkillBrush, inactiveSkillBrush;
private Settings settings;
private SkillExecutor skillExecutor;
private Thread settingsThread;
public pHelper()
{
Enabled = true;
}
public override void Load(IController hud)
{
base.Load(hud);
settings = new Settings(Hud);
skillExecutor = new SkillExecutor(settings);
settingsThread = new Thread(() =>
{
settings.ShowDialog();
});
settingsThread.SetApartmentState(ApartmentState.STA);
settingsThread.Start();
watermarkEnabled = Hud.Render.CreateFont("tahoma", 8, 255, 0, 170, 0, true, false, false);
watermarkDisabled = Hud.Render.CreateFont("tahoma", 8, 255, 170, 0, 0, true, false, false);
version = Hud.Render.CreateFont("tahoma", 8, 255, 227, 227, 0, false, false, false);
activeSkillBrush = settings.Hud.Render.CreateBrush(255, 0, 170, 0, 3.14f);
inactiveSkillBrush = settings.Hud.Render.CreateBrush(255, 170, 0, 0, 3.14f);
}
public void OnNewArea(bool newGame, ISnoArea area)
{
if (newGame)
settings.cb_ShowOnlyForCurrentClass_CheckedChanged(null, null);
}
public void OnKeyEvent(IKeyEvent keyEvent)
{
settings.Hotkeys.InvokeIfExists(keyEvent, Hud);
}
public void PaintTopInGame(ClipState clipState)
{
if (clipState != ClipState.BeforeClip)
return;
DrawSkillBrushes();
if (Settings.Active)
watermarkEnabled.DrawText("pHelper", 4, Hud.Window.Size.Height * 0.966f);
else
watermarkDisabled.DrawText("pHelper", 4, Hud.Window.Size.Height * 0.966f);
if (Hud.Window.CursorInsideRect(4, Hud.Window.Size.Height * 0.966f, 70, 20))
version.DrawText("v" + ConfigPersistence.VERSION, 4, Hud.Window.Size.Height * 0.946f);
}
private void DrawSkillBrushes()
{
Hud.Game.Me.Powers.UsedSkills.ForEach(skill =>
{
if (!settings.SnoToDefinitionGroups.TryGetValue(skill.SnoPower.Sno, out var definitionGroupsForSkill) || !definitionGroupsForSkill.active || !Settings.KeyToActive[skill.Key])
inactiveSkillBrush.DrawRectangle(settings.Hud.Render.GetPlayerSkillUiElement(skill.Key).Rectangle);
else
activeSkillBrush.DrawRectangle(settings.Hud.Render.GetPlayerSkillUiElement(skill.Key).Rectangle);
});
}
public void AfterCollect()
{
if (Hud.Game.IsLoading || Hud.Game.IsPaused || !D3Client.IsInForeground() || !Settings.Active)
return;
if (Hud.Input.IsKeyDown(Settings.Keybinds[ConfigPersistence.QOL_KEY_INDEX]))
ExecuteQolMacro();
settings.AutoActions.ExecuteAutoActions(Hud);
if (CharacterCanCast())
ExecuteClassMacros();
}
private void ExecuteQolMacro()
{
if (!Hud.Game.IsInTown || (!Hud.Render.IsShopOpen() && !Hud.Inventory.StashMainUiElement.Visible))
InputSimulator.PostMessageMouseClickLeft(Hud.Window.CursorX, Hud.Window.CursorY);
else if (Hud.Inventory.HoveredItem != null)
Hud.Inventory.GetItemRect(Hud.Inventory.HoveredItem).RightClick();
}
private void ExecuteClassMacros()
{
Hud.Game.Me.Powers.CurrentSkills.ForEach(skill =>
skillExecutor.Cast(skill)
);
}
private bool CharacterCanCast()
{
if (ShouldUpGems())
return false;
return Hud.Game.IsInGame
&& !Hud.Game.IsInTown
&& !Hud.Game.IsLoading
&& Hud.Game.MapMode == MapMode.Minimap
&& !Hud.Game.Me.IsDead
&& Hud.Game.Me.AnimationState != AcdAnimationState.CastingPortal
&& !Hud.Render.IsUiElementVisible(UiPathConstants.Ui.CHAT_INPUT)
&& !Hud.Game.Me.Powers.BuffIsActive(Hud.Sno.SnoPowers.Generic_ActorInvulBuff.Sno)
&& !Hud.Game.Me.Powers.BuffIsActive(Hud.Sno.SnoPowers.Generic_TeleportToPlayerCast.Sno)
&& !Hud.Game.Me.Powers.BuffIsActive(Hud.Sno.SnoPowers.Generic_TeleportToWaypointCast.Sno)
&& !Hud.Game.Me.Powers.BuffIsActive(Hud.Sno.SnoPowers.Generic_AxeOperateGizmo.Sno);
}
private bool ShouldUpGems()
{
if (Hud.Game.Quests.FirstOrDefault(quest => quest.SnoQuest.Sno == Hud.Sno.SnoQuests.NephalemRift_337492.Sno) is IQuest riftQuest)
return riftQuest.QuestStepId == 34;
return false;
}
}
}