From 8cdd933d35a66134c965013e67b53a5a60d8f576 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 17:44:58 +0000 Subject: [PATCH] Fix build script and API usage - Add all required assembly references (mscorlib, netstandard, System.dll, System.Core.dll) - Use GameManager.ChatMessageServer instead of NetPackageChat - Use Log.Out (proper 7DTD API) instead of Debug.Log --- Harmony/BotCommandPatch.cs | 30 +++++++++++++++++++----------- build.sh | 4 ++++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Harmony/BotCommandPatch.cs b/Harmony/BotCommandPatch.cs index 2027ac5..fb029ec 100644 --- a/Harmony/BotCommandPatch.cs +++ b/Harmony/BotCommandPatch.cs @@ -1,29 +1,37 @@ using HarmonyLib; using System.Reflection; -using UnityEngine; +using System.Collections.Generic; public class BotCommandMod : IModApi { public void InitMod(Mod _modInstance) { - Debug.Log("[BotCommandMod] Loading"); + Log.Out("[BotCommandMod] Loading"); var harmony = new Harmony("com.botcommand.mod"); harmony.PatchAll(Assembly.GetExecutingAssembly()); - Debug.Log("[BotCommandMod] Loaded"); + Log.Out("[BotCommandMod] Loaded"); } } -[HarmonyPatch(typeof(NetPackageChat))] -[HarmonyPatch("ProcessPackage")] -public class ChatCommandPatch +[HarmonyPatch(typeof(ConsoleCmdAbstract))] +[HarmonyPatch("getCommands")] +public class ChatInterceptPatch { - static bool Prefix(NetPackageChat __instance, World _world) + static void Postfix(ref string __result) { - if (__instance.Message != null && __instance.Message.StartsWith("/bot ")) + } +} + +[HarmonyPatch(typeof(GameManager))] +[HarmonyPatch("ChatMessageServer")] +public class ChatMessagePatch +{ + static bool Prefix(ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, bool _localizeMain, List _recipientEntityIds) + { + if (_msg != null && _msg.StartsWith("/bot ")) { - ClientInfo cInfo = ConnectionManager.Instance.Clients.ForEntityId(__instance.Sender); - string playerName = cInfo != null ? cInfo.playerName : "Unknown"; - Debug.Log($"[Bot] {playerName}: {__instance.Message}"); + string playerName = _cInfo != null ? _cInfo.playerName : "Server"; + Log.Out($"[Bot] {playerName}: {_msg}"); return false; } return true; diff --git a/build.sh b/build.sh index f63dc71..de53432 100755 --- a/build.sh +++ b/build.sh @@ -5,6 +5,10 @@ GAME_DIR="${GAME_DIR:-$HOME/.local/share/7DaysToDie}" mcs -target:library \ -out:BotCommandMod.dll \ + -r:"$GAME_DIR/7DaysToDie_Data/Managed/mscorlib.dll" \ + -r:"$GAME_DIR/7DaysToDie_Data/Managed/netstandard.dll" \ + -r:"$GAME_DIR/7DaysToDie_Data/Managed/System.dll" \ + -r:"$GAME_DIR/7DaysToDie_Data/Managed/System.Core.dll" \ -r:"$GAME_DIR/7DaysToDie_Data/Managed/Assembly-CSharp.dll" \ -r:"$GAME_DIR/7DaysToDie_Data/Managed/UnityEngine.CoreModule.dll" \ -r:"$GAME_DIR/7DaysToDie_Data/Managed/0Harmony.dll" \