diff --git a/include/menu/ncc/List.hpp b/include/menu/ncc/List.hpp index d2eb5042..ecd9acad 100755 --- a/include/menu/ncc/List.hpp +++ b/include/menu/ncc/List.hpp @@ -28,6 +28,8 @@ public: void FillWithCatVars(std::vector vec); void OpenSublist(List *sublist, int dy); bool ShouldClose(); + static void ShowInvalidCatVars(); + static void ShowMissingCatVars(); static List *FromString(const std::string &string); @@ -48,6 +50,20 @@ public: List *open_sublist{ nullptr }; std::string title; }; +class DecoyCatVar +{ + CatVar_t type{ CV_SWITCH }; + const std::string name; + int defaults{ 0 }; + const std::string desc_short{ "" }; + const std::string desc_long{ "INVALID COMMAND" }; + bool registered{ false }; + +public: + DecoyCatVar(const std::string value) : desc_short(value) + { + } +}; } } #endif diff --git a/src/menu/GUI.cpp b/src/menu/GUI.cpp index 6be2b76a..e02d5d97 100755 --- a/src/menu/GUI.cpp +++ b/src/menu/GUI.cpp @@ -37,8 +37,10 @@ CatVar gui_visible(CV_SWITCH, "gui_visible", "0", "GUI Active", "GUI switch (bind it to a key!)"); CatVar gui_draw_bounds(CV_SWITCH, "gui_bounds", "0", "Draw Bounds", "Draw GUI elements' bounding boxes"); -// CatVar gui_nullcore(CV_SWITCH, "gui_nullcore", "1", "NullCore GUI", "Use -// NullCoreCheat GUI"); +CatCommand debug_invalid("debug_invalid", "Display all invalid CatVars", + []() { menu::ncc::List::ShowInvalidCatVars(); }); +CatCommand debug_missing("debug_missing", "Display all missing CatVars", + []() { menu::ncc::List::ShowMissingCatVars(); }); CatGUI::CatGUI() { @@ -76,6 +78,7 @@ int NCGUIColor() void CatGUI::Setup() { menu::ncc::Init(); + menu::ncc::List::ShowInvalidCatVars(); root_nullcore = menu::ncc::root; gui_visible.OnRegister([](CatVar *var) { var->convar->InstallChangeCallback(GUIVisibleCallback); diff --git a/src/menu/ncc/ItemVariable.cpp b/src/menu/ncc/ItemVariable.cpp index 7fb19021..1d092554 100755 --- a/src/menu/ncc/ItemVariable.cpp +++ b/src/menu/ncc/ItemVariable.cpp @@ -40,7 +40,8 @@ void ItemVariable::Change(float amount) { case CV_SWITCH: { - catvar = !catvar; + if (catvar.desc_long != "INVALID COMMAND") + catvar = !catvar; } break; case CV_ENUM: @@ -89,7 +90,8 @@ void ItemVariable::OnMousePress() capturing = true; } if (catvar.type == CV_SWITCH) - catvar = !catvar; + if (catvar.desc_long != "INVALID COMMAND") + catvar = !catvar; } void ItemVariable::OnFocusLose() @@ -107,7 +109,7 @@ void ItemVariable::OnKeyPress(ButtonCode_t key, bool repeat) if (capturing) { if (key == ButtonCode_t::KEY_ESCAPE) - key = (ButtonCode_t) 0; + key = (ButtonCode_t) 0; catvar = (int) key; capturing = false; return; @@ -159,10 +161,10 @@ void ItemVariable::OnKeyPress(ButtonCode_t key, bool repeat) if (key == ButtonCode_t::MOUSE_WHEEL_UP) { - if (catvar.type == CV_FLOAT && + if ((catvar.type == CV_FLOAT || catvar.type == CV_INT) && g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_LSHIFT)) Change(change * 2); - else if (catvar.type == CV_FLOAT && + else if ((catvar.type == CV_FLOAT || catvar.type == CV_INT) && g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_LCONTROL)) Change(change / 4); else @@ -189,7 +191,8 @@ void ItemVariable::Draw(int x, int y) { case CV_SWITCH: { - val = catvar ? "ON" : "OFF"; + if (catvar.desc_long != "INVALID COMMAND") + val = catvar ? "ON" : "OFF"; } break; case CV_INT: diff --git a/src/menu/ncc/List.cpp b/src/menu/ncc/List.cpp index 14146321..6a5c23b6 100755 --- a/src/menu/ncc/List.cpp +++ b/src/menu/ncc/List.cpp @@ -18,6 +18,7 @@ namespace menu { namespace ncc { +std::vector invalidvars, missingvars, menu_vars; List::List(std::string title) : open_sublist(nullptr), title(title), got_mouse(false), @@ -100,8 +101,51 @@ CatVar *FindCatVar(const std::string name) if (var->name == name) return var; } - logging::Info("can't find %s", name.c_str()); - throw std::runtime_error("can't find catvar " + name); + invalidvars.push_back(name); + DecoyCatVar *unknownvar = + new DecoyCatVar(format("Error, can't find ", name)); + logging::Info("Can't find %s", name.c_str()); + return (CatVar *) unknownvar; +} + +void FindMissingCatVars() +{ + for (auto var : CatVarList()) + { + if (std::find(menu_vars.begin(), menu_vars.end(), var->name) == + menu_vars.end()) + missingvars.push_back(var->name); + } +} + +void List::ShowInvalidCatVars() +{ + if (invalidvars.size()) + { + g_ICvar->ConsolePrintf("The following CatVars are invalid\n"); + for (int i = 0; i < invalidvars.size(); i++) + g_ICvar->ConsolePrintf("%s\n", invalidvars[i].c_str()); + } + else + g_ICvar->ConsolePrintf("No CatVars are invalid\n"); + static bool init = false; + if (!init) + { + FindMissingCatVars(); + init = true; + } +} + +void List::ShowMissingCatVars() +{ + if (missingvars.size()) + { + g_ICvar->ConsolePrintf("The following CatVars are missing\n"); + for (int i = 0; i < missingvars.size(); i++) + g_ICvar->ConsolePrintf("%s\n", missingvars[i].c_str()); + } + else + g_ICvar->ConsolePrintf("No CatVars are missing\n"); } // abc def, ghj, [, fdg sgf saqw rter, ], gs void FillFromTokens(List *list, const std::vector &tokens) @@ -114,6 +158,7 @@ void FillFromTokens(List *list, const std::vector &tokens) if (i == tokens.size() - 1 || tokens[i + 1] != "[") { list->AddChild(new ItemVariable(*FindCatVar(str))); + menu_vars.push_back(str); } else {