Skip to content

Commit ed8fafe

Browse files
committed
hook gores mode directly into bind execution
instead of changing a keys bind to "+fire;+prevweapon" it will append ";+prevweapon" to any command that has +fire and no +prevweapon
1 parent 60c0f28 commit ed8fafe

7 files changed

Lines changed: 34 additions & 131 deletions

File tree

src/engine/shared/config_variables_entity.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,9 @@ MACRO_CONFIG_INT(ClFreezeKillDebug, ec_freeze_kill_debug, 0, 0, 1, CFGFLAG_CLIEN
265265
MACRO_CONFIG_INT(SndFriendChat, snd_friend_chat, 0, 0, 1, CFGFLAG_SAVE | CFGFLAG_CLIENT, "Enable regular Chat Sound Only When a Friend Says Something") // Aiodob Menu color plates
266266

267267
// Gores Mode
268-
MACRO_CONFIG_INT(ClGoresMode, ec_gores_mode, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "always have a gun in your hand :p")
269-
MACRO_CONFIG_INT(ClGoresModeKey, ec_gores_mode_key, 291, 0, 512, CFGFLAG_CLIENT | CFGFLAG_SAVE, "The key it binds to")
268+
MACRO_CONFIG_INT(ClGoresMode, ec_gores_mode, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Automatically switches to gun, when firing it switches to hammer and then back")
270269
MACRO_CONFIG_INT(ClGoresModeDisableIfWeapons, ec_gores_mode_disable_weapons, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Disable Gores Mode When The Player Has Another Weapon")
271270
MACRO_CONFIG_INT(ClAutoEnableGoresMode, ec_gores_mode_auto_enable, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "enables it on Gores gametype and disables on others")
272-
MACRO_CONFIG_STR(ClGoresModeSaved, ec_gores_mode_saved, 128, "+fire", CFGFLAG_CLIENT | CFGFLAG_SAVE, "Dont Edit This")
273271

274272
// Tee
275273
MACRO_CONFIG_INT(ClOwnTeeSkin, ec_own_tee_skin, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Renders your own skin differently for yourself")

src/game/client/component.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,11 @@ class CComponent : public CComponentInterfaces
305305
virtual void OnSelfDeath()
306306
{
307307
}
308+
308309
/*
309310
* Called when the current focus of the window changes, for example when the user alt-tabs out of the game.
310311
* @param Focused `true` if the window is now focused, `false` if it lost focus.
311-
*/
312+
*/
312313
virtual void OnFocusChange(bool Focused)
313314
{
314315
}

src/game/client/components/binds.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,21 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
131131
if(ActiveBind == m_vActiveBinds.end())
132132
{
133133
const auto &&OnKeyPress = [&](int Mask) {
134-
const char *pBind = m_aapKeyBindings[Mask][Event.m_Key];
134+
char aBind[512];
135+
str_copy(aBind, m_aapKeyBindings[Mask][Event.m_Key], sizeof(aBind));
135136
if(g_Config.m_ClSubTickAiming)
136137
{
137-
if(str_comp("+fire", pBind) == 0 || str_comp("+hook", pBind) == 0)
138+
if(str_comp("+fire", aBind) == 0 || str_comp("+hook", aBind) == 0)
138139
{
139140
m_MouseOnAction = true;
140141
}
141142
}
142-
Console()->ExecuteLineStroked(1, pBind, IConsole::CLIENT_ID_UNSPECIFIED);
143+
if(g_Config.m_ClGoresMode && !GameClient()->m_EClient.m_WeaponsGot && str_find(aBind, "+fire") && !str_find(aBind, "+prevweapon"))
144+
{
145+
str_append(aBind, ";+prevweapon", sizeof(aBind));
146+
}
147+
148+
Console()->ExecuteLineStroked(1, aBind, IConsole::CLIENT_ID_UNSPECIFIED);
143149
m_vActiveBinds.emplace_back(Event.m_Key, Mask);
144150
};
145151

@@ -162,7 +168,14 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
162168
// Have to check for nullptr again because the previous execute can unbind itself
163169
if(m_aapKeyBindings[ActiveBind->m_ModifierMask][ActiveBind->m_Key])
164170
{
165-
Console()->ExecuteLineStroked(1, m_aapKeyBindings[ActiveBind->m_ModifierMask][ActiveBind->m_Key], IConsole::CLIENT_ID_UNSPECIFIED);
171+
char aBind[512];
172+
str_copy(aBind, m_aapKeyBindings[ActiveBind->m_ModifierMask][ActiveBind->m_Key], sizeof(aBind));
173+
if(g_Config.m_ClGoresMode && !GameClient()->m_EClient.m_WeaponsGot && str_find(aBind, "+fire") && !str_find(aBind, "+prevweapon"))
174+
{
175+
str_append(aBind, ";+prevweapon", sizeof(aBind));
176+
}
177+
178+
Console()->ExecuteLineStroked(1, aBind, IConsole::CLIENT_ID_UNSPECIFIED);
166179
}
167180
Handled = true;
168181
}
@@ -184,7 +197,14 @@ bool CBinds::OnInput(const IInput::CEvent &Event)
184197
{
185198
return;
186199
}
187-
Console()->ExecuteLineStroked(0, m_aapKeyBindings[Bind.m_ModifierMask][Bind.m_Key], IConsole::CLIENT_ID_UNSPECIFIED);
200+
char aBind[512];
201+
str_copy(aBind, m_aapKeyBindings[Bind.m_ModifierMask][Bind.m_Key], sizeof(aBind));
202+
if(g_Config.m_ClGoresMode && !GameClient()->m_EClient.m_WeaponsGot && str_find(aBind, "+fire") && !str_find(aBind, "+prevweapon"))
203+
{
204+
str_append(aBind, ";+prevweapon", sizeof(aBind));
205+
}
206+
207+
Console()->ExecuteLineStroked(0, aBind, IConsole::CLIENT_ID_UNSPECIFIED);
188208
};
189209

190210
// Release active bind that uses this primary key

src/game/client/components/entity/commands.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,6 @@ void CEClient::OnConsoleInit()
491491
Console()->Register("specid", "i[id]", CFGFLAG_CLIENT, ConSpectateId, this, "Spectate Id");
492492
Console()->Register("crash", "", CFGFLAG_CLIENT, ConCrash, this, "Crash your own client");
493493

494-
Console()->Chain("ec_gores_mode", ConchainGoresMode, this);
495494
Console()->Chain("ec_fast_input", ConchainFastInputs, this);
496495
Console()->Chain("ec_fast_input_amount", ConchainFastInputs, this);
497496

@@ -502,17 +501,6 @@ void CEClient::OnConsoleInit()
502501
Console()->Chain("ec_discord_normal_process_priority", ConchainDiscordProcessPriority, this);
503502
}
504503

505-
void CEClient::ConchainGoresMode(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
506-
{
507-
pfnCallback(pResult, pCallbackUserData);
508-
CEClient *pSelf = (CEClient *)pUserData;
509-
if(pResult->NumArguments())
510-
{
511-
int GoresMode = pResult->GetInteger(0);
512-
pSelf->ToggleGoresMode(GoresMode);
513-
}
514-
}
515-
516504
void CEClient::ConchainFastInputs(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
517505
{
518506
pfnCallback(pResult, pCallbackUserData);

src/game/client/components/entity/entity.cpp

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -232,74 +232,8 @@ void CEClient::GoresMode()
232232
return;
233233
}
234234

235-
int Key = g_Config.m_ClGoresModeKey;
236-
if(Key < KEY_FIRST || Key >= KEY_LAST)
237-
{
238-
g_Config.m_ClGoresMode = 0;
239-
dbg_msg("E-Client", "Invalid key: %d", Key);
240-
return;
241-
}
242-
const char *pKeyName = Input()->KeyName(Key);
243-
const CBindSlot BindSlot = GameClient()->m_Binds.GetBindSlot(pKeyName);
244-
const char *pBind = GameClient()->m_Binds.GetKeyBinding(BindSlot.m_ModifierMask, BindSlot.m_Key);
245-
if(!pBind)
246-
return;
247-
248-
bool GoresBind = false;
249-
250-
if(!str_comp(pBind, "+fire;+prevweapon"))
251-
GoresBind = true;
252-
253-
if(!GoresBind)
254-
return;
255-
256-
if(GoresBind)
257-
{
258-
if(GameClient()->m_Snap.m_pLocalCharacter->m_Weapon == 0)
259-
{
260-
GameClient()->m_Controls.m_aInputData[g_Config.m_ClDummy].m_WantedWeapon = 2;
261-
}
262-
}
263-
}
264-
265-
void CEClient::GoresModeSave()
266-
{
267-
int Key = g_Config.m_ClGoresModeKey;
268-
if(Key < KEY_FIRST || Key >= KEY_LAST)
269-
{
270-
g_Config.m_ClGoresMode = 0;
271-
dbg_msg("E-Client", "Invalid key: %d", Key);
272-
return;
273-
}
274-
const char *pKeyName = Input()->KeyName(Key);
275-
276-
const CBindSlot BindSlot = GameClient()->m_Binds.GetBindSlot(pKeyName);
277-
const char *pBind = GameClient()->m_Binds.GetKeyBinding(BindSlot.m_ModifierMask, BindSlot.m_Key);
278-
if(!pBind)
279-
return;
280-
str_copy(g_Config.m_ClGoresModeSaved, pBind);
281-
282-
GameClient()->m_Binds.Bind(Key, "+fire;+prevweapon");
283-
}
284-
285-
void CEClient::GoresModeRestore()
286-
{
287-
int Key = g_Config.m_ClGoresModeKey;
288-
if(Key < KEY_FIRST || Key >= KEY_LAST)
289-
{
290-
g_Config.m_ClGoresMode = 0;
291-
dbg_msg("E-Client", "Invalid key: %d", Key);
292-
return;
293-
}
294-
GameClient()->m_Binds.Bind(Key, g_Config.m_ClGoresModeSaved);
295-
}
296-
297-
void CEClient::ToggleGoresMode(bool Value)
298-
{
299-
if(Value)
300-
GoresModeSave();
301-
else
302-
GoresModeRestore();
235+
if(GameClient()->m_Snap.m_pLocalCharacter->m_Weapon == 0)
236+
GameClient()->m_Controls.m_aInputData[g_Config.m_ClDummy].m_WantedWeapon = WEAPON_GUN + 1;
303237
}
304238

305239
void CEClient::OnConnect()
@@ -330,7 +264,7 @@ void CEClient::OnConnect()
330264
{
331265
if(g_Config.m_ClAutoEnableGoresMode)
332266
{
333-
if(str_find(CurrentServerInfo.m_aGameType, "Gores"))
267+
if(str_find_nocase(CurrentServerInfo.m_aGameType, "Gores"))
334268
{
335269
m_GoresServer = true;
336270
g_Config.m_ClGoresMode = 1;

src/game/client/components/entity/entity.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class CEClient : public CComponent
1616
bool m_AttemptedJoinTeam;
1717
bool m_JoinedTeam;
1818

19-
bool m_WeaponsGot;
2019
bool m_GoresServer;
2120

2221
// Reply to Ping
@@ -63,16 +62,16 @@ class CEClient : public CComponent
6362

6463
static void ConCrash(IConsole::IResult *pResult, void *pUserData);
6564

66-
static void ConchainGoresMode(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
6765
static void ConchainFastInputs(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
6866
static void ConchainDiscordUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
69-
67+
7068
static void ConchainDDNetProcessPriority(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
7169
static void ConchainDiscordProcessPriority(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
7270

7371
static void DiscordPriorityThread(void *pUserData);
7472

7573
public:
74+
bool m_WeaponsGot;
7675
int m_KillCount;
7776

7877
void Votekick(const char *pName, const char *pReason);
@@ -120,10 +119,6 @@ class CEClient : public CComponent
120119

121120
void GoresMode();
122121

123-
void GoresModeSave();
124-
void GoresModeRestore();
125-
void ToggleGoresMode(bool Value);
126-
127122
int64_t m_JoinTeam;
128123
void AutoJoinTeam();
129124
void OnConnect();

src/game/client/components/entity/menus_entity.cpp

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,43 +2589,10 @@ void CMenus::RenderSettingsEClient(CUIRect MainView)
25892589
GoresMode.HSplitTop(HeaderHeight, &Button, &GoresMode);
25902590
Ui()->DoLabel(&Button, Localize("Gores Mode"), HeaderSize, HeaderAlignment);
25912591

2592-
if(DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClGoresMode, ("\"advanced\" Gores Mode"), &g_Config.m_ClGoresMode, &GoresMode, LineSize))
2593-
GameClient()->m_EClient.ToggleGoresMode(g_Config.m_ClGoresMode);
2592+
DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClGoresMode, ("\"advanced\" Gores Mode"), &g_Config.m_ClGoresMode, &GoresMode, LineSize);
25942593

25952594
DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClGoresModeDisableIfWeapons, ("Disable if You Have Any Weapon"), &g_Config.m_ClGoresModeDisableIfWeapons, &GoresMode, LineSize);
25962595
DoButton_CheckBoxAutoVMarginAndSet(&g_Config.m_ClAutoEnableGoresMode, ("Auto Enable if Gametype is \"Gores\""), &g_Config.m_ClAutoEnableGoresMode, &GoresMode, LineSize);
2597-
2598-
// Key Reader for Gores Mode
2599-
{
2600-
static CBindSlot s_GoresBind(g_Config.m_ClGoresModeKey, 0);
2601-
if(s_GoresBind.m_Key != g_Config.m_ClGoresModeKey)
2602-
s_GoresBind.m_Key = g_Config.m_ClGoresModeKey;
2603-
2604-
const char *pText = Localize("Gores Mode Key:");
2605-
float Length = TextRender()->TextBoundingBox(FontSize, pText).m_W + 3.5f;
2606-
CUIRect KeyLabel, KeyButton;
2607-
GoresMode.HSplitTop(LineSize, &KeyButton, &GoresMode);
2608-
KeyButton.VSplitLeft(Length, &KeyLabel, &KeyButton);
2609-
2610-
Ui()->DoLabel(&KeyLabel, pText, 14.0f, TEXTALIGN_ML);
2611-
2612-
static CButtonContainer s_ReaderButtonGores;
2613-
const auto Result = GameClient()->m_KeyBinder.DoKeyReader(&s_ReaderButtonGores, &KeyButton, s_GoresBind, false);
2614-
2615-
if(Result.m_Bind != s_GoresBind)
2616-
{
2617-
GameClient()->m_EClient.GoresModeRestore();
2618-
2619-
if(Result.m_Bind.m_Key == KEY_UNKNOWN)
2620-
g_Config.m_ClGoresModeKey = KEY_UNKNOWN;
2621-
else
2622-
{
2623-
s_GoresBind = Result.m_Bind;
2624-
g_Config.m_ClGoresModeKey = s_GoresBind.m_Key;
2625-
}
2626-
GameClient()->m_EClient.GoresModeSave();
2627-
}
2628-
}
26292596
}
26302597
}
26312598

0 commit comments

Comments
 (0)