ModLoader now support calling entry functions.
模组加载器现在支持调用入口函数了。
This commit is contained in:
parent
a7a5a309a2
commit
d95515fdb7
|
@ -109,3 +109,4 @@ log_dll_name,已加载{0}。,Loaded {0}.,{0}をロードしました。
|
|||
log_dll_does_not_register_lifecycle_processor,位于{0}的dll文件,未注册生命周期处理器{1}。,"The DLL file located at {0} does not register the lifecycle processor {1}.",{0}にあるDLLファイルは、ライフサイクルプロセッサ{1}を登録していません。
|
||||
log_mod_lifecycle_handler_not_implement_interface,位于{0}的dll文件,生命周期处理器未实现IModLifecycleHandler接口。,"The DLL file located at {0}, the lifecycle processor does not implement the IModLifecycleHandler interface.",{0}にあるDLLファイル、ライフサイクルプロセッサはIModLifecycleHandlerインターフェースを実装していません。
|
||||
log_dll_no_parameterless_constructor,位于{0}的dll文件,没有无参构造函数。,"The DLL file located at {0} does not have a parameterless constructor.",{0}にあるDLLファイルにはパラメータのないコンストラクタがありません。
|
||||
log_dll_type_length,位于{0}的dll文件内,共包含{1}个类型。,"The DLL file located at {0} contains a total of {1} types.",{0}にあるDLLファイルには合計{1}個のタイプが含まれています。
|
|
|
@ -34,6 +34,7 @@ radius = 172.29
|
|||
collision_layer = 64
|
||||
collision_mask = 38
|
||||
script = ExtResource("1_ubaid")
|
||||
InitWeaponRes = null
|
||||
LootListId = "test"
|
||||
metadata/CampId = "Mazoku"
|
||||
metadata/MaxHp = 50
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using System.Text;
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.utils;
|
||||
using Godot;
|
||||
|
@ -98,52 +101,50 @@ public class ModLoader
|
|||
}
|
||||
|
||||
LogCat.LogWithFormat("dll_name", LogCat.LogLabel.ModLoader, true, assemblyName);
|
||||
// if (assemblyName != Config.SolutionName)
|
||||
// {
|
||||
// //If the load is not its own Dll file.
|
||||
// //如果加载的不是自身的Dll文件.
|
||||
// }
|
||||
//If the load is not its own Dll file.
|
||||
//如果加载的不是自身的Dll文件.
|
||||
if (assemblyName == Config.SolutionName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Call the method of the entry class.
|
||||
//调用入口类的方法
|
||||
var modLifecycleHandlerFullName = assemblyName + "." + Config.ModLifecycleHandlerName;
|
||||
var modLifecycleHandlerType = assembly.GetType(modLifecycleHandlerFullName);
|
||||
var exportedTypes = assembly.GetExportedTypes();
|
||||
LogCat.LogWarningWithFormat("dll_type_length", LogCat.LogLabel.ModLoader, LogCat.UploadFormat, dllPath,
|
||||
exportedTypes.Length);
|
||||
var modLifecycleHandlerType =
|
||||
FindTypeInTypeArray(exportedTypes, Config.ModLifecycleHandlerName);
|
||||
if (modLifecycleHandlerType == null)
|
||||
{
|
||||
//The module does not register a lifecycle processor.
|
||||
//模组没有注册生命周期处理器。
|
||||
LogCat.LogWarningWithFormat("dll_does_not_register_lifecycle_processor", LogCat.LogLabel.ModLoader,
|
||||
LogCat.UploadFormat,
|
||||
dllPath, modLifecycleHandlerFullName);
|
||||
dllPath, Config.ModLifecycleHandlerName);
|
||||
return;
|
||||
}
|
||||
else
|
||||
var constructor = modLifecycleHandlerType.GetConstructor(Type.EmptyTypes);
|
||||
if (constructor == null)
|
||||
{
|
||||
var constructor = modLifecycleHandlerType.GetConstructor(Type.EmptyTypes);
|
||||
if (constructor == null)
|
||||
{
|
||||
//No parameterless constructor found.
|
||||
//未找到无参构造方法。
|
||||
LogCat.LogWarningWithFormat("dll_no_parameterless_constructor", LogCat.LogLabel.ModLoader,
|
||||
LogCat.UploadFormat,
|
||||
dllPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
var modLifecycleHandler = constructor.Invoke(null) as IModLifecycleHandler;
|
||||
if (modLifecycleHandler == null)
|
||||
{
|
||||
//The ModLifecycleHandler class in the dll does not yet implement the IModLifecycleHandler interface.
|
||||
//dll内的ModLifecycleHandler类尚未实现IModLifecycleHandler接口。
|
||||
LogCat.LogWarningWithFormat("mod_lifecycle_handler_not_implement_interface",
|
||||
LogCat.LogLabel.ModLoader,
|
||||
LogCat.UploadFormat, dllPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
modLifecycleHandler.OnModLoaded();
|
||||
}
|
||||
}
|
||||
//No parameterless constructor found.
|
||||
//未找到无参构造方法。
|
||||
LogCat.LogWarningWithFormat("dll_no_parameterless_constructor", LogCat.LogLabel.ModLoader,
|
||||
LogCat.UploadFormat,
|
||||
dllPath);
|
||||
return;
|
||||
}
|
||||
var modLifecycleHandler = constructor.Invoke(null);
|
||||
var methodInfo =
|
||||
modLifecycleHandlerType.GetMethod(nameof(IModLifecycleHandler.OnModLoaded));
|
||||
if (methodInfo == null)
|
||||
{
|
||||
LogCat.LogWarningWithFormat("mod_lifecycle_handler_not_implement_interface",
|
||||
LogCat.LogLabel.ModLoader,
|
||||
LogCat.UploadFormat, dllPath);
|
||||
return;
|
||||
}
|
||||
methodInfo.Invoke(modLifecycleHandler, null);
|
||||
}
|
||||
catch (ArgumentNullException argumentNullException)
|
||||
{
|
||||
|
@ -184,6 +185,25 @@ public class ModLoader
|
|||
LogCat.LogWithFormat("load_dll_success", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>Find a specific type by class name</para>
|
||||
/// <para>通过类名查找特定的类型</para>
|
||||
/// </summary>
|
||||
/// <param name="types">
|
||||
///<para>TypeArray</para>
|
||||
///<para>类型数组</para>
|
||||
/// </param>
|
||||
/// <param name="className">
|
||||
///<para>ClassName</para>
|
||||
///<para>类名</para>
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static Type? FindTypeInTypeArray(Type[] types, string className)
|
||||
{
|
||||
return types.FirstOrDefault(type => type.Name == className);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Load all mods</para>
|
||||
/// <para>加载全部模组</para>
|
||||
|
|
Loading…
Reference in New Issue
Block a user