### Start Method Declaration (C#) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.NetLauncher This snippet shows the declaration of the public static void Start method within the NetPreloader class. This method is designed to accept an array of strings as parameters, typically representing command-line arguments. ```csharp public static void Start(string[] args) ``` -------------------------------- ### Verify .NET SDK Installation Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/1_setup This command verifies if the .NET SDK is installed correctly by listing all installed SDK versions and their locations. It's a crucial step after installing the .NET SDK to ensure it's ready for use in development. ```bash dotnet --list-sdks ``` -------------------------------- ### Install BepInEx Plugin Templates Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/1_setup This command installs the official BepInEx plugin templates using the BepInEx NuGet source. This allows developers to quickly scaffold new BepInEx plugins for various BepInEx versions and game types. ```bash dotnet new -i BepInEx.Templates --nuget-source https://nuget.bepinex.dev/v3/index.json ``` -------------------------------- ### Install BepInEx Templates (Bash) Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Installs the BepInEx project templates using the .NET CLI. This command fetches the templates from the specified NuGet source, enabling the creation of new BepInEx plugin projects with a pre-configured structure. ```bash # Install BepInEx templates dotnet new -i BepInEx.Templates --nuget-source https://nuget.bepinex.dev/v3/index.json ``` -------------------------------- ### Install BepInEx on Windows Unity Mono Games Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Provides step-by-step instructions for installing BepInEx on Windows Unity Mono games. This involves extracting BepInEx to the game folder, running the game once to generate configuration files, and enabling the console for debugging. ```bash # 1. Download BepInEx_x64_6.0.0-pre.1.zip # 2. Extract to game folder (where GameName.exe is located) # 3. Folder structure should look like: GameFolder/ ├── GameName.exe ├── GameName_Data/ ├── doorstop_config.ini ├── winhttp.dll └── BepInEx/ ├── core/ ├── plugins/ └── config/ # 4. Run game once to generate config GameName.exe # 5. Enable BepInEx console for debugging # Edit BepInEx/config/BepInEx.cfg: [Logging.Console] Enabled = true # 6. Install plugins by placing DLLs in BepInEx/plugins/ # 7. Run game again - plugins will load automatically ``` -------------------------------- ### BepInEx Configuration File Example Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Illustrates the structure and common settings within the `BepInEx/config/BepInEx.cfg` file. It shows how to enable the console, set log levels, include Unity log messages, and configure preloader and chainloader behavior. ```ini [Logging.Console] ## Enables showing a console for log output. # Setting type: Boolean # Default value: false Enabled = true ## Log levels to display in the console. # Setting type: LogLevel # Default value: Fatal, Error, Warning, Message, Info LogLevels = Fatal, Error, Warning, Message, Info, Debug [Logging.Disk] ## Include unity log messages in log file output. # Setting type: Boolean # Default value: false WriteUnityLog = true [Preloader] ## Enables or disables assembly patching # Setting type: Boolean # Default value: true Enabled = true [Chainloader] ## If enabled, hides BepInEx Manager GameObject from Unity. # Setting type: Boolean # Default value: true HideManagerGameObject = true ``` -------------------------------- ### Install BepInEx on Linux (Steam) Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Guides users on installing BepInEx for Linux games on Steam. It involves extracting BepInEx to the game folder, setting execute permissions for the initialization script, and configuring Steam launch options to run the script. ```bash # 1. Extract BepInEx to game folder # 2. Set execution permissions cd "/path/to/game" chmod u+x run_bepinex.sh # 3. Open game properties in Steam # 4. Set launch options to: ./run_bepinex.sh %command% # 5. Run game through Steam # 6. Configure BepInEx in BepInEx/config/BepInEx.cfg ``` -------------------------------- ### Initialize Method Declaration Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Unity.Bootstrap Declares the Initialize method, which overrides the base class method. It takes an optional game executable path as input and is responsible for the initial setup of the BepInEx environment. ```csharp public override void Initialize(string gameExePath = null) ``` -------------------------------- ### Execute run_bepinex.sh Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/user_guide/installation/unity_mono This command executes the 'run_bepinex.sh' script, initiating BepInEx. This step is crucial for generating configuration files and log output. ```bash ./run_bepinex.sh ``` -------------------------------- ### Basic BepInEx Plugin Configuration Example Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Demonstrates how to define and use configuration entries within a BepInEx plugin. It covers binding string, int, float, and bool types, accessing their values, and listening for changes. Requires BepInEx and BepInEx.Configuration namespaces. ```csharp using BepInEx; using BepInEx.Configuration; namespace ConfigExample { [BepInPlugin("org.example.config", "Config Example", "1.0.0")] public class Plugin : BaseUnityPlugin { private ConfigEntry playerName; private ConfigEntry maxHealth; private ConfigEntry damageMultiplier; private ConfigEntry enableDebugMode; private void Awake() { // Define configuration entries playerName = Config.Bind("Player", "PlayerName", "DefaultPlayer", "The name displayed for the player"); maxHealth = Config.Bind("Player.Stats", "MaxHealth", 100, "Maximum health points (default: 100)"); damageMultiplier = Config.Bind("Gameplay", "DamageMultiplier", 1.0f, new ConfigDescription( "Multiplier for all damage values", new AcceptableValueRange(0.1f, 10.0f) )); enableDebugMode = Config.Bind("Debug", "EnableDebug", false, "Show debug information in console"); // Access values immediately Logger.LogInfo($"Player name: {playerName.Value}"); Logger.LogInfo($"Max health: {maxHealth.Value}"); if (enableDebugMode.Value) { Logger.LogDebug("Debug mode enabled"); } // Listen for config changes at runtime playerName.SettingChanged += OnPlayerNameChanged; } private void OnPlayerNameChanged(object sender, System.EventArgs e) { Logger.LogInfo($"Player name changed to: {playerName.Value}"); } } } ``` -------------------------------- ### Create .NET Framework Plugin with BepInEx Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Provides a C# example for creating a BepInEx plugin targeting .NET Framework applications. This code inherits from BasePlugin and uses the BepInEx.NetLauncher namespace, overriding the Load method for initialization. ```csharp using BepInEx; using BepInEx.NetLauncher; using BepInEx.Logging; namespace MyNetPlugin { [BepInPlugin("org.example.netplugin", "NET Framework Plugin", "1.0.0")] public class Plugin : BasePlugin { public override void Load() { Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); // .NET Framework application modifications } } } ``` -------------------------------- ### Configure dnSpy for Debugging Unity Games - C# Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/advanced/debug/plugins_dnSpy This outlines the configuration steps within dnSpy to start debugging a Unity game. It specifies the choice between 'Unity' and 'Unity (Connect)' debug engines and the parameters required for each, such as the executable path and port. ```csharp // Debug Engine: Unity or Unity (Connect) // Executable: Path to the game's executable (for Unity engine) // Timeout (s): Duration before timeout (e.g., 30) // IP Address: Leave blank (for Unity (Connect) engine) // Port: 55555 (for Unity (Connect) engine) ``` -------------------------------- ### BepInPlugin Attribute Example Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/2_plugin_start This C# code snippet illustrates the BepInPlugin attribute, which is mandatory for BepInEx to load a plugin. It specifies the plugin's unique GUID, a human-readable name, and its version number, adhering to semantic versioning. The attribute must be applied directly to the plugin class. ```csharp [BepInPlugin("org.bepinex.plugins.exampleplugin", "Example Plug-In", "1.0.0.0")] public class ExamplePlugin : BaseUnityPlugin ``` -------------------------------- ### Make run_bepinex.sh executable Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/user_guide/installation/unity_mono This command makes the 'run_bepinex.sh' script executable for Linux and macOS users. It ensures that the script can be run directly from the terminal to launch BepInEx. ```bash chmod u+x run_bepinex.sh ``` -------------------------------- ### Basic Plugin Logging with BepInEx Logger (Unity Il2Cpp) Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/3_logging Shows how to implement logging in a BepInEx plugin for Unity using the Il2Cpp backend. This example uses the `Log` class provided by `BepInEx.IL2CPP` for logging messages. ```csharp using BepInEx; using BepInEx.IL2CPP; namespace MyFirstPlugin { [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BasePlugin { public override void Load() { Log.LogInfo("This is information"); Log.LogWarning("This is a warning"); Log.LogError("This is an error"); } } } ``` -------------------------------- ### PatcherPluginInfoAttribute Constructor (C#) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Preloader.Core.Patching The PatcherPluginInfoAttribute constructor initializes a new instance of the PatcherPluginInfoAttribute class. It requires the plugin's unique GUID, a user-friendly name, and its specific version. The GUID should remain constant across versions, while the name and version can change. ```csharp public PatcherPluginInfoAttribute(string GUID, string Name, string Version) ``` -------------------------------- ### Start Coroutine with MonoBehaviour and IEnumerator (C#) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.IL2CPP.Utils This method extends MonoBehaviour to facilitate the starting of coroutines. It takes a MonoBehaviour instance and an IEnumerator as input, returning a Coroutine object that can be used to manage the execution of the coroutine. This is useful for handling asynchronous operations in Unity. ```csharp public static Coroutine StartCoroutine(this MonoBehaviour self, IEnumerator coroutine) ``` -------------------------------- ### Bind Configuration Entries in .NET Framework Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/4_configuration Provides an example of binding string and boolean configuration entries for a .NET Framework plugin using BepInEx. This code snippet covers the essential steps for defining user-configurable settings with BepInEx's configuration system. ```csharp using BepInEx; using BepInEx.NetLauncher; namespace MyFirstPlugin { [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BasePlugin { private ConfigEntry configGreeting; private ConfigEntry configDisplayGreeting; public override void Load() { configGreeting = Config.Bind("General", // The section under which the option is shown "GreetingText", // The key of the configuration option in the configuration file "Hello, world!", // The default value "A greeting text to show when the game is launched"); // Description of the option to show in the config file configDisplayGreeting = Config.Bind("General.Toggles", "DisplayGreeting", true, "Whether or not to show the greeting text"); // Test code Log.LogInfo("Hello, world!"); } } } ``` -------------------------------- ### Specify BepInEx Plugin Dependencies Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Shows how to declare plugin dependencies using the [BepInDependency] attribute in C#. This example demonstrates hard, soft, and version-specific dependencies, controlling load order and ensuring required plugins are present. ```csharp using BepInEx; namespace DependentPlugin { [BepInPlugin("org.example.dependentplugin", "Dependent Plugin", "2.0.0")] // Hard dependency - plugin won't load if this is missing [BepInDependency("com.essential.core")] // Soft dependency - plugin loads even if missing [BepInDependency("com.optional.enhancement", BepInDependency.DependencyFlags.SoftDependency)] // Version-specific dependency using node-semver syntax [BepInDependency("com.versioned.library", "~1.2.0")] // Multiple dependencies ensure proper load order [BepInDependency("com.another.required", BepInDependency.DependencyFlags.HardDependency)] public class Plugin : BaseUnityPlugin { private void Awake() { Logger.LogInfo("All dependencies loaded successfully!"); } } } ``` -------------------------------- ### Global Plugin Logger in BepInEx (.NET Framework) Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/3_logging Provides an example of a global plugin logger for .NET Framework applications using BepInEx. This approach facilitates shared logging across different classes within a plugin by exposing a static logger instance. The logger is initialized in the Load method of the BasePlugin class. ```csharp using BepInEx; using BepInEx.NetLauncher; using BepInEx.Logging; namespace MyFirstPlugin { [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BasePlugin { internal static new ManualLogSource Log; public override void Load() { Plugin.Log = base.Log; } } } // Some other class in the plugin assembly class SomeOtherAssembly { public void SomeMethod() { Plugin.Log.LogInfo("Plugin message!"); } } ``` -------------------------------- ### UnityChainloader Methods Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Unity.Bootstrap Details the methods available in the UnityChainloader class, including Initialize, InitializeLoggers, LoadPlugin, and StaticStart. ```APIDOC ## UnityChainloader Methods ### Initialize(String) **Description**: Initializes the chainloader with the game executable path. **Declaration**: `public override void Initialize(string gameExePath = null)` **Parameters**: - `System.String` `gameExePath`: The path to the game executable (optional). ### InitializeLoggers() **Description**: Initializes the loggers for the chainloader. **Declaration**: `protected override void InitializeLoggers()` ### LoadPlugin(PluginInfo, Assembly) **Description**: Loads a specific plugin. **Declaration**: `public override BaseUnityPlugin LoadPlugin(PluginInfo pluginInfo, Assembly pluginAssembly)` **Parameters**: - `PluginInfo` `pluginInfo`: Information about the plugin to load. - `System.Reflection.Assembly` `pluginAssembly`: The assembly of the plugin. **Returns**: - Type: `BaseUnityPlugin` - Description: The loaded plugin instance. ### StaticStart(String) **Description**: **Obsolete**. A method for initializing BepInEx on certain Unity versions. Do not call this method directly. **Declaration**: `[Obsolete("This method is public so that BepInEx can correctly initialize on some versions of Unity that do not respect InternalsVisibleToAttribute. DO NOT CALL", true)] public static void StaticStart(string gameExePath = null)` **Parameters**: - `System.String` `gameExePath`: The path to the game executable (optional). ``` -------------------------------- ### Initialize Unity (Il2Cpp) Plugin Project with dotnet new Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/2_plugin_start Creates a new Unity (Il2Cpp) BepInEx plugin project using the `bep6plugin_il2cpp` template. After project creation, `dotnet restore` is executed to download necessary NuGet packages and dependencies. ```bash dotnet new bep6plugin_il2cpp -n MyFirstPlugin dotnet restore MyFirstPlugin ``` -------------------------------- ### Initialize Unity (Mono) Plugin Project with dotnet new Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/2_plugin_start Creates a new Unity (Mono) BepInEx plugin project using the `bep6plugin_unitymono` template. Requires specifying the .NET Target Framework (TFM) and Unity version. After creation, `dotnet restore` is run to fetch project dependencies. ```bash dotnet new bep6plugin_unitymono -n MyFirstPlugin -T -U dotnet restore MyFirstPlugin ``` -------------------------------- ### Initialize .NET Framework Plugin Project with dotnet new Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/2_plugin_start Initializes a new BepInEx plugin project for the .NET Framework using the `bep6plugin_netfx` template. The command creates the project structure, and `dotnet restore` is then used to ensure all required libraries are available. ```bash dotnet new bep6plugin_netfx -n MyFirstPlugin dotnet restore MyFirstPlugin ``` -------------------------------- ### PatcherPluginInfoAttribute GUID Property (C#) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Preloader.Core.Patching This C# code snippet defines the public 'GUID' property of the PatcherPluginInfoAttribute class. This property stores the unique identifier for the plugin. It has a public getter and a protected setter, meaning it can be read from anywhere but only set within the class or derived classes. ```csharp public string GUID { get; protected set; } ``` -------------------------------- ### StaticStart Method Declaration (Obsolete) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Unity.Bootstrap Declares the static StaticStart method, marked as obsolete. This method was used for initializing BepInEx on certain Unity versions but should not be called directly by users. ```csharp [Obsolete("This method is public so that BepInEx can correctly initialize on some versions of Unity that do not respect InternalsVisibleToAttribute. DO NOT CALL", true)] public static void StaticStart(string gameExePath = null) ``` -------------------------------- ### PatcherPluginInfoAttribute Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Preloader.Core.Patching The PatcherPluginInfoAttribute is used to denote that a class is a patcher plugin and to specify its required metadata, such as GUID, Name, and Version. ```APIDOC ## Class PatcherPluginInfoAttribute This attribute denotes that a class is a patcher plugin, and specifies the required metadata. ### Namespace BepInEx.Preloader.Core.Patching ### Assembly BepInEx.Preloader.Core.dll ### Syntax ```csharp [AttributeUsage(AttributeTargets.Class)] public class PatcherPluginInfoAttribute : Attribute, _Attribute ``` ### Constructors #### PatcherPluginInfoAttribute(String, String, String) ##### Declaration ```csharp public PatcherPluginInfoAttribute(string GUID, string Name, string Version) ``` ##### Parameters - **GUID** (System.String) - The unique identifier of the plugin. Should not change between plugin versions. - **Name** (System.String) - The user friendly name of the plugin. Is able to be changed between versions. - **Version** (System.String) - The specific version of the plugin. ### Properties #### GUID The unique identifier of the plugin. Should not change between plugin versions. ##### Declaration ```csharp public string GUID { get; protected set; } ``` ##### Property Value - **System.String** - The GUID of the plugin. ``` -------------------------------- ### Create .NET Framework Plugin with dotnet CLI Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Initializes a BepInEx plugin project compatible with .NET Framework for non-Unity games using the 'bep6plugin_netfx' template. The command creates the project and then proceeds to restore its dependencies. ```bash dotnet new bep6plugin_netfx -n MyPlugin dotnet restore MyPlugin ``` -------------------------------- ### UnityChainloader Properties Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Unity.Bootstrap Provides information about the properties of the UnityChainloader class, including ConsoleTitle, Instance, and ManagerObject. ```APIDOC ## UnityChainloader Properties ### ConsoleTitle **Description**: Gets the console title for the chainloader. **Declaration**: `protected override string ConsoleTitle { get; }` **Property Value**: - Type: `System.String` - Description: The console title. ### Instance **Description**: Gets or sets the static instance of the UnityChainloader. **Declaration**: `public static UnityChainloader Instance { get; set; }` **Property Value**: - Type: `UnityChainloader` - Description: The static instance. ### ManagerObject **Description**: Gets the GameObject that all plugins are attached to as components. **Declaration**: `public static GameObject ManagerObject { get; }` **Property Value**: - Type: `GameObject` - Description: The manager GameObject. ``` -------------------------------- ### ManagedIl2CppEnumerator Current Property (C#) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.IL2CPP.Utils.Collections Gets the current element in the collection. This property is part of the IEnumerator interface implementation, providing access to the item the enumerator is currently at. ```csharp public object Current { get; } ``` -------------------------------- ### Create Unity Mono Plugin with dotnet CLI Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Scaffolds a new BepInEx plugin project for Unity Mono games using the 'bep6plugin_unitymono' template. It specifies the project name and target framework. `dotnet restore` is then used to download necessary dependencies. ```bash dotnet new bep6plugin_unitymono -n MyPlugin -T netstandard2.0 -U 2020.3.24 dotnet restore MyPlugin ``` -------------------------------- ### Open Wine Configuration GUI via Protontricks Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/advanced/steam_interop Launches the graphical user interface for Wine configuration using the `protontricks` utility. This is used to manage Wine settings, specifically for configuring DLL overrides for BepInEx with Proton. ```bash protontricks --gui ``` -------------------------------- ### ManualLogSource Constructor Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Logging Initializes a new instance of the ManualLogSource class with a specified name. ```APIDOC ## ManualLogSource(String) ### Description Creates a manual log source with a given name. ### Method Constructor ### Parameters #### Path Parameters - **sourceName** (string) - Required - Name of the log source. ``` -------------------------------- ### Basic BepInEx Plugin (Unity Mono) Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/2_plugin_start This C# code demonstrates the basic structure of a BepInEx plugin targeting Unity (Mono). It includes the necessary using directives, the BepInPlugin attribute for metadata, and the Plugin class inheriting from BaseUnityPlugin with an Awake method for startup logic. The Logger.LogInfo function is used for output. ```csharp using BepInEx; namespace MyFirstPlugin { [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BaseUnityPlugin { private void Awake() { // Plugin startup logic Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); } } } ``` -------------------------------- ### Build Project with dotnet CLI Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/2_plugin_start This command compiles your BepInEx plugin project using the .NET command-line interface. After running this in your project folder, the compiled plugin DLL will be generated in the 'bin/Debug/' directory, ready to be deployed to the game's 'BepInEx/plugins' folder. ```bash dotnet build ``` -------------------------------- ### Filter BepInEx Plugin by Process Name Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Demonstrates using the [BepInProcess] attribute in C# to restrict a BepInEx plugin's execution to specific game executables. This prevents the plugin from loading in unintended games when installed in a shared directory. ```csharp using BepInEx; namespace GameSpecificPlugin { [BepInPlugin("org.example.gamespecific", "Game Specific Plugin", "1.0.0")] [BepInProcess("MyGame.exe")] [BepInProcess("MyGameServer.exe")] public class Plugin : BaseUnityPlugin { private void Awake() { Logger.LogInfo("Running only in allowed processes!"); } } } ``` -------------------------------- ### Declare Assembly Patch Method - C# Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/preloader_patchers Example declaration for a patch method targeting a specific assembly. The method receives an AssemblyDefinition object for modification. It can optionally receive the filename and return a boolean indicating modification. ```csharp [TargetAssembly("Assembly-CSharp.dll")] public void PatchAssembly(AssemblyDefinition assembly) { ... } ``` -------------------------------- ### HarmonyBackendFix Initialize Method Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Preloader.RuntimeFixes Documents the static Initialize method of the HarmonyBackendFix class. This method is used to perform initialization tasks for Harmony backend fixes within the BepInEx preloader. It does not take any parameters and returns void. ```csharp public static void Initialize() ``` -------------------------------- ### IL2CPPDetourMethodPatcher Constructors Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.IL2CPP.Hook Provides information about the constructors available for the IL2CPPDetourMethodPatcher class. ```APIDOC ## IL2CPPDetourMethodPatcher(MethodBase) ### Description Constructs a new instance of method patcher. ### Method Constructor ### Parameters #### Path Parameters - **original** (System.Reflection.MethodBase) - Description: ### Request Example ```json { "original": "System.Reflection.MethodBase" } ``` ### Response #### Success Response (200) - **IL2CPPDetourMethodPatcher**: An instance of the IL2CPPDetourMethodPatcher class. ### Response Example ```json { "instance": "IL2CPPDetourMethodPatcher" } ``` ``` -------------------------------- ### Build BepInEx Plugin Project Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Compiles the BepInEx plugin project after navigating into its directory. The output DLL, typically found in `bin/Debug//`, should then be copied to the BepInEx/plugins/ folder of the target game. ```bash cd MyPlugin dotnet build ``` -------------------------------- ### Declare Type Patch Method - C# Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/preloader_patchers Example of a patch method targeting a specific type within an assembly. The method receives a TypeDefinition object for modification. The `[TargetType]` attribute specifies the assembly and the full type name. ```csharp [TargetType("Assembly-CSharp.dll", "GameNamespace.GameClass")] public void PatchAssembly(TypeDefinition type) { ... } ``` -------------------------------- ### Declare Plugin Incompatibilities with BepInIncompatibility Attribute Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Prevents a plugin from loading if specific conflicting plugins are detected. This attribute is applied at the plugin class level and takes the GUID of the incompatible plugin as an argument. It's crucial for ensuring plugin stability and avoiding runtime errors caused by conflicting functionalities. ```csharp using BepInEx; namespace ExclusivePlugin { [BepInPlugin("org.example.exclusive", "Exclusive Plugin", "1.0.0")] [BepInIncompatibility("com.conflicting.plugin")] [BepInIncompatibility("org.obsolete.oldversion")] public class Plugin : BaseUnityPlugin { private void Awake() { Logger.LogInfo("No conflicting plugins detected!"); } } } ``` -------------------------------- ### BuildInfoAttribute Constructor Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Shared Initializes a new instance of the BuildInfoAttribute class. ```APIDOC ## BuildInfoAttribute(String) ### Description Initializes a new instance of the BuildInfoAttribute class. ### Method CONSTRUCTOR ### Endpoint N/A ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```csharp // Example of attribute usage [assembly: BuildInfo("My bleeding edge build")] ``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Create Basic Unity Mono Plugin with BepInEx Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Demonstrates creating a basic BepInEx plugin for Unity Mono games. This C# code inherits from BaseUnityPlugin and uses the Awake method for initialization and logging. It requires the BepInEx.dll. ```csharp using BepInEx; using BepInEx.Logging; namespace MyFirstPlugin { [BepInPlugin("org.example.myfirstplugin", "My First Plugin", "1.0.0")] public class Plugin : BaseUnityPlugin { private void Awake() { Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); Logger.LogInfo("Initializing custom game modifications..."); } private void Update() { // Called every frame - use for runtime modifications } } } ``` -------------------------------- ### Prepare Original Method for Patching with IL2CPPDetourMethodPatcher Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.IL2CPP.Hook Prepares the original method for patching by generating a DynamicMethodDefinition. This step is crucial before applying detours or other modifications to ensure the method is in a suitable state. ```csharp public override DynamicMethodDefinition PrepareOriginal() ``` -------------------------------- ### Create Unity IL2CPP Plugin with dotnet CLI Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Generates a BepInEx plugin project for Unity IL2CPP games using the 'bep6plugin_il2cpp' template. The command creates a new project with the specified name and then restores its dependencies. ```bash dotnet new bep6plugin_il2cpp -n MyPlugin dotnet restore MyPlugin ``` -------------------------------- ### Manual Configuration File Creation in C# Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/4_configuration Illustrates how to manually create a configuration file using BepInEx's ConfigFile class in C#. This is useful for scenarios like preloader patchers or non-plugin DLLs. It shows how to instantiate ConfigFile and bind configuration entries with default values and descriptions. ```csharp // Create a new configuration file. // First argument is the path to where the configuration is saved // Second arguments specifes whether to create the file right away or whether to wait until any values are accessed/written var customFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "custom_config.cfg"), true); // You can now create configuration wrappers for it var userName = customFile.Bind("General", "UserName", "Deuce", "Name of the user"); // In plug-ins, you can still access the default configuration file var configGreeting = Config.Bind("General", "GreetingTest", "Hello, world!", "A greeting text to show when the game is launched"); ``` -------------------------------- ### Create Unity IL2CPP Plugin with BepInEx Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Illustrates how to create a BepInEx plugin for Unity IL2CPP games. This C# code inherits from BasePlugin and overrides the Load method for initialization, utilizing BepInEx.IL2CPP and BepInEx.Logging. It shows how to add custom components. ```csharp using BepInEx; using BepInEx.IL2CPP; using BepInEx.Logging; namespace MyIL2CPPPlugin { [BepInPlugin("org.example.il2cppplugin", "IL2CPP Plugin", "1.0.0")] public class Plugin : BasePlugin { public override void Load() { Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); // IL2CPP-specific initialization AddComponent(); } } } ``` -------------------------------- ### Configure Steam Launch Options for BepInEx (Linux) Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/advanced/steam_interop Sets the Steam launch option to execute the BepInEx run script before launching the game on Linux. The `%command%` placeholder is replaced by Steam with the game's actual launch command. ```bash ./run_bepinex.sh %command% ``` -------------------------------- ### Display BepInEx and Unity Version - Console Log Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/advanced/debug/plugins_dnSpy This snippet shows the output from BepInEx during game startup, which is crucial for identifying the Unity version your game is built against. This information is needed to download the correct Mono debugging package for dnSpy. ```text [Message: BepInEx] BepInEx 5.0.1.0 - [Info : BepInEx] Running under Unity v5.4.0.6710170 [Info : BepInEx] CLR runtime version: 2.0.50727.1433 ... ``` -------------------------------- ### Basic Plugin Logging with BepInEx Logger (.NET Framework/NetLauncher) Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/3_logging Illustrates logging within a BepInEx plugin for .NET Framework or NetLauncher environments. This code uses the `Log` class from `BepInEx.NetLauncher` to output log messages. ```csharp using BepInEx; using BepInEx.NetLauncher; namespace MyFirstPlugin { [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BasePlugin { public override void Load() { Log.LogInfo("This is information"); Log.LogWarning("This is a warning"); Log.LogError("This is an error"); } } } ``` -------------------------------- ### BasePlugin Load Method (C#) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.NetLauncher.Common This is an abstract method that must be implemented by all derived plugin classes. It is called by BepInEx when the plugin is loaded, and is the primary entry point for plugin initialization logic. ```csharp public abstract void Load() ``` -------------------------------- ### Instantiate IL2CPPDetourMethodPatcher with Original Method Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.IL2CPP.Hook Constructs a new instance of the IL2CPPDetourMethodPatcher. This is used to create a patcher for a specific original method that needs to be detoured or modified. ```csharp public IL2CPPDetourMethodPatcher(MethodBase original) ``` -------------------------------- ### BepInEx Unity Mono Plugin Project Configuration (.csproj) Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Defines the project settings for a BepInEx plugin targeting Unity Mono. It specifies the target framework, assembly name, version, description, and includes necessary BepInEx, Harmony, and Unity NuGet packages, along with local game assembly references. ```xml netstandard2.0 MyPlugin 1.0.0 My BepInEx Plugin true latest lib/Assembly-CSharp.dll False ``` -------------------------------- ### IL2CPPDetourMethodPatcher Methods Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.IL2CPP.Hook Details the methods available within the IL2CPPDetourMethodPatcher class. ```APIDOC ## CopyOriginal() ### Description Copies the original method definition. ### Method `public override DynamicMethodDefinition CopyOriginal()` ### Returns - **DynamicMethodDefinition**: The definition of the original method. ### Response Example ```json { "definition": "DynamicMethodDefinition" } ``` ``` ```APIDOC ## DetourTo(MethodBase) ### Description Applies a detour to the original method. ### Method `public override MethodBase DetourTo(MethodBase replacement)` ### Parameters #### Path Parameters - **replacement** (System.Reflection.MethodBase) - Description: The replacement method to detour to. ### Request Example ```json { "replacement": "System.Reflection.MethodBase" } ``` ### Returns - **System.Reflection.MethodBase**: The original method base after applying the detour. ### Response Example ```json { "originalMethod": "System.Reflection.MethodBase" } ``` ``` ```APIDOC ## PrepareOriginal() ### Description Prepares the original method for patching. ### Method `public override DynamicMethodDefinition PrepareOriginal()` ### Returns - **DynamicMethodDefinition**: The definition of the original method after preparation. ### Response Example ```json { "definition": "DynamicMethodDefinition" } ``` ``` ```APIDOC ## TryResolve(Object, PatchManager.PatcherResolverEventArgs) ### Description A handler for PatchManager.PatcherResolver that checks if a method doesn't have a body (e.g. it's icall or marked with abstract) and thus can be patched with IL2CPPDetourMethodPatcher. ### Method `public static void TryResolve(object sender, PatchManager.PatcherResolverEventArgs args)` ### Parameters #### Path Parameters - **sender** (System.Object) - Description: Not used. - **args** (PatchManager.PatcherResolverEventArgs) - Description: Patch resolver arguments. ### Request Example ```json { "sender": "System.Object", "args": "PatchManager.PatcherResolverEventArgs" } ``` ### Response #### Success Response (200) - **void**: This method does not return a value. ### Response Example ```json { "status": "success" } ``` ``` -------------------------------- ### Enable BepInEx Console Logging Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/1_setup This configuration snippet enables the console output for BepInEx logs. Modifying the `BepInEx.cfg` file with `Enabled = true` under the `[Logging.Console]` section is necessary for real-time log viewing during development. ```ini [Logging.Console] ## Enables showing a console for log output. # Setting type: Boolean # Default value: false Enabled = true ``` -------------------------------- ### Create ManualLogSource Instance (C#) Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Logging This constructor creates a new instance of the ManualLogSource class. It requires a string parameter representing the name of the log source, which is used to identify logs originating from this source. ```csharp public ManualLogSource(string sourceName) ``` -------------------------------- ### Bind Configuration Entries in Unity (Il2Cpp) Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/4_configuration Shows how to bind string and boolean configuration entries for a Unity (Il2Cpp) plugin using BepInEx. This code snippet illustrates the process of defining configuration options with sections, keys, default values, and descriptive text. ```csharp using BepInEx; using BepInEx.IL2CPP; using BepInEx.Configuration; namespace MyFirstPlugin { [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BasePlugin { private ConfigEntry configGreeting; private ConfigEntry configDisplayGreeting; public override void Load() { configGreeting = Config.Bind("General", // The section under which the option is shown "GreetingText", // The key of the configuration option in the configuration file "Hello, world!", // The default value "A greeting text to show when the game is launched"); // Description of the option to show in the config file configDisplayGreeting = Config.Bind("General.Toggles", "DisplayGreeting", true, "Whether or not to show the greeting text"); // Test code Log.LogInfo("Hello, world!"); } } } ``` -------------------------------- ### Basic Method Patching with HarmonyX (C#) Source: https://context7.com/context7/bepinex_dev_v6_0_0-pre_1/llms.txt Applies a prefix and postfix patch to the 'TakeDamage' method of 'PlayerController'. The prefix intercepts the damage, logs it, reduces it by 50%, and returns true to continue execution. The postfix logs the player's health after the damage. ```csharp using BepInEx; using HarmonyLib; namespace HarmonyExample { [BepInPlugin("org.example.harmony", "Harmony Example", "1.0.0")] public class Plugin : BaseUnityPlugin { private void Awake() { // Create Harmony instance var harmony = new Harmony("org.example.harmony"); // Apply all patches in this assembly harmony.PatchAll(); Logger.LogInfo("All patches applied successfully!"); } } // Patch class - separate from plugin class [HarmonyPatch(typeof(PlayerController), "TakeDamage")] public class PlayerController_TakeDamage_Patch { // Prefix runs before the original method static bool Prefix(PlayerController __instance, ref float damage) { // Access to instance via __instance // Modify parameters via ref Plugin.Log.LogInfo($"Player taking {damage} damage"); // Reduce damage by 50% damage *= 0.5f; // Return false to skip original method // Return true to continue to original method return true; } // Postfix runs after the original method static void Postfix(PlayerController __instance, float damage) { Plugin.Log.LogInfo($"Player health after damage: {__instance.health}"); } } } ``` -------------------------------- ### Basic BepInEx Plugin (Unity Il2Cpp/.NET Framework) Source: https://docs.bepinex.dev/v6.0.0-pre.1/articles/dev_guide/plugin_tutorial/2_plugin_start This C# code shows a basic BepInEx plugin structure for Unity (Il2Cpp) or .NET Framework. It utilizes the BasePlugin class and its Load method for plugin initialization. The Log.LogInfo function is used for logging plugin loading status. The BepInPlugin attribute is essential for BepInEx to recognize and load the plugin. ```csharp using BepInEx; using BepInEx.IL2CPP; // For Il2Cpp targets // using BepInEx.NetLauncher; // For .NET Framework targets namespace MyFirstPlugin { [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BasePlugin { public override void Load() { // Plugin startup logic Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); } } } ``` -------------------------------- ### Instantiate UnityLogSource Constructor Source: https://docs.bepinex.dev/v6.0.0-pre.1/api/BepInEx.Unity.Logging This C# code demonstrates the default constructor for the UnityLogSource class. Calling this constructor creates a new instance of the Unity log source, making it ready to be configured and used for logging within a Unity application managed by BepInEx. ```csharp public UnityLogSource() ```