-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathOCRcore.ahk
346 lines (324 loc) · 9.17 KB
/
OCRcore.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
#singleinstance force
#NoEnv
SetWorkingDir %A_ScriptDir%
SendMode Input
SetMouseDelay, -1
SetKeyDelay, -1
SetDefaultMouseSpeed, 0
SetControlDelay, -1
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
;Initialize Variables and Coordinates
Global readfirstline := 0
Gosub, CoordinateSystem
IniRead, Tries, OCRsettings.ini, Settings, Tries
IniRead, SleepClick, OCRsettings.ini, Settings, SleepClick
IniRead, Desired, OCRsettings.ini, Settings, Desired
IniRead, DesiredNumber, OCRsettings.ini, Settings, DesiredNumber
IniRead, SleepWait, OCRsettings.ini, Settings, SleepWait
While (Tries > 0) {
Gosub, ClickSelect
Sleep %SleepWait%
Gosub, RunReaders ;; OCRs
IfNotInString, DesiredNumber, - ;;note a damage number
{
IfInString, secondline, %Desired%
{
if (secondlinenumber >= DesiredNumber)
{
IfInString, thirdline, %Desired%
{
if (thirdlinenumber >= secondlinenumber)
{
Gosub, ClickThirdLine
Gosub, ClickSelect
ExitApp
;chose
}
else
{
Gosub, ClickSecondLine
Gosub, ClickSelect
ExitApp
;chose
}
}
IfNotInString, thirdline, %Desired%
{
Gosub, ClickSecondLine
Gosub, ClickSelect
ExitApp
;chose
}
}
else
{
IfInString, thirdline, %Desired%
{
if (thirdlinenumber >= DesiredNumber)
{
Gosub, ClickThirdLine
Gosub, ClickSelect
ExitApp
;chose
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
}
else
{
IfInString, thirdline, %Desired%
{
if (thirdlinenumber >= Desirednumber)
{
Gosub, ClickThirdLine
Gosub, ClickSelect
ExitApp
;chose
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
}
IfInString, DesiredNumber, - ;;it is a damage roll
{
StringSplit, DesiredNumberArray, DesiredNumber, -
IfInString, secondline, %Desired%
{
StringSplit, secondlinenumberArray, secondlinenumber, -
if (secondlinenumberArray1 >= DesiredNumberArray1 and secondlinenumberArray2 >= DesiredNumberArray2)
{
IfInString, thirdline, %Desired%
{
StringSplit, thirdlinenumberArray, thirdlinenumber, -
if (thirdlinenumberArray1 >= secondlinenumberArray1 and thirdlinenumberArray2 >= secondlinenumberArray2)
{
Gosub, ClickThirdLine
Gosub, ClickSelect
ExitApp
;chose
}
else
{
Gosub, ClickSecondLine
Gosub, ClickSelect
ExitApp
;chose
}
}
IfNotInString, thirdline, %Desired%
{
Gosub, ClickSecondLine
Gosub, ClickSelect
ExitApp
;chose
}
}
else
{
IfInString, thirdline, %Desired%
{
StringSplit, thirdlinenumberArray, thirdlinenumber, -
if (thirdlinenumberArray1 >= DesiredNumberArray1 and thirdlinenumberArray2 >= DesiredNumberArray2)
{
Gosub, ClickThirdLine
Gosub, ClickSelect
ExitApp
;chose
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
}
else
{
IfInString, thirdline, %Desired%
{
StringSplit, thirdlinenumberArray, thirdlinenumber, -
if (thirdlinenumberArray1 >= DesiredNumberArray1 and thirdlinenumberArray2 >= DesiredNumberArray2)
{
Gosub, ClickThirdLine
Gosub, ClickSelect
ExitApp
;chose
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
else
{
Gosub, ClickFirstLine
Gosub, ClickSelect
}
}
}
Tries--
}
MsgBox Tries Over
ExitApp
CoordinateSystem:
;Initialize Coordinates and Convert them
global FirstLinePos := [ 75, 375, 445, 420, 2 ]
global SecondLinePos := [ 75, 420, 445, 460, 2 ]
global ThirdLinePos := [ 75, 460, 445, 505, 2 ]
global FirstLineClick := [ 255, 400, 2]
global SecondLineClick := [ 255, 440, 2]
global ThirdLineClick := [ 255, 480, 2]
global SelectClick := [ 255, 780, 2]
wOrigin := 1920
hOrigin := 1080
ConvertCoordinates(FirstLinePos,wOrigin,hOrigin)
ConvertCoordinates(SecondLinePos,wOrigin,hOrigin)
ConvertCoordinates(ThirdLinePos,wOrigin,hOrigin)
ConvertClick(FirstLineClick,wOrigin,hOrigin)
ConvertClick(SecondLineClick,wOrigin,hOrigin)
ConvertClick(ThirdLineClick,wOrigin,hOrigin)
ConvertClick(SelectClick,wOrigin,hOrigin)
return
RunReaders:
;OCR Reader
if (readfirstline = 1){
StringRun := A_ScriptDir . "\Capture2Text\Capture2Text_CLI.exe --clipboard -o lastread.txt --output-file-append --screen-rect """ . FirstLinePos[1] . " " . FirstLinePos[2] . " " . FirstLinePos[3] . " " . FirstLinePos[4] . """"
RunWait, %StringRun%,%A_ScriptDir%, Hide, ocrPID
Process, WaitClose, %ocrPID%
global firstline := clipboard
global firstlinenumber := ExtractNumbers(firstline)
}
StringRun := A_ScriptDir . "\Capture2Text\Capture2Text_CLI.exe --clipboard -o lastread.txt --output-file-append --screen-rect """ . SecondLinePos[1] . " " . SecondLinePos[2] . " " . SecondLinePos[3] . " " . SecondLinePos[4] . """"
RunWait, %StringRun%,%A_ScriptDir%, Hide, ocrPID
Process, WaitClose, %ocrPID%
global secondline := clipboard
global secondlinenumber := ExtractNumbers(secondline)
StringRun := A_ScriptDir . "\Capture2Text\Capture2Text_CLI.exe --clipboard -o lastread.txt --output-file-append --screen-rect """ . ThirdLinePos[1] . " " . ThirdLinePos[2] . " " . ThirdLinePos[3] . " " . ThirdLinePos[4] . """"
RunWait, %StringRun%,%A_ScriptDir%, Hide, ocrPID
Process, WaitClose, %ocrPID%
global thirdline := clipboard
global thirdlinenumber := ExtractNumbers(thirdline)
return
ConvertCoordinates(ByRef Array, wOrigin, hOrigin)
{
WinGetPos, , , DiabloWidth, DiabloHeight, Diablo III
D3ScreenResolution := DiabloWidth*DiabloHeight
Position := Array[5]
;Pixel is always relative to the middle of the Diablo III window
If (Position == 1){
Array[1] := Round(Array[1]*DiabloHeight/hOrigin+(DiabloWidth-wOrigin*DiabloHeight/hOrigin)/2, 0)
Array[3] := Round(Array[3]*DiabloHeight/hOrigin+(DiabloWidth-wOrigin*DiabloHeight/hOrigin)/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/hOrigin), 0)
Array[3] := Round(Array[3]*(DiabloHeight/hOrigin), 0)
}
;Pixel is always relative to the right side of the Diablo III window
If Else (Position == 3){
Array[1] := Round(DiabloWidth-(wOrigin-Array[1])*DiabloHeight/hOrigin, 0)
Array[3] := Round(DiabloWidth-(wOrigin-Array[3])*DiabloHeight/hOrigin, 0)
}
Array[2] := Round(Array[2]*(DiabloHeight/hOrigin), 0)
Array[4] := Round(Array[4]*(DiabloHeight/hOrigin), 0)
}
ConvertClick(ByRef Array, wOrigin, hOrigin)
{
WinGetPos, , , DiabloWidth, DiabloHeight, Diablo III
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/hOrigin+(DiabloWidth-wOrigin*DiabloHeight/hOrigin)/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/hOrigin), 0)
}
;Pixel is always relative to the right side of the Diablo III window
If Else (Position == 3){
Array[1] := Round(DiabloWidth-(wOrigin-Array[1])*DiabloHeight/hOrigin, 0)
}
Array[2] := Round(Array[2]*(DiabloHeight/hOrigin), 0)
}
ExtractNumbers(MyString){
firstdot := 0
Loop, Parse, MyString
{
If A_LoopField is Number
NewVar .= A_LoopField
IfInString,A_LoopField,.
{
if (firstdot = 0){
NewVar .= A_LoopField
firstdot := 1
}
}
IfInString,A_LoopField,`,
NewVar .= A_LoopField
IfInString,A_LoopField,-
NewVar .= A_LoopField
}
checklastdigit := SubStr(NewVar, 0) ;;removes a last dot
IfInString, checklastdigit , .
StringTrimRight, NewVar, NewVar, 1
StringReplace, NewVar, NewVar,`,,., ;;replaces commas with dots
FoundPos := InStr(NewVar, "-")
if (FoundPos = 1){
StringTrimLeft,NewVar,NewVar,1
}
Return NewVar
}
ClickFirstLine:
x1 := FirstLineClick[1]
y1 := FirstLineClick[2]
SendInput, {Click %x1%, %y1%}
Sleep %SleepClick%
return
ClickSecondLine:
x1 := SecondLineClick[1]
y1 := SecondLineClick[2]
SendInput, {Click %x1%, %y1%}
Sleep %SleepClick%
return
ClickThirdLine:
x1 := ThirdLineClick[1]
y1 := ThirdLineClick[2]
SendInput, {Click %x1%, %y1%}
Sleep %SleepClick%
return
ClickSelect:
x1 := SelectClick[1]
y1 := SelectClick[2]
SendInput, {Click %x1%, %y1%}
Sleep %SleepClick%
return
F12::ExitApp