From beb39d9ce11745341b75aee664454d674fb348d3 Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Fri, 4 Oct 2024 15:49:23 +0800
Subject: [PATCH 1/7] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E6=94=AF=E6=8C=81Economi?=
=?UTF-8?q?c=E6=95=B0=E6=8D=AE=E6=9F=A5=E8=AF=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/CaiBot/CaiBot.csproj | 5 +++++
src/CaiBot/EconomicSupport.cs | 23 +++++++++++++++++++++++
src/Economics.Skill/Skill.cs | 2 +-
3 files changed, 29 insertions(+), 1 deletion(-)
create mode 100644 src/CaiBot/EconomicSupport.cs
diff --git a/src/CaiBot/CaiBot.csproj b/src/CaiBot/CaiBot.csproj
index e181d9a9..2a1967d4 100644
--- a/src/CaiBot/CaiBot.csproj
+++ b/src/CaiBot/CaiBot.csproj
@@ -14,5 +14,10 @@
SixLabors.ImageSharp.dll
+
+
+
+
+
diff --git a/src/CaiBot/EconomicSupport.cs b/src/CaiBot/EconomicSupport.cs
new file mode 100644
index 00000000..f3d34a7e
--- /dev/null
+++ b/src/CaiBot/EconomicSupport.cs
@@ -0,0 +1,23 @@
+using TShockAPI;
+
+namespace CaiBot;
+
+public static class EconomicSupport
+{
+ public static string GetCoins(TSPlayer player)
+ {
+ return $"拥有{EconomicsAPI.Economics.Setting.CurrencyName}:{EconomicsAPI.Economics.CurrencyManager.GetUserCurrency(player.Name)}";
+ }
+
+ public static string GetLevelName(TSPlayer player)
+ {
+ return $"当前职业: {Economics.RPG.RPG.PlayerLevelManager.GetLevel(player.Name)}";
+ }
+
+ public static string GetSkill(TSPlayer player)
+ {
+ var skill = Economics.Skill.Skill.PlayerSKillManager.QuerySkill(player.Name);
+ var msg = skill.Any() ? string.Join(",", skill.Select(x => x.Skill == null ? "无效技能" : x.Skill.Name)) : "无";
+ return $"绑定技能:{msg}";
+ }
+}
\ No newline at end of file
diff --git a/src/Economics.Skill/Skill.cs b/src/Economics.Skill/Skill.cs
index 471350f1..fb48fd81 100644
--- a/src/Economics.Skill/Skill.cs
+++ b/src/Economics.Skill/Skill.cs
@@ -30,7 +30,7 @@ public class Skill : TerrariaPlugin
internal static Config Config { get; set; } = new();
- internal static PlayerSKillManager PlayerSKillManager { get; set; } = null!;
+ public static PlayerSKillManager PlayerSKillManager { get; set; } = null!;
public Skill(Main game) : base(game)
{
From 529ff108df03e90f8cc19c768f16a38d3f69bff5 Mon Sep 17 00:00:00 2001
From: xuyuwtu <3082068984@qq.com>
Date: Fri, 4 Oct 2024 17:24:48 +0800
Subject: [PATCH 2/7] =?UTF-8?q?CaiBot=E6=B7=BB=E5=8A=A0=E5=AF=B9Economics?=
=?UTF-8?q?=E7=9A=84=E5=BC=B1=E5=BC=95=E7=94=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/CaiBot/EconomicSupport.cs | 159 +++++++++++++++++++++++++++++++++-
src/CaiBot/Plugin.cs | 1 +
2 files changed, 156 insertions(+), 4 deletions(-)
diff --git a/src/CaiBot/EconomicSupport.cs b/src/CaiBot/EconomicSupport.cs
index f3d34a7e..27515426 100644
--- a/src/CaiBot/EconomicSupport.cs
+++ b/src/CaiBot/EconomicSupport.cs
@@ -1,23 +1,174 @@
-using TShockAPI;
+using System.Reflection.Emit;
+using System.Runtime.CompilerServices;
+using TerrariaApi.Server;
+using TShockAPI;
namespace CaiBot;
public static class EconomicSupport
{
+ private static bool GetCoinsSupport = false;
+ private static bool GetLevelNameSupport = false;
+ private static bool GetSkillSupport = false;
+ private static Func GetCurrencyNameFunc = null!;
+ private static Func GetUserCurrencyFunc = null!;
+ private static Func GetLevelNameFunc = null!;
+ private static Func QuerySkillFunc = null!;
+ public static void Init()
+ {
+ var pluginContainer = ServerApi.Plugins.Where(x => x.Plugin.Name == "EconomicsAPI").FirstOrDefault();
+ if (pluginContainer is not null)
+ {
+ do
+ {
+ var economicsType = pluginContainer.Plugin.GetType();
+
+ var settingProperty = economicsType.GetProperty(nameof(EconomicsAPI.Economics.Setting));
+ if (settingProperty is null)
+ {
+ break;
+ }
+ var currencyNameField = settingProperty.PropertyType.GetField(nameof(EconomicsAPI.Economics.Setting.CurrencyName));
+ if (currencyNameField is null)
+ {
+ break;
+ }
+
+ var func = new DynamicMethod("GetCurrencyName", typeof(string), Type.EmptyTypes);
+ var iL = func.GetILGenerator();
+ iL.Emit(OpCodes.Call, settingProperty.GetMethod!);
+ iL.Emit(OpCodes.Ldfld, currencyNameField);
+ iL.Emit(OpCodes.Ret);
+ GetCurrencyNameFunc = func.CreateDelegate>();
+ var currencyManagerProperty = economicsType.GetProperty(nameof(EconomicsAPI.Economics.CurrencyManager));
+ if (currencyManagerProperty is null)
+ {
+ break;
+ }
+ var paramTypes = new Type[] { typeof(string) };
+ var getUserCurrencyMethod = currencyManagerProperty.PropertyType.GetMethod(nameof(EconomicsAPI.Economics.CurrencyManager.GetUserCurrency), paramTypes);
+ if (getUserCurrencyMethod is null)
+ {
+ break;
+ }
+ func = new DynamicMethod("GetUserCurrency", typeof(long), paramTypes);
+ iL = func.GetILGenerator();
+ iL.Emit(OpCodes.Call, currencyManagerProperty.GetMethod!);
+ iL.Emit(OpCodes.Ldarg_0);
+ iL.Emit(OpCodes.Callvirt, getUserCurrencyMethod);
+ iL.Emit(OpCodes.Ret);
+ GetUserCurrencyFunc = func.CreateDelegate>();
+
+ GetCoinsSupport = true;
+ } while (false);
+ }
+
+ pluginContainer = ServerApi.Plugins.Where(x => x.Plugin.Name == "Economics.RPG").FirstOrDefault();
+ if (pluginContainer is not null)
+ {
+ do
+ {
+ var economicsRPGType = pluginContainer.Plugin.GetType();
+
+ var playerLevelManagerProperty = economicsRPGType.GetProperty(nameof(Economics.RPG.RPG.PlayerLevelManager));
+ if (playerLevelManagerProperty is null)
+ {
+ break;
+ }
+ var paramTypes = new Type[] { typeof(string) };
+ var getLevelMethod = playerLevelManagerProperty.PropertyType.GetMethod(nameof(Economics.RPG.RPG.PlayerLevelManager.GetLevel), paramTypes);
+ if (getLevelMethod is null)
+ {
+ break;
+ }
+ var nameProperty = getLevelMethod.ReturnType.GetProperty(nameof(Economics.RPG.Model.Level.Name));
+ if (nameProperty is null)
+ {
+ break;
+ }
+ var func = new DynamicMethod("GetLevelName", typeof(long), paramTypes);
+ var iL = func.GetILGenerator();
+ iL.Emit(OpCodes.Call, playerLevelManagerProperty.GetMethod!);
+ iL.Emit(OpCodes.Ldarg_0);
+ iL.Emit(OpCodes.Callvirt, getLevelMethod);
+ iL.Emit(OpCodes.Callvirt, nameProperty.GetMethod!);
+ iL.Emit(OpCodes.Ret);
+ GetLevelNameFunc = func.CreateDelegate>();
+
+ GetLevelNameSupport = true;
+ }
+ while (false);
+ }
+
+ pluginContainer = ServerApi.Plugins.Where(x => x.Plugin.Name == "Economics.Skill").FirstOrDefault();
+ if (pluginContainer is not null)
+ {
+ do
+ {
+ var economicsSkillType = pluginContainer.Plugin.GetType();
+
+ var playerSKillManagerProperty = economicsSkillType.GetProperty(nameof(Economics.Skill.Skill.PlayerSKillManager));
+ if (playerSKillManagerProperty is null)
+ {
+ break;
+ }
+ var paramTypes = new Type[] { typeof(string) };
+ var getLevelMethod = playerSKillManagerProperty.PropertyType.GetMethod(nameof(Economics.Skill.Skill.PlayerSKillManager.QuerySkill), paramTypes);
+ if (getLevelMethod is null)
+ {
+ break;
+ }
+ var func = new DynamicMethod("QuerySkill", typeof(object), paramTypes);
+ var iL = func.GetILGenerator();
+ iL.Emit(OpCodes.Call, playerSKillManagerProperty.GetMethod!);
+ iL.Emit(OpCodes.Ldarg_0);
+ iL.Emit(OpCodes.Callvirt, getLevelMethod);
+ iL.Emit(OpCodes.Ret);
+ QuerySkillFunc = func.CreateDelegate>();
+
+ GetSkillSupport = true;
+ }
+ while (false);
+ }
+ }
+
+ public static bool IsSupported(string feature)
+ {
+ return feature switch
+ {
+ nameof(GetCoins) => GetCoinsSupport,
+ nameof(GetLevelName) => GetLevelNameSupport,
+ nameof(GetSkill) => GetSkillSupport,
+ _ => false,
+ };
+ }
+
public static string GetCoins(TSPlayer player)
{
+ ThrowIfNotSupported();
return $"拥有{EconomicsAPI.Economics.Setting.CurrencyName}:{EconomicsAPI.Economics.CurrencyManager.GetUserCurrency(player.Name)}";
}
public static string GetLevelName(TSPlayer player)
{
- return $"当前职业: {Economics.RPG.RPG.PlayerLevelManager.GetLevel(player.Name)}";
+ ThrowIfNotSupported();
+ return $"当前职业: {Economics.RPG.RPG.PlayerLevelManager.GetLevel(player.Name).Name}";
}
public static string GetSkill(TSPlayer player)
{
- var skill = Economics.Skill.Skill.PlayerSKillManager.QuerySkill(player.Name);
- var msg = skill.Any() ? string.Join(",", skill.Select(x => x.Skill == null ? "无效技能" : x.Skill.Name)) : "无";
+ ThrowIfNotSupported();
+ dynamic obj = QuerySkillFunc(player.Name);
+ IEnumerable skill = Enumerable.Cast(obj);
+ var msg = skill.Any() ? string.Join(',', Enumerable.Select(skill, new Func(obj => obj.Skill is null ? "无效技能" : (string)obj.Skill.Name))) : "无";
return $"绑定技能:{msg}";
}
+
+ private static void ThrowIfNotSupported([CallerMemberName] string memberName = "")
+ {
+ if (!IsSupported(memberName))
+ {
+ throw new NotSupportedException(memberName);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/CaiBot/Plugin.cs b/src/CaiBot/Plugin.cs
index 48e866d8..845a7e86 100644
--- a/src/CaiBot/Plugin.cs
+++ b/src/CaiBot/Plugin.cs
@@ -150,6 +150,7 @@ await WebSocket.ConnectAsync(new Uri("ws://api.terraria.ink:22334/bot/" + Config
}
}
});
+ EconomicSupport.Init();
}
private void GenCode(EventArgs args)
From 3ecb96a07f15b176aaa52a3aa74ce08ae8fa38e2 Mon Sep 17 00:00:00 2001
From: xuyuwtu <3082068984@qq.com>
Date: Fri, 4 Oct 2024 17:37:52 +0800
Subject: [PATCH 3/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?=
=?UTF-8?q?=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/CaiBot/EconomicSupport.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/CaiBot/EconomicSupport.cs b/src/CaiBot/EconomicSupport.cs
index 27515426..0171bc5e 100644
--- a/src/CaiBot/EconomicSupport.cs
+++ b/src/CaiBot/EconomicSupport.cs
@@ -86,7 +86,7 @@ public static void Init()
{
break;
}
- var func = new DynamicMethod("GetLevelName", typeof(long), paramTypes);
+ var func = new DynamicMethod("GetLevelName", typeof(string), paramTypes);
var iL = func.GetILGenerator();
iL.Emit(OpCodes.Call, playerLevelManagerProperty.GetMethod!);
iL.Emit(OpCodes.Ldarg_0);
@@ -146,13 +146,13 @@ public static bool IsSupported(string feature)
public static string GetCoins(TSPlayer player)
{
ThrowIfNotSupported();
- return $"拥有{EconomicsAPI.Economics.Setting.CurrencyName}:{EconomicsAPI.Economics.CurrencyManager.GetUserCurrency(player.Name)}";
+ return $"拥有{GetCurrencyNameFunc()}:{GetUserCurrencyFunc(player.Name)}";
}
public static string GetLevelName(TSPlayer player)
{
ThrowIfNotSupported();
- return $"当前职业: {Economics.RPG.RPG.PlayerLevelManager.GetLevel(player.Name).Name}";
+ return $"当前职业: {GetLevelNameFunc(player.Name)}";
}
public static string GetSkill(TSPlayer player)
From 7488ccea1c22dfe5bad31eb6a8d7964b8ab117b7 Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Fri, 4 Oct 2024 20:15:21 +0800
Subject: [PATCH 4/7] =?UTF-8?q?=E6=96=B0=E5=A2=9EEconomic=E6=9F=A5?=
=?UTF-8?q?=E8=AF=A2=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/CaiBot/EconomicData.cs | 31 +++++++++++++++++++++++++++
src/CaiBot/EconomicSupport.cs | 39 +++++++++++++++++-----------------
src/CaiBot/MessageHandler.cs | 2 ++
src/CaiBot/Plugin.cs | 40 +++++++++++++++++++++--------------
src/Economics.Skill/Skill.cs | 2 +-
5 files changed, 78 insertions(+), 36 deletions(-)
create mode 100644 src/CaiBot/EconomicData.cs
diff --git a/src/CaiBot/EconomicData.cs b/src/CaiBot/EconomicData.cs
new file mode 100644
index 00000000..90c2925d
--- /dev/null
+++ b/src/CaiBot/EconomicData.cs
@@ -0,0 +1,31 @@
+using System.Text.Json.Serialization;
+
+namespace CaiBot;
+
+public class EconomicData
+{
+ [JsonPropertyOrder(1)]
+ public string Coins = "";
+ [JsonPropertyOrder(2)]
+ public string LevelName = "";
+ [JsonPropertyOrder(3)]
+ public string Skill = "";
+
+ public static EconomicData GetEconomicData(string name)
+ {
+ EconomicData economicData = new();
+ if (EconomicSupport.GetCoinsSupport)
+ {
+ economicData.Coins = EconomicSupport.GetCoins(name);
+ }
+ if (EconomicSupport.GetLevelNameSupport)
+ {
+ economicData.LevelName = EconomicSupport.GetLevelName(name);
+ }
+ if (EconomicSupport.GetSkillSupport)
+ {
+ economicData.Skill = EconomicSupport.GetSkill(name);
+ }
+ return economicData;
+ }
+}
\ No newline at end of file
diff --git a/src/CaiBot/EconomicSupport.cs b/src/CaiBot/EconomicSupport.cs
index 0171bc5e..39052bca 100644
--- a/src/CaiBot/EconomicSupport.cs
+++ b/src/CaiBot/EconomicSupport.cs
@@ -7,13 +7,13 @@ namespace CaiBot;
public static class EconomicSupport
{
- private static bool GetCoinsSupport = false;
- private static bool GetLevelNameSupport = false;
- private static bool GetSkillSupport = false;
- private static Func GetCurrencyNameFunc = null!;
- private static Func GetUserCurrencyFunc = null!;
- private static Func GetLevelNameFunc = null!;
- private static Func QuerySkillFunc = null!;
+ public static bool GetCoinsSupport = false;
+ public static bool GetLevelNameSupport = false;
+ public static bool GetSkillSupport = false;
+ private static Func _getCurrencyNameFunc = null!;
+ private static Func _getUserCurrencyFunc = null!;
+ private static Func _getLevelNameFunc = null!;
+ private static Func _querySkillFunc = null!;
public static void Init()
{
var pluginContainer = ServerApi.Plugins.Where(x => x.Plugin.Name == "EconomicsAPI").FirstOrDefault();
@@ -39,7 +39,7 @@ public static void Init()
iL.Emit(OpCodes.Call, settingProperty.GetMethod!);
iL.Emit(OpCodes.Ldfld, currencyNameField);
iL.Emit(OpCodes.Ret);
- GetCurrencyNameFunc = func.CreateDelegate>();
+ _getCurrencyNameFunc = func.CreateDelegate>();
var currencyManagerProperty = economicsType.GetProperty(nameof(EconomicsAPI.Economics.CurrencyManager));
if (currencyManagerProperty is null)
{
@@ -57,7 +57,7 @@ public static void Init()
iL.Emit(OpCodes.Ldarg_0);
iL.Emit(OpCodes.Callvirt, getUserCurrencyMethod);
iL.Emit(OpCodes.Ret);
- GetUserCurrencyFunc = func.CreateDelegate>();
+ _getUserCurrencyFunc = func.CreateDelegate>();
GetCoinsSupport = true;
} while (false);
@@ -93,7 +93,7 @@ public static void Init()
iL.Emit(OpCodes.Callvirt, getLevelMethod);
iL.Emit(OpCodes.Callvirt, nameProperty.GetMethod!);
iL.Emit(OpCodes.Ret);
- GetLevelNameFunc = func.CreateDelegate>();
+ _getLevelNameFunc = func.CreateDelegate>();
GetLevelNameSupport = true;
}
@@ -124,7 +124,7 @@ public static void Init()
iL.Emit(OpCodes.Ldarg_0);
iL.Emit(OpCodes.Callvirt, getLevelMethod);
iL.Emit(OpCodes.Ret);
- QuerySkillFunc = func.CreateDelegate>();
+ _querySkillFunc = func.CreateDelegate>();
GetSkillSupport = true;
}
@@ -143,25 +143,26 @@ public static bool IsSupported(string feature)
};
}
- public static string GetCoins(TSPlayer player)
+ public static string GetCoins(string name)
{
ThrowIfNotSupported();
- return $"拥有{GetCurrencyNameFunc()}:{GetUserCurrencyFunc(player.Name)}";
+ return $"{_getCurrencyNameFunc()}:{_getUserCurrencyFunc(name)}";
}
- public static string GetLevelName(TSPlayer player)
+ public static string GetLevelName(string name)
{
ThrowIfNotSupported();
- return $"当前职业: {GetLevelNameFunc(player.Name)}";
+ var levelName = _getLevelNameFunc(name);
+ return $"职业:{(string.IsNullOrEmpty(levelName)?"无":levelName)}";
}
- public static string GetSkill(TSPlayer player)
+ public static string GetSkill(string name)
{
ThrowIfNotSupported();
- dynamic obj = QuerySkillFunc(player.Name);
+ var obj = _querySkillFunc(name);
IEnumerable skill = Enumerable.Cast(obj);
- var msg = skill.Any() ? string.Join(',', Enumerable.Select(skill, new Func(obj => obj.Skill is null ? "无效技能" : (string)obj.Skill.Name))) : "无";
- return $"绑定技能:{msg}";
+ var msg = skill.Any() ? string.Join(',', Enumerable.Select(skill, obj => obj.Skill is null ? "无效技能" : (string)obj.Skill.Name)) : "无";
+ return $"技能:{msg}";
}
private static void ThrowIfNotSupported([CallerMemberName] string memberName = "")
diff --git a/src/CaiBot/MessageHandler.cs b/src/CaiBot/MessageHandler.cs
index 50122f93..64d70b83 100644
--- a/src/CaiBot/MessageHandler.cs
+++ b/src/CaiBot/MessageHandler.cs
@@ -482,6 +482,7 @@ public static async Task HandleMessageAsync(string receivedData)
{ "inventory", itemList },
{ "buffs", buffs },
{ "enhances", enhance },
+ { "economic", EconomicData.GetEconomicData(plr.name) },
{ "group", (long) jsonObject["group"]! }
};
await SendDateAsync(JsonConvert.SerializeObject(result));
@@ -578,6 +579,7 @@ public static async Task HandleMessageAsync(string receivedData)
{ "inventory", itemList },
{ "buffs", buffs },
{ "enhances", enhance },
+ { "economic", EconomicData.GetEconomicData(acc.Name) },
{ "group", (long) jsonObject["group"]! }
};
await SendDateAsync(JsonConvert.SerializeObject(result));
diff --git a/src/CaiBot/Plugin.cs b/src/CaiBot/Plugin.cs
index 845a7e86..91d5f36a 100644
--- a/src/CaiBot/Plugin.cs
+++ b/src/CaiBot/Plugin.cs
@@ -1,5 +1,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using Rests;
using System.Net;
using System.Net.WebSockets;
using System.Reflection;
@@ -29,7 +30,8 @@ public Plugin(Main game) : base(game)
public static int InitCode = -1;
public static ClientWebSocket WebSocket = new();
-
+ public static Task WebSocketTask = Task.CompletedTask;
+ public static readonly CancellationTokenSource TokenSource = new ();
public Task WsTask;
public Task HeartBeat;
@@ -53,6 +55,7 @@ public Plugin(Main game) : base(game)
public override void Initialize()
{
+ // Commands.ChatCommands.Add(new Command( TestCommand,"test"));
Config.Read();
AppDomain.CurrentDomain.AssemblyResolve += this.CurrentDomain_AssemblyResolve;
On.OTAPI.Hooks.MessageBuffer.InvokeGetData += this.MessageBuffer_InvokeGetData;
@@ -127,7 +130,7 @@ await WebSocket.ConnectAsync(new Uri("ws://api.terraria.ink:22334/bot/" + Config
await Task.Delay(5000);
}
- });
+ },TokenSource.Token);
this.HeartBeat = Task.Run(async () =>
{
while (true)
@@ -149,10 +152,26 @@ await WebSocket.ConnectAsync(new Uri("ws://api.terraria.ink:22334/bot/" + Config
TShock.Log.ConsoleInfo("[CaiBot]心跳包发送失败!");
}
}
- });
+ },TokenSource.Token);
EconomicSupport.Init();
}
-
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ AppDomain.CurrentDomain.AssemblyResolve -= this.CurrentDomain_AssemblyResolve;
+ On.OTAPI.Hooks.MessageBuffer.InvokeGetData -= this.MessageBuffer_InvokeGetData;
+ ServerApi.Hooks.NetGetData.Deregister(this, Login.OnGetData);
+ ServerApi.Hooks.GamePostInitialize.Deregister(this, this.GenCode);
+ if (!WebSocketTask.IsCompleted)
+ {
+ TokenSource.Cancel();
+ TokenSource.Dispose();
+ }
+ }
+ base.Dispose(disposing);
+ }
private void GenCode(EventArgs args)
{
if (!string.IsNullOrEmpty(Config.config.Token))
@@ -199,16 +218,5 @@ private bool MessageBuffer_InvokeGetData(On.OTAPI.Hooks.MessageBuffer.orig_Invok
return orig(instance, ref packetId, ref readOffset, ref start, ref length, ref messageType, maxPackets);
}
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- AppDomain.CurrentDomain.AssemblyResolve -= this.CurrentDomain_AssemblyResolve;
- On.OTAPI.Hooks.MessageBuffer.InvokeGetData -= this.MessageBuffer_InvokeGetData;
- ServerApi.Hooks.NetGetData.Deregister(this, Login.OnGetData);
- ServerApi.Hooks.GamePostInitialize.Deregister(this, this.GenCode);
- }
-
- base.Dispose(disposing);
- }
+
}
\ No newline at end of file
diff --git a/src/Economics.Skill/Skill.cs b/src/Economics.Skill/Skill.cs
index fb48fd81..471350f1 100644
--- a/src/Economics.Skill/Skill.cs
+++ b/src/Economics.Skill/Skill.cs
@@ -30,7 +30,7 @@ public class Skill : TerrariaPlugin
internal static Config Config { get; set; } = new();
- public static PlayerSKillManager PlayerSKillManager { get; set; } = null!;
+ internal static PlayerSKillManager PlayerSKillManager { get; set; } = null!;
public Skill(Main game) : base(game)
{
From 03529c78a0f62c38fbd2ef8606944051eadd5d53 Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Fri, 4 Oct 2024 20:32:05 +0800
Subject: [PATCH 5/7] =?UTF-8?q?=E5=85=BC=E5=AE=B9Skill?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/CaiBot/EconomicSupport.cs | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/CaiBot/EconomicSupport.cs b/src/CaiBot/EconomicSupport.cs
index 39052bca..840378b8 100644
--- a/src/CaiBot/EconomicSupport.cs
+++ b/src/CaiBot/EconomicSupport.cs
@@ -1,4 +1,5 @@
-using System.Reflection.Emit;
+using System.Reflection;
+using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using TerrariaApi.Server;
using TShockAPI;
@@ -106,21 +107,21 @@ public static void Init()
do
{
var economicsSkillType = pluginContainer.Plugin.GetType();
-
- var playerSKillManagerProperty = economicsSkillType.GetProperty(nameof(Economics.Skill.Skill.PlayerSKillManager));
- if (playerSKillManagerProperty is null)
+ var playerSkillManagerProperty = economicsSkillType.GetProperty("PlayerSKillManager", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (playerSkillManagerProperty is null)
{
break;
}
- var paramTypes = new Type[] { typeof(string) };
- var getLevelMethod = playerSKillManagerProperty.PropertyType.GetMethod(nameof(Economics.Skill.Skill.PlayerSKillManager.QuerySkill), paramTypes);
+ var playerSkillManager = playerSkillManagerProperty.GetValue(pluginContainer.Plugin);
+ var paramTypes = new [] { typeof(string) };
+ var getLevelMethod = playerSkillManager!.GetType().GetMethod("QuerySkill", BindingFlags.NonPublic | BindingFlags.Instance, null, paramTypes, null);
if (getLevelMethod is null)
{
break;
}
var func = new DynamicMethod("QuerySkill", typeof(object), paramTypes);
var iL = func.GetILGenerator();
- iL.Emit(OpCodes.Call, playerSKillManagerProperty.GetMethod!);
+ iL.Emit(OpCodes.Call, playerSkillManagerProperty.GetMethod!);
iL.Emit(OpCodes.Ldarg_0);
iL.Emit(OpCodes.Callvirt, getLevelMethod);
iL.Emit(OpCodes.Ret);
From 419dd4492c018b5a31ee3e476e9de3b0eccdb824 Mon Sep 17 00:00:00 2001
From: Cai <13110818005@qq.com>
Date: Fri, 4 Oct 2024 20:34:42 +0800
Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88=E6=9C=AC?=
=?UTF-8?q?=E5=8F=B7=E5=92=8C=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/CaiBot/Plugin.cs | 4 ++--
src/CaiBot/README.md | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/CaiBot/Plugin.cs b/src/CaiBot/Plugin.cs
index 91d5f36a..9c35b57d 100644
--- a/src/CaiBot/Plugin.cs
+++ b/src/CaiBot/Plugin.cs
@@ -16,10 +16,10 @@ namespace CaiBot;
[ApiVersion(2, 1)]
public class Plugin : TerrariaPlugin
{
- public override string Author => "Cai,羽学";
+ public override string Author => "Cai,羽学,西江";
public override string Description => "CaiBot机器人的适配插件";
public override string Name => "CaiBotPlugin";
- public static readonly Version VersionNum = new(2024, 10, 4, 0); //日期+版本号(0,1,2...)
+ public static readonly Version VersionNum = new(2024, 10, 4, 1); //日期+版本号(0,1,2...)
public override Version Version => VersionNum;
//插件的构造器
diff --git a/src/CaiBot/README.md b/src/CaiBot/README.md
index 09e3f713..5b546bd1 100644
--- a/src/CaiBot/README.md
+++ b/src/CaiBot/README.md
@@ -13,6 +13,7 @@
## 更新日志
```
+v2024.10.4.1 查背包支持Economic数据查询
v2024.10.4.0 查背包支持更多数据
v2024.9.17.1 修复查背包模糊搜索名字显示不完整
v2024.9.16.1 远程指令日志记录执行群和执行者
From 39244e667da1eff9840c1df2bd8f914c521165b6 Mon Sep 17 00:00:00 2001
From: xuyuwtu <107350249+xuyuwtu@users.noreply.github.com>
Date: Fri, 4 Oct 2024 21:01:39 +0800
Subject: [PATCH 7/7] Update EconomicSupport.cs
---
src/CaiBot/EconomicSupport.cs | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/src/CaiBot/EconomicSupport.cs b/src/CaiBot/EconomicSupport.cs
index 840378b8..eb98d359 100644
--- a/src/CaiBot/EconomicSupport.cs
+++ b/src/CaiBot/EconomicSupport.cs
@@ -107,15 +107,14 @@ public static void Init()
do
{
var economicsSkillType = pluginContainer.Plugin.GetType();
- var playerSkillManagerProperty = economicsSkillType.GetProperty("PlayerSKillManager", BindingFlags.NonPublic | BindingFlags.Instance);
+ var playerSkillManagerProperty = economicsSkillType.GetProperty("PlayerSKillManager", BindingFlags.NonPublic | BindingFlags.Static);
if (playerSkillManagerProperty is null)
{
break;
}
- var playerSkillManager = playerSkillManagerProperty.GetValue(pluginContainer.Plugin);
- var paramTypes = new [] { typeof(string) };
- var getLevelMethod = playerSkillManager!.GetType().GetMethod("QuerySkill", BindingFlags.NonPublic | BindingFlags.Instance, null, paramTypes, null);
- if (getLevelMethod is null)
+ var paramTypes = new Type[] { typeof(string) };
+ var querySkillMethod = playerSkillManagerProperty.PropertyType.GetMethod("QuerySkill", paramTypes);
+ if (querySkillMethod is null)
{
break;
}
@@ -123,7 +122,7 @@ public static void Init()
var iL = func.GetILGenerator();
iL.Emit(OpCodes.Call, playerSkillManagerProperty.GetMethod!);
iL.Emit(OpCodes.Ldarg_0);
- iL.Emit(OpCodes.Callvirt, getLevelMethod);
+ iL.Emit(OpCodes.Callvirt, querySkillMethod);
iL.Emit(OpCodes.Ret);
_querySkillFunc = func.CreateDelegate>();
@@ -173,4 +172,4 @@ private static void ThrowIfNotSupported([CallerMemberName] string memberName = "
throw new NotSupportedException(memberName);
}
}
-}
\ No newline at end of file
+}