fix(protocol): send super/new faces with the right wire encoding (#168)

A face was always built as a legacy FaceElem (face.index). QQ-NT only renders
classic small faces that way; newer 'super'/animated faces sent as face.index
are silently remapped by the server (e.g. 424→168) or shown as a placeholder.

Classify each face id off QQ's own system-face catalog (0x9154_1, ported from
SLE/Lagrange) and pick the matching wire form:
  - super (animated, aniSticker pack ≠ (1,1)) → CommonElem 37 + QFaceExtra
  - other id ≥ 260                            → CommonElem 33 + QSmallFaceExtra
  - classic id < 260                          → legacy FaceElem

The catalog is fetched once (shared, lazy-warmed off the first face send) and
classify falls back to an id-range guess until it lands. Data-driven so all 66
non-(1,1) super faces encode correctly, not just a hardcoded few.

Verified on a live account: 424→424 (was 168), super 392→392, classic 14→14.
This commit is contained in:
DrSmoothl committed 2026-06-30 16:09:28 +08:00
1 parent f9900053b0
commit c839121fdb
6 files changed
+429 -6

No files matched your search

+42 -6
View File
@@ -2,11 +2,12 @@ import type {
MarkdownData,
MentionExtraSend,
} from '@snowluma/proto-defs/action';
import type { Elem, GroupFileExtra, MarketFacePbReserve } from '@snowluma/proto-defs/element';
import type { Elem, GroupFileExtra, MarketFacePbReserve, QFaceExtra, QSmallFaceExtra } from '@snowluma/proto-defs/element';
import { protobuf_encode } from '@snowluma/proton';
import { randomUUID } from 'crypto';
import { deflateSync } from 'zlib';
import type { BridgeContext } from './bridge-context';
import { sysFaceStore } from './sys-face-store';
import type { MessageElement } from './events';
import { uploadImageMsgInfo } from './highway/image-upload';
import { hexToBytes } from './highway/pipeline';
@@ -39,10 +40,45 @@ function makeTextElem(text: string): ProtoElem {
};
}
function makeFaceElem(faceId: number): ProtoElem {
return {
face: { index: faceId },
};
// QQ-NT splits face ids across three wire encodings. The legacy FaceElem only
// renders classic small faces; newer "super" / animated faces sent that way are
// silently remapped by the server (e.g. 424→168, issue #168). The split is
// data-driven off the system-face catalog (0x9154_1, see sys-face-store):
// super (animated, aniSticker not pack (1,1)) → CommonElem 37 + QFaceExtra
// other id ≥ 260 → CommonElem 33 + QSmallFaceExtra
// classic id < 260 → legacy FaceElem
function makeFaceElem(faceId: number, ctx?: SendContext): ProtoElem {
// Keep the catalog warm so subsequent super-face sends are classified even if
// this one raced ahead of the first fetch.
if (ctx) sysFaceStore.ensureWarm(ctx.bridge);
const wire = sysFaceStore.classify(faceId);
if (wire.kind === 'super') {
return {
commonElem: {
serviceType: 37,
pbElem: protobuf_encode<QFaceExtra>({
packId: wire.packId,
stickerId: wire.stickerId,
qsid: faceId,
sourceType: 1,
stickerType: wire.stickerType,
randomType: 1,
}),
businessType: 1,
},
};
}
if (wire.kind === 'small') {
return {
commonElem: {
serviceType: 33,
pbElem: protobuf_encode<QSmallFaceExtra>({ faceId, preview: '', preview2: '' }),
businessType: 1,
},
};
}
return { face: { index: faceId } };
}
function resolveMentionDisplay(ctx: SendContext | undefined, targetUin: number): string {
@@ -414,7 +450,7 @@ export async function buildSendElems(elements: MessageElement[], ctx?: SendConte
break;
case 'face':
if (elem.faceId !== undefined) result.push(makeFaceElem(elem.faceId));
if (elem.faceId !== undefined) result.push(makeFaceElem(elem.faceId, ctx));
break;
case 'mface':