-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverclocker.ahk
371 lines (336 loc) · 10.8 KB
/
overclocker.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
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, Pixel, Client ; Better portability
CoordMode, Mouse, Client ; Better portability
global msi_name := "MSI Afterburner"
global msi_graph_name := "Voltage/Frequency curve editor"
global msi_path := "C:\Program Files (x86)\MSI Afterburner\MSIAfterburner.exe"
global msi_yellow := 0x008080
global msi_node_grey := 0x7F7F7F
global msi_node_selected := 0xFFFFFF
global msi_fan_red := 0x06069E
global msi_fan_selected := 0x1F1FB7
global msi_graph_top_margin := 32
global msi_graph_bottom_margin := 41
global msi_graph_left_margin := 32
global msi_graph_right_margin := 33
global msi_fan_x := 283
global msi_fan_y := 305
global msi_curve_button_x := 291
global msi_curve_button_y := 219
global msi_profile_4_x := 638
global msi_profile_4_y := 395
global msi_profile_5_x := 666
global msi_profile_5_y := 395
global msi_save_x := 693
global msi_save_y := 395
global msi_apply_x := 469
global msi_apply_y := 339
global 3dmark_name := "3DMark Basic Edition"
global 3dmark_path := "C:\Program Files\Futuremark\3DMark\3DMark.exe"
global 3dmark_workload_name = "3DMark Workload"
global 3dmark_orange := 0x167DFD
global 3dmark_grey := 0xFBFBFB
global 3dmark_pass_x1 := 630
global 3dmark_pass_x2 := 670
global 3dmark_pass_y := 210
global 3dmark_benchmarks_x := 910
global 3dmark_benchmarks_y := 23
global 3dmark_firestrike_x := 1119
global 3dmark_firestrike_y := 715
global 3dmark_benchrun_x := 1197
global 3dmark_benchrun_y := 311
global powershell_name := "Administrator: Windows PowerShell"
global stopscript = 0
start_powershell()
sleep_or_exit(20)
main()
main() {
WinClose, %msi_graph_name%
Loop {
if (get_setting("State", "Complete", 0)) {
logi("Overclocking process is marked complete, closing script.")
ExitApp
}
if (get_setting("State", "Unstable", 0))
adjust_clock("Down")
else if (get_setting("State", "Stable", 0))
adjust_clock("Up")
run_iterations()
}
}
run_iterations() {
start_app(msi_name, msi_path)
Loop {
WinActivate, %msi_name%
PixelGetColor, fan, %msi_fan_x%, %msi_fan_x%
if (fan <> msi_fan_red) and (fan <> msi_fan_selected) {
click %msi_fan_x%, %msi_fan_y%
sleep_or_exit(1)
} else
Break
}
WinActivate, %msi_name%
click %msi_profile_5_x%, %msi_profile_5_y%
sleep_or_exit(1)
WinActivate, %msi_name%
click %msi_apply_x%, %msi_apply_y%
iteration := get_setting("State", "Iteration", 0)
Loop {
iteration := iteration + 1
logi("Starting iteration " . iteration)
pass := get_stress_test_stability()
if (pass) {
logi("Successfully completed iteration " . iteration)
if (get_setting("State", "Rising", 1)) {
if (iteration >= get_setting("UserSettings", "IterationsForStableQuick", 1)) {
IniWrite, 1, overclocker.ini, State, Stable
IniWrite, 0, overclocker.ini, State, Iteration
Return
}
} else if (iteration >= get_setting("UserSettings", "IterationsForStableFinal", 1)) {
logi("Successfully completed " . iteration . " iterations. Clock is considered stable.")
WinClose, %msi_graph_name%
WinActivate, %msi_name%
click %msi_curve_button_x%, %msi_curve_button_y%
sleep_or_exit(2)
WinActivate, %msi_graph_name%
SendInput L ;remove lock
WinClose, %msi_graph_name%
sleep_or_exit(1)
WinActivate, %msi_name%
click %msi_save_x%, %msi_save_y%
sleep_or_exit(1)
WinActivate, %msi_name%
click %msi_profile_4_x%, %msi_profile_4_y%
logi("Saved current stable clock to profile 4.")
start_node := get_setting("UserSettings", "HighNode", 30)
node := get_setting("State", "Node", start_node)
if (node <= get_setting("UserSettings", "LowNode", 1)) {
logi("Overclock tuning is complete!")
IniWrite, 1, overclocker.ini, State, Complete
Shutdown, 1
}
node := node - 1
IniWrite, 1, overclocker.ini, State, Rising
IniWrite, %node%, overclocker.ini, State, Node
IniWrite, 1, overclocker.ini, State, Stable
IniWrite, 0, overclocker.ini, State, Iteration
Return
} else {
IniWrite, %iteration%, overclocker.ini, State, Iteration
}
} else {
;sleep in case the logs haven't been read yet
sleep_or_exit(10)
TrayTip, INTERRUPTED, Will raise Unknown Error if script is not paused within 10 seconds, 10, 2
sleep_or_exit(10)
loge("Unknown Error on iteration " . iteration)
}
}
}
get_stress_test_stability() { ;return 0 for unknown, 1 for stable, and should restart during sleeps if unstable
start_app(3dmark_name, 3dmark_path)
click %3dmark_benchmarks_x%, %3dmark_benchmarks_y%
sleep_or_exit(1)
WinActivate, %3dmark_name%
click %3dmark_firestrike_x%, %3dmark_firestrike_y%
sleep_or_exit(1)
WinActivate, %3dmark_name%
click %3dmark_benchrun_x%, %3dmark_benchrun_y%
pass := 0
Loop {
if (!WinExist(3dmark_workload_name)) {
if (A_Index > 60) {
loge("Benchmark did not start")
}
sleep_or_exit(1)
} else {
break
}
}
Loop {
if (!WinExist(3dmark_workload_name)) {
sleep_or_exit(10)
if (!WinExist(3dmark_workload_name)) {
if !WinActive(3dmark_name) {
return 0
} else {
break
}
}
}
sleep_or_exit(1)
}
sleep_or_exit(20)
WinActivate, %3dmark_name%
PixelSearch, dummy_x, dummy_y, %3dmark_pass_x1%, %3dmark_pass_y%, %3dmark_pass_x2%, %3dmark_pass_y%, %3dmark_orange%, 0, Fast
if (ErrorLevel = 0) {
PixelSearch, dummy_x, dummy_y, %3dmark_pass_x1%, %3dmark_pass_y%, %3dmark_pass_x2%, %3dmark_pass_y%, %3dmark_grey%, 0, Fast
if (ErrorLevel = 0)
pass := 1
}
return pass
}
adjust_clock(direction) {
if direction = Down
distance := get_setting("UserSettings", "DroppingIncrements", 12)
else if direction = Up
distance := get_setting("UserSettings", "ClimbingIncrements", 24)
else
loge("Invalid clock adjustment direction: " . direction)
start_node := get_setting("UserSettings", "HighNode", 30)
node := get_setting("State", "Node", start_node)
start_app(msi_name, msi_path)
click %msi_profile_5_x%, %msi_profile_5_y%
sleep_or_exit(1)
WinClose, %msi_graph_name%
WinActivate, %msi_name%
click %msi_curve_button_x%, %msi_curve_button_y%
sleep_or_exit(2)
logi("Searching for node " . node . "...")
WinActivate, %msi_graph_name%
WinGetPos, X, Y, width, height, %msi_graph_name%
column := msi_graph_left_margin
msi_graph_bottom := height - msi_graph_bottom_margin
msi_graph_right := width - msi_graph_right_margin
SendInput L ;remove lock
Loop, %node% {
WinActivate, %msi_graph_name%
columns := msi_graph_right - column + 1
Loop %columns% {
PixelSearch, node_x, node_y, %column%, %msi_graph_top_margin%, %column%, %msi_graph_bottom%, %msi_node_grey%, 0, Fast
if ErrorLevel {
column := column + 1
} else {
break
}
}
if ErrorLevel
loge("Could not find node " . A_Index)
column := column + 6
sleep_or_exit(0)
}
node_x := node_x + 2
node_y := node_y + 2
WinActivate, %msi_graph_name%
click %node_x%, %node_y%
sleep_or_exit(1)
WinActivate, %msi_graph_name%
PixelGetColor, color_target, %node_x%, %node_y%
if not (color_target = msi_node_selected)
loge("Could not click node " . node)
logi("Adjusting node " . node . " " . direction . " " . distance . "MHz...")
WinActivate, %msi_graph_name%
SendInput {%direction% %distance%}
sleep_or_exit(1)
WinActivate, %msi_graph_name%
SendInput L ;reapply lock
sleep_or_exit(1)
WinActivate, %msi_graph_name%
PixelSearch, dummy_x, dummy_y, node_x - 8, %node_y%, node_x + 8, node_y + 20, %msi_yellow%, 0, Fast
if ErrorLevel
loge("Could not lock selection")
WinClose, %msi_graph_name%
sleep_or_exit(1)
WinActivate, %msi_name%
click %msi_save_x%, %msi_save_y%
sleep_or_exit(1)
WinActivate, %msi_name%
click %msi_profile_5_x%, %msi_profile_5_y%
IniWrite, 0, overclocker.ini, State, Unstable
IniWrite, 0, overclocker.ini, State, Stable
IniWrite, 0, overclocker.ini, State, Iteration
logi("Done.")
}
logi(msg) {
FormatTime, timestamp,, yyyy-MM-dd HH:mm:ss
entry = %timestamp% - [INFO] - %msg%`n
FileAppend, %entry%, overclocker.log
TrayTip, INFO, %msg%, 4, 1
}
loge(msg) {
if get_setting("UserSettings", "ScreenshotOnError", 1) {
SendInput {RWin Down}{PrintScreen}{RWin Up}
}
FormatTime, timestamp,, yyyy-MM-dd HH:mm:ss
entry = %timestamp% - [ERROR] - %msg%, aborting.`n
FileAppend, %entry%, overclocker.log
TrayTip, ERROR, %msg%`, aborting., 4, 3
close_apps()
if get_setting("UserSettings", "RestartOnError", 0) {
Shutdown, 2
}
Exit
}
run_then_close() {
run_iterations()
close_apps()
}
sleep_or_exit(seconds) {
check_exit()
loop % seconds * 2 {
sleep 500
FileRead, crashed, crashed.dat
if crashed {
FileDelete, crashed.dat
FileAppend, 0, crashed.dat
logi("Unstable Clock")
IniWrite, 1, overclocker.ini, State, Unstable
IniWrite, 0, overclocker.ini, State, Rising
IniWrite, 0, overclocker.ini, State, Iteration
logi("Restarting...")
Shutdown, 2
}
check_exit()
}
}
check_exit() {
if (stopscript = 1) {
logi("Received exit signal, stopping...")
SendInput {Esc} ;Close 3dmark workload if running
close_apps()
Exit
}
}
close_apps() {
WinClose, %3dmark_name%
WinClose, %msi_name%
WinClose, %powershell_name%
}
start_app(app_title, path) {
If !WinExist(app_title) {
logi("Starting " . app_title . "...")
run %path%
Loop {
If !WinExist(app_title) {
if (A_Index > 60)
loge(app_title . " took too long")
sleep_or_exit(1)
} else
Break
}
}
sleep_or_exit(1)
WinActivate, %app_title%
}
get_setting(section, key, default) {
IniRead, x, overclocker.ini, %section%, %key%, %default%
IniWrite, %x%, overclocker.ini, %section%, %key%
Return %x%
}
start_powershell() {
Run C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "restart_on_crash.ps1"
WinMinimize %powershell_name%
}
^p::
if (stopscript) {
stopscript = 0
start_powershell()
main()
} else {
stopscript = 1
}
Return