Fixed invalid command crashing game (#3388)
Some checks failed
Nightly Build / Build Nightly (push) Has been skipped
Nightly Build / Recreate Release (push) Has been skipped
Nightly Build / Check Recent Commit (push) Failing after 4s

This commit is contained in:
DayibBaba 2024-07-20 12:26:51 +02:00 committed by GitHub
parent c1f68cb632
commit e2f9714e18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -9,6 +9,13 @@ namespace big
{ {
using player_command::player_command; using player_command::player_command;
std::string sterilized_name(std::string name)
{
string::operations::remove_whitespace(name);
string::operations::to_lower(name);
return name;
}
virtual std::optional<std::vector<std::string>> get_argument_suggestions(int arg) override virtual std::optional<std::vector<std::string>> get_argument_suggestions(int arg) override
{ {
if (arg == 1) if (arg == 1)
@ -26,7 +33,7 @@ namespace big
std::vector<std::string> suggestions; std::vector<std::string> suggestions;
for (auto& item : g_squad_spawner_service.m_templates) for (auto& item : g_squad_spawner_service.m_templates)
{ {
suggestions.push_back(item.m_name); suggestions.push_back(sterilized_name(item.m_name));
} }
return suggestions; return suggestions;
} }
@ -58,7 +65,7 @@ namespace big
int template_index = -1; int template_index = -1;
for (int i = 0; i < g_squad_spawner_service.m_templates.size(); i++) for (int i = 0; i < g_squad_spawner_service.m_templates.size(); i++)
{ {
if (g_squad_spawner_service.m_templates[i].m_name == args[1]) if (sterilized_name(g_squad_spawner_service.m_templates[i].m_name) == args[1])
{ {
template_index = i; template_index = i;
break; break;

View File

@ -598,11 +598,13 @@ namespace big
// set focus by default on input box // set focus by default on input box
ImGui::SetKeyboardFocusHere(0); ImGui::SetKeyboardFocusHere(0);
ImGui::SetNextItemWidth((screen_x * 0.5f) - 30.f); ImGui::SetNextItemWidth((screen_x * 0.5f) - 30.f);
s_buffer = serialized_buffer(command_buffer); // Update serialized buffer every frame s_buffer = serialized_buffer(command_buffer); // Update serialized buffer every frame
if (components::input_text_with_hint("", "CMD_EXECUTOR_TYPE_CMD"_T, command_buffer, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways, nullptr, input_callback)) if (components::input_text_with_hint("", "CMD_EXECUTOR_TYPE_CMD"_T, command_buffer, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways, nullptr, input_callback))
{ {
if (!s_buffer.get_command_of_index(cursor_pos))
return;
if (command::process(command_buffer, std::make_shared<default_command_context>(), false)) if (command::process(command_buffer, std::make_shared<default_command_context>(), false))
{ {
g.cmd_executor.enabled = false; g.cmd_executor.enabled = false;