forked from Hirohiko360/LiquidBounceScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lib
More file actions
876 lines (737 loc) · 44 KB
/
Core.lib
File metadata and controls
876 lines (737 loc) · 44 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
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
//Core - Simple, yet powerful ScriptAPI base
var Core = {
version: "4.9",
API_V2: typeof _AdaptedModule === "undefined"
}, module, command, scriptName, scriptVersion, scriptAuthor;
/*-------------*/
/* Module core */
/*-------------*/
Core.registerModule = function (m) {
if (!Object.keys(m).length) return;
var settings = {};
(m.values = toArray(m.values)).forEach(function (v, i) {
if (Core.dynamicValues[v]) m.values[i] = v = Core.dynamicValues[v];
//Makes multiple "spacer" values possible
for each (var v in toArray(v)) settings[v.getName() || ("spacer" + Object.keys(settings).length)] = v instanceof Value ? v : v.getValue();
});
script.registerModule({
name: m.name || script.scriptName,
category: Core.categories.add(m.category || "Core"),
description: m.description || "",
tag: m.tag || "",
settings: settings
}, function (module) {
m.module = module;
m.moduleReflector = new Reflector(module);
m.onEnable && module.on("enable", m.onEnable.bind(m));
m.onDisable && module.on("disable", m.onDisable.bind(m));
m.onUpdate && module.on("update", m.onUpdate.bind(m));
m.onMotion && module.on("motion", m.onMotion.bind(m));
m.onRender2D && module.on("render2D", m.onRender2D.bind(m));
m.onRender3D && module.on("render3D", m.onRender3D.bind(m));
m.onAttack && module.on("attack", m.onAttack.bind(m));
m.onJump && module.on("jump", m.onJump.bind(m));
m.onPacket && module.on("packet", m.onPacket.bind(m));
m.onKey && module.on("key", m.onKey.bind(m));
m.onMove && module.on("move", m.onMove.bind(m));
m.onStep && module.on("step", m.onStep.bind(m));
m.onStepConfirm && module.on("stepConfirm", m.onStepConfirm.bind(m));
m.onWorld && module.on("world", m.onWorld.bind(m));
m.onSession && module.on("session", m.onSession.bind(m));
m.onClickBlock && module.on("clickBlock", m.onClickBlock.bind(m));
m.onStrafe && module.on("strafe", m.onStrafe.bind(m));
m.onSlowDown && module.on("slowDown", m.onSlowDown.bind(m));
m.onShutdown && module.on("shutdown", m.onShutdown.bind(m));
m.onClickGuiLoaded && module.on("clickGuiLoaded", m.onClickGuiLoaded.bind(m));
m.onClickGuiOpen && module.on("clickGuiOpen", m.onClickGuiOpen.bind(m));
m.onClickGuiClosed && module.on("clickGuiClosed", m.onClickGuiClosed.bind(m));
m.onValueChanged && module.on("valueChanged", m.onValueChanged.bind(m))
/*-------------------------*/
/* Artificial Events™ core */
/*-------------------------*/
for each (var key in Object.keys(Core.artificialEvents)) m[key] && hookEvent(Core.artificialEvents[key], m[key].bind(m), function () m.module.state, m);
/*----------------------*/
/* Dynamic Values™ core */
/*----------------------*/
if (m.values.some(function (v) Array.isArray(v))) //Detects if module values contain a dynamic value
["shutdown", "clickGuiClosed", "clickGuiOpen"].forEach(function (event, i) module.on(event, function () Core.dynamicValues.update(m, i < 2)));
});
}
Core.hookedEvents = new java.util.HashMap();
function hookEvent(eventClass, func, handleEventsCallback, coreModule) {
var listener = new (Java.extend(Listenable, java.util.function.Consumer, {
handleEvents: handleEventsCallback,
accept: func
})),
targets = Core.eventManager.registry.getOrDefault(eventClass, new ArrayList()),
hook = new EventHook(listener, getMethod(listener, "accept"), Core.defaultAnnotation);
targets.add(hook);
Core.hookedEvents[eventClass] = toArray(Core.hookedEvents[eventClass]).concat(hook);
Core.eventManager.registry[eventClass] = targets;
//Registering event in ScriptModule's events HashMap to make them callable via callEvent() function.
coreModule && coreModule.moduleReflector.events.put(eventClass.simpleName[0].toLowerCase() + eventClass.simpleName.slice(1, -5) /*BlockBBEvent -> blockBB, ...*/, func);
}
/*--------------*/
/* Command core */
/*--------------*/
Core.registerCommand = function (c, stale) {
if (!Object.keys(c).length) return;
var aliases = toArray(c.aliases || c.name || script.scriptName).toLowerCase();
var command = new (Java.extend(Command)) (aliases[0], Java.to(aliases, "java.lang.String[]")) {
execute: function (args) {
args = Java.from(args);
var formattedArgs = args.toLowerCase(), scope = c, scopePos = 0, parameters = [], found;
formattedArgs[0] = "handler";
for each (var arg in formattedArgs) {
var scopeArray = toArray(scope);
found = scopeArray.find(function (e) e.hasOwnProperty(arg));
if (found) {
scope = found[arg];
scopePos++;
var scopeArray = toArray(scope),
objects = scopeArray.filter(function (e) isObject(e)),
scopeSubcommands = objects.map(function (o) Object.keys(o)).flat();
if (scopeSubcommands.includes(formattedArgs[scopePos])) continue
var functions = scopeArray.filter(function (e) e instanceof Function).sort(function (a, b) getFunctionParameters(b).length - getFunctionParameters(a).length);
if (functions.length) {
for each (func in functions) {
var parameters = getFunctionParameters(func);
if (scopePos + parameters.length <= args.length) return func.apply(command, args.slice(scopePos));
}
parameters = functions.map(function (func) getFunctionParameters(func));
break
}
} else {
args = args.slice(0, formattedArgs.indexOf(arg));
clearChat();
print("§4▏ §c§lInvalid subcommand§4:");
print("§4▏§c", args.join(" "), "„§4§l" + arg + "§c“");
break
}
}
if (args.length == 1) {
found !== null && clearChat();
print("§8▏§7§l", c.name || script.scriptName, "§8v§l" + (c.version || script.scriptVersion), "§7by§8§l", toArray(c.author || Java.from(script.scriptAuthors)).join("§7, §8§l"));
if (c.aliases.length > 1) {
print("§8▏ §7§lAvailable aliases§8: (§7§l" + c.aliases.length + "§8)");
print("§8▏ §f" + c.aliases.map(function (alias) LiquidBounce.commandManager.prefix + alias).join("§7, §f"));
}
}
var subcommands = Array.isArray(scope) ? scope.filter(function (e) isObject(e)).map(function (o) Object.keys(o)).flat() : Object.keys(scope);
if (subcommands.length && scopePos == args.length) {
print("§8▏ §7§lValid subcommand" + (subcommands.length > 1 ? "s" : "") + "§8: (§7§l" + subcommands.length + "§8)");
print("§8▏§f", args.join(" "), "§8[§f" + subcommands.join("§7, §f") + "§8]");
}
if (parameters.length) {
print("§8▏ §7§lRequired parameters§8: (§7§l" + parameters.map(function (params) params.length).join("§8/§7§l") + "§8)");
for each (params in parameters) print("§8▏§f", args.join(" "), "„§7" + params.slice(args.length - scopePos).map(function (param) param.replaceAll("_", " ")).join("§f“ „§7") + "§f“");
}
},
tabComplete: function (args) {
args = Java.from(args);
return Java.to(c.onTabComplete ? c.onTabComplete(args)/*.filter(function (string) string.toLowerCase().startsWith(args.last().toLowerCase()))*/ : [], "java.util.List");
}
}
LiquidBounce.commandManager.registerCommand(command);
!stale && Core.registeredCommandsField.get(script).add(command);
return command;
}
/*-------------------*/
/* Utility functions */
/*-------------------*/
function isMovingHorizontally(entity) entity && entity != mc.thePlayer ? entity.lastTickPosX != entity.posX || entity.lastTickPosZ != entity.posZ : !!(mc.thePlayer.movementInput.moveForward || mc.thePlayer.movementInput.moveStrafe);
function isMovingVertically(entity) entity && entity != mc.thePlayer ? entity.lastTickPosY != entity.posY : mc.thePlayer.movementInput.jump || mc.thePlayer.movementInput.sneak;
function isMoving(entity) isMovingHorizontally(entity) || isMovingVertically(entity);
function isInputHorizontally() Keyboard.isKeyDown(mc.gameSettings.keyBindForward.getKeyCode()) || Keyboard.isKeyDown(mc.gameSettings.keyBindLeft.getKeyCode()) || Keyboard.isKeyDown(mc.gameSettings.keyBindBack.getKeyCode()) || Keyboard.isKeyDown(mc.gameSettings.keyBindRight.getKeyCode());
function isInputVertically(jumpOnly) Keyboard.isKeyDown(mc.gameSettings.keyBindJump.getKeyCode()) || (!jumpOnly && Keyboard.isKeyDown(mc.gameSettings.keyBindSneak.getKeyCode()));
function move(horizontal, vertical, timer, event, ignoreInput) {
horizontal = ignoreInput ? horizontal : isInputHorizontally() ? horizontal : 0;
vertical = ignoreInput ? vertical : isInputHorizontally() ? vertical : null;
yaw = MovementUtils.getDirection();
timer != null && timer > 0 && (mc.timer.timerSpeed = timer);
horizontal != null && ((mc.thePlayer.motionX = -Math.sin(yaw) * horizontal, mc.thePlayer.motionZ = Math.cos(yaw) * horizontal), (event && (event.setX(mc.thePlayer.motionX), event.setZ(mc.thePlayer.motionZ))));
vertical != null && ((mc.thePlayer.motionY = vertical), (event && event.setY(vertical)));
}
function interval(ms, func, _timer) (_timer = new Timer("setInterval", true), _timer.schedule(func, 0, ms), _timer);
function timeout(ms, func, _timer) (_timer = new Timer("setTimeout", true), _timer.schedule(func, ms), _timer);
function setValues(module, values) {
values = toArray(values);
if (module instanceof ScriptModule) {
var valuesMap = new LinkedHashMap();
for each (var v in values) valuesMap[v.getName() || ("spacer" + valuesMap.size())] = v instanceof Value ? v : v.getValue();
Core.ignoreValueChange = true;
getField(module, "_values").set(module, valuesMap);
} else if (module instanceof Module) {
getFields(module).forEach(function (field, i) {
field.setAccessible(true);
getField(Field, "modifiers").setInt(field, field.getModifiers() & ~Modifier.FINAL);
var instance = field.get(module);
if (instance instanceof Value) {
var suitable = values.find(function (value) instance.class.isAssignableFrom(value.class));
field.set(module, suitable);
values.remove(suitable);
}
});
} else return
LiquidBounce.fileManager.saveConfig(LiquidBounce.fileManager.valuesConfig);
}
function getValues(module) Java.from(module.values);
function getNearestTarget(entityType, fromEntity, _entity) mc.theWorld.loadedEntityList.stream().filter(function (e) e != mc.thePlayer && (e instanceof entityType || (!entityType && EntityUtils.isSelected(e, true)))).min(function (a, b) (_entity = fromEntity || mc.thePlayer).getDistanceToEntity(a) - _entity.getDistanceToEntity(b)).orElse(null);
function getTargetsInRange(range, entityType) Java.from(mc.theWorld.loadedEntityList).filter(function (e) e != mc.thePlayer && (e instanceof entityType || (!entityType && EntityUtils.isSelected(e, true))) && (!range || PlayerExtensionKt.getDistanceToEntityBox(e, mc.thePlayer) <= range));
function getPlayer(nick) Java.from(mc.theWorld.playerEntities).find(function (e) StringUtils.stripControlCodes(e.getName()).equals(nick));
function rand(min, max) (Array.isArray(min) && (max = min[1], min = min[0]), Math.random() * (max - min) + min);
function getDurability(stack) stack && stack.getMaxDamage() - stack.getItemDamage();
function getAttackDamage(stack, _item) stack && (_item = stack.getItem()) && (_item instanceof ItemSword || _item instanceof ItemTool) ? Java.from(_item.getItemAttributeModifiers().get("generic.attackDamage"))[0].getAmount() + 1.25 * ItemUtils.getEnchantment(stack, Enchantment.sharpness) : -1;
function getBreakingSpeed(stack, block, _item) stack && (_item = stack.getItem()) && (_item instanceof ItemTool) ? _item.getStrVsBlock(stack, block) : 1;
function getFacing(blockData) blockData && (blockData instanceof BlockPos ? mc.theWorld.getBlockState(blockData) : blockData).getProperties().get(BlockDirectional.FACING);
print = (Chat = chat = { print: function () { ClientUtils.displayChatMessage(Array.prototype.slice.call(arguments).join(" ")) } }).print;
function showMessage(text, title, alwaysOnTop, type, _dialog)
new Thread(function () {
(_dialog = new JOptionPane(text || "", type || JOptionPane.INFORMATION_MESSAGE).createDialog(title || "")).setAlwaysOnTop(alwaysOnTop != null ? alwaysOnTop : true);
_dialog.setVisible(true);
}).start();
function getMethod(clazz, name, _method) ((_method = Java.from((clazz instanceof Class ? clazz : clazz.class).getDeclaredMethods()).find(function (m) m.getName() == name)) && _method.setAccessible(true), _method);
function getField(clazz, name, _field) ((_field = getFields(clazz instanceof Class ? clazz : clazz.class).find(function (f) f.getName() == name)) && _field.setAccessible(true), _field);
function getFields(clazz) {
var _fields = Java.from((clazz = clazz instanceof Class ? clazz : clazz.class).getDeclaredFields());
while (clazz = clazz.superclass) _fields = _fields.concat(Java.from(clazz.getDeclaredFields()));
return _fields;
}
function getMethods(clazz) {
var _methods = Java.from((clazz = clazz instanceof Class ? clazz : clazz.class).getDeclaredMethods());
while (clazz = clazz.superclass) _methods = _methods.concat(Java.from(clazz.getDeclaredMethods()));
return _methods;
}
function getConstructor(clazz, index, _constructor) ((_constructor = (clazz instanceof Class ? clazz : clazz.class).getDeclaredConstructors()[index]).setAccessible(true), _constructor);
function openFolder(folder) Desktop.open(folder);
function toArray(object, notFlat) (Array.isArray(object) ? object : [object]).flat(!notFlat).filter(Boolean);
function isObject(object) object && object.constructor === Object;
function canStep(stepHeight, predictDistance) {
if (mc.thePlayer.isCollidedHorizontally || predictDistance) {
var yaw = MovementUtils.getDirection(), bb = mc.thePlayer.getEntityBoundingBox(), possiblePlaces = [], otherBB, predictDistance = predictDistance || 0.01;
for (var i = 0; (i += 0.125) <= stepHeight;) {
if (!mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, bb.offset(0, i, 0)).isEmpty()) break
if (mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, otherBB = bb.offset(-Math.sin(yaw) * predictDistance, i, Math.cos(yaw) * predictDistance)).isEmpty() && !mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, otherBB.offset(0, -0.125, 0)).isEmpty()) possiblePlaces.push(i);
}
return possiblePlaces.length && Math.max.apply(null, possiblePlaces);
}
}
function getStepHeight() {
var yaw = MovementUtils.getDirection(), bb = mc.thePlayer.getEntityBoundingBox();
for (var i = 0; (i += 0.125) <= 255 - mc.thePlayer.posY;) {
if (!mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, bb.offset(0, i, 0)).isEmpty()) break
var offsetBB = bb.offset(-Math.sin(yaw) * 0.01, i, Math.cos(yaw) * 0.01);
if (mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, offsetBB).isEmpty()) return i;
}
}
function callEvent(name, args) scriptManager.scripts.forEach(function (s) Core.registeredModulesField.get(s).forEach(function (m) Core.callEventMethod.invoke(m, name, args)));
function playSound(name, pitch) mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation(name), pitch || 1));
function sendPacket(packet, triggerEvent) {
var networkManager = mc.getNetHandler().getNetworkManager();
if (triggerEvent) networkManager.sendPacket(packet);
else if (networkManager.isChannelOpen()) {
Core.flushOutboundQueueMethod.invoke(networkManager);
Core.dispatchPacketMethod.invoke(networkManager, packet, null);
} else {
Core.readWriteLockField.get(networkManager).writeLock().lock();
try {
var outboundPackets = Core.outboundPacketsQueueField.get(networkManager);
outboundPackets.add(new NetworkManager.InboundHandlerTuplePacketListener(packet, null));
Core.outboundPacketsQueueField.set(networkManager, outboundPackets);
} finally {
Core.readWriteLockField.get(networkManager).writeLock().unlock();
}
}
}
function getSRGName(clazz, name, map) {
clazz = clazz instanceof Class ? clazz : clazz.class;
if (map.containsKey(clazz.name)) {
for each (var entry in map.get(clazz.name).entrySet()) {
if (entry.getValue() == name) return entry.getKey().split("(")[0];
}
}
return name;
}
function getFunctionParameters(func) {
if (func instanceof Function) {
var match = func.toString().match(/function.*\((.*)\)/)[1];
if (match.length) return match.replaceAll(" ", "").split(",")
}
return []
}
//Downloads a GitHub directory.
//Uses GitHub's API URL (for example https://api.github.com/repos/CzechHek/Core/contents/Scripts)
function downloadDirectory(url, destination, onSuccess, onFailure) {
new Thread(function () {
try {
if (!(url instanceof URL)) url = new URL(url);
if (!(destination instanceof File)) destination = new File(destination);
var json = JSON.parse(HttpUtils.get(url));
for each (var info in json) {
if (info.type == "file") HttpUtils.download(info.download_url, new File(destination, info.name));
else downloadDirectory(info.url, new File(destination, info.name));
}
onSuccess instanceof Function && onSuccess();
} catch (e) {
(onFailure instanceof Function ? onFailure : print)(e);
}
}).start();
}
//mc.ingameGUI.getChatGUI().clearChatMessages() also clears message history cache that's accessible by pressing arrow up
function clearChat() {
var chatGui = new Reflector(mc.ingameGUI.getChatGUI());
chatGui.drawnChatLines.clear();
chatGui.chatLines.clear();
}
/*----------------------*/
/* Class-like functions */
/*----------------------*/
function EditableEnum(target) {
var valuesField = getField(target, "$VALUES")
getField(Field, "modifiers").setInt(valuesField, valuesField.getModifiers() & ~Modifier.FINAL);
var accessor = getMethod(java.lang.reflect.Constructor, "acquireConstructorAccessor").invoke(getConstructor(target, 0)), a;
this.add = function (name) (!(a = this.values()).some(function (v) v.getDisplayName().equalsIgnoreCase(name)) && valuesField.set(null, Java.to(a.concat(accessor.newInstance([name.toUpperCase(), 0, name])), "net.ccbluex.liquidbounce.features.module.ModuleCategory[]")), name);
this.remove = function (name) (this.values().some(function (v, i, a) v.getDisplayName().equalsIgnoreCase(name) && (a.splice(i, 1), !valuesField.set(null, Java.to(a, "net.ccbluex.liquidbounce.features.module.ModuleCategory[]")))), name);
this.get = function () target;
this.values = function () Java.from(valuesField.get(null));
}
function Reflector(object) object instanceof java.lang.Object ?
new JSAdapter() {
__get__: function (name) {
var field = getField(object, getSRGName(object, name, Core.remapperFields));
return field ? new Reflector(field.get(object)) : object[name];
},
__put__: function (name, value) {
var field = getField(object, getSRGName(object, name, Core.remapperFields));
field ? field.set(object, value) : object[name] = value;
},
__call__: function (name) {
switch (name) {
case "toString": return object.toString();
case "valueOf": return object;
default: return getMethod(object, getSRGName(object, name, Core.remapperMethods)).invoke(object, Java.to(Array.prototype.slice.call(arguments, 1), "java.lang.Object[]"));
}
}
} : object;
function TextEditor(file) file instanceof File && (
file.createNewFile(),
new JSAdapter() {
__get__: function (name) {
switch (name) {
case "text": return FileUtils.readFileToString(file)
case "file": return file
}
},
__put__: function (name, value) {
switch (name) {
case "text":
FileUtils.writeStringToFile(file, value);
return value
case "file": return file = value
}
},
__call__: function (name, value) {
switch (name) {
case "toString":
case "valueOf":
case "getText": return this.text
case "setText": return this.text = value
case "getFile": return file
case "setFile": return file = value
}
}
}
);
Core.dynamicValues = {
update: function (coreModule, forceAll) {
if (forceAll || mc.currentScreen instanceof ClickGui)
setValues(coreModule.module, coreModule.values.map(function (v) forceAll || !Array.isArray(v) || v[0].get() ? v : v[0]).flat())
}
};
value = {
createBlock: function (name, value) new BlockValue(name, value),
createBoolean: function (name, value, dynamicValues) {
if (!dynamicValues) return new BoolValue(name, value);
var instance = new (Java.extend(BoolValue)) (name, value) {
onChanged: function () {
for each (var coreModule in toArray(module)) Core.dynamicValues.update(coreModule);
}
}
Core.dynamicValues[instance] = [instance, dynamicValues].flat();
return instance
},
createFloat: function (name, value, min, max) new FloatValue(name, value, min, max),
createFont: function (name, value) new FontValue(name, value),
createInteger: function (name, value, min, max) new IntegerValue(name, value, min, max),
createList: function (name, values, value) new ListValue(name, values, value),
createText: function (name, value) new TextValue(name, value),
createSpacer: function () new BoolValue("", false),
createHeader: function (title) {
if (!title) return this.createSpacer();
title = title.replace(":", "");
var Adapter = Java.extend(TextValue);
return (Core.headers = Core.headers || {})[Adapter] = new Adapter(title, "") {
onChanged: function () {
Core.headers[Adapter].set("");
}
}
}
}
/*-------------------*/
/* Object extensions */
/*-------------------*/
//Array.shuffle([boolean]) - randomizes elements order, overwrites and returns the array
//parameters: boolean - optional; false -> doesn't shuffle
Object.defineProperty(Array.prototype, "shuffle", {
writable: true,
value: function (bool) {
var i = this.length, j, t;
if (bool === false || !i) return this;
while (--i) {
j = ~~(Math.random() * (i + 1)),
t = this.i;
this.i = this.j;
this.j = t;
} return this;
}
});
//Array.find(function, [boolean]) - finds the first element that fulfills a condition, returns the element or index of the element
//parameters: function - defines the condition, boolean - optional; true -> returns index
Object.defineProperty(Array.prototype, "find", {
value: function (func, returnIndex) {
for (var i in this) if (func(this[i], i, this)) return returnIndex ? +i : this[i];
return returnIndex ? -1 : null;
}
});
//Array.includes(element) - checks if array has an element, returns boolean
//parameters: element - element of the array to check for
Object.defineProperty(Array.prototype, "includes", {
value: function (element) this.indexOf(element) !== -1
});
//String.includes(string, [boolean]) - checks if a string contains other string, case sensitive / insensitive, returns boolean
//parameters: string - string to check for, boolean - optional; true -> case insensitive search
Object.defineProperty(String.prototype, "includes", {
value: function (string, ignoreCase) ignoreCase ? this.toString().toLowerCase().contains(string.toLowerCase()) : this.toString().contains(string)
});
//Array.remove(element) - removes element from array, returns if successful
//parameters: element - element to remove
Object.defineProperty(Array.prototype, "remove", {
value: function (element, _index) !!(~(_index = this.indexOf(element)) && this.splice(_index, 1))
});
//Array.last() - returns last element of array
Object.defineProperty(Array.prototype, "last", {
value: function () this[this.length - 1]
});
//Array.random([from: int], [to: int]) - returns a random element (between optional boundaries)
//parameters: from - minimal index, optional; to - maximal index, optional
Object.defineProperty(Array.prototype, "random", {
value: function (from, to) this.length > 0 ? this[Math.floor(rand(from || 0, (to + 1) || this.length))] : null
});
//Array.toLowerCase() - clones an array, all it's elements will be lowercase
Object.defineProperty(Array.prototype, "toLowerCase", {
value: function () this.map(function (element) element.toLowerCase())
});
//Array.flat(boolean) - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat
//parameters: false -> doesn't flatten
Object.defineProperty(Array.prototype, "flat", {
value: function (bool) bool === false ? this : Array.prototype.concat.apply([], this)
});
Math.trunc = function (v) (v = +v, (v - v % 1) || (!isFinite(v) || v === 0 ? v : v < 0 ? -0 : 0));
Math.toRadians = function (degrees) degrees * 0.01745329252;
Math.toDegrees = function (radians) radians * 57.29577951308;
/*----------------*/
/* Java importing */
/*----------------*/
Core.importedPackages = [
"net.minecraft.block", "net.minecraft.block.material", "net.minecraft.block.properties", "net.minecraft.block.state",
"net.minecraft.client.gui", "net.minecraft.client.gui.inventory",
"net.minecraft.client.renderer", "net.minecraft.client.renderer.block.model",
"net.minecraft.entity", "net.minecraft.entity.boss", "net.minecraft.entity.effect", "net.minecraft.entity.item", "net.minecraft.entity.monster", "net.minecraft.entity.passive", "net.minecraft.entity.player", "net.minecraft.entity.projectile",
"net.minecraft.init",
"net.minecraft.item",
"net.minecraft.network", "net.minecraft.network.handshake.client", "net.minecraft.network.login.client", "net.minecraft.network.login.server", "net.minecraft.network.play.client", "net.minecraft.network.play.client.C03PacketPlayer", "net.minecraft.network.play.server", "net.minecraft.network.status.client", "net.minecraft.network.status.server",
"net.minecraft.util",
"net.ccbluex.liquidbounce.utils", "net.ccbluex.liquidbounce.utils.block", "net.ccbluex.liquidbounce.utils.extensions", "net.ccbluex.liquidbounce.utils.item", "net.ccbluex.liquidbounce.utils.login", "net.ccbluex.liquidbounce.utils.misc", "net.ccbluex.liquidbounce.utils.render", "net.ccbluex.liquidbounce.utils.render.shader", "net.ccbluex.liquidbounce.utils.render.shader.shaders", "net.ccbluex.liquidbounce.utils.timer",
"net.ccbluex.liquidbounce.value",
"net.ccbluex.liquidbounce.event"
];
function importPackage() {
var packages = Array.prototype.slice.call(arguments);
Core.importedPackages = Core.importedPackages.concat(packages);
}
__noSuchProperty__ = function (name) {
if (name.endsWith("Module")) {
var module = LiquidBounce.moduleManager.getModule(name.slice(0, -6));
if (module) return this[name] = module;
}
for each (var package in Core.importedPackages) {
try {
var type = Java.type(package + "." + name);
return this[name] = type;
} catch (e) {}
}
throw new ReferenceError(name + " is not defined");
}
//Used variables
URL = Java.type("java.net.URL");
File = Java.type("java.io.File");
List = Java.type("java.util.List");
Timer = Java.type("java.util.Timer");
Class = Java.type("java.lang.Class");
Thread = Java.type("java.lang.Thread");
Desktop = java.awt.Desktop.getDesktop();
ArrayList = Java.type("java.util.ArrayList");
Field = Java.type("java.lang.reflect.Field");
Keyboard = Java.type("org.lwjgl.input.Keyboard");
Modifier = Java.type("java.lang.reflect.Modifier");
JOptionPane = Java.type("javax.swing.JOptionPane");
LinkedHashMap = Java.type("java.util.LinkedHashMap");
FileUtils = Java.type("org.apache.commons.io.FileUtils");
Script = Java.type("net.ccbluex.liquidbounce.script.Script");
Enchantment = Java.type("net.minecraft.enchantment.Enchantment");
LiquidBounce = Java.type("net.ccbluex.liquidbounce.LiquidBounce");
FileManager = Java.type("net.ccbluex.liquidbounce.file.FileManager");
Module = Java.type("net.ccbluex.liquidbounce.features.module.Module");
Command = Java.type("net.ccbluex.liquidbounce.features.command.Command");
Remapper = Java.type("net.ccbluex.liquidbounce.script.remapper.Remapper");
ScriptModule = Java.type("net.ccbluex.liquidbounce.script.api.ScriptModule");
ClickGui = Java.type("net.ccbluex.liquidbounce.ui.client.clickgui.ClickGui");
ValuesConfig = Java.type("net.ccbluex.liquidbounce.file.configs.ValuesConfig");
ModuleCategory = Java.type("net.ccbluex.liquidbounce.features.module.ModuleCategory");
PositionedSoundRecord = Java.type("net.minecraft.client.audio.PositionedSoundRecord");
Core.outboundPacketsQueueField = getField(NetworkManager, "field_150745_j");
Core.flushOutboundQueueMethod = getMethod(NetworkManager, "func_150733_h");
Core.dispatchPacketMethod = getMethod(NetworkManager, "func_150732_b");
Core.registeredCommandsField = getField(Script, "registeredCommands");
Core.readWriteLockField = getField(NetworkManager, "field_181680_j");
Core.registeredModulesField = getField(Script, "registeredModules");
Core.remapperMethods = getField(Remapper, "methods").get(Remapper);
Core.remapperFields = getField(Remapper, "fields").get(Remapper);
Core.callEventMethod = getMethod(ScriptModule, "callEvent");
/*-------------*/
/* Event hooks */
/*-------------*/
Core.hookClickGui = function () {
LiquidBounce.clickGui = new (Java.extend(ClickGui))() {
func_73866_w_: function () {
callEvent("clickGuiOpen");
},
func_146281_b: function () {
callEvent("clickGuiClosed");
LiquidBounce.fileManager.saveConfig(LiquidBounce.fileManager.clickGuiConfig);
}
}
LiquidBounce.fileManager.loadConfig(LiquidBounce.fileManager.clickGuiConfig);
if (mc.currentScreen instanceof ClickGui) ClickGUIModule.onEnable();
callEvent("clickGuiLoaded");
};
Core.hookFileManager = function () {
Core.ignoreValueChange = false;
LiquidBounce.fileManager = new (Java.extend(FileManager))() {
saveConfig: function (config) {
if (config instanceof ValuesConfig) {
if (Core.ignoreValueChange) Core.ignoreValueChange = false;
else callEvent("valueChanged");
}
Java.super(LiquidBounce.fileManager).saveConfig(config);
}
}
}
Core.hookReloader = function () {
var ReloadCommand = Java.type("net.ccbluex.liquidbounce.features.command.commands.ReloadCommand"),
ModuleCommand = Java.type("net.ccbluex.liquidbounce.features.module.ModuleCommand"),
Fonts = Java.type("net.ccbluex.liquidbounce.ui.font.Fonts"),
FileConfigClass = Java.type("net.ccbluex.liquidbounce.file.FileConfig").class;
for each (var command in LiquidBounce.commandManager.commands.clone()) {
if (command instanceof ReloadCommand) {
LiquidBounce.commandManager.commands.remove(command);
return Core.registerCommand({
name: "Reloader",
aliases: ["reload", "r"],
author: "CzechHek",
version: "4.1",
handler: function (type) {
clearChat();
switch (type.toLowerCase()) {
case "scripts":
LiquidBounce.INSTANCE.setStarting(true);
scriptManager.disableScripts();
scriptManager.unloadScripts();
for each (var command in LiquidBounce.commandManager.commands.clone())
command instanceof ModuleCommand && command.getModule() instanceof ScriptModule && LiquidBounce.commandManager.unregisterCommand(command);
for each (var file in scriptManager.scriptsFolder.listFiles()) {
if (file.getName().endsWith(".js")) {
var newScript = new Script(file);
try {
newScript.initScript();
} catch (e) {
print("§4▏ §c§lFailed§c to reload script „§4" + file.getName().slice(0, -3) + "§c“§4!");
print(e);
continue
}
scriptManager.scripts.add(newScript);
}
}
scriptManager.enableScripts();
LiquidBounce.fileManager.loadConfigs(LiquidBounce.fileManager.modulesConfig, LiquidBounce.fileManager.valuesConfig);
Core.hookClickGui();
LiquidBounce.INSTANCE.setStarting(false);
scriptManager.scripts.length && print("§2▏ §a§lReloaded§a scripts§2! §8(§7§l" + scriptManager.scripts.length + "§8)");
break
case "clickgui":
Core.hookClickGui();
print("§2▏ §a§lReloaded§a ClickGUI§2!");
break
case "fonts":
Fonts.loadFonts();
print("§2▏ §a§lReloaded§a all fonts§2! §8(§7§l" + Fonts.getFonts().length + "§8)");
break
case "configs":
LiquidBounce.fileManager.loadAllConfigs();
print("§2▏ §a§lReloaded§a all configs§2! §8(§7§l" + Java.from(LiquidBounce.fileManager.class.superclass.getDeclaredFields()).filter(function (field) field.getType() == FileConfigClass).length + "§8)");
break
default:
var targetScript = Java.from(scriptManager.scripts).find(function (script) script.scriptName.equalsIgnoreCase(type));
if (!targetScript) return print("§4▏ §cScript „§4" + type + "§c“ §lnot found§4!");
LiquidBounce.INSTANCE.setStarting(true);
targetScript.onDisable();
scriptManager.scripts.remove(targetScript);
var registeredModules = Core.registeredModulesField.get(targetScript);
if (registeredModules.length) {
for each (var command in LiquidBounce.commandManager.commands.clone()) {
if (!(command instanceof ModuleCommand)) continue
for each (var module in registeredModules) {
if (command.getModule() == module) {
LiquidBounce.commandManager.unregisterCommand(command);
registeredModules.remove(module);
break
}
}
}
}
var newScript = new Script(targetScript.scriptFile);
try {
newScript.initScript();
} catch (e) {
print("§4▏ §c§lFailed§c to reload script „§4" + type + "§c“§4!");
print(e);
LiquidBounce.INSTANCE.setStarting(false);
return
}
scriptManager.scripts.add(newScript);
newScript.onEnable();
LiquidBounce.fileManager.loadConfigs(LiquidBounce.fileManager.modulesConfig, LiquidBounce.fileManager.valuesConfig);
Core.hookClickGui();
LiquidBounce.INSTANCE.setStarting(false);
print("§2▏ §aScript „§2" + type + "§a“ §lreloaded§2!");
}
},
onTabComplete: function (args) {
var options = Java.from(scriptManager.scripts).map(function (script) script.scriptName);
options.push("Fonts", "ClickGUI", "Scripts", "Configs");
return options.filter(function (name) name.toLowerCase().startsWith(args[0].toLowerCase()));
}
}, true);
}
}
}
/*---------------*/
/* Updating core */
/*---------------*/
Core.runUpdater = function () {
(Core.logFile = new File("logs/core.log")).deleteOnExit();
Core.log = Core.logFile.exists() ? JSON.parse(FileUtils.readFileToString(Core.logFile)) : {};
var scriptCache, responseCache, charset = java.nio.charset.Charset.forName("UTF-8");
if (!Core.log.Core) {
try {
if ((responseCache = (scriptCache = HttpUtils.get("https://raw.githubusercontent.com/CzechHek/Core/master/Core.lib")).match(/version: "(.+)"/)[1]) != Core.version) {
FileUtils.writeStringToFile(new File(LiquidBounce.fileManager.dir, "scripts/Core.lib"), scriptCache, charset);
var changelog = JSON.parse(HttpUtils.get("https://api.github.com/repos/CzechHek/Core/commits?path=Core.lib"))[0].commit.message;
showMessage("Automatically updated Core " + Core.version + " to " + responseCache + (changelog ? "\nChangelog:\n" + changelog : ""), "Core Updater");
Core.shouldReload = true;
}
Core.log.Core = true;
} catch (e) {
print("Couldn't check Core for updates! Error:", e);
Core.log.Core = e.toString();
}
}
if ((Core.updateURL || Core.updateURL === undefined) && !Core.log[script.scriptName]) {
try {
if ((responseCache = (scriptCache = HttpUtils.get(Core.updateURL || "https://raw.githubusercontent.com/CzechHek/Core/master/Scripts/" + script.scriptName + ".js")).match(/version"?\s*:\s*"?([^"]+)"?[\n\s,}]/)[1]) != script.scriptVersion) {
FileUtils.writeStringToFile(script.getScriptFile(), scriptCache, charset);
var changelog = Core.updateURL ? "" : JSON.parse(HttpUtils.get("https://api.github.com/repos/CzechHek/Core/commits?path=Scripts/" + script.scriptName + ".js"))[0].commit.message;
showMessage("Automatically updated " + script.scriptName + " " + script.scriptVersion + " to " + responseCache + (changelog ? "\nChangelog:\n" + changelog : ""), "Core Updater");
Core.shouldReload = true;
}
Core.log[script.scriptName] = true;
} catch (e) {
print("Couldn't check", script.scriptName, "for updates! Error:", e);
Core.log[script.scriptName] = e.toString();
}
}
if (!Core.shouldReload && (!Core.log.eventHooks || Core.log.eventHooks == script.scriptName)) {
Core.log.eventHooks = script.scriptName;
LiquidBounce.clickGui = null;
var timer = interval(250, function () {
if (LiquidBounce.clickGui) {
Core.hookClickGui();
Core.hookFileManager();
Core.hookReloader();
timer.cancel();
timer.purge();
}
});
}
FileUtils.writeStringToFile(Core.logFile, JSON.stringify(Core.log));
}
/*-------------------*/
/* Module management */
/*-------------------*/
script.on("load", function () {
module = toArray(module || {}); command = toArray(command || {});
if (!Core.API_V2) {
script.scriptName = (script.scriptName === "Legacy Script" ? scriptName || module[0].name || command[0].name || (command[0].aliases && command[0].aliases[0]) || script.getScriptFile().getName().slice(0, -3) : script.scriptName).toString();
script.scriptAuthors = script.scriptAuthors[0] === "Please Update Script" ? toArray((scriptAuthor || module[0].author || command[0].author || "Author").toString()) : script.scriptAuthors;
script.scriptVersion = (script.scriptVersion === "1.0.0" ? scriptVersion || module[0].version || command[0].version || "1.0.0" : script.scriptVersion).toString();
}
Core.runUpdater();
if (Core.shouldReload) {
script.on("enable", function () timeout(1000, function () scriptManager.scripts.remove(script))); //Prevents ConcurrentModificationException if a script gets updated after reloading scripts.
scriptManager.scripts.add(new Script(script.getScriptFile()));
return
}
Core.categories = new EditableEnum(ModuleCategory);
Core.eventManager = new Reflector(LiquidBounce.eventManager);
Core.scriptReflector = new Reflector(script);
Core.defaultAnnotation = getMethod(LiquidBounce.moduleManager, "onKey").getAnnotation(EventTarget.class);
Core.artificialEvents = {
onBlockBB: BlockBBEvent.class,
onClickWindow: ClickWindowEvent.class,
onEntityMovement: EntityMovementEvent.class,
onPushOut: PushOutEvent.class,
onRenderEntity: RenderEntityEvent.class,
onScreen: ScreenEvent.class,
onText: TextEvent.class,
onTick: TickEvent.class
};
[module, command].forEach(function (c, i) c.forEach(function (v) Core[["registerModule", "registerCommand"][i]](v)));
script.on("enable", function () {
for each (var c in [module, command]) for each (var v in c) v.onLoad && v.onLoad();
Core.onLoad && Core.onLoad();
});
script.on("disable", function () {
for each (var c in [module, command]) for each (var v in c) v.onUnload && v.onUnload();
//Unregistering artificial event hooks
for each (var entry in Core.hookedEvents.entrySet()) {
var key = entry.getKey(), targets = entry.getValue();
for each (var target in targets) Core.eventManager.registry[key].remove(target);
}
if (Core.log.eventHooks == script.scriptName) {
Core.log = JSON.parse(FileUtils.readFileToString(Core.logFile));
delete Core.log.eventHooks;
FileUtils.writeStringToFile(Core.logFile, JSON.stringify(Core.log));
}
Core.onUnload && Core.onUnload();
});
});