Skip to content

Commit

Permalink
add check of whether level is loaded before processing command
Browse files Browse the repository at this point in the history
  • Loading branch information
GooberRF authored and rafalh committed Oct 16, 2024
1 parent 6247aad commit 160dbf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
-----------------------------------
Expand Down
14 changes: 14 additions & 0 deletions game_patch/os/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <common/utils/list-utils.h>
#include <algorithm>
#include <patch_common/CallHook.h>
#include <patch_common/FunHook.h>
#include <patch_common/AsmWriter.h>

ConsoleCommand2 dot_cmd{
Expand Down Expand Up @@ -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<void()> 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<std::unique_ptr<rf::console::Command>> builtin_commands;
Expand Down Expand Up @@ -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();
}

0 comments on commit 160dbf8

Please sign in to comment.