> For AI agents: the complete documentation index is available at https://renmori.mewbaka.cn/llms.txt, the full documentation bundle is available at https://renmori.mewbaka.cn/llms-full.txt.

# Steam 发行指南

RenMori 保护的是**已构建完成**的 Ren'Py 发行版构建。发布到 Steam 分为三个有序步骤，且顺序不可调换：

```
Ren'Py launcher: Build Distributions   →   renmori protect   →   SteamPipe upload
   (from your project source)              (encrypt game/)        (upload the folder)
```

:::danger 请勿颠倒顺序
若先执行保护，再对项目重新运行 Ren'Py 启动器的 Build Distributions，启动器会从源码重新构建，产出一份全新的**未受保护**发行版构建，此前的保护随之失效。请对启动器的输出执行保护，并且切勿将受保护的文件夹重新交给启动器处理。
:::

本指南以 Ren'Py SDK 自带的示例项目 `the_question` 及其 **market** 构建为例，因为该构建包含全部三个平台。

## 应上传哪个构建

Ren'Py 启动器可产出以下构建：

- **pc**：Windows 与 Linux
- **mac**：macOS
- **market**：一个通用包，内含 Windows（`.exe`）、macOS（`.app`）与 Linux（`.sh`）启动器，三者共享同一个 `game/`

两种方式在 Steam 上均可行：

| 方式             | 操作                                                                                        | 取舍                    |
| -------------- | ----------------------------------------------------------------------------------------- | --------------------- |
| **Market（简单）** | 保护这一个 market 文件夹；将其放入挂载到所有操作系统的**单一 depot**；按操作系统分别设置启动选项                                 | 每位玩家都会下载全部三个平台的文件     |
| **分平台（精简）**    | 分别构建 **pc** 与 **mac**，各自运行 `renmori protect`，并各自上传到**独立的 depot**（Windows / macOS / Linux） | 步骤更多，但每位玩家只下载其所在平台的文件 |

RenMori 的保护与平台无关：`renmori.rpe` 加载器运行在各操作系统上 Ren'Py 自带的 Python 之中。因此**对 market 构建运行一次 `protect`，即可同时覆盖 Windows、macOS 与 Linux**。

## 步骤 1：保护

将启动器生成的 market 压缩包解压到一个文件夹（RenMori 接收目录而非 `.zip`），然后执行：

```bash
renmori protect ./the_question-7.0-market -o ./the_question-7.0-market-protected
renmori verify  ./the_question-7.0-market-protected
```

只有 `game/` 发生变化，各平台启动器保持不变：

```
the_question-7.0-market-protected/
├─ game/
│   ├─ renmori.rmc        # all assets, encrypted
│   ├─ renmori.rpe        # runtime loader (Ren'Py loads it automatically)
│   └─ steam_appid.txt    # kept as plaintext (the Steam SDK reads it directly)
├─ lib/                   # untouched — per-platform Python runtimes
├─ renpy/                 # untouched
├─ the_question.app/      # untouched — macOS launcher
├─ the_question.exe       # untouched — Windows launcher
├─ the_question.py
├─ the_question.sh        # untouched — Linux launcher
└─ renmori-manifest.json
```

原先位于 `game/` 下的明文 `.rpa` 封包与 `.rpyc` 已不复存在，`unrpa` 与 `unrpyc` 均无可处理的对象。

## 步骤 2：通过 SteamPipe 上传

Steam **不**接收单个文件。一次构建是**一个文件夹的全部内容**，通过 SteamPipe 上传到 depot。因此：

- **请勿**上传 `.zip`
- **请勿**只上传 `renmori.rmc`
- **请**将 depot 的 `contentroot` 指向**受保护的文件夹**，由 SteamPipe 上传其中的全部内容（`game/`、`lib/`、`renpy/` 与各启动器）

`app_build_<APPID>.vdf`：

```
"appbuild"
{
  "appid"       "YOUR_APPID"
  "desc"        "the_question 1.0 (renmori protected)"
  "buildoutput" "D:\steam\output\"
  "contentroot" "D:\dists\the_question-7.0-market-protected\"
  "setlive"     ""          // upload only; set the live branch in the web UI
  "depots"
  {
    "YOUR_DEPOTID"
    {
      "FileMapping" { "LocalPath" "*"  "DepotPath" "."  "recursive" "1" }
    }
  }
}
```

```bash
steamcmd +login YOUR_ACCOUNT +run_app_build "D:\steam\app_build_YOUR_APPID.vdf" +quit
```

Steamworks 提供的 SteamPipe GUI 执行的是相同的操作，将其指向受保护的文件夹即可。

采用**分平台 depot** 时，请分别保护每个平台的构建，并为每个平台配置独立的 depot 与各自的 `contentroot`。

## 步骤 3：设置启动选项

在 Steamworks 网页后台（Installation → General Installation → Launch Options）中为每个操作系统各设置一项启动选项，指向构建内对应的启动器：

| 操作系统    | 可执行文件              |
| ------- | ------------------ |
| Windows | `the_question.exe` |
| Linux   | `the_question.sh`  |
| macOS   | `the_question.app` |

启动器引导 Ren'Py 启动后，由 `renmori.rpe` 接管资源加载并在内存中解密资源，整个过程对玩家透明。

## Steam 兼容性要点

- **请勿再叠加 Steam DRM**（DRMToolkit 可执行文件包装器）：它会改写启动器二进制文件，可能与运行时自检冲突，且其自身防护较弱，而 RenMori 已对数据层提供保护
- **Steam 叠加层（Overlay）可正常使用**：RenMori 仅挂钩 Ren'Py 的文件加载，从不进行进程或 DLL 注入，因此 Steam 叠加层工作正常
- **成就与云存档**经由 Ren'Py 的 Python API 实现，不受影响；`renmori.rmc` 是静态文件，因此 Steam 的文件校验与增量更新均正常工作
- **`steam_appid.txt`** 由 Steam SDK 在 `renpy.loader` 之外直接读取，因此 RenMori 默认将其保留为明文（`DEFAULT_KEEP_ON_DISK`）；将其保留在发行版构建中并无风险，其他由外部读取的文件可通过 `renmori.toml` 中的 `keep_on_disk` 添加，详见 [配置文件](https://renmori.mewbaka.cn/cli/configuration.md)

## 检查清单

- [ ] 已在 Ren'Py 启动器中从源码构建（Build Distributions）
- [ ] 已对解压后的构建文件夹运行 `renmori protect`
- [ ] `renmori verify` 已通过
- [ ] SteamPipe 的 `contentroot` 指向**受保护的文件夹**，而非 `.zip`
- [ ] 已按操作系统设置启动选项（`the_question.exe` / `.sh` / `.app`）
- [ ] 未叠加 Steam DRM 包装器
- [ ] **未**对受保护的文件夹重新运行启动器
