Skip to content

Commit 0bbd324

Browse files
author
CapitaineToinon
committed
Fixed PTDE to work with pirated version
1 parent 8e34747 commit 0bbd324

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Gadgetlemage/DarkSouls/PrepareToDie.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ public class PrepareToDie : DarkSouls
1313
private const string INVENTORY_DATA_AOB = "A1 ? ? ? ? 53 55 8B 6C 24 10 56 8B 70 08 32 DB 85 F6";
1414
private const string FLAGS_AOB = "56 8B F1 8B 46 1C 50 A1 ? ? ? ? 32 C9";
1515
private const string CHR_DATA_AOB = "83 EC 14 A1 ? ? ? ? 8B 48 04 8B 40 08 53 55 56 57 89 4C 24 1C 89 44 24 20 3B C8";
16+
private const string FUNC_ITEM_GET_AOB = "55 8B EC 83 E4 F8 83 EC 34 8B 4D 0C 53 8B 5D 08 56 83 C8 FF 33 F6 81 F9 00 00 00 20 57 89 44 24 1C 89 74 24 20 89 B3 8C 01 00 00 89 44 24 18";
17+
private const uint FUNC_ITEM_CALL_OFFSET = 0x26; // the offset of the instrcution in the asm that will call the item function
1618
private const uint INVENTORY_INDEX_START = 0x1B8;
17-
private const uint FUNC_ITEM_GET_PTR = 0xC0B6DA;
1819

1920
/// <summary>
2021
/// Properties
2122
/// </summary>
2223
public PHPointer pBasePtr { get; private set; }
2324
public PHPointer pInventoryData { get; private set; }
25+
public PHPointer pFuncItemGet { get; private set; }
26+
27+
2428

2529
/// <summary>
2630
/// Constructor
@@ -35,6 +39,7 @@ public PrepareToDie(PHook process) : base(process)
3539

3640
pBasePtr = Process.RegisterAbsoluteAOB(BASE_PTR_AOB, 2);
3741
pInventoryData = Process.RegisterAbsoluteAOB(INVENTORY_DATA_AOB, 1);
42+
pFuncItemGet = Process.RegisterAbsoluteAOB(FUNC_ITEM_GET_AOB);
3843

3944
Process.RescanAOB();
4045
}
@@ -49,28 +54,29 @@ public override void CreateWeapon(BlackKnightWeapon weapon)
4954
byte[] asm = (byte[])Assembly.PTDE.Clone();
5055

5156
// Get the pointer to CharBasePtr
52-
IntPtr pointer = pBasePtr.Resolve();
53-
pointer = Process.CreateChildPointer(pBasePtr, 0, 8).Resolve();
57+
pBasePtr.Resolve();
58+
IntPtr pointer = Process.CreateChildPointer(pBasePtr, 0, 8).Resolve();
5459

5560
// Have to allocate first to rebase the code
5661
IntPtr memory = Process.Allocate((uint)asm.Length);
57-
uint funcPointer = (uint)(FUNC_ITEM_GET_PTR - (uint)memory);
62+
uint funcPointer = (uint)pFuncItemGet.Resolve() - (uint)memory - FUNC_ITEM_CALL_OFFSET;
5863

5964
// Now we can write the rebased bytes
60-
byte[] bytes = BitConverter.GetBytes((ulong)pointer + INVENTORY_INDEX_START);
65+
byte[] bytes;
66+
bytes = BitConverter.GetBytes((ulong)pointer + INVENTORY_INDEX_START);
6167
Array.Copy(bytes, 0, asm, 0x1, 4);
6268
bytes = BitConverter.GetBytes(ItemCategory);
6369
Array.Copy(bytes, 0, asm, 0x6, 4);
6470
bytes = BitConverter.GetBytes(weapon.ID);
6571
Array.Copy(bytes, 0, asm, 0xB, 4);
6672
bytes = BitConverter.GetBytes(ItemQuantity);
6773
Array.Copy(bytes, 0, asm, 0x10, 4);
68-
bytes = BitConverter.GetBytes((ulong)funcPointer);
74+
bytes = BitConverter.GetBytes(funcPointer);
6975
Array.Copy(bytes, 0, asm, 0x22, 4);
7076

7177
// Write, Execute and Free
7278
Kernel32.WriteBytes(Process.Handle, memory, asm);
73-
int result = Process.Execute(memory);
79+
Process.Execute(memory);
7480
Process.Free(memory);
7581
}
7682
}
@@ -104,12 +110,11 @@ public override InventoryItem[] GetInventoryItems()
104110
/// <param name="weapon"></param>
105111
public override void DeleteItem(BlackKnightWeapon weapon)
106112
{
107-
InventoryItem[] result = new InventoryItem[0];
108-
109113
if (Process.Hooked)
110114
{
111-
result = new InventoryItem[2048];
112-
IntPtr pointer = pInventoryData.Resolve();
115+
InventoryItem[] result = new InventoryItem[2048];
116+
117+
pInventoryData.Resolve();
113118
PHPointer pInventory = Process.CreateChildPointer(pInventoryData, 0, 8, 0x2DC);
114119
byte[] bytes = pInventory.ReadBytes(0, 2048 * 0x1C);
115120

0 commit comments

Comments
 (0)