杀戮尖塔通过修改记录文件和备份文件进行修改血量和金币

python 复制代码
import json
import os
import shutil
from pathlib import Path

# ================= 配置区 =================
# 在这里设定你期望的数值
NEW_CURRENT_HP = 120    # 当前生命值
NEW_MAX_HP = 130        # 最大生命值
NEW_GOLD = 2000         # 金币
# ==========================================

def find_sts2_save_dir() -> Path | None:
    """
    自动定位《杀戮尖塔2》的最新存档目录
    """
    appdata = os.getenv('APPDATA')
    if not appdata:
        return None
    
    base_path = Path(appdata) / "SlayTheSpire2" / "steam"
    if not base_path.exists():
        return None
        
    # 遍历寻找 steam ID 和 profile 文件夹
    for steam_id_dir in base_path.iterdir():
        if steam_id_dir.is_dir():
            for profile_dir in steam_id_dir.glob("profile*"):
                save_dir = profile_dir / "saves"
                if save_dir.exists():
                    return save_dir
    return None

def inject_save_data(save_dir: Path):
    """
    解析 JSON 并注入修改数据
    """
    target_files = ["current_run.save", "current_run.save.backup"]
    
    for filename in target_files:
        file_path = save_dir / filename
        if not file_path.exists():
            print(f"[-] 忽略缺失文件: {file_path.name}")
            continue
            
        try:
            # [安全机制] 操作前创建强制备份
            backup_path = file_path.with_suffix(".save.bak_script")
            if not backup_path.exists():
                shutil.copy2(file_path, backup_path)
                print(f"[*] 已生成防呆备份: {backup_path.name}")

            # 读取存档
            with open(file_path, 'r', encoding='utf-8') as f:
                data = json.load(f)

            # 遍历并修改 players 数据流
            is_modified = False
            if "players" in data:
                for player in data["players"]:
                    player["current_hp"] = NEW_CURRENT_HP
                    player["max_hp"] = NEW_MAX_HP
                    player["gold"] = NEW_GOLD
                    is_modified = True

            # 回写存档
            if is_modified:
                with open(file_path, 'w', encoding='utf-8') as f:
                    json.dump(data, f, indent=2, ensure_ascii=False)
                print(f"[+] 成功覆盖数值: {file_path.name}")
            else:
                print(f"[!] {file_path.name} 结构异常: 缺失 'players' 节点")

        except json.JSONDecodeError:
            print(f"[x] JSON 解析失败,文件可能已损坏: {file_path.name}")
        except Exception as e:
            print(f"[x] 处理 {file_path.name} 时发生未知异常: {str(e)}")

if __name__ == "__main__":
    print("=== STS2 存档自动化注入工具 ===")
    target_dir = find_sts2_save_dir()
    
    if target_dir:
        print(f"[*] 成功解析存档路径: {target_dir}")
        inject_save_data(target_dir)
        print("=== 注入完成 ===")
    else:
        print("[x] 寻址失败: 未在系统 APPDATA 中检测到游戏存档,请确认游戏是否已在本机运行过。")
相关推荐
AI 编程助手GPT36 分钟前
GPT 排的日志时间线差一小时?用 zoneinfo 复现夏令时回拨
人工智能·python·gpt
Thanks_ks1 小时前
【第 003 讲】全面认识 Python:语言起源与设计哲学 | 行业地位与流行趋势 | 技术优势与应用领域 | 技术边界与工程局限
人工智能·python·数据分析·编程语言·python 入门·web 开发·python 之禅
用户790860057261 小时前
给 AI 装上耳朵:离线语音识别与唤醒,国内环境踩坑实录
python
用户790860057261 小时前
我让 AI 自己上了趟网:browser-use 的三个致命坑和 CDP 混合方案
python
安枳杦1 小时前
把一个 FastAPI 网页塞进 macOS 的 Dock:Tauri 2 + PyInstaller 实战
python
像风一样自由20202 小时前
3.Dockerfile如何构建一个Python算法镜像
开发语言·人工智能·python·大模型
Dmz丶2 小时前
前端转 AI 100 天 Day 36:Prompt 工程入门——从“感觉对了就行”到方法论
python
日日大王学编程2 小时前
AI 时代后端方向新人的未来规划与看法
人工智能·后端·python·ai·golang
CCblandy3 小时前
缓存淘汰实测:一次全表扫描把 LRU 命中率从 46% 打到 38%,W-TinyLFU 守住 50% 却贵 11 倍
后端·python·缓存·性能优化·架构
汤米粥3 小时前
cmd手动创建的Django项目怎么用社区版Pycharm运行起来
python·pycharm·django