[1.10f] Fixing the CorruptArcher's AI

This forum is for discussions on how to edit what can not be edited through the txt files, needless to say this isn't about battle net hacking.

Moderators: Nefarius, Havvoric

Post Reply
User avatar
Senior Moderator
Champion of the Light
Posts: 455
Joined: Thu Mar 10, 2016 8:31 am


[1.10f] Fixing the CorruptArcher's AI

Post by Ogodei » Fri Jun 01, 2018 10:08 am

Hello ;)

Since v1.10f the CorruptArcher's AI became bugged, and often makes the units run back and forth without an apparent logic. This is due to a bad distance check in the ai flee routine, which makes it act much like a short-range monster rather than the archer it's supposed to be.

The part of the code we need to look at is this:

Code: Select all

CPU Disasm
Address   Hex dump          Command                                  Comments
6FCD8328    837C24 10 06    CMP DWORD PTR SS:[ESP+10],6              ; // Check Distance from the Target
6FCD832D   7D 5C           JGE SHORT 6FCD838B                       ; ; If the Distance is > 6 , skip everything
6FCD832F    8B46 20         MOV EAX,DWORD PTR DS:[ESI+20]
6FCD8332    BA C590C66A     MOV EDX,6AC690C5
6FCD8337    F7E2            MUL EDX
6FCD8339    8B4E 24         MOV ECX,DWORD PTR DS:[ESI+24]
6FCD833C    33ED            XOR EBP,EBP
6FCD833E    03C1            ADD EAX,ECX
6FCD8340    B9 64000000     MOV ECX,64
6FCD8345    13D5            ADC EDX,EBP
6FCD8347    8946 20         MOV DWORD PTR DS:[ESI+20],EAX
6FCD834A    8956 24         MOV DWORD PTR DS:[ESI+24],EDX
6FCD834D    33D2            XOR EDX,EDX
6FCD834F    F7F1            DIV ECX
6FCD8351    33C0            XOR EAX,EAX
6FCD8353    8A47 6D         MOV AL,BYTE PTR DS:[EDI+6D]
6FCD8356    0FBF4C43 68     MOVSX ECX,WORD PTR DS:[EAX*2+EBX+68]
6FCD835B    3BD1            CMP EDX,ECX                              ; ; Roll chance to flee
6FCD835D   7D 28           JGE SHORT 6FCD8387
6FCD835F    55              PUSH EBP
6FCD8360    6A 64           PUSH 64                                  ; ; Bonus to Speed = 100%
6FCD8362    33D2            XOR EDX,EDX
6FCD8364    8BCE            MOV ECX,ESI                              ; ; ESI = Unit
6FCD8366    E8 457EFFFF     CALL 6FCD01B0                            ; ; Call AI_Add_Speed
6FCD836B    8BD6            MOV EDX,ESI                              ; ; ESI = Unit
6FCD836D    8BCF            MOV ECX,EDI                              ; ; EDI = Target
6FCD836F    8B6C24 24       MOV EBP,DWORD PTR SS:[ESP+24]
6FCD8373    6A 01           PUSH 1                                   ; ; Check Flags
6FCD8375    6A 0C           PUSH 0C                                  ; ; Check Free Sub Tiles in Range (and flee by those exact sub-tiles)
6FCD8377    55              PUSH EBP
6FCD8378    E8 5383FFFF     CALL 6FCD06D0                            ; ; Call AI_Check_Flee_Free_Path
6FCD837D    85C0            TEST EAX,EAX                             ; ; Is the path Free?
As you can see, there's an error in the logic of this. The AI first checks if the distance from the target is >= 6 , and if so, it starts rolling a chance to flee, or else it will approach to re-enter in range (you can notice it if you scroll down in the code).
What we're doing here is making the Distance check greater than the Flee sub tiles.

I'll show you an example:


Code: Select all

 6FCD8375    6A 0C           PUSH 0C
change to:

Code: Select all

6FCD8375    6A 05           PUSH 5
with this change, the corrupt archers will stop running back and forth, and will only flee from the target. Once they're safe, they will start barraging the enemies with either missiles or skills.

p.s : There is also a softcoded approach, which can be done to perfectly fix this AI even without coding. Set AIP8 (''walk towards distance'') to 255. With this, you'll need to be 255 tiles far (impossible) from the unit for it to approach you (in the bugged way). Keep in mind, however, that the AI will always try to enter a range in which it will be able to shoot at the enemy.

happy modding!

User avatar
Forum Regular
Posts: 724
Joined: Sat Mar 07, 2015 9:07 pm
United States of America

Re: [1.10f] Fixing the CorruptArcher's AI

Post by devurandom » Fri Jun 01, 2018 12:21 pm

Nice Find... :cool:
I'm wondering what other units are bugged by this function.. those with Arg2 = 1E ?.

Other Calls to the same func in 1.10

Code: Select all

6FCD8378  CALL 6FCD06D0                            Arg2 = 0C, Arg3 = 1
6FCD974A  CALL 6FCD06D0                            Arg2 = 8, Arg3 = 1
6FCD97C0  CALL 6FCD06D0                            Arg2 = 8, Arg3 = 1
6FCE5EA2  CALL 6FCD06D0                            Arg3 = 0
6FCE7FF9  CALL 6FCD06D0                            Arg2 = 1E, Arg3 = 0
6FCE8177  CALL 6FCD06D0                            Arg2 = 1E, Arg3 = 1
6FCEBA9A  CALL 6FCD06D0                            Arg2 = 8, Arg3 = 1
For anyone interested, I found the most likely port to 1.13c to test

Code: Select all

6FCA66C7    6A 0C         PUSH 0C                  ; |Arg2 = 0C
Assembly Reference | 1.13d Code Edits | UVLoD | BaseMod Plugin

Fiat paper money is the most elaborate and well devised form of slavery the world has ever seen..

Post Reply

Return to “Code Editing”