Tutorial Other [VB.Net] How to write bannerlord mod using VB.net

Users who are viewing this thread

Because Bannerlord uses .Net framework for its gameplay functionality, we can use Visual Basic .Net if you're not fond of C# or just doesn't like curly brackets.

To start, create a VB.Net Framework Class Library project.

LbGzHo.jpg


Make sure you choose the correct .Net framework target. Bannerlord uses version 4.7.2


qb8KN4.jpg


Right click on reference and add click Browse...
Go to your bannerlord.exe location and add all Taleworlds.* dll
Click OK.

MWFwLz.jpg


After you added the Reference don't forget to set them not to be copied during compilation process as this may interfere with your mod (loading wrong assemblies) or copyright infringement

Yzif1T.jpg



Code:
Imports TaleWorlds.Core
Imports TaleWorlds.MountAndBlade

Namespace Global.MyVBProject
    Public Class MySubModule
        Inherits MBSubModuleBase

        Protected Overrides Sub OnSubModuleLoad()
            MyBase.OnSubModuleLoad()
        End Sub

        Protected Overrides Sub OnBeforeInitialModuleScreenSetAsRoot()
            MyBase.OnBeforeInitialModuleScreenSetAsRoot()
            Dim ver = System.Environment.Version
            InformationManager.ShowInquiry(New InquiryData(
                "Net Enviroment",
                $"running on version {ver}",
                True,
                False,
                "Accept",
                "",
                Sub()
                    'Environment.Exit(1)
                End Sub,
                Sub()

                End Sub))

        End Sub


    End Class

End Namespace

WZMUm3.jpg


Make sure your namespace starts with Global !
Otherwise the engine won't recognise your class Entry point (which is class you inherit with MBSubModuleBase.

Now let setup the project, debug options, and your module manifest data.
Create a new directory in Bannerlord Module in highlighted path:
And makes sure your compiled dll is located in that directory!

yzb5cC.jpg


In Modules\MyVBProject\ we create mod manifest file: SubModule.xml

XML:
<?xml version="1.0" encoding="utf-8"?>
<Module>
    <Name value="MyVBProject"/> <!-- this is your project name -->
    <Id value="MyVBProject"/>  <!-- this is your project Id, it can be unique string or just use your project name -->
    <Version value="v1.0.0"/> <!-- your project version -->
    <SingleplayerModule value="true"/>
    <MultiplayerModule value="false"/>
  <Official value="false" />
    <DependedModules/>
    <SubModules>
        <SubModule>
            <Name value="MyVBProject"/>
            <DLLName value="MyVBProject.dll"/> <!-- this is your assembly file name in bin (or dll name) -->
            <SubModuleClassType value="MyVBProject.MySubModule"/> <!-- this is your entry point!, a namespace followed by your class entry point.  if you're using VB.net MAKE SURE TO PUT GLOBAL PREFIX IN NAMESPACE, otherwise the game cannot locate it, it's VB.net quirk -->
            <Tags>
                <Tag key="DedicatedServerType" value="none" />
                <Tag key="IsNoRenderModeElement" value="false" />
            </Tags>
        </SubModule>
    </SubModules>

    <Xmls/>
</Module>


85zpxq.jpg


Now let's setup debug parameter:

Lh1c3P.jpg


Start external program: Put your TaleWorlds.MountAndBlade.Launcher.exe (NOT BANNERLORD.EXE) location here
Command line arguments: leave it empty
Working directory: The bin location where TaleWorlds.MountAndBlade.Launcher.exe resides. If you leave this blank you'll crash.

Save the VB project.

Run the program.

Make sure you load appropriate project in the launcher (MyVBProject)!

Ahck4t.jpg


If you see this screen, congrats your mod works!

B0cwTh.jpg


Remember: To every time you write Namespace, don't forget to put Global prefix like so: Namespace Global.MyVBProject

Thanks for reading, glhf programming bannerlord in VB.net


  1. Debug parameter is prone to glitch during debug, repalce Bannerlord.exe with the launcher executable.
  2. Added guide to remove unnecessary DLL copying, as this may lead to loading wrong module and copyright issue during publishing.

I think you can also write mod with F#, maybe next guide I guess :^)
 
Last edited:
Interesting, thanks for this. One thing that I'm wondering about is Harmony seems to be the go to for a lot of patching operations. Is there a way to use vb.net with it or a similar library I'm not aware of?
 
Because Bannerlord uses .Net framework for its gameplay functionality, we can use Visual Basic .Net if you're not fond of C# or just doesn't like curly brackets.

Well, you are going to have a hard time with the vast majority of other programming languages if you are not fond of curly brackets :smile:
 
Coming up next... nodejs modding, how to make javascript great again...

Kidding of course, I pass
y'know your post challenged me to create such a thing. we have our tool ready https://github.com/JavascriptNet/Javascript.Net
we can totally slap this and called it bannerlord.js on nexus or something where user can load javascript program dynamically without compiling and all that jazz, but we need to write debugger tool to make this bearable
 
Back
Top Bottom