骑砍2霸主MOD开发(2)-基础开发环境搭建

2024-04-09 20:52

本文主要是介绍骑砍2霸主MOD开发(2)-基础开发环境搭建,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一.骑砍2霸主程序架构

二.骑砍2霸主C#接口层代码查看

     1.C#反编译工具dnspy下载:

     2.骑砍2霸主游戏引擎接口查看:

     例如IMBAgent interface接口:

#调用TaleWorlds.Native.dll中的函数
[EngineMethod("get_movement_flags", false)]
uint GetMovementFlags(UIntPtr agentPointer);// Token: 0x060015BE RID: 5566
[EngineMethod("set_movement_flags", false)]
void SetMovementFlags(UIntPtr agentPointer, Agent.MovementControlFlag value);// Token: 0x060015BF RID: 5567
[EngineMethod("get_movement_input_vector", false)]
Vec2 GetMovementInputVector(UIntPtr agentPointer);// Token: 0x060015C0 RID: 5568
[EngineMethod("set_movement_input_vector", false)]
void SetMovementInputVector(UIntPtr agentPointer, Vec2 value);// Token: 0x060015C1 RID: 5569
[EngineMethod("get_collision_capsule", false)]
void GetCollisionCapsule(UIntPtr agentPointer, ref CapsuleData value);

三.MOD下C#代码编译调试

     1.VisualStudio下载并创建csproj配置文件:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><Version>0.0.1</Version>#指定VS编译依赖.net6框架<TargetFramework>net6</TargetFramework><Platforms>x64</Platforms>#指定游戏安装目录<GameFolder>D:\work\Steam\steamapps\common\Mount &amp; Blade II Bannerlord</GameFolder><GameBinariesFolder Condition="Exists('$(GameFolder)\bin\Win64_Shipping_Client\Bannerlord.exe')">Win64_Shipping_Client</GameBinariesFolder><GameBinariesFolder Condition="Exists('$(GameFolder)\bin\Gaming.Desktop.x64_Shipping_Client\Bannerlord.exe')">Gaming.Desktop.x64_Shipping_Client</GameBinariesFolder>#指定输出dll名称,输出dll路径<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath><AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath><AssemblyName>NativeTest</AssemblyName><OutputPath>D:\work\Steam\steamapps\common\Mount &amp; Blade II Bannerlord\Modules\NativeTest\bin\Win64_Shipping_Client</OutputPath></PropertyGroup>#指定使用C#接口<ItemGroup><Reference Include="$(GameFolder)\bin\$(GameBinariesFolder)\Newtonsoft.Json.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference><Reference Include="$(GameFolder)\bin\$(GameBinariesFolder)\TaleWorlds.*.dll" Exclude="$(GameFolder)\bin\$(GameBinariesFolder)\TaleWorlds.Native.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference><Reference Include="$(GameFolder)\Modules\Native\bin\$(GameBinariesFolder)\*.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference><Reference Include="$(GameFolder)\Modules\SandBox\bin\$(GameBinariesFolder)\*.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference><Reference Include="$(GameFolder)\Modules\SandBoxCore\bin\$(GameBinariesFolder)\*.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference><Reference Include="$(GameFolder)\Modules\StoryMode\bin\$(GameBinariesFolder)\*.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference><Reference Include="$(GameFolder)\Modules\CustomBattle\bin\$(GameBinariesFolder)\*.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference><Reference Include="$(GameFolder)\Modules\BirthAndDeath\bin\$(GameBinariesFolder)\*.dll"><HintPath>%(Identity)</HintPath><Private>False</Private></Reference></ItemGroup>
</Project>

    2.生成/生成解决方案编译cs文件为dll

四.MOD文件目录结构

    1.sub_module.xml

       MOD启动配置文件,配置XML

<?xml version="1.0" encoding="utf-8"?>
<Module>#对应MOD启动器下显示MOD的版本和名称<Id value = "NativeTest"/><Name value = "NativeTest"/><Version value = "v1.2.9.36960"/><DependedModules><DependedModule Id="Native" DependentVersion="v1.2.9" Optional="false"/><DependedModule Id="SandBoxCore" DependentVersion="v1.2.9" Optional="false"/></DependedModules>#对应module_data下武器装备,军团属性的xml文件<Xmls><XmlNode>                <XmlName id="Items" path="items"/><IncludedGameTypes><GameType value = "Campaign"/><GameType value = "CampaignStoryMode"/><GameType value = "CustomGame"/><GameType value = "EditorGame"/></IncludedGameTypes></XmlNode></Xmls>#对应bin\Win64_Shipping_Client下的MOD自定义DLL<SubModules><SubModule><Name value="NativeTestSubModule" /><DLLName value="NativeTest.dll" /><SubModuleClassType value="NativeTest.NativeTest" />		<Tags><Tag key="DedicatedServerType" value ="none" /></Tags></SubModule></SubModules>
</Module>

    2.module_data

       存放武器装备,军队兵种,场景物等相关配置xml文件.

       SandBoxCore\ModuleData\items:存放装备的配置文件

       SandBoxCore\ModuleData'spnpccharacters:存放军团兵种的配置文件

五.MOD启动C#接口

    通过实现MBSubModuleBase中的接口实现各个阶段的重写


// Token: 0x06001AAB RID: 6827 RVA: 0x0005D190 File Offset: 0x0005B390
protected internal virtual void OnSubModuleLoad()
{
}// Token: 0x06001AAC RID: 6828 RVA: 0x0005D192 File Offset: 0x0005B392
protected internal virtual void OnSubModuleUnloaded()
{
}// Token: 0x06001AAD RID: 6829 RVA: 0x0005D194 File Offset: 0x0005B394
protected internal virtual void OnBeforeInitialModuleScreenSetAsRoot()
{
}// Token: 0x06001AAE RID: 6830 RVA: 0x0005D196 File Offset: 0x0005B396
public virtual void OnConfigChanged()
{
}// Token: 0x06001AAF RID: 6831 RVA: 0x0005D198 File Offset: 0x0005B398
protected internal virtual void OnGameStart(Game game, IGameStarter gameStarterObject)
{
}

六.日志收集&诊断

     cs文件范例:

using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using TaleWorlds.Core;
using TaleWorlds.Engine;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;
using TaleWorlds.MountAndBlade.Source.Missions.Handlers;namespace NativeTest
{public class NativeTest : MBSubModuleBase{#调用windows弹框MessageBox[DllImport("user32.dll", EntryPoint = "MessageBoxA")]public static extern int MsgBox(int hWnd, string msg, string caption, int type);protected override void OnSubModuleLoad(){base.OnSubModuleLoad();MsgBox(0, "OnSubModuleLoad", "msg box", 0x30);}public override void OnGameLoaded(Game game, object initializerObject){base.OnGameLoaded(game, initializerObject);MsgBox(0, "OnGameLoaded", "msg box", 0x30);}public override void OnNewGameCreated(Game game, object initializerObject){base.OnNewGameCreated(game, initializerObject);MsgBox(0, "OnNewGameCreated", "msg box", 0x30);}public override void OnBeforeMissionBehaviorInitialize(Mission mission){base.OnBeforeMissionBehaviorInitialize(mission);try{var val = 0;var rst = 8 / val;throw new Exception("Dummy exception for stack trace");InformationManager.DisplayMessage(new InformationMessage("on mission behavior initialize"));mission.AddMissionBehavior(new FlyMissionTimer());}catch (Exception ex){string stackTrace = new StackTrace(ex, true).ToString();File.WriteAllText("../../Modules/NativeTest/crash_log.txt", stackTrace);}}}

这篇关于骑砍2霸主MOD开发(2)-基础开发环境搭建的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/889185

相关文章

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

Go语言开发实现查询IP信息的MCP服务器

《Go语言开发实现查询IP信息的MCP服务器》随着MCP的快速普及和广泛应用,MCP服务器也层出不穷,本文将详细介绍如何在Go语言中使用go-mcp库来开发一个查询IP信息的MCP... 目录前言mcp-ip-geo 服务器目录结构说明查询 IP 信息功能实现工具实现工具管理查询单个 IP 信息工具的实现服

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

Python如何自动生成环境依赖包requirements

《Python如何自动生成环境依赖包requirements》:本文主要介绍Python如何自动生成环境依赖包requirements问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录生成当前 python 环境 安装的所有依赖包1、命令2、常见问题只生成当前 项目 的所有依赖包1、

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

Spring Shell 命令行实现交互式Shell应用开发

《SpringShell命令行实现交互式Shell应用开发》本文主要介绍了SpringShell命令行实现交互式Shell应用开发,能够帮助开发者快速构建功能丰富的命令行应用程序,具有一定的参考价... 目录引言一、Spring Shell概述二、创建命令类三、命令参数处理四、命令分组与帮助系统五、自定义S

Redis在windows环境下如何启动

《Redis在windows环境下如何启动》:本文主要介绍Redis在windows环境下如何启动的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Redis在Windows环境下启动1.在redis的安装目录下2.输入·redis-server.exe

Pytest多环境切换的常见方法介绍

《Pytest多环境切换的常见方法介绍》Pytest作为自动化测试的主力框架,如何实现本地、测试、预发、生产环境的灵活切换,本文总结了通过pytest框架实现自由环境切换的几种方法,大家可以根据需要进... 目录1.pytest-base-url2.hooks函数3.yml和fixture结论你是否也遇到过

mysql的基础语句和外键查询及其语句详解(推荐)

《mysql的基础语句和外键查询及其语句详解(推荐)》:本文主要介绍mysql的基础语句和外键查询及其语句详解(推荐),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋... 目录一、mysql 基础语句1. 数据库操作 创建数据库2. 表操作 创建表3. CRUD 操作二、外键

Python基础语法中defaultdict的使用小结

《Python基础语法中defaultdict的使用小结》Python的defaultdict是collections模块中提供的一种特殊的字典类型,它与普通的字典(dict)有着相似的功能,本文主要... 目录示例1示例2python的defaultdict是collections模块中提供的一种特殊的字