Mount & Blade II: Bannerlord Modding Documentation

repository·master·Indexed 42 days ago

https://github.com/bannerlord-modding/documentation

Comprehensive documentation for modding Mount & Blade II: Bannerlord, featuring C# API references, Gauntlet UI development, and XML data definitions. Includes detailed guides on localization using TextObject, implementing MissionBehaviour for mission logic and agent lifecycle management, and configuring std_module_strings_xml.xml for multi-language support.

Tokens
38.8K
Snippets
90
Records
194
Agent score
54%

What's inside Bannerlord Modding

  1. Explore Bannerlord Modding Documentation

    master

    The Bannerlord Modding documentation repository provides a comprehensive set of resources for developers looking to create mods for Mount & Blade II: Bannerlord. The documentation is organized into four primary pillars:

    1. Introduction to Modding: Foundational knowledge covering getting started, folder structures, and advanced concepts.
    2. Tutorials: Step-by-step guides ranging from basic C# modding to UI modification (Gauntlet) and packing mods for Vortex.
    3. C# API Documentation: Detailed technical references for the game's internal systems, including CampaignSystem, Core, Engine, InputSystem, MountAndBlade, and more.
    4. Gauntlet Documentation: Specific guidance for working with the game's UI framework, covering Widgets, ViewModels, Screens, and XML-based Movies and Brushes.
    5. XML Documentation: Reference for the game's data-driven XML schemas, such as Items, Cultures, NPCCharacters, and SubModule definitions.
  2. What is a MissionView and when to use it

    master

    A MissionView is a specialized type of MissionBehaviour designed primarily for the client side. They are used to handle interactions with UI elements and client-side logic during a mission.

    Common use cases include:

    • Handling player movement via inputs.
    • Managing UI-driven requests (e.g., checking if a player is requesting to spawn as a bot).
    • Interacting with any mission-specific UI components.
  3. What is MissionBehaviour and how to use it

    master

    A MissionBehaviour is a class used to control a Mission. It allows you to implement logic such as spawning Agents, adding mission boundaries, or managing mission-specific rules.

    A single mission can have multiple MissionBehaviour instances attached to it.

    Key inheritance notes:

    • MissionLogic is a type of MissionBehaviour.
    • MissionViews is a type of MissionBehaviour.

    When creating your own behaviour, it is recommended to set the BehaviourType property to Other unless you are implementing mission logic.

  4. Use Harmony for runtime patching

    master

    Harmony is a library used to alter the functionality of applications and DLLs during runtime. These changes are non-permanent and only persist for the current session.

    Common usage patterns include:

    • Prefix: Execute code before a specific method runs.
    • Postfix: Execute code after a specific method runs.
    • Replacement: Replace an entire method with your own implementation.
    • IL Patching: Patch individual IL instructions (use with caution).

    Warning: Using Harmony can cause incompatibilities between mods if multiple mods attempt to patch the same method(s). Use it only when absolutely necessary.

  5. Load order requirements for overwriting Gauntlet UIs

    master

    If your mod intends to overwrite Gauntlet UIs from official TaleWorlds modules, your mod MUST be loaded BEFORE the official module.

    To ensure this high priority in the load order, it is highly recommended to:

    1. Use a prefix like an underscore (e.g., _ExampleUIMod) in your module name/ID.
    2. Do not use <DependedModules/> for these types of mods, as dependencies can affect load order positioning.
  6. Generate unique String IDs for TextObjects

    master

    String IDs are global. If two different modules use the same stringID, they will conflict. To avoid this, do not use semantically meaningful keys (like {=my_mod_text}). Instead, use short, random alphanumeric codes.

    Best Practices:

    • Use 8-digit alphanumeric codes (e.g., {=zmR6sT03}).
    • Avoid long IDs as they can impact performance.
    • You can generate these using services like random.org.