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
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;
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;
}
}
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
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;
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;
}
}