From f99f2e7a86770fa391343075b65d2a52123d4dce Mon Sep 17 00:00:00 2001 From: Terry Hearst Date: Sun, 29 Oct 2023 16:57:15 -0400 Subject: [PATCH] More robust unlocking and scanning --- PatchEntryPoint.cs | 1 - Patches/PlatformSetupPatches.cs | 22 +++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/PatchEntryPoint.cs b/PatchEntryPoint.cs index cf44f47..74ee3de 100644 --- a/PatchEntryPoint.cs +++ b/PatchEntryPoint.cs @@ -1,5 +1,4 @@ using HarmonyLib; -using System; using UnityEngine.SceneManagement; namespace ConsoleUnlocker diff --git a/Patches/PlatformSetupPatches.cs b/Patches/PlatformSetupPatches.cs index 0798231..7768bed 100644 --- a/Patches/PlatformSetupPatches.cs +++ b/Patches/PlatformSetupPatches.cs @@ -1,16 +1,32 @@ using HarmonyLib; using System; -using MIU; +using System.Reflection; namespace ConsoleUnlocker.Patches { + /* + * Emit "DevModeActivated" signal to enable the console, and do some other setup. + */ [HarmonyPatch(typeof(PlatformSetup), "GetDevIDs")] internal class PlatformSetupPatches { static void Postfix() { - GlobalContext.Invoke(Array.Empty()); - MIU.Console.Instance.gameObject.SetActive(true); + if (!PlatformSetup.HasDevAccess(DevUser.IsDev)) + { + // If someone is already a dev, don't emit this twice just in case + GlobalContext.Invoke(Array.Empty()); + } + 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); } } }