CWX-mods/Live/CWX_DebuggingTool/DebuggingTool.cs

82 lines
2.6 KiB
C#
Raw Normal View History

2024-01-12 14:08:58 +00:00
using Aki.Reflection.Patching;
using BepInEx;
using BepInEx.Configuration;
2023-01-17 19:34:30 +00:00
using Comfort.Common;
2024-01-12 14:08:58 +00:00
using CWX_DebuggingTool.Helpers;
using CWX_DebuggingTool.Models;
2023-01-17 19:34:30 +00:00
using EFT;
using EFT.Console.Core;
using EFT.UI;
2024-01-12 14:08:58 +00:00
using System.Reflection;
2023-01-17 19:34:30 +00:00
namespace CWX_DebuggingTool
{
2024-01-12 14:08:58 +00:00
[BepInPlugin("com.cwx.debuggingtool-dxyz", "cwx-debuggingtool-dxyz", "2.2.1")]
2023-01-17 19:34:30 +00:00
public class DebuggingTool : BaseUnityPlugin
{
2024-01-12 14:08:58 +00:00
public static ConfigEntry<BotMonitorMode> DefaultMode;
2023-01-17 19:34:30 +00:00
private void Awake()
{
2024-01-12 14:08:58 +00:00
DefaultMode = Config.Bind(
"Main Settings",
"DefaultMode",
BotMonitorMode.None,
"Default Mode on Startup");
2023-01-17 19:34:30 +00:00
ConsoleScreen.Processor.RegisterCommandGroup<DebuggingTool>();
2024-01-12 14:08:58 +00:00
new MatchStartPatch().Enable();
2023-01-17 19:34:30 +00:00
}
[ConsoleCommand("BotMonitor")]
2024-01-12 14:08:58 +00:00
public static void BotMonitorConsoleCommand([ConsoleArgument("", "Options: 0 = off, 1 = Total bots, 2 = 1+Total bots per Zone, 3 = 2+Each bot")] BotMonitorMode mode )
2023-01-17 19:34:30 +00:00
{
2024-01-12 14:08:58 +00:00
if (mode == BotMonitorMode.None)
{
DisableBotMonitor();
ConsoleScreen.Log("BotMonitor disabled");
}
else if (!mode.IsValid())
2023-01-17 19:34:30 +00:00
{
2024-01-12 14:08:58 +00:00
ConsoleScreen.LogError("Wrong Option used, please use 0, 1, 2 or 3");
}
else
{
ConsoleScreen.Log($"BotMonitor enabled with {mode.Description()}");
EnableBotMonitor(mode);
2023-01-17 19:34:30 +00:00
}
}
2024-01-12 14:08:58 +00:00
public static void DisableBotMonitor()
2023-01-17 19:34:30 +00:00
{
2024-01-12 14:08:58 +00:00
var gameWorld = Singleton<GameWorld>.Instance;
var btmInstance = gameWorld.GetComponent<BotmonClass>();
if (btmInstance != null)
{
Destroy(btmInstance);
}
2023-01-17 19:34:30 +00:00
}
2024-01-12 14:08:58 +00:00
public static void EnableBotMonitor(BotMonitorMode mode)
2023-01-17 19:34:30 +00:00
{
var gameWorld = Singleton<GameWorld>.Instance;
2024-01-12 14:08:58 +00:00
var btmInstance = gameWorld.GetOrAddComponent<BotmonClass>();
btmInstance.Mode = mode;
}
2023-01-17 19:34:30 +00:00
2024-01-12 14:08:58 +00:00
// Add the component every time a match starts if enabled
internal class MatchStartPatch : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted));
2024-01-12 14:08:58 +00:00
[PatchPrefix]
public static void PatchPrefix()
{
if (DefaultMode.Value != BotMonitorMode.None)
{
EnableBotMonitor(DefaultMode.Value);
}
}
2023-01-17 19:34:30 +00:00
}
}
}