Files
RAGECOOP-V/Client/Scripts/Menus/Sub/DebugMenu.cs

113 lines
4.2 KiB
C#
Raw Normal View History

2022-10-23 19:02:39 +08:00
using System;
2022-09-06 21:46:35 +08:00
using System.Drawing;
2023-03-18 15:58:31 +08:00
using System.Linq;
using System.Reflection;
2022-10-23 19:02:39 +08:00
using GTA.UI;
using LemonUI.Menus;
2023-03-18 15:58:31 +08:00
using RageCoop.Core;
2022-05-22 15:55:26 +08:00
namespace RageCoop.Client
{
internal static class DebugMenu
{
2023-03-18 15:58:31 +08:00
public static NativeMenu Menu = new("RAGECOOP", "Debug", "Debug settings")
2022-07-20 17:50:01 +08:00
{
UseMouse = false,
2023-02-13 20:44:50 +08:00
Alignment = Settings.FlipMenu ? Alignment.Right : Alignment.Left
};
2022-10-23 19:02:39 +08:00
2023-03-18 15:58:31 +08:00
public static NativeMenu DiagnosticMenu = new("RAGECOOP", "Diagnostic", "Performence and Diagnostic")
{
UseMouse = false,
Alignment = Settings.FlipMenu ? Alignment.Right : Alignment.Left
};
public static NativeMenu TuneMenu = new("RAGECOOP", "Change tunable values")
{
2022-05-22 15:55:26 +08:00
UseMouse = false,
2023-02-13 20:44:50 +08:00
Alignment = Settings.FlipMenu ? Alignment.Right : Alignment.Left
2022-05-22 15:55:26 +08:00
};
2022-10-23 19:02:39 +08:00
public static NativeItem SimulatedLatencyItem =
2023-03-18 15:58:31 +08:00
new("Simulated network latency", "Simulated network latency in ms (one way)", "0");
2022-10-23 19:02:39 +08:00
2023-03-18 15:58:31 +08:00
public static NativeCheckboxItem ShowOwnerItem = new("Show entity owner",
2022-10-23 19:02:39 +08:00
"Show the owner name of the entity you're aiming at", false);
private static readonly NativeCheckboxItem ShowNetworkInfoItem =
2023-03-18 15:58:31 +08:00
new("Show Network Info", Networking.ShowNetworkInfo);
2022-08-04 17:47:57 +08:00
2022-05-22 15:55:26 +08:00
static DebugMenu()
{
Menu.Banner.Color = Color.FromArgb(225, 0, 0, 0);
Menu.Title.Color = Color.FromArgb(255, 165, 0);
2023-03-18 15:58:31 +08:00
TuneMenu.Opening += (s, e) =>
{
TuneMenu.Clear();
foreach (var t in typeof(Main).Assembly.GetTypes())
{
foreach (var field in t.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic))
{
var attri = field.GetCustomAttribute<DebugTunableAttribute>();
if (attri == null)
continue;
2023-03-19 16:58:07 +08:00
var item = new NativeItem(field.Name);
2023-03-18 15:58:31 +08:00
item.AltTitle = field.GetValue(null).ToString();
item.Activated += (s, e) =>
{
try
{
field.SetValue(null, Convert.ChangeType(Game.GetUserInput(), field.FieldType));
item.AltTitle = field.GetValue(null).ToString();
}
catch (Exception ex)
{
Log.Error(ex);
}
};
TuneMenu.Add(item);
}
}
};
2022-09-06 21:46:35 +08:00
DiagnosticMenu.Opening += (sender, e) =>
{
DiagnosticMenu.Clear();
2022-05-23 19:19:56 +08:00
DiagnosticMenu.Add(new NativeItem("EntityPool", EntityPool.DumpDebug()));
2023-03-06 21:54:41 +08:00
// foreach (var pair in Debug.TimeStamps)
// DiagnosticMenu.Add(
// new NativeItem(pair.Key.ToString(), pair.Value.ToString(), pair.Value.ToString()));
};
ShowNetworkInfoItem.CheckboxChanged += (s, e) =>
{
Networking.ShowNetworkInfo = ShowNetworkInfoItem.Checked;
};
ShowOwnerItem.CheckboxChanged += (s, e) =>
{
2023-02-13 20:44:50 +08:00
Settings.ShowEntityOwnerName = ShowOwnerItem.Checked;
Util.SaveSettings();
};
#if DEBUG
2022-09-06 21:46:35 +08:00
SimulatedLatencyItem.Activated += (s, e) =>
2022-08-04 17:14:07 +08:00
{
try
{
2022-10-23 19:02:39 +08:00
SimulatedLatencyItem.AltTitle =
((Networking.SimulatedLatency =
int.Parse(Game.GetUserInput(SimulatedLatencyItem.AltTitle)) * 0.002f) * 500).ToString();
}
catch (Exception ex)
{
2023-02-13 17:51:18 +08:00
Log.Error(ex);
2022-08-04 17:14:07 +08:00
}
};
Menu.Add(SimulatedLatencyItem);
#endif
2022-09-06 21:46:35 +08:00
Menu.Add(ShowNetworkInfoItem);
2022-08-23 17:43:24 +08:00
Menu.Add(ShowOwnerItem);
2022-08-04 17:14:07 +08:00
Menu.AddSubMenu(DiagnosticMenu);
2023-03-18 15:58:31 +08:00
Menu.AddSubMenu(TuneMenu);
2022-10-09 22:07:52 +08:00
}
2022-05-22 15:55:26 +08:00
}
2022-10-23 19:02:39 +08:00
}