Skip to content

Commit

Permalink
Merge pull request #1642 from summonFox/Tweaks-RangedWeaponsUseOnHitI…
Browse files Browse the repository at this point in the history
…temProperties

Tweaks: Add `NWNX_TWEAKS_RANGED_WEAPONS_USE_ON_HIT_EFFECT_ITEM_PROPERTIES`
  • Loading branch information
Daztek authored Apr 15, 2023
2 parents 6fdb3e6 + 5fc320d commit fc37add
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
https://github.com/nwnxee/unified/compare/build8193.35.37...HEAD

### Added
- Tweaks: added `NWNX_TWEAKS_RANGED_WEAPONS_USE_ON_HIT_EFFECT_ITEM_PROPERTIES` which makes all bows, crossbows, and slings use On Hit: Effect item properties (in addition to their ammunition).
- Tweaks: added `NWNX_TWEAKS_RANGED_WEAPONS_USE_ON_HIT_CAST_SPELL_ITEM_PROPERTIES` which makes all bows, crossbows, and slings use On Hit: Cast Spell item properties (in addition to their ammunition).
- Tweaks: added `NWNX_TWEAKS_CAST_ALL_ON_HIT_CAST_SPELL_ITEM_PROPERTIES` which casts all On Hit: Cast Spell item properties on hit, instead of only the first property.
- Events: added skippable event `NWNX_ON_BROADCAST_SAFE_PROJECTILE_{BEFORE|AFTER}` which fires whenever a projectile VFX is created for ranged weapons and spells.
Expand Down
1 change: 1 addition & 0 deletions Plugins/Tweaks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ add_plugin(Tweaks
"UnhardcodeShields.cpp"
"UncapDamageResistanceDamageFlags.cpp"
"PreventAttackBonusBypassingReductions.cpp"
"RangedWeaponsUseOnHitEffectItemProperties.cpp"
"RangedWeaponsUseOnHitCastSpellItemProperties.cpp"
"CastAllOnHitCastSpellItemProperties.cpp")
1 change: 1 addition & 0 deletions Plugins/Tweaks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Tweaks stuff. See below.
| `NWNX_TWEAKS_UNCAP_DAMAGE_RESISTANCE_DAMAGE_FLAGS` | true or false | Uncaps the compounded damage flags of EffectDamageResistance. |
| `NWNX_TWEAKS_FIX_RESOLVE_SPECIAL_ATTACK_DAMAGE` | true or false | Stops damage from being resolved when a special attack misses. |
| `NWNX_TWEAKS_FIX_TURD_EFFECT_UNLINKING` | true or false | Stops effects from unlinking when restored from a TURD due to their effect ID changing. |
| `NWNX_TWEAKS_RANGED_WEAPONS_USE_ON_HIT_EFFECT_ITEM_PROPERTIES` | true or false | Makes all bows, crossbows, and slings use On Hit: Effect item properties (in addition to their ammunition). |
| `NWNX_TWEAKS_RANGED_WEAPONS_USE_ON_HIT_CAST_SPELL_ITEM_PROPERTIES` | true or false | Makes all bows, crossbows, and slings use On Hit: Cast Spell item properties (in addition to their ammunition). |
| `NWNX_TWEAKS_CAST_ALL_ON_HIT_CAST_SPELL_ITEM_PROPERTIES` | true or false | Casts all On Hit: Cast Spell item properties on hit, instead of only the first property. |

Expand Down
51 changes: 51 additions & 0 deletions Plugins/Tweaks/RangedWeaponsUseOnHitEffectItemProperties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "nwnx.hpp"

#include "API/CNWSCreature.hpp"
#include "API/CNWSCombatRound.hpp"
#include "API/CNWSItem.hpp"
#include "API/CNWBaseItemArray.hpp"
#include "API/CNWBaseItem.hpp"
#include "API/CNWRules.hpp"

namespace Tweaks {

using namespace NWNXLib;
using namespace NWNXLib::API;

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

LOG_INFO("Ranged weapons will use On Hit: Effect item properties.");

static Hooks::Hook s_ResolveOnHitEffectHook = Hooks::HookFunction(&CNWSCreature::ResolveOnHitEffect,
(void*)+[](CNWSCreature *pCreature, CNWSObject *pTarget, BOOL bOffHandAttack, BOOL bCritical) -> void
{
if (auto *pCombatRound = pCreature->m_pcCombatRound)
{
if (auto *pWeapon = pCombatRound->GetCurrentAttackWeapon(pCombatRound->GetWeaponAttackType()))
{
auto nBaseItem = pWeapon->m_nBaseItem;

if (nBaseItem == Constants::BaseItem::HeavyCrossbow ||
nBaseItem == Constants::BaseItem::LightCrossbow ||
nBaseItem == Constants::BaseItem::Longbow ||
nBaseItem == Constants::BaseItem::Shortbow ||
nBaseItem == Constants::BaseItem::Sling)
{
pWeapon->m_nBaseItem = Constants::BaseItem::Shortsword;
s_ResolveOnHitEffectHook->CallOriginal<void>(pCreature, pTarget, bOffHandAttack, bCritical);
pWeapon->m_nBaseItem = nBaseItem;
}
}
}

s_ResolveOnHitEffectHook->CallOriginal<void>(pCreature, pTarget, bOffHandAttack, bCritical);

}, Hooks::Order::Earliest);
}

}

0 comments on commit fc37add

Please sign in to comment.