MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

DarkestDungeonSaveEditor:深入剖析

项目背景与痛点

《Darkest Dungeon》是一款备受玩家喜爱的 Roguelike 游戏,而玩家的保存文件无疑是游戏的命脉。然而,保存文件一旦损坏,就会导致玩家辛苦积累的数据丢失。robojumper/DarkestDungeonSaveEditor 正是为了填补这一空白,它是一款针对《Darkest Dungeon》保存文件(.json 格式)的阅读器、编辑器和写入工具,同时支持以电子表格的形式展示。该工具不仅能够便捷地导入和导出保存数据,还能够提供直观的编辑功能,使玩家能够轻松地调整游戏中的角色属性和成就,增强游戏体验。

核心技术揭秘

从技术层面来看,项目的核心在于解析和修改 JSON 格式的保存文件。其架构设计具备良好的扩展性和灵活性,并采用了现代 JavaScript 编程范式。以下是项目的关键技术栈及设计模式:

  • 技术栈:前端主要使用 JavaScript,依赖于 Node.js 和 Electron 来开发跨平台桌面应用。
  • 设计模式:采用了 MVC 模式来实现业务逻辑与界面的解耦,使代码结构清晰,易于维护和扩展。
  • 数据流:保存文件作为输入,经过数据读取、解析和编辑,最终输出修改后的保存文件或电子表格格式。

运行架构图

graph TD A[用户启动应用] --> B[读取保存文件] B --> C[JSON 解析] C --> D[数据展示] D --> E{"用户操作?"} E -->|"编辑保存"| F[应用修改] E -->|"退出应用"| H[保存并关闭] F --> G[保存文件写入] G --> H

功能亮点与差异

相比较其他类似工具,DarkestDungeonSaveEditor 提供了以下独特功能:

  • 多格式支持:除了直接编辑 JSON 文件,还支持将数据导出为电子表格,使得数据对比和分析更加直观。
  • 用户友好界面:使用 Electron 构建的跨平台界面,具备一致的用户体验。
  • 插件扩展性:由于良好的 API 接口和模块化设计,开发者可以扩展更多功能,如数据恢复、自动记录等。

应用场景与落地建议

在使用上,该工具非常适合于以下场景:

  • 数据恢复和修复
  • 玩家自定义角色属性
  • 游戏研究与数据对比

在生产环境使用该工具需要注意以下几点:

  • 备份数据:尽管工具提供了保存文件的读写功能,但建议在任何修改之前备份原始保存文件。
  • 避免干扰游戏进程:修改保存文件时,避免同时运行游戏可能导致不兼容或数据丢失。

综合评价

优点

  1. 用户友好的界面:提供可视化编辑工具,用户无需掌握晦涩的技术知识即可进行保存数据修改。
  2. 插件扩展性:插件机制允许社区更为丰富的功能扩展。
  3. 数据多格式兼容:支持文件导入导出为不同的格式,便于数据分析和存储。

缺点

  1. 稳定性:作为一个开源项目,尤其是其跨平台特性,其稳定性可能有待进一步加强,部分版本可能存在一些小的 bug。
  2. 性能:对于大容量的 JSON 保存文件,解析和编辑可能占用较多资源,影响用户体验。

总体而言,DarkestDungeonSaveEditor 非常适合那些想要深入游戏保存文件内部玩法的玩家和研究者。虽然在性能和稳定性上还有改进空间,但其强大的功能性和开放的社区支持,使得它在同类工具中脱颖而出。

关于

GitHub 原始描述(英文)

Darkest Dungeon Save File (.json) Reader, Writer, Editor. Also, Spreadsheets.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
240
价值分
76
活跃状态
活跃

语言占比

HTML
Java
JavaScript
Rust

README

Darkest Dungeon Save Editor

GitHub license GitHub release Github issues reddit contact

A Darkest Dungeon Save Game Reader, Editor and Writer. Requires Java Runtime Environment 8+.

There also is an experimental Rust implementation with an online save editor.

Download

The link takes you to the latest release on the Releases page. You may also wish to build it yourself, see Building for that.

Motivation & Fundamentals

Darkest Dungeon uses a proprietary save fomat. The files have a .json extension, but are actually binary files.

While the general structure of the format resembles JSON, there are differences. A full documentation of the format can be found in docs/dson.md.

GUI

screenshot

Decoding

java -jar DDSaveEditor.jar decode [--debug, -d] [--names, -n <namefile>] [--output, -o <outfile>] filename

-d dumps all metadata without known purpose as comments into the JSON file at the appropriate place. This might come in handy when trying to find a pattern in them. With -d, the file is not valid JSON, but should be after removing all comments. Files translated without the -d flag should be valid JSON. -n provides a Name File, a newline separated list of strings that are recognized as hashed values.

Name Files

Darkest Dungeon hashes some strings using their own hash algorithm, which can make reading some files rather complicated for you. Whenever an integer is recognized as the hash of a given string, it’s replaced with that String instead. When combined with the -d flag, the hashed integers are added as comments.

A list can be compiled by running

java -jar DDSaveEditor.jar names [dir1] [dir2] [dir3] [...]

dir1, … are directories that contain Darkest Dungeon game data. These are usually the game root directory, but can also be mods.
There is no output file parameter, just pipe it to a file (append > names.txt).

Saving

There also is a save writer:

java -jar DDSaveEditor.jar encode [--output, -o outfile] filename

The input file must be a save file decoded without a name file and without the debug parameter. Providing a name file changes the JSON structure and replaces some integers with strings, which breaks the game compatibility.

While the JSON exported by the decoder is valid JSON without any nonstandard extensions, the application still only de-/serializes Darkest Dungeon save files correctly. There are no guarantees that any additions that don’t resemble the Darkest Dungeon data will serialize correctly.

Spreadsheets

This application includes a service that uploads some save file data live to a Google Spreadsheet. In order to use this, you need to create a new Application using the Google API Developer Console, enable the Google Sheets API and create an OAuth client ID and secret.

If you have done that, create a file client_secret.json with the following content in the same directory as the jar file:

{
    "installed": {
        "client_id": "clientid",
        "client_secret": "clientsecret"
    }
}

And launch it via

java -jar DDSaveEditor.jar sheets [--names, -n <namefile>] [--sheet, -s <sheetid>] saveDir

or the GUI (Tools->Spreadsheets).

You will be asked whether to grant your application access to the spreadsheets. Confirm your choice and the data should start uploading.

Building

The application uses Gradle to build. You can build a complete jar file using ./gradlew fatJar. The jar file can be found as build/libs/DDSaveEditor.jar.

If you are using the spreadsheets service, you can add the client_secret.json to src/main/resources and build with ./gradlew fatJar -PincludeSecret. This will include the id and secret in the jar file so you don’t need to add a separate client_secret.json to the file system, just make sure you don’t accidentally give this jar to anyone else as this would incur the risk of API Key abuse.

Tests

In src/tests, there are a number of save files, some are mine, some are picked from other places on the internet. By running ./gradlew test, a round trip-test is performed: the tests check if all of them can be loaded, and produce somewhat correct save files again.
If the game updates, we’ll probably need to update those save files too (I don’t expect major changes to the format, but there might be the occasional new field that needs to be identified).

Contributing

Contributions via Pull Requests or Issue reports welcome! For Pull Requests, please make sure that the round-trip tests pass and include your own save files as tests.

Plans

  • Figure out unknown variables
  • Make a better GUI

Attribution

License

This application is licensed under the MIT License.

评论

暂无评论