• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

Single Player Mod / XML / Disable Console

eris667

Refugee
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 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:

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).

 
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.

 
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:

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!

 
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

 
Back
Top