diff --git a/Plugins/Tweaks/BlockDMConsoleCommands.cpp b/Plugins/Tweaks/BlockDMConsoleCommands.cpp new file mode 100644 index 00000000000..123a830ee17 --- /dev/null +++ b/Plugins/Tweaks/BlockDMConsoleCommands.cpp @@ -0,0 +1,44 @@ +#include "nwnx.hpp" + + +namespace Tweaks { + +using namespace NWNXLib; +using namespace NWNXLib::API; + + +void BlockDMConsoleCommands() __attribute__((constructor)); +void BlockDMConsoleCommands() +{ + static const auto SPAWN_CREATURE_DISABLED = Config::Get("BLOCK_DM_SPAWNCREATURE", false); + static const auto SPAWN_ITEM_DISABLED = Config::Get("BLOCK_DM_SPAWNITEM", false); + + + if (!SPAWN_CREATURE_DISABLED || !SPAWN_ITEM_DISABLED) + return; + + if (SPAWN_ITEM_DISABLED) + LOG_INFO("Blocking the 'dm_spawnitem' console command."); + if (SPAWN_CREATURE_DISABLED) + LOG_INFO("Blocking the 'dm_spawncreature' console command."); + + static Hooks::Hook s_HandlePlayerToServerGameObjectUpdateHook = + Hooks::HookFunction(Functions::_ZN11CNWSMessage36HandlePlayerToServerGameObjectUpdateEP10CNWSPlayerh, + (void*)+[](CNWSMessage *pMessage, CNWSPlayer *pPlayer, uint8_t nMinor) -> int32_t + { + // The message types defining the dm command type + const auto MSGTYPE_SPAWN_CREATURE = 67; + const auto MSGTYPE_SPAWN_ITEM = 65; + auto nMsgType = Utils::PeekMessage(pMessage, 0); + + LOG_DEBUG("BlockDMConsoleCommands: nMinor: %i, nMsgType: %i", nMinor, nMsgType); + + if ((nMinor == 1 && nMsgType == MSGTYPE_SPAWN_CREATURE && SPAWN_CREATURE_DISABLED) || // dm_spawnitem + (nMinor == 1 && nMsgType == MSGTYPE_SPAWN_ITEM && SPAWN_ITEM_DISABLED)) // dm_spawncreature + return false; + else + return s_HandlePlayerToServerGameObjectUpdateHook->CallOriginal(pMessage, pPlayer, nMinor); + }, Hooks::Order::Late); + } + +} diff --git a/Plugins/Tweaks/BlockDMSpawnItem.cpp b/Plugins/Tweaks/BlockDMSpawnItem.cpp deleted file mode 100644 index 5a5555e96fa..00000000000 --- a/Plugins/Tweaks/BlockDMSpawnItem.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "nwnx.hpp" - - -namespace Tweaks { - -using namespace NWNXLib; -using namespace NWNXLib::API; - - -void BlockDMSpawnItem() __attribute__((constructor)); -void BlockDMSpawnItem() -{ - if (!Config::Get("BLOCK_DM_SPAWNITEM", false)) - return; - - LOG_INFO("Blocking the 'dm_spawnitem' console command."); - - static Hooks::Hook s_HandlePlayerToServerGameObjectUpdateHook = - Hooks::HookFunction(Functions::_ZN11CNWSMessage36HandlePlayerToServerGameObjectUpdateEP10CNWSPlayerh, - (void*)+[](CNWSMessage *pMessage, CNWSPlayer *pPlayer, uint8_t nMinor) -> int32_t - { - auto nMsgType = Utils::PeekMessage(pMessage, 0); - - LOG_DEBUG("BlockDMSpawnItem: nMinor: %i, nMsgType: %i", nMinor, nMsgType); - - // TODO: add these as constants sometime - if (nMinor == 1 && nMsgType == 65) // dm_spawnitem - return false; - else - return s_HandlePlayerToServerGameObjectUpdateHook->CallOriginal(pMessage, pPlayer, nMinor); - }, Hooks::Order::Late); -} - -} diff --git a/Plugins/Tweaks/CMakeLists.txt b/Plugins/Tweaks/CMakeLists.txt index eaa03901ac7..a20b1e3c363 100644 --- a/Plugins/Tweaks/CMakeLists.txt +++ b/Plugins/Tweaks/CMakeLists.txt @@ -1,7 +1,7 @@ add_plugin(Tweaks "AddPrestigeclassCasterLevels.cpp" "AlwaysReturnFullDEXStat.cpp" - "BlockDMSpawnItem.cpp" + "BlockDMConsoleCommands.cpp" "ClearSpellEffectsOnTURDs.cpp" "CompareVarsForMerge.cpp" "DeadCreatureFiresOnAreaExit.cpp" diff --git a/Plugins/Tweaks/README.md b/Plugins/Tweaks/README.md index 35d2da40cd5..cc930452fcc 100644 --- a/Plugins/Tweaks/README.md +++ b/Plugins/Tweaks/README.md @@ -28,6 +28,7 @@ Tweaks stuff. See below. | `NWNX_TWEAKS_FIX_UNLIMITED_POTIONS_BUG` | true or false | Fixes a bug where scrolls/potions could have unlimited uses. | | `NWNX_TWEAKS_UNHARDCODE_SHIELDS` | true or false | baseitems.2da will be used to define shield AC for shields and shield-like items. | | `NWNX_TWEAKS_BLOCK_DM_SPAWNITEM` | true or false | Disables the dm_spawnitem console command. | +| `NWNX_TWEAKS_BLOCK_DM_SPAWNCREATURE` | true or false | Disables the dm_spawncreature console command. | | `NWNX_TWEAKS_FIX_ARMOR_DEX_BONUS_UNDER_ONE` | true or false | Allows armor with a max DEX bonus of under 1. | | `NWNX_TWEAKS_FIX_ITEM_NULLPTR_IN_CITEMREPOSITORY` | true or false | Fixes a (rare?) inventory crash bug. | | `NWNX_TWEAKS_CLEAR_SPELL_EFFECTS_ON_TURDS` | true or false | Effects on logged out player characters will be removed when a caster rests. |