Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion GameMod/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ static class Console
{
public static bool KeyEnabled;
public static int CustomUIColor;
public static string[] ActivationChars = { "`", "~", "ö" };

private static MethodInfo _GameManager_InitializeMissionList_Method = typeof(GameManager).GetMethod("InitializeMissionList", AccessTools.all);
public static void CmdReloadMissions()
Expand Down Expand Up @@ -347,9 +348,68 @@ private static void HandleConsoleToggle()
[HarmonyPatch(typeof(uConsoleInput), "ProcessActivationInput")]
class ConsoleEnablePatch
{
private static bool lastFramePresent = false;

private static bool ActivationCharTyped()
{
string s = Input.inputString;
if (string.IsNullOrEmpty(s)) return false;
foreach (string c in Console.ActivationChars)
if (!string.IsNullOrEmpty(c) && s.Contains(c))
return true;
return false;
}

private static bool Prefix()
{
return Console.KeyEnabled || uConsole.IsOn();
bool down = ActivationCharTyped() && !lastFramePresent;
bool up = !ActivationCharTyped() && lastFramePresent;
lastFramePresent = ActivationCharTyped();

if (!(Console.KeyEnabled || uConsole.IsOn()))
return false;

if (down)
{
if (!uConsole.IsOn())
{
uConsole.TurnOn();
uConsole.m_GUI.InputFieldMoveCaretToEnd();
uConsole.m_GUI.InputFieldSetFocus();
}
else
{
uConsole.TurnOff();
uConsole.m_GUI.InputFieldDeactivate();
}
}
else if (up && uConsole.IsOn())
{
uConsole.m_GUI.InputFieldSetFocus();
}

return false;
}

// remove the activation character from the input field
private static void Postfix()
{
string text = uConsole.m_GUI.InputFieldGetText();
if (string.IsNullOrEmpty(text)) return;

string stripped = text;
foreach (string c in Console.ActivationChars)
if (!string.IsNullOrEmpty(c))
stripped = stripped.Replace(c, "");

if (stripped == text) return;
if (stripped.Length == 0)
uConsole.m_GUI.InputFieldClearText();
else
{
uConsole.m_GUI.InputFieldSetText(stripped);
uConsole.m_GUI.InputFieldMoveCaretToEnd();
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions GameMod/GameMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,14 @@ public static void Initialize()
}

uConsole.RegisterCommand("getval", "Gets the value of a specified variable -- \"getval [static class].[field]\" (classes can be nested to reach instance fields)", new uConsole.DebugCommand(GetVal));

if (FindArg("-telemetry"))

// sets the console activation character list (seperated by comma)
if (FindArgVal("-console_key", out string consoleKey))
if (!String.IsNullOrEmpty(consoleKey)){
global::GameMod.Console.ActivationChars = consoleKey.Split(',');
}

if (FindArg("-telemetry"))
TelemetryMod.telemetry_enabled = true;

if (FindArgVal("-telemetry-ip", out string ip_string)){
Expand Down