private static void OnRemoveAssociate(void *pCreature, uint oidAssociate) { ProcessEvent(new OnAssociateRemove { Owner = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Associate = oidAssociate.ToNwObject <NwCreature>() !, });
private static int OnLearnScroll(void *pCreature, uint oidScrollToLearn) { OnItemScrollLearn eventData = ProcessEvent(new OnItemScrollLearn { Creature = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Scroll = oidScrollToLearn.ToNwObject <NwItem>() !, });
private static OnCreatureAttack[] GetAttackEvents(void *pCreature, void *pTarget, int nAttacks) { CNWSCreature?creature = CNWSCreature.FromPointer(pCreature); NwGameObject?target = CNWSObject.FromPointer(pTarget).ToNwObject <NwGameObject>(); if (creature == null || target == null) { return(Array.Empty <OnCreatureAttack>()); } NwCreature nwCreature = creature.ToNwObject <NwCreature>() !; // m_nCurrentAttack points to the attack after this flurry. int attackNumberOffset = creature.m_pcCombatRound.m_nCurrentAttack - nAttacks; CNWSCombatRound combatRound = creature.m_pcCombatRound; // Create an event for each attack in the flurry OnCreatureAttack[] attackEvents = new OnCreatureAttack[nAttacks]; for (int i = 0; i < nAttacks; i++) { attackEvents[i] = GetEventData(nwCreature, target, combatRound, attackNumberOffset + i); } return(attackEvents); }
private static int OnAddCastSpellActions(void *pCreature, uint nSpellId, int nMultiClass, int nDomainLevel, int nMetaType, int bSpontaneousCast, Vector3 vTargetLocation, uint oidTarget, int bAreaTarget, int bAddToFront, int bFake, byte nProjectilePathType, int bInstant, int bAllowPolymorphedCast, int nFeat, byte nCasterLevel) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); OnSpellAction eventData = new OnSpellAction { Caster = creature.ToNwObject <NwCreature>() !, Spell = NwSpell.FromSpellId((int)nSpellId) !, ClassIndex = nMultiClass, Domain = (Domain)nDomainLevel, MetaMagic = (MetaMagic)nMetaType, IsSpontaneous = bSpontaneousCast.ToBool(), TargetPosition = vTargetLocation, TargetObject = oidTarget.ToNwObject <NwGameObject>() !, IsAreaTarget = bAreaTarget.ToBool(), IsFake = bFake.ToBool(), ProjectilePath = (ProjectilePathType)nProjectilePathType, IsInstant = bInstant.ToBool(), Feat = NwFeat.FromFeatId(nFeat) !, CasterLevel = nCasterLevel, }; eventData.Result = new Lazy <bool>(() => !eventData.PreventSpellCast && Hook.CallOriginal(pCreature, nSpellId, nMultiClass, nDomainLevel, nMetaType, bSpontaneousCast, vTargetLocation, oidTarget, bAreaTarget, bAddToFront, bFake, nProjectilePathType, bInstant, bAllowPolymorphedCast, nFeat, nCasterLevel).ToBool()); ProcessEvent(eventData); return(eventData.Result.Value.ToInt()); }
private static void OnSendFeedbackMessage(void *pCreature, ushort nFeedbackId, void *pMessageData, void *pFeedbackPlayer) { const ushort resistanceId = 66; const ushort reductionId = 67; const int remainingDRIndex = 2; if (pMessageData == null) { Hook.CallOriginal(pCreature, nFeedbackId, null, pFeedbackPlayer); return; } CNWSCreature creature = CNWSCreature.FromPointer(pCreature); CNWCCMessageData messageData = CNWCCMessageData.FromPointer(pMessageData); if (nFeedbackId != resistanceId && nFeedbackId != reductionId || creature.m_idSelf != messageData.GetObjectID(0) || messageData.GetInteger(remainingDRIndex) != 0) { Hook.CallOriginal(pCreature, nFeedbackId, pMessageData, pFeedbackPlayer); return; } ProcessEvent(new OnCombatDRBroken { Creature = creature.ToNwObject <NwCreature>() !, Type = nFeedbackId == resistanceId ? DRType.DamageResistance : DRType.DamageReduction, });
private static int OnUnequipItem(void *pCreature, uint oidItemToUnequip, uint oidTargetRepository, byte x, byte y, int bMergeIntoRepository, uint oidFeedbackPlayer) { OnItemUnequip eventData = ProcessEvent(new OnItemUnequip { Creature = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Item = oidItemToUnequip.ToNwObject <NwItem>() !, });
private static int OnRequestSell(void *pCreature, uint oidItemToSell, uint oidStore) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); NwItem? item = oidItemToSell.ToNwObject <NwItem>(); NwStore? store = oidStore.ToNwObject <NwStore>(); int price = 0; if (store != null && item != null) { price = store.Store.CalculateItemBuyPrice(item, creature.m_idSelf); } OnStoreRequestSell eventData = new OnStoreRequestSell { Creature = creature.ToNwObject <NwCreature>() !, Item = item, Store = store, Price = price, }; eventData.Result = new Lazy <bool>(() => !eventData.PreventSell && Hook.CallOriginal(pCreature, oidItemToSell, oidStore).ToBool()); ProcessEvent(eventData); return(eventData.Result.Value.ToInt()); }
private static void OnPayToIdentifyItem(void *pCreature, uint oidItem, uint oidStore) { OnItemPayToIdentify eventData = ProcessEvent(new OnItemPayToIdentify { Creature = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Item = oidItem.ToNwObject <NwItem>() !, Store = oidStore.ToNwObject <NwStore>() !, });
private static int OnCanUseItem(void *pCreature, void *pItem, int bIgnoreIdentifiedFlag) { OnItemValidateUse eventData = ProcessEvent(new OnItemValidateUse { UsedBy = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Item = CNWSItem.FromPointer(pItem).ToNwObject <NwItem>() !, CanUse = Hook.CallOriginal(pCreature, pItem, bIgnoreIdentifiedFlag).ToBool(), });
private static void OnAddAssociate(void *pCreature, uint oidAssociate, ushort associateType) { ProcessEvent(new OnAssociateAdd { Owner = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Associate = oidAssociate.ToNwObject <NwCreature>() !, AssociateType = (AssociateType)associateType, });
private static void OnAddGold(void *pCreature, int nGold, int bDisplayFeedback) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); OnInventoryGoldAdd eventData = ProcessEvent(new OnInventoryGoldAdd { Creature = creature.ToNwObject <NwCreature>() !, Gold = nGold, });
private static void OnPossessFamiliar(void *pCreature) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); ProcessEvent(new OnFamiliarPossess { Owner = creature.ToNwObject <NwCreature>() !, Familiar = creature.GetAssociateId((ushort)AssociateType.Familiar).ToNwObject <NwCreature>() !, });
private static int OnCanEquipItem(void *pCreature, void *pItem, uint *pEquipToSLot, int bEquipping, int bLoading, int bDisplayFeedback, void *pFeedbackPlayer) { OnItemValidateEquip eventData = ProcessEvent(new OnItemValidateEquip { UsedBy = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Item = CNWSItem.FromPointer(pItem).ToNwObject <NwItem>() !, Slot = (InventorySlot)Math.Round(Math.Log2(*pEquipToSLot)), Result = (EquipValidationResult)Hook.CallOriginal(pCreature, pItem, pEquipToSLot, bEquipping, bLoading, bDisplayFeedback, pFeedbackPlayer), });
private static void OnBroadcastSpellCast(void *pCreature, uint nSpellId, byte nMultiClass, ushort nFeat) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); OnSpellBroadcast eventData = ProcessEvent(new OnSpellBroadcast { Caster = creature.ToNwObject <NwCreature>() !, Spell = NwSpell.FromSpellId((int)nSpellId) !, ClassIndex = nMultiClass, Feat = NwFeat.FromFeatId(nFeat) !, });
private static int OnUseSkill(void *pCreature, byte nSkill, byte nSubSkill, uint oidTarget, Vector3 vTargetPosition, uint oidArea, uint oidUsedItem, int nActivePropertyIndex) { OnUseSkill eventData = ProcessEvent(new OnUseSkill { Creature = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Skill = NwSkill.FromSkillId(nSkill) !, SubSkill = (SubSkill)nSubSkill, Target = oidTarget.ToNwObject <NwGameObject>() !, Area = oidArea.ToNwObject <NwArea>() !, UsedItem = oidUsedItem.ToNwObject <NwItem>() !, TargetPosition = vTargetPosition, });
private static int OnCreatureUseFeat(void *pCreature, ushort nFeat, ushort nSubFeat, uint oidTarget, uint oidArea, void *pTargetPos) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); OnUseFeat eventData = ProcessEvent(new OnUseFeat { Creature = creature.ToNwObject <NwCreature>() !, Feat = NwFeat.FromFeatId(nFeat) !, SubFeatId = nSubFeat, TargetObject = oidTarget.ToNwObject <NwGameObject>() !, TargetArea = oidArea.ToNwObject <NwArea>() !, TargetPosition = pTargetPos != null ? Marshal.PtrToStructure <Vector3>((IntPtr)pTargetPos) : Vector3.Zero, });
private static int OnUseItem(void *pCreature, uint oidItem, byte nActivePropertyIndex, byte nSubPropertyIndex, uint oidTarget, Vector3 vTargetPosition, uint oidArea, int bUseCharges) { OnItemUse eventData = ProcessEvent(new OnItemUse { UsedBy = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Item = oidItem.ToNwObject <NwItem>() !, TargetObject = oidTarget.ToNwObject <NwGameObject>() !, ItemPropertyIndex = nActivePropertyIndex, ItemSubPropertyIndex = nSubPropertyIndex, TargetPosition = vTargetPosition, TargetArea = oidArea.ToNwObject <NwArea>() !, UseCharges = bUseCharges.ToBool(), });
private float OnGetWalkRate(void *pCreature) { NwCreature?creature = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>(); if (creature == null) { return(walkRateHook.CallOriginal(pCreature)); } InternalVariableFloat rateCap = InternalVariables.WalkRateCap(creature); return(rateCap.HasValue ? rateCap.Value : walkRateHook.CallOriginal(pCreature)); }
private static void OnSetCombatMode(void *pCreature, byte nNewMode, int bForceNewMode) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); if (creature == null) { Hook.CallOriginal(pCreature, nNewMode, bForceNewMode); return; } OnCombatModeToggle eventData = ProcessEvent(new OnCombatModeToggle { Creature = creature.ToNwObject <NwCreature>() !, NewMode = (CombatMode)nNewMode, ForceNewMode = bForceNewMode.ToBool(), });
private static int OnDoListenDetection(void *pCreature, void *pTarget, int bTargetInvisible) { CNWSCreature target = CNWSCreature.FromPointer(pTarget); if (target.m_nStealthMode == 0 && !bTargetInvisible.ToBool()) { return(true.ToInt()); } CNWSCreature creature = CNWSCreature.FromPointer(pCreature); OnDoListenDetection eventData = ProcessEvent(new OnDoListenDetection { Creature = creature.ToNwObject <NwCreature>() !, Target = target.ToNwObject <NwCreature>() !, });
private float OnMaxAttackRange(void *pCreature, uint oidTarget, int bBaseValue, int bPassiveRange) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); CNWSItem equippedItem = creature.m_pInventory.GetItemInSlot((uint)EquipmentSlot.RightHand); if (equippedItem != null) { uint baseItemType = equippedItem.m_nBaseItem; CNWBaseItem baseItem = NWNXLib.Rules().m_pBaseItemArray.GetBaseItem((int)baseItemType); if (baseItem != null && baseItem.m_nWeaponRanged > 0 && maxRangedAttackDistanceOverrideMap.TryGetValue(baseItemType, out MaxRangedAttackDistanceOverride distanceOverride)) { return(bPassiveRange.ToBool() ? distanceOverride.MaxRangedPassiveAttackDistance : distanceOverride.MaxRangedAttackDistance); } } return(creature.DesiredAttackRange(oidTarget, bBaseValue) + 1.5f); }
private static uint OnAIActionHeal(void *pCreature, void *pNode) { CNWSObjectActionNode actionNode = CNWSObjectActionNode.FromPointer(pNode); OnHealKitUse eventData = new OnHealKitUse { UsedBy = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Target = ((uint)actionNode.m_pParameter[0].AsULong()).ToNwObject <NwGameObject>() !, ItemUsed = ((uint)actionNode.m_pParameter[1].AsULong()).ToNwObject <NwItem>() !, ItemPropertyIndex = (int)actionNode.m_pParameter[2], MoveToTarget = ((int)actionNode.m_pParameter[2]).ToBool(), }; eventData.Result = new Lazy <ActionState>(() => !eventData.PreventUse ? (ActionState)Hook.CallOriginal(pCreature, pNode) : ActionState.Failed); ProcessEvent(eventData); return((uint)eventData.Result.Value); }
private static int OnDoSpotDetection(void *pCreature, void *pTarget, int bTargetInvisible) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); CNWSCreature target = CNWSCreature.FromPointer(pTarget); if (bTargetInvisible.ToBool() || creature.GetBlind().ToBool()) { return(false.ToInt()); } if (target.m_nStealthMode == 0) { return(true.ToInt()); } OnDoSpotDetection eventData = ProcessEvent(new OnDoSpotDetection { Creature = creature.ToNwObject <NwCreature>() !, Target = target.ToNwObject <NwCreature>() !, });
private uint OnAIActionRest(void *pCreature, void *pNode) { CNWSCreature creature = CNWSCreature.FromPointer(pCreature); NwCreature? nwCreature = creature.ToNwObject <NwCreature>(); if (nwCreature != null && restDurationOverrides.TryGetValue(nwCreature, out int durationOverride)) { byte creatureLevel = creature.m_pStats.GetLevel(0); int originalValue; C2DA durationTable = NWNXLib.Rules().m_p2DArrays.m_pRestDurationTable; durationTable.GetINTEntry(creatureLevel, DurationTableKey, &originalValue); durationTable.SetINTEntry(creatureLevel, DurationTableKey, durationOverride); uint retVal = aiActionRestHook.CallOriginal(pCreature, pNode); durationTable.SetINTEntry(creatureLevel, DurationTableKey, originalValue); return(retVal); } return(aiActionRestHook.CallOriginal(pCreature, pNode)); }
private static int OnRunEquip(void *pCreature, uint oidItemToEquip, uint nInventorySlot, uint oidFeedbackPlayer) { uint slot = nInventorySlot; byte slotId = 0; while ((slot >>= 1) != 0) { slotId++; } OnItemEquip eventData = new OnItemEquip { EquippedBy = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>() !, Item = oidItemToEquip.ToNwObject <NwItem>() !, Slot = (InventorySlot)slotId, }; eventData.Result = new Lazy <bool>(() => !eventData.PreventEquip && Hook.CallOriginal(pCreature, oidItemToEquip, nInventorySlot, oidFeedbackPlayer).ToBool()); ProcessEvent(eventData); return(eventData.Result.Value.ToInt()); }
private static int OnCheckProficiencies(void *pCreature, void *pItem, uint nEquipToSlot) { NwCreature?creature = CNWSCreature.FromPointer(pCreature).ToNwObject <NwCreature>(); NwItem? item = CNWSItem.FromPointer(pItem).ToNwObject <NwItem>(); if (creature == null || item == null) { return(Hook.CallOriginal(pCreature, pItem, nEquipToSlot)); } OnCreatureCheckProficiencies eventData = ProcessEvent(new OnCreatureCheckProficiencies { Creature = creature, Item = item, TargetSlot = (EquipmentSlots)nEquipToSlot, }); return(eventData.ResultOverride switch { CheckProficiencyOverride.HasProficiency => true.ToInt(), CheckProficiencyOverride.NoProficiency => false.ToInt(), _ => Hook.CallOriginal(pCreature, pItem, nEquipToSlot), });