-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
317 lines (282 loc) · 7.05 KB
/
index.js
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
/** @format */
const path = require("path"),
fs = require("fs")
module.exports = function fly(mod) {
const CATEGORY_GLOBAL = 99999
const SKILL_FLYING_DISMOUNT = 65000001
const SKILL_FLYING_MOUNT = 12200271
var currZone
/*
category: 13003
category: 13009
category: 13021
*/
let gameId = 0n,
location = null,
outOfEnergy = false,
dismountByUser = false,
mountDisabled = false,
inCombat = false,
mountSkill = -1,
serverMounted = false,
remountTimer = null,
unlock = false,
enabled = false,
_inCombat = false,
config,
fileopen = true,
stopwrite,
mounted = false,
delay = 0,
setMount = false,
currentMount = 0,
bigzero = BigInt(0),
w,
loc,
flying = false
try {
config = JSON.parse(fs.readFileSync(path.join(__dirname, "config.json"), "utf8"))
enabled = config.enabled
} catch (e) {
config = JSON.parse(fs.readFileSync(path.join(__dirname, "config-default.json"), "utf8"))
save(config, "config.json")
msg("New Config loaded")
}
if (mod.majorPatchVersion >= 100) {
mod.game.initialize
currentMount = config.currentMount[mod.game.me.name]
delay = config.delay
enabled = config.enabled
}
mod.hook("C_PLAYER_FLYING_LOCATION", 4, (event) => {
location = {
flying: true,
pos: event.loc,
dir: event.w,
}
if (outOfEnergy && event.type !== 7 && event.type !== 8) {
event.type = 7
return true
}
})
mod.hook("S_LOAD_TOPO", 3, (e) => {
currZone = e.zone
})
mod.hook("C_PLAYER_LOCATION", 5, (e) => {
return !([2, 10].includes(e.type) && (currZone < 10 || currZone > 200))
})
mod.hook("C_PLAYER_LOCATION", 5, (event) => {
location = {
flying: false,
pos: event.loc,
dir: event.w,
}
})
mod.hook("C_PLAYER_LOCATION", 5, (event) => {
flying = false
if (enabled && !mounted && !_inCombat) {
switch (event.type) {
case 0:
case 1:
delay--
w = event.w
loc = event.loc
mount()
break
default:
delay = config.delay
}
}
})
mod.hook("S_MOUNT_VEHICLE", 2, (event) => {
if (!mod.game.me.is(event.gameId)) return
mounted = true
flying = false
if (setMount) {
currentMount = event.skill
setMount = false
config.currentMount[mod.game.me.name] = currentMount
msg("Mount set to: " + currentMount)
save(config, "config.json")
}
})
mod.hook("S_UNMOUNT_VEHICLE", 2, (event) => {
if (!mod.game.me.is(event.gameId)) return
mounted = false
flying = false
delay = config.delay
})
mod.hook("S_SHORTCUT_CHANGE", 2, (event) => {
if (enabled && mounted) return false
})
mod.hook("C_START_SKILL", 7, { order: -999 }, (event) => {
return unmount()
})
mod.hook("C_PRESS_SKILL", 4, { order: -999 }, (event) => {
return unmount()
})
mod.hook("C_PLAYER_FLYING_LOCATION", 4, (event) => {
flying = true
})
mod.hook("C_START_SKILL", 7, (event) => {
if (event.skill.id == mountSkill || event.skill.id == SKILL_FLYING_DISMOUNT) {
dismountByUser = true
mountSkill = -1
}
})
mod.hook("S_CANT_FLY_ANYMORE", 1, (event) => {
return false
})
mod.hook("S_MOUNT_VEHICLE", 2, { order: 10 }, (event) => {
if (event.gameId == mod.game.me.gameId) {
const fakeMounted = mountSkill !== -1
serverMounted = true
mountSkill = event.skill
if (fakeMounted) {
return false
}
}
})
mod.hook("S_PLAYER_CHANGE_FLIGHT_ENERGY", 1, (event) => {
outOfEnergy = event.energy === 0
})
mod.hook("S_SKILL_CATEGORY", 3, (event) => {
if (event.category == CATEGORY_GLOBAL) {
mountDisabled = !event.enabled
}
})
mod.hook("S_UNMOUNT_VEHICLE", 2, { order: 10 }, (event) => {
if (event.gameId != mod.game.me.gameId) {
return
}
serverMounted = false
if (!location.flying || dismountByUser) {
dismountByUser = false
mountSkill = -1
} else {
clearTimeout(remountTimer)
remountTimer = setTimeout(tryRemount, 30)
return false
}
})
mod.hook("S_USER_STATUS", 3, (event) => {
if (event.gameId == mod.game.me.gameId) {
inCombat = event.status == 1
}
_inCombat = event.status == 1
if (_inCombat && enabled) delay = config.delay
})
function unmount() {
if (enabled && mounted && !flying) {
mod.toServer("C_UNMOUNT_VEHICLE", 1, {})
mod.send("C_UPDATE_REACTION_POS", 1, {
skill: currentMount,
loc: location.pos,
})
mod.toClient("S_UNMOUNT_VEHICLE", 2, {
gameId: mod.game.me.gameId,
skill: currentMount,
})
return false
}
return true
}
function mount() {
currentMount = config.currentMount[mod.game.me.name]
if (enabled && delay <= 0 && !_inCombat) {
if (currentMount == 0 || currentMount == null) {
msg("mount not set. Use command: am set")
enabled = false
return
}
delay = config.delay
mod.toServer("C_START_SKILL", 7, {
skill: {
reserved: 0,
npc: false,
type: 1,
huntingZoneId: 0,
id: currentMount,
},
w: w,
loc: loc,
dest: {
x: 0,
y: 0,
z: 0,
},
unk: true,
moving: false,
continue: false,
target: bigzero,
unk2: false,
})
}
}
function tryRemount() {
if (!mountDisabled && !inCombat) {
mod.send("C_START_SKILL", 7, {
skill: mountSkill,
w: location.dir,
loc: location.pos,
unk: true,
})
mod.send("C_UPDATE_REACTION_POS", 1, {
skill: mountSkill,
loc: location.pos,
})
remountTimer = setTimeout(() => {
if (!serverMounted) {
mod.send("S_UNMOUNT_VEHICLE", 2, {
gameId,
skill: mountSkill,
})
mountSkill = -1
}
}, 1000)
} else {
mod.send("S_UNMOUNT_VEHICLE", 2, {
gameId,
skill: mountSkill,
})
mountSkill = -1
}
}
function save(data, filename) {
if (fileopen) {
fileopen = false
fs.writeFile(path.join(__dirname, filename), JSON.stringify(data, null, "\t"), (err) => {
if (err) {
mod.command.message("Error Writing File, attempting to rewrite")
console.log(err)
}
fileopen = true
})
} else {
clearTimeout(stopwrite) //if file still being written
stopwrite = setTimeout(save(__dirname, filename), 2000)
return
}
}
function msg(event) {
mod.command.message(event)
}
mod.command.add(["ff"], {
$none() {
enabled = !enabled
config.enabled = enabled
save(config, "config.json")
msg(enabled ? "enabled" : "disabled")
},
set() {
setMount = !setMount
msg(setMount ? "Setting Mount ON" : "Setting Mount OFF")
},
delay(arg) {
delay = Number(arg)
config.delay = delay
save(config, "config.json")
msg("delay set to " + delay)
},
})
}