> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/modding-framework/modding-cyberpunk-2077.md).

# 为 Cyberpunk 2077 制作 Mod

本指南将向你展示如何制作将 Convai 功能添加到 Cyberpunk 2077 的 Mod

视频链接

本指南将介绍如何制作模组，为任何已有或已发行的游戏添加 Convai 的功能。无论游戏使用哪种引擎，只要它具备能够创建基于逻辑的模组的模组框架，并且可以调用脚本或可执行文件，或者至少能够写入文本文件，就可以制作。我们将以《赛博朋克 2077》及其模组框架 Cyber Engine Tweaks 为例。制作的模组将让玩家通过麦克风或键盘与角色交谈，角色甚至还能选择并执行动作。口型同步稍微有些棘手，具体取决于游戏的实现方式。如果你正在为虚幻引擎游戏制作模组，请查看我们在 Nexus Mods 上发布的《霍格沃茨之遗》模组指南，里面对口型同步有更详细的说明。\
\
我们将使用以下工具：\
\
[**Convai SDK(C++)**](https://github.com/Conv-AI/convai-sdk-cpp) ：此代码仓库提供了一组库，可通过 gRPC 流式传输访问 Convai Character GetResponse API。\
[**Cyber Engine Tweaks**](https://www.nexusmods.com/cyberpunk2077/mods/107) ：Cyber Engine Tweaks 是一个框架，可让模组制作者使用 Lua 编写模组，并访问所有内部脚本功能。它还提供了一个 UI，用于配置你正在使用的各类模组，也可以直接使用控制台。

### **安装**

开始之前，你需要先设置 Convai SDK。如果尚未完成，请按照 [此处](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/modding-framework.md)列出的步骤进行操作。\
\
可以在 Nexus Mods 上找到 Cyber Engine Tweaks。

### **创建模组**

为了了解模组的创建流程，我们来看看我为《赛博朋克 2077》模组所采取的步骤。你可以在该模组的 Source Code 文件夹中找到我使用的代码。\
\
首先来看 main.cc，它包含了 main.exe 的逻辑。简单来说，main.cc 会根据 Lua 模组设置的 user\_method\_of\_input.txt 中的值，捕获玩家通过麦克风输入的音频或通过键盘输入的文本。main.cc 会从 get\_response\_config\_example.txt 文件中读取角色 ID、API 密钥、可用动作等信息；这些内容同样由 Lua 模组设置。然后，它会将这些信息发送给 Convai。之后，它会播放玩家正在互动的角色所生成对话的音频，并将对话和动作保存到文本文件中。稍后会用这个文本文件显示字幕并选择合适的游戏内动作。此外，你还可以从 Convai SDK 获取口型同步用的 viseme 数据，从而实现精准的口型同步。\
\
我们使用 Cyber Engine Tweaks 创建 Lua 模组，让它等待玩家按下 F6、F7，或玩家选作模组快捷键的其他按键。按键按下后，Lua 模组会找到玩家正在注视的角色，提取角色名称等信息，并根据 Lua 文件中定义的字典查找角色 ID。随后，这些信息会被写入 get\_response\_config\_example.txt 文件。\
\
接下来，我们原本会使用 os.execute 来运行 main.exe，但由于 Cyber Engine Tweaks 不支持 os.execute，因此需要检查名为 control.txt 的文本文件，并等待其中出现 start；出现后再运行主逻辑。玩家需要在启动游戏前双击 main.exe。你可以查看源代码文件夹中的 main.cc，更好地了解其运行方式。对话播放完毕后，程序执行结束。我们会解析对话文本和动作值，并将其显示为字幕。然后使用字符串匹配来检查选中了哪个动作，并执行该动作对应的 if 代码块。\
\
查看 init.lua 和 main.cc 中的代码，可以更清楚地了解整个过程。

### **社区提供的实用工具、示例和指南**

* <https://www.nexusmods.com/cyberpunk2077/articles/945>
* <https://wiki.redmodding.org/home/>
* <https://wiki.redmodding.org/cyber-engine-tweaks/>
* <https://github.com/psiberx/cp2077-cet-kit/tree/main>
* <https://github.com/WolvenKit/cet-examples/tree/main/ai-components>

### **特别鸣谢**

特别感谢《赛博朋克 2077》的模组社区。没有他们提供的宝贵帮助、工具、指南和文档，这一切都不可能实现。衷心感谢他们所做出的不可或缺的贡献！


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/modding-framework/modding-cyberpunk-2077.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
