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
@@ -1,16 +1,10 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AmongUs.Data;
|
||||
using AmongUs.GameOptions;
|
||||
global using static Reactor.Utilities.Logger<Reactor.Debugger.DebuggerPlugin>;
|
||||
using BepInEx;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using InnerNet;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.ImGui;
|
||||
using UnityEngine;
|
||||
using Reactor.Debugger.AutoJoin;
|
||||
using Reactor.Debugger.Patches;
|
||||
using Reactor.Debugger.Window;
|
||||
|
||||
namespace Reactor.Debugger;
|
||||
|
||||
@@ -20,107 +14,17 @@ namespace Reactor.Debugger;
|
||||
public partial class DebuggerPlugin : BasePlugin
|
||||
{
|
||||
public Harmony Harmony { get; } = new(Id);
|
||||
public DebuggerComponent Component { get; private set; } = null!;
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
Component = this.AddComponent<DebuggerComponent>();
|
||||
DebuggerConfig.Bind(Config);
|
||||
|
||||
var maxImpostors = (Il2CppStructArray<int>) Enumerable.Repeat((int) byte.MaxValue, byte.MaxValue).ToArray();
|
||||
GameOptionsData.MaxImpostors = GameOptionsData.RecommendedImpostors = maxImpostors;
|
||||
NormalGameOptionsV07.MaxImpostors = NormalGameOptionsV07.RecommendedImpostors = maxImpostors;
|
||||
HideNSeekGameOptionsV07.MaxImpostors = maxImpostors;
|
||||
this.AddComponent<DebuggerWindow>();
|
||||
|
||||
var minPlayers = (Il2CppStructArray<int>) Enumerable.Repeat(1, byte.MaxValue).ToArray();
|
||||
GameOptionsData.MinPlayers = minPlayers;
|
||||
NormalGameOptionsV07.MinPlayers = minPlayers;
|
||||
HideNSeekGameOptionsV07.MinPlayers = minPlayers;
|
||||
GameOptionsPatches.Initialize();
|
||||
|
||||
Harmony.PatchAll();
|
||||
}
|
||||
|
||||
[RegisterInIl2Cpp]
|
||||
public class DebuggerComponent : MonoBehaviour
|
||||
{
|
||||
[HideFromIl2Cpp]
|
||||
public bool DisableGameEnd { get; set; }
|
||||
|
||||
[HideFromIl2Cpp]
|
||||
public DragWindow TestWindow { get; }
|
||||
|
||||
public DebuggerComponent(IntPtr ptr) : base(ptr)
|
||||
{
|
||||
TestWindow = new DragWindow(new Rect(20, 20, 0, 0), "Debugger", () =>
|
||||
{
|
||||
GUILayout.Label("Name: " + DataManager.Player.Customization.Name);
|
||||
DisableGameEnd = GUILayout.Toggle(DisableGameEnd, "Disable game end");
|
||||
|
||||
if (ShipStatus.Instance && AmongUsClient.Instance.AmHost)
|
||||
{
|
||||
if (GUILayout.Button("Force game end"))
|
||||
{
|
||||
ShipStatus.Instance.enabled = false;
|
||||
GameManager.Instance.RpcEndGame(GameOverReason.ImpostorDisconnect, false);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Call a meeting"))
|
||||
{
|
||||
PlayerControl.LocalPlayer.CmdReportDeadBody(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (TutorialManager.InstanceExists && PlayerControl.LocalPlayer)
|
||||
{
|
||||
var data = PlayerControl.LocalPlayer.Data;
|
||||
|
||||
var newIsImpostor = GUILayout.Toggle(data.Role.IsImpostor, "Is Impostor");
|
||||
if (data.Role.IsImpostor != newIsImpostor)
|
||||
{
|
||||
PlayerControl.LocalPlayer.RpcSetRole(newIsImpostor ? RoleTypes.Impostor : RoleTypes.Crewmate);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Spawn a dummy"))
|
||||
{
|
||||
var playerControl = Instantiate(TutorialManager.Instance.PlayerPrefab);
|
||||
var i = playerControl.PlayerId = (byte) GameData.Instance.GetAvailableId();
|
||||
GameData.Instance.AddPlayer(playerControl);
|
||||
AmongUsClient.Instance.Spawn(playerControl, -2, SpawnFlags.None);
|
||||
playerControl.transform.position = PlayerControl.LocalPlayer.transform.position;
|
||||
playerControl.GetComponent<DummyBehaviour>().enabled = true;
|
||||
playerControl.NetTransform.enabled = false;
|
||||
playerControl.SetName($"{TranslationController.Instance.GetString(StringNames.Dummy, Array.Empty<Il2CppSystem.Object>())} {i}");
|
||||
var color = (byte) (i % Palette.PlayerColors.Length);
|
||||
playerControl.SetColor(color);
|
||||
playerControl.SetHat(HatManager.Instance.allHats[i % HatManager.Instance.allHats.Count].ProdId, playerControl.Data.DefaultOutfit.ColorId);
|
||||
playerControl.SetPet(HatManager.Instance.allPets[i % HatManager.Instance.allPets.Count].ProdId);
|
||||
playerControl.SetSkin(HatManager.Instance.allSkins[i % HatManager.Instance.allSkins.Count].ProdId, color);
|
||||
GameData.Instance.RpcSetTasks(playerControl.PlayerId, new Il2CppStructArray<byte>(0));
|
||||
}
|
||||
}
|
||||
|
||||
if (PlayerControl.LocalPlayer)
|
||||
{
|
||||
var position = PlayerControl.LocalPlayer.transform.position;
|
||||
GUILayout.Label($"x: {position.x}");
|
||||
GUILayout.Label($"y: {position.y}");
|
||||
}
|
||||
})
|
||||
{
|
||||
Enabled = false,
|
||||
};
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F1))
|
||||
{
|
||||
TestWindow.Enabled = !TestWindow.Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
TestWindow.OnGUI();
|
||||
}
|
||||
AutoJoinConnectionManager.StartOrConnect();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user