This repository has been archived by the owner on Jan 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
realmscript.ahk
428 lines (400 loc) · 14 KB
/
realmscript.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
; include global options
global USE_CUSTOM_CURSOR, CUSTOM_CURSOR, CHAT_ACTIVATION_KEY
, TELL_ACTIVATION_KEY, GUILD_ACTIVATION_KEY, SCROLL_CHAT_UP_KEY
, SCROLL_CHAT_DOWN_KEY, DISABLE_RESIZE
#include options.ahk
; check version, install files (for compiled scripts), set up global vars,
; start hotkey checking
goto STARTUP
; include hotkeys (must happen after window title group creation)
#include hotkeys.ahk
STARTUP:
; check AHK version, exit if incompatible (v1.1.13 req for arrays)
requiredVersion := "1.1.13"
runningVersion := A_AhkVersion
requiredVersionParts := StrSplit(requiredVersion, ".")
runningVersionParts := StrSplit(runningVersion, ".")
Loop % requiredVersionParts.MaxIndex()
{
if (runningVersionParts[A_Index] > requiredVersionParts[A_Index]) {
break
} else if (runningVersionParts[A_Index]
< requiredVersionParts[A_Index]) {
ahkSite := "https://autohotkey.com"
MsgBox, 16, You must update AHK!, % "Your version of AutoHotKey (v"
. runningVersion . ") is not sufficient to correctly run "
. "realmscript!`nPlease download and install the latest version "
. "from " . ahkSite . " and run realmscript again."
Run, % ahkSite
ExitApp
}
}
; ensure working directories, create dependencies for compiled versions
IfNotExist, img/
FileCreateDir, img
IfNotExist, img/cursors/
FileCreateDir, img/cursors
FileInstall, img/change-high.png, img/change-high.png, 1
FileInstall, img/change-med.png, img/change-med.png, 1
FileInstall, img/change-low.png, img/change-low.png, 1
FileInstall, img/close-low.png, img/close-low.png, 1
FileInstall, img/enter-high.png, img/enter-high.png, 1
FileInstall, img/enter-med.png, img/enter-med.png, 1
FileInstall, img/enter-low.png, img/enter-low.png, 1
FileInstall, img/inv-high.png, img/inv-high.png, 1
FileInstall, img/inv-med.png, img/inv-med.png, 1
FileInstall, img/inv-low.png, img/inv-low.png, 1
FileInstall, img/realmscript.ico, img/realmscript.ico, 1
FileInstall, img/realmscript_paused.ico, img/realmscript_paused.ico, 1
FileInstall, img/cursors/bmj_precision.cur, img/cursors/bmj_precision.cur
; set script directives, global settings, global vars
OnExit, ExitSub
#include includes/SetSystemCursor.ahk
#NoEnv
#SingleInstance force
#ClipboardTimeout -1
SetWorkingDir %A_ScriptDir%
SendMode Input
SetKeyDelay 0
SetMouseDelay 0
SetTitleMatchMode 3
global menuHeight, vBorderWidth, hBorderWidth, titleHeight
SysGet, menuHeight, 15
SysGet, vBorderWidth, 32
SysGet, hBorderWidth, 33
SysGet, titleHeight, 4
; set icon
Menu, Tray, Icon, img/realmscript.ico, , 1
Suspend On
GroupAdd rotmg, % "Realm of the Mad God"
GroupAdd rotmg, % "Realm of the Mad God - Mozilla Firefox"
GroupAdd rotmg, % "Realm of the Mad God - Mozilla Firefox "
. "(Private Browsing)"
GroupAdd rotmg, % "Realm of the Mad God - Google Chrome"
GroupAdd rotmg, % "Realm of the Mad God - Opera"
GroupAdd rotmg, % "Realm of the Mad God - Windows Internet Explorer"
GroupAdd rotmg, % "Realm of the Mad God | Kabam"
GroupAdd rotmg, % "Realm of the Mad God | Kabam - Mozilla Firefox"
GroupAdd rotmg, % "Realm of the Mad God | Kabam - Mozilla Firefox "
. "(Private Browsing)"
GroupAdd rotmg, % "Realm of the Mad God | Kabam - Google Chrome"
GroupAdd rotmg, % "Realm of the Mad God | Kabam - Opera"
GroupAdd rotmg, % "Realm of the Mad God | Kabam - Windows Internet Explorer"
GroupAdd rotmg, % "Play Realm of the Mad God, a free online game on "
. "Kongregate"
GroupAdd rotmg, % "Play Realm of the Mad God, a free online game on "
. "Kongregate - Mozilla Firefox"
GroupAdd rotmg, % "Play Realm of the Mad God, a free online game on "
. "Kongregate - Mozilla Firefox (Private Browsing)"
GroupAdd rotmg, % "Play Realm of the Mad God, a free online game on "
. "Kongregate - Google Chrome"
GroupAdd rotmg, % "Play Realm of the Mad God, a free online game on "
. "Kongregate - Opera"
GroupAdd rotmg, % "Play Realm of the Mad God, a free online game on "
. "Kongregate - Windows Internet Explorer"
GroupAdd rotmg, % "Adobe Flash Player 10"
GroupAdd rotmg, % "Adobe Flash Player 11"
GroupAdd rotmg, % "Adobe Flash Player 12"
GroupAdd rotmg, % "Adobe Flash Player 13"
GroupAdd rotmg, % "Adobe Flash Player 14"
GroupAdd rotmg, % "Adobe Flash Player 15"
GroupAdd rotmg, % "Adobe Flash Player 16"
GroupAdd rotmg, % "Adobe Flash Player 17"
GroupAdd rotmg, % "Adobe Flash Player 18"
GroupAdd rotmg, % "Adobe Flash Player 19"
GroupAdd rotmg, % "Adobe Flash Player 20"
GroupAdd rotmg, % "Adobe Flash Player 21"
GroupAdd rotmg, % "Adobe Flash Player 22"
GroupAdd rotmg, % "Adobe Flash Player 23"
GroupAdd rotmg, % "Adobe Flash Player 24"
GroupAdd rotmg, % "Adobe Flash Player 25"
GroupAdd rotmg, % "Adobe Flash Player 26"
GroupAdd rotmg, % "Adobe Flash Player 27"
GroupAdd rotmg, % "Adobe Flash Player 28"
GroupAdd rotmg, % "Adobe Flash Player 29"
GroupAdd rotmg, % "Adobe Flash Player 30"
WinNotActive()
Return
WinActive() {
WinGetTitle, winTitle, A
WinGet, winProcessName, ProcessName, A
Suspend Off
Menu, Tray, Icon, img/realmscript.ico, , 1
if (DISABLE_RESIZE
&& (InStr(winTitle, "Adobe Flash Player")
|| winProcessName == "Realm of the Mad God.exe")) {
WinSet, Style, -0x40000, ahk_group rotmg ; disable resize borders
}
if (USE_CUSTOM_CURSOR) {
SetSystemCursor("img/cursors/"+CUSTOM_CURSOR,0,0)
}
WinWaitNotActive ahk_group rotmg
{
WinNotActive()
}
}
WinNotActive() {
Suspend on
Menu, Tray, Icon, img/realmscript_paused.ico, , 1
if (USE_CUSTOM_CURSOR) {
RestoreCursors()
}
WinWaitActive ahk_group rotmg
{
WinActive()
}
}
; convert /tp to /teleport in the game chat
:*:/tp::
ClipSaved := ClipboardAll
clipboard := "/teleport"
Blockinput, on
Send ^a
Send ^v
Send {Space}
Blockinput, off
Sleep 100
clipboard := ClipSaved
ClipSaved := "" ; save memory
Return
; sends passed string to the chat using the specified mode
sendChat(message, mode="public") {
if (mode == "public") {
activationKey = %CHAT_ACTIVATION_KEY%
key = Enter
} else if (mode == "guild") {
activationKey = %GUILD_ACTIVATION_KEY%
key = g
} else if (mode == "tell") {
activationKey = %TELL_ACTIVATION_KEY%
key = Tab
}
if (activationKey) {
key = %activationKey%
}
ClipSaved := ClipboardAll
clipboard := message
Blockinput, on
Send {%key%}
Send ^v
Send {Enter}
Blockinput, off
Sleep 100
clipboard := ClipSaved
ClipSaved := "" ; save memory
}
tpTarget() {
global tptarget
InputBox, tptarget, Teleport target, Please enter a person to teleport to:
}
scrollChat(direction:="up") {
if (direction == "up") {
if (SCROLL_CHAT_UP_KEY) {
key = %SCROLL_CHAT_UP_KEY%
} else {
key = PgUp
}
} else if (direction == "down") {
if (SCROLL_CHAT_DOWN_KEY) {
key = %SCROLL_CHAT_DOWN_KEY%
} else {
key = PgDn
}
}
Send {%key%}
}
; interact key replacement
interact() {
MouseGetPos, mousePosX, mousePosY
WinGetPos, , , winSizeX, winSizeY, A
stretched := false
if (!imageQualitySearch("enter", imageLocX, imageLocY)) {
stretched := !imageQualitySearch("change", imageLocX, imageLocY)
}
if (stretched) {
clientButtonX := 698
clientButtonY := 575
stretchedWindowPosition(clientButtonX, clientButtonY, stretchedX, stretchedY)
windowPosToClientPos(stretchedX, stretchedY, buttonCenterX, buttonCenterY)
} else {
imageSearchSizeX := 76
imageSearchSizeY := 30
windowPosToClientPos(imageLocX, imageLocY, posX, posY)
buttonCenterX := posX + (imageSearchSizeX / 2)
buttonCenterY := posY + (imageSearchSizeY / 2)
}
BlockInput, on
CoordMode, Mouse, Client
MouseMove, buttonCenterX, buttonCenterY
SendEvent {LButton Down}
SendEvent {LButton Up}
CoordMode, Mouse, Window
MouseMove, mousePosX, mousePosY
BlockInput, off
stretched := false
}
closeAd() {
MouseGetPos, mousePosX, mousePosY
WinGetPos, , , winSizeX, winSizeY, A
stretched := !imageQualitySearch("close", imageLocX, imageLocY)
if (stretched) {
clientButtonX := 637
clientButtonY := 104
stretchedWindowPosition(clientButtonX, clientButtonY, stretchedX, stretchedY)
windowPosToClientPos(stretchedX, stretchedY, buttonCenterX, buttonCenterY)
} else {
imageSearchSizeX := 24
imageSearchSizeY := 25
windowPosToClientPos(imageLocX, imageLocY, posX, posY)
buttonCenterX := posX + Floor(imageSearchSizeX / 2)
buttonCenterY := posY + Floor(imageSearchSizeY / 2)
}
BlockInput, on
CoordMode, Mouse, Client
MouseMove, buttonCenterX, buttonCenterY
SendEvent {LButton Down}
SendEvent {LButton Up}
CoordMode, Mouse, Window
MouseMove, mousePosX, mousePosY
BlockInput, off
stretched := false
}
; item swap function
; move the mouse to the correct slot, double-click, and move it back
invSwap(slot) {
MouseGetPos, mousePosX, mousePosY ; mousePosX/Y have old mouse position
WinGetPos, , , winSizeX, winSizeY, A ; winSizeX/Y have window size
WinGet, winProcessName, ProcessName, A
GetKeyState, LB, LButton, P
; move the mouse to the correct slot, double-click (using events),
; then move it back
invIconOffsetX := 27
invIconOffsetY := 46
slotOffsetX := Mod((44 * (slot - 1)), (4 * 44))
slotOffsetY := (44 * ((slot - 1) // 4))
if (!imageQualitySearch("inv", imageLocX, imageLocY)) {
; the image search failed (stretched screen)
; determine if the window is a steam or projector window,
; and adjust the value accordingly
windowX := 634 + slotOffsetX
windowY := 400 + slotOffsetY
; stretchedX and stretchedY are set by the function call
stretchedWindowPosition(windowX, windowY, stretchedX, stretchedY)
; slotX and slotY are set by the function call
windowPosToClientPos(stretchedX, stretchedY, slotX, slotY)
} else {
; not stretched, imageLocX/Y are set
windowX := imageLocX + invIconOffsetX + slotOffsetX
windowY := imageLocY + invIconOffsetY + slotOffsetY
; slotX and slotY are set by the function call
windowPosToClientPos(windowX, windowY, slotX, slotY)
}
BlockInput, on
CoordMode, Mouse, Client
MouseMove, slotX, slotY
SendEvent {Control Up}
SendEvent {LButton Down}
SendEvent {LButton Up}
SendEvent {LButton Down}
SendEvent {LButton Up}
CoordMode, Mouse, Window
MouseMove, mousePosX, mousePosY
if (LB == "D") {
Send {LButton down}
}
BlockInput, off
stretched := false
}
; @param imageName: base file name (<name>-[low|high|med].png); must be located
; in the img\ directory
; @param imageLocX: by-reference variable to be set to the window-related x
; position of the upper-left corner of the image
; @param imageLocY: by-reference variable to be set to the window-related y
; position of the upper-left corner of the image
; @return: returns true if the search succeeds; false otherwise
; @notes: If the image search fails (and the function returns false),
; imageLocX and imageLocY will not be set.
imageQualitySearch(imageName, byref imageLocX, byref imageLocY) {
WinGetPos, , , winSizeX, winSizeY, A ; winSizeX/Y have window size
; start with lowest quality level, and work up to high
imageQuality := "low"
ErrorLevel := 1
while ErrorLevel {
IfExist, img\%imageName%-%imageQuality%.png
{
ImageSearch, imageLocX, imageLocY, 0, 0, %winSizeX%, %winSizeY%
, img\%imageName%-%imageQuality%.png
}
IfNotExist, img\%imageName%-%imageQuality%.png
{
return false
}
; increment quality for potential future image searches
if (imageQuality == "low"){
imageQuality := "med"
} else if (imageQuality == "med") {
imageQuality := "high"
} else if (imageQuality == "high") {
; stretched screen
return false
}
}
return true
}
; @param intendedX: what would otherwise be the correct x location in a
; non-stretched client
; @param intendedY: what would otherwise be the correct y location in a
; non-stretched client
; @param actualX: by-reference variable to be set to the window-related x
; position of the new x position
; @param actualY: by-reference variable to be set to the window-related x
; position of the new y position
stretchedWindowPosition(intendedX, intendedY, byref actualX, byref actualY) {
WinGetPos, , , winSizeX, winSizeY, A ; winSizeX/Y have window size
WinGet, winProcessName, ProcessName, A
yMultiplierSubtract := (winProcessName == "Realm of the Mad God.exe")
? ((hBorderWidth * 2) + titleHeight)
: (menuHeight + (hBorderWidth * 2) + titleHeight)
multiplierX := ((winSizeX - (vBorderWidth * 2)) / 800)
multiplierY := ((winSizeY-yMultiplierSubtract) / 600)
actualX := Round((intendedX * multiplierX) + (vBorderWidth*2))
actualY := Round((intendedY * multiplierY) + (yMultiplierSubtract))
}
; @param windowX: x position of a window-related coordinate
; @param windowY: y position of a window-related coordinate
; @param outputX: by-reference variable to be set to a client-related
; x coordinate
; @param outputY: by-reference variable to be set to a client-related
; y coordinate
windowPosToClientPos(windowX, windowY, byref outputX, byref outputY) {
WinGetTitle, winTitle, A
WinGet, winProcessName, ProcessName, A
WinGet, winMax, MinMax, A
; chrome (not maximized)
if (winTitle == "Realm of the Mad God - Google Chrome" && winMax == 0) {
outputX := windowX
outputY := windowY
; opera, ff
} else if (winTitle == "Realm of the Mad God - Opera"
|| InStr(winTitle, "Realm of the Mad God - Mozilla Firefox")) {
outputX := windowX - vBorderWidth
outputY := windowY
; IE, safari, steam
} else if (winTitle == "Realm of the Mad God - Windows Internet Explorer"
|| winProcessName == "Safari.exe"
|| winProcessName == "Realm of the Mad God.exe") {
outputX := windowX - vBorderWidth
outputY := windowY - (hBorderWidth + titleHeight)
; chrome (when maximized)
} else if (winTitle == "Realm of the Mad God - Google Chrome"
&& winMax == 1) {
outputX := windowX - vBorderWidth
outputY := windowY - hBorderWidth
} else { ; projector
outputX := windowX - vBorderWidth
outputY := windowY - (menuHeight + hBorderWidth + titleHeight)
}
}
ExitSub:
RestoreCursors()
ExitApp