> 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).

# 《赛博朋克 2077》模组制作

视频链接

本指南将向你展示如何制作 Mod，将 Convai 的功能添加到任何现有或已发布的游戏中，而不受其所使用引擎的限制，只要它拥有能够创建基于逻辑的 Mod、并且能够调用脚本或可执行文件，或者至少能够写入文本文件的 Mod 制作框架即可。我们将以《赛博朋克 2077》以及它的 Mod 制作框架 Cyber Engine Tweaks 作为示例。我们将创建的 Mod 会让玩家通过麦克风或键盘与角色对话，而且角色甚至可以选择并执行动作。唇形同步有点棘手，取决于游戏如何实现它。如果你正在为 Unreal Engine 游戏制作 Mod，请查看我们在 Nexus Mods 上发布的《霍格沃茨之遗》Mod 指南，我们在那里更详细地解释了唇形同步。\
\
我们将使用以下工具：\
\
[**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 是一个框架，为 Mod 制作者提供了一种使用 Lua 编写 Mod 的方式，并可访问所有内部脚本功能；它还带有一个 UI，可用于配置你正在使用的不同 Mod，或者直接使用控制台。

### **安装**

在开始之前，你需要先设置 Convai SDK。如果你还没有这样做，请按照以下步骤进行 [这里](/api-docs/zh/cha-jian-yu-ji-cheng/modding-framework.md)。\
\
Cyber Engine Tweaks 可在 nexusmods 上找到。

### **Mod 创建**

为了理解 Mod 的创建过程，让我们逐步看看我为《赛博朋克 2077》Mod 所采取的步骤。你可以在该 Mod 的 Source Code 文件夹中找到我使用的代码。\
\
我们将从“main.cc”开始，它包含了“main.exe”的逻辑。本质上，“main.cc”会根据 user\_method\_of\_input.txt 中的值捕获玩家的麦克风音频或键盘文本输入，而该值由 lua Mod 设置。main.cc 会在“get\_response\_config\_example.txt”文件中查找角色 ID、API 密钥、可用动作等详细信息，这些同样由 lua Mod 设置。然后它会将这些信息发送给 Convai。之后，它会播放玩家正在交互的角色所产生的对话音频，并将对话和动作都保存到一个文本文件中。这个文本文件随后会被用来显示字幕并选择合适的游戏内动作。此外，你甚至可以从 convai sdk 获取唇形同步的 viseme 数据，以实现准确的唇形同步。\
\
我们使用 Cyber Engine Tweaks 来创建一个 Lua Mod，它会等待玩家按下 F6 或 F7，或者玩家为该 Mod 选择的其他热键。当按下时，Lua Mod 会找到玩家正在注视的角色，提取诸如角色名称之类的信息，并用它在 Lua 文件中定义的字典中查找角色 ID。然后，这些信息会被写入“get\_response\_config\_example.txt”文件。\
\
接下来，我们会使用 os.execute 来运行“main.exe”，但由于 Cyber Engine Tweaks 不支持 os.execute，所以我们需要查看一个名为 control.txt 的文本文件，并等待其中出现“start”；当它出现时，就运行主逻辑。玩家需要在启动游戏之前双击 main.exe。你可以查看 Source Code 文件夹中的 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》的 Mod 制作社区致敬。若没有他们宝贵的帮助、工具、指南和文档，这一切都不可能实现。非常感谢他们作出的不可或缺的贡献！


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
