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 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
{
ClientInfo cInfo = ConnectionManager.Instance.Clients.ForEntityId(__instance.Sender);
string playerName = cInfo != null ? cInfo.playerName : "Unknown";
Debug.Log($"[Bot] {playerName}: {__instance.Message}");
static bool Prefix(ClientInfo _cInfo, EChatType _type, int _senderId, string _msg, string _mainName, bool _localizeMain, List<int> _recipientEntityIds)
{
if (_msg != null && _msg.StartsWith("/bot "))
{
string playerName = _cInfo != null ? _cInfo.playerName : "Server";
Log.Out($"[Bot] {playerName}: {_msg}");
return false;
}
return true;

View File

@@ -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" \