// File: Agusyc[P]CTRPG/src/jsonparser.cpp
// Function: parseEnemy(int)
Enemy parseEnemy(int index) {
    Json::Value root; // The root element
    Json::Reader reader; // The reader... that reads

    ifstream ifs("./json/enemies.json");

    bool parsingSuccessful = reader.parse(ifs, root);
    if (!parsingSuccessful) {
        // Print error
        cout << "Failed to parse the enemies." << endl << "Error:" << endl << reader.getFormattedErrorMessages();
        exit(1);
    }

    Json::Value jEnemy = root[index];

    Enemy enemy;

    enemy.name = jEnemy["name"].asString();
    enemy.attack = jEnemy["attack"].asInt();
    enemy.defense = jEnemy["defense"].asInt();
    enemy.shieldDefense = jEnemy["shieldDefense"].asInt();
    enemy.mana = jEnemy["mana"].asInt();
    enemy.stamina = jEnemy["stamina"].asInt();
    enemy.hp = jEnemy["hp"].asInt();
    enemy.xp = jEnemy["xp"].asInt();
    enemy.id = index;
    enemy.minLevel = jEnemy["minLevel"].asInt();
    enemy.maxLevel = jEnemy["maxLevel"].asInt();

    // Iterates trough the array "attacks", which contains all the indexes of the attacks of the enemy
    for (const Json::Value& attack : jEnemy["attacks"]) {
        enemy.attacks.push_back(parseAttack(attack.asInt())); // Pushes the attack to the vector
    }

    return enemy;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x550, %rsp            # imm = 0x550
movq %rdi, -0x458(%rbp)
movq %rdi, %rax
movq %rax, -0x450(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x3120
leaq -0x148(%rbp), %rdi
callq 0x32c0
jmp 0xdb9c
leaq 0x390b(%rip), %rsi      # 0x114ae
leaq -0x360(%rbp), %rdi
movl $0x8, %edx
callq 0x3550
jmp 0xdbb6
leaq -0x148(%rbp), %rdi
leaq -0x360(%rbp), %rsi
leaq -0x38(%rbp), %rdx
movl $0x1, %ecx
callq 0x3570
movb %al, -0x459(%rbp)
jmp 0xdbda
movb -0x459(%rbp), %al
andb $0x1, %al
movb %al, -0x361(%rbp)
testb $0x1, -0x361(%rbp)
jne 0xdd0d
movq 0xa3d4(%rip), %rdi      # 0x17fd0
leaq 0x38bf(%rip), %rsi      # 0x114c2
callq 0x3290
movq %rax, -0x468(%rbp)
jmp 0xdc11
movq -0x468(%rbp), %rdi
movq 0xa3a1(%rip), %rsi      # 0x17fc0
callq 0x32b0
movq %rax, -0x470(%rbp)
jmp 0xdc2d
movq -0x470(%rbp), %rdi
leaq 0x386c(%rip), %rsi      # 0x114a7
callq 0x3290
movq %rax, -0x478(%rbp)
jmp 0xdc49
movq -0x478(%rbp), %rdi
movq 0xa369(%rip), %rsi      # 0x17fc0
callq 0x32b0
movq %rax, -0x480(%rbp)
jmp 0xdc65
leaq -0x388(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x3480
jmp 0xdc7a
movq -0x480(%rbp), %rdi
leaq -0x388(%rbp), %rsi
callq 0x3230
jmp 0xdc8f
leaq -0x388(%rbp), %rdi
callq 0x31b0
movl $0x1, %edi
callq 0x3350
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xe1b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xe1a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xe19d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
leaq -0x388(%rbp), %rdi
callq 0x31b0
jmp 0xe19d
movl -0xc(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x32f0
movq %rax, -0x488(%rbp)
jmp 0xdd22
movq -0x488(%rbp), %rsi
leaq -0x3b0(%rbp), %rdi
callq 0x34b0
jmp 0xdd37
movq -0x458(%rbp), %rdi
movb $0x0, -0x3b1(%rbp)
callq 0x8040
leaq 0x37bd(%rip), %rsi      # 0x1150e
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x490(%rbp)
jmp 0xdd66
movq -0x490(%rbp), %rsi
leaq -0x3d8(%rbp), %rdi
callq 0x3560
jmp 0xdd7b
movq -0x458(%rbp), %rdi
leaq -0x3d8(%rbp), %rsi
movq %rsi, -0x4a0(%rbp)
callq 0x3360
movq -0x4a0(%rbp), %rdi
callq 0x31b0
leaq 0x35c0(%rip), %rsi      # 0x11368
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x498(%rbp)
jmp 0xddbd
movq -0x498(%rbp), %rdi
callq 0x3450
movl %eax, -0x4a4(%rbp)
jmp 0xddd1
movq -0x458(%rbp), %rax
movl -0x4a4(%rbp), %ecx
movl %ecx, 0x20(%rax)
leaq 0x35d4(%rip), %rsi      # 0x113bc
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x4b0(%rbp)
jmp 0xddfd
movq -0x4b0(%rbp), %rdi
callq 0x3450
movl %eax, -0x4b4(%rbp)
jmp 0xde11
movq -0x458(%rbp), %rax
movl -0x4b4(%rbp), %ecx
movl %ecx, 0x24(%rax)
leaq 0x3753(%rip), %rsi      # 0x1157b
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x4c0(%rbp)
jmp 0xde3d
movq -0x4c0(%rbp), %rdi
callq 0x3450
movl %eax, -0x4c4(%rbp)
jmp 0xde51
movq -0x458(%rbp), %rax
movl -0x4c4(%rbp), %ecx
movl %ecx, 0x28(%rax)
leaq 0x355c(%rip), %rsi      # 0x113c4
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x4d0(%rbp)
jmp 0xde7d
movq -0x4d0(%rbp), %rdi
callq 0x3450
movl %eax, -0x4d4(%rbp)
jmp 0xde91
movq -0x458(%rbp), %rax
movl -0x4d4(%rbp), %ecx
movl %ecx, 0x2c(%rax)
leaq 0x3521(%rip), %rsi      # 0x113c9
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x4e0(%rbp)
jmp 0xdebd
movq -0x4e0(%rbp), %rdi
callq 0x3450
movl %eax, -0x4e4(%rbp)
jmp 0xded1
movq -0x458(%rbp), %rax
movl -0x4e4(%rbp), %ecx
movl %ecx, 0x30(%rax)
leaq 0x34d1(%rip), %rsi      # 0x113b9
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x4f0(%rbp)
jmp 0xdefd
movq -0x4f0(%rbp), %rdi
callq 0x3450
movl %eax, -0x4f4(%rbp)
jmp 0xdf11
movq -0x458(%rbp), %rax
movl -0x4f4(%rbp), %ecx
movl %ecx, 0x34(%rax)
leaq 0x34ae(%rip), %rsi      # 0x113d6
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x500(%rbp)
jmp 0xdf3d
movq -0x500(%rbp), %rdi
callq 0x3450
movl %eax, -0x504(%rbp)
jmp 0xdf51
movq -0x458(%rbp), %rax
movl -0x504(%rbp), %ecx
movl %ecx, 0x38(%rax)
movl -0xc(%rbp), %ecx
movl %ecx, 0x3c(%rax)
leaq 0x35e3(%rip), %rsi      # 0x11551
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x510(%rbp)
jmp 0xdf83
movq -0x510(%rbp), %rdi
callq 0x3450
movl %eax, -0x514(%rbp)
jmp 0xdf97
movq -0x458(%rbp), %rax
movl -0x514(%rbp), %ecx
movl %ecx, 0x40(%rax)
leaq 0x35ac(%rip), %rsi      # 0x1155a
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x520(%rbp)
jmp 0xdfc3
movq -0x520(%rbp), %rdi
callq 0x3450
movl %eax, -0x524(%rbp)
jmp 0xdfd7
movq -0x458(%rbp), %rax
movl -0x524(%rbp), %ecx
movl %ecx, 0x44(%rax)
leaq 0x33c3(%rip), %rsi      # 0x113b1
leaq -0x3b0(%rbp), %rdi
callq 0x3100
movq %rax, -0x530(%rbp)
jmp 0xe003
movq -0x530(%rbp), %rax
movq %rax, -0x3e0(%rbp)
movq -0x3e0(%rbp), %rsi
leaq -0x3f0(%rbp), %rdi
callq 0x3300
jmp 0xe026
movq -0x3e0(%rbp), %rsi
leaq -0x400(%rbp), %rdi
callq 0x3420
jmp 0xe03b
jmp 0xe03d
leaq -0x3f0(%rbp), %rdi
leaq -0x400(%rbp), %rsi
callq 0xf0f0
movb %al, -0x531(%rbp)
jmp 0xe058
movb -0x531(%rbp), %al
testb $0x1, %al
jne 0xe067
jmp 0xe12c
leaq -0x3f0(%rbp), %rdi
callq 0xf120
movq %rax, -0x540(%rbp)
jmp 0xe07c
movq -0x458(%rbp), %rax
movq -0x540(%rbp), %rcx
movq %rcx, -0x408(%rbp)
addq $0x48, %rax
movq %rax, -0x550(%rbp)
movq -0x408(%rbp), %rdi
callq 0x3450
movl %eax, -0x544(%rbp)
jmp 0xe0b0
movl -0x544(%rbp), %esi
leaq -0x448(%rbp), %rdi
callq 0xd6a0
jmp 0xe0c4
movq -0x550(%rbp), %rdi
leaq -0x448(%rbp), %rsi
callq 0xf140
jmp 0xe0d9
leaq -0x448(%rbp), %rdi
callq 0x8560
leaq -0x3f0(%rbp), %rdi
callq 0xf170
jmp 0xe0f3
jmp 0xe03d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
jmp 0xe185
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x150(%rbp)
movl %eax, -0x154(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x8560
jmp 0xe185
movb $0x1, -0x3b1(%rbp)
testb $0x1, -0x3b1(%rbp)
jne 0xe148
movq -0x458(%rbp), %rdi
callq 0x8140
leaq -0x3b0(%rbp), %rdi
callq 0x3150
leaq -0x360(%rbp), %rdi
callq 0x30b0
leaq -0x148(%rbp), %rdi
callq 0xf0a0
leaq -0x38(%rbp), %rdi
callq 0x3150
movq -0x450(%rbp), %rax
addq $0x550, %rsp            # imm = 0x550
popq %rbp
retq
movq -0x458(%rbp), %rdi
callq 0x8140
leaq -0x3b0(%rbp), %rdi
callq 0x3150
leaq -0x360(%rbp), %rdi
callq 0x30b0
leaq -0x148(%rbp), %rdi
callq 0xf0a0
leaq -0x38(%rbp), %rdi
callq 0x3150
movq -0x150(%rbp), %rdi
callq 0x3530
nopw (%rax,%rax)