@@ -343,48 +343,28 @@ static __declspec(naked) void protinst_use_item_on_hack() {
343343 }
344344}
345345
346- static __declspec (naked) void SetDefaultAmmo() {
346+ static __declspec (naked) void item_identical_hack() {
347+ static const DWORD item_identical_Ret = 0x477A8E ;
348+ static const DWORD item_identical_End = 0x477AD5 ;
347349 using namespace fo ;
348- using namespace Fields ;
349- __asm {
350- push ecx;
351- mov ecx, edx; // ecx = item
352- mov eax, edx;
353- call fo::funcoffs::item_get_type_;
354- cmp eax, item_type_weapon; // is it item_type_weapon?
355- jne end; // no
356- cmp dword ptr [ecx + charges], 0 ; // is there any ammo in the weapon?
357- jne end; // yes
358- sub esp, 4 ;
359- mov edx, esp;
360- mov eax, [ecx + protoId]; // eax = weapon pid
361- call fo::funcoffs::proto_ptr_;
362- mov edx, [esp];
363- mov eax, [edx + 0x5C ]; // eax = default ammo pid
364- mov [ecx + ammoPid], eax; // set current ammo pid
365- add esp, 4 ;
366- end:
367- pop ecx;
368- retn;
369- }
370- }
371-
372- static __declspec (naked) void inven_action_cursor_hack() {
373- __asm {
374- mov edx, [esp + 0x6C - 0x50 + 4 ]; // source_item
375- call SetDefaultAmmo;
376- cmp dword ptr [esp + 0x6C - 0x54 + 4 ], 0 ; // overwritten engine code
377- retn;
378- }
379- }
380-
381- static __declspec (naked) void item_add_mult_hook() {
382- __asm {
383- push edx;
384- call SetDefaultAmmo;
385- pop edx;
386- mov eax, ecx; // restore
387- jmp fo::funcoffs::item_add_force_;
350+ __asm { // edx - inv_item.inventory, edi - place_item.inventory
351+ pop ebx; // ret addr
352+ cmp dword ptr [eax + 0x20 ], item_type_weapon;
353+ je isWeapon;
354+ cmp dword ptr [eax + 0x20 ], item_type_ammo; // overwritten engine code
355+ jne skip;
356+ jmp item_identical_Ret;
357+ isWeapon:
358+ mov ecx, [edx + 0xC ]; // inv_item.miscFlags
359+ cmp ecx, [edi + 0xC ]; // place_item.miscFlags
360+ jne skip;
361+ cmp dword ptr [edx + 0x10 ], 0 ; // inv_item.charges
362+ jg skip;
363+ cmp dword ptr [edi + 0x10 ], 0 ; // place_item.charges
364+ jg skip;
365+ jmp item_identical_End; // return true
366+ skip:
367+ jmp ebx; // check caps pid
388368 }
389369}
390370
@@ -923,10 +903,9 @@ void Inventory::init() {
923903 ApplyInvenApCostPatch ();
924904 }
925905
926- // Set default ammo pid for unloaded weapons to make them stack regardless of previously loaded ammo
906+ // Stack empty weapons regardless of their previous ammo type
927907 // if (IniReader::GetConfigInt("Misc", "StackEmptyWeapons", 1)) {
928- MakeCall (0x4736C6 , inven_action_cursor_hack);
929- HookCall (0x4772AA , item_add_mult_hook);
908+ MakeCall (0x477A82 , item_identical_hack, 1 );
930909 // }
931910
932911 // Do not call the 'Move Items' window when using drag and drop to reload weapons in the inventory
0 commit comments