From e2d0cbf772d355d550916cd6e6aa617663d3d23b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 23 Oct 2022 14:46:23 +0200 Subject: [PATCH] - allow entering cheats in the chat editor without using '#'. --- source/core/cheathandler.cpp | 19 +++++++++++++------ source/core/cheathandler.h | 4 ++-- source/core/ct_chat.cpp | 4 +++- source/core/uiinput.h | 2 +- source/games/duke/src/cheats.cpp | 23 ----------------------- 5 files changed, 19 insertions(+), 33 deletions(-) diff --git a/source/core/cheathandler.cpp b/source/core/cheathandler.cpp index 5d3ee95f2..336f1a619 100644 --- a/source/core/cheathandler.cpp +++ b/source/core/cheathandler.cpp @@ -101,9 +101,9 @@ static bool CheatAddKey (cheatseq_t *cheat, uint8_t key, bool *eat) // //-------------------------------------------------------------------------- -bool Cheat_Responder (event_t *ev) +int Cheat_Responder (event_t *ev) { - bool eat = false; + bool eat = false, done = false; if (nocheats) { @@ -120,11 +120,11 @@ bool Cheat_Responder (event_t *ev) { if (cheats->DontCheck || !CheckCheatmode ()) { + done = true; if (cheats->Handler) eat |= cheats->Handler (cheats); else if (cheats->ccmd) { - eat = true; C_DoCommand(cheats->ccmd); } } @@ -136,7 +136,7 @@ bool Cheat_Responder (event_t *ev) } } } - return eat; + return done? -1 : eat? 1 : 0; } bool SendGenericCheat(cheatseq_t* cheat) @@ -146,8 +146,9 @@ bool SendGenericCheat(cheatseq_t* cheat) return true; } -void PlaybackCheat(const char *p) +bool PlaybackCheat(const char *p) { + bool success = false; if (!CheckCheatmode(true)) { event_t ev = { EV_KeyDown, 0, 0, -1 }; @@ -156,11 +157,17 @@ void PlaybackCheat(const char *p) { // just play the cheat command through the event parser ev.data2 = *p; - Cheat_Responder(&ev); + int result = Cheat_Responder(&ev); + if (result == -1) + { + success = true; + break; + } } ev.data2 = -1; Cheat_Responder(&ev); } + return success; } CCMD(activatecheat) diff --git a/source/core/cheathandler.h b/source/core/cheathandler.h index 0c201a230..ca1872587 100644 --- a/source/core/cheathandler.h +++ b/source/core/cheathandler.h @@ -14,8 +14,8 @@ struct cheatseq_t }; struct event_t; -bool Cheat_Responder(event_t* ev); +int Cheat_Responder(event_t* ev); void SetCheats(cheatseq_t *cht, int count); -void PlaybackCheat(const char* p); +bool PlaybackCheat(const char* p); bool SendGenericCheat(cheatseq_t* cheat); diff --git a/source/core/ct_chat.cpp b/source/core/ct_chat.cpp index ec353c377..2320948fe 100644 --- a/source/core/ct_chat.cpp +++ b/source/core/ct_chat.cpp @@ -52,6 +52,7 @@ #include "gamestruct.h" #include "gamecvars.h" #include "menustate.h" +#include "cheathandler.h" enum { @@ -326,10 +327,11 @@ static void ShoveChatStr (const char *str, uint8_t who) if (*str == '#') { - C_DoCommand(FStringf("activatecheat \"%s\"", str + 1)); + PlaybackCheat(str + 1); } else { + if (PlaybackCheat(str)) return; #if 0 FString substBuff; diff --git a/source/core/uiinput.h b/source/core/uiinput.h index 8dd4f49ae..044dcf5d7 100644 --- a/source/core/uiinput.h +++ b/source/core/uiinput.h @@ -8,5 +8,5 @@ struct event; void CT_Init (void); bool CT_Responder (event_t* ev); void CT_Drawer (void); -bool Cheat_Responder (event_t* ev); +int Cheat_Responder (event_t* ev); \ No newline at end of file diff --git a/source/games/duke/src/cheats.cpp b/source/games/duke/src/cheats.cpp index f1c36ff4b..b74db5e30 100644 --- a/source/games/duke/src/cheats.cpp +++ b/source/games/duke/src/cheats.cpp @@ -359,30 +359,7 @@ static bool cheatGary(cheatseq_t *) } static cheatseq_t dukecheats[] = { - { "dncornholio", nullptr, SendGenericCheat, 0, CHT_GOD }, - { "dnstuff", "give all", }, { "dnscotty###", nullptr, cheatLevel }, // -> levelwarp - { "dncoords", "stat coord", nullptr, 1 }, - { "dnview", "third_person_view",nullptr, 1 }, - { "dntime", "stat fps", nullptr, 1 }, - { "dnunlock", nullptr, SendGenericCheat, 0, CHT_UNLOCK }, - { "dncashman", nullptr, SendGenericCheat, 0, CHT_CASHMAN }, - { "dnitems", "give items", }, - { "dnrate", "toggle vid_fps", nullptr, 1 }, - { "dnskill#", nullptr, cheatSkill }, // restartmap - { "dnbeta", nullptr, cheatBeta }, - { "dnhyper", nullptr, SendGenericCheat, 0, CHT_HYPER }, - { "dnmonsters", nullptr, SendGenericCheat, 0, CHT_MONSTERS }, - { "dntodd", nullptr, cheatTodd }, - { "dnshowmap", nullptr, cheatMap }, - { "dnkroz", nullptr, SendGenericCheat, 0, CHT_GOD }, - { "dnallen", nullptr, cheatAllen }, - { "dnclip", nullptr, SendGenericCheat, 0, CHT_NOCLIP }, - { "dnweapons", "give weapons" }, - { "dninventory", "give inventory" }, - { "dnkeys", "give keys" }, - { "dndebug", nullptr, cheatDebug, 1 }, - { "dncgs", nullptr, SendGenericCheat, 0, CHT_KILL }, }; static cheatseq_t ww2cheats[] =