Skip to content

Commit

Permalink
Merge pull request nwnxee#390 from Daztek/events-learn-scroll
Browse files Browse the repository at this point in the history
Events: add ScrollLearn event to ItemEvents
  • Loading branch information
mtijanic authored Feb 24, 2019
2 parents 6112443 + 7542ff7 commit 6bd2625
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NOTICE: The ABI has changed, please make sure to update your nwnx.nss and recomp
- Events: Added On{Un}Polymorph events as PolymorphEvents
- Events: Added Event Data for SpawnObject, GiveItem and GiveAlignment, Heal, Kill, ToggleInvulnerabilty, ForceRest, Limbo, ToggleAI, ToggleImmortal, Goto, Possess, PossessFullPower, ToggleLock, DisableTrap, JumpToPoint, JumpTargetToPoint, JumpAllPlayersToPoint, ChangeDifficulty, ViewInventory, SpawnTrapOnObject events in DMActionEvents
- Events: Added OnClientConnect events that fire before the player sees the server vault.
- Events: Added ItemInventory{Open/Close} and ItemInventory{Add/Remove}Item events to ItemEvents
- Events: Added ItemInventory{Open/Close}, ItemInventory{Add/Remove}Item and ScrollLearn events to ItemEvents
- Events: Added {Set|Clear}MemorizedSpellSlot events to SpellEvents
- Events: Added AmmoReload events that are used when the engine is looking for ammunition to reload
- Profiler: Support profiler perf scopes via nwscript
Expand Down
28 changes: 28 additions & 0 deletions Plugins/Events/Events/ItemEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static Hooking::FunctionHook* m_OpenInventoryHook = nullptr;
static Hooking::FunctionHook* m_CloseInventoryHook = nullptr;
static Hooking::FunctionHook* m_AddItemHook = nullptr;
static Hooking::FunctionHook* m_FindItemWithBaseItemIdHook = nullptr;
static Hooking::FunctionHook* m_LearnScrollHook = nullptr;

ItemEvents::ItemEvents(ViewPtr<Services::HooksProxy> hooker)
{
Expand Down Expand Up @@ -53,6 +54,11 @@ ItemEvents::ItemEvents(ViewPtr<Services::HooksProxy> hooker)
m_FindItemWithBaseItemIdHook = hooker->FindHookByAddress(API::Functions::CItemRepository__FindItemWithBaseItemId);
});

Events::InitOnFirstSubscribe("NWNX_ON_ITEM_SCROLL_LEARN_.*", [hooker]() {
hooker->RequestExclusiveHook<API::Functions::CNWSCreature__LearnScroll>(&LearnScrollHook);
m_LearnScrollHook = hooker->FindHookByAddress(API::Functions::CNWSCreature__LearnScroll);
});

}

int32_t ItemEvents::UseItemHook(
Expand Down Expand Up @@ -249,5 +255,27 @@ uint32_t ItemEvents::FindItemWithBaseItemIdHook(CItemRepository* thisPtr, uint32
return retVal;
}

int32_t ItemEvents::LearnScrollHook(CNWSCreature *thisPtr, Types::ObjectID oidScrollToLearn)
{
int32_t retVal;

auto PushAndSignal = [&](std::string ev) -> bool {
Events::PushEventData("SCROLL", Utils::ObjectIDToString(oidScrollToLearn));
return Events::SignalEvent(ev, thisPtr->m_idSelf);
};

if (PushAndSignal("NWNX_ON_ITEM_SCROLL_LEARN_BEFORE"))
{
retVal = m_LearnScrollHook->CallOriginal<int32_t>(thisPtr, oidScrollToLearn);
}
else
{
retVal = false;
}

PushAndSignal("NWNX_ON_ITEM_SCROLL_LEARN_AFTER");

return retVal;
}

}
1 change: 1 addition & 0 deletions Plugins/Events/Events/ItemEvents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ItemEvents
static int32_t AddItemHook(NWNXLib::API::CItemRepository*, NWNXLib::API::CNWSItem**, uint8_t, uint8_t, int32_t, int32_t);
static void RemoveItemHook(NWNXLib::Services::Hooks::CallType, NWNXLib::API::CItemRepository*, NWNXLib::API::CNWSItem*);
static uint32_t FindItemWithBaseItemIdHook(NWNXLib::API::CItemRepository*, uint32_t, int32_t);
static int32_t LearnScrollHook(NWNXLib::API::CNWSCreature*, NWNXLib::API::Types::ObjectID);
};

}
10 changes: 10 additions & 0 deletions Plugins/Events/NWScript/nwnx_events.nss
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@
BASE_ITEM_ID int
BASE_ITEM_NTH int Find the Nth instance of this item
ACTION_RESULT int The object that was determined in BEFORE (only in after)
NWNX_ON_ITEM_SCROLL_LEARN_BEFORE
NWNX_ON_ITEM_SCROLL_LEARN_AFTER
Usage:
OBJECT_SELF = The creature learning the scroll
Event data:
Variable Name Type Notes
SCROLL object Convert to object with NWNX_Object_StringToObject()
////////////////////////////////////////////////////////////////////////////////
NWNX_ON_USE_FEAT_BEFORE
NWNX_ON_USE_FEAT_AFTER
Expand Down

0 comments on commit 6bd2625

Please sign in to comment.