-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweaks: add
NWNX_TWEAKS_CAN_USE_ITEMS_WHILE_POLYMORPHED
- Loading branch information
1 parent
bd6577f
commit 62ba8a8
Showing
4 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "nwnx.hpp" | ||
|
||
#include "API/CNWSCreature.hpp" | ||
|
||
namespace Tweaks { | ||
|
||
using namespace NWNXLib; | ||
using namespace NWNXLib::API; | ||
|
||
void CanUseItemsWhilePolymorphed() __attribute__((constructor)); | ||
void CanUseItemsWhilePolymorphed() | ||
{ | ||
if (!Config::Get<bool>("CAN_USE_ITEMS_WHILE_POLYMORPHED", false)) return; | ||
|
||
LOG_INFO("Allow all items to be used while polymorphed."); | ||
|
||
static Hooks::Hook s_CanUseItemHook = Hooks::HookFunction(&CNWSCreature::CanUseItem, | ||
+[](CNWSCreature* thisPtr, CNWSItem* pItem, BOOL bIgnoreIdentifiedFlag) -> BOOL | ||
{ | ||
bool isPolymorphed = thisPtr->m_bIsPolymorphed; | ||
thisPtr->m_bIsPolymorphed = false; | ||
BOOL retVal = s_CanUseItemHook->CallOriginal<BOOL>(thisPtr, pItem, bIgnoreIdentifiedFlag); | ||
thisPtr->m_bIsPolymorphed = isPolymorphed; | ||
return retVal; | ||
}, Hooks::Order::Early); | ||
|
||
static Hooks::Hook s_UseItemHook = Hooks::HookFunction(&CNWSCreature::UseItem, | ||
+[](CNWSCreature* thisPtr, OBJECT_ID oidItem, uint8_t nActivePropertyIndex, uint8_t nSubPropertyIndex, | ||
OBJECT_ID oidTarget, Vector vTargetPosition, OBJECT_ID oidArea, BOOL bUseCharges = true) -> BOOL | ||
{ | ||
bool isPolymorphed = thisPtr->m_bIsPolymorphed; | ||
thisPtr->m_bIsPolymorphed = false; | ||
BOOL retVal = s_UseItemHook->CallOriginal<BOOL>(thisPtr, oidItem, nActivePropertyIndex, nSubPropertyIndex, | ||
oidTarget, vTargetPosition, oidArea, bUseCharges); | ||
thisPtr->m_bIsPolymorphed = isPolymorphed; | ||
return retVal; | ||
}, Hooks::Order::Early); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters