Exemple #1
0
            private static int OnEffectApplied(void *pEffectListHandler, void *pObject, void *pEffect, int bLoadingGame)
            {
                if (pEffect == null)
                {
                    return(Hook.CallOriginal(pEffectListHandler, pObject, null, bLoadingGame));
                }

                CGameEffect effect = CGameEffect.FromPointer(pEffect);

                if (effect.m_nType != (int)EffectTrueType.VisualEffect || effect.m_nNumIntegers == 0 ||
                    effect.m_nParamInteger[0] != 292 && effect.m_nParamInteger[0] != 293)
                {
                    return(Hook.CallOriginal(pEffectListHandler, pObject, pEffect, bLoadingGame));
                }

                CNWSObject gameObject = CNWSObject.FromPointer(pObject);

                ProcessEvent(new OnSpellInterrupt
                {
                    InterruptedCaster = gameObject.ToNwObject <NwGameObject>() !,
                    Spell             = NwSpell.FromSpellId((int)gameObject.m_nLastSpellId) !,
                    ClassIndex        = gameObject.m_nLastSpellCastMulticlass,
                    Feat        = NwFeat.FromFeatId(gameObject.m_nLastSpellCastFeat) !,
                    Domain      = (Domain)gameObject.m_nLastDomainLevel,
                    Spontaneous = gameObject.m_bLastSpellCastSpontaneous.ToBool(),
                    MetaMagic   = (MetaMagic)gameObject.m_nLastSpellCastMetaType,
                });
Exemple #2
0
            private static int OnApplyHeal(void *pEffectListHandler, void *pObject, void *pGameEffect, int bLoadingGame)
            {
                CGameEffect gameEffect = CGameEffect.FromPointer(pGameEffect);
                CNWSObject  target     = CNWSObject.FromPointer(pObject);

                OnHeal eventData = ProcessEvent(new OnHeal
                {
                    Healer     = gameEffect.m_oidCreator.ToNwObject <NwObject>() !,
                    Target     = target.ToNwObject <NwGameObject>() !,
                    HealAmount = gameEffect.GetInteger(0),
                });
Exemple #3
0
        public void CreateSoftEffectReferencAndDisposeDoesNotFreeMemory()
        {
            Effect effect = Effect.Blindness();

            Assert.That(effect.IsValid, Is.True, "Effect was not valid after creation.");

            CGameEffect gameEffect = effect;

            Assert.That(gameEffect, Is.Not.Null, "Native effect was not valid after implicit cast.");

            Effect softReference = gameEffect.ToEffect(false) !;

            softReference.Dispose();
            Assert.That(softReference.IsValid, Is.True, "The soft reference disposed the memory of the original effect.");
        }
Exemple #4
0
            private static int OnApplyDisarm(void *pEffectHandler, void *pObject, void *pEffect, int bLoadingGame)
            {
                CNWSObject  gameObject = CNWSObject.FromPointer(pObject);
                CGameEffect gameEffect = CGameEffect.FromPointer(pEffect);

                OnDisarmWeapon eventData = new OnDisarmWeapon
                {
                    DisarmedObject = gameObject.ToNwObject <NwGameObject>() !,
                    DisarmedBy     = gameEffect.m_oidCreator.ToNwObject <NwGameObject>() !,
                    Feat           = gameEffect.GetInteger(0) == 1 ? NwFeat.FromFeatType(API.Feat.ImprovedDisarm) ! : NwFeat.FromFeatType(API.Feat.Disarm) !,
                };

                eventData.Result = new Lazy <bool>(() => !eventData.PreventDisarm && Hook.CallOriginal(pEffectHandler, pObject, pEffect, bLoadingGame).ToBool());
                ProcessEvent(eventData);

                return(eventData.Result.Value.ToInt());
            }
        }
Exemple #5
0
            private static int OnApplyDamage(void *pEffectListHandler, void *pObject, void *pEffect, int bLoadingGame)
            {
                CNWSObject  gameObject = CNWSObject.FromPointer(pObject);
                CGameEffect effect     = CGameEffect.FromPointer(pEffect);

                if (gameObject == null || effect == null)
                {
                    return(Hook.CallOriginal(pEffectListHandler, pObject, pEffect, bLoadingGame));
                }

                if (IsValidObjectTarget((ObjectType)gameObject.m_nObjectType))
                {
                    ProcessEvent(new OnCreatureDamage
                    {
                        DamagedBy  = effect.m_oidCreator.ToNwObject <NwObject>() !,
                        Target     = gameObject.ToNwObject <NwGameObject>() !,
                        DamageData = new DamageData <int>(effect.m_nParamInteger),
                    });
Exemple #6
0
        private protected unsafe EffectBase(CGameEffect effect, bool memoryOwn) : base(effect.Pointer, memoryOwn)
        {
            Effect = effect;

            IntParams = new EffectParams <int>(effect.m_nNumIntegers,
                                               i => effect.m_nParamInteger[i],
                                               (i, value) => effect.m_nParamInteger[i] = value);
            FloatParams = new EffectParams <float>(effect.m_nParamFloat.Length,
                                                   i => effect.m_nParamFloat[i],
                                                   (i, value) => effect.m_nParamFloat[i] = value);
            StringParams = new EffectParams <string>(6,
                                                     i => effect.m_sParamString[i].ToString(),
                                                     (i, value) => effect.m_sParamString[i] = value?.ToExoString());
            VectorParams = new EffectParams <Vector3>(2,
                                                      i => effect.m_vParamVector[i].ToManagedVector(),
                                                      (i, value) => effect.m_vParamVector[i] = value.ToNativeVector());
            ObjectParams = new EffectParams <NwObject>(effect.m_oidParamObjectID.Length,
                                                       i => effect.m_oidParamObjectID[i].ToNwObject(),
                                                       (i, value) => effect.m_oidParamObjectID[i] = value);
        }
Exemple #7
0
            private static int OnEffectRemoved(void *pEffectListHandler, void *pObject, void *pEffect)
            {
                CNWSObject  gameObject = CNWSObject.FromPointer(pObject);
                CGameEffect gameEffect = CGameEffect.FromPointer(pEffect);

                if (gameObject == null || gameEffect == null)
                {
                    return(Hook.CallOriginal(pEffectListHandler, pObject, pEffect));
                }

                EffectDurationType durationType = (EffectDurationType)gameEffect.GetDurationType();

                if (durationType != EffectDurationType.Temporary && durationType != EffectDurationType.Permanent)
                {
                    return(Hook.CallOriginal(pEffectListHandler, pObject, pEffect));
                }

                OnEffectRemove eventData = ProcessEvent(new OnEffectRemove
                {
                    Object = gameObject.ToNwObject() !,
                    Effect = gameEffect.ToEffect(false) !,
                });
Exemple #8
0
 internal ItemProperty(CGameEffect effect, bool memoryOwn) : base(effect, memoryOwn)
 {
 }
Exemple #9
0
 internal Effect(CGameEffect effect, bool memoryOwn) : base(effect, memoryOwn)
 {
 }