Hey there, it's been a while.
During a conversation on our discord server I thought that I could do this fix way better. The previous work was more like a guess work as I was completely new to code edit and also eager to share info, guides and useful features with the community.
So, here I am " fixing my fix " so to speak, in order for it to only affect the Hirelings (i.e units that use the 'hireable' AI).
Let's start:
Our work begins at D2Game.0xB414F: we are inside the Hireable's AI code, and there are two functions to notice :
Code: Select all
07F8414F 8B4C24 40 mov ecx,dword ptr ss:[esp+40]
07F84153 6A 64 push 64 ; 100 extra speed
07F84155 51 push ecx
07F84156 33D2 xor edx,edx
07F84158 8BCE mov ecx,esi ; monster
07F84169 E8 32C3FEFF call d2game.7F704A0 ; call AI_SetSpeedEx
07F8415F 8BCF mov ecx,edi
07F84161 8BD6 mov edx,esi
07F84163 8B4424 38 mov eax,dword ptr ss:[esp+38]
07F84167 53 push ebx
07F84168 55 push ebp
07F84169 E832C3FEFF call d2game.7F704A0 -> hijack to D2Game.0xA04C0 (approach_RN)
07F8416E 85C0 test eax,eax
07F84170 0F85 6B040000 jne d2game.7F845E1
The second step is a bit more complex as we have to write a new custom function for our hireable. We are editing the basic leash where the pUnit is told to walk to a spot near its pOwner. We want a function that still does that but also checks the animation mode used by the pOwner unit ( in this case, pOwner is the player who owns the mercenary).
Code: Select all
07F84030 8B4424 34 mov eax,dword ptr ss:[esp+34]
07F84034 50 push eax
07F84035 8BD6 mov edx,esi
07F84037 53 push ebx
07F84038 E8 63C4FEFF call d2game.7F704A0 -> hijack to custom function ( in this example, it should be call d2game.7FC6EA6)
07F8403D 85C0 test eax,eax
Code: Select all
- - - c u s t o m f u n c t i o n - - -
07FC6EA6 8B4424 08 mov eax,dword ptr ss:[esp+8] ; get Y coord;
07FC6EAA 6A 04 push 4 ;
07FC6EAC 6A 01 push 1 ;
07FC6EAE 50 push eax ; use Y coord as argument
07FC6EAF 8B4424 10 mov eax,dword ptr ss:[esp+10] ; get X coord
07FC6EB3 50 push eax ; use X coord as argument
07FC6EB4 85ED test ebp,ebp ; Is there any owner ? (pOwner gets stored in EBP in this AI, at this point)
07FC6EB6 74 10 je d2game.7FC6EC8 ; if it's not, just use WL
07FC6EB8 837D 00 00 cmp dword ptr ss:[ebp],0 ; is pOwner a player type unit?
07FC6EBC 75 0A jne d2game.7FC6EC8 ; if it's not, just use WL
07FC6EBE 837D 10 03 cmp dword ptr ss:[ebp+10],3 ; is the pOwner using RN anim ?
07FC6EC2 75 04 jne d2game.7FC6EC8 ; if they're not, just use WL
07FC6EC4 6A 0F push F ; use RN as argument
07FC6EC6 EB 02 jmp d2game.7FC6ECA ; skip using WL
07FC6EC8 6A 02 push 2 ; use WL as argument
07FC6ECA 6A 00 push 0 ; pTarget = NULL ( not needed because the function already uses x\y coords )
07FC6ECC E8 6F93FAFF call d2game.7F70240 ; call the standard AI_Approach function
07FC6ED1 C2 0800 ret 8 ; return to the vanilla code
07FC6ED4 90 nop
Happy modding