REDIVIVUS

Proposals / #981

MONSTERAI_CastSkillAtRandomOffset's skill mode is an int: callers push it sign-extended or whole

rejected · by Niehztog · submitted 2026-11-02, rejected 2026-11-02

nSkillMode (Stack[0x8]) is declared char, but the callers pass a full dword: AITHINK_Fn1_Imp sign-extends the monstats skill-mode byte before pushing it, 005e31d2 MOVSX EDX,byte ptr [EAX+0x180] / 005e31e0 PUSH EDX (call 005e31ec) and 005e32a3 MOVSX EDX,byte ptr [ECX+0x180] / 005e32b1 PUSH EDX (call 005e32bd); AITHINK_Fn1_Nihlathak pushes a whole EAX (005ee646 PUSH EAX, call 005ee663). For a char parameter VC8 passes the byte as it is (MOVZX), so the parameter was an int. Recompiled with VC8 SP1 (oracle, tree 3dba660): AITHINK_Fn1_Imp goes from OUR-1 (0.746) to the original's instruction count (0.804), AITHINK_Fn1_Nihlathak from OUR+3 (0.764) to OUR+1 (0.790); the function itself is unchanged and nothing loses its match.

Changes 1, applied together

  1. Set prototype win 0x005df850

    signaturevoid MONSTERAI_CastSkillAtRandomOffset(D2UnitStrc * pUnit, int32_t nRange, eD2Skills eSkill, char nSkillMode)→void MONSTERAI_CastSkillAtRandomOffset(D2UnitStrc * pUnit, int32_t nRange, eD2Skills eSkill, int nSkillMode)
    convention__fastcall