> 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 作为示例。我们将创建的这个模组会让玩家通过麦克风或键盘与角色对话，而角色甚至可以选择并执行动作。唇形同步有点棘手，取决于游戏如何实现它。如果你正在为 Unreal Engine 游戏制作模组，请查看我们在 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。如果你还没有这样做，请按照以下步骤进行 [这里](/api-docs/zh/cha-jian-yu-ji-cheng/modding-framework.md)。\
\
Cyber Engine Tweaks 可在 nexusmods 上找到。

### **模组创建**

为了理解模组创建流程，让我们回顾一下我为《赛博朋克 2077》模组所采取的步骤。你可以在该模组的 Source Code 文件夹中找到我使用的代码。\
\
我们从“main.cc”开始，它包含“main.exe”的逻辑。基本上，“main.cc”会根据用户方法文件 user\_method\_of\_input.txt 中的值捕获玩家来自麦克风的音频或来自键盘的文本输入，而该文件是由 Lua 模组设置的；main.cc 会在“get\_response\_config\_example.txt”文件中查找角色 ID、API 密钥、可用动作等详细信息，而这些同样由 Lua 模组设置。随后，它会将这些信息发送给 Convai。之后，它会播放玩家正在互动的角色所生成对话的音频，并将对话和动作都保存到一个文本文件中。这个文本文件之后会用于显示字幕并选择合适的游戏内动作。此外，你甚至可以从 convai sdk 获取用于精确唇形同步的 lipsync 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.
