diff --git a/src/common/helper.ts b/src/common/helper.ts index 2d9968bb..b39aa395 100644 --- a/src/common/helper.ts +++ b/src/common/helper.ts @@ -245,3 +245,36 @@ export function stringifyWithBigInt(obj: any) { typeof value === 'bigint' ? value.toString() : value ); } + +export function parseAppidFromMajor(nodeMajor: string): string | undefined { + const hexSequence = "A4 09 00 00 00 35"; + const sequenceBytes = Buffer.from(hexSequence.replace(/ /g, ""), "hex"); + const filePath = path.resolve(nodeMajor); + const fileContent = fs.readFileSync(filePath); + + let searchPosition = 0; + while (true) { + const index = fileContent.indexOf(sequenceBytes, searchPosition); + if (index === -1) { + break; + } + + const start = index + sequenceBytes.length - 1; + const end = fileContent.indexOf(0x00, start); + if (end === -1) { + break; + } + const content = fileContent.subarray(start, end); + if (!content.every(byte => byte === 0x00)) { + try { + return content.toString("utf-8"); + } catch (error) { + break; + } + } + + searchPosition = end + 1; + } + + return undefined; +} \ No newline at end of file diff --git a/src/common/qq-basic-info.ts b/src/common/qq-basic-info.ts index 20207c2f..f1d4e0a6 100644 --- a/src/common/qq-basic-info.ts +++ b/src/common/qq-basic-info.ts @@ -1,8 +1,9 @@ import fs from 'node:fs'; import { systemPlatform } from '@/common/system'; -import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath } from './helper'; +import { getDefaultQQVersionConfigInfo, getQQPackageInfoPath, getQQVersionConfigPath, parseAppidFromMajor } from './helper'; import AppidTable from '@/core/external/appid.json'; import { LogWrapper } from './log'; +import { getMajorPath } from '@/core'; export class QQBasicInfoWrapper { QQMainPath: string | undefined; @@ -72,6 +73,7 @@ export class QQBasicInfoWrapper { } getAppidV2(): { appid: string; qua: string } { + // 通过已有表 性能好 const appidTbale = AppidTable as unknown as QQAppidTableType; const fullVersion = this.getFullQQVesion(); if (fullVersion) { @@ -80,10 +82,22 @@ export class QQBasicInfoWrapper { return data; } } - - // else + // 通过Major拉取 性能差 + try { + let majorAppid = this.getAppidV2ByMajor(fullVersion); + if (majorAppid) { return { appid: majorAppid, qua: this.getQUAFallback() }; } + } catch (error) { + this.context.logger.log(`[QQ版本兼容性检测] 通过Major 获取Appid异常 请检测NapCat/QQNT是否正常`); + } + // 最终兜底为老版本 this.context.logger.log(`[QQ版本兼容性检测] 获取Appid异常 请检测NapCat/QQNT是否正常`); this.context.logger.log(`[QQ版本兼容性检测] ${fullVersion} 版本兼容性不佳,可能会导致一些功能无法正常使用`,); return { appid: this.getAppIdFallback(), qua: this.getQUAFallback() }; } + getAppidV2ByMajor(QQVersion: string) { + let majorPath = getMajorPath(QQVersion); + let appid = parseAppidFromMajor(majorPath); + return appid; + } + } diff --git a/src/core/index.ts b/src/core/index.ts index 68d478e2..a9f11647 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -62,7 +62,26 @@ export function loadQQWrapper(QQVersion: string): WrapperNodeApi { process.dlopen(nativemodule, wrapperNodePath); return nativemodule.exports; } - +export function getMajorPath(QQVersion: string): string { + // major.node + let appPath; + if (os.platform() === 'darwin') { + appPath = path.resolve(path.dirname(process.execPath), '../Resources/app'); + } else if (os.platform() === 'linux') { + appPath = path.resolve(path.dirname(process.execPath), './resources/app'); + } else { + appPath = path.resolve(path.dirname(process.execPath), `./versions/${QQVersion}/`); + } + let majorPath = path.resolve(appPath, 'major.node'); + if (!fs.existsSync(majorPath)) { + majorPath = path.join(appPath, `./resources/app/major.node`); + } + //老版本兼容 未来去掉 + if (!fs.existsSync(majorPath)) { + majorPath = path.join(path.dirname(process.execPath), `./resources/app/versions/${QQVersion}/major.node`); + } + return majorPath; +} export class NapCatCore { readonly context: InstanceContext; readonly apis: StableNTApiWrapper; diff --git a/src/onebot/api/msg.ts b/src/onebot/api/msg.ts index 119573c8..1e2b6466 100644 --- a/src/onebot/api/msg.ts +++ b/src/onebot/api/msg.ts @@ -229,6 +229,7 @@ export class OneBotMsgApi { ); // 再次筛选 replyMsgList = (await this.core.apis.MsgApi.queryMsgsWithFilterExWithSeqV3(peer, element.replayMsgSeq, [element.senderUidStr])).msgList; + // console.log(JSON.stringify(replyMsgList, null, 4)); replyMsg = replyMsgList.find(msg => msg.msgRandom === records.msgRandom); } if (!replyMsg || records.msgRandom !== replyMsg.msgRandom) {