fix(commands): fix crashes on invalid commands (#1081)

This commit is contained in:
Johann 2023-03-13 09:26:04 +01:00 committed by GitHub
parent 11c0c2ab2f
commit cb23e221b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,9 @@ namespace big
static void command_button(const std::vector<std::uint64_t> args = {}, std::optional<const std::string_view> label_override = std::nullopt)
{
static command* command = command::get(rage::consteval_joaat(cmd_str.value));
if (command == nullptr)
return ImGui::Text("INVALID COMMAND");
if (ImGui::Button(label_override.value_or(command->get_label()).data()))
command->call(args);
if (ImGui::IsItemHovered())
@ -45,6 +48,9 @@ namespace big
static void player_command_button(player_ptr player = g_player_service->get_selected(), const std::vector<std::uint64_t> args = {}, std::optional<const std::string_view> label_override = std::nullopt)
{
static player_command* command = (player_command*)command::get(rage::consteval_joaat(cmd_str.value));
if (command == nullptr)
return ImGui::Text("INVALID COMMAND");
if (ImGui::Button(label_override.value_or(command->get_label()).data()))
command->call(player, args);
if (ImGui::IsItemHovered())
@ -55,6 +61,9 @@ namespace big
static void command_checkbox(std::optional<const std::string_view> label_override = std::nullopt)
{
static bool_command* command = (bool_command*)command::get(rage::consteval_joaat(cmd_str.value));
if (command == nullptr)
return ImGui::Text("INVALID COMMAND");
if (ImGui::Checkbox(label_override.value_or(command->get_label()).data(), &command->is_enabled()))
command->refresh();
if (ImGui::IsItemHovered())