Fix compilation errors - use correct 7DTD APIs

- Use NetPackageChat instead of non-existent ChatCommandManager
- Use Debug.Log instead of Log.Out
- Add UnityEngine namespace
This commit is contained in:
Claude
2025-11-23 17:41:37 +00:00
parent 8495249cb1
commit 79718c0acd

View File

@@ -1,26 +1,29 @@
using HarmonyLib; using HarmonyLib;
using System.Reflection; using System.Reflection;
using UnityEngine;
public class BotCommandMod : IModApi public class BotCommandMod : IModApi
{ {
public void InitMod(Mod _modInstance) public void InitMod(Mod _modInstance)
{ {
Log.Out("[BotCommandMod] Loading"); Debug.Log("[BotCommandMod] Loading");
var harmony = new Harmony("com.botcommand.mod"); var harmony = new Harmony("com.botcommand.mod");
harmony.PatchAll(Assembly.GetExecutingAssembly()); harmony.PatchAll(Assembly.GetExecutingAssembly());
Log.Out("[BotCommandMod] Loaded"); Debug.Log("[BotCommandMod] Loaded");
} }
} }
[HarmonyPatch(typeof(ChatCommandManager))] [HarmonyPatch(typeof(NetPackageChat))]
[HarmonyPatch("ExecuteCommand")] [HarmonyPatch("ProcessPackage")]
public class ChatCommandPatch public class ChatCommandPatch
{ {
static bool Prefix(string _command, ClientInfo _cInfo) static bool Prefix(NetPackageChat __instance, World _world)
{ {
if (_command != null && _command.StartsWith("/bot ")) if (__instance.Message != null && __instance.Message.StartsWith("/bot "))
{ {
Log.Out($"[Bot] {(_cInfo != null ? _cInfo.playerName : "Server")}: {_command}"); ClientInfo cInfo = ConnectionManager.Instance.Clients.ForEntityId(__instance.Sender);
string playerName = cInfo != null ? cInfo.playerName : "Unknown";
Debug.Log($"[Bot] {playerName}: {__instance.Message}");
return false; return false;
} }
return true; return true;