From c735adba474486711d0ba62dcf6b518211f485c1 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Fri, 21 Feb 2025 12:59:55 +0100 Subject: [PATCH] tr2/commands: add /wireframe and /cheats Resolves #2500. --- docs/tr2/CHANGELOG.md | 2 ++ docs/tr2/COMMANDS.md | 20 ++++++++++----- src/tr2/game/console/cmd/easy_config.c | 34 ++++++++++++++++++++++++++ src/tr2/meson.build | 1 + 4 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 src/tr2/game/console/cmd/easy_config.c diff --git a/docs/tr2/CHANGELOG.md b/docs/tr2/CHANGELOG.md index 032e179ca..18d725cbe 100644 --- a/docs/tr2/CHANGELOG.md +++ b/docs/tr2/CHANGELOG.md @@ -1,4 +1,6 @@ ## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr2-0.9.2...develop) - ××××-××-×× +- added a `/cheats` console command +- added a `/wireframe` console command (#2500) - fixed smashed windows blocking enemy pathing after loading a save (#2535) ## [0.9.2](https://github.com/LostArtefacts/TRX/compare/tr2-0.9.1...tr2-0.9.2) - 2025-02-19 diff --git a/docs/tr2/COMMANDS.md b/docs/tr2/COMMANDS.md index e98cd9cfa..757776d46 100644 --- a/docs/tr2/COMMANDS.md +++ b/docs/tr2/COMMANDS.md @@ -16,8 +16,10 @@ Currently supported commands: - `/heal` Tough day, Lara? Heals our girl back to full health. -- `/fly` - Turns on the fly cheat. Why even walk? +- `/flip` + `/flip off` + `/flip on` + Switches the global flipmap on or off, turning the reality around you on its head. - `/give {item_name}` `/give {num} {item_name}` @@ -31,10 +33,16 @@ Currently supported commands: `/kill {enemy_type}` Tired of rats, spiders, tigers, Italian mafia and literally every living thing trying to spoil your adventure? This command instantly disposes of the nearest enemy, or kills them all at once. -- `/flip` - `/flip off` - `/flip on` - Switches the global flipmap on or off, turning the reality around you on its head. +- `/fly` + Turns on the fly cheat. Why even walk? + +- `/cheats on` + `/cheats off` + Enables or disables cheat keys. It's not like disabling them will make this console any less of a cheat. + +- `/wireframe on` + `/wireframe off` + Enables or disables the wireframe mode. Enter the debugging realm! - `/endlevel` Ends the current level. Ideal for speedruns. diff --git a/src/tr2/game/console/cmd/easy_config.c b/src/tr2/game/console/cmd/easy_config.c new file mode 100644 index 000000000..c350382d4 --- /dev/null +++ b/src/tr2/game/console/cmd/easy_config.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +typedef struct { + const char *prefix; + void *target; +} COMMAND_TO_OPTION_MAP; + +static COMMAND_TO_OPTION_MAP m_CommandToOptionMap[] = { + { "cheats", &g_Config.gameplay.enable_cheats }, + { "wireframe", &g_Config.rendering.enable_wireframe }, + { nullptr, nullptr }, +}; + +static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *ctx); + +static COMMAND_RESULT M_Entrypoint(const COMMAND_CONTEXT *const ctx) +{ + COMMAND_TO_OPTION_MAP *match = m_CommandToOptionMap; + while (match->target != nullptr) { + if (String_Equivalent(match->prefix, ctx->prefix)) { + return Console_Cmd_Config_Helper( + Console_Cmd_Config_GetOptionFromTarget(match->target), + ctx->args); + } + match++; + } + + return CR_FAILURE; +} + +REGISTER_CONSOLE_COMMAND("cheats|wireframe", M_Entrypoint) diff --git a/src/tr2/meson.build b/src/tr2/meson.build index 5fa475516..50307321b 100644 --- a/src/tr2/meson.build +++ b/src/tr2/meson.build @@ -94,6 +94,7 @@ sources = [ 'game/camera.c', 'game/clock.c', 'game/collide.c', + 'game/console/cmd/easy_config.c', 'game/console/common.c', 'game/creature.c', 'game/cutscene.c',