internal override void Apply()
        {
            _timer.Start();

            flesh_kw = (settings.fleshEffectKeywords.Value ?? "").Split(new[] { ' ', '\t', ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (flesh_kw.Length == 0)
            {
                flesh_kw = null;
            }

            custom_kw = (settings.customEffectKeywords.Value ?? "").Split(new[] { ' ', '\t', ';', ',' }, StringSplitOptions.RemoveEmptyEntries);
            if (custom_kw.Length == 0)
            {
                custom_kw = null;
            }

            Addr_FlashHudMeter        = NetScriptFramework.Main.GameInfo.GetAddressOf(51907);
            Addr_SetAVRegenDelay      = NetScriptFramework.Main.GameInfo.GetAddressOf(38526); // 38525 is directly set
            Addr_TimeSinceFrame       = NetScriptFramework.Main.GameInfo.GetAddressOf(516940);
            Addr_StaminaRegenDelayMax = NetScriptFramework.Main.GameInfo.GetAddressOf(503351, 8);
            Addr_MagickaRegenDelayMax = NetScriptFramework.Main.GameInfo.GetAddressOf(503353, 8);

            Events.OnFrame.Register(UpdateFrame);

            if (this.IsStaminaEnabled && settings.jumpStuffEnabled.Value && (settings.jumpBlock.Value || settings.jumpStamina.Value > 0.0))
            {
                Memory.WriteHook(new HookParameters()
                {
                    Address       = NetScriptFramework.Main.GameInfo.GetAddressOf(36271, 0x96, 0, "E8"),
                    IncludeLength = 5,
                    ReplaceLength = 5,

                    Before = ctx =>
                    {
                        var plr = PlayerCharacter.Instance;
                        if (plr == null || plr.Address != ctx.DI)
                        {
                            return;
                        }

                        if (this.ShouldBlockJump())
                        {
                            ctx.Skip();
                            ctx.AX          = new IntPtr(0);
                            _skippedJumpNow = true;
                        }
                        else
                        {
                            _skippedJumpNow = false;
                        }
                    },

                    After = ctx =>
                    {
                        if (settings.jumpStamina.Value <= 0.0)
                        {
                            return;
                        }

                        var plr = PlayerCharacter.Instance;
                        if (plr == null || plr.Cast <PlayerCharacter>() != ctx.DI)
                        {
                            return;
                        }

                        if (!_skippedJumpNow)
                        {
                            this.SpendStamina(plr, (float)settings.jumpStamina.Value, (float)settings.jumpDelay.Value, true, modes.jump);
                        }
                    },
                });
            }
        }
示例#2
0
        private void Event_UpdatedCamera(UpdateCameraEventArgs e)
        {
            bool   enabled     = false;
            bool   showedDebug = false;
            bool   disabled    = settings.uninstallMode.Value;
            string extraDebug  = null;

            try
            {
                if (disabled)
                {
                    return;
                }

                var camera = e.Camera as PlayerCamera;
                if (camera == null)
                {
                    return;
                }

                var state = camera.State;
                if (state == null)
                {
                    return;
                }

                var id = state.Id;
                if (settings.onlyRegularThird.Value)
                {
                    switch (id)
                    {
                    //case TESCameraStates.Dragon:
                    //case TESCameraStates.Horse:
                    case TESCameraStates.ThirdPerson2:
                        break;

                    case TESCameraStates.ThirdPerson1:
                    case TESCameraStates.Furniture:
                        disabled = true;
                        return;

                    case TESCameraStates.Free:
                        break;

                    default:
                        disabled = true;
                        return;
                    }
                }
                else
                {
                    switch (id)
                    {
                    //case TESCameraStates.Dragon:
                    //case TESCameraStates.Horse:
                    case TESCameraStates.ThirdPerson1:
                    case TESCameraStates.ThirdPerson2:
                        break;

                    case TESCameraStates.Furniture:
                        disabled = true;
                        return;

                    case TESCameraStates.Free:
                        break;

                    default:
                        disabled = true;
                        return;
                    }
                }

                var third = state as ThirdPersonState;
                if (third == null)
                {
                    if (debug_msg)
                    {
                        extraDebug = "third == null";
                    }
                    return;
                }

                if (settings.forceDisableGlobal.Value != null)
                {
                    float fgval = settings.forceDisableGlobal.Value.FloatValue;
                    if (fgval >= 1.5f)
                    {
                        disabled = true;
                        return;
                    }
                    if (fgval >= 0.5f)
                    {
                        return;
                    }
                }

                var plr = PlayerCharacter.Instance;
                if (plr == null)
                {
                    return;
                }

                {
                    // Aiming bow or crossbow.
                    uint flags = NetScriptFramework.Memory.ReadUInt32(plr.Cast <PlayerCharacter>() + 0xC0) >> 28;
                    //if (flags == 0xA)
                    if (flags >= 8)
                    {
                        disabled = true;
                        return;
                    }

                    for (int i = 0; i < 3; i++)
                    {
                        var caster = plr.GetMagicCaster((EquippedSpellSlots)i);
                        if (caster == null)
                        {
                            continue;
                        }

                        var mstate = caster.State;
                        switch (mstate)
                        {
                        case MagicCastingStates.Charged:
                        case MagicCastingStates.Charging:
                        case MagicCastingStates.Concentrating:
                        {
                            disabled = true;
                            return;
                        }
                        }
                    }
                }

                if (this.IsSpecialFurniture)
                {
                    disabled = true;
                    return;
                }

                bool hadpos    = false;
                bool skipAngle = false;

                try
                {
                    var mm = MenuManager.Instance;
                    if (mm != null)
                    {
                        if (mm.IsMenuOpen("Dialogue Menu"))
                        {
                            var menuMgr = NetScriptFramework.Memory.ReadPointer(this.addr_MenuTopicManager);
                            if (menuMgr != null)
                            {
                                uint refHandleId = NetScriptFramework.Memory.ReadUInt32(menuMgr + 0x68);
                                using (var refObj = new ObjectRefHolder(refHandleId))
                                {
                                    var objPtr = refObj.Object;
                                    if (objPtr != null)
                                    {
                                        var root = objPtr.Node;
                                        if (root != null)
                                        {
                                            var head = root.LookupNodeByName("NPCEyeBone") ?? root.LookupNodeByName("NPC Head [Head]");
                                            if (head != null)
                                            {
                                                var hpos = head.WorldTransform.Position;
                                                this.TargetHeadTrack.X = hpos.X;
                                                this.TargetHeadTrack.Y = hpos.Y;
                                                this.TargetHeadTrack.Z = hpos.Z;
                                                hadpos    = true;
                                                skipAngle = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                }

                if (!hadpos)
                {
                    try
                    {
                        var pickData = NetScriptFramework.Memory.ReadPointer(addr_PickData);
                        if (pickData != IntPtr.Zero)
                        {
                            uint refHandleId = NetScriptFramework.Memory.ReadUInt32(pickData + 4);
                            using (var refObj = new ObjectRefHolder(refHandleId))
                            {
                                var objPtr = refObj.Object as Actor;
                                if (objPtr != null && !objPtr.IsDead)
                                {
                                    var root = objPtr.Node;
                                    if (root != null)
                                    {
                                        var head = root.LookupNodeByName("NPCEyeBone") ?? root.LookupNodeByName("NPC Head [Head]");
                                        if (head != null)
                                        {
                                            var hpos = head.WorldTransform.Position;
                                            this.TargetHeadTrack.X = hpos.X;
                                            this.TargetHeadTrack.Y = hpos.Y;
                                            this.TargetHeadTrack.Z = hpos.Z;
                                            hadpos    = true;
                                            skipAngle = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }

                double x = 0, y = 0;
                if (!skipAngle)
                {
                    x = (180.0 / Math.PI) * third.XRotationFromLastResetPoint;
                    y = 0.0;

                    {
                        float amount = -plr.Rotation.X;
                        float offset = third.YRotationFromLastResetPoint;
                        y = (180.0 / Math.PI) * (amount + offset);
                    }

                    x = Math.Abs(x);
                    y = Math.Abs(y);

                    if (x < settings.horizontalMinAngle.Value || x > settings.horizontalMaxAngle.Value || y < settings.verticalMinAngle.Value || y > settings.verticalMaxAngle.Value)
                    {
                        return;
                    }
                }

                var node = camera.Node;
                if (node == null)
                {
                    return;
                }

                if (this.IsIFPVMaybe(plr, node.WorldTransform.Position))
                {
                    disabled = true;
                    if (debug_msg)
                    {
                        extraDebug = "ifpv";
                    }
                    return;
                }

                if (!hadpos)
                {
                    node.WorldTransform.Translate(this.TranslateHeadTrack, this.TargetHeadTrack);
                }
                enabled = true;

                if (debug_msg)
                {
                    if (!_timer.IsRunning)
                    {
                        _timer.Start();
                    }
                    if (_timer.Time >= 1000)
                    {
                        NetScriptFramework.Main.WriteDebugMessage("============================================");
                        Action <string, NiPoint3> report = (type, pos) =>
                        {
                            NetScriptFramework.Main.WriteDebugMessage(type + "_x: " + pos.X + "; " + type + "_y: " + pos.Y + "; " + type + "_z: " + pos.Z + "; dist: " + node.WorldTransform.Position.GetDistance(pos));
                        };
                        NetScriptFramework.Main.WriteDebugMessage("rot_x = " + x + "; rot_y = " + y);
                        report("target", this.TargetHeadTrack);
                        report("cam", node.WorldTransform.Position);
                        try
                        {
                            report("head", PlayerCharacter.Instance.GetSkeletonNode(false).LookupNodeByName("NPC Head [Head]").WorldTransform.Position);
                        }
                        catch
                        {
                        }
                        _timer.Restart();
                        debug_msg2 = true;
                    }
                    showedDebug = true;
                }
            }
            finally
            {
                this.SetEnabled(enabled, disabled);

                if (enabled)
                {
                    this.State &= ~states.need_new_target;
                }

                if (!showedDebug && debug_msg)
                {
                    if (!_timer.IsRunning)
                    {
                        _timer.Start();
                    }
                    if (_timer.Time >= 1000)
                    {
                        string dmsg = !string.IsNullOrEmpty(extraDebug) ? extraDebug : "?";
                        NetScriptFramework.Main.WriteDebugMessage(dmsg);
                        _timer.Restart();
                    }
                }
            }
        }