Implement ChatMessageServer patch with correct signature
Intercepts /bot messages and logs to console only
This commit is contained in:
@@ -1,26 +1,30 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class CHRANIBotTNG : IModApi
|
public class CHRANIBotTNG : IModApi
|
||||||
{
|
{
|
||||||
public void InitMod(Mod _modInstance)
|
public void InitMod(Mod _modInstance)
|
||||||
{
|
{
|
||||||
Console.WriteLine("[CHRANIBotTNG] Loading");
|
Console.WriteLine("[CHRANIBotTNG] Loading");
|
||||||
|
var harmony = new Harmony("com.chranibottng.mod");
|
||||||
// List all GameManager methods containing "Chat"
|
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
||||||
var gmType = typeof(GameManager);
|
|
||||||
Console.WriteLine("[CHRANIBotTNG] 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("[CHRANIBotTNG] Loaded");
|
Console.WriteLine("[CHRANIBotTNG] Loaded");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(GameManager), "ChatMessageServer")]
|
||||||
|
public class ChatMessagePatch
|
||||||
|
{
|
||||||
|
static bool Prefix(ClientInfo _cInfo, EChatType _chatType, int _senderEntityId, string _msg, List<int> _recipientEntityIds, EMessageSender _msgSender, BbCodeSupportMode _bbMode)
|
||||||
|
{
|
||||||
|
if (_msg != null && _msg.StartsWith("/bot "))
|
||||||
|
{
|
||||||
|
string playerName = _cInfo != null ? _cInfo.playerName : "Server";
|
||||||
|
Console.WriteLine($"[Bot] {playerName}: {_msg}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user