Skip to content

Commit

Permalink
Tweaks: add NWNX_TWEAKS_CAN_USE_ITEMS_WHILE_POLYMORPHED
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrikgit committed Oct 14, 2024
1 parent bd6577f commit 62ba8a8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ https://github.com/nwnxee/unified/compare/build8193.36.12...HEAD
- 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.
- Tweaks: added `NWNX_TWEAKS_CAN_USE_ITEMS_WHILE_POLYMORPHED` to allow all items to be used while polymorphed.

##### 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 @@ -38,4 +38,5 @@ add_plugin(Tweaks
"CastAllOnHitCastSpellItemProperties.cpp"
"SetAreaCallsSetPosition.cpp"
"EquipUnequipEventTweaks.cpp"
"CutsceneModeNoTURD.cpp")
"CutsceneModeNoTURD.cpp"
"CanUseItemsWhilePolymorphed.cpp")
40 changes: 40 additions & 0 deletions Plugins/Tweaks/CanUseItemsWhilePolymorphed.cpp
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);
}

}
7 changes: 4 additions & 3 deletions Plugins/Tweaks/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@addtogroup tweaks Tweaks
@page tweaks Readme
@ingroup tweaks
@ingroup tweaks

Tweaks stuff. See below.

Expand All @@ -14,7 +14,7 @@ Tweaks stuff. See below.
| `NWNX_TWEAKS_DISABLE_QUICKSAVE` | true or false | Disables DM quicksave. |
| `NWNX_TWEAKS_COMPARE_VARIABLES_WHEN_MERGING` | true or false | When trying to merge items, local variables are also considered. |
| `NWNX_TWEAKS_PARRY_ALL_ATTACKS` | true or false | Removes the number of parried attacks per round limit. |
| `NWNX_TWEAKS_SNEAK_ATTACK_IGNORE_CRIT_IMMUNITY` | true or false | Allow sneakattacks on creatures that are immune to critical hits. |
| `NWNX_TWEAKS_SNEAK_ATTACK_IGNORE_CRIT_IMMUNITY` | true or false | Allow sneakattacks on creatures that are immune to critical hits. |
| `NWNX_TWEAKS_PRESERVE_DEPLETED_ITEMS` | true or false | Items that run out of charges are not destroyed. |
| `NWNX_TWEAKS_HIDE_PLAYERS_ON_CHAR_LIST` | between 1 and 3 | See [here](https://github.com/nwnxee/unified/tree/master/Plugins/Tweaks#nwnx_tweaks_hide_players_on_char_list). |
| `NWNX_TWEAKS_DISABLE_MONK_ABILITIES_WHEN_POLYMORPHED` | true or false | Disables monk abilities (ac, speed, etc) when polymorphed. |
Expand Down Expand Up @@ -50,6 +50,7 @@ Tweaks stuff. See below.
| `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. |
| `NWNX_TWEAKS_CAN_USE_ITEMS_WHILE_POLYMORPHED` | true or false | Allow all items to be used while polymorphed. |

## Environment variable values

Expand Down Expand Up @@ -88,7 +89,7 @@ Values between 1 and 3 are valid. Any of those values will adjust the item cost

### NWNX_TWEAKS_HIDE_HARDCODED_ITEM_VFX

Add the numbers of the VFX you want to hide. For example to hide all Elemental Damage Bonus, Holy Avenger and OnHitVorpal visual effects you'd set the environment variable to 318 (2 + 4 + 8 + 16 + 32 + 256)
Add the numbers of the VFX you want to hide. For example to hide all Elemental Damage Bonus, Holy Avenger and OnHitVorpal visual effects you'd set the environment variable to 318 (2 + 4 + 8 + 16 + 32 + 256)

Specific VFX values in order of priority:

Expand Down

0 comments on commit 62ba8a8

Please sign in to comment.