Skip to content

Commit

Permalink
Enforce con_enable 1 to fix console toggle issue
Browse files Browse the repository at this point in the history
* Instead always enforce the "legacy" toggleconsole, because internally
  it requires con_enable to be set anyway, although the legacy menu
  toggles this.
* Basically means the support for legacy menu on this is an unsupported
  thing anyway
* Write the command file on save
* Fix attempts to write empty keys
* Unbind duplicate key
* fixes NeotokyoRebuild#586
  • Loading branch information
nullsystem committed Sep 18, 2024
1 parent 9cc6e24 commit d08756d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 25 deletions.
13 changes: 5 additions & 8 deletions mp/src/game/client/cdll_client_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,10 @@ void MusicVol_ChangeCallback(IConVar *cvar, const char *pOldVal, float flOldVal)
UpdateBgm((ConVar*)cvar);
}

#ifdef NEO
extern void NeoToggleConsoleEnforce();
#endif

//-----------------------------------------------------------------------------
// Purpose: Called after client & server DLL are loaded and all systems initialized
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1266,14 +1270,7 @@ void CHLClient::PostInit()
Assert(false);
}

// Rebind ` from toggleconsole to neo_toggleconsole
const auto toggleConsoleBind = gameuifuncs->GetButtonCodeForBind("toggleconsole");
if (toggleConsoleBind == KEY_BACKQUOTE)
{
char cmdStr[128];
V_sprintf_safe(cmdStr, "bind \"`\" \"neo_toggleconsole\"\n");
engine->ClientCmd_Unrestricted(cmdStr);
}
NeoToggleConsoleEnforce();
#endif
}

Expand Down
27 changes: 24 additions & 3 deletions mp/src/game/client/neo/ui/neo_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extern ConVar cl_onlysteamnick;
CNeoRoot *g_pNeoRoot = nullptr;
void NeoToggleconsole();
inline NeoUI::Context g_uiCtx;
inline ConVar neo_cl_toggleconsole("neo_cl_toggleconsole", "0", FCVAR_ARCHIVE,
"If the console can be toggled with the ` keybind or not.", true, 0.0f, true, 1.0f);

namespace {

Expand Down Expand Up @@ -104,6 +106,18 @@ void CNeoRootInput::OnThink()
{
if (code != KEY_ESCAPE)
{
if (code != KEY_DELETE)
{
// The keybind system used requires 1:1 so unbind a duplicate
for (auto &bind : m_pNeoRoot->m_ns.keys.vBinds)
{
if (bind.bcNext == code)
{
bind.bcNext = BUTTON_CODE_NONE;
break;
}
}
}
m_pNeoRoot->m_ns.keys.vBinds[m_pNeoRoot->m_iBindingIdx].bcNext =
(code == KEY_DELETE) ? BUTTON_CODE_NONE : code;
m_pNeoRoot->m_ns.bModified = true;
Expand Down Expand Up @@ -1299,9 +1313,16 @@ bool NeoRootCaptureESC()

void NeoToggleconsole()
{
if (engine->IsInGame() && g_pNeoRoot)
if (neo_cl_toggleconsole.GetBool())
{
g_pNeoRoot->m_state = STATE_ROOT;
if (engine->IsInGame() && g_pNeoRoot)
{
g_pNeoRoot->m_state = STATE_ROOT;
}
// NEO JANK (nullsystem): con_enable 1 is required to allow toggleconsole to
// work and using the legacy settings will alter that value.
// It's in here rather than startup so it doesn't trigger the console on startup
ConVarRef("con_enable").SetValue(true);
engine->ClientCmd_Unrestricted("toggleconsole");
}
engine->ClientCmd_Unrestricted("toggleconsole");
}
29 changes: 15 additions & 14 deletions mp/src/game/client/neo/ui/neo_root_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern ConVar cl_righthand;
extern ConVar cl_showpos;
extern ConVar cl_showfps;
extern ConVar hud_fastswitch;
extern ConVar neo_cl_toggleconsole;

extern NeoUI::Context g_uiCtx;

Expand Down Expand Up @@ -198,7 +199,7 @@ void NeoSettingsRestore(NeoSettings *ns)
{
NeoSettings::Keys *pKeys = &ns->keys;
pKeys->bWeaponFastSwitch = hud_fastswitch.GetBool();
pKeys->bDeveloperConsole = (gameuifuncs->GetButtonCodeForBind("neo_toggleconsole") > KEY_NONE);
pKeys->bDeveloperConsole = neo_cl_toggleconsole.GetBool();
for (int i = 0; i < pKeys->iBindsSize; ++i)
{
auto *bind = &pKeys->vBinds[i];
Expand Down Expand Up @@ -318,6 +319,14 @@ void NeoSettingsRestore(NeoSettings *ns)
}
}

void NeoToggleConsoleEnforce()
{
// NEO JANK (nullsystem): Force neo_toggleconsole bind always
// neo_cl_toggleconsole instead will be the determining ConVar for toggle
engine->ClientCmd_Unrestricted("unbind \"`\"");
engine->ClientCmd_Unrestricted("bind \"`\" neo_toggleconsole");
}

void NeoSettingsSave(const NeoSettings *ns)
{
const_cast<NeoSettings *>(ns)->bModified = false;
Expand All @@ -341,21 +350,12 @@ void NeoSettingsSave(const NeoSettings *ns)
{
const NeoSettings::Keys *pKeys = &ns->keys;
hud_fastswitch.SetValue(pKeys->bWeaponFastSwitch);
{
char cmdStr[128];
V_sprintf_safe(cmdStr, "unbind \"`\"\n");
engine->ClientCmd_Unrestricted(cmdStr);

if (pKeys->bDeveloperConsole)
{
V_sprintf_safe(cmdStr, "bind \"`\" \"neo_toggleconsole\"\n");
engine->ClientCmd_Unrestricted(cmdStr);
}
}
NeoToggleConsoleEnforce();
neo_cl_toggleconsole.SetValue(pKeys->bDeveloperConsole);
for (int i = 0; i < pKeys->iBindsSize; ++i)
{
const auto *bind = &pKeys->vBinds[i];
if (bind->szBindingCmd[0] != '\0')
if (bind->szBindingCmd[0] != '\0' && bind->bcCurrent > KEY_NONE)
{
char cmdStr[128];
const char *bindBtnName = g_pInputSystem->ButtonCodeToString(bind->bcCurrent);
Expand All @@ -366,7 +366,7 @@ void NeoSettingsSave(const NeoSettings *ns)
for (int i = 0; i < pKeys->iBindsSize; ++i)
{
const auto *bind = &pKeys->vBinds[i];
if (bind->szBindingCmd[0] != '\0')
if (bind->szBindingCmd[0] != '\0' && bind->bcNext > KEY_NONE)
{
char cmdStr[128];
const char *bindBtnName = g_pInputSystem->ButtonCodeToString(bind->bcNext);
Expand Down Expand Up @@ -445,6 +445,7 @@ void NeoSettingsSave(const NeoSettings *ns)
cvr->mat_hdr_level.SetValue(pVideo->iHDR);
cvr->mat_monitorgamma.SetValue(pVideo->flGamma);
}
engine->ClientCmd_Unrestricted("host_writeconfig");
}

static const wchar_t *DLFILTER_LABELS[] = {
Expand Down

0 comments on commit d08756d

Please sign in to comment.