REDIVIVUS

Proposals / #1032

MONREGION_PopulateMonsterTypes's nMaxMons and nRandPick are ints: clamped and tested against 0 with JLE

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

Ghidra v1841 · 4ca0e98

nMaxMons ([EBP-0x40] = Stack[-0x44]) takes levels.txt NumMon and nRandPick ([EBP-0x3c] = Stack[-0x40]) the valid-monster count; every compare on them is signed: 005475fa CMP ECX,0xd / 00547609 JLE (cap at 13), 00547626 CMP [EBP-0x40],EDX / 00547629 JLE (EDX = nRandPick), 0054765a CMP [EBP-0x40],0 / 00547665 JLE, and 00547673 TEST EDX,EDX / 00547675 JLE. Ghidra leaves both undefined4 and resolves them to uint, so the generator declares uint32_t: the clamp comes out unsigned (JAE) and the tests against 0 become JE. Recompiled with VC8 SP1 (the 1.14d compiler) on main f26206a with both as int: the clamp is signed like the original's and the similarity rises 0.243 -> 0.256 (the function still differs in its pool copy and loops); no function in the TU changes status.

Changes 2, applied together

  1. Retype variable win 0x005475e0 Stack[-0x44]

    typeundefined4→int
  2. Retype variable win 0x005475e0 Stack[-0x40]

    typeundefined4→int