{"id":51235920,"url":"https://github.com/yehuoshun/czn-auto","last_synced_at":"2026-06-28T20:30:35.211Z","repository":{"id":365720429,"uuid":"1273413860","full_name":"yehuoshun/czn-auto","owner":"yehuoshun","description":"卡厄斯梦境自动化脚本 - Python + OpenCV + Win32 API","archived":false,"fork":false,"pushed_at":"2026-06-28T18:03:06.000Z","size":166,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-28T18:15:24.774Z","etag":null,"topics":["automation","game","opencv","python","win32"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yehuoshun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-18T13:54:36.000Z","updated_at":"2026-06-28T18:03:09.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yehuoshun/czn-auto","commit_stats":null,"previous_names":["yehuoshun/czn-auto"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yehuoshun/czn-auto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yehuoshun%2Fczn-auto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yehuoshun%2Fczn-auto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yehuoshun%2Fczn-auto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yehuoshun%2Fczn-auto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yehuoshun","download_url":"https://codeload.github.com/yehuoshun/czn-auto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yehuoshun%2Fczn-auto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34903523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","game","opencv","python","win32"],"created_at":"2026-06-28T20:30:34.543Z","updated_at":"2026-06-28T20:30:35.200Z","avatar_url":"https://github.com/yehuoshun.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 卡厄思梦境自动化脚本\n\n基于 **Python + OpenCV + Win32 API** 的游戏自动化框架。\n\n\u003e 不碰内存、不注入、不改包。纯视觉识别 + 模拟点击。\n\n## 核心能力\n\n| 模块 | 能力 | 技术方案 |\n|------|------|----------|\n| **截图** | 游戏窗口截图 | ImageGrab（主） → PrintWindow（回退） |\n| **识别** | 主页/子页面判定 | 竖线检测 + 返回箭头模板匹配 |\n| **OCR** | 菜单按钮文字识别 | PaddleOCR（PP-OCRv6） |\n| **点击** | 模拟真实鼠标点击 | SetCursorPos + mouse_event（管理员权限） |\n| **导航** | 主页↔子页面切换 | OCR 定位菜单按钮 + 返回箭头模板匹配 |\n\n## 项目结构\n\n```\nczn-auto/\n├── main.py                    # 主入口，状态机主循环\n├── src/\n│   ├── config.json            # 配置文件\n│   ├── core/                  # 底层能力\n│   │   ├── screenshot.py      # 截图：ImageGrab + PrintWindow\n│   │   ├── recognizer.py      # 识别：模板匹配 + PaddleOCR\n│   │   ├── clicker.py         # 点击：SetCursorPos / SendInput\n│   │   ├── config.py          # 配置：JSON 加载，自动缩放\n│   │   └── logger.py          # 日志：文件+控制台双输出，终端文件一致\n│   ├── modules/               # 识别层（纯视觉，不点击）\n│   │   ├── home.py            # 主页检测 / 页面判定 / 赛季入口\n│   │   ├── season.py          # 赛季页面识别 / 卡厄思按钮\n│   │   └── czn.py             # 常驻卡厄思页面识别 / 关卡/难度/确认按钮\n│   ├── actions/               # 操作层（封装点击）\n│   │   ├── home_actions.py    # 导航 / 返回主页 / 关闭弹窗\n│   │   ├── season_actions.py  # 赛季页面操作 / 进入卡厄思\n│   │   └── czn_actions.py     # 常驻卡厄思操作 / 关卡选择 / 难度 / 进入战斗\n│   ├── data/                  # 游戏数据\n│   │   ├── card_loader.py     # 卡牌数据加载器\n│   │   └── cards/             # 角色卡牌图鉴（JSON）\n│   │       ├── 海德玛丽.json   # 已更新：7张卡牌 + 神光一闪\n│   │       ├── 米卡.json\n│   │       └── ...            # 36+ 角色卡牌数据\n│   ├── images/\n│   │   ├── commons/           # 公共模板（跨赛季复用）\n│   │   │   └── back_arrow.png\n│   │   └── s3/                # 赛季3「回荡在银河中的歌声」\n│   │       ├── banner.png     # 主页赛季入口横幅\n│   │       └── czn.png        # 赛季页面「卡厄思」按钮\n│   └── logs/                  # 日志输出\n└── .github/workflows/         # CI：钉钉通知\n```\n\n## 依赖\n\n```bash\npip install opencv-python pillow numpy \"paddlepaddle\u003e=3\" \"paddleocr\u003e=3\"\n```\n\n## 快速开始\n\n### 1. 配置\n\n编辑 `src/config.json`：\n\n```json\n{\n  \"game\": { \"window_title\": \"卡厄思梦境\" },\n  \"click\": { \"delay_ms\": 100, \"post_click_wait_ms\": 500, \"humanize\": true },\n  \"loop\": { \"interval_ms\": 1000, \"max_iterations\": 0 },\n  \"log\": { \"level\": \"DEBUG\", \"file\": \"src/logs/czn-auto.log\", \"max_size_mb\": 50, \"backup_count\": 5 }\n}\n```\n\n### 2. 运行\n\n```bash\npython main.py\n```\n\n**必须以管理员权限运行**（ACE 反作弊拦截非管理员进程）。\n\n## 架构\n\n```\nmain.py (CZNAuto)\n  ├── Screenshot    ← 截图\n  ├── Recognizer    ← 识别\n  ├── Clicker       ← 点击\n  ├── HomePage      ← 识别层: is_home / detect_page / find_season_banner\n  ├── SeasonPage    ← 识别层: find_czn_button\n  ├── CznPage       ← 识别层: is_czn / find_stages / find_difficulty / find_confirm_button\n  ├── HomeActions   ← 操作层: navigate_to / go_home / close_popup\n  ├── SeasonActions ← 操作层: enter_czn\n  └── CznActions    ← 操作层: select_stage / select_difficulty / enter_battle / scan_page\n```\n\n**分层规则**：\n- `core/` — 底层能力，不依赖业务\n- `modules/` — 纯识别，不操作鼠标键盘\n- `actions/` — 纯操作，调 modules 拿坐标后执行点击\n- 新增页面 → `modules/` 加识别类 + `actions/` 加操作类\n\n## 主页判定逻辑\n\n```\n竖线 ✅ + 返回箭头 ❌ → 主页大厅\n竖线 ✅ + 返回箭头 ✅ → 子页面（出击/模拟/卡厄思…）\n竖线 ❌                 → 非游戏页面\n```\n\n- **竖线检测**：菜单栏 ROI `(88%-99%) × (8%-82%)`，Sobel 梯度 + 列投影\n- **返回箭头**：模板匹配 `src/images/commons/back_arrow.png`，阈值 0.45\n- 子页面左上角有返回箭头（←），主页没有，模板匹配不依赖颜色\n\n## 模块 API\n\n### HomePage — 识别层 (`src/modules/home.py`)\n\n| 方法 | 说明 |\n|------|------|\n| `is_home(screenshot) → bool` | 判定是否在主页 |\n| `detect_page(screenshot) → str` | 返回页面标识（\"home\" / \"season\" / \"czn\" / \"popup\" / \"unknown\"） |\n| `has_back_arrow(screenshot) → bool` | 检测返回箭头是否存在 |\n| `find_button(screenshot, target) → tuple | None` | OCR 查找菜单按钮坐标 |\n| `find_back_arrow(screenshot) → tuple | None` | 模板匹配找返回箭头坐标（1920×1080 基准） |\n| `find_season_banner(screenshot) → tuple | None` | 模板匹配找赛季入口横幅坐标 |\n| `get_layout_debug(screenshot) → dict` | 导出调试图数据 |\n\n### HomeActions — 操作层 (`src/actions/home_actions.py`)\n\n| 方法 | 说明 |\n|------|------|\n| `navigate_to(target, screenshot) → bool` | 导航到目标页面 |\n| `go_home() → bool` | 点击返回箭头回到主页，ESC 兜底 |\n| `close_popup() → bool` | 关闭弹窗（ESC） |\n\n### CznPage — 识别层 (`src/modules/czn.py`)\n\n| 方法 | 说明 |\n|------|------|\n| `is_czn(screenshot) → bool` | 判定是否在常驻卡厄思页面 |\n| `find_stages(screenshot) → list[dict]` | OCR 识别关卡列表 |\n| `find_stage_by_name(screenshot, keyword) → tuple | None` | 按名称查找关卡坐标 |\n| `find_difficulty(screenshot) → dict | None` | 识别当前选中难度 |\n| `find_difficulty_button(screenshot, target) → tuple | None` | 查找指定难度按钮 |\n| `find_confirm_button(screenshot) → tuple | None` | 查找确定/进入战斗按钮 |\n\n### CznActions — 操作层 (`src/actions/czn_actions.py`)\n\n| 方法 | 说明 |\n|------|------|\n| `select_stage(screenshot, keyword) → bool` | 选择关卡 |\n| `select_difficulty(screenshot, target) → bool` | 选择难度 |\n| `enter_battle(screenshot) → bool` | 点击确认进入战斗 |\n| `quick_start(screenshot, difficulty) → bool` | 一键选难度+进入战斗 |\n| `scan_page(screenshot) → dict` | 扫描页面所有可操作元素 |\n\n## 卡牌数据系统\n\n`src/data/cards/*.json` — 角色卡牌图鉴，数据来源 GameKee。\n\n### CardLoader API\n\n| 方法 | 说明 |\n|------|------|\n| `load_all_cards() → dict` | 加载所有卡牌，返回 `{卡名: {...}}` |\n| `get_by_character(cards, char_name) → dict` | 返回指定角色的所有卡牌 |\n| `get_by_type(cards, card_type) → dict` | 返回指定类型（攻击/技能）的所有卡牌 |\n\n### 卡牌 JSON 格式\n\n```json\n{\n  \"角色\": \"海德玛丽\",\n  \"属性\": \"热情\", \"职业\": \"游侠\", \"稀有度\": \"五星\",\n  \"卡牌\": {\n    \"卡牌名\": {\n      \"id\": 972,\n      \"type\": \"攻击\",\n      \"cost\": 1,\n      \"effect\": \"...\",\n      \"kind\": \"独特卡牌\",\n      \"rarity\": \"稀有\",\n      \"灵光一闪\": true,\n      \"神光一闪\": [{\"cost\": 1, \"effect\": \"...\", \"recommend\": true}]\n    }\n  },\n  \"自我意识技能\": { \"名称\": \"剑之乐园\", \"EP\": 5, \"效果\": \"...\" },\n  \"来源\": \"GameKee URL\"\n}\n```\n\n### 已更新角色\n\n| 角色 | 卡牌数 | 灵光一闪 | 最后更新 |\n|------|--------|----------|----------|\n| 海德玛丽 | 8 张（2 基本 + 4 独特 + 2 可生成） | ✅ | 2026-06-22 |\n\n## 注意事项\n\n- **必须管理员权限**：ACE 反作弊拦截非管理员进程\n- **必须窗口化**：PrintWindow 对全屏独占模式可能失效\n- 所有坐标基于 1920×1080 基准，`Clicker` 自动缩放\n- 截图默认不唤醒 UI（`capture(wake_ui=False)`），避免子页面误触按钮\n- 日志文件始终 DEBUG 全量记录，终端与文件格式内容完全一致\n- **赛季入口**：模板匹配右下角横幅 `s3/banner.png`，每季换图即可复用\n- **赛季模板**：`src/images/s3/` 目录，换季新建 `s4/` 目录即可\n- **测试脚本**：`python test_season_flow.py` 验证赛季流程，`python test_czn_flow.py` 验证常驻卡厄思流程","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyehuoshun%2Fczn-auto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyehuoshun%2Fczn-auto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyehuoshun%2Fczn-auto/lists"}