-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtensor.js
More file actions
3529 lines (3085 loc) · 136 KB
/
tensor.js
File metadata and controls
3529 lines (3085 loc) · 136 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
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name Tensor
// @namespace Scripts
// @match https://*.bloxd.io/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant unsafeWindow
// @run-at document-end
// @version 1.0.0
// @author -
// @description Tensor Framework for Bloxd.io
// ==/UserScript==
(() => {
// tensor-src/utils.js
// src/utils.js
// 工具函数库(基于 inject.js)
var keys = (obj) => Object.keys(obj ?? {});
var values = (obj) => keys(obj).map((key) => obj[key]);
var entries = (obj) => Object.entries(obj ?? {});
var attempt = (fn, fallback = null) => {
try {
return fn();
} catch {
return fallback;
}
};
var clone = typeof structuredClone === 'function'
? structuredClone
: (obj) => obj && JSON.parse(JSON.stringify(obj));
var style = (el3, props) => Object.assign(el3.style, props);
var el = (tag) => document.createElement(tag);
var floor = Math.floor;
// Export as utils object(保持 Tensor 兼容性)
const utils = { keys, values, entries, attempt, clone, style, el, floor };
// tensor-src/config.js
// Configuration System
const config = {
keyMap: {},
killaura: { delay: 120, range: 6.8, jitterRatio: 0.4 },
scaffold: { interval: 20 },
slowSwing: { duration: 2000 }
};
const moduleNames = ["Killaura", "Scaffold", "SlowSwing", "CoordsList", "ESP", "Bhop"];
const defaultKeybinds = {
Killaura: "KeyK", ESP: "KeyE", CoordsList: "KeyL",
Scaffold: "KeyG", SlowSwing: "KeyH", Bhop: "KeyB"
};
// tensor-src/bloxd.js
// src/bloxd.js - 基于 inject.js 的注入核心(完整版本)
// ============================================
// 核心注入对象 B
// ============================================
var B = {
wpRequire: null,
_noa: null,
bloxdProps: null,
get noa() {
if (!this._noa && this.bloxdProps) {
this._noa = values(this.bloxdProps).find((p) => p?.entities);
}
return this._noa;
},
clear() {
this.wpRequire = null;
this._noa = null;
this.bloxdProps = null;
},
init(force = false) {
if (this.wpRequire && !force) return;
this.clear();
// 处理 Tampermonkey 沙盒环境
const globalWindow = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
// 方法 1: 通过描述符查找 Webpack chunk setter
let descriptors = Object.getOwnPropertyDescriptors(globalWindow);
let chunkKey = Object.keys(descriptors).find((key) => {
let setter = descriptors[key]?.set;
return setter && setter.toString().includes("++");
});
// 方法 2: 通过数组属性查找 Webpack chunk
if (!chunkKey) {
chunkKey = Object.keys(globalWindow).find((key) => {
let value = globalWindow[key];
return Array.isArray(value) && typeof value.push === "function";
});
}
// 如果仍然找不到,抛出错误
if (!chunkKey) {
throw new Error("无法定位 Webpack chunk");
}
// 注入自定义模块
let chunk = globalWindow[chunkKey];
let randomID = Math.floor(Math.random() * 9999999) + 1;
chunk.push([[randomID], {}, (req) => this.wpRequire = req]);
// 查找游戏属性对象
this.bloxdProps = values(this.findModule("nonBlocksClient:")).find(
(o) => typeof o === "object"
);
this._noa = null;
},
findModule(str) {
if (!this.wpRequire) return null;
let mods = this.wpRequire.m;
for (let id in mods) {
let modFn = mods[id];
if (modFn && modFn.toString().includes(str))
return this.wpRequire(id);
}
return null;
},
reinject() {
try {
this.init(true);
return true;
} catch (error) {
return false;
}
}
};
// ============================================
// 游戏上下文辅助函数
// ============================================
var getImpKey = () => attempt(() => {
let entities = B.noa.entities;
let target = values(entities)[2];
return entries(entities).find(([, val]) => val === target)?.[0] ?? null;
});
var getInventoryContext = () => {
let noa = B.noa;
if (!noa) return null;
let entities = noa.entities;
let impKey = getImpKey();
if (!impKey) return null;
let entity = entities[impKey];
if (!entity) return null;
let inventoryWrapper = values(entity).find(
(value) => value?.list?.[0]?._blockItem
);
if (!inventoryWrapper?.list?.length) return null;
let listItem = inventoryWrapper.list[0];
return { impKey, entity, inventoryWrapper, listItem };
};
var getHeldBlockContext = () => {
let ctx = getInventoryContext();
if (!ctx) return null;
let heldBlock = ctx.listItem?._blockItem;
if (!heldBlock) return null;
let playerEntity = values(ctx.listItem).find(
(value) => typeof value?.checkTargetedBlockCanBePlacedOver === "function"
);
if (!playerEntity) return null;
let worldInstanceKey, worldInstance;
if (keys(heldBlock).some((key) => {
let value = heldBlock[key];
if (value && typeof value === "object") {
worldInstanceKey = key;
worldInstance = value;
return true;
}
return false;
}), !worldInstanceKey || !worldInstance) return null;
let targetedBlockKey = null, targetedBlock = null;
keys(worldInstance).some((key) => {
let value = worldInstance[key];
if (value && typeof value === "object" && (value.normal || value.position)) {
targetedBlockKey = key;
targetedBlock = value;
return true;
}
return false;
});
return {
heldBlock,
worldInstanceKey,
worldInstance,
targetedBlockKey,
targetedBlock,
playerEntity
};
};
var createSpoofedContext = (context, position) => {
let {
heldBlock,
worldInstanceKey,
worldInstance,
targetedBlockKey,
targetedBlock
} = context, safeTarget = clone(targetedBlock) || {
normal: [0, 1, 0],
position: [...position],
blockPosition: position.map(floor),
hitPoint: [...position]
};
return safeTarget.position = [...position], safeTarget.blockPosition = safeTarget.blockPosition ?? position.map(floor), safeTarget.normal = safeTarget.normal ?? [0, 1, 0], safeTarget.hitPoint = safeTarget.hitPoint ?? [...position], new Proxy(
{},
{
get(_target, prop) {
if (prop === worldInstanceKey)
return new Proxy(worldInstance, {
get(inner, key) {
return key === targetedBlockKey ? safeTarget : inner[key];
}
});
if (prop === "checkTargetedBlockCanBePlacedOver") return () => !0;
let value = heldBlock[prop];
return typeof value == "function" ? value.bind(heldBlock) : value;
}
}
);
}, placeSpoofedBlock = (position, context) => {
let ctx = context ?? getHeldBlockContext();
return ctx?.heldBlock?.placeBlock ? attempt(() => {
let spoofed = createSpoofedContext(ctx, position);
return ctx.heldBlock.placeBlock.call(spoofed), !0;
}, !1) : !1;
};
// tensor-src/modules/base.js
// Tensor Module Base Class (compatible with minin)
var Module = class {
constructor(name) {
this.name = name, this.enabled = !1;
}
onEnable() {
}
onDisable() {
}
onRender() {
}
toggle() {
this.enabled ? this.disable() : this.enable();
}
enable() {
this.enabled || (this.enabled = !0, this.onEnable());
}
disable() {
this.enabled && (this.enabled = !1, this.onDisable());
}
}, base_default = Module;
// TensorModule for Tensor framework compatibility
class TensorModule extends Module {
constructor(name, tensor) {
super(name);
this.tensor = tensor;
}
enable() { super.enable(); }
disable() { super.disable(); }
update() {}
getConfig() { return this.tensor.config.modules[this.name] || {}; }
setConfig(config) { this.tensor.config.modules[this.name] = config; this.tensor.saveConfig(); }
}
// tensor-src/math.js
// src/math.js
// 数学函数库(基于 inject.js)
var norm = (v) => {
let s = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
if (!s) return v;
let i = 1 / Math.sqrt(s);
return [v[0] * i, v[1] * i, v[2] * i];
};
var dist = (a, b) => {
let dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2];
return Math.sqrt(dx * dx + dy * dy + dz * dz);
};
var distSq = (a, b) => {
let dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2];
return dx * dx + dy * dy + dz * dz;
};
// 数学对象导出(保持 Tensor 兼容性)
var math = { norm, dist, distSq };
// tensor-src/game.js
// Game API for Tensor - 基于 inject.js 的完整版本
var gameAPI = {
/**
* 获取实体位置
* @param {number} id - 实体 ID
* @returns {number[]|null} 位置数组 [x, y, z]
*/
getPosition: (id) => attempt(() => B.noa.entities.getState(id, "position").position),
/**
* 获取实体移动状态
* @param {number} id - 实体 ID
* @returns {Object|null} 移动状态对象
*/
getMoveState: (id) => attempt(() => B.noa.entities.getState(id, "movement")),
/**
* 获取游戏注册表
*/
get registry() {
return attempt(() => values(B.noa)[17], {});
},
/**
* 获取方块硬度检查函数
*/
get getSolidity() {
return values(this.registry)[5];
},
/**
* 获取方块 ID 获取函数
*/
get getBlockID() {
return attempt(
() => {
let names = Object.getOwnPropertyNames(B.noa.bloxd.constructor.prototype);
return B.noa.bloxd[names[3]].bind(B.noa.bloxd);
},
() => 0
);
},
/**
* 获取手持物品获取函数
*/
getHeldItemGetter() {
return attempt(
() => values(B.noa.entities).find((fn) => {
if (typeof fn !== "function" || fn.length !== 1) return false;
let body = fn.toString();
return body.length < 80 && body.includes(").") && !body.includes("opWrapper");
})
);
},
/**
* 安全获取手持物品
* @param {number} id - 实体 ID
* @returns {Object|null} 手持物品对象
*/
safeHeld(id) {
let getter = this.getHeldItemGetter();
return getter ? attempt(() => getter(id)) : null;
},
/**
* 获取玩家列表(排除自己)
*/
get playerList() {
return attempt(() => {
let ids = B.noa?.bloxd?.getPlayerIds?.();
return ids ? Object.values(ids).map(Number).filter((id) =>
id && id !== 1 && this.safeHeld(id)) : [];
}, []);
},
/**
* 获取攻击函数
*/
get doAttack() {
let held = this.safeHeld(1);
if (!held) return () => {};
let attack = held.doAttack || held.breakingItem?.doAttack;
return attack ? attack.bind(held) : () => {};
},
/**
* 检查是否接触墙壁
*/
touchingWall() {
let pos = this.getPosition(1);
if (!pos) return false;
let r = 0.35, offsets = [[0,0],[r,0],[-r,0],[0,r],[0,-r],[r,r],[r,-r],[-r,r],[-r,-r]], heights = [0,1,2], getId = this.getBlockID;
for (let [ox, oz] of offsets) for (let h of heights) {
let id = attempt(() => getId(floor(pos[0] + ox), floor(pos[1]) + h, floor(pos[2] + oz)), null);
if (id !== null && this.getSolidity(id)) return true;
}
return false;
},
/**
* 获取手持物品状态
*/
getHeldItemState() {
return getHeldBlockContext()?.playerEntity?.heldItemState || null;
},
/**
* 放置方块(封装)
* @param {number[]} position - 放置位置
* @returns {boolean} 是否成功
*/
placeBlock: (position) => placeSpoofedBlock(position),
/**
* 获取玩家 ID 列表
*/
getPlayerIds: () => attempt(() => B.noa?.bloxd?.getPlayerIds?.(), {}),
/**
* 获取实体名称映射
*/
getEntityNames: () => attempt(() => B.noa?.bloxd?.entityNames, {}),
/**
* 计算距离(独立实现,避免依赖 math 变量)
* @param {number[]} a - 点 A
* @param {number[]} b - 点 B
* @returns {number} 距离
*/
distance(a, b) {
let dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2];
return Math.sqrt(dx * dx + dy * dy + dz * dz);
},
/**
* 计算距离平方(独立实现,避免依赖 math 变量)
* @param {number[]} a - 点 A
* @param {number[]} b - 点 B
* @returns {number} 距离平方
*/
distanceSquared(a, b) {
let dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2];
return dx * dx + dy * dy + dz * dz;
},
/**
* 向量归一化(独立实现,避免依赖 math 变量)
* @param {number[]} v - 向量
* @returns {number[]} 归一化后的向量
*/
normalize(v) {
let s = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
if (!s) return v;
let i = 1 / Math.sqrt(s);
return [v[0] * i, v[1] * i, v[2] * i];
}
};
// tensor-src/modules/Killaura.js
// Killaura Module
class KillauraModule extends TensorModule {
constructor(name, tensor) {
super(name, tensor);
this.lastAttack = 0;
this.config = { delay: 120, range: 6.8, jitter: 0.4 };
}
enable() { super.enable(); this.lastAttack = 0; }
update() {
if (!this.enabled) return;
const now = Date.now();
const effectiveDelay = this.config.delay + (this.config.delay * this.config.jitter * (Math.random() - 0.5));
if (now - this.lastAttack < effectiveDelay) return;
this.lastAttack = now;
const playerPos = this.tensor.gameAPI.getPosition(1);
if (!playerPos) return;
const rangeSq = this.config.range * this.config.range;
const players = this.tensor.gameAPI.playerList;
for (const playerId of players) {
const enemyPos = this.tensor.gameAPI.getPosition(playerId);
if (!enemyPos || this.tensor.gameAPI.distanceSquared(playerPos, enemyPos) > rangeSq) continue;
const vector = this.tensor.gameAPI.normalize([
enemyPos[0] - playerPos[0],
enemyPos[1] - playerPos[1],
enemyPos[2] - playerPos[2]
]);
this.tensor.gameAPI.doAttack(vector, playerId.toString(), "BodyMesh");
}
}
}
// tensor-src/modules/Scaffold.js
// Scaffold Module
class ScaffoldModule extends TensorModule {
constructor(name, tensor) {
super(name, tensor);
this.config = { interval: 20 };
this.intervalId = null;
}
enable() {
super.enable();
this.intervalId = setInterval(() => {
if (this.enabled) this.tryPlace();
}, this.config.interval);
}
disable() {
super.disable();
if (this.intervalId) {
clearInterval(this.intervalId);
this.intervalId = null;
}
}
tryPlace() {
const ctx = getHeldBlockContext();
if (!ctx?.playerEntity || ctx.playerEntity.heldItemState?.heldType !== "CubeBlock") return;
const pos = this.tensor.gameAPI.getPosition(1);
if (!pos) return;
const blockX = Math.floor(pos[0]), blockY = Math.floor(pos[1]), blockZ = Math.floor(pos[2]);
const target = [blockX, blockY - 1, blockZ];
placeSpoofedBlock(target, ctx);
}
}
// tensor-src/modules/SlowSwing.js
// SlowSwing Module
class SlowSwingModule extends TensorModule {
constructor(name, tensor) {
super(name, tensor);
this.config = { duration: 2000 };
this.normalDuration = 200;
}
enable() {
super.enable();
const heldState = this.tensor.gameAPI.getHeldItemState();
if (heldState) heldState.swingDuration = this.config.duration;
}
disable() {
super.disable();
const heldState = this.tensor.gameAPI.getHeldItemState();
if (heldState) heldState.swingDuration = this.normalDuration;
}
}
// tensor-src/modules/CoordsList.js
// CoordsList Module
class CoordsListModule extends TensorModule {
constructor(name, tensor) {
super(name, tensor);
this.disabled = true;
}
enable() { super.enable(); this.disabled = false; }
disable() { super.disable(); this.disabled = true; }
update() {
if (!this.enabled || this.disabled) return;
const entityNames = this.tensor.gameAPI.getEntityNames();
if (!entityNames) return;
for (let entityId in entityNames) {
if (entityId === "1") continue;
const entityData = entityNames[entityId];
const position = this.tensor.gameAPI.getPosition(entityId);
if (!position) continue;
const x = Math.round(position[0]), y = Math.round(position[1]), z = Math.round(position[2]);
const baseName = entityData.entityName.replace(/\s*\(\-?\d+,\s*\-?\d+,\s*\-?\d+\)$/, "");
entityData.entityName = `${baseName} (${x}, ${y}, ${z})`;
}
}
}
// tensor-src/modules/ESP.js
// ESP Module
class ESPModule extends TensorModule {
constructor(name, tensor) {
super(name, tensor);
this.intervalId = null;
}
enable() {
super.enable();
this.updateVisibility(true);
this.intervalId = setInterval(() => this.updateVisibility(true), 300);
}
disable() {
super.disable();
if (this.intervalId) clearInterval(this.intervalId);
this.updateVisibility(false);
}
updateVisibility(state) {
if (!B.noa) return;
const rendering = values(B.noa)[12];
if (!rendering) return;
const thinMeshes = values(rendering).find(v => v?.thinMeshes)?.thinMeshes;
if (!Array.isArray(thinMeshes)) return;
const renderingGroupId = state ? 2 : 0;
for (let item of thinMeshes) {
const mesh = item?.meshVariations?.__DEFAULT__?.mesh;
if (mesh && typeof mesh.renderingGroupId == "number") {
mesh.renderingGroupId = renderingGroupId;
}
}
}
}
// tensor-src/modules/Bhop.js
// Bhop Module
class BhopModule extends TensorModule {
constructor(name, tensor) {
super(name, tensor);
this.intervalId = null;
this.moveState = null;
this.movement = null;
this.bunnyhopping = false;
}
enable() {
super.enable();
this.startBhop();
}
disable() {
super.disable();
this.stopBhop();
}
startBhop() {
this.moveState = this.tensor.gameAPI.getMoveState(1);
if (this.moveState) this.movement = attempt(() => B.noa.entities.getState(1, "movement"));
this.intervalId = setInterval(() => this.bhopTick(), 1);
}
stopBhop() {
if (this.intervalId) clearInterval(this.intervalId);
this.bunnyhopping = false;
this.moveState = null;
this.movement = null;
}
bhopTick() {
if (!this.moveState) return;
if (this.moveState._isAlive) {
if (this.moveState.crouching || this.moveState.speed < 0.05 || this.movement?._flying) {
if (this.bunnyhopping) {
if (B.noa?.inputs?.state) B.noa.inputs.state.jump = false;
this.bunnyhopping = false;
}
} else {
if (!this.bunnyhopping) this.bunnyhopping = true;
if (this.movement?.isOnGround?.()) {
if (B.noa?.inputs?.state) B.noa.inputs.state.jump = true;
} else {
if (B.noa?.inputs?.state) B.noa.inputs.state.jump = false;
}
}
}
}
}
// tensor-src/modules/index.js
// Tensor modules will be registered by Tensor framework
var modules = [];
// tensor-src/core/Tensor.js
// Tensor Core Framework
const Tensor = {
modules: new Map(),
gameAPI: gameAPI,
B: B,
utils: utils,
get math() {
if (typeof math !== 'undefined') return math;
// Fallback math implementation
console.warn('[Tensor] math variable not found, using fallback');
return {
norm(v) {
let s = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
if (!s) return v;
let i = 1 / Math.sqrt(s);
return [v[0] * i, v[1] * i, v[2] * i];
},
dist(a, b) {
let dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2];
return Math.sqrt(dx * dx + dy * dy + dz * dz);
},
distSq(a, b) {
let dx = b[0] - a[0], dy = b[1] - a[1], dz = b[2] - a[2];
return dx * dx + dy * dy + dz * dz;
}
};
},
config: {
modules: {},
ui: { theme: 'dark', position: { x: 10, y: 10 }, fontSize: 14, showSidebar: true },
sounds: { enabled: true, volume: 0.5 },
keybinds: {}
},
uiContainer: null,
island: null,
panel: null,
toast: null,
isDragging: false,
audio: { on: null, off: null, initialized: false },
// Keybind system
keybind: {
setting: false, // 是否正在设置快捷键
targetModule: null, // 正在设置快捷键的模块名
targetElement: null, // 正在设置快捷键的元素
keyMap: new Map(), // 快捷键映射表 (key -> moduleName)
listeners: new Map() // 事件监听器存储
},
init() {
console.log('[Tensor] Initializing framework...');
console.log('[Tensor] math variable:', math);
console.log('[Tensor] Tensor.math property:', this.math);
this.loadConfig();
// Initialize keybind system
this.initKeybinds();
console.log('[Tensor] B.noa:', B.noa);
console.log('[Tensor] B.wpRequire:', B.wpRequire);
console.log('[Tensor] B.bloxdProps:', B.bloxdProps);
// Initialize audio system
this.initAudio();
this.initUI();
this.loadBuiltInModules();
this.loadUserModules();
this.updateSidebar();
console.log('[Tensor] Framework ready');
},
// Audio System
initAudio() {
if (!this.config.sounds.enabled) {
console.log('[Tensor] Audio system disabled');
return;
}
try {
// Create audio elements (lazy loading)
this.audio.on = new Audio();
this.audio.off = new Audio();
// Set audio sources
this.audio.on.src = 'https://tuku.wigwy.xyz/down.php/b3d852a5ac7f7bd18693422bef43d6f6.wav';
this.audio.off.src = 'https://tuku.wigwy.xyz/down.php/6c0219c7e47f836fe923fcbd953084ae.wav';
// Set volume
this.audio.on.volume = this.config.sounds.volume;
this.audio.off.volume = this.config.sounds.volume;
// Set preload to metadata (load only metadata, not the entire file)
this.audio.on.preload = 'metadata';
this.audio.off.preload = 'metadata';
// Handle loading errors
this.audio.on.onerror = () => console.warn('[Tensor] Failed to load ON sound');
this.audio.off.onerror = () => console.warn('[Tensor] Failed to load OFF sound');
this.audio.initialized = true;
console.log('[Tensor] Audio system initialized (lazy loading)');
} catch (error) {
console.warn('[Tensor] Failed to initialize audio system:', error);
this.audio.initialized = false;
}
},
playSound(type) {
if (!this.config.sounds.enabled || !this.audio.initialized) return;
try {
let audio;
if (type === 'on') {
audio = this.audio.on;
} else if (type === 'off') {
audio = this.audio.off;
} else {
console.warn(`[Tensor] Unknown sound type: ${type}`);
return;
}
// Reset audio to start
audio.currentTime = 0;
// Play sound
audio.play().catch(e => console.debug('[Tensor] Audio play failed:', e));
} catch (error) {
console.debug('[Tensor] Error playing sound:', error);
}
},
// Keybind System
getKeybind(moduleName) {
// 获取模块的快捷键,如果没有则返回'none'
return this.config.keybinds[moduleName] || 'none';
},
setKeybind(moduleName, key) {
// 设置模块的快捷键
if (key === 'none' || key === null || key === undefined) {
// 移除快捷键
delete this.config.keybinds[moduleName];
} else {
// 检查是否已被其他模块使用
const existingModule = Object.keys(this.config.keybinds).find(name =>
this.config.keybinds[name] === key && name !== moduleName
);
if (existingModule) {
// 移除其他模块的该快捷键
delete this.config.keybinds[existingModule];
}
// 设置新快捷键
this.config.keybinds[moduleName] = key;
}
this.saveConfig();
this.updateKeyMap();
return true;
},
removeKeybind(moduleName) {
// 移除模块的快捷键
delete this.config.keybinds[moduleName];
this.saveConfig();
this.updateKeyMap();
return true;
},
updateKeyMap() {
// 更新内部快捷键映射表
this.keybind.keyMap.clear();
Object.entries(this.config.keybinds).forEach(([moduleName, key]) => {
if (key && key !== 'none') {
this.keybind.keyMap.set(key.toLowerCase(), moduleName);
}
});
},
initKeybinds() {
// 初始化快捷键系统
this.updateKeyMap();
this.setupGlobalKeyListeners();
console.log('[Tensor] Keybind system initialized');
},
setupGlobalKeyListeners() {
// 移除旧的监听器
this.keybind.listeners.forEach((listener, event) => {
document.removeEventListener(event, listener);
});
this.keybind.listeners.clear();
// 添加全局键盘事件监听
const keydownHandler = (e) => {
if (this.keybind.setting) {
// 如果正在设置快捷键,忽略按键触发
return;
}
// 获取按下的键
let key = e.key.toLowerCase();
// 处理特殊键
if (e.ctrlKey && key !== 'control') key = 'ctrl+' + key;
if (e.shiftKey && key !== 'shift') key = 'shift+' + key;
if (e.altKey && key !== 'alt') key = 'alt+' + key;
if (e.metaKey && key !== 'meta') key = 'meta+' + key;
// 检查是否有模块绑定到此键
const moduleName = this.keybind.keyMap.get(key);
if (moduleName) {
// 触发模块切换
this.toggleModule(moduleName);
this.updateModuleList();
this.showToast(`Module "${moduleName}" toggled by keybind "${key}"`);
e.preventDefault();
}
};
// 添加事件监听器
document.addEventListener('keydown', keydownHandler);
this.keybind.listeners.set('keydown', keydownHandler);
},
startKeybindSetting(moduleName, element) {
// 开始设置快捷键
if (this.keybind.setting) {
this.cancelKeybindSetting();
}
this.keybind.setting = true;
this.keybind.targetModule = moduleName;
this.keybind.targetElement = element;
// 更新UI显示正在设置
element.classList.add('setting');
element.textContent = 'Press any key...';
// 添加临时全局按键监听器
const tempKeyHandler = (e) => {
e.preventDefault();
e.stopPropagation();
// 处理ESC键取消
if (e.key.toLowerCase() === 'escape') {
this.cancelKeybindSetting();
return;
}
let key = e.key.toLowerCase();
// 忽略部分特殊键
if (key === 'control' || key === 'shift' || key === 'alt' || key === 'meta' ||
key === 'capslock' || key === 'tab' || key === 'enter' || key === ' ') {
// 这些键单独按下时不作为快捷键,等待组合键
return;
}
// 处理修饰键
const modifiers = [];
if (e.ctrlKey) modifiers.push('ctrl');
if (e.shiftKey) modifiers.push('shift');
if (e.altKey) modifiers.push('alt');
if (e.metaKey) modifiers.push('meta');
// 构建快捷键字符串
if (modifiers.length > 0) {
// 组合键:修饰键 + 普通键
key = modifiers.join('+') + '+' + key;
} else if (key.length === 1) {
// 单个字母或数字键
key = key;
} else {
// 功能键(如F1-F12)
key = key;
}
// 完成设置
this.finishKeybindSetting(key);
};
// 添加事件监听器(不使用once:true,持续监听直到完成或取消)
document.addEventListener('keydown', tempKeyHandler);
// 保存临时处理器以便取消
this.keybind.tempHandler = tempKeyHandler;
},
finishKeybindSetting(key) {
// 完成快捷键设置
if (!this.keybind.setting || !this.keybind.targetModule) return;
const moduleName = this.keybind.targetModule;
const element = this.keybind.targetElement;
// 移除临时事件监听器
if (this.keybind.tempHandler) {
document.removeEventListener('keydown', this.keybind.tempHandler);
}
// 设置快捷键
this.setKeybind(moduleName, key);
// 更新UI
if (element) {
element.classList.remove('setting');
element.textContent = key === 'none' ? 'none' : key;
}
// 重置状态
this.keybind.setting = false;
this.keybind.targetModule = null;
this.keybind.targetElement = null;
this.keybind.tempHandler = null;
this.showToast(`Keybind for "${moduleName}" set to "${key}"`);
},
cancelKeybindSetting() {
// 取消快捷键设置
if (!this.keybind.setting) return;
const element = this.keybind.targetElement;
const moduleName = this.keybind.targetModule;
// 恢复原来的显示
if (element && moduleName) {