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
local cfg = UI.Schema({
enable_right_click = UI.Toggle(false, { label = "Enable Right-Click Combat Loop" }),
enable_dump = UI.Toggle(false, { label = "Enable Full Inventory Dump" }),
combat_button = UI.Keybind("Mouse2", { label = "Hold for Combat Loop", group = "Hotkeys" }),
transfer_button = UI.Keybind("Mouse1", { label = "Hold with Ctrl for Stash Transfer", group = "Hotkeys" }),
win_remap_key = UI.Keybind("LWin", { label = "Key That Sends Right Shift", group = "Hotkeys" }),
cursor_key = UI.Keybind("F12", { label = "Show Cursor Position", group = "Hotkeys" }),
setup_key = UI.Keybind("F10", { label = "Calibrate Coordinates" }),
portal_key = UI.Keybind("Grave", { label = "Instant Portal", group = "Hotkeys" }),
dump_key = UI.Keybind("Left", { label = "Dump Inventory (Ctrl+Click)", group = "Hotkeys" }),
right_click_all_key = UI.Keybind("Right", { label = "Right-Click All Slots", group = "Hotkeys" }),
inspect_trade_key = UI.Keybind("Up", { label = "Inspect Trade Window", group = "Hotkeys" }),
hideout_key = UI.Keybind("F1", { label = "Go to Hideout", group = "Chat Commands" }),
ty_key = UI.Keybind("F2", { label = "Quick Reply 'ty'", group = "Chat Commands" }),
leave_key = UI.Keybind("F3", { label = "Leave Party", group = "Chat Commands" }),
destroy_key = UI.Keybind("F11", { label = "Destroy Held Item", group = "Chat Commands" }),
})
local COORDS_FILE = "coords.json"
local function load_coords()
if File.Exists(COORDS_FILE) then
local ok, data = pcall(File.ReadJSON, COORDS_FILE)
if ok and data then return data end
end
return {
inv_tl = { x = 1780, y = 818 },
inv_br = { x = 2495, y = 1078 },
trade_tl = { x = 494, y = 324 },
trade_br = { x = 1209, y = 584 },
}
end
local function save_coords(data)
File.WriteJSON(COORDS_FILE, data)
end
local coords = load_coords()
local setup_step = 0
local function get_inv_cell(col, row)
local dx = (coords.inv_br.x - coords.inv_tl.x) / 11
local dy = (coords.inv_br.y - coords.inv_tl.y) / 4
return {
x = math.floor(coords.inv_tl.x + col * dx),
y = math.floor(coords.inv_tl.y + row * dy),
}
end
local function get_trade_cell(col, row)
local dx = (coords.trade_br.x - coords.trade_tl.x) / 11
local dy = (coords.trade_br.y - coords.trade_tl.y) / 4
return {
x = math.floor(coords.trade_tl.x + col * dx),
y = math.floor(coords.trade_tl.y + row * dy),
}
end
local function send_chat(command)
HID.Press("Enter", 15)
Sleep(25)
HID.Type(command)
Sleep(25)
HID.Press("Enter", 15)
end
Bind(cfg.setup_key, function()
local pos = Input.GetMousePos()
if setup_step == 0 then
setup_step = 1
UI.Notify("Step 1/4: Hover TOP-LEFT inventory slot center, press key", "info")
elseif setup_step == 1 then
coords.inv_tl = { x = pos.x, y = pos.y }
setup_step = 2
UI.Notify(string.format("Saved TL (%d, %d). Step 2/4: Hover BOTTOM-RIGHT inventory slot, press key", pos.x, pos.y), "info")
elseif setup_step == 2 then
coords.inv_br = { x = pos.x, y = pos.y }
setup_step = 3
UI.Notify(string.format("Saved BR (%d, %d). Step 3/4: Open trade, hover TOP-LEFT trade slot, press key", pos.x, pos.y), "info")
elseif setup_step == 3 then
coords.trade_tl = { x = pos.x, y = pos.y }
setup_step = 4
UI.Notify(string.format("Saved Trade TL (%d, %d). Step 4/4: Hover BOTTOM-RIGHT trade slot, press key", pos.x, pos.y), "info")
elseif setup_step == 4 then
coords.trade_br = { x = pos.x, y = pos.y }
save_coords(coords)
setup_step = 0
UI.Notify(string.format("Calibration saved to %s", COORDS_FILE), "success")
Log.Info(string.format("Saved grid coordinates to %s", COORDS_FILE))
end
end)
Bind.Remap(cfg.win_remap_key, "RShift")
Bind(cfg.transfer_button, {
when = function()
return Input.GetModifiers().ctrl
end,
action = Async(function()
while Input.IsDown(cfg.transfer_button) and Input.GetModifiers().ctrl do
HID.Press("Mouse1", 10)
Sleep(15)
end
end),
})
Bind(cfg.combat_button, {
when = function()
return cfg.enable_right_click
end,
action = Async(function()
while Input.IsDown(cfg.combat_button) and cfg.enable_right_click do
HID.Press("Mouse2", 15)
Sleep(50)
if not Input.IsDown(cfg.combat_button) then break end
Sleep(10)
HID.Press("Q", 15)
if not Input.IsDown(cfg.combat_button) then break end
Sleep(10)
HID.Press("E", 15)
Sleep(10)
end
end),
})
Bind(cfg.portal_key, Async(function()
local orig_pos = Input.GetMousePos()
local portal_cell = get_inv_cell(11, 4)
HID.Press("B", 15)
Sleep(15)
HID.MoveTo(portal_cell.x, portal_cell.y)
Sleep(10)
HID.Press("Mouse2", 15)
Sleep(15)
HID.Press("B", 15)
Sleep(10)
HID.MoveTo(orig_pos.x, orig_pos.y)
end))
Bind(cfg.dump_key, {
when = function()
return cfg.enable_dump
end,
action = Async(function()
HID.Down("LCtrl")
for row = 0, 4 do
for col = 0, 11 do
local pos = get_inv_cell(col, row)
HID.MoveTo(pos.x, pos.y)
Sleep(10)
HID.Press("Mouse1", 10)
Sleep(10)
end
end
HID.Up("LCtrl")
end),
})
Bind(cfg.right_click_all_key, Async(function()
if not cfg.enable_right_click then
HID.Press("Mouse2", 15)
return
end
for row = 0, 4 do
for col = 0, 11 do
local pos = get_inv_cell(col, row)
HID.MoveTo(pos.x, pos.y)
Sleep(10)
HID.Press("Mouse2", 10)
Sleep(10)
end
end
end))
Bind(cfg.inspect_trade_key, Async(function()
for row = 0, 4 do
for col = 0, 11 do
local pos = get_trade_cell(col, row)
HID.MoveTo(pos.x, pos.y)
Sleep(10)
end
end
end))
Bind(cfg.hideout_key, Async(function()
send_chat("/hideout")
end))
Bind(cfg.ty_key, Async(function()
HID.Combo("LCtrl+Enter")
Sleep(25)
HID.Type("ty")
Sleep(25)
HID.Press("Enter", 15)
end))
Bind(cfg.leave_key, Async(function()
send_chat("/leave")
end))
Bind(cfg.destroy_key, Async(function()
send_chat("/destroy")
end))
Bind(cfg.cursor_key, function()
local pos = Input.GetMousePos()
UI.Notify(string.format("Cursor: %d, %d", pos.x, pos.y), "info")
Log.Info(string.format("Cursor: %d, %d", pos.x, pos.y))
end)
function OnStop()
HID.Up("LCtrl")
HID.Up("Mouse1")
HID.Up("Mouse2")
end
function OnBlur()
HID.Up("LCtrl")
HID.Up("Mouse1")
HID.Up("Mouse2")
end