Unity Il2cpp 游戏的 Mod 制作教程01 - 环境搭建
BepInEx 框架介绍
BepInEx 工作原理基于 Dll 劫持。Unity游戏启动时,总是会调用 winhttp.dll
来检查文件信息或网络连接,默认情况下首先在当前文件夹中查找dll,然后在系统目录中查找。BepInEx 通过修改伪造的 winhttp.dll
,来 hook kernel32.dll
中的 GetProcAddress,
CloseHandle
等函数来进行一系列操作,比如获取 mono_thread_current
,mono_thread_set_main
,mono_runtime_invoke
等函数的地址,加载 BepInEx Core 等,而后 BepInEx 再去加载 plugins 下的 mod dll。
BepInEx 版本的选择:
对于Unity Mono游戏,请考虑使用BepInEx 5
对于Il2Cpp游戏,请考虑使用最新版本的 Bleeding Edge 版本(6.0.0-be.577+)
BepInEx下载以及安装
对于 Il2Cpp 游戏,我们需要 Bleeding Edge 版本的BepInEx,官网地址为:
https://builds.bepinex.dev/projects/bepinex_be
在页面下方 Artifacts 中找到需要的版本下载即可。
安装过程可以参考官网上的安装文档:
https://docs.bepinex.dev/master/articles/user_guide/installation/index.html
基本过程为:
下载正确版本的BepInEx,解压到游戏根目录中
运行一次游戏以生成配置文件
首次在Il2Cpp游戏中运行可能需要一些时间,因为它需要生成用于 modding 的文件。
配置BepInEx
所有配置选项都记录在**
BepInEx/config/BepInEx.cfg
** 文件中。
安装依赖组件
.NET 6 or newer SDK
使用 dotnet 安装 https://dotnet.microsoft.com/download
IDE,以下都可
Visual Studio Community (需要注意使用.NET6 可能需要最新 VS 2022)
JetBrains Rider
Visual Studio Code
开启控制台
为了更方便地 debugging,可以在 BepInEx/config/BepInEx.cfg 中开启 BepInEx console
安装 BepInEx plugin 模板
BepInEx 提供了 plugin 的工程模板,可以使用下面的命令安装(需要翻墙)
如果安装成功会得到如下的模板列表
