Adjust Mod timing, temporarily disable Mod.

调整Mod时序,暂时禁用Mod。
This commit is contained in:
Cold-Mint 2024-07-28 10:09:44 +08:00
parent d95515fdb7
commit f4660fe581
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
8 changed files with 49 additions and 34 deletions

View File

@ -55,6 +55,7 @@ data/*
#### Custom feature
- **disableVersionIsolation** Disable version isolation.
- **enableMod** Experimental feature, the game loads dll files and pck files in the mod directory when the mod is enabled. Due to the isolation of AssemblyLoadContext, the main game content cannot be accessed from within the Mod for the time being.
## Configuring Openobserve

View File

@ -53,6 +53,7 @@ data/*
#### 風習特徴
- **disableVersionIsolation** 版孤立を無効化する。
- **enableMod**実験的な機能、modが有効になっている場合、ゲームはmodディレクトリにdllファイルとpckファイルをロードします。assemblyloadcontextが分離されているため、当面の間、mod内からメインゲームのコンテンツにアクセスすることはできません。
## はいちOpenobserve

View File

@ -55,6 +55,7 @@ data/*
#### 自定义特性
- **disableVersionIsolation** 禁用版本隔离。
- **enableMod** 实验性功能当启用模组时游戏会在mod目录加载dll文件和pck文件。由于AssemblyLoadContext的隔离性暂时不能从Mod内访问主游戏内容。
## 配置Openobserve

View File

@ -16,12 +16,7 @@ collision_mask = 34
script = ExtResource("1_w8hhv")
ProjectileScenes = [ExtResource("2_34250")]
FiringIntervalAsMillisecond = 300
_recoil = null
Id = "staff_of_the_undead"
UniqueName = null
UniqueDescription = null
_minContactInjury = null
_maxContactInjury = null
[node name="DamageArea2D" type="Area2D" parent="."]
collision_layer = 8

View File

@ -132,6 +132,16 @@ public static class Config
return !OS.HasFeature("disableVersionIsolation");
}
/// <summary>
/// <para>Whether to enable Mod</para>
/// <para>是否启用Mod</para>
/// </summary>
/// <returns></returns>
public static bool EnableMod()
{
return OS.HasFeature("enableMod");
}
/// <summary>
/// <para>Default version name</para>
/// <para>默认的版本名称</para>

View File

@ -96,7 +96,7 @@ public partial class SplashScreenLoader : UiLoaderTemplate
{
Directory.CreateDirectory(dataPath);
}
//Registered camp
//注册阵营
var defaultCamp = new Camp(Config.CampId.Default)
@ -118,13 +118,18 @@ public partial class SplashScreenLoader : UiLoaderTemplate
LootRegister.StaticRegister();
//Load mod
//加载模组
var modPath = Config.GetModDataDirectory();
if (!Directory.Exists(modPath))
if (Config.EnableMod())
{
Directory.CreateDirectory(modPath);
var modPath = Config.GetModDataDirectory();
if (!Directory.Exists(modPath))
{
Directory.CreateDirectory(modPath);
}
ModLoader.Init();
ModLoader.LoadAllMods(modPath);
}
ModLoader.Init();
ModLoader.LoadAllMods(modPath);
await Task.Delay(TimeSpan.FromMilliseconds(500));
await Task.CompletedTask;
}
}

View File

@ -7,8 +7,8 @@
public interface IModLifecycleHandler
{
/// <summary>
/// <para>When loading the Mod</para>
/// <para>当加载Mod时</para>
/// <para>When the game loads the Mod</para>
/// <para>当游戏加载Mod时</para>
/// </summary>
void OnModLoaded();
}

View File

@ -4,7 +4,6 @@ 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;
@ -124,6 +123,7 @@ public class ModLoader
dllPath, Config.ModLifecycleHandlerName);
return;
}
var constructor = modLifecycleHandlerType.GetConstructor(Type.EmptyTypes);
if (constructor == null)
{
@ -134,6 +134,7 @@ public class ModLoader
dllPath);
return;
}
var modLifecycleHandler = constructor.Invoke(null);
var methodInfo =
modLifecycleHandlerType.GetMethod(nameof(IModLifecycleHandler.OnModLoaded));
@ -144,6 +145,7 @@ public class ModLoader
LogCat.UploadFormat, dllPath);
return;
}
methodInfo.Invoke(modLifecycleHandler, null);
}
catch (ArgumentNullException argumentNullException)
@ -269,6 +271,25 @@ public class ModLoader
throw new NullReferenceException("mod manifest is null:" + modManifestPath);
}
var pckList = modManifest.PckList;
if (pckList == null || pckList.Length == 0)
{
//The module does not contain a pck file.
//模组不包含pck文件。
LogCat.LogWarningWithFormat("mod_not_contain_pck", LogCat.LogLabel.ModLoader, LogCat.UploadFormat,
modFolderPath);
}
else
{
//The module contains pck files, load the pck files.
//包含pck文件加载pck文件。
foreach (var pck in pckList)
{
var pckPath = Path.GetFullPath(pck, modFolderPath);
LoadPckFile(pckPath);
}
}
var dllList = modManifest.DllList;
if (dllList == null || dllList.Length == 0)
{
@ -287,25 +308,6 @@ public class ModLoader
LoadDllFile(dllPath);
}
}
var pakList = modManifest.PckList;
if (pakList == null || pakList.Length == 0)
{
//The module does not contain a pck file.
//模组不包含pck文件。
LogCat.LogWarningWithFormat("mod_not_contain_pck", LogCat.LogLabel.ModLoader, LogCat.UploadFormat,
modFolderPath);
}
else
{
//The module contains pck files, load the pck files.
//包含pck文件加载pck文件。
foreach (var pak in pakList)
{
var pakPath = Path.GetFullPath(pak, modFolderPath);
LoadPckFile(pakPath);
}
}
}
/// <summary>