mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-20 01:46:21 +00:00
Rework debugger (#79)
This commit is contained in:
1 parent
d82268b88a
commit
5db20ca9de
27 files changed
+1068
-180
No files matched your search
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using AmongUs.Data;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using Reactor.Debugger.Window.Tabs;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.ImGui;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reactor.Debugger.Window;
|
||||
|
||||
[RegisterInIl2Cpp]
|
||||
internal sealed class DebuggerWindow : MonoBehaviour
|
||||
{
|
||||
private readonly DragWindow _window;
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public BaseTab[] Tabs { get; } =
|
||||
{
|
||||
new ConfigTab(),
|
||||
new GameTab(),
|
||||
new AutoJoinTab(),
|
||||
};
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public BaseTab SelectedTab { get; private set; }
|
||||
|
||||
public DebuggerWindow(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
SelectedTab = Tabs[0];
|
||||
|
||||
_window = new DragWindow(new Rect(20, 20, 0, 0), "Reactor.Debugger", () =>
|
||||
{
|
||||
var clientName = DataManager.Player.Customization.Name;
|
||||
if (AmongUsClient.Instance && AmongUsClient.Instance.AmHost) clientName += " (host)";
|
||||
GUILayout.Label("Name: " + clientName);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
foreach (var tab in Tabs)
|
||||
{
|
||||
if (GUILayout.Toggle(tab == SelectedTab, tab.Name, new GUIStyle(GUI.skin.button)))
|
||||
{
|
||||
SelectedTab = tab;
|
||||
}
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(5f);
|
||||
|
||||
SelectedTab.OnGUI();
|
||||
})
|
||||
{
|
||||
Enabled = false,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F1))
|
||||
{
|
||||
_window.Enabled = !_window.Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
_window.OnGUI();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using BepInEx.Unity.IL2CPP.Utils;
|
||||
using Reactor.Debugger.AutoJoin;
|
||||
using Reactor.Debugger.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reactor.Debugger.Window.Tabs;
|
||||
|
||||
internal sealed class AutoJoinTab : BaseTab
|
||||
{
|
||||
public override string Name => "AutoJoin";
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
if (AutoJoinConnectionManager.Server is { } server)
|
||||
{
|
||||
GUILayout.Label($"Hosting ({server.Clients.Count} clients)");
|
||||
|
||||
if (GUILayout.Button("Stop"))
|
||||
{
|
||||
server.Dispose();
|
||||
}
|
||||
|
||||
if (AmongUsClient.Instance)
|
||||
{
|
||||
if (GUILayout.Button("Create an online game"))
|
||||
{
|
||||
AmongUsClient.Instance.StartCoroutine(AmongUsClient.Instance.CoCreateOnlineGame());
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Create a local game"))
|
||||
{
|
||||
AmongUsClient.Instance.StartCoroutine(AmongUsClient.Instance.CoCreateLocalGame());
|
||||
}
|
||||
|
||||
if (
|
||||
AmongUsClient.Instance.AmConnected &&
|
||||
AmongUsClient.Instance.NetworkMode != NetworkModes.FreePlay &&
|
||||
GUILayout.Button("Join me")
|
||||
)
|
||||
{
|
||||
server.SendJoinMe(AmongUsClient.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (AutoJoinConnectionManager.Client is { } client)
|
||||
{
|
||||
GUILayout.Label("Connected");
|
||||
|
||||
if (GUILayout.Button("Disconnect"))
|
||||
{
|
||||
AutoJoinConnectionManager.Client = null;
|
||||
client.Dispose();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Request join"))
|
||||
{
|
||||
client.SendRequestJoin();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Connect"))
|
||||
{
|
||||
AutoJoinConnectionManager.StartOrConnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Reactor.Debugger.Window.Tabs;
|
||||
|
||||
internal abstract class BaseTab
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
public abstract void OnGUI();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Linq;
|
||||
using BepInEx.Configuration;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Reactor.Debugger.Window.Tabs;
|
||||
|
||||
internal sealed class ConfigTab : BaseTab
|
||||
{
|
||||
public override string Name => "Config";
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
var configs = PluginSingleton<ReactorPlugin>.Instance.Config.Concat(PluginSingleton<DebuggerPlugin>.Instance.Config);
|
||||
|
||||
foreach (var section in configs.GroupBy(e => e.Key.Section))
|
||||
{
|
||||
GUILayout.Label(section.Key);
|
||||
|
||||
foreach (var (definition, entry) in section)
|
||||
{
|
||||
if (entry is ConfigEntry<bool> booleanEntry)
|
||||
{
|
||||
booleanEntry.Value = GUILayout.Toggle(booleanEntry.Value, definition.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
using AmongUs.GameOptions;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Reactor.Debugger.Window.Tabs;
|
||||
|
||||
internal sealed class GameTab : BaseTab
|
||||
{
|
||||
public override string Name => "Game";
|
||||
|
||||
public override void OnGUI()
|
||||
{
|
||||
var localPlayer = PlayerControl.LocalPlayer;
|
||||
if (!localPlayer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var amHost = AmongUsClient.Instance.AmHost;
|
||||
|
||||
var position = localPlayer.transform.position;
|
||||
GUILayout.Label($"Position: ({position.x:F3}, {position.y:F3})");
|
||||
|
||||
var physics = localPlayer.MyPhysics;
|
||||
GUILayout.Label($"Speed: {physics.Speed}");
|
||||
physics.Speed = GUILayout.HorizontalSlider(physics.Speed, 0, 25);
|
||||
|
||||
localPlayer.Collider.enabled = GUILayout.Toggle(localPlayer.Collider.enabled, "Collisions");
|
||||
|
||||
if (ShipStatus.Instance)
|
||||
{
|
||||
if (amHost && GUILayout.Button("Force game end"))
|
||||
{
|
||||
ShipStatus.Instance.enabled = false;
|
||||
GameManager.Instance.RpcEndGame(GameOverReason.ImpostorDisconnect, false);
|
||||
}
|
||||
|
||||
if (MeetingHud.Instance)
|
||||
{
|
||||
if (GUILayout.Button("Stop the meeting"))
|
||||
{
|
||||
MeetingHud.Instance.RpcClose();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GUILayout.Button("Call a meeting"))
|
||||
{
|
||||
localPlayer.CmdReportDeadBody(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (TutorialManager.InstanceExists)
|
||||
{
|
||||
var newIsImpostor = GUILayout.Toggle(localPlayer.Data.Role.IsImpostor, "Is Impostor");
|
||||
if (localPlayer.Data.Role.IsImpostor != newIsImpostor)
|
||||
{
|
||||
localPlayer.RpcSetRole(newIsImpostor ? RoleTypes.Impostor : RoleTypes.Crewmate);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Spawn a dummy"))
|
||||
{
|
||||
SpawnDummy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void SpawnDummy()
|
||||
{
|
||||
var playerControl = Object.Instantiate(TutorialManager.Instance.PlayerPrefab);
|
||||
var playerId = playerControl.PlayerId = (byte) GameData.Instance.GetAvailableId();
|
||||
|
||||
GameData.Instance.AddPlayer(playerControl);
|
||||
AmongUsClient.Instance.Spawn(playerControl);
|
||||
|
||||
playerControl.transform.position = PlayerControl.LocalPlayer.transform.position;
|
||||
playerControl.GetComponent<DummyBehaviour>().enabled = true;
|
||||
playerControl.NetTransform.enabled = false;
|
||||
|
||||
playerControl.SetName($"{TranslationController.Instance.GetString(StringNames.Dummy)} {playerId}");
|
||||
|
||||
var color = (byte) (playerId % Palette.PlayerColors.Length);
|
||||
playerControl.SetColor(color);
|
||||
playerControl.SetHat(HatManager.Instance.allHats[playerId % HatManager.Instance.allHats.Count].ProdId, playerControl.Data.DefaultOutfit.ColorId);
|
||||
playerControl.SetPet(HatManager.Instance.allPets[playerId % HatManager.Instance.allPets.Count].ProdId);
|
||||
playerControl.SetSkin(HatManager.Instance.allSkins[playerId % HatManager.Instance.allSkins.Count].ProdId, color);
|
||||
playerControl.SetVisor(HatManager.Instance.allVisors[playerId % HatManager.Instance.allVisors.Count].ProdId, color);
|
||||
playerControl.SetNamePlate(HatManager.Instance.allNamePlates[playerId % HatManager.Instance.allNamePlates.Count].ProdId);
|
||||
playerControl.Data.PlayerLevel = playerId;
|
||||
|
||||
GameData.Instance.RpcSetTasks(playerControl.PlayerId, new Il2CppStructArray<byte>(0));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user