From 658340732b98182d54952bcf5b9a386dd954f30d Mon Sep 17 00:00:00 2001 From: CWX Date: Tue, 17 Jan 2023 19:34:30 +0000 Subject: [PATCH] updpate with rough BotMon mod --- Live/CWX_DebuggingTool/BotmonClass.cs | 179 ++++++++++++++++++ .../CWX_DebuggingTool.csproj | 46 +++++ Live/CWX_DebuggingTool/DebuggingTool.cs | 52 +++++ Live/CWX_DebuggingTool/StringBuilderExt.cs | 17 ++ Live/CWX_Mods.sln | 6 + 5 files changed, 300 insertions(+) create mode 100644 Live/CWX_DebuggingTool/BotmonClass.cs create mode 100644 Live/CWX_DebuggingTool/CWX_DebuggingTool.csproj create mode 100644 Live/CWX_DebuggingTool/DebuggingTool.cs create mode 100644 Live/CWX_DebuggingTool/StringBuilderExt.cs diff --git a/Live/CWX_DebuggingTool/BotmonClass.cs b/Live/CWX_DebuggingTool/BotmonClass.cs new file mode 100644 index 0000000..81646b8 --- /dev/null +++ b/Live/CWX_DebuggingTool/BotmonClass.cs @@ -0,0 +1,179 @@ +using EFT.UI; +using System; +using UnityEngine; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Comfort.Common; +using EFT; +using System.Drawing; + +namespace CWX_DebuggingTool +{ + public sealed class BotmonClass : MonoBehaviour, IDisposable + { + private static BotmonClass _instance = null; + private GUIContent _guiContent = null; + private GUIStyle _textStyle; + private StringBuilder _stringBuilder = new StringBuilder(200); + private Player _player; + private Dictionary> _zoneAndPlayers = new Dictionary>(); + private List _zones = null; + private GameWorld _gameWorld = null; + + private float updateTimer; + private float updateRate = 5f; + private float GuiTimer; + private float GuiRate = 5f; + + private BotmonClass() + { + + } + + public static BotmonClass Instance + { + get + { + if (_instance == null) + { + _instance = new BotmonClass(); + } + + return _instance; + } + } + + public void Dispose() + { + var gameWorld = Singleton.Instance; + + var gameobj = gameWorld.GetComponent(); + Destroy(gameobj); + _instance = null; + GC.SuppressFinalize(this); + } + + ~BotmonClass() + { + ConsoleScreen.Log("BotMonitor Disabled on game end"); + } + + public void Awake() + { + // Set Basics + _gameWorld = Singleton.Instance; + + // get all zones + _zones = LocationScene.GetAllObjects().ToList(); + + foreach (var zone in _zones) + { + // add zones and a new list of players + _zoneAndPlayers.Add(zone.NameZone, new List()); + } + + // get player + _player = _gameWorld.AllPlayers.Find(x => x.IsYourPlayer); + + } + public void Update() + { + if (!Application.isFocused) return; + + updateTimer += Time.deltaTime; + + if (updateTimer < updateRate) return; + + updateTimer = 0; + + if (_gameWorld == null) return; + + foreach (var z in _zoneAndPlayers) + { + z.Value.Clear(); + } + + if (_gameWorld.AllPlayers.Count > 1) + { + foreach (var player in _gameWorld.AllPlayers) + { + if (!player.IsYourPlayer) + { + var zoneName = player.AIData.BotOwner.BotsGroup.BotZone.NameZone; + + if (_zoneAndPlayers.ContainsKey(zoneName) && !_zoneAndPlayers[zoneName].Contains(player)) + { + _zoneAndPlayers[zoneName].Add(player); + } + } + } + } + + foreach (var pair in _zoneAndPlayers) + { + foreach (var person in pair.Value) + { + if (!person.HealthController.IsAlive) + { + pair.Value.Remove(person); + } + } + } + } + + public void OnGUI() + { + GuiTimer += Time.deltaTime; + + if (GuiRate < GuiTimer) return; + + GuiTimer = 0; + + // set basics on GUI + if (_textStyle == null) + { + _textStyle = new GUIStyle(GUI.skin.box); + _textStyle.alignment = TextAnchor.MiddleLeft; + _textStyle.fontSize = 20; + _textStyle.margin = new RectOffset(3, 3, 3, 3); + } + + // new GUI Content + if (_guiContent == null) + { + _guiContent = new GUIContent(); + } + + _stringBuilder.Clear(); + + if (_zoneAndPlayers != null) + { + var total = 0; + + foreach (var zone in _zoneAndPlayers) + { + if (_zoneAndPlayers[zone.Key].Count > 0) + { + _stringBuilder.AppendLine($"{zone.Key} = {_zoneAndPlayers[zone.Key].Count}"); + } + + foreach (var player in _zoneAndPlayers[zone.Key]) + { + total++; + var distance = Vector3.Distance(player.Position, _player.Position); + _stringBuilder.AppendLine($"> [{distance:n2}m] [{player.Profile.Info.Settings.Role}] [{player.Profile.Side}] {player.Profile.Nickname}"); + } + } + + _stringBuilder.PrependLine($"Total = {total}"); + } + + _guiContent.text = _stringBuilder.ToString(); + + var size = _textStyle.CalcSize(_guiContent); + + GUI.Box(new Rect(Screen.width - size.x - 5f, 60f, size.x, size.y), _guiContent, _textStyle); + } + } +} \ No newline at end of file diff --git a/Live/CWX_DebuggingTool/CWX_DebuggingTool.csproj b/Live/CWX_DebuggingTool/CWX_DebuggingTool.csproj new file mode 100644 index 0000000..bf8f1fe --- /dev/null +++ b/Live/CWX_DebuggingTool/CWX_DebuggingTool.csproj @@ -0,0 +1,46 @@ + + + + net472 + + + + + ..\..\..\Shared\Aki\Aki.Common.dll + + + ..\..\..\Shared\Aki\Aki.Reflection.dll + + + ..\..\..\Shared\EFT\Assembly-CSharp.dll + + + ..\..\..\Shared\BepInEx\BepInEx.dll + + + ..\..\..\Shared\EFT\bsg.console.core.dll + + + ..\..\..\Shared\EFT\Comfort.dll + + + ..\..\..\Shared\BepInEx\ConfigurationManager.dll + + + ..\..\..\Shared\BepInEx\Mono.Cecil.dll + + + ..\..\..\Shared\EFT\UnityEngine.dll + + + ..\..\..\Shared\EFT\UnityEngine.CoreModule.dll + + + ..\..\..\Shared\EFT\UnityEngine.IMGUIModule.dll + + + ..\..\..\Shared\EFT\UnityEngine.TextRenderingModule.dll + + + + diff --git a/Live/CWX_DebuggingTool/DebuggingTool.cs b/Live/CWX_DebuggingTool/DebuggingTool.cs new file mode 100644 index 0000000..16e6056 --- /dev/null +++ b/Live/CWX_DebuggingTool/DebuggingTool.cs @@ -0,0 +1,52 @@ +using System; +using BepInEx; +using Comfort.Common; +using EFT; +using EFT.Console.Core; +using EFT.UI; + +namespace CWX_DebuggingTool +{ + [BepInPlugin("com.cwx.debuggingtool", "cwx-debuggingtool", "1.0.0")] + public class DebuggingTool : BaseUnityPlugin + { + private void Awake() + { + ConsoleScreen.Processor.RegisterCommandGroup(); + } + + [ConsoleCommand("BotMonitor")] + public static void BotMonitorConsoleCommand([ConsoleArgument("", "Options: 0 = off, 1 = on")] int value ) + { + switch (value) + { + case 0: + DisableBotMonitor(); + ConsoleScreen.Log("BotMonitor disabled"); + break; + case 1: + EnableBotMonitor(); + ConsoleScreen.Log("BotMonitor enabled"); + break; + default: + // fail to load, or wrong option used + ConsoleScreen.LogError("Wrong Option used, please use 0 or 1"); + break; + } + } + + public static void DisableBotMonitor() + { + BotmonClass.Instance.Dispose(); + } + + public static void EnableBotMonitor() + { + var botmon = BotmonClass.Instance; + + var gameWorld = Singleton.Instance; + + gameWorld.GetOrAddComponent(); + } + } +} \ No newline at end of file diff --git a/Live/CWX_DebuggingTool/StringBuilderExt.cs b/Live/CWX_DebuggingTool/StringBuilderExt.cs new file mode 100644 index 0000000..bec0f57 --- /dev/null +++ b/Live/CWX_DebuggingTool/StringBuilderExt.cs @@ -0,0 +1,17 @@ +using System.Text; + +namespace CWX_DebuggingTool +{ + public static class MyExtensions + { + public static StringBuilder Prepend(this StringBuilder sb, string content) + { + return sb.Insert(0, content); + } + + public static StringBuilder PrependLine(this StringBuilder sb, string content) + { + return sb.Insert(0, content + "\n"); + } + } +} diff --git a/Live/CWX_Mods.sln b/Live/CWX_Mods.sln index 151e55d..5c660f9 100644 --- a/Live/CWX_Mods.sln +++ b/Live/CWX_Mods.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CWX_DeSharpener", "CWX_DeSh EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CWX_MasterKey", "CWX_MasterKey\CWX_MasterKey.csproj", "{40BE277F-55BE-4579-9535-D1F5ED9CC549}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CWX_DebuggingTool", "CWX_DebuggingTool\CWX_DebuggingTool.csproj", "{E439D92F-26FD-42A2-9EA5-38A318EB5403}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {40BE277F-55BE-4579-9535-D1F5ED9CC549}.Debug|Any CPU.Build.0 = Debug|Any CPU {40BE277F-55BE-4579-9535-D1F5ED9CC549}.Release|Any CPU.ActiveCfg = Release|Any CPU {40BE277F-55BE-4579-9535-D1F5ED9CC549}.Release|Any CPU.Build.0 = Release|Any CPU + {E439D92F-26FD-42A2-9EA5-38A318EB5403}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E439D92F-26FD-42A2-9EA5-38A318EB5403}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E439D92F-26FD-42A2-9EA5-38A318EB5403}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E439D92F-26FD-42A2-9EA5-38A318EB5403}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE