Пример #1
0
            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,
                });
Пример #2
0
            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());
            }
Пример #3
0
            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());
            }
Пример #4
0
 private static void HandleEnter(CNWSCreature creature, byte nDetectMode)
 {
     OnDetectModeUpdate eventData = ProcessEvent(new OnDetectModeUpdate
     {
         Creature  = creature.ToNwObject <NwCreature>() !,
         EventType = ToggleModeEventType.Enter,
     });
Пример #5
0
            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,
                });
Пример #6
0
            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>() !,
                });
Пример #7
0
            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) !,
                });
Пример #8
0
            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,
                });
Пример #9
0
            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>() !,
                });
Пример #10
0
            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(),
                });
Пример #11
0
            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>() !,
                });
Пример #12
0
        private int OnSendServerToPlayerPopUpGUIPanel(void *pMessage, uint observerOid, int nGuiPanel, int bGUIOption1, int bGUIOption2, int nStringReference, void **psStringReference)
        {
            if (nGuiPanel == 1) // Party invite popup
            {
                CNWSCreature?observerCreature = LowLevel.ServerExoApp.GetCreatureByGameObjectID(observerOid);
                NwPlayer?    observerPlayer   = observerCreature?.ToNwObject <NwCreature>()?.ControllingPlayer;
                NwPlayer?    targetPlayer     = observerCreature?.m_oidInvitedToPartyBy.ToNwPlayer();

                if (targetPlayer != null)
                {
                    PlayerNameOverride?name = GetPlayerNameOverride(targetPlayer, observerPlayer);
                    if (name != null)
                    {
                        *psStringReference = (void *)name.CharacterNameInternal.Pointer;
                    }
                }
            }

            return(sendServerToPlayerPopUpGUIPanelHook.CallOriginal(pMessage, observerOid, nGuiPanel, bGUIOption1, bGUIOption2, nStringReference, psStringReference));
        }
Пример #13
0
        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));
        }