Skip to content

Commit

Permalink
Tweaks: add NWNX_TWEAKS_CUTSCENE_MODE_NO_TURD (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daztek authored Sep 25, 2024
1 parent 02bc1b1 commit 9fda84a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
- DotNET: Added `RequestFunctionHook`, `ReturnFunctionHook`.
- Events: Added events `NWNX_ON_SET_EXPERIENCE_{BEFORE|AFTER}` which fire when the XP of a player changes.
- NoStack: Added `NWNX_NOSTACK_IGNORE_SUPERNATURAL_INNATE` to ignore effects created by the Feat, Race and SkillRanks plugins when stacking.
- Tweaks: added `NWNX_TWEAKS_CUTSCENE_MODE_NO_TURD` to not drop a TURD when SetCutsceneMode() is called.

##### New Plugins
- Store: Enables getting and setting store data.
Expand Down
3 changes: 2 additions & 1 deletion Plugins/Tweaks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ add_plugin(Tweaks
"RangedWeaponsUseOnHitCastSpellItemProperties.cpp"
"CastAllOnHitCastSpellItemProperties.cpp"
"SetAreaCallsSetPosition.cpp"
"EquipUnequipEventTweaks.cpp")
"EquipUnequipEventTweaks.cpp"
"CutsceneModeNoTURD.cpp")
47 changes: 47 additions & 0 deletions Plugins/Tweaks/CutsceneModeNoTURD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "nwnx.hpp"

#include "API/CNWSModule.hpp"
#include "API/CNWSPlayer.hpp"
#include "API/CNWSVirtualMachineCommands.hpp"


namespace Tweaks {

using namespace NWNXLib;
using namespace NWNXLib::API;

static bool s_CutsceneModeNoTURD;

void CutsceneModeNoTURD() __attribute__((constructor));
void CutsceneModeNoTURD()
{
if (!Config::Get<bool>("CUTSCENE_MODE_NO_TURD", false))
return;

LOG_INFO("SetCutsceneMode() will not drop a TURD.");

static Hooks::Hook s_ExecuteCommandSetCutsceneModeHook = Hooks::HookFunction(&CNWSVirtualMachineCommands::ExecuteCommandSetCutsceneMode,
+[](CNWSVirtualMachineCommands *thisPtr, int32_t nCommandId, int32_t nParameters) -> int32_t
{
s_CutsceneModeNoTURD = true;
auto retVal = s_ExecuteCommandSetCutsceneModeHook->CallOriginal<int32_t>(thisPtr, nCommandId, nParameters);
s_CutsceneModeNoTURD = false;
return retVal;
}, Hooks::Order::Early);

static Hooks::Hook s_DropTURDHook = Hooks::HookFunction(&CNWSPlayer::DropTURD,
+[](CNWSPlayer *pPlayer) -> void
{
if (!s_CutsceneModeNoTURD)
s_DropTURDHook->CallOriginal<void>(pPlayer);
}, Hooks::Order::Earliest);

static Hooks::Hook s_CleanMyTURDsHook = Hooks::HookFunction(&CNWSPlayer::CleanMyTURDs,
+[](CNWSPlayer *pPlayer) -> void
{
if (!s_CutsceneModeNoTURD)
s_CleanMyTURDsHook->CallOriginal<void>(pPlayer);
}, Hooks::Order::Earliest);
}

}
1 change: 1 addition & 0 deletions Plugins/Tweaks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Tweaks stuff. See below.
| `NWNX_TWEAKS_SETAREA_CALLS_SETPOSITION` | true or false | If enabled, a creature getting added to an area will fire the `NWNX_ON_MATERIALCHANGE_*` and `NWNX_ON_CREATURE_TILE_CHANGE_*` events. |
| `NWNX_TWEAKS_FIRE_EQUIP_EVENTS_FOR_ALL_CREATURES` | true or false | The module OnPlayerEquipItem and OnPlayerUnEquipItem events are fired for all creatures |
| `NWNX_TWEAKS_DONT_DELAY_EQUIP_EVENT` | true or false | Fixes Unequip/Equip events being out of sync if an item is equipped/unequipped multiple times per server tick |
| `NWNX_TWEAKS_CUTSCENE_MODE_NO_TURD` | true or false | SetCutsceneMode() will not cause a TURD to be dropped. |

## Environment variable values

Expand Down

0 comments on commit 9fda84a

Please sign in to comment.