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
This commit is contained in:
Claude
2025-11-23 17:44:58 +00:00
parent 79718c0acd
commit 8cdd933d35
2 changed files with 23 additions and 11 deletions

View File

@@ -1,29 +1,37 @@
using HarmonyLib; using HarmonyLib;
using System.Reflection; using System.Reflection;
using UnityEngine; using System.Collections.Generic;
public class BotCommandMod : IModApi public class BotCommandMod : IModApi
{ {
public void InitMod(Mod _modInstance) public void InitMod(Mod _modInstance)
{ {
Debug.Log("[BotCommandMod] Loading"); Log.Out("[BotCommandMod] Loading");
var harmony = new Harmony("com.botcommand.mod"); var harmony = new Harmony("com.botcommand.mod");
harmony.PatchAll(Assembly.GetExecutingAssembly()); harmony.PatchAll(Assembly.GetExecutingAssembly());
Debug.Log("[BotCommandMod] Loaded"); Log.Out("[BotCommandMod] Loaded");
} }
} }
[HarmonyPatch(typeof(NetPackageChat))] [HarmonyPatch(typeof(ConsoleCmdAbstract))]
[HarmonyPatch("ProcessPackage")] [HarmonyPatch("getCommands")]
public class ChatCommandPatch 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<int> _recipientEntityIds)
{ {
ClientInfo cInfo = ConnectionManager.Instance.Clients.ForEntityId(__instance.Sender); if (_msg != null && _msg.StartsWith("/bot "))
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 false;
} }
return true; return true;

View File

@@ -5,6 +5,10 @@ GAME_DIR="${GAME_DIR:-$HOME/.local/share/7DaysToDie}"
mcs -target:library \ mcs -target:library \
-out:BotCommandMod.dll \ -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/Assembly-CSharp.dll" \
-r:"$GAME_DIR/7DaysToDie_Data/Managed/UnityEngine.CoreModule.dll" \ -r:"$GAME_DIR/7DaysToDie_Data/Managed/UnityEngine.CoreModule.dll" \
-r:"$GAME_DIR/7DaysToDie_Data/Managed/0Harmony.dll" \ -r:"$GAME_DIR/7DaysToDie_Data/Managed/0Harmony.dll" \