eris667 Posted June 28, 2023 Share Posted June 28, 2023 I am finding remnant posts that this can be done... but not sure what exactly to do, I would like to disable the console for all of my single player games (which in turn disables CM -- that works from console even when it is turned off in game settings) Any pointers or suggestions are appreciated - thank you Reference: Link to comment Share on other sites More sharing options...
Sqeegie Posted July 7, 2023 Share Posted July 7, 2023 I'm not sure how to do this in XML, but it can easily be done in C#. Here is an example for A21 that disables console commands and creative/debug menus in single player. PoC: Spoiler using UnityEngine; using UnityEngine.UI; using HarmonyLib; using System.Reflection; /* .NET Framework 4.5 * * References: * - 0Harmony.dll * - Assembly-CSharp.dll * - LogLibrary.dll * - UnityEngine.CoreModule.dll * - UnityEngine.UI.dll */ public class PeskyConsole : IModApi { public void InitMod(Mod _modInstance) { if (!GameObject.FindObjectOfType<PeskyConsoleMB>()) new GameObject().AddComponent<PeskyConsoleMB>(); Harmony harmony = new Harmony(base.GetType().ToString()); harmony.PatchAll(Assembly.GetExecutingAssembly()); Log.Out("[MODS] [PeskyConsole] Loaded!"); } } public class PeskyConsoleMB : MonoBehaviour { public void Update() { if (ConnectionManager.Instance.IsSinglePlayer) { bool cm = GamePrefs.GetBool(EnumGamePrefs.CreativeMenuEnabled); bool dm = GamePrefs.GetBool(EnumGamePrefs.DebugMenuEnabled); if (cm || dm) { GamePrefs.Set(EnumGamePrefs.CreativeMenuEnabled, false); GamePrefs.Set(EnumGamePrefs.DebugMenuEnabled, false); GamePrefs.Instance.Save(); } } } } [HarmonyPatch(typeof(GUIWindowConsole), "EnterCommand")] class ConsoleCommandPatch { static bool Prefix(ref InputField ___commandField, string _command) { if (ConnectionManager.Instance.IsSinglePlayer) { Log.Out("[MODS] [PeskyConsole] " + GameManager.Instance.World.GetPrimaryPlayer().EntityName + " is not in the sudoers file. This incident will be reported."); ___commandField.text = ""; ___commandField.Select(); ___commandField.ActivateInputField(); return false; } return true; } } Compiled version: https://drive.google.com/file/d/1uY4gYiSgL340dbb1SOk1vjB-O2nzbRiB (extract and dump into the mods folder). 1 Link to comment Share on other sites More sharing options...
Riamus Posted July 7, 2023 Share Posted July 7, 2023 On 6/28/2023 at 6:53 PM, eris667 said: I am finding remnant posts that this can be done... but not sure what exactly to do, I would like to disable the console for all of my single player games (which in turn disables CM -- that works from console even when it is turned off in game settings) Any pointers or suggestions are appreciated - thank you Reference: I'm curious why you'd want to? I mean if it is single player, you can just not use it. Having access to the console can be very helpful when identifying bugs or correcting bugs. Link to comment Share on other sites More sharing options...
eris667 Posted July 27, 2023 Author Share Posted July 27, 2023 On 7/7/2023 at 10:44 AM, Sqeegie said: I'm not sure how to do this in XML, but it can easily be done in C#. Here is an example for A21 that disables console commands and creative/debug menus in single player. PoC: Reveal hidden contents using UnityEngine; using UnityEngine.UI; using HarmonyLib; using System.Reflection; /* .NET Framework 4.5 * * References: * - 0Harmony.dll * - Assembly-CSharp.dll * - LogLibrary.dll * - UnityEngine.CoreModule.dll * - UnityEngine.UI.dll */ public class PeskyConsole : IModApi { public void InitMod(Mod _modInstance) { if (!GameObject.FindObjectOfType<PeskyConsoleMB>()) new GameObject().AddComponent<PeskyConsoleMB>(); Harmony harmony = new Harmony(base.GetType().ToString()); harmony.PatchAll(Assembly.GetExecutingAssembly()); Log.Out("[MODS] [PeskyConsole] Loaded!"); } } public class PeskyConsoleMB : MonoBehaviour { public void Update() { if (ConnectionManager.Instance.IsSinglePlayer) { bool cm = GamePrefs.GetBool(EnumGamePrefs.CreativeMenuEnabled); bool dm = GamePrefs.GetBool(EnumGamePrefs.DebugMenuEnabled); if (cm || dm) { GamePrefs.Set(EnumGamePrefs.CreativeMenuEnabled, false); GamePrefs.Set(EnumGamePrefs.DebugMenuEnabled, false); GamePrefs.Instance.Save(); } } } } [HarmonyPatch(typeof(GUIWindowConsole), "EnterCommand")] class ConsoleCommandPatch { static bool Prefix(ref InputField ___commandField, string _command) { if (ConnectionManager.Instance.IsSinglePlayer) { Log.Out("[MODS] [PeskyConsole] " + GameManager.Instance.World.GetPrimaryPlayer().EntityName + " is not in the sudoers file. This incident will be reported."); ___commandField.text = ""; ___commandField.Select(); ___commandField.ActivateInputField(); return false; } return true; } } Compiled version: https://drive.google.com/file/d/1uY4gYiSgL340dbb1SOk1vjB-O2nzbRiB (extract and dump into the mods folder). Thank You! Link to comment Share on other sites More sharing options...
eris667 Posted August 10, 2023 Author Share Posted August 10, 2023 I installed into the Save Folder (A21.1 b16) /home/eris667/.local/share/7DaysToDie/Mods/PeskyConsole Mod works perfectly - - funny caveat, to run the mod that disables console / creative menu (cheats) I have to disable Easy Anti Cheat! When I modified the .xml files it did not trigger the EAC (but the changes died every update) Now when my game starts it informs me that I have a mod installed and I pick EAC or not Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now