2025-11-23 17:15:09 +00:00
|
|
|
using HarmonyLib;
|
|
|
|
|
using System.Reflection;
|
2025-11-23 17:41:37 +00:00
|
|
|
using UnityEngine;
|
2025-11-23 17:15:09 +00:00
|
|
|
|
|
|
|
|
public class BotCommandMod : IModApi
|
|
|
|
|
{
|
|
|
|
|
public void InitMod(Mod _modInstance)
|
|
|
|
|
{
|
2025-11-23 17:41:37 +00:00
|
|
|
Debug.Log("[BotCommandMod] Loading");
|
2025-11-23 17:15:09 +00:00
|
|
|
var harmony = new Harmony("com.botcommand.mod");
|
|
|
|
|
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
2025-11-23 17:41:37 +00:00
|
|
|
Debug.Log("[BotCommandMod] Loaded");
|
2025-11-23 17:15:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-23 17:41:37 +00:00
|
|
|
[HarmonyPatch(typeof(NetPackageChat))]
|
|
|
|
|
[HarmonyPatch("ProcessPackage")]
|
2025-11-23 17:15:09 +00:00
|
|
|
public class ChatCommandPatch
|
|
|
|
|
{
|
2025-11-23 17:41:37 +00:00
|
|
|
static bool Prefix(NetPackageChat __instance, World _world)
|
2025-11-23 17:15:09 +00:00
|
|
|
{
|
2025-11-23 17:41:37 +00:00
|
|
|
if (__instance.Message != null && __instance.Message.StartsWith("/bot "))
|
2025-11-23 17:15:09 +00:00
|
|
|
{
|
2025-11-23 17:41:37 +00:00
|
|
|
ClientInfo cInfo = ConnectionManager.Instance.Clients.ForEntityId(__instance.Sender);
|
|
|
|
|
string playerName = cInfo != null ? cInfo.playerName : "Unknown";
|
|
|
|
|
Debug.Log($"[Bot] {playerName}: {__instance.Message}");
|
2025-11-23 17:15:09 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|