diff --git a/source/blood/src/messages.cpp b/source/blood/src/messages.cpp index e540002f7..5208453a4 100644 --- a/source/blood/src/messages.cpp +++ b/source/blood/src/messages.cpp @@ -38,6 +38,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "gstrings.h" #include "cheathandler.h" #include "d_protocol.h" +#include "gamestate.h" BEGIN_BLD_NS @@ -288,10 +289,14 @@ static int parseArgs(char *pzArgs, int *nArg1, int *nArg2) const char* GameInterface::GenericCheat(int player, int cheat) { // message processing is not perfect because many cheats output multiple messages. - if (gGameOptions.nGameType != 0) // sp only for now. - return nullptr; - int nEpisode, nLevel; + if (gGameOptions.nGameType != 0 || numplayers > 1) // sp only for now. + return nullptr; + + if (gamestate != GS_LEVEL || gMe->pXSprite->health == 0) // must be alive and in a level to cheat. + return nullptr; + + bPlayerCheated = true; switch (cheat) { case CHT_GOD: @@ -479,7 +484,6 @@ static cheatseq_t s_CheatInfo[] = { //{"SPIELBERG", nullptr, doCheatpXSprite->health == 0) + { + Printf("give: Cannot give while dead or not in a single-player game.\n"); + return; + } + + switch (type) + { + case GIVE_ALL: + SetWeapons(true); + SetAmmo(true); + SetToys(true); + SetArmor(true); + SetKeys(true); + bPlayerCheated = true; + break; + + case GIVE_HEALTH: + actHealDude(gMe->pXSprite, 200, 200); + bPlayerCheated = true; + break; + + case GIVE_WEAPONS: + SetWeapons(true); + bPlayerCheated = true; + break; + + case GIVE_AMMO: + SetAmmo(true); + bPlayerCheated = true; + break; + + case GIVE_ARMOR: + SetArmor(true); + bPlayerCheated = true; + break; + + case GIVE_KEYS: + SetKeys(true); + bPlayerCheated = true; + break; + + case GIVE_INVENTORY: + SetToys(true); + bPlayerCheated = true; + break; + + default: + break; + } +} + + class MessagesLoadSave : public LoadSave { public: @@ -517,6 +580,7 @@ void MessagesLoadSaveConstruct(void) void InitCheats() { SetCheats(s_CheatInfo, countof(s_CheatInfo)); + Net_SetCommandHandler(DEM_GIVE, cmd_Give); } END_BLD_NS diff --git a/source/blood/src/osdcmd.cpp b/source/blood/src/osdcmd.cpp index 41344ea7c..2afd61da2 100644 --- a/source/blood/src/osdcmd.cpp +++ b/source/blood/src/osdcmd.cpp @@ -70,65 +70,6 @@ static int osdcmd_map(CCmdFuncPtr parm) } -static int osdcmd_give(CCmdFuncPtr parm) -{ - if (numplayers != 1 || gamestate != GS_LEVEL|| gMe->pXSprite->health == 0) - { - Printf("give: Cannot give while dead or not in a single-player game.\n"); - return CCMD_OK; - } - - if (parm->numparms != 1) return CCMD_SHOWHELP; - - if (!Bstrcasecmp(parm->parms[0], "all")) - { - SetWeapons(true); - SetAmmo(true); - SetToys(true); - SetArmor(true); - SetKeys(true); - bPlayerCheated = true; - return CCMD_OK; - } - else if (!Bstrcasecmp(parm->parms[0], "health")) - { - actHealDude(gMe->pXSprite, 200, 200); - bPlayerCheated = true; - return CCMD_OK; - } - else if (!Bstrcasecmp(parm->parms[0], "weapons")) - { - SetWeapons(true); - bPlayerCheated = true; - return CCMD_OK; - } - else if (!Bstrcasecmp(parm->parms[0], "ammo")) - { - SetAmmo(true); - bPlayerCheated = true; - return CCMD_OK; - } - else if (!Bstrcasecmp(parm->parms[0], "armor")) - { - SetArmor(true); - bPlayerCheated = true; - return CCMD_OK; - } - else if (!Bstrcasecmp(parm->parms[0], "keys")) - { - SetKeys(true); - bPlayerCheated = true; - return CCMD_OK; - } - else if (!Bstrcasecmp(parm->parms[0], "inventory")) - { - SetToys(true); - bPlayerCheated = true; - return CCMD_OK; - } - return CCMD_SHOWHELP; -} - static int osdcmd_levelwarp(CCmdFuncPtr parm) { if (parm->numparms != 2) @@ -220,7 +161,6 @@ static int osdcmd_show_weapon(CCmdFuncPtr parm) int32_t registerosdcommands(void) { C_RegisterFunction("map","map : loads the given map", osdcmd_map); - C_RegisterFunction("give","give : gives requested item", osdcmd_give); C_RegisterFunction("levelwarp","levelwarp : warp to episode 'e' and map 'm'", osdcmd_levelwarp); C_RegisterFunction("warptocoords","warptocoords [x] [y] [z] [ang] (optional) [horiz] (optional): warps the player to the specified coordinates",osdcmd_warptocoords); C_RegisterFunction("third_person_view", "Switch to third person view", osdcmd_third_person_view); diff --git a/source/core/cheats.cpp b/source/core/cheats.cpp index 67560b5df..b1dcd1ef9 100644 --- a/source/core/cheats.cpp +++ b/source/core/cheats.cpp @@ -138,4 +138,32 @@ CCMD(allmap) gFullMap = !gFullMap; Printf("%s\n", GStrings(gFullMap ? "SHOW MAP: ON" : "SHOW MAP: OFF")); } +} + +CCMD(give) +{ + static const char* type[] = { "ALL","AMMO","ARMOR","HEALTH","INVENTORY","ITEMS","KEYS","WEAPONS",nullptr }; + if (argv.argc() < 2) + { + Printf("give : gives requested item\n"); + return; + } + size_t found = -1; + for (size_t i = 0; i < countof(type); i++) + { + if (!stricmp(argv[1], type[i])) + { + found = i; + break; + } + } + if (found == -1) + { + Printf("Unable to give %s\n", argv[1]); + } + if (!CheckCheatmode(true, true)) + { + Net_WriteByte(DEM_GIVE); + Net_WriteByte(found); + } } \ No newline at end of file diff --git a/source/core/d_protocol.h b/source/core/d_protocol.h index 2215e8d76..a7a924a8f 100644 --- a/source/core/d_protocol.h +++ b/source/core/d_protocol.h @@ -89,6 +89,8 @@ enum EDemoCommand DEM_USERCMD, DEM_EMPTYUSERCMD, DEM_GENERICCHEAT, + DEM_GIVE, + DEM_CHANGEMAP, DEM_MAX }; @@ -150,6 +152,18 @@ enum ECheat CHT_MAX }; +enum EGiveType +{ + GIVE_ALL, + GIVE_AMMO, + GIVE_ARMOR, + GIVE_HEALTH, + GIVE_INVENTORY, + GIVE_ITEMS, + GIVE_KEYS, + GIVE_WEAPONS +}; + typedef void(*NetCommandHandler)(int player, uint8_t **stream, bool skip); void Net_SetCommandHandler(EDemoCommand cmd, NetCommandHandler handler) noexcept; diff --git a/source/exhumed/src/osdcmds.cpp b/source/exhumed/src/osdcmds.cpp index 7ca015713..fce8a25ff 100644 --- a/source/exhumed/src/osdcmds.cpp +++ b/source/exhumed/src/osdcmds.cpp @@ -243,7 +243,7 @@ int32_t registerosdcommands(void) C_RegisterFunction("third_person_view", "Switch to third person view", osdcmd_third_person_view); C_RegisterFunction("coop_view", "Switch player to view from in coop", osdcmd_noop); C_RegisterFunction("show_weapon", "Show opponents' weapons", osdcmd_noop); - C_RegisterFunction("give", "give : gives requested item", ccmd_give); + //C_RegisterFunction("give", "give : gives requested item", ccmd_give); return 0; } diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index 77dd81bd9..7a7d0d840 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -312,7 +312,7 @@ int registerosdcommands(void) { C_RegisterFunction("map","map : warp to the given map, identified by its name", ccmd_map); C_RegisterFunction("levelwarp","levelwarp : warp to episode 'e' and map 'm'", ccmd_levelwarp); - C_RegisterFunction("give","give : gives requested item", ccmd_give); + //C_RegisterFunction("give","give : gives requested item", ccmd_give); C_RegisterFunction("restartmap", "restartmap: restarts the current map", ccmd_restartmap); C_RegisterFunction("spawn","spawn [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",ccmd_spawn); C_RegisterFunction("warptocoords","warptocoords [x] [y] [z] [ang] (optional) [horiz] (optional): warps the player to the specified coordinates",osdcmd_warptocoords); diff --git a/source/sw/src/cheats.cpp b/source/sw/src/cheats.cpp index f02ee7871..6d2bf2a38 100644 --- a/source/sw/src/cheats.cpp +++ b/source/sw/src/cheats.cpp @@ -56,7 +56,7 @@ static PLAYERp checkCheat(cheatseq_t* c) if (CommEnabled) return nullptr; - if (Skill >= 3 && !c->DontCheck && !sv_cheats) + if (Skill >= 3 && (!c || !c->DontCheck) && !sv_cheats) { PutStringInfo(&Player[screenpeek], GStrings("TXTS_TOOSKILLFUL")); return nullptr; @@ -409,28 +409,30 @@ bool EveryCheatToggle(cheatseq_t* c) { EveryCheat ^= 1; C_DoCommand("god"); - return WeaponCheat(c) && ItemCheat(c); + C_DoCommand("give weapons"); + C_DoCommand("give items"); + return true; } // The prefix was changed from 'sw' to 'lw' so that it doesn't contain two keys of the WASD control scheme, which interferes with input control. static cheatseq_t swcheats[] = { {"lwgod", "god" }, {"lwchan", "god" }, - {"lwgimme", nullptr, ItemCheat, 0}, - {"lwmedic", nullptr, HealCheat, 0}, + {"lwgimme", "give all" }, + {"lwmedic", "give health" }, {"lwkey#", nullptr, KeyCheat, 0}, - {"lwkeys", nullptr, KeysCheat, 0}, - {"lwammo", nullptr, AmmoCheat, 0}, - {"lwarmor", nullptr, ArmorCheat, 0}, - {"lwitems", nullptr, ItemCheat, 0}, - {"lwguns", nullptr, WeaponCheat, 0}, + {"lwkeys", "give keys" }, + {"lwammo", "give ammo" }, + {"lwarmor", "give armor" }, + {"lwitems", "give items" }, + {"lwguns", "give weapons" }, {"lwtrek##", nullptr, WarpCheat, 0}, {"lwgreed", nullptr, EveryCheatToggle, 0}, {"lwghost", "noclip" }, {"lwstart", nullptr, RestartCheat, 0}, {"lwloc", "stat coord", nullptr, true}, {"lwmap", nullptr, MapCheat, 0}, - {"lwroom", nullptr, RoomCheat, true}, // Room above room dbug + {"lwroom", nullptr, RoomCheat, true}, // Room above room debug }; diff --git a/source/sw/src/osdcmds.cpp b/source/sw/src/osdcmds.cpp index 91cdad340..0c4b95eb7 100644 --- a/source/sw/src/osdcmds.cpp +++ b/source/sw/src/osdcmds.cpp @@ -114,6 +114,15 @@ int osdcmd_levelwarp(CCmdFuncPtr parm) return CCMD_OK; } +struct cheatseq_t; +bool WeaponCheat(cheatseq_t* c); +bool AmmoCheat(cheatseq_t* c); +bool ItemCheat(cheatseq_t* c); +bool InventoryCheat(cheatseq_t* c); +bool ArmorCheat(cheatseq_t* c); +bool HealCheat(cheatseq_t* c); +bool KeysCheat(cheatseq_t* c); + static int osdcmd_give(CCmdFuncPtr parm) { @@ -123,37 +132,37 @@ static int osdcmd_give(CCmdFuncPtr parm) if (!stricmp(parm->parms[0], "all")) { - C_DoCommand("activatecheat lwgimme"); + ItemCheat(nullptr); return CCMD_OK; } else if (!stricmp(parm->parms[0], "health")) { - C_DoCommand("activatecheat lwmedic"); + HealCheat(nullptr); return CCMD_OK; } else if (!stricmp(parm->parms[0], "weapons")) { - C_DoCommand("activatecheat lwguns"); + WeaponCheat(nullptr); return CCMD_OK; } else if (!stricmp(parm->parms[0], "ammo")) { - C_DoCommand("activatecheat lwammo"); + AmmoCheat(nullptr); return CCMD_OK; } else if (!stricmp(parm->parms[0], "armor")) { - C_DoCommand("activatecheat lwarmor"); + ArmorCheat(nullptr); return CCMD_OK; } else if (!stricmp(parm->parms[0], "keys")) { - C_DoCommand("activatecheat lwkeys"); + KeysCheat(nullptr); return CCMD_OK; } else if (!stricmp(parm->parms[0], "inventory")) { - C_DoCommand("activatecheat lwitems"); + InventoryCheat(nullptr); return CCMD_OK; } return CCMD_SHOWHELP; @@ -271,7 +280,7 @@ static int osdcmd_noop(CCmdFuncPtr parm) int32_t registerosdcommands(void) { C_RegisterFunction("map","map : loads the given map", osdcmd_map); - C_RegisterFunction("give","give : gives requested item", osdcmd_give); + //C_RegisterFunction("give","give : gives requested item", osdcmd_give); C_RegisterFunction("mirror_debug", "mirror [mirrornum]: print mirror debug info", osdcmd_mirror); C_RegisterFunction("levelwarp", "levelwarp : warp to level", osdcmd_levelwarp); C_RegisterFunction("restartmap", "restartmap: restarts the current map", osdcmd_restartmap);