Ejemplo n.º 1
0
        internal static Actor GetCurrentlyPickPocketing()
        {
            int type = Memory.ReadInt32(BetterStealingPlugin._ContOpenType_Var);

            if (type != 2)
            {
                return(null);
            }

            uint handle = Memory.ReadUInt32(BetterStealingPlugin._ContOpen_Var);

            if (handle == 0)
            {
                return(null);
            }

            TESObjectREFR obj = null;

            using (var objRef = new ObjectRefHolder(handle))
            {
                obj = objRef.Object;
            }

            return(obj as Actor);
        }
Ejemplo n.º 2
0
        internal static TESObjectREFR GetCurrentlyStealingFromContainer()
        {
            int type = Memory.ReadInt32(BetterStealingPlugin._ContOpenType_Var);

            if (type != 1)
            {
                return(null);
            }

            uint handle = Memory.ReadUInt32(BetterStealingPlugin._ContOpen_Var);

            if (handle == 0)
            {
                return(null);
            }

            TESObjectREFR obj = null;

            using (var objRef = new ObjectRefHolder(handle))
            {
                obj = objRef.Object;
            }

            return(obj);
        }
Ejemplo n.º 3
0
        private CameraTarget SelectTarget(UpdateCameraEventArgs e)
        {
            var cameraBase = e.Camera;

            if (!(cameraBase is PlayerCamera playerCamera))
            {
                return(null);
            }

            TESObjectREFR target    = null;
            var           refHandle = playerCamera.TargetRefHandle;

            using (var objRef = new ObjectRefHolder(refHandle))
            {
                if (objRef.IsValid)
                {
                    target = objRef.Object;
                }
            }

            var t = CameraTarget.Create(target);

            if (t == null)
            {
                return(null);
            }

            var actor = t.Actor;
            var obj   = t.Object;

            LastActorWasPlayer = actor != null && actor.IsPlayer;
            LastTargetFormId   = obj?.FormId ?? 0;

            return(t);
        }
Ejemplo n.º 4
0
        private CameraTarget SelectTarget(UpdateCameraEventArgs e)
        {
            var cameraBase   = e.Camera;
            var playerCamera = cameraBase.As <PlayerCamera>();

            if (playerCamera == null)
            {
                return(null);
            }

            TESObjectREFR target    = null;
            uint          refHandle = playerCamera.TargetRefHandle;

            using (var objRef = new ObjectRefHolder(refHandle))
            {
                if (objRef.IsValid)
                {
                    target = objRef.Object;
                }
            }

            var t = CameraTarget.Create(target);

            if (t == null)
            {
                return(null);
            }

            var actor = t.Actor;
            var obj   = t.Object;

            this.LastActorWasPlayer = actor != null && actor.IsPlayer;
            this.LastTargetFormId   = obj != null ? obj.FormId : 0;

            return(t);
        }
        internal override bool Check(CameraUpdate update)
        {
            if (!update.CameraMain.IsEnabled)
            {
                return(false);
            }

            var actor = update.Target.Actor;

            if (actor == null)
            {
                return(false);
            }

            var process = actor.Process;

            if (process == null)
            {
                return(false);
            }

            var middleHigh = process.MiddleHigh;

            if (middleHigh == null)
            {
                return(false);
            }

            uint handle = middleHigh.CurrentFurnitureRefHandle;

            if (handle == 0)
            {
                return(false);
            }

            TESObjectREFR obj = null;

            using (var objHandle = new ObjectRefHolder(handle))
            {
                if (objHandle.IsValid)
                {
                    obj = objHandle.Object;
                }
            }

            if (obj == null)
            {
                return(false);
            }

            var baseObj = obj.BaseForm;

            if (baseObj == null)
            {
                return(false);
            }

            foreach (var x in SpecialKeywords)
            {
                if (baseObj.HasKeywordText(x))
                {
                    return(true);
                }
            }

            return(false);
        }
        internal static CameraTarget Create(TESObjectREFR obj)
        {
            if (obj == null)
            {
                return(null);
            }

            TESObjectREFR originalObj   = obj;
            Actor         originalActor = obj as Actor;

            bool isMountChange = false;
            {
                var horse = obj as Actor;
                if (horse != null && horse.IsBeingRidden)
                {
                    var rider = horse.GetMountedBy();
                    if (rider != null)
                    {
                        obj           = rider;
                        isMountChange = true;
                    }
                }
            }

            var t = new CameraTarget();

            t.Object         = obj;
            t.Actor          = obj as Actor;
            t.OriginalObject = originalObj;
            t.OriginalActor  = originalActor;

            var node = t.Actor != null && t.Actor.IsPlayer ? t.Actor.GetSkeletonNode(false) : obj.Node;

            if (node == null)
            {
                return(null);
            }

            for (int i = 0; i < EyeNodeNames.Length; i++)
            {
                var name = EyeNodeNames[i];
                var n    = node.LookupNodeByName(name);
                if (n != null)
                {
                    t.HeadNode = n;
                    break;
                }
            }

            if (t.HeadNode == null)
            {
                t.HeadNode = node;
            }

            for (int i = 0; i < RootNodeNames.Length; i++)
            {
                var name = RootNodeNames[i];
                var n    = node.LookupNodeByName(name);
                if (n != null)
                {
                    t.RootNode = n;
                    break;
                }
            }

            if (t.RootNode == null)
            {
                t.RootNode = node;
            }

            t.StabilizeRootNode = t.RootNode;
            if (isMountChange && t.Actor != null && t.OriginalActor != null && !t.Actor.Equals(t.OriginalActor))
            {
                var stabilize = t.OriginalActor.IsPlayer ? t.OriginalActor.GetSkeletonNode(false) : t.OriginalActor.Node;
                if (stabilize != null)
                {
                    t.StabilizeRootNode = stabilize;
                }
            }

            return(t);
        }
Ejemplo n.º 7
0
        private bool ProcessInventory(ExtraContainerChanges.Data inventory, TESObjectREFR instance, TESForm item, TESForm owner, int count, uint?cdata = null)
        {
            if (inventory == null || item == null)
            {
                return(false);
            }

            // Special case for references, it might already be handled before. Containers have this check elsewhere.
            if (instance != null && instance.ExtraDataList.IsStolenForever())
            {
                return(false);
            }

            ExtraContainerChanges.ItemEntry entry = null;
            BSExtraDataList best      = null;
            int             bestCount = 0;

            foreach (var o in inventory.Objects)
            {
                var template = o.Template;
                if (template == null)
                {
                    continue;
                }

                if (!item.Equals(template))
                {
                    continue;
                }

                entry = o;

                o.ForeachEntry((data, icount) =>
                {
                    // Already not stolen.
                    var iowner = data != null ? data.GetOwner() : null;
                    if (iowner == null)
                    {
                        return;
                    }

                    if (cdata.HasValue && cdata.Value != data.GetCustomData())
                    {
                        return;
                    }

                    if (data.IsStolenForever())
                    {
                        return;
                    }

                    if (!CheckConditions(o, data, item))
                    {
                        return;
                    }

                    if (best == null || Math.Abs(count - bestCount) > Math.Abs(count - icount))
                    {
                        best      = data;
                        bestCount = icount;
                    }
                });

                break;
            }

            if (best == null)
            {
                return(false);
            }

            this.ApplyResult(entry, best, this.WasDetected);
            return(true);
        }
Ejemplo n.º 8
0
        private OpenResults TryToUnlockObject(Actor actor, TESObjectREFR obj)
        {
            if (_tryUnlockCounter != 1 || IsDoingOurUnlocking > 0)
            {
                Report("NoLockPicking: ERROR #1!");
                return(OpenResults.Return0);
            }

            IntPtr plrPtr;
            IntPtr objPtr;

            if (actor == null || !actor.IsPlayer || obj == null || (plrPtr = actor.Cast <PlayerCharacter>()) == IntPtr.Zero || (objPtr = obj.Cast <TESObjectREFR>()) == IntPtr.Zero)
            {
                Report("NoLockPicking: ERROR #2!");
                return(OpenResults.Return0);
            }

            if (cfg.OnlyWorksWhenSneaking && !actor.IsSneaking)
            {
                Memory.InvokeCdecl(this.Addr_PlaySound_Func.Value, this.Addr_LockedSound_Var.Value);
                return(OpenResults.Return0);
            }

            var extraLock = obj.GetLockData(true);

            if (extraLock == null)
            {
                Report("NoLockPicking: ERROR #3!");
                return(OpenResults.Return0);
            }

            var lockData = extraLock.LockData;

            if (lockData == null)
            {
                Report("NoLockPicking: ERROR #4!");
                return(OpenResults.Return0);
            }

            if (lockData.IsBroken)
            {
                this.ReportImpossible();
                return(OpenResults.Return0);
            }

            int lockLevel = lockData.LockLevel;
            ExtraLockDifficultyRanks lockDifficulty = lockData.GetDifficultyRank(obj);

            if (lockDifficulty == ExtraLockDifficultyRanks.Impossible)
            {
                if (!cfg.AllowPickKeyDoors)
                {
                    this.ReportImpossible();
                    return(OpenResults.Return0);
                }

                lockDifficulty = ExtraLockDifficultyRanks.VeryHard;
                lockLevel      = 100;
            }

            bool hasSkeletonKey = false;
            int  lockPickCount  = 0;

            if (cfg.SuperCheatMode)
            {
                hasSkeletonKey = true;
            }
            else
            {
                var    objMgr = BGSDefaultObjectManager.Instance;
                IntPtr mgrPtr;
                if (objMgr != null && (mgrPtr = objMgr.Cast <BGSDefaultObjectManager>()) != IntPtr.Zero)
                {
                    if (Memory.ReadUInt8(mgrPtr + 0xB85) != 0)
                    {
                        var skey = Memory.ReadPointer(mgrPtr + 0x48);
                        if (skey != IntPtr.Zero && Memory.InvokeCdecl(this.Addr_CheckItemCount_Func.Value, plrPtr, skey).ToInt32Safe() > 0)
                        {
                            hasSkeletonKey = true;
                        }
                    }
                }
            }

            if (!hasSkeletonKey)
            {
                var lpick = Memory.ReadPointer(this.Addr_LockPickMisc_Var.Value);
                if (lpick != IntPtr.Zero)
                {
                    lockPickCount = Memory.InvokeCdecl(this.Addr_CheckItemCount_Func.Value, plrPtr, lpick).ToInt32Safe();
                }
            }

            int requiredPicks          = 0;
            int requiredInventoryPicks = cfg.RequireAtLeastOneLockPickInInventory ? 1 : 0;

            if (!hasSkeletonKey)
            {
                float mySkillMult = 1.0f;
                if (cfg.BonusReducesPickUsage)
                {
                    using (var alloc = Memory.Allocate(0x10))
                    {
                        Memory.WriteZero(alloc.Address, 0x10);
                        Memory.WriteFloat(alloc.Address, 1.0f);
                        Memory.InvokeCdecl(this.Addr_ApplyPerk_Func.Value, (int)PerkEntryPoints.Modify_Lockpick_Sweet_Spot, plrPtr, objPtr, alloc.Address);
                        mySkillMult = Memory.ReadFloat(alloc.Address);
                    }
                }

                float mySkill = actor.GetActorValue(ActorValueIndices.Lockpicking);
                //float mySkillExtra = actor.GetActorValue(ActorValueIndices.LockpickingMod);
                //float mySkillExtraPower = actor.GetActorValue(ActorValueIndices.LockpickingPowerMod);

                if (mySkillMult <= 0.0f)
                {
                    this.ReportImpossible();
                    return(OpenResults.Return0);
                }

                int diffIndex = 0;
                {
                    int diffDiff = (int)mySkill - lockLevel;
                    if (diffDiff > 40) // My skill is 40+ to lock's
                    {
                        diffIndex = 0;
                    }
                    else if (diffDiff > 15) // My skill is 15+ to lock's
                    {
                        diffIndex = 1;
                    }
                    else if (diffDiff > -15) // My skill is -15 to 15 to lock's
                    {
                        diffIndex = 2;
                    }
                    else if (diffDiff > -40) // My skill is -40 to -15 to lock's
                    {
                        diffIndex = 3;
                    }
                    else
                    {
                        diffIndex = 4; // My skill is -40 or lower to lock's
                    }
                }

                double cost = 0.0;
                switch (diffIndex)
                {
                case 0: cost = cfg.CostVeryEasy; break;

                case 1: cost = cfg.CostEasy; break;

                case 2: cost = cfg.CostMedium; break;

                case 3: cost = cfg.CostHard; break;

                case 4: cost = cfg.CostVeryHard; break;
                }

                if (cost < 0.0)
                {
                    this.ReportImpossible();
                    return(OpenResults.Return0);
                }

                if (cost > 0.0)
                {
                    float unbreakable = 0.0f;
                    using (var alloc3 = Memory.Allocate(0x10))
                    {
                        Memory.WriteFloat(alloc3.Address, 0.0f);
                        Memory.InvokeCdecl(this.Addr_ApplyPerk_Func.Value, 0x41, plrPtr, alloc3.Address, IntPtr.Zero);
                        unbreakable = Memory.ReadFloat(alloc3.Address);
                    }
                    if (unbreakable >= 0.5f)
                    {
                        cost = 0.0;
                    }
                }

                if (cost > 0.0)
                {
                    cost /= mySkillMult;

                    requiredPicks = (int)cost;
                    int maxCost = requiredPicks;
                    cost -= requiredPicks;
                    if (cost > 0.000001)
                    {
                        maxCost++;

                        if (NetScriptFramework.Tools.Randomizer.NextDouble() < cost)
                        {
                            requiredPicks++;
                        }
                    }

                    requiredInventoryPicks = Math.Max(requiredInventoryPicks, maxCost);
                }

                if (requiredInventoryPicks > lockPickCount || requiredPicks > lockPickCount)
                {
                    this.ReportNoPicks();
                    return(OpenResults.Return0);
                }
            }

            // Take picks.
            if (!hasSkeletonKey && requiredPicks > 0)
            {
                actor.InvokeVTableThisCall <TESObjectREFR>(0x2B0, NetScriptFramework.Main.TrashMemory, Memory.ReadPointer(this.Addr_LockPickMisc_Var.Value), requiredPicks, 0, 0, 0, 0, 0);
                Memory.InvokeCdecl(this.Addr_PlaySound_Func.Value, this.Addr_PickBreakSound_Var.Value);
            }

            // Unlock object.
            {
                IsDoingOurUnlocking++;
                Memory.WritePointer(this.Addr_CurrentLockPickTarget_Var.Value, objPtr);
                Memory.WriteInt32(this.Addr_CurrentLockPickRank_Var.Value, Math.Max(0, Math.Min(4, (int)lockDifficulty)));
                Memory.WritePointer(this.Addr_CurrentLockPickThing_Var.Value, IntPtr.Zero);
                Memory.WriteUInt8(this.FakeMenu + 0x10D, 0);
                Memory.WriteUInt8(this.FakeMenu + 0x10B, 1);
                Memory.InvokeCdecl(this.Addr_ActualUnlock_Func.Value, this.FakeMenu);
                Memory.WritePointer(this.Addr_CurrentLockPickTarget_Var.Value, IntPtr.Zero);
                IsDoingOurUnlocking--;
            }

            //return OpenResults.TryOpenAgain;
            return(OpenResults.Return0);
        }
        private TESEffectShader ShouldGlow(TESObjectREFR obj, NiPoint3 pos)
        {
            if (obj == null)
            {
                return(null);
            }

            var           form = obj.BaseForm;
            TESObjectBOOK book = null;

            if (form == null || (book = form as TESObjectBOOK) == null || book.IsRead)
            {
                return(null);
            }

            TESObjectCELL cell = null;

            if (obj.Node == null || (cell = obj.ParentCell) == null)
            {
                return(null);
            }

            var tes = TES.Instance;

            if (tes == null)
            {
                return(null);
            }

            if (!Memory.InvokeCdecl(_is_cell_loaded, tes.Cast <TES>(), cell.Cast <TESObjectCELL>(), 0).ToBool())
            {
                return(null);
            }

            var tracker = Tools.BookTracker.Instance;
            var type    = tracker.GetBookType(book);

            if (!type.HasValue)
            {
#if DEBUG_MSG
                NetScriptFramework.Main.WriteDebugMessage("Warning: " + book.ToString() + " does not have a type in tracker!");
#endif
                return(null);
            }

            int mask = 1 << (int)type.Value;
            if ((this._care_mask & mask) == 0)
            {
                return(null);
            }

            if (obj.Position.GetDistance(pos) > 8000.0f)
            {
                return(null);
            }

            var ls = this._shaders[(int)type.Value];
            if (ls.Count == 0)
            {
                return(null);
            }

            if (ls.Count == 1)
            {
                return(ls[0]);
            }

            return(ls[rnd.Next(0, ls.Count)]);
        }