prevent crashes/show missing items

This commit is contained in:
Lighty 2018-04-19 15:20:16 +02:00
parent aed4d8cb79
commit ff731fffaf
4 changed files with 77 additions and 10 deletions

View File

@ -28,6 +28,8 @@ public:
void FillWithCatVars(std::vector<CatVar *> 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

View File

@ -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);

View File

@ -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:

View File

@ -18,6 +18,7 @@ namespace menu
{
namespace ncc
{
std::vector<std::string> 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<std::string> &tokens)
@ -114,6 +158,7 @@ void FillFromTokens(List *list, const std::vector<std::string> &tokens)
if (i == tokens.size() - 1 || tokens[i + 1] != "[")
{
list->AddChild(new ItemVariable(*FindCatVar(str)));
menu_vars.push_back(str);
}
else
{