This article breaks down the modding process for Mount & Blade II: Bannerlord into five manageable steps. We’ll cover everything from setting up your environment to exporting your finished mod, offering practical advice and personal insights to help you create your own unique additions to the game.
The first hurdle in creating your own Bannerlord 2 custom mods is preparing your development environment. This involves setting up the necessary tools and understanding the file structure of Bannerlord. It might seem daunting at first, but it’s a crucial foundation for a smooth modding experience.
Installing the Modding Tools
Bannerlord relies heavily on the game’s built-in tools and a compatible IDE (Integrated Development Environment). Visual Studio is the recommended IDE for Bannerlord modding.
- Download and Install Visual Studio: Download Visual Studio Community (it’s free!) from the official website. https://visualstudio.microsoft.com/. During installation, ensure you select the “.NET desktop development” workload. This provides the necessary compilers and libraries for working with C# code, which is the primary language for Bannerlord mods.
- Install the Bannerlord SDK: The Bannerlord SDK (Software Development Kit) is bundled with the game. You can access it through the game’s launcher in Steam. Enabling the “Developer Console” from the launcher options will also prove beneficial for testing and debugging your mod.
Understanding the Bannerlord File Structure
Familiarizing yourself with the Bannerlord directory structure is vital. Here’s a simplified breakdown:
- Modules: This folder is where all the game’s modules (including the base game and any installed mods) are located. Your mod will also reside here.
- bin/Win64_Shipping_Client: This directory contains the game’s executable (.exe) and important DLL files (Dynamic Link Libraries). You’ll need to reference these DLLs in your Visual Studio project.
- Assets: This folder houses the game’s assets, such as textures, models, and sounds. You can create your own assets or modify existing ones.
- ModuleData: Here you’ll find XML files that define various aspects of the game, like items, troops, and cultures. You’ll likely be creating and modifying these files extensively in your mod.
Pro Tip: Creating a dedicated folder structure within your mod’s directory mirroring the relevant parts of the base game’s folder structure will make organization easier. For example, if you’re adding a new item, create a “ModuleData/Items” folder within your mod to keep things tidy.
Now for the fun part: building a basic mod. This involves creating a new module, writing some code, and testing your changes in the game.
Creating a New Module
- Navigate to the “Modules” folder in your Bannerlord installation directory.
- Create a new folder for your mod. Choose a descriptive name (e.g., “MyAwesomeMod”).
- Inside your mod’s folder, create a file named “SubModule.xml.” This file tells the game about your mod.
SubModule.xml is the cornerstone of any mod, defining its name, description, and the DLLs it uses. Here’s a simple example:
Creating the DLL File
- Open Visual Studio.
- Create a new project. Select “Class Library (.NET Framework)” as the project type.
- Name the project the same as the DLL specified in your SubModule.xml file (e.g., “MyAwesomeMod”).
- Set the project’s .NET Framework version to match the one used by Bannerlord (typically .NET Framework 4.7.2).
Add references to the Bannerlord DLLs. In the Solution Explorer, right-click on “References” and select “Add Reference.” Browse to the “bin/Win64_Shipping_Client” folder in your Bannerlord installation and add references to the following DLLs (at a minimum):
- TaleWorlds.System.dll
- TaleWorlds.Core.dll
- TaleWorlds.Engine.dll
- TaleWorlds.Localization.dll
- TaleWorlds.ObjectSystem.dll
- TaleWorlds.SaveSystem.dll
First-hand Experience: Referencing the correct DLLs is crucial. If you encounter errors related to missing types or methods, double-check that you’ve added all the necessary references and that their versions match the game’s version.
Writing Some Basic Code
Let’s add some simple code to display a message when the game starts. Replace the contents of the default “Class1.cs” file (or whatever it’s named) with the following:
csharp
using TaleWorlds.System;
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
namespace MyAwesomeMod
{
public class MySubModule : MBSubModuleBase
{
protected override void OnStart( game, IStarter gameStarterObject)
{
InformationManager.DisplayMessage(new InformationMessage(“MyAwesomeMod is loaded!”));
}
}
}
Rename “Class1.cs” to “MySubModule.cs” to match the class name.
Building and Testing Your Mod
- Build your project in Visual Studio (Build -> Build Solution). This will create the DLL file in the project’s “bin/Debug” or “bin/Release” folder.
- Copy the DLL file to your mod’s folder in the “Modules” directory.
- Launch Bannerlord. In the launcher, make sure your mod is enabled.
- Start a new game or load a saved game. You should see the message “MyAwesomeMod is loaded!” displayed on the screen.
While adding new content is exciting, modifying existing content can be just as powerful. This involves understanding how to access and change the game’s data.
Accessing Data
Bannerlord uses an object-oriented system for managing game data. You can access this data using the and
classes. For example, to access a list of all items in the game, you can use the following code:
This line of code retrieves all ‘ItemObject’ instances in the game and converts them into a list.
Modifying XML Files
Many aspects of the game are defined in XML files located in the “ModuleData” folders. You can modify these files to change things like item stats, troop characteristics, and culture settings.
Important: Never directly modify the base game’s XML files. Instead, create copies of the files in your mod’s “ModuleData” folder and modify those. This ensures that your mod is compatible with future game updates.
Example: Changing Item Stats
Let’s say you want to increase the damage of a specific sword.
- Locate the XML file that defines the sword (e.g., “ModuleData/Items/swords.xml”).
- Copy the XML file to your mod’s “ModuleData/Items” folder.
- Open the copied XML file and find the entry for the sword you want to modify.
- Change the “swing_damage” or “thrust_damage” attribute to increase the damage.
- Save the XML file and launch the game to see the changes.
Here is a table presenting what you have learned.
Step | Description | Location in the Mod Folder |
---|---|---|
Create new mod folder | Making a dedicated space for your mod’s files. | Modules/YourModName/ |
SubModule.xml | Declares the mod’s core info to the game. | Modules/YourModName/SubModule.xml |
DLL creation | C# code that controls your mod’s functions. | Modules/YourModName/YourModName.dll |
XML data alteration | Adjusts game items, characters, etc., through XML files. | Modules/YourModName/ModuleData/ |
Ref Dlls in the code | Refrence important Dlls to ensure success in modding. | Modules/Bannerlord/bin/Win64_Shipping_Client/ |
Beyond the basics, there are several advanced techniques that can significantly enhance your modding capabilities.
Harmony Patching
Harmony is a powerful library that allows you to modify the game’s code without directly changing the game’s DLLs. This is done through “patches” that inject code into existing methods.
Harmony is essential for complex mods that require significant code modifications. https://harmony.pardeike.net/
Using the Developer Console
Bannerlord’s developer console is an invaluable tool for testing and debugging your mod. You can access it by pressing (tilde) in-game.
The console allows you to execute commands, spawn items, teleport, and perform other actions that can help you quickly test your mod’s functionality.
Debugging with Visual Studio
Visual Studio’s debugging capabilities can save you countless hours of frustration. You can attach the debugger to the Bannerlord process and set breakpoints in your code to step through it line by line and inspect variables.
Once you’re happy with your mod, it’s time to share it with the world.
Packaging Your Mod
To package your mod, simply zip up your mod’s folder in the “Modules” directory. Include a README file with instructions on how to install and use your mod.
Sharing on Nexus Mods
Nexus Mods is the primary platform for sharing Bannerlord mods. Create an account, upload your mod, and write a detailed description to attract users. https://www.nexusmods.com/mountandblade2bannerlord