Add reflection to discover available Chat methods

This commit is contained in:
Claude
2025-11-23 19:20:52 +00:00
parent 1ee6f45f70
commit 41517582a7

View File

@@ -1,30 +1,27 @@
using HarmonyLib; using HarmonyLib;
using System.Reflection; using System.Reflection;
using System; using System;
using System.Linq;
public class BotCommandMod : IModApi public class BotCommandMod : IModApi
{ {
public void InitMod(Mod _modInstance) public void InitMod(Mod _modInstance)
{ {
Console.WriteLine("[BotCommandMod] Loading"); Console.WriteLine("[BotCommandMod] Loading");
var harmony = new Harmony("com.botcommand.mod");
harmony.PatchAll(Assembly.GetExecutingAssembly()); // List all GameManager methods containing "Chat"
var gmType = typeof(GameManager);
Console.WriteLine("[BotCommandMod] GameManager methods with 'Chat':");
foreach (var method in gmType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static))
{
if (method.Name.Contains("Chat"))
{
var parameters = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name + " " + p.Name));
Console.WriteLine($" {method.Name}({parameters})");
}
}
Console.WriteLine("[BotCommandMod] Loaded"); Console.WriteLine("[BotCommandMod] Loaded");
} }
} }
[HarmonyPatch(typeof(ChatCommandManager), "ProcessCommand")]
public class ChatCommandPatch
{
static bool Prefix(ChatCommandManager __instance, string _chatText, ClientInfo _cInfo)
{
if (_chatText != null && _chatText.StartsWith("/bot "))
{
string playerName = _cInfo != null ? _cInfo.playerName : "Server";
Console.WriteLine($"[Bot] {playerName}: {_chatText}");
return false;
}
return true;
}
}