From 160dbf83ef5b828a0e3cd4590a1fd22ab58fdb56 Mon Sep 17 00:00:00 2001 From: Goober Date: Wed, 16 Oct 2024 10:10:22 -0230 Subject: [PATCH] add check of whether level is loaded before processing command --- docs/CHANGELOG.md | 1 + game_patch/os/commands.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1c2cb258..e88023cd 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -43,6 +43,7 @@ Version 1.9.0 (not released yet) - Do not load unnecessary VPPs in dedicated server mode - Add level filename to "Level Initializing" console message - Properly handle WM_PAINT in dedicated server, may improve performance (DF bug) +- Fix crash when `verify_level` command is run without a level being loaded Version 1.8.0 (released 2022-09-17) ----------------------------------- diff --git a/game_patch/os/commands.cpp b/game_patch/os/commands.cpp index 5bfdf978..a1586ad8 100644 --- a/game_patch/os/commands.cpp +++ b/game_patch/os/commands.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include ConsoleCommand2 dot_cmd{ @@ -91,6 +92,18 @@ DcCommandAlias map_info_cmd{ level_info_cmd, }; +// only allow verify_level if a level is loaded (avoid a crash if command is run in menu) +FunHook verify_level_cmd_hook{ + 0x0045E1F0, + []() { + if (rf::level.flags & rf::LEVEL_LOADED) { + verify_level_cmd_hook.call_target(); + } else { + rf::console::print("No level loaded!"); + } + } +}; + static void register_builtin_command(const char* name, const char* description, uintptr_t addr) { static std::vector> builtin_commands; @@ -192,4 +205,5 @@ void console_commands_init() map_cmd.register_cmd(); level_info_cmd.register_cmd(); map_info_cmd.register_cmd(); + verify_level_cmd_hook.install(); }