// File: /workspace/github_cpp_makefile_star2_O2/OpenFodder[P]SOS_Unpacker/SOS_Unpacker.cpp
// Function: main
int main(int argc, char* argv[]) {
    std::cout << "SOS Unpacker\n";
    std::cout << "https://github.com/OpenFodder\n\n";

    if (CAPSInit()) {
        std::cout << "CAPSImg.dll not found\n";
    } else {

        system("mkdir out");

        for (auto& extension : { ".raw", ".ipf" } ) {
            std::cout << "Finding " << extension << " files\n";
            auto Files = local_DirectoryList(".", extension);

            if (!Files.size())
                std::cout << "No " << extension << " files found\n";

            //local_DirectoryList
            for (auto& File : Files) {
                std::cout << "\nLoading " << File << "\n";
                auto Tracks = GetSOSTracks(File);

                if (!Tracks.size()) {
                    std::cout << "No Tracks found in file: " << File << "\n";
                    continue;
                }


                std::cout << "Extracting to .\\out\\...\n";
                ExtractFiles(Tracks, "out");
            }
        }
    }

    std::cout << "Press enter to finish\n";
    std::cin.get();

    CAPSExit();
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq 0x90fc(%rip), %rbx      # 0x16fd0
leaq 0x15e7(%rip), %rsi      # 0xf4c2
movq %rbx, %rdi
callq 0x31c0
leaq 0x15e6(%rip), %rsi      # 0xf4d0
movq %rbx, %rdi
callq 0x31c0
callq 0x4804
testl %eax, %eax
je 0xdf46
movq 0x90ce(%rip), %rdi      # 0x16fd0
leaq 0x15e7(%rip), %rsi      # 0xf4f0
callq 0x31c0
movq 0x90bb(%rip), %rdi      # 0x16fd0
leaq 0x165f(%rip), %rsi      # 0xf57b
callq 0x31c0
movq 0x90b8(%rip), %rdi      # 0x16fe0
callq 0x3230
callq 0x4807
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15ba(%rip), %rdi      # 0xf507
callq 0x3170
leaq 0x15b8(%rip), %rax      # 0xf511
movq %rax, 0x30(%rsp)
leaq 0x15b1(%rip), %rax      # 0xf516
movq %rax, 0x38(%rsp)
xorl %eax, %eax
movq 0x905d(%rip), %rbx      # 0x16fd0
leaq 0x60(%rsp), %r13
leaq 0x40(%rsp), %r14
leaq 0x80(%rsp), %rbp
cmpq $0x10, %rax
je 0xdf0e
movq %rbx, %rdi
leaq 0x1586(%rip), %rsi      # 0xf51b
movq %rax, %r15
callq 0x31c0
movq %r15, 0x28(%rsp)
movq 0x30(%rsp,%r15), %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x31c0
movq %rax, %rdi
leaq 0x1568(%rip), %rsi      # 0xf524
callq 0x31c0
movq %r13, %rdi
leaq 0x136b(%rip), %rsi      # 0xf336
leaq 0x6(%rsp), %rdx
callq 0x30a0
movq %r14, %rdi
movq %r15, %rsi
leaq 0x7(%rsp), %rdx
callq 0x30a0
movq %r15, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0xe8cb
movq %r14, %rdi
callq 0x33f8
movq %r13, %rdi
callq 0x33f8
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %r12
cmpq %r15, %r12
jne 0xe117
movq %rbx, %rdi
leaq 0x1505(%rip), %rsi      # 0xf52c
callq 0x31c0
movq %rax, %rdi
movq 0x20(%rsp), %rsi
callq 0x31c0
movq %rax, %rdi
leaq 0x14ed(%rip), %rsi      # 0xf530
callq 0x31c0
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %r12
jmp 0xe117
movq %rbx, %rdi
leaq 0x14dd(%rip), %rsi      # 0xf53e
callq 0x31c0
movq %rax, %rdi
movq %r15, %rsi
callq 0x3190
movq %rax, %rdi
leaq 0x1442(%rip), %rsi      # 0xf4bd
callq 0x31c0
movq %r14, %rdi
movq %r15, %rsi
callq 0xd7a2
movq 0x48(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0xe0e2
movq %rbx, %rdi
leaq 0x14c1(%rip), %rsi      # 0xf562
callq 0x31c0
movq %rbp, %rdi
movq %r14, %rsi
callq 0xe252
movq %r13, %rdi
leaq 0x1452(%rip), %rsi      # 0xf50d
leaq 0x6(%rsp), %rdx
callq 0x30a0
movq %rbp, %rdi
movq %r13, %rsi
callq 0xdbc0
movq %r13, %rdi
callq 0x33f8
movq %rbp, %rdi
callq 0xe1d4
jmp 0xe10b
movq %rbx, %rdi
leaq 0x145c(%rip), %rsi      # 0xf548
callq 0x31c0
movq %rax, %rdi
movq %r15, %rsi
callq 0x3190
movq %rax, %rdi
leaq 0x13b7(%rip), %rsi      # 0xf4bd
callq 0x31c0
movq %r14, %rdi
callq 0xe1d4
addq $0x20, %r15
cmpq %r12, %r15
jne 0xe057
leaq 0x8(%rsp), %rdi
callq 0xe1d4
movq 0x28(%rsp), %rax
addq $0x8, %rax
jmp 0xdf85
movq %rax, %rbx
jmp 0xe19c
movq %rax, %rbx
jmp 0xe14f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x33f8
leaq 0x60(%rsp), %rdi
callq 0x33f8
jmp 0xe19c
jmp 0xe18f
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x33f8
jmp 0xe16f
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xe1d4
jmp 0xe183
jmp 0xe18f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xe1d4
jmp 0xe192
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0xe1d4
movq %rbx, %rdi
callq 0x3380