Skip to content

[WIP] Plugins/Tweak: added dm_spawncreature to blockable console commands #1338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Plugins/Tweaks/BlockDMConsoleCommands.cpp
Original file line number Diff line number Diff line change
@@ -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<bool>("BLOCK_DM_SPAWNCREATURE", false);
static const auto SPAWN_ITEM_DISABLED = Config::Get<bool>("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<uint8_t>(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<int32_t>(pMessage, pPlayer, nMinor);
}, Hooks::Order::Late);
}

}
34 changes: 0 additions & 34 deletions Plugins/Tweaks/BlockDMSpawnItem.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion Plugins/Tweaks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_plugin(Tweaks
"AddPrestigeclassCasterLevels.cpp"
"AlwaysReturnFullDEXStat.cpp"
"BlockDMSpawnItem.cpp"
"BlockDMConsoleCommands.cpp"
"ClearSpellEffectsOnTURDs.cpp"
"CompareVarsForMerge.cpp"
"DeadCreatureFiresOnAreaExit.cpp"
Expand Down
1 change: 1 addition & 0 deletions Plugins/Tweaks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down