-
Notifications
You must be signed in to change notification settings - Fork 14
/
CubeConverter.ahk
374 lines (324 loc) · 10.7 KB
/
CubeConverter.ahk
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
;========================================================================
;
; CubeConverter v1.5.0
;
; provides multiple usefull functions regarding cube item conversion
;
; Created by DaLeberkasPepi
; https://github.com/DaLeberkasPepi
;
; Last Update: 2020-02-20 18:00 GMT+2
;
;========================================================================
#NoEnv
#IfWinActive, ahk_class D3 Main Window Class
#SingleInstance force
SendMode Input
SetWorkingDir %A_ScriptDir%
SetDefaultMouseSpeed, 0
CoordMode, Pixel, Client
global ColumnCount := 0
, RowCount := 0
, Cycles := 0
global D3ScreenResolution
,NativeDiabloHeight := 1440
,NativeDiabloWidth := 3440
,#ctrls = 4
IfNotExist, Hotkeys.ini
FileAppend,
(
[Settings]
Globalsleep=50
[Hotkeys]
1=^5
2=^6
3=^7
4=j
), Hotkeys.ini
IniRead, Globalsleep, Hotkeys.ini, Settings, Globalsleep
Loop,% #ctrls
{
If (A_Index == 1)
GUI, Add, Text, xm, Hotkey for 1 Slot Items:
If (A_Index == 2)
GUI, Add, Text, xm, Hotkey for 2 Slot Items:
If (A_Index == 3)
GUI, Add, Text, xm, Hotkey for Inventoryclear:
If (A_Index == 4)
GUI, Add, Text, xm, Hotkey for Reforge:
IniRead, savedHK%A_Index%, Hotkeys.ini, Hotkeys, %A_Index%, %A_Space% ;Check for saved hotkeys in INI file.
If savedHK%A_Index% ;Activate saved hotkeys if found.
Hotkey,% savedHK%A_Index%, Label%A_Index% ;Remove tilde (~) and Win (#) modifiers...
StringReplace, noMods, savedHK%A_Index%, ~ ;They are incompatible with hotkey controls (cannot be shown).
StringReplace, noMods, noMods, #,,UseErrorLevel ;Add hotkey controls and show saved hotkeys.
GUI, Add, Hotkey, x+5 vHK%A_Index% gGuiLabel, %noMods% ;Add checkboxes to allow the Windows key (#) as a modifier...
GUI, Add, CheckBox, x+5 vCB%A_Index% Checked%ErrorLevel%, Win ;Check the box if Win modifier is used.
}
GUI, Add, Text, xm, [ms] for Globalsleep:
GUI, Add, Edit, x+5 Limit3 Number gSubmit vGlobalsleep, %Globalsleep%
Menu, Tray, Add ; Creates a separator line.
Menu, Tray, Add, CubeConverter Hotkeys, Hotkeys ; Creates a new menu item.
Return
Hotkeys:
GUI, Show,,CubeConverter Hotkeys
Return
Submit:
GUIControlGet, Globalsleep
IniWrite, %Globalsleep%, Hotkeys.ini, Settings, Globalsleep
Return
GuiClose:
GUI, Hide
IfWinExist, ahk_class D3 Main Window Class
WinActivate, ahk_class D3 Main Window Class
Return
~ESC::Reload
Return
Label1: ;Hotkey for 1 Slot Items
IfWinNotActive, CubeConverter Hotkeys
{
global ItemSize := 1
KanaisCube("KanaisCube")
}
Return
Label2: ;Hotkey for 2 Slot Items
IfWinNotActive, CubeConverter Hotkeys
{
global ItemSize := 2
KanaisCube("KanaisCube")
}
Return
Label3: ;Hotkey for Inventoryclear
IfWinNotActive, CubeConverter Hotkeys
{
If (ItemSize == "")
global ItemSize := 1
KanaisCube("Blacksmith")
}
Return
Label4: ;Hotkey for Reforge
IfWinNotActive, CubeConverter Hotkeys
{
If (ItemSize == "")
global ItemSize := 1
KanaisCube("Reforge")
}
Return
KanaisCube(Setting)
{
GUIControlGet, Globalsleep
GetClientWindowInfo("ahk_class D3 Main Window Class", DiabloWidth, DiabloHeight, DiabloX, DiabloY)
If (D3ScreenResolution != DiabloWidth*DiabloHeight)
{
;all needed coordinates to use the Kanais Cube, all coordinates are based on a resolution of 3440x1440 and calculated later to the used resolution
global Fill := [957, 1121, 2]
, Transmute := [315, 1106, 2]
, TopLeftInv := [2753, 748, 3]
, InvSize := [668, 394, 4]
, SwitchPages := [180, 180, 4]
, Salvage := [220, 390, 2]
, SwitchPagesLeft
, SwitchPagesRight
, Columns := 10
, Rows := 6
, SlotX
, SlotY
;convert coordinates for the used resolution of Diablo III
ConvertCoordinates(Fill)
ConvertCoordinates(Transmute)
ConvertCoordinates(TopLeftInv)
ConvertCoordinates(InvSize)
ConvertCoordinates(SwitchPages)
ConvertCoordinates(Salvage)
;calculate all other needed coordinates of the base coordinates that where converted into the used Diablo III resolution
SlotX := Round(InvSize[1]/Columns)
SlotY := Round(InvSize[2]/Rows)
TopLeftInv[1] := TopLeftInv[1]+SlotX/2
TopLeftInv[2] := TopLeftInv[2]+SlotY/2
SwitchPagesLeft := [Fill[1]-SwitchPages[1], Fill[2]]
SwitchPagesRight := [Fill[1]+SwitchPages[1], Fill[2]]
}
ColumnCount := 0
RowCount := 0
Cycles := 0
If (Setting == "Blacksmith")
MouseClick, left, Salvage[1], Salvage[2]
If (Setting == "Reforge")
{
MouseClick, right, TopLeftInv[1], TopLeftInv[2]
Sleep % Globalsleep
MouseClick, left, Fill[1], Fill[2]
Sleep % Globalsleep
MouseClick, left, Transmute[1], Transmute[2]
Sleep % Globalsleep + 125
MouseClick, left, SwitchPagesRight[1], SwitchPagesRight[2]
Sleep % Globalsleep
MouseClick, left, SwitchPagesLeft[1], SwitchPagesLeft[2]
Sleep % Globalsleep
MouseMove, TopLeftInv[1], TopLeftInv[2]
}
If (Setting != "Reforge"){
Loop
{
++Cycles
XClick := TopLeftInv[1]+SlotX*(ColumnCount)
YClick := TopLeftInv[2]+SlotY*(RowCount)
If (Setting == "KanaisCube")
MouseClick, right, XClick, YClick
If (Setting == "Blacksmith")
{
global AdjustedSleep := Max(Globalsleep - 35, 3)
Sleep % AdjustedSleep
MouseClick, left, XClick, YClick
}
If (ItemSize == 2)
{
ColumnCount++
If (ColumnCount > 9) && (RowCount < 4)
{
ColumnCount := 0
RowCount := RowCount + ItemSize
}
}
Else
{
RowCount++
If (RowCount > 5) && (ColumnCount < 9)
{
RowCount := 0
ColumnCount := ColumnCount + ItemSize
}
}
If (Setting == "KanaisCube")
{
Sleep % Globalsleep
MouseClick, left, Fill[1], Fill[2]
Sleep % Globalsleep
MouseClick, left, Transmute[1], Transmute[2]
Sleep % Globalsleep + 125
MouseClick, left, SwitchPagesRight[1], SwitchPagesRight[2]
Sleep % Globalsleep
MouseClick, left, SwitchPagesLeft[1], SwitchPagesLeft[2]
Sleep % Globalsleep
}
If (Setting == "Blacksmith")
{
Sleep % AdjustedSleep
Send, {Enter}
}
} Until Cycles>=Columns*Rows/ItemSize
}
}
ConvertCoordinates(ByRef Array)
{
GetClientWindowInfo("ahk_class D3 Main Window Class", DiabloWidth, DiabloHeight, DiabloX, DiabloY)
D3ScreenResolution := DiabloWidth*DiabloHeight
Position := Array[3]
;Pixel is always relative to the middle of the Diablo III window
If (Position == 1)
Array[1] := Round(Array[1]*DiabloHeight/NativeDiabloHeight+(DiabloWidth-NativeDiabloWidth*DiabloHeight/NativeDiabloHeight)/2, 0)
;Pixel is always relative to the left side of the Diablo III window or just relative to the Diablo III windowheight
If Else (Position == 2 || Position == 4)
Array[1] := Round(Array[1]*(DiabloHeight/NativeDiabloHeight), 0)
;Pixel is always relative to the right side of the Diablo III window
If Else (Position == 3)
Array[1] := Round(DiabloWidth-(NativeDiabloWidth-Array[1])*DiabloHeight/NativeDiabloHeight, 0)
Array[2] := Round(Array[2]*(DiabloHeight/NativeDiabloHeight), 0)
}
GetClientWindowInfo(ClientWindow, ByRef ClientWidth, ByRef ClientHeight, ByRef ClientX, ByRef ClientY)
{
hwnd := WinExist(ClientWindow)
VarSetCapacity(rc, 16)
DllCall("GetClientRect", "uint", hwnd, "uint", &rc)
ClientWidth := NumGet(rc, 8, "int")
ClientHeight := NumGet(rc, 12, "int")
WinGetPos, WindowX, WindowY, WindowWidth, WindowHeight, %ClientWindow%
ClientX := Floor(WindowX + (WindowWidth - ClientWidth) / 2)
ClientY := Floor(WindowY + (WindowHeight - ClientHeight - (WindowWidth - ClientWidth) / 2))
}
GuiLabel:
If %A_GuiControl% in +,^,!,+^,+!,^!,+^! ;If the hotkey contains only modifiers, return to wait for a key.
return
If InStr(%A_GuiControl%,"vk07") ;vk07 = MenuMaskKey (see below)
GuiControl,,%A_GuiControl%, % lastHK ;Reshow the hotkey, because MenuMaskKey clears it.
Else
validateHK(A_GuiControl)
return
validateHK(GuiControl)
{
global lastHK
Gui, Submit, NoHide
lastHK := %GuiControl% ;Backup the hotkey, in case it needs to be reshown.
num := SubStr(GuiControl,3) ;Get the index number of the hotkey control.
If (HK%num% != "") ;If the hotkey is not blank...
{
StringReplace, HK%num%, HK%num%, SC15D, AppsKey ;Use friendlier names,
StringReplace, HK%num%, HK%num%, SC154, PrintScreen ; instead of these scan codes.
If CB%num% ; If the 'Win' box is checked, then add its modifier (#).
HK%num% := "#" HK%num%
If !RegExMatch(HK%num%,"[#!\^\+]") ; If the new hotkey has no modifiers, add the (~) modifier.
HK%num% := "~" HK%num% ; This prevents any key from being blocked.
checkDuplicateHK(num)
}
If (savedHK%num% || HK%num%) ;Unless both are empty,
setHK(num, savedHK%num%, HK%num%) ; update INI/GUI
}
checkDuplicateHK(num)
{
global #ctrls
Loop,% #ctrls
If (HK%num% = savedHK%A_Index%)
{
dup := A_Index
Loop,6
{
GuiControl,% "Disable" b:=!b, HK%dup% ;Flash the original hotkey to alert the user.
Sleep,200
}
GuiControl,,HK%num%,% HK%num% :="" ;Delete the hotkey and clear the control.
break
}
}
setHK(num,INI,GUI)
{
If INI ;If previous hotkey exists,
Hotkey, %INI%, Label%num%, Off ; disable it.
If GUI ;If new hotkey exists,
Hotkey, %GUI%, Label%num%, On ; enable it.
IniWrite,% GUI ? GUI:null, Hotkeys.ini, Hotkeys, %num%
savedHK%num% := HK%num%
}
#MenuMaskKey vk07 ;Requires AHK_L 38+
#If ctrl := HotkeyCtrlHasFocus()
*AppsKey:: ;Add support for these special keys,
*BackSpace:: ; which the hotkey control does not normally allow.
*Delete::
*Enter::
*Escape::
*Pause::
*PrintScreen::
*Space::
*Tab::
modifier := ""
If GetKeyState("Shift","P")
modifier .= "+"
If GetKeyState("Ctrl","P")
modifier .= "^"
If GetKeyState("Alt","P")
modifier .= "!"
Gui, Submit, NoHide ;If BackSpace is the first key press, Gui has never been submitted.
If (A_ThisHotkey == "*BackSpace" && %ctrl% && !modifier) ;If the control has text but no modifiers held,
GuiControl,,%ctrl% ; allow BackSpace to clear that text.
Else ;Otherwise,
GuiControl,,%ctrl%, % modifier SubStr(A_ThisHotkey,2) ; show the hotkey.
validateHK(ctrl)
return
#If
HotkeyCtrlHasFocus()
{
GuiControlGet, ctrl, Focus ;ClassNN
If InStr(ctrl,"hotkey")
{
GuiControlGet, ctrl, FocusV ;Associated variable
Return, ctrl
}
}