Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
287 lines (250 loc) · 8.28 KB
/
Copy pathinit.lua
File metadata and controls
287 lines (250 loc) · 8.28 KB
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
-- ==== IMPORTS ====
local waywall = require("waywall")
local helpers = require("waywall.helpers")
local options = require("options")
local utils = require("utils")
local screen = require("screen")
if options.safe_guards == nil then
error("WARNING: Your waywall config is not setup correctly, you should read the setup guide")
end
-- ==== HELPERS ====
-- currently active remap
local active_remap = "default"
-- paused keymap indicator
local chat_text = utils.make_text({
text = "keymap paused",
dst = { pos_anchor = "bottomleft", item_anchor = "bottomleft" },
size = 1,
color = "ffffff7f"
})
local function chat_key(key)
return function()
if not utils.has_state and active_remap == "chat" then
waywall.press_key(key)
waywall.sleep(100)
waywall.set_remaps(options.remapped_kb)
active_remap = "default"
chat_text(false)
return false
end
if active_remap ~= "chat" then
waywall.press_key(key)
waywall.sleep(100)
waywall.set_remaps(options.normal_kb)
active_remap = "chat"
chat_text(true)
return false
end
return false
end
end
local current_sens = options.sens._normal
local function res_enable(current)
local sens = options.sens[current] ---@cast sens number
if sens ~= current_sens then
if sens == nil then
sens = options.sens._normal
end
if options.sens._use_maccel then
waywall.exec("maccel set param sens_mult " .. sens)
else
waywall.set_sensitivity(sens)
end
current_sens = sens
end
for _, o in pairs(options.objects) do
for name, obj in pairs(o) do
if name ~= "enabled" and name ~= "action" and o.enabled then
if (o.enabled == true) then
obj(true)
else
obj(o.enabled[current])
end
end
end
end
end
local function res_disable()
res_enable("_normal")
end
local has_launched = false
local function on_launch()
has_launched = true
local counter = 0
while true do
-- print("running on_launch #" .. counter)
local did_something = false
for name, obj in pairs(options.action.on_launch) do
if name ~= "key" then
if obj(options) then
did_something = true
end
end
end
if did_something then
waywall.sleep(1000)
counter = counter + 1
if counter > 10 then
error("on launch function looped " .. counter .. " times!")
break
end
else
break
end
end
end
-- ==== CONFIG ====
local config = { actions = {} }
if options.safe_guards.filter then
config.shaders = {
["pie_chart"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/pie_chart.frag"),
},
["pie_chart_modern"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/pie_chart_modern.frag"),
},
["pie_chart_modern_shadow"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/pie_chart_modern_shadow.frag"),
},
["pie_text"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/pie_text.frag"),
},
["pie_text_shadow"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/pie_text_shadow.frag"),
},
["text"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/text.frag"),
},
["shadow"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/text_shadow.frag"),
},
}
end
-- allowed under proposed filter ban
config.shaders["pie_crop"] = {
vertex = utils.read_file("shaders/general.vert"),
fragment = utils.read_file("shaders/pie_crop.frag"),
}
-- apply default waywall options
config.input = options.input
config.input.remaps = options.remapped_kb
config.input.sensitivity = options.sens._normal
config.theme = options.theme
config.window = {
fullscreen_width = options.window.width,
fullscreen_height = options.window.height,
}
config.experimental = options.experimental
screen.width = options.window.width
screen.height = options.window.height
-- apply base actions
utils.apply_action(config.actions, options.action.fullscreen, waywall.toggle_fullscreen)
utils.apply_action(config.actions, options.action.on_launch, on_launch)
utils.apply_action(config.actions, options.action.toggle_ninbot, helpers.toggle_floating)
-- apply chat key action
if type(options.action.chat_key1) == "string" then
config.actions[options.action.chat_key1] = chat_key(options.action.chat_key1)
elseif type(options.action.chat_key1) == "table" then
config.actions[options.action.chat_key1[1]] = chat_key(options.action.chat_key1[2])
end
if type(options.action.chat_key2) == "string" then
config.actions[options.action.chat_key2] = chat_key(options.action.chat_key2)
elseif type(options.action.chat_key2) == "table" then
config.actions[options.action.chat_key2[1]] = chat_key(options.action.chat_key2[2])
end
-- apply extra actions
for _, extra in pairs(options.action.extra) do
utils.apply_action(config.actions, extra.key, extra.exec, options)
end
for _, obj in pairs(options.objects) do
if obj.action then
utils.apply_action(config.actions, obj.action, function()
for name, el in pairs(obj) do
if name ~= "enabled" and name ~= "action" then
el("toggle", options)
end
end
end)
end
end
-- apply resolutions
screen.res = {}
---@param name string
---@param res res
local function apply_res(name, res)
local size
if type(res.size) == "number" then
---@diagnostic disable-next-line: assign-type-mismatch
size = screen.dst({ size = res.size })
else
---@diagnostic disable-next-line: param-type-mismatch
size = screen.dst(res.size)
end
if options.safe_guards.safe_resolution then
size.w = math.min(math.max(size.w, 340), 16384)
size.h = math.min(math.max(size.h, 340), 16384)
end
screen.res["res:" .. name] = size
local res_fun = utils.make_res(size.w, size.h, function() res_enable(name) end, res_disable, res.animate)
utils.apply_action(config.actions, res, res_fun)
if res.auto_disable and options.safe_guards.state_output then
waywall.listen("state", function()
local state = waywall.state()
if state.screen ~= "inworld" or state.inworld ~= "unpaused" then
res_fun(false)
end
end)
end
end
for name, res in pairs(options.res) do
if not res.defer then
apply_res(name, res)
end
end
for name, res in pairs(options.res) do
if res.defer then
apply_res(name, res)
end
end
-- apply mpk
if options.safe_guards.macro then
utils.mpk(options.mpk, config)
end
waywall.listen("load", function()
pcall(waywall.set_resolution, 0, 0) -- minecraft window doesn't exist at this point when launching
res_disable()
waywall.sleep(5000)
on_launch()
waywall.sleep(5000) -- sometimes ninjabrain bot closes and i don't know why
on_launch()
end)
waywall.listen("state", function()
utils.has_state = options.safe_guards.state_output
if not options.safe_guards.state_output then return end
local state = waywall.state()
if not has_launched then
on_launch()
end
if state.screen == "inworld" and state.inworld == "unpaused" then
waywall.set_remaps(options.remapped_kb)
chat_text(false)
active_remap = "default"
if utils.starting_mpk then
utils.starting_mpk = false
waywall.press_key(options.mpk.load)
end
end
if state.screen ~= "inworld" then
waywall.set_remaps(options.normal_kb)
chat_text(true)
active_remap = "chat"
end
end)
return config