Unity Il2cpp 游戲的 Mod 制作教程01 - 環(huán)境搭建
BepInEx 框架介紹
BepInEx 工作原理基于 Dll 劫持。Unity游戲啟動(dòng)時(shí),總是會(huì)調(diào)用?winhttp.dll?
來(lái)檢查文件信息或網(wǎng)絡(luò)連接,默認(rèn)情況下首先在當(dāng)前文件夾中查找dll,然后在系統(tǒng)目錄中查找。BepInEx 通過(guò)修改偽造的 winhttp.dll
,來(lái) hook kernel32.dll
中的?GetProcAddress,
CloseHandle?
等函數(shù)來(lái)進(jìn)行一系列操作,比如獲取 mono_thread_current
,mono_thread_set_main
,mono_runtime_invoke
等函數(shù)的地址,加載 BepInEx Core 等,而后 BepInEx 再去加載 plugins 下的 mod dll。
BepInEx 版本的選擇:
對(duì)于Unity Mono游戲,請(qǐng)考慮使用BepInEx 5
對(duì)于Il2Cpp游戲,請(qǐng)考慮使用最新版本的 Bleeding Edge 版本(6.0.0-be.577+)
BepInEx下載以及安裝
對(duì)于 Il2Cpp 游戲,我們需要 Bleeding Edge 版本的BepInEx,官網(wǎng)地址為:
https://builds.bepinex.dev/projects/bepinex_be
在頁(yè)面下方 Artifacts 中找到需要的版本下載即可。
安裝過(guò)程可以參考官網(wǎng)上的安裝文檔:
https://docs.bepinex.dev/master/articles/user_guide/installation/index.html
基本過(guò)程為:
下載正確版本的BepInEx,解壓到游戲根目錄中
運(yùn)行一次游戲以生成配置文件
首次在Il2Cpp游戲中運(yùn)行可能需要一些時(shí)間,因?yàn)樗枰捎糜?modding 的文件。
配置BepInEx
所有配置選項(xiàng)都記錄在**
BepInEx/config/BepInEx.cfg
** 文件中。
安裝依賴(lài)組件
.NET 6 or newer?SDK
使用?dotnet?安裝?https://dotnet.microsoft.com/download
IDE,以下都可
Visual Studio Community (需要注意使用.NET6 可能需要最新 VS 2022)
JetBrains Rider
Visual Studio Code
開(kāi)啟控制臺(tái)
為了更方便地 debugging,可以在 BepInEx/config/BepInEx.cfg 中開(kāi)啟 BepInEx console
安裝 BepInEx plugin 模板
BepInEx 提供了 plugin 的工程模板,可以使用下面的命令安裝(需要翻墻)
如果安裝成功會(huì)得到如下的模板列表
