Unity Game Mod/Plugin Production Tutorial 01 - Installation and Use of BepInEx

Preface
This chapter introduces the installation and use of BepInEx for students who have not used BepInEx before. If you have used BepInEx before and know how to use it, you can skip this chapter directly.

BepInEx download
BepInEx's Github link https://github.com/BepInEx/BepInEx/releases

There are 3 versions in total. BepInEx_unix_5.xxx is the version used by unix-like operating systems. The tutorial is based on the windwos version (I don’t have a computer with other systems), so there is no need to download this version. BepInEx_x64_5.xxx and BepInEx_x86_5.xxx correspond to 64-bit Unity and 32-bit Unity respectively. For games that want to make plug-ins, open the root directory of the game, you can find one of the two files, UnityCrashHandler64 or UnityCrashHandler32, and select the corresponding version according to the number at the end BepInEx download.

BepInEx installation
As mentioned above, the installation of BepInEx is very simple, you only need to decompress BepInEx to the root directory of the game.

The file structure after decompression should be as follows (the parts with asterisks are BepInEx):

|-XXXGame
  |-BepInEx*
    |-core
      |-...
  |-XXXGame_Data
  |-doorstop_config.ini*
  |-UnityCrashHandler64.exe
  |-UnityPlayer.dll
  |-XXXGame.exe
  |-winhttp.dll*
If the installation is correct, start After the game, several folders should be generated under the BepInEx folder, as follows:

|-BepInEx
  |-cache //cache folder
  |-config //plugin configuration folder
  |-core //framework core folder
  |-patchers //special plugin folder
  |-plugins //regular plugin folder
  |-LogPutput .log //BepInEx log
If these folders are not generated, please reconfirm the Unity version used by the game, whether the game path contains Chinese, and whether the installation location is correct.

You may be wondering why BepInEx is successfully loaded without running any programs or injecting dlls?

This is actually because the application always uses some library files in the system directory, and when the program is loaded, it first searches for the library files in its own folder, and if it cannot be found, it goes to the system directory to search. Using this principle, UnityDoorStop embeds the logic of loading plug-ins into the winhttp.dll library, while keeping its original logic unchanged. In this way, our plug-in is loaded under the condition that the original function remains unchanged and the game program does not need to be destroyed.

Plug-in installation
This tutorial focuses on the production of conventional plug-ins. All conventional plug-ins are finally in the form of a dll file, which can be placed in the BepInEx/plugins folder. It will automatically read the plug-ins under this folder and load.

Opening the console
During the use of ordinary players, most of the cases do not need to see the console, and the player does not need to understand what is done behind the plug-in, but for the author, the console plays a very important role, as you can see here The log output by the game itself, and the plug-in can also output logs, which is convenient for us to troubleshoot errors.

After BepInEx is started once, a file named BepInEx.cfg will be generated under the BepInEx/config folder, which is the configuration file of BepInEx. Open the configuration file (advanced text editors such as VSCode and Notepad++ are recommended), under the [Logging.Console] entry, we change Enabled = false to Enabled = true, so that the display of the console is turned on, and the game is opened. See console.

BepInEx Console

If you have any questions or suggestions, you can comment in the comment area or communicate with me privately.

Guess you like

Origin blog.csdn.net/m0_69824302/article/details/127938356