Advertisement
TKGP

Untitled

Feb 16th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using PropertyHook;
  2. using System;
  3.  
  4. namespace PropertyHookTest
  5. {
  6.     class DS1Hook : PHook
  7.     {
  8.         private PHPointer InventoryData;
  9.  
  10.         public DS1Hook() : base(p => p.MainWindowTitle == "DARK SOULS" || p.MainWindowTitle == "DARK SOULS™: REMASTERED", 5000)
  11.         {
  12.             InventoryData = null;
  13.             OnHooked += DS1Hook_OnHooked;
  14.             OnUnhooked += DS1Hook_OnUnhooked;
  15.         }
  16.  
  17.         private void DS1Hook_OnHooked(object sender, PHEventArgs e)
  18.         {
  19.             if (Is64Bit)
  20.             {
  21.                 InventoryData = RegisterPointer("48 8B 05 ? ? ? ? 48 85 C0 ? ? F3 0F 58 80 AC 00 00 00", 3, true, 0, 0x10, 0x3B8);
  22.                 RescanAOB();
  23.             }
  24.             else
  25.             {
  26.                 InventoryData = RegisterPointer("A1 ? ? ? ? 53 55 8B 6C 24 10 56 8B 70 08 32 DB 85 F6", 1, false, 0, 8, 0x2DC);
  27.                 RescanAOB();
  28.             }
  29.         }
  30.  
  31.         private void DS1Hook_OnUnhooked(object sender, PHEventArgs e)
  32.         {
  33.             InventoryData = UnregisterPointer(InventoryData);
  34.         }
  35.  
  36.         public InventoryItem[] GetInventoryItems()
  37.         {
  38.             if (InventoryData == null)
  39.             {
  40.                 return new InventoryItem[0];
  41.             }
  42.             else
  43.             {
  44.                 var result = new InventoryItem[2048];
  45.                 byte[] bytes = InventoryData.ReadBytes(0, 2048 * 0x1C);
  46.                 for (int i = 0; i < 2048; i++)
  47.                 {
  48.                     result[i] = new InventoryItem(bytes, i * 0x1C);
  49.                 }
  50.                 return result;
  51.             }
  52.         }
  53.     }
  54.  
  55.     public struct InventoryItem
  56.     {
  57.         public int Category { get; }
  58.  
  59.         public int ID { get; }
  60.  
  61.         public int Quantity { get; }
  62.  
  63.         public int Unk0C { get; }
  64.  
  65.         public int Unk10 { get; }
  66.  
  67.         public int Durability { get; }
  68.  
  69.         public int Unk18 { get; }
  70.  
  71.         public InventoryItem(byte[] bytes, int index)
  72.         {
  73.             Category = BitConverter.ToInt32(bytes, index + 0x00) >> 28;
  74.             ID = BitConverter.ToInt32(bytes, index + 0x04);
  75.             Quantity = BitConverter.ToInt32(bytes, index + 0x08);
  76.             Unk0C = BitConverter.ToInt32(bytes, index + 0x0C);
  77.             Unk10 = BitConverter.ToInt32(bytes, index + 0x10);
  78.             Durability = BitConverter.ToInt32(bytes, index + 0x14);
  79.             Unk18 = BitConverter.ToInt32(bytes, index + 0x18);
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement