Jump to content

Single Player Mod / XML / Disable Console


eris667

Recommended Posts

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

  • 2 weeks later...

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

Link to comment
Share on other sites

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

  • 3 weeks later...
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

  • 2 weeks later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...