internal static StealInfo Begin() { int t = Memory.GetCurrentNativeThreadId(); StealInfo info = null; lock (Locker) { List <StealInfo> ls = null; if (!Map.TryGetValue(t, out ls)) { ls = new List <StealInfo>(1); Map[t] = ls; } if (ls.Count != 0) { info = ls[ls.Count - 1]; } if (info == null || info.State != 0) { info = new StealInfo(); ls.Add(info); } } return(info); }
internal static StealInfo Get() { int t = Memory.GetCurrentNativeThreadId(); StealInfo info = null; lock (Locker) { List <StealInfo> ls = null; if (Map.TryGetValue(t, out ls) && ls.Count != 0) { info = ls[ls.Count - 1]; if (info.State != 0) { info = null; } } } return(info); }
private void init() { NeverKeywords = (Settings.Instance.IgnoreKeywords ?? "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); AlwaysKeywords = (Settings.Instance.AlwaysKeywords ?? "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); RequiredKeywords = (Settings.Instance.RequireKeywords ?? "").Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); MaxPrice = Settings.Instance.MaxPrice; if (Settings.Instance.Enabled) { Events.OnMainMenu.Register(e => { ExcludeForms = CachedFormList.TryParse(Settings.Instance.ExcludeFormIds ?? "", "BetterStealing", "ExcludeFormIds"); }); this.InstallHook("send steal alarm #1", 36427, 0, 7, "48 8B C4 44 89 48 20", ctx => { var info = StealInfo.Begin(); if (info == null) { return; } info.Type = StealInfo.GetCalledFromType(Memory.ReadPointer(ctx.SP)); info.Thief = MemoryObject.FromAddress <Actor>(ctx.CX); info.TargetObjRef = MemoryObject.FromAddress <TESObjectREFR>(ctx.DX); info.TargetObjBase = MemoryObject.FromAddress <TESForm>(ctx.R8); info.TargetObjCount = ctx.R9.ToInt32Safe(); info.UnspecifiedItemsWorth = Memory.ReadInt32(ctx.SP + 0x28); info.OwnerForm = MemoryObject.FromAddress <TESForm>(Memory.ReadPointer(ctx.SP + 0x30)); }); this.InstallHook("send steal alarm #2", 36427, 0x9D3, 7, "48 81 C4 38 01 00 00", ctx => { var info = StealInfo.Get(); if (info == null) { return; } info.WasDetected = Memory.ReadUInt8(ctx.SP + 0x40) != 0; info.State = 1; ApplyStolenSoon.Queue(1); }); this.InstallHook("open container", 50195, 0x20, 5, "E8", ctx => { StealInfo.BeginContainer(); ApplyFixCDataSoon.Queue(3); var pickpocket = _InventoryExtensions.GetCurrentlyPickPocketing(); if (pickpocket != null) { var info = StealInfo.Begin(); if (info != null) { info.Type = StealTypes.PickPocketCustom; info.Thief = PlayerCharacter.Instance; info.TargetObjRef = pickpocket; info.TargetObjBase = null; info.TargetObjCount = 0; info.WasDetected = false; info.UnspecifiedItemsWorth = 0; info.OwnerForm = pickpocket.BaseForm; info.State = 1; FinishPickPocketCheck.Queue(3); } } }); this.InstallHook("actor add item", 36525, 0, 5, "44 89 4C 24 20", ctx => { var pickpocket = _InventoryExtensions.GetCurrentlyPickPocketing(); if (pickpocket != null) { var who = MemoryObject.FromAddress <TESObjectREFR>(ctx.CX); if (who == null || !(who is Actor) || !((Actor)who).IsPlayer) { return; } var where = MemoryObject.FromAddress <TESObjectREFR>(Memory.ReadPointer(ctx.SP + 0x28)); if (where == null || !where.Equals(pickpocket)) { return; } var item = MemoryObject.FromAddress <TESForm>(ctx.DX); var data = MemoryObject.FromAddress <BSExtraDataList>(ctx.R8); int count = ctx.R9.ToInt32Safe(); StealInfo.PushContainerItem(item, data, count); } else { var stealing = _InventoryExtensions.GetCurrentlyStealingFromContainer(); if (stealing == null) { return; } var who = MemoryObject.FromAddress <TESObjectREFR>(ctx.CX); if (who == null || !(who is Actor) || !((Actor)who).IsPlayer) { return; } var where = MemoryObject.FromAddress <TESObjectREFR>(Memory.ReadPointer(ctx.SP + 0x28)); if (where == null || !where.Equals(stealing)) { return; } var item = MemoryObject.FromAddress <TESForm>(ctx.DX); var data = MemoryObject.FromAddress <BSExtraDataList>(ctx.R8); int count = ctx.R9.ToInt32Safe(); StealInfo.PushContainerItem(item, data, count); } }); this.InstallHook("object add item", 19282, 0, 6, "40 55 56 57 41 54", ctx => { var pickpocket = _InventoryExtensions.GetCurrentlyPickPocketing(); if (pickpocket != null) { var who = MemoryObject.FromAddress <TESObjectREFR>(ctx.CX); if (who == null || !who.Equals(pickpocket)) { return; } var where = MemoryObject.FromAddress <TESObjectREFR>(Memory.ReadPointer(ctx.SP + 0x28)); if (where == null || !(where is Actor) || !((Actor) where).IsPlayer) { return; } var item = MemoryObject.FromAddress <TESForm>(ctx.DX); var data = MemoryObject.FromAddress <BSExtraDataList>(ctx.R8); int count = ctx.R9.ToInt32Safe(); StealInfo.RemoveContainerItem(item, data, count); } else { var stealing = _InventoryExtensions.GetCurrentlyStealingFromContainer(); if (stealing == null) { return; } var who = MemoryObject.FromAddress <TESObjectREFR>(ctx.CX); if (who == null || !who.Equals(stealing)) { return; } var where = MemoryObject.FromAddress <TESObjectREFR>(Memory.ReadPointer(ctx.SP + 0x28)); if (where == null || !(where is Actor) || !((Actor) where).IsPlayer) { return; } var item = MemoryObject.FromAddress <TESForm>(ctx.DX); var data = MemoryObject.FromAddress <BSExtraDataList>(ctx.R8); int count = ctx.R9.ToInt32Safe(); StealInfo.RemoveContainerItem(item, data, count); } }); Events.OnFrame.Register(e => { FinishPickPocketCheck.Do(); ApplyStolenSoon.Do(); ApplyFixCDataSoon.Do(); }); _SetItemOwner_Func = NetScriptFramework.Main.GameInfo.GetAddressOf(15784); _SetListOwner_Func = NetScriptFramework.Main.GameInfo.GetAddressOf(11463); _GetCount_Func = NetScriptFramework.Main.GameInfo.GetAddressOf(11558); _GetNorth_Func = NetScriptFramework.Main.GameInfo.GetAddressOf(11773); _SetNorth_Func = NetScriptFramework.Main.GameInfo.GetAddressOf(11774); _ContOpenType_Var = NetScriptFramework.Main.GameInfo.GetAddressOf(519396); _ContOpen_Var = NetScriptFramework.Main.GameInfo.GetAddressOf(519421); _CalcCost_Func = NetScriptFramework.Main.GameInfo.GetAddressOf(15757); } if (Settings.Instance.FixBadStolenItemCount) { var ptr = NetScriptFramework.Main.GameInfo.GetAddressOf(15821, 0x110A, 0, "0F B7 95 A0 01 00 00"); Memory.WriteBytes(ptr, new byte[] { 0x8B, 0x54, 0x24, 0x60, 0x90, 0x90, 0x90 }, true); } }