// File: Thilotilo[P]DoaERando/Generals.cpp
// Function: DoaERando::Generals::RandomizeCaoCaoAndSunCe(DoaERando::RandomNumberGenerator&)
void Generals::RandomizeCaoCaoAndSunCe(RNG& rng)
{
    // Scale the generals STR/INT/AGI to a high range (220-255)
    int CaoCaoIndex = GetGeneralIndexById(CAO_CAO_ID);
    myGenerals[CaoCaoIndex].strength = rng.GetRandomByte(220, 255);
    myGenerals[CaoCaoIndex].intelligence = rng.GetRandomByte(220, 255);
    myGenerals[CaoCaoIndex].agility = rng.GetRandomByte(220, 255);

    int SunCeIndex = GetGeneralIndexById(SUN_CE_ID);
    myGenerals[SunCeIndex].strength = rng.GetRandomByte(220, 255);
    myGenerals[SunCeIndex].intelligence = rng.GetRandomByte(220, 255);
    myGenerals[SunCeIndex].agility = rng.GetRandomByte(220, 255);

    // Update the Sun Ce portrait to look like Sun Quan but different color
    myRom.WriteByte(0x330CD, 0x4E); // Portrait Slices
    myRom.WriteByte(0x330CE, 0x4F);
    myRom.WriteByte(0x330CF, 0x50);
    myRom.WriteByte(0x330D0, 0x51);
    myRom.WriteByte(0x330D1, 0x52);
    myRom.WriteByte(0x330D2, 0x53);
    myRom.WriteByte(0x330D3, 0x07); // Portrait color

    // Update the Cao Cao portrait to look like Cao Pi but different color
    myRom.WriteByte(0x333AD, 0x42); // Portrait Slices
    myRom.WriteByte(0x333AE, 0x43);
    myRom.WriteByte(0x333AF, 0x44);
    myRom.WriteByte(0x333B0, 0x45);
    myRom.WriteByte(0x333B1, 0x46);
    myRom.WriteByte(0x333B2, 0x47);
    myRom.WriteByte(0x333B3, 0x07); // Portrait color
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x20(%rbp)
movl $0x70, %esi
callq 0x415940
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x41db50
movq -0x20(%rbp), %rdi
movb %al, -0x26(%rbp)
movslq -0x14(%rbp), %rsi
callq 0x416bd0
movb -0x26(%rbp), %cl
movb %cl, 0x6(%rax)
movq -0x10(%rbp), %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x41db50
movq -0x20(%rbp), %rdi
movb %al, -0x25(%rbp)
movslq -0x14(%rbp), %rsi
callq 0x416bd0
movb -0x25(%rbp), %cl
movb %cl, 0x7(%rax)
movq -0x10(%rbp), %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x41db50
movq -0x20(%rbp), %rdi
movb %al, -0x24(%rbp)
movslq -0x14(%rbp), %rsi
callq 0x416bd0
movb -0x24(%rbp), %cl
movq -0x20(%rbp), %rdi
movb %cl, 0xe(%rax)
movl $0x56, %esi
callq 0x415940
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x41db50
movq -0x20(%rbp), %rdi
movb %al, -0x23(%rbp)
movslq -0x18(%rbp), %rsi
callq 0x416bd0
movb -0x23(%rbp), %cl
movb %cl, 0x6(%rax)
movq -0x10(%rbp), %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x41db50
movq -0x20(%rbp), %rdi
movb %al, -0x22(%rbp)
movslq -0x18(%rbp), %rsi
callq 0x416bd0
movb -0x22(%rbp), %cl
movb %cl, 0x7(%rax)
movq -0x10(%rbp), %rdi
movl $0xdc, %esi
movl $0xff, %edx
callq 0x41db50
movq -0x20(%rbp), %rdi
movb %al, -0x21(%rbp)
movslq -0x18(%rbp), %rsi
callq 0x416bd0
movb -0x21(%rbp), %dl
movq %rax, %rcx
movq -0x20(%rbp), %rax
movb %dl, 0xe(%rcx)
movq 0x48(%rax), %rdi
movl $0x330cd, %esi          # imm = 0x330CD
movl $0x4e, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x330ce, %esi          # imm = 0x330CE
movl $0x4f, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x330cf, %esi          # imm = 0x330CF
movl $0x50, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x330d0, %esi          # imm = 0x330D0
movl $0x51, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x330d1, %esi          # imm = 0x330D1
movl $0x52, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x330d2, %esi          # imm = 0x330D2
movl $0x53, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x330d3, %esi          # imm = 0x330D3
movl $0x7, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x333ad, %esi          # imm = 0x333AD
movl $0x42, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x333ae, %esi          # imm = 0x333AE
movl $0x43, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x333af, %esi          # imm = 0x333AF
movl $0x44, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x333b0, %esi          # imm = 0x333B0
movl $0x45, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x333b1, %esi          # imm = 0x333B1
movl $0x46, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x333b2, %esi          # imm = 0x333B2
movl $0x47, %edx
callq 0x404c20
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x333b3, %esi          # imm = 0x333B3
movl $0x7, %edx
callq 0x404c20
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)