Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion repo/js/AccountSwitchStateMachine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@
- **勾选**:在切换前后检查当前账号UID,辅助判断切换是否成功
- **不勾选**:不进行UID校验

### 6. 截图模式
### 6. UID验证失败时尝试停止配置组
- **勾选**:当UID验证失败时自动终止整个配置组(需配合停止快捷键使用)
- **不勾选**:仅记录错误日志,不干预后续任务
- **停止快捷键**:填写 `VK_` 格式的虚拟键码(如 `VK_F8`),需与BetterGI全局设置一致

### 7. 截图模式
- **勾选**:进入截图模式,自动截图保存对应UID的账号图片
- **不勾选**:正常执行账号切换流程

Expand Down Expand Up @@ -137,6 +142,7 @@ A: UID用于:
- **通知提醒**:切换成功或失败时发送系统通知
- **循环防护**:防止状态循环卡死
- **UID校验**:支持切换前后检查当前账号UID,提高切换准确性
- **智能终止** UID验证失败时可自动终止整个配置组
- **截图模式**:自动截图保存账号图片,方便后续切换

### 目录结构
Expand Down Expand Up @@ -216,6 +222,10 @@ AccountSwitchStateMachine/

### 更新日志

#### v1.1
- **新增**:UID验证失败时自动终止配置组功能,支持配置对应键值
- **优化**:修改了账号密码界面的识别条件,修复可能会出现的误识别问题

#### v1.0
- 初始版本
- 实现状态机管理
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 47 additions & 7 deletions repo/js/AccountSwitchStateMachine/assets/states.json
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,30 @@
"id": "enterAccountAndPassword",
"template": "assets/RecognitionObjects/EnterAccountAndPassword.png",
"region": {
"x": 0,
"y": 0,
"width": 1920,
"height": 1080
"x": 547,
"y": 168,
"width": 825,
"height": 744
}
},
{
"id": "phoneLogin",
"template": "assets/RecognitionObjects/LoginByPhone.png",
"region": {
"x": 547,
"y": 168,
"width": 825,
"height": 744
}
},
{
"id": "forgotPassword",
"template": "assets/RecognitionObjects/ForgotPassword.png",
"region": {
"x": 547,
"y": 168,
"width": 825,
"height": 744
}
},
{
Expand All @@ -316,7 +336,7 @@
}
}
],
"logic": "enterAccountAndPassword && !confirm"
"logic": "((enterAccountAndPassword && phoneLogin) || (enterAccountAndPassword && forgotPassword) || (phoneLogin && forgotPassword)) && !confirm"
}
},
{
Expand Down Expand Up @@ -404,9 +424,29 @@
"width": 439,
"height": 116
}
},
{
"id": "phoneLogin",
"template": "assets/RecognitionObjects/LoginByPhone.png",
"region": {
"x": 547,
"y": 168,
"width": 825,
"height": 744
}
},
{
"id": "forgotPassword",
"template": "assets/RecognitionObjects/ForgotPassword.png",
"region": {
"x": 547,
"y": 168,
"width": 825,
"height": 744
}
}
],
"logic": "login && !enterGame && !selectAccount && !enterAccountAndPassword && !confirm"
"logic": "login && !enterGame && !selectAccount && !enterAccountAndPassword && !confirm && !phoneLogin && !forgotPassword"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
]
]
49 changes: 46 additions & 3 deletions repo/js/AccountSwitchStateMachine/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,42 @@ let stateMachineConfig = null;
// 全局游戏画面区域
let gameRegion = null;

/**
* 停止整个配置组
* @param {string} reason - 停止原因
*/
async function emergencyStopConfigGroup(reason) {
notification.error(`⛔ ${reason}\n\n已尝试终止后续任务`);

await sleep(1000);

try {
let hotkey = settings.stopHotkey || 'VK_F8';

if (typeof hotkey === 'string' && hotkey.trim()) {
hotkey = hotkey.trim().toUpperCase();

if (!hotkey.startsWith('VK_')) {
log.error('停止快捷键格式不正确,跳过按键');
throw new Error(`[CONFIG_GROUP_STOPPED] ${reason}`);
}
} else {
log.error('停止快捷键未配置或格式错误,跳过按键');
throw new Error(`[CONFIG_GROUP_STOPPED] ${reason}`);
}

log.info(`模拟按下停止键 (${hotkey})...`);
keyPress(hotkey);
await sleep(500);
} catch (e) {
if (!e.message.includes('[CONFIG_GROUP_STOPPED]')) {
log.error(`按键模拟失败: ${e.message}`);
}
}

throw new Error(`[CONFIG_GROUP_STOPPED] ${reason}`);
}

// 主逻辑
(async function () {
// 只有当未开启截图模式时,才检查 verifyUid 和 targetUid
Expand Down Expand Up @@ -141,10 +177,10 @@ let gameRegion = null;
const uidFound = await findAndClick(accountRo, true, 5000);

if (uidFound) {
log.info(`成功点击账号图片:${settings.targetUid}.png`);
log.info(`成功点击账号图片:${settings.targetUid}.png`);

// 定位到主界面
log.info('开始:尝试切换到 mainUI 状态');
// 定位到主界面
log.info('开始:尝试切换到 mainUI 状态');
const mainUIResult = await goToState('mainUI');
if (mainUIResult) {
log.info('成功到达 mainUI 状态,账号切换完成');
Expand Down Expand Up @@ -335,6 +371,13 @@ let gameRegion = null;
log.warn(`切换后的账号UID ${currentUid} 与目标UID ${settings.targetUid} 不匹配,需要重新尝试`);
currentSwitchSuccess = false;
currentNotificationMessage = `切换失败,当前账号UID ${currentUid} 与目标UID ${settings.targetUid} 不匹配`;

// UID验证失败时自动停止配置组(如果开启)
if (settings.uidMismatchAutoStop) {
await emergencyStopConfigGroup(
`UID验证失败!为防止在错误账号下继续执行,已尝试终止配置组`
);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion repo/js/AccountSwitchStateMachine/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"manifest_version": 1,
"name": "带状态机的账号切换",
"version": "1.0",
"version": "1.1",
"description": "",
"authors": [
{
"name": "mno"
},
{
"name": "lingyu",
"links": "https://github.com/aaahai00"
}
],
"settings_ui": "settings.json",
Expand Down
13 changes: 12 additions & 1 deletion repo/js/AccountSwitchStateMachine/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@
"name": "screenshotMode",
"type": "checkbox",
"label": "勾选后进入截图模式,自动截图保存对应UID的账号图片"
},
{
"name": "uidMismatchAutoStop",
"type": "checkbox",
"label": "当UID验证失败时尝试终止配置组(原理是模拟指定键盘按键,需提前去BetterGI设置)"
},
{
"name": "stopHotkey",
"type": "input-text",
"label": "终止配置组用的停止快捷键(需提前去BetterGI设置,与bgi停止快捷键需要一致)",
"default": "VK_F8"
}
]
]