miuu-console-unlocker/Patches/PlatformSetupPatches.cs

33 lines
1.1 KiB
C#
Raw Permalink Normal View History

2023-09-07 22:51:16 -04:00
using HarmonyLib;
using System;
2023-10-29 16:57:15 -04:00
using System.Reflection;
2023-09-07 22:51:16 -04:00
namespace ConsoleUnlocker.Patches
{
2023-10-29 16:57:15 -04:00
/*
* Emit "DevModeActivated" signal to enable the console, and do some other setup.
*/
2023-09-07 22:51:16 -04:00
[HarmonyPatch(typeof(PlatformSetup), "GetDevIDs")]
internal class PlatformSetupPatches
{
static void Postfix()
{
2023-10-29 16:57:15 -04:00
if (!PlatformSetup.HasDevAccess(DevUser.IsDev))
{
// If someone is already a dev, don't emit this twice just in case
GlobalContext.Invoke<DevModeActivated>(Array.Empty<object>());
}
if (!PlatformSetup.HasDevAccess(DevUser.CommandlineAccess) || !PlatformSetup.HasDevAccess(DevUser.IsDev))
{
// If a dev already has console access... why are they using the mod lol
MIU.Console.Instance.gameObject.SetActive(true);
}
// It seems it doesn't scan on first console open, but waits for you to type something. Just scan now so all
// commands are available right away
MethodInfo scanMethod = typeof(MIU.Console).GetMethod("CheckInitializeVarsAndCommands", BindingFlags.Instance | BindingFlags.NonPublic);
scanMethod.Invoke(MIU.Console.Instance, null);
2023-09-07 22:51:16 -04:00
}
}
}