Skip to content

Commit e8d29f8

Browse files
Moved the knockback code to a separate thread
1 parent 0a93720 commit e8d29f8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Hayzen/src/Games/MW2/MenuFunctions.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ void MW2MenuFunctions::SpawnCP(Menu *pMenu)
123123
SV_LinkEntity(entity);
124124
}
125125

126-
void MW2MenuFunctions::Knockback(Menu *pMenu)
126+
// Threaded function that prompts a keyboard and sets the knockback strength to what was entered.
127+
static DWORD KnockbackThread(Menu *pMenu)
127128
{
128129
// Get the value from the user via the virtual keyboard
129130
std::string strValue = Xam::ShowKeyboard("Knockback", "Recommended value: 30000", "30000", 6, VKBD_LATIN_NUMERIC);
@@ -136,6 +137,16 @@ void MW2MenuFunctions::Knockback(Menu *pMenu)
136137
SetClientDvar(-1, "g_knockback", strValue);
137138

138139
iPrintLn(pMenu->GetClientNum(), "Knockback set to ^2" + strValue);
140+
141+
return 0;
142+
}
143+
144+
void MW2MenuFunctions::Knockback(Menu *pMenu)
145+
{
146+
// This needs to execute on a separate thread because we need to wait for the user
147+
// to finish typing. If this wasn't done on a separate thread, it would block the
148+
// game's thread and make it crash.
149+
Memory::Thread(reinterpret_cast<PTHREAD_START_ROUTINE>(KnockbackThread), pMenu);
139150
}
140151

141152
void MW2MenuFunctions::ToggleSaveLoadBinds(Menu *pMenu)

0 commit comments

Comments
 (0)