From 19e728c3cbf07ebe956d8b865ce4be1f74093dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Wed, 30 Oct 2024 13:50:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8F=90=E5=8D=87=E5=85=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/helper.ts | 33 +++++++++++++++++++++++++++++++++ src/common/qq-basic-info.ts | 20 +++++++++++++++++--- src/core/index.ts | 21 ++++++++++++++++++++- src/onebot/api/msg.ts | 1 + 4 files changed, 71 insertions(+), 4 deletions(-) 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) {