Skip to content

Commit e048bc8

Browse files
committed
双版本 Tomlet 兼容
1 parent 4aa0937 commit e048bc8

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

mod/Core.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using MelonLoader;
2-
using Tomlet;
32

43
namespace WorldLink;
54

@@ -17,7 +16,7 @@ public override void OnInitializeMelon()
1716
{
1817
// Load config
1918
LoggerInstance.Msg("Loading config...");
20-
Config = TomletMain.To<Config>(File.ReadAllText("WorldLink.toml"));
19+
Config = TomletShim.To<Config>(File.ReadAllText("WorldLink.toml"));
2120

2221
LoggerInstance.Msg("Patching...");
2322
Futari.OnBeforePatch();

mod/TomletShim.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Reflection;
2+
using Tomlet;
3+
4+
namespace WorldLink;
5+
6+
public static class TomletShim
7+
{
8+
private static MethodInfo methodOld;
9+
private static MethodInfo methodNew;
10+
11+
static TomletShim()
12+
{
13+
var method = typeof(TomletMain).GetMethods(BindingFlags.Public | BindingFlags.Static).Where(it => it.Name == "To");
14+
methodOld = method.FirstOrDefault(it => it.GetParameters().Length == 1 && it.GetParameters()[0].ParameterType == typeof(string));
15+
methodNew = method.FirstOrDefault(it => it.GetParameters().Length == 2 && it.GetParameters()[0].ParameterType == typeof(string));
16+
}
17+
18+
public static T To<T>(string toml)
19+
{
20+
if (methodOld != null)
21+
{
22+
return (T)methodOld.MakeGenericMethod(typeof(T)).Invoke(null, [toml]);
23+
}
24+
if (methodNew != null)
25+
{
26+
return (T)methodNew.MakeGenericMethod(typeof(T)).Invoke(null, [toml, null]);
27+
}
28+
throw new InvalidOperationException("Tomlet methods not found. Please ensure you are using the correct version of Tomlet.");
29+
}
30+
}

0 commit comments

Comments
 (0)