@xx_amaba_xx/robloxbot 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/bot.js +56 -6
- package/src/constants/packets.js +365 -31
- package/src/core/chat.js +53 -27
- package/src/core/movement.js +79 -60
- package/src/plugins/settings.js +4 -4
- package/src/transport/base.js +2 -0
- package/src/transport/raknet.js +631 -77
- package/src/transport/web.js +1 -1
- package/src/vision/index.js +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xx_amaba_xx/robloxbot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "A mineflayer-style headless Roblox bot library for Node.js/Termux",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
],
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
|
-
"url": "https://github.com/pal3241/Royer.git"
|
|
37
|
+
"url": "git+https://github.com/pal3241/Royer.git"
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://github.com/pal3241/Royer#readme",
|
|
40
40
|
"bugs": {
|
package/src/bot.js
CHANGED
|
@@ -42,12 +42,8 @@ export class RobloxBot extends RobloxEventEmitter {
|
|
|
42
42
|
|
|
43
43
|
await this.client.connect();
|
|
44
44
|
|
|
45
|
-
this.movement = new Movement(this.client.transport, this.character
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
this.chat = new Chat(this.client.transport, this, {
|
|
49
|
-
simulationMode: this.options.simulationMode,
|
|
50
|
-
});
|
|
45
|
+
this.movement = new Movement(this.client.transport, this.character);
|
|
46
|
+
this.chat = new Chat(this.client.transport, this);
|
|
51
47
|
this.game = new GameJoin(this.client.transport);
|
|
52
48
|
|
|
53
49
|
// Auto-create vision service and wire map fetch to the transport.
|
|
@@ -80,6 +76,12 @@ export class RobloxBot extends RobloxEventEmitter {
|
|
|
80
76
|
}
|
|
81
77
|
|
|
82
78
|
_handlePacket(packet) {
|
|
79
|
+
// Handle new packet format from RakNet transport: { opcode, opcodeName, fields }
|
|
80
|
+
if (packet.opcode !== undefined && packet.fields) {
|
|
81
|
+
this._handleRakNetPacket(packet);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Legacy format (for web transport or backwards compat)
|
|
83
85
|
switch (packet.type) {
|
|
84
86
|
case "spawn":
|
|
85
87
|
this.character.update({ ...packet.data, spawned: true, alive: true });
|
|
@@ -102,6 +104,54 @@ export class RobloxBot extends RobloxEventEmitter {
|
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
|
|
107
|
+
_handleRakNetPacket(packet) {
|
|
108
|
+
const { opcodeName, fields } = packet;
|
|
109
|
+
switch (opcodeName) {
|
|
110
|
+
case "ROBLOX_CHARACTER_SPAWN":
|
|
111
|
+
this.character.update({
|
|
112
|
+
userId: fields.userId,
|
|
113
|
+
username: fields.username,
|
|
114
|
+
position: fields.position,
|
|
115
|
+
health: fields.health,
|
|
116
|
+
maxHealth: fields.maxHealth,
|
|
117
|
+
spawned: true,
|
|
118
|
+
alive: true,
|
|
119
|
+
});
|
|
120
|
+
this.emit("spawn", this.character);
|
|
121
|
+
break;
|
|
122
|
+
case "ROBLOX_CHAT_MESSAGE":
|
|
123
|
+
this.emit("chat", {
|
|
124
|
+
player: fields.username,
|
|
125
|
+
message: fields.message,
|
|
126
|
+
});
|
|
127
|
+
break;
|
|
128
|
+
case "ROBLOX_PLAYER_JOIN":
|
|
129
|
+
this.emit("playerJoin", {
|
|
130
|
+
userId: fields.userId,
|
|
131
|
+
username: fields.username,
|
|
132
|
+
displayName: fields.displayName,
|
|
133
|
+
});
|
|
134
|
+
break;
|
|
135
|
+
case "ROBLOX_PLAYER_LEAVE":
|
|
136
|
+
this.emit("playerLeave", {
|
|
137
|
+
userId: fields.userId,
|
|
138
|
+
reason: fields.reason,
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
case "ROBLOX_MOVEMENT_UPDATE":
|
|
142
|
+
// Update character position if it's our own character
|
|
143
|
+
if (fields.userId === this.character.userId) {
|
|
144
|
+
this.character.position = fields.position;
|
|
145
|
+
}
|
|
146
|
+
this.emit("movement", fields);
|
|
147
|
+
break;
|
|
148
|
+
default:
|
|
149
|
+
// Emit raw packet for plugins to handle
|
|
150
|
+
this.emit("packet:raw", packet);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
105
155
|
async stop() {
|
|
106
156
|
if (this.client) {
|
|
107
157
|
await this.client.disconnect();
|
package/src/constants/packets.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* RakNet / Roblox packet opcode and structure definitions.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* reverse-engineer the real protocol.
|
|
4
|
+
* Based on community reverse-engineering of Roblox protocol.
|
|
5
|
+
* OpCodes 0x80-0xFF are Roblox game packets.
|
|
6
|
+
* These structures are educated guesses — validate against real captures.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* "i32", "f32", "f64", "string", "bytes", "bool".
|
|
8
|
+
* Reference: Roblox protocol uses a custom bitstream format on top of RakNet.
|
|
9
|
+
* Each packet starts with a 1-byte opcode, followed by serialized data.
|
|
12
10
|
*/
|
|
13
11
|
|
|
14
12
|
export const PACKET_OPCODES = {
|
|
@@ -18,14 +16,66 @@ export const PACKET_OPCODES = {
|
|
|
18
16
|
ID_NEW_INCOMING_CONNECTION: 0x03,
|
|
19
17
|
ID_DISCONNECTION_NOTIFICATION: 0x15,
|
|
20
18
|
ID_CONNECTION_LOST: 0x16,
|
|
19
|
+
ID_CONNECTED_PING: 0x03,
|
|
20
|
+
ID_CONNECTED_PONG: 0x00,
|
|
21
|
+
ID_UNCONNECTED_PING: 0x01,
|
|
22
|
+
ID_UNCONNECTED_PONG: 0x1C,
|
|
21
23
|
|
|
22
24
|
// ── Roblox game packets (0x80–0xFF) ──────────────────────────────
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
// Connection / Replication
|
|
26
|
+
ROBLOX_CLIENT_REPLICATE: 0x80, // Client → Server: replication data
|
|
27
|
+
ROBLOX_SERVER_REPLICATE: 0x81, // Server → Client: replication data
|
|
28
|
+
ROBLOX_PROPERTY_CHANGE: 0x82, // Property change replication
|
|
29
|
+
ROBLOX_INSTANCE_CREATE: 0x83, // New instance created
|
|
30
|
+
ROBLOX_INSTANCE_DESTROY: 0x84, // Instance destroyed
|
|
31
|
+
ROBLOX_INSTANCE_PARENT: 0x85, // Parent changed
|
|
32
|
+
|
|
33
|
+
// Character / Physics
|
|
34
|
+
ROBLOX_CHARACTER_SPAWN: 0x86, // Character spawned
|
|
35
|
+
ROBLOX_CHARACTER_DESPAWN: 0x87, // Character despawned
|
|
36
|
+
ROBLOX_MOVEMENT_UPDATE: 0x88, // Position/velocity update
|
|
37
|
+
ROBLOX_ANIMATION_PLAY: 0x89, // Animation started
|
|
38
|
+
ROBLOX_ANIMATION_STOP: 0x8A, // Animation stopped
|
|
39
|
+
ROBLOX_TOOL_EQUIP: 0x8B, // Tool equipped
|
|
40
|
+
ROBLOX_TOOL_UNEQUIP: 0x8C, // Tool unequipped
|
|
41
|
+
ROBLOX_TOOL_ACTIVATE: 0x8D, // Tool activated
|
|
42
|
+
ROBLOX_TOOL_DEACTIVATE: 0x8E, // Tool deactivated
|
|
43
|
+
|
|
44
|
+
// Chat / Social
|
|
45
|
+
ROBLOX_CHAT_MESSAGE: 0x90, // Chat message
|
|
46
|
+
ROBLOX_CHAT_HISTORY: 0x91, // Chat history request/response
|
|
47
|
+
ROBLOX_PLAYER_JOIN: 0x92, // Player joined
|
|
48
|
+
ROBLOX_PLAYER_LEAVE: 0x93, // Player left
|
|
49
|
+
ROBLOX_FRIEND_REQUEST: 0x94, // Friend request
|
|
50
|
+
ROBLOX_FRIEND_ACCEPT: 0x95, // Friend accepted
|
|
51
|
+
ROBLOX_BLOCK_PLAYER: 0x96, // Player blocked
|
|
52
|
+
|
|
53
|
+
// Game / Place
|
|
54
|
+
ROBLOX_PLACE_INFO: 0xA0, // Place info (name, description, etc.)
|
|
55
|
+
ROBLOX_TELEPORT_REQUEST: 0xA1, // Teleport to place
|
|
56
|
+
ROBLOX_TELEPORT_FAILED: 0xA2, // Teleport failed
|
|
57
|
+
ROBLOX_SERVER_INFO: 0xA3, // Server info (jobId, player count, etc.)
|
|
58
|
+
|
|
59
|
+
// UI / Input
|
|
60
|
+
ROBLOX_KEY_PRESS: 0xB0, // Key pressed
|
|
61
|
+
ROBLOX_KEY_RELEASE: 0xB1, // Key released
|
|
62
|
+
ROBLOX_MOUSE_MOVE: 0xB2, // Mouse moved
|
|
63
|
+
ROBLOX_MOUSE_CLICK: 0xB3, // Mouse clicked
|
|
64
|
+
ROBLOX_UI_INTERACTION: 0xB4, // UI button clicked, etc.
|
|
65
|
+
|
|
66
|
+
// Physics / Assembly
|
|
67
|
+
ROBLOX_ASSEMBLY_MOVE: 0xC0, // Assembly (character, vehicle) moved
|
|
68
|
+
ROBLOX_ASSEMBLY_ROTATE: 0xC1, // Assembly rotated
|
|
69
|
+
ROBLOX_JOINT_CREATE: 0xC2, // Joint created (weld, motor, etc.)
|
|
70
|
+
ROBLOX_JOINT_DESTROY: 0xC3, // Joint destroyed
|
|
71
|
+
|
|
72
|
+
// Voice / Audio
|
|
73
|
+
ROBLOX_VOICE_DATA: 0xD0, // Voice chat data
|
|
74
|
+
ROBLOX_VOICE_STATE: 0xD1, // Voice state (muted, etc.)
|
|
75
|
+
|
|
76
|
+
// Custom / Vision
|
|
77
|
+
ROBLOX_VISION_DETECT: 0xE0, // Vision detection result
|
|
78
|
+
ROBLOX_CUSTOM_EVENT: 0xFF, // Custom game event
|
|
29
79
|
};
|
|
30
80
|
|
|
31
81
|
// Map opcode number → name for logging/debugging.
|
|
@@ -36,42 +86,228 @@ export const PACKET_NAMES = Object.fromEntries(
|
|
|
36
86
|
/**
|
|
37
87
|
* Packet structure descriptors. Each field is { name, type }.
|
|
38
88
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
89
|
+
* Types: "u8", "u16", "u32", "u64", "i32", "f32", "f64", "bool", "string", "bytes", "vector3", "cframe", "color3", "udim2"
|
|
90
|
+
* Compound types (vector3, cframe, etc.) are serialized as their component primitives.
|
|
91
|
+
*
|
|
92
|
+
* NOTE: These are BEST GUESSES. Roblox uses a custom bitstream with variable-length integers,
|
|
93
|
+
* optional fields, and compression. Update as you capture real traffic.
|
|
42
94
|
*/
|
|
43
95
|
export const PACKET_FIELDS = {
|
|
96
|
+
// ── Connection / Replication ─────────────────────────────────────
|
|
97
|
+
[PACKET_OPCODES.ROBLOX_CLIENT_REPLICATE]: [
|
|
98
|
+
{ name: "replicatorId", type: "u32" },
|
|
99
|
+
{ name: "entries", type: "bytes" }, // Serialized replication entries
|
|
100
|
+
],
|
|
101
|
+
[PACKET_OPCODES.ROBLOX_SERVER_REPLICATE]: [
|
|
102
|
+
{ name: "replicatorId", type: "u32" },
|
|
103
|
+
{ name: "entries", type: "bytes" },
|
|
104
|
+
],
|
|
105
|
+
[PACKET_OPCODES.ROBLOX_PROPERTY_CHANGE]: [
|
|
106
|
+
{ name: "instanceId", type: "u32" },
|
|
107
|
+
{ name: "propertyName", type: "string" },
|
|
108
|
+
{ name: "valueType", type: "u8" }, // Roblox type enum
|
|
109
|
+
{ name: "valueData", type: "bytes" },
|
|
110
|
+
],
|
|
111
|
+
[PACKET_OPCODES.ROBLOX_INSTANCE_CREATE]: [
|
|
112
|
+
{ name: "instanceId", type: "u32" },
|
|
113
|
+
{ name: "className", type: "string" },
|
|
114
|
+
{ name: "parentId", type: "u32" },
|
|
115
|
+
{ name: "properties", type: "bytes" }, // Serialized properties
|
|
116
|
+
],
|
|
117
|
+
[PACKET_OPCODES.ROBLOX_INSTANCE_DESTROY]: [
|
|
118
|
+
{ name: "instanceId", type: "u32" },
|
|
119
|
+
],
|
|
120
|
+
[PACKET_OPCODES.ROBLOX_INSTANCE_PARENT]: [
|
|
121
|
+
{ name: "instanceId", type: "u32" },
|
|
122
|
+
{ name: "newParentId", type: "u32" },
|
|
123
|
+
],
|
|
124
|
+
|
|
125
|
+
// ── Character / Physics ──────────────────────────────────────────
|
|
126
|
+
[PACKET_OPCODES.ROBLOX_CHARACTER_SPAWN]: [
|
|
127
|
+
{ name: "userId", type: "u32" },
|
|
128
|
+
{ name: "characterId", type: "u32" },
|
|
129
|
+
{ name: "position", type: "vector3" }, // x, y, z as f32 each
|
|
130
|
+
{ name: "health", type: "f32" },
|
|
131
|
+
{ name: "maxHealth", type: "f32" },
|
|
132
|
+
{ name: "walkSpeed", type: "f32" },
|
|
133
|
+
{ name: "jumpPower", type: "f32" },
|
|
134
|
+
],
|
|
135
|
+
[PACKET_OPCODES.ROBLOX_CHARACTER_DESPAWN]: [
|
|
136
|
+
{ name: "userId", type: "u32" },
|
|
137
|
+
{ name: "characterId", type: "u32" },
|
|
138
|
+
],
|
|
139
|
+
[PACKET_OPCODES.ROBLOX_MOVEMENT_UPDATE]: [
|
|
140
|
+
{ name: "userId", type: "u32" },
|
|
141
|
+
{ name: "characterId", type: "u32" },
|
|
142
|
+
{ name: "position", type: "vector3" },
|
|
143
|
+
{ name: "velocity", type: "vector3" },
|
|
144
|
+
{ name: "cframe", type: "cframe" }, // Full CFrame (position + rotation)
|
|
145
|
+
{ name: "moveDirection", type: "vector3" },
|
|
146
|
+
{ name: "isGrounded", type: "bool" },
|
|
147
|
+
{ name: "isJumping", type: "bool" },
|
|
148
|
+
{ name: "walkSpeed", type: "f32" },
|
|
149
|
+
],
|
|
150
|
+
[PACKET_OPCODES.ROBLOX_ANIMATION_PLAY]: [
|
|
151
|
+
{ name: "userId", type: "u32" },
|
|
152
|
+
{ name: "animationId", type: "u64" }, // Roblox asset ID
|
|
153
|
+
{ name: "priority", type: "u8" },
|
|
154
|
+
{ name: "speed", type: "f32" },
|
|
155
|
+
{ name: "looped", type: "bool" },
|
|
156
|
+
{ name: "timePosition", type: "f32" },
|
|
157
|
+
],
|
|
158
|
+
[PACKET_OPCODES.ROBLOX_ANIMATION_STOP]: [
|
|
159
|
+
{ name: "userId", type: "u32" },
|
|
160
|
+
{ name: "animationId", type: "u64" },
|
|
161
|
+
],
|
|
162
|
+
[PACKET_OPCODES.ROBLOX_TOOL_EQUIP]: [
|
|
163
|
+
{ name: "userId", type: "u32" },
|
|
164
|
+
{ name: "toolId", type: "u32" },
|
|
165
|
+
{ name: "toolName", type: "string" },
|
|
166
|
+
],
|
|
167
|
+
[PACKET_OPCODES.ROBLOX_TOOL_UNEQUIP]: [
|
|
168
|
+
{ name: "userId", type: "u32" },
|
|
169
|
+
{ name: "toolId", type: "u32" },
|
|
170
|
+
],
|
|
171
|
+
[PACKET_OPCODES.ROBLOX_TOOL_ACTIVATE]: [
|
|
172
|
+
{ name: "userId", type: "u32" },
|
|
173
|
+
{ name: "toolId", type: "u32" },
|
|
174
|
+
{ name: "mousePosition", type: "vector3" }, // World position
|
|
175
|
+
],
|
|
176
|
+
[PACKET_OPCODES.ROBLOX_TOOL_DEACTIVATE]: [
|
|
177
|
+
{ name: "userId", type: "u32" },
|
|
178
|
+
{ name: "toolId", type: "u32" },
|
|
179
|
+
],
|
|
180
|
+
|
|
181
|
+
// ── Chat / Social ────────────────────────────────────────────────
|
|
182
|
+
[PACKET_OPCODES.ROBLOX_CHAT_MESSAGE]: [
|
|
183
|
+
{ name: "userId", type: "u32" },
|
|
184
|
+
{ name: "username", type: "string" },
|
|
185
|
+
{ name: "message", type: "string" },
|
|
186
|
+
{ name: "channel", type: "u8" }, // 0=All, 1=Team, 2=Whisper, etc.
|
|
187
|
+
{ name: "targetUserId", type: "u32" }, // For whispers
|
|
188
|
+
{ name: "timestamp", type: "u64" }, // Unix ms
|
|
189
|
+
],
|
|
190
|
+
[PACKET_OPCODES.ROBLOX_CHAT_HISTORY]: [
|
|
191
|
+
{ name: "requestId", type: "u32" },
|
|
192
|
+
{ name: "messages", type: "bytes" }, // Array of chat messages
|
|
193
|
+
],
|
|
44
194
|
[PACKET_OPCODES.ROBLOX_PLAYER_JOIN]: [
|
|
45
195
|
{ name: "userId", type: "u32" },
|
|
46
196
|
{ name: "username", type: "string" },
|
|
197
|
+
{ name: "displayName", type: "string" },
|
|
47
198
|
{ name: "placeId", type: "u32" },
|
|
199
|
+
{ name: "accountAge", type: "u32" },
|
|
200
|
+
{ name: "isFriend", type: "bool" },
|
|
48
201
|
],
|
|
49
202
|
[PACKET_OPCODES.ROBLOX_PLAYER_LEAVE]: [
|
|
50
203
|
{ name: "userId", type: "u32" },
|
|
51
|
-
{ name: "reason", type: "u8" },
|
|
204
|
+
{ name: "reason", type: "u8" }, // 0=Left, 1=Kicked, 2=Banned, 3=Disconnected
|
|
52
205
|
],
|
|
53
|
-
[PACKET_OPCODES.
|
|
206
|
+
[PACKET_OPCODES.ROBLOX_FRIEND_REQUEST]: [
|
|
207
|
+
{ name: "fromUserId", type: "u32" },
|
|
208
|
+
{ name: "fromUsername", type: "string" },
|
|
209
|
+
{ name: "toUserId", type: "u32" },
|
|
210
|
+
],
|
|
211
|
+
[PACKET_OPCODES.ROBLOX_FRIEND_ACCEPT]: [
|
|
54
212
|
{ name: "userId", type: "u32" },
|
|
213
|
+
{ name: "friendUserId", type: "u32" },
|
|
214
|
+
],
|
|
215
|
+
[PACKET_OPCODES.ROBLOX_BLOCK_PLAYER]: [
|
|
216
|
+
{ name: "userId", type: "u32" },
|
|
217
|
+
{ name: "targetUserId", type: "u32" },
|
|
218
|
+
{ name: "blocked", type: "bool" },
|
|
219
|
+
],
|
|
220
|
+
|
|
221
|
+
// ── Game / Place ─────────────────────────────────────────────────
|
|
222
|
+
[PACKET_OPCODES.ROBLOX_PLACE_INFO]: [
|
|
223
|
+
{ name: "placeId", type: "u32" },
|
|
224
|
+
{ name: "name", type: "string" },
|
|
225
|
+
{ name: "description", type: "string" },
|
|
226
|
+
{ name: "creatorId", type: "u32" },
|
|
227
|
+
{ name: "creatorType", type: "u8" }, // 0=User, 1=Group
|
|
228
|
+
{ name: "maxPlayers", type: "u32" },
|
|
229
|
+
{ name: "universeId", type: "u32" },
|
|
230
|
+
],
|
|
231
|
+
[PACKET_OPCODES.ROBLOX_TELEPORT_REQUEST]: [
|
|
232
|
+
{ name: "placeId", type: "u32" },
|
|
233
|
+
{ name: "jobId", type: "string" }, // Specific server, or empty for any
|
|
234
|
+
{ name: "teleportData", type: "bytes" }, // Custom teleport data
|
|
235
|
+
],
|
|
236
|
+
[PACKET_OPCODES.ROBLOX_TELEPORT_FAILED]: [
|
|
237
|
+
{ name: "errorCode", type: "u32" },
|
|
238
|
+
{ name: "errorMessage", type: "string" },
|
|
239
|
+
],
|
|
240
|
+
[PACKET_OPCODES.ROBLOX_SERVER_INFO]: [
|
|
241
|
+
{ name: "jobId", type: "string" },
|
|
242
|
+
{ name: "playerCount", type: "u32" },
|
|
243
|
+
{ name: "maxPlayers", type: "u32" },
|
|
244
|
+
{ name: "ping", type: "u32" },
|
|
245
|
+
{ name: "region", type: "string" },
|
|
246
|
+
],
|
|
247
|
+
|
|
248
|
+
// ── UI / Input ───────────────────────────────────────────────────
|
|
249
|
+
[PACKET_OPCODES.ROBLOX_KEY_PRESS]: [
|
|
250
|
+
{ name: "keyCode", type: "u32" }, // Roblox KeyCode enum
|
|
251
|
+
{ name: "isRepeat", type: "bool" },
|
|
252
|
+
],
|
|
253
|
+
[PACKET_OPCODES.ROBLOX_KEY_RELEASE]: [
|
|
254
|
+
{ name: "keyCode", type: "u32" },
|
|
255
|
+
],
|
|
256
|
+
[PACKET_OPCODES.ROBLOX_MOUSE_MOVE]: [
|
|
55
257
|
{ name: "x", type: "f32" },
|
|
56
258
|
{ name: "y", type: "f32" },
|
|
57
|
-
{ name: "
|
|
58
|
-
{ name: "
|
|
259
|
+
{ name: "deltaX", type: "f32" },
|
|
260
|
+
{ name: "deltaY", type: "f32" },
|
|
59
261
|
],
|
|
60
|
-
[PACKET_OPCODES.
|
|
262
|
+
[PACKET_OPCODES.ROBLOX_MOUSE_CLICK]: [
|
|
263
|
+
{ name: "button", type: "u8" }, // 0=Left, 1=Right, 2=Middle
|
|
264
|
+
{ name: "x", type: "f32" },
|
|
265
|
+
{ name: "y", type: "f32" },
|
|
266
|
+
{ name: "isDown", type: "bool" },
|
|
267
|
+
],
|
|
268
|
+
[PACKET_OPCODES.ROBLOX_UI_INTERACTION]: [
|
|
269
|
+
{ name: "elementId", type: "u32" },
|
|
270
|
+
{ name: "action", type: "string" }, // "click", "hover", "input", etc.
|
|
271
|
+
{ name: "data", type: "bytes" },
|
|
272
|
+
],
|
|
273
|
+
|
|
274
|
+
// ── Physics / Assembly ───────────────────────────────────────────
|
|
275
|
+
[PACKET_OPCODES.ROBLOX_ASSEMBLY_MOVE]: [
|
|
276
|
+
{ name: "assemblyId", type: "u32" },
|
|
277
|
+
{ name: "position", type: "vector3" },
|
|
278
|
+
{ name: "velocity", type: "vector3" },
|
|
279
|
+
],
|
|
280
|
+
[PACKET_OPCODES.ROBLOX_ASSEMBLY_ROTATE]: [
|
|
281
|
+
{ name: "assemblyId", type: "u32" },
|
|
282
|
+
{ name: "cframe", type: "cframe" },
|
|
283
|
+
{ name: "angularVelocity", type: "vector3" },
|
|
284
|
+
],
|
|
285
|
+
[PACKET_OPCODES.ROBLOX_JOINT_CREATE]: [
|
|
286
|
+
{ name: "jointId", type: "u32" },
|
|
287
|
+
{ name: "jointType", type: "u8" }, // Weld, Motor, Hinge, etc.
|
|
288
|
+
{ name: "part0Id", type: "u32" },
|
|
289
|
+
{ name: "part1Id", type: "u32" },
|
|
290
|
+
{ name: "c0", type: "cframe" },
|
|
291
|
+
{ name: "c1", type: "cframe" },
|
|
292
|
+
],
|
|
293
|
+
[PACKET_OPCODES.ROBLOX_JOINT_DESTROY]: [
|
|
294
|
+
{ name: "jointId", type: "u32" },
|
|
295
|
+
],
|
|
296
|
+
|
|
297
|
+
// ── Voice / Audio ────────────────────────────────────────────────
|
|
298
|
+
[PACKET_OPCODES.ROBLOX_VOICE_DATA]: [
|
|
61
299
|
{ name: "userId", type: "u32" },
|
|
62
|
-
{ name: "
|
|
63
|
-
{ name: "
|
|
64
|
-
{ name: "
|
|
300
|
+
{ name: "audioData", type: "bytes" }, // Opus encoded
|
|
301
|
+
{ name: "sequence", type: "u16" },
|
|
302
|
+
{ name: "timestamp", type: "u64" },
|
|
65
303
|
],
|
|
66
|
-
[PACKET_OPCODES.
|
|
304
|
+
[PACKET_OPCODES.ROBLOX_VOICE_STATE]: [
|
|
67
305
|
{ name: "userId", type: "u32" },
|
|
68
|
-
{ name: "
|
|
69
|
-
{ name: "
|
|
70
|
-
{ name: "z", type: "f32" },
|
|
71
|
-
{ name: "velocityX", type: "f32" },
|
|
72
|
-
{ name: "velocityY", type: "f32" },
|
|
73
|
-
{ name: "velocityZ", type: "f32" },
|
|
306
|
+
{ name: "muted", type: "bool" },
|
|
307
|
+
{ name: "volume", type: "f32" },
|
|
74
308
|
],
|
|
309
|
+
|
|
310
|
+
// ── Vision / Custom ──────────────────────────────────────────────
|
|
75
311
|
[PACKET_OPCODES.ROBLOX_VISION_DETECT]: [
|
|
76
312
|
{ name: "label", type: "string" },
|
|
77
313
|
{ name: "confidence", type: "f32" },
|
|
@@ -79,6 +315,12 @@ export const PACKET_FIELDS = {
|
|
|
79
315
|
{ name: "boxY", type: "f32" },
|
|
80
316
|
{ name: "boxW", type: "f32" },
|
|
81
317
|
{ name: "boxH", type: "f32" },
|
|
318
|
+
{ name: "imageWidth", type: "u16" },
|
|
319
|
+
{ name: "imageHeight", type: "u16" },
|
|
320
|
+
],
|
|
321
|
+
[PACKET_OPCODES.ROBLOX_CUSTOM_EVENT]: [
|
|
322
|
+
{ name: "eventName", type: "string" },
|
|
323
|
+
{ name: "eventData", type: "bytes" },
|
|
82
324
|
],
|
|
83
325
|
};
|
|
84
326
|
|
|
@@ -92,6 +334,11 @@ export const TYPE_SIZES = {
|
|
|
92
334
|
f32: 4,
|
|
93
335
|
f64: 8,
|
|
94
336
|
bool: 1,
|
|
337
|
+
// Compound types (serialized as components)
|
|
338
|
+
vector3: 12, // 3 * f32
|
|
339
|
+
cframe: 48, // 12 * f32 (4x4 matrix, or pos+rot)
|
|
340
|
+
color3: 12, // 3 * f32
|
|
341
|
+
udim2: 16, // 4 * f32 (xScale, xOffset, yScale, yOffset)
|
|
95
342
|
};
|
|
96
343
|
|
|
97
344
|
/**
|
|
@@ -108,3 +355,90 @@ export function getPacketFields(opcode) {
|
|
|
108
355
|
export function isPacketDefined(opcode) {
|
|
109
356
|
return !!PACKET_FIELDS[opcode];
|
|
110
357
|
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Encode compound types (vector3, cframe, etc.) to bytes.
|
|
361
|
+
* Used by encodePacket in raknet.js.
|
|
362
|
+
*/
|
|
363
|
+
export function encodeCompound(type, value, view, offset) {
|
|
364
|
+
switch (type) {
|
|
365
|
+
case "vector3":
|
|
366
|
+
view.setFloat32(offset, value.x, true);
|
|
367
|
+
view.setFloat32(offset + 4, value.y, true);
|
|
368
|
+
view.setFloat32(offset + 8, value.z, true);
|
|
369
|
+
return 12;
|
|
370
|
+
case "cframe":
|
|
371
|
+
// Assume value is { position: {x,y,z}, rotation: {x,y,z,w} } or 4x4 matrix
|
|
372
|
+
if (value.position) {
|
|
373
|
+
view.setFloat32(offset, value.position.x, true);
|
|
374
|
+
view.setFloat32(offset + 4, value.position.y, true);
|
|
375
|
+
view.setFloat32(offset + 8, value.position.z, true);
|
|
376
|
+
// Rotation as quaternion (x,y,z,w)
|
|
377
|
+
if (value.rotation) {
|
|
378
|
+
view.setFloat32(offset + 12, value.rotation.x, true);
|
|
379
|
+
view.setFloat32(offset + 16, value.rotation.y, true);
|
|
380
|
+
view.setFloat32(offset + 20, value.rotation.z, true);
|
|
381
|
+
view.setFloat32(offset + 24, value.rotation.w, true);
|
|
382
|
+
}
|
|
383
|
+
// Fill rest with identity
|
|
384
|
+
for (let i = 28; i < 48; i += 4) view.setFloat32(offset + i, i === 28 || i === 40 ? 1 : 0, true);
|
|
385
|
+
}
|
|
386
|
+
return 48;
|
|
387
|
+
case "color3":
|
|
388
|
+
view.setFloat32(offset, value.r, true);
|
|
389
|
+
view.setFloat32(offset + 4, value.g, true);
|
|
390
|
+
view.setFloat32(offset + 8, value.b, true);
|
|
391
|
+
return 12;
|
|
392
|
+
case "udim2":
|
|
393
|
+
view.setFloat32(offset, value.xScale, true);
|
|
394
|
+
view.setFloat32(offset + 4, value.xOffset, true);
|
|
395
|
+
view.setFloat32(offset + 8, value.yScale, true);
|
|
396
|
+
view.setFloat32(offset + 12, value.yOffset, true);
|
|
397
|
+
return 16;
|
|
398
|
+
default:
|
|
399
|
+
throw new Error(`Unknown compound type: ${type}`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Decode compound types from bytes.
|
|
405
|
+
*/
|
|
406
|
+
export function decodeCompound(type, view, offset) {
|
|
407
|
+
switch (type) {
|
|
408
|
+
case "vector3":
|
|
409
|
+
return {
|
|
410
|
+
x: view.getFloat32(offset, true),
|
|
411
|
+
y: view.getFloat32(offset + 4, true),
|
|
412
|
+
z: view.getFloat32(offset + 8, true),
|
|
413
|
+
};
|
|
414
|
+
case "cframe":
|
|
415
|
+
return {
|
|
416
|
+
position: {
|
|
417
|
+
x: view.getFloat32(offset, true),
|
|
418
|
+
y: view.getFloat32(offset + 4, true),
|
|
419
|
+
z: view.getFloat32(offset + 8, true),
|
|
420
|
+
},
|
|
421
|
+
rotation: {
|
|
422
|
+
x: view.getFloat32(offset + 12, true),
|
|
423
|
+
y: view.getFloat32(offset + 16, true),
|
|
424
|
+
z: view.getFloat32(offset + 20, true),
|
|
425
|
+
w: view.getFloat32(offset + 24, true),
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
case "color3":
|
|
429
|
+
return {
|
|
430
|
+
r: view.getFloat32(offset, true),
|
|
431
|
+
g: view.getFloat32(offset + 4, true),
|
|
432
|
+
b: view.getFloat32(offset + 8, true),
|
|
433
|
+
};
|
|
434
|
+
case "udim2":
|
|
435
|
+
return {
|
|
436
|
+
xScale: view.getFloat32(offset, true),
|
|
437
|
+
xOffset: view.getFloat32(offset + 4, true),
|
|
438
|
+
yScale: view.getFloat32(offset + 8, true),
|
|
439
|
+
yOffset: view.getFloat32(offset + 12, true),
|
|
440
|
+
};
|
|
441
|
+
default:
|
|
442
|
+
throw new Error(`Unknown compound type: ${type}`);
|
|
443
|
+
}
|
|
444
|
+
}
|
package/src/core/chat.js
CHANGED
|
@@ -1,56 +1,82 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Chat actions — routed through the
|
|
3
|
-
*
|
|
4
|
-
* When RakNet isn't implemented, chat still emits local events so the
|
|
5
|
-
* bot can react to its own messages. Set `simulationMode: true` in bot
|
|
6
|
-
* options to skip transport entirely.
|
|
2
|
+
* Chat actions — routed through the RakNet transport.
|
|
3
|
+
* Requires an active RakNet connection to the Roblox game server.
|
|
7
4
|
*/
|
|
8
5
|
|
|
9
6
|
export class Chat {
|
|
10
|
-
constructor(transport, bot = null
|
|
7
|
+
constructor(transport, bot = null) {
|
|
11
8
|
this.transport = transport;
|
|
12
9
|
this.bot = bot;
|
|
13
|
-
this.simulationMode = options.simulationMode || false;
|
|
14
10
|
this._messageHistory = [];
|
|
15
11
|
}
|
|
16
12
|
|
|
13
|
+
_requireTransport() {
|
|
14
|
+
if (!this.transport || !this.transport.connected) {
|
|
15
|
+
throw new Error("Chat requires an active RakNet transport connection. Call bot.start() first.");
|
|
16
|
+
}
|
|
17
|
+
if (!this.transport.send) {
|
|
18
|
+
throw new Error("Transport does not implement send(). Is RakNet transport active?");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
async say(message) {
|
|
18
23
|
if (!message || typeof message !== "string") {
|
|
19
24
|
throw new Error("Chat message must be a non-empty string.");
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
this._requireTransport();
|
|
28
|
+
|
|
29
|
+
const packet = {
|
|
30
|
+
opcode: 0x90,
|
|
31
|
+
userId: this.bot?.character?.userId || 0,
|
|
32
|
+
username: this.bot?.character?.username || "bot",
|
|
33
|
+
message,
|
|
34
|
+
channel: 0,
|
|
35
|
+
targetUserId: 0,
|
|
36
|
+
timestamp: Date.now(),
|
|
37
|
+
};
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
await this.transport.send(packet);
|
|
40
|
+
|
|
41
|
+
const chatEntry = { message, to: "all", timestamp: Date.now(), sent: true };
|
|
26
42
|
this._messageHistory.push(chatEntry);
|
|
27
43
|
|
|
28
|
-
// Emit local event so listeners can react
|
|
29
44
|
if (this.bot) {
|
|
30
45
|
this.bot.emit("message", { ...chatEntry });
|
|
31
46
|
this.bot.emit("chat", { player: this.bot.character?.username || "bot", message });
|
|
32
47
|
}
|
|
33
48
|
|
|
34
|
-
return { message, sent, simulated:
|
|
49
|
+
return { message, sent: true, simulated: false };
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
async whisper(player, message) {
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
if (!message || typeof message !== "string") {
|
|
54
|
+
throw new Error("Chat message must be a non-empty string.");
|
|
55
|
+
}
|
|
40
56
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
this._requireTransport();
|
|
58
|
+
|
|
59
|
+
const packet = {
|
|
60
|
+
opcode: 0x90,
|
|
61
|
+
userId: this.bot?.character?.userId || 0,
|
|
62
|
+
username: this.bot?.character?.username || "bot",
|
|
63
|
+
message,
|
|
64
|
+
channel: 2,
|
|
65
|
+
targetUserId: 0, // Would need to resolve player name to userId
|
|
66
|
+
timestamp: Date.now(),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
await this.transport.send(packet);
|
|
70
|
+
|
|
71
|
+
const chatEntry = { message, to: player, timestamp: Date.now(), sent: true };
|
|
72
|
+
this._messageHistory.push(chatEntry);
|
|
73
|
+
|
|
74
|
+
if (this.bot) {
|
|
75
|
+
this.bot.emit("message", { ...chatEntry });
|
|
76
|
+
this.bot.emit("chat", { player: this.bot.character?.username || "bot", message });
|
|
53
77
|
}
|
|
78
|
+
|
|
79
|
+
return { message, to: player, sent: true, simulated: false };
|
|
54
80
|
}
|
|
55
81
|
|
|
56
82
|
get messageHistory() {
|
|
@@ -62,4 +88,4 @@ export class Chat {
|
|
|
62
88
|
}
|
|
63
89
|
}
|
|
64
90
|
|
|
65
|
-
export default Chat;
|
|
91
|
+
export default Chat;
|