-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject.js
More file actions
154 lines (131 loc) · 5.14 KB
/
Copy pathinject.js
File metadata and controls
154 lines (131 loc) · 5.14 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
/**
* OpenFront Hardware Macro Payload
*
* Executes entirely within the target page's context.
* Manages stateful keystroke tracking and dispatches high-frequency
* synthetic events to emulate realistic user interactions.
*/
(function() {
const pressedKeys = new Set();
let loopActive = false;
let targetX = 0;
let targetY = 0;
let buildInterval = null;
// State registry for the currently active building hotkey
let activeKey = '1';
let activeCode = 'Digit1';
let activeKeyCode = 49;
// Movement threshold (in pixels) to trigger sequence abortion
const MOUSE_MOVE_THRESHOLD = 50;
// Execution polling rate. Defines the ms delay between synthetic macro steps.
// Optimal stability at 75ms (approx. 13 operations per second).
const BUILD_SPEED = 75;
/**
* Hardware input listeners (Capture Phase)
*/
window.addEventListener('keydown', (e) => {
// Filter out synthetic events dispatched by this payload to prevent recursive feedback loops
if (!e.isTrusted) return;
pressedKeys.add(e.code);
}, true);
window.addEventListener('keyup', (e) => {
if (!e.isTrusted) return;
pressedKeys.delete(e.code);
// Terminate the sequence if primary modifier or the active building digit is released
if (e.code === 'KeyZ' || e.code === activeCode) {
stopLoop();
}
}, true);
// Purge hardware state registry on context loss to prevent phantom input locks
window.addEventListener('blur', () => {
pressedKeys.clear();
stopLoop();
});
/**
* Macro Sequence Initialization
*/
window.addEventListener('mousedown', (e) => {
// Validate composite trigger: Primary Modifier (Z) + Mouse 0
if (pressedKeys.has('KeyZ') && e.button === 0 && !loopActive) {
// Scan state registry for the secondary modifier (Digits 1-9) dictating the target entity index
let foundDigit = null;
for (let i = 1; i <= 9; i++) {
if (pressedKeys.has(`Digit${i}`)) {
foundDigit = i;
break;
}
}
// Resolve operational parameters and allocate sequence
if (foundDigit !== null) {
activeKey = foundDigit.toString();
activeCode = `Digit${foundDigit}`;
activeKeyCode = 48 + foundDigit; // Map to ASCII baseline (48 = '0')
loopActive = true;
targetX = e.clientX;
targetY = e.clientY;
startLoop();
}
}
}, true);
/**
* Positional Variance Monitor
*/
window.addEventListener('mousemove', (e) => {
if (loopActive) {
// Calculate euclidean distance delta
const dist = Math.sqrt(Math.pow(e.clientX - targetX, 2) + Math.pow(e.clientY - targetY, 2));
if (dist > MOUSE_MOVE_THRESHOLD) {
stopLoop();
}
}
}, true);
/**
* Execution Controller
*/
function startLoop() {
if (buildInterval) clearInterval(buildInterval);
executeStep(); // Dispatch immediate first frame
buildInterval = setInterval(() => {
if (!loopActive) {
stopLoop();
return;
}
executeStep();
}, BUILD_SPEED);
}
function stopLoop() {
loopActive = false;
if (buildInterval) {
clearInterval(buildInterval);
buildInterval = null;
}
}
/**
* Synthetic Event Dispatcher
*/
function executeStep() {
// 1. Dispatch synthetic keystroke sequence targeting the engine's global input handler
const keyEventDown = new KeyboardEvent('keydown', {
bubbles: true, cancelable: true,
key: activeKey, code: activeCode, keyCode: activeKeyCode, which: activeKeyCode
});
document.dispatchEvent(keyEventDown);
const keyEventUp = new KeyboardEvent('keyup', {
bubbles: true, cancelable: true,
key: activeKey, code: activeCode, keyCode: activeKeyCode, which: activeKeyCode
});
document.dispatchEvent(keyEventUp);
// 2. Resolve the underlying DOM node (typically the primary canvas)
const targetElement = document.elementFromPoint(targetX, targetY) || document.body;
// 3. Dispatch a full synthetic pointer lifecycle
const mouseEvents = ['pointerdown', 'mousedown', 'pointerup', 'mouseup', 'click'];
mouseEvents.forEach(eventType => {
const mouseEvent = new MouseEvent(eventType, {
bubbles: true, cancelable: true, view: window,
clientX: targetX, clientY: targetY,
button: 0, buttons: eventType.includes('down') || eventType === 'click' ? 1 : 0
});
targetElement.dispatchEvent(mouseEvent);
});
}
})();