fix(protocol): preserve all system face catalog groups

Decode every group in the third face panel and allow IDs absent from the catalog to use the small-face wire format. Keep animation resources dependent on authoritative catalog metadata.

Fixes #482
This commit is contained in:
DrSmoothl committed 2026-09-26 16:11:58 +08:00
1 parent 075a27cc46
commit e05d3176a2
4 files changed
+35 -43

No files matched your search

@@ -32,15 +32,6 @@ export interface OidbFaceContent {
resourceUrl?: pb<2, OidbFaceResourceUrl>; resourceUrl?: pb<2, OidbFaceResourceUrl>;
} }
export interface OidbFaceMagicContentList {
emojiList?: pb_repeated<2, OidbFaceEmoji>;
}
export interface OidbFaceMagicContent {
field1?: pb<1, OidbFaceMagicContentList>;
resourceUrl?: pb<2, OidbFaceResourceUrl>;
}
export interface OidbFetchSysFacesExpInfo { export interface OidbFetchSysFacesExpInfo {
field1?: pb<1, string>; field1?: pb<1, string>;
} }
@@ -56,5 +47,5 @@ export interface OidbFetchSysFacesResp {
field1?: pb<1, int_32>; field1?: pb<1, int_32>;
commonFace?: pb<2, OidbFaceContent>; commonFace?: pb<2, OidbFaceContent>;
specialBigFace?: pb<3, OidbFaceContent>; specialBigFace?: pb<3, OidbFaceContent>;
specialMagicFace?: pb<4, OidbFaceMagicContent>; specialMagicFace?: pb<4, OidbFaceContent>;
} }
@@ -123,31 +123,21 @@ export namespace FetchSysFaces {
export const deserialize = (_ctx: Deps, body: OidbFetchSysFacesResp): SysFacePackEntry[] => { export const deserialize = (_ctx: Deps, body: OidbFetchSysFacesResp): SysFacePackEntry[] => {
const packs: SysFacePackEntry[] = []; const packs: SysFacePackEntry[] = [];
// common + special-big share the same content shape. // All panels contain repeated groups, including unnamed/hidden groups.
for (const [source, content] of [ for (const [source, content] of [
['common', body.commonFace], ['common', body.commonFace],
['special-big', body.specialBigFace], ['special-big', body.specialBigFace],
['magic', body.specialMagicFace],
] as const) { ] as const) {
for (const list of content?.emojiList ?? []) { for (const list of content?.emojiList ?? []) {
const packIndex = packs.length; const packIndex = packs.length;
packs.push({ packs.push({
packName: list.emojiPackName ?? '', packName: list.emojiPackName || (source === 'magic' ? 'MagicFace' : ''),
emojis: emojisToEntries(list.emojiDetail ?? [], source, packIndex), emojis: emojisToEntries(list.emojiDetail ?? [], source, packIndex),
}); });
} }
} }
// QQ returns magic faces as a single unnamed bundle. Keep a stable local
// name so callers can identify the group across refreshes.
const magicEmojis = body.specialMagicFace?.field1?.emojiList ?? [];
if (magicEmojis.length > 0) {
const packIndex = packs.length;
packs.push({
packName: 'MagicFace',
emojis: emojisToEntries(magicEmojis, 'magic', packIndex),
});
}
return packs; return packs;
}; };
+4 -8
View File
@@ -46,12 +46,9 @@ interface IndexedCatalog {
overlapCount: number; overlapCount: number;
} }
/** Pure classification once an authoritative entry is known. */ /** Use animation metadata when available; any numeric id has a small-face encoding. */
export function faceWireFor(entry: SysFaceEntry | null | undefined, faceId: number): FaceWire { export function faceWireFor(entry: SysFaceEntry | null | undefined, faceId: number): FaceWire {
if (!entry) { if (entry && isSuperFaceEntry(entry)) {
throw new Error(`QQ system face id ${faceId} is absent from the current catalog`);
}
if (isSuperFaceEntry(entry)) {
if (entry.aniStickerPackId == null if (entry.aniStickerPackId == null
|| entry.aniStickerId == null || entry.aniStickerId == null
|| entry.aniStickerType == null) { || entry.aniStickerType == null) {
@@ -133,8 +130,7 @@ export class SysFaceStore {
return matches; return matches;
} }
/** Synchronous classification for callers that already established catalog /** Synchronous classification, including IDs no longer listed in a panel. */
* readiness. Unknown ids fail instead of guessing a QQ wire shape. */
classify(faceId: number): FaceWire { classify(faceId: number): FaceWire {
return faceWireFor(this.lookup(faceId), faceId); return faceWireFor(this.lookup(faceId), faceId);
} }
@@ -226,7 +222,7 @@ export class SysFaceStore {
async resolveWire(sender: OidbSender, faceId: number): Promise<FaceWire> { async resolveWire(sender: OidbSender, faceId: number): Promise<FaceWire> {
const entry = await this.resolve(sender, faceId); const entry = await this.resolve(sender, faceId);
if (!entry) { if (!entry) {
throw new Error(`QQ system face id ${faceId} is absent from the current catalog`); log.debug('system face id %d is not listed in the catalog; sending its small representation', faceId);
} }
return faceWireFor(entry, faceId); return faceWireFor(entry, faceId);
} }
+27 -12
View File
@@ -100,9 +100,9 @@ describe('faceWireFor — classification', () => {
kind: 'super', packId: '1', stickerId: '52', stickerType: 1, kind: 'super', packId: '1', stickerId: '52', stickerType: 1,
}); });
}); });
it('rejects an unknown id instead of guessing a wire shape', () => { it('permits uncatalogued ids using their small representation', () => {
expect(() => faceWireFor(null, 14)).toThrow(/absent from the current catalog/); expect(faceWireFor(null, 14)).toEqual({ kind: 'classic' });
expect(() => faceWireFor(undefined, 424)).toThrow(/absent from the current catalog/); expect(faceWireFor(undefined, 504)).toEqual({ kind: 'small' });
}); });
}); });
@@ -128,11 +128,25 @@ describe('FetchSysFaces protocol contract', () => {
}); });
describe('FetchSysFaces.deserialize', () => { describe('FetchSysFaces.deserialize', () => {
it('decodes every group in the third panel, including unnamed and hidden faces (#482)', () => {
const wire = protobuf_encode<OidbFetchSysFacesResp>({
specialMagicFace: { emojiList: [
{ emojiPackName: 'MagicFace', emojiDetail: [{ qSid: '358' }] },
{ emojiDetail: [{ qSid: '504', unknown10: 1 }, { qSid: '505' }] },
{ emojiPackName: 'Limited', emojiDetail: [{ qSid: '506' }, { qSid: '507' }] },
] },
});
const packs = FetchSysFaces.deserialize({} as never, protobuf_decode<OidbFetchSysFacesResp>(wire));
expect(packs.map((pack) => pack.packName)).toEqual(['MagicFace', 'MagicFace', 'Limited']);
expect(packs.flatMap((pack) => pack.emojis.map((face) => face.qSid)))
.toEqual(['358', '504', '505', '506', '507']);
});
it('flattens common + big + magic packs', () => { it('flattens common + big + magic packs', () => {
const packs = FetchSysFaces.deserialize({} as never, { const packs = FetchSysFaces.deserialize({} as never, {
commonFace: { emojiList: [{ emojiPackName: '经典', emojiDetail: [{ qSid: '14' }] }] }, commonFace: { emojiList: [{ emojiPackName: '经典', emojiDetail: [{ qSid: '14' }] }] },
specialBigFace: { emojiList: [{ emojiPackName: '超级', emojiDetail: [{ qSid: '392', aniStickerType: 3, aniStickerPackId: 2 }] }] }, specialBigFace: { emojiList: [{ emojiPackName: '超级', emojiDetail: [{ qSid: '392', aniStickerType: 3, aniStickerPackId: 2 }] }] },
specialMagicFace: { field1: { emojiList: [{ qSid: '999' }] } }, specialMagicFace: { emojiList: [{ emojiDetail: [{ qSid: '999' }] }] },
} as never); } as never);
expect(packs.map((p) => p.packName)).toEqual(['经典', '超级', 'MagicFace']); expect(packs.map((p) => p.packName)).toEqual(['经典', '超级', 'MagicFace']);
expect(packs[1].emojis[0].aniStickerType).toBe(3); expect(packs[1].emojis[0].aniStickerType).toBe(3);
@@ -171,7 +185,7 @@ describe('FetchSysFaces.deserialize', () => {
}); });
expect(() => FetchSysFaces.deserialize({} as never, { expect(() => FetchSysFaces.deserialize({} as never, {
specialMagicFace: { field1: { emojiList: [driftedFace] } }, specialMagicFace: { emojiList: [{ emojiDetail: [driftedFace] }] },
} as never)).toThrow(/unsupported wire encoding.*wireTypes=0/); } as never)).toThrow(/unsupported wire encoding.*wireTypes=0/);
}); });
}); });
@@ -352,12 +366,12 @@ describe('SysFaceStore — persistent catalog and query seam', () => {
}], }],
}, },
specialMagicFace: { specialMagicFace: {
field1: { emojiList: [{
emojiList: [ emojiDetail: [
{ qDes: '/目录占位' }, { qDes: '/目录占位' },
{ qSid: '999', qDes: '/魔法表情' }, { qSid: '999', qDes: '/魔法表情' },
], ],
}, }],
}, },
} as never); } as never);
const store = new SysFaceStore({ const store = new SysFaceStore({
@@ -390,6 +404,7 @@ describe('SysFaceStore — persistent catalog and query seam', () => {
expect((await store.resolve(sender, 392))?.qSid).toBe('392'); expect((await store.resolve(sender, 392))?.qSid).toBe('392');
expect(await store.resolve(sender, 99999)).toBeNull(); expect(await store.resolve(sender, 99999)).toBeNull();
expect(await store.resolve(sender, 99999)).toBeNull(); expect(await store.resolve(sender, 99999)).toBeNull();
expect(await store.resolveWire(sender, 99999)).toEqual({ kind: 'small' });
expect(fetches).toBe(1); expect(fetches).toBe(1);
}); });
@@ -527,10 +542,10 @@ describe('makeFaceElem (via buildSendElems) — three-way wire encoding', () =>
expect(protobuf_decode<QSmallFaceExtra>(small.commonElem!.pbElem!).faceId).toBe(504); expect(protobuf_decode<QSmallFaceExtra>(small.commonElem!.pbElem!).faceId).toBe(504);
}); });
it('rejects an unknown id even when building without a live send context', async () => { it('sends uncatalogued ids without inventing animation metadata', async () => {
sysFaceStore.load(CATALOG); sysFaceStore.load(CATALOG);
const [element] = await buildSendElems([{ type: 'face', faceId: 504 }]);
await expect(buildSendElems([{ type: 'face', faceId: 99999 }])) expect(element.commonElem?.serviceType).toBe(33);
.rejects.toThrow(/absent from the current catalog/); expect(protobuf_decode<QSmallFaceExtra>(element.commonElem!.pbElem!).faceId).toBe(504);
}); });
}); });