From b4232ef4c14fccba4c82fd3f70ce6d30f1d372c0 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sun, 13 Mar 2022 15:27:02 +0100 Subject: [PATCH] Revert "Fix" This reverts commit 39fa6db1fb9e9e50c91a5be06be24696f8fc2ea3. --- src/client/component/game_console.cpp | 103 +++++++++++++------------- src/client/component/game_console.hpp | 6 +- 2 files changed, 56 insertions(+), 53 deletions(-) diff --git a/src/client/component/game_console.cpp b/src/client/component/game_console.cpp index deec2813..1e5ce400 100644 --- a/src/client/component/game_console.cpp +++ b/src/client/component/game_console.cpp @@ -177,58 +177,6 @@ namespace game_console game::R_AddCmdDrawText(text, 0x7FFFFFFF, console_font, con.globals.x + offset_x, _y, 1.0f, 1.0f, 0.0f, color, 0); } - bool match_compare(const std::string& input, const std::string& text, const bool exact) - { - if (exact && text == input) return true; - if (!exact && text.find(input) != std::string::npos) return true; - return false; - } - - void find_matches(std::string input, std::vector& suggestions, const bool exact) - { - input = utils::string::to_lower(input); - - for (const auto& dvar : dvars::dvar_list) - { - auto name = utils::string::to_lower(dvar.name); - if (game::Dvar_FindVar(name.data()) && match_compare(input, name, exact)) - { - suggestions.push_back(dvar); - } - - if (exact && suggestions.size() > 1) - { - return; - } - } - - if (suggestions.size() == 0 && game::Dvar_FindVar(input.data())) - { - suggestions.push_back({input.data(), ""}); - } - - game::cmd_function_s* cmd = (*game::cmd_functions); - while (cmd) - { - if (cmd->name) - { - std::string name = utils::string::to_lower(cmd->name); - - if (match_compare(input, name, exact)) - { - suggestions.push_back({cmd->name, ""}); - } - - if (exact && suggestions.size() > 1) - { - return; - } - } - - cmd = cmd->next; - } - } - void draw_input() { con.globals.font_height = static_cast(console_font->pixelHeight); @@ -718,6 +666,57 @@ namespace game_console return true; } + bool match_compare(const std::string& input, const std::string& text, const bool exact) + { + if (exact && text == input) return true; + if (!exact && text.find(input) != std::string::npos) return true; + return false; + } + + void find_matches(std::string input, std::vector& suggestions, const bool exact) + { + input = utils::string::to_lower(input); + + for (const auto& dvar : dvars::dvar_list) + { + auto name = utils::string::to_lower(dvar.name); + if (game::Dvar_FindVar(name.data()) && match_compare(input, name, exact)) + { + suggestions.push_back(dvar); + } + + if (exact && suggestions.size() > 1) + { + return; + } + } + + if (suggestions.size() == 0 && game::Dvar_FindVar(input.data())) + { + suggestions.push_back({ input.data(), "" }); + } + + game::cmd_function_s* cmd = (*game::cmd_functions); + while (cmd) + { + if (cmd->name) + { + std::string name = utils::string::to_lower(cmd->name); + + if (match_compare(input, name, exact)) + { + suggestions.push_back({ cmd->name, "" }); + } + + if (exact && suggestions.size() > 1) + { + return; + } + } + + cmd = cmd->next; + } + } class component final : public component_interface { diff --git a/src/client/component/game_console.hpp b/src/client/component/game_console.hpp index cdc001a7..0e5a1ca1 100644 --- a/src/client/component/game_console.hpp +++ b/src/client/component/game_console.hpp @@ -1,7 +1,11 @@ #pragma once +#include "game/dvars.hpp" namespace game_console { bool console_char_event(int local_client_num, int key); bool console_key_event(int local_client_num, int key, int down); -} \ No newline at end of file + + bool match_compare(const std::string& input, const std::string& text, const bool exact); + void find_matches(std::string input, std::vector& suggestions, const bool exact); +}