I've found start_dwarf_count for 50.07 Classic.
Unfortunately, it's not going to be that easy. Setting it above 9 causes a crash.
.text:0000000140CB5976 loc_140CB5976: ; CODE XREF: sub_140CB3AD0+1E35↑j
.text:0000000140CB5976 BF 07 00 00 00 mov edi, 7 ; START_DWARF_COUNT
.text:0000000140CB597B 48 8B 74 24 60 mov rsi, [rsp+2C0h+unit]
.text:0000000140CB5980 4C 8B 75 B8 mov r14, [rbp+1C0h+var_208]
.text:0000000140CB5984 44 8D 67 F8 lea r12d, [rdi-8] ; OKAY! This parameter needs to be set to -1 !
.text:0000000140CB5984 ; That chooses caste at random.
.text:0000000140CB5984 ; If it's >= 0, it selects that caste.
.text:0000000140CB5988
.text:0000000140CB5988 loc_140CB5988: ; CODE XREF: sub_140CB3AD0+1FEB↓j
.text:0000000140CB5988 FF CF dec edi
.text:0000000140CB598A E8 A1 49 3B FF call new_unit
.text:0000000140CB598F 48 8B D8 mov rbx, rax
.text:0000000140CB5992 48 89 44 24 60 mov [rsp+2C0h+unit], rax
.text:0000000140CB5997 45 8B C4 mov r8d, r12d
.text:0000000140CB599A 45 33 C9 xor r9d, r9d
.text:0000000140CB599D 0F B7 15 28 26 15 01 movzx edx, cs:word_141E07FCC ; example value: 23Ch, 572, DWARF. Unit type.
.text:0000000140CB59A4 48 8B C8 mov rcx, rax
.text:0000000140CB59A7
.text:0000000140CB59A7 this call crashes when startdwarf is 10 or higher.
.text:0000000140CB59A7 turns out that's because of the caste flag in r12d
.text:0000000140CB59A7 (passed in r8d, per above code).
.text:0000000140CB59A7 This parameter should be -1. When startdwarf is forced to 10,
.text:0000000140CB59A7 r12d is set to (10-8) = 2, which is a nonexistant caste.
.text:0000000140CB59A7 E8 94 4D 27 00 call sub_140F2A740 ; parameters: rcx=*unit,
.text:0000000140CB59A7 ; dx = creature type index (572=DWARF),
.text:0000000140CB59A7 ; r8w = caste (-1 for random),
.text:0000000140CB59A7 ; r9b flag: set unit 6-byte field @ 0D70h
This excessively-optimized code depends on knowing that EDI is set to 7 as a space-saving way to set R12D to -1, using the calculation (7-8).
R12 is then used to select the caste of the unit being generated. -1 means random; 0 means FEMALE; 1 means MALE; 2 or higher lead to a crash.
We need to enter the call to sub_140F2A740 with R8 == -1. I don't see a way to squeeze that into the current code.
Anyone have thoughts?
We found the startdwarf location relatively early on in the development cycle (we have a script for it that worked, so it was trivial), but we decided (as lethosor notes) not to publish it because our testing showed that it failed for counts greater than 9. I never investigated deeply to figure out why, since we wanted to get a release out and it wasn't worth blocking for this, and honestly I've never worked back to the problem.
Good find. I'm not inclined to try to try to come up with a patch that will make this work "as desired". If someone else wants to, more power to them. If someone comes up with a patch that works for start dwarf counts
less than 7 (such as, oh I don't know,
one), that I might be more interested in...
Poking at it a bit, the obvious solution is to patch n into the startdwarf location
and (255-n) in the last byte of the
LEA instruction, exactly 16 bytes later.