From e154c1ab14f06d367f612c7aee39b34d8c2e5c02 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 12 Oct 2026 10:35:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(sockets):=20=E6=8E=A2=E9=92=88=20WS=20?= =?UTF-8?q?=E5=AD=97=E8=8A=82=E8=AF=BB=E5=8F=96=E5=85=BC=E5=AE=B9=20DataVi?= =?UTF-8?q?ew=EF=BC=88=E6=AD=A4=E5=89=8D=20hex=20=E6=81=92=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 游戏实际发的是 DataView(有 byteLength、无 slice),走 buffer+byteOffset 取视图;此前 new Uint8Array(dataView,0,24) 得到长度 0 视图,导致 SEND 行 hex 恒空。 --- sockets/probe_railgun.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sockets/probe_railgun.js b/sockets/probe_railgun.js index 4bd962a..a99abcf 100644 --- a/sockets/probe_railgun.js +++ b/sockets/probe_railgun.js @@ -69,8 +69,18 @@ Buf.push('[+' + Now() + 'ms] SEND blob len=' + size + ' hex=' + Hex(new Uint8Array(ab))); }).catch(function () {}); } else if (d && d.byteLength !== undefined) { - var u = new Uint8Array(d.slice ? d.slice(0, 24) : d, 0, Math.min(24, d.byteLength)); - Buf.push('[+' + Now() + 'ms] SEND len=' + d.byteLength + ' hex=' + Hex(u)); + // 注意:游戏实际发的是 DataView / TypedArray / ArrayBuffer(实测 DataView), + // 且有 .byteLength 但没有 .slice —— 必须走 buffer+byteOffset 取视图, + // 否则 new Uint8Array(dataView, 0, 24) 会得到长度 0 的视图(hex 恒为空)。 + var View; + if (d.buffer && typeof d.byteOffset === 'number') { + View = new Uint8Array(d.buffer, d.byteOffset, Math.min(24, d.byteLength)); + } else if (typeof d.slice === 'function') { + View = new Uint8Array(d.slice(0, 24)); + } else { + View = new Uint8Array(d, 0, Math.min(24, d.byteLength)); + } + Buf.push('[+' + Now() + 'ms] SEND len=' + d.byteLength + ' hex=' + Hex(View)); } } catch (e) {} return Orig.apply(this, arguments);