updpate with rough BotMon mod

This commit is contained in:
CWX 2023-01-17 19:34:30 +00:00
parent a0b59a71fd
commit 658340732b
5 changed files with 300 additions and 0 deletions

View File

@ -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<string, List<Player>> _zoneAndPlayers = new Dictionary<string, List<Player>>();
private List<BotZone> _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<GameWorld>.Instance;
var gameobj = gameWorld.GetComponent<BotmonClass>();
Destroy(gameobj);
_instance = null;
GC.SuppressFinalize(this);
}
~BotmonClass()
{
ConsoleScreen.Log("BotMonitor Disabled on game end");
}
public void Awake()
{
// Set Basics
_gameWorld = Singleton<GameWorld>.Instance;
// get all zones
_zones = LocationScene.GetAllObjects<BotZone>().ToList();
foreach (var zone in _zones)
{
// add zones and a new list of players
_zoneAndPlayers.Add(zone.NameZone, new List<Player>());
}
// 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);
}
}
}

View File

@ -0,0 +1,46 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="Aki.Common">
<HintPath>..\..\..\Shared\Aki\Aki.Common.dll</HintPath>
</Reference>
<Reference Include="Aki.Reflection">
<HintPath>..\..\..\Shared\Aki\Aki.Reflection.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\Shared\EFT\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\..\..\Shared\BepInEx\BepInEx.dll</HintPath>
</Reference>
<Reference Include="bsg.console.core">
<HintPath>..\..\..\Shared\EFT\bsg.console.core.dll</HintPath>
</Reference>
<Reference Include="Comfort">
<HintPath>..\..\..\Shared\EFT\Comfort.dll</HintPath>
</Reference>
<Reference Include="ConfigurationManager">
<HintPath>..\..\..\Shared\BepInEx\ConfigurationManager.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil">
<HintPath>..\..\..\Shared\BepInEx\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\Shared\EFT\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\Shared\EFT\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>..\..\..\Shared\EFT\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>..\..\..\Shared\EFT\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@ -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<DebuggingTool>();
}
[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<GameWorld>.Instance;
gameWorld.GetOrAddComponent<BotmonClass>();
}
}
}

View File

@ -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");
}
}
}

View File

@ -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