忘机山人
在《植物大战僵尸》这类游戏中,金币、钻石、植物解锁等信息,其实都存储在本地的存档文件里。上一次我们已经通过修改存档文件,成功实现了无限金币和钻石的解锁。当时的关键发现是:导出的存档其实就是一个 JSON 文件。

这意味着存档本质上是一种结构化数据,可以直接用 Python 等编程语言进行解析和修改。只要找到相应的字段,就能批量调整游戏进度。
在进一步探索时,我注意到存档中有一个字段叫做 plantProps。从命名上看,plant 代表植物,props 代表属性。结合游戏机制,我猜测这里存储的就是每个植物的状态信息,比如是否解锁、解锁进度、是否拥有某些皮肤等等。
于是我决定写一段脚本,来验证并修改其中的进度字段,看看是否能一键解锁所有植物。
在导出的 JSON 文件中,我们可以看到类似这样的片段:
{
"plantProps": {
"1": {
"progress": 0,
"level": 1,
"otherProp": "xxx"
},
"2": {
"progress": 1,
"level": 1,
"otherProp": "yyy"
}
}
}
从数据上可以推断:
1、2),可能代表植物的 ID。"progress" 字段就是解锁进度,数值不同代表不同状态。根据测试结果,大致可以推测:
0 → 未解锁1 → 解锁中/部分解锁2 → 完全解锁这就印证了我的猜想:只要把所有 "progress" 改成 2,就能解锁全部植物。

脚本的目标非常明确:
plantProps,找到所有 "progress" 字段。2。完整代码如下:
import json
def main():
input_file = "~/Downloads/save.json" # 原始存档文件
output_file = "save_mod.json" # 修改后的存档文件
# 1. 读取 JSON
with open(input_file, "r", encoding="utf-8") as f:
data = json.load(f)
# 2. 遍历并修改 progress
if "plantProps" in data and isinstance(data["plantProps"], dict):
for plant, props in data["plantProps"].items():
if isinstance(props, dict) and "progress" in props:
props["progress"] = 2
# 3. 保存修改结果
with open(output_file, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
# 4. 完成提示
print(f"plantProps 下所有 progress 已改为 2,结果保存在 {output_file}")
if __name__ == "__main__":
main()
这个脚本很短,但涵盖了完整的存档解锁逻辑。接下来我会逐步拆解。
input_file = "~/Downloads/save.json" # 原始存档
output_file = "save_mod.json" # 修改后的存档
input_file:指向游戏导出的存档文件。output_file:修改后的文件存储位置,避免覆盖原文件。养成好习惯,不要直接修改原始存档,否则一旦出错就没法恢复。
with open(input_file, "r", encoding="utf-8") as f:
data = json.load(f)
这里使用 Python 内置的 json 模块:
json.load(f) 会把 JSON 内容转换为 Python 字典。if "plantProps" in data and isinstance(data["plantProps"], dict):
for plant, props in data["plantProps"].items():
if isinstance(props, dict) and "progress" in props:
props["progress"] = 2
plantProps 存在并且是字典。"progress",就直接改为 2。这一步就是解锁的核心操作。
with open(output_file, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)
json.dump() 把修改过的字典重新写回 JSON 文件。indent=2:让输出文件缩进更清晰,方便阅读。ensure_ascii=False:保证中文不会被转义。print(f"plantProps 下所有 progress 已改为 2,结果保存在 {output_file}")
程序执行完成后,会在命令行输出提示,确认修改成功。
实际测试时,我把修改后的 save_mod.json 覆盖回游戏存档,再次启动游戏,结果发现:
这说明 "progress" 字段确实是控制植物解锁进度的关键变量。

评论
0暂无评论