// File: BleuLlama[P]msf-tools/VoiceFile.cpp
// Function: VoiceFile::VoiceFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
VoiceFile::VoiceFile( std::string _path )
	: valid( false )
	, buffer( NULL )
	, vrDir( "." )
	, vrVoiceDir( "." )
	, vrMSFFile( "x" )
{
	if( DiskUtils::IsValidDir( _path )) {
		this->ConfigurePath( _path );
	} else {
		return;
	}


	/* load in the buffer */
	FILE * fp = NULL;

	size_t bufsize = 0;
	size_t readbytes = 0;

	/* attempt to open the file */
	fp = fopen( this->vrMSFFile.c_str(), "r" );

	if( !fp ) {
		std::cerr << "Unable to open file: " << vrMSFFile << std::endl;
		return;
	}

	/* read it in to a buffer */
	fseek( fp, 0, SEEK_END );
	bufsize = ftell( fp );
	fseek( fp, 0, SEEK_SET );
	//printf( "File is %ld bytes\n", bufsize );
	if( bufsize != 16384 ) {
		std::cerr << "File is the wrong size." << std::endl;
		std::cerr << "Bad things might happen" << std::endl;
		std::cerr << std::endl;
	}

	this->buffer = (unsigned char *) malloc( sizeof( unsigned char ) * bufsize );

	if( !this->buffer ) {
		std::cerr << "Mem Alloc error!" << std::endl;
		fclose( fp );
		return;
	}


	readbytes = fread( this->buffer, sizeof( char ), bufsize, fp );
	fclose( fp );

	if( readbytes == 0 ) {
		std::cerr << "Couldn't read!" << std::endl;
		return;
	}


	/* 1. validate its' the right file */
	if(   this->buffer[0] != 'M'
	   || this->buffer[1] != 'S'
	   || this->buffer[2] != 'G'
	   || this->buffer[3] != 'L' ) {
		std::cerr << "This is not a Message List file!" << std::endl;
		return;
	}


	valid = true;
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rsi, -0xa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movb $0x0, (%rax)
movq $0x0, 0x8(%rax)
addq $0x10, %rax
movq %rax, -0x90(%rbp)
leaq -0x11(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x2330
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rdx
leaq 0x2dad(%rip), %rsi      # 0x601d
callq 0x2e40
jmp 0x3277
leaq -0x11(%rbp), %rdi
callq 0x21c0
movq -0x98(%rbp), %rax
addq $0x30, %rax
movq %rax, -0xb0(%rbp)
leaq -0x25(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x2330
movq -0xb0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
leaq 0x2d66(%rip), %rsi      # 0x601d
callq 0x2e40
jmp 0x32be
leaq -0x25(%rbp), %rdi
callq 0x21c0
movq -0x98(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xc0(%rbp)
leaq -0x26(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x2330
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
leaq 0x2d86(%rip), %rsi      # 0x6084
callq 0x2e40
jmp 0x3305
leaq -0x26(%rbp), %rdi
callq 0x21c0
movq -0xa0(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x20a0
jmp 0x3320
leaq -0x48(%rbp), %rdi
callq 0x2640
movb %al, -0xc1(%rbp)
jmp 0x3331
leaq -0x48(%rbp), %rdi
callq 0x20e0
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x3349
jmp 0x340e
movq -0xa0(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x20a0
jmp 0x335b
movq -0x98(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3720
jmp 0x336d
leaq -0x68(%rbp), %rdi
callq 0x20e0
jmp 0x3413
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x11(%rbp), %rdi
callq 0x21c0
jmp 0x3717
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x25(%rbp), %rdi
callq 0x21c0
jmp 0x3700
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x26(%rbp), %rdi
callq 0x21c0
jmp 0x36f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x36e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x20e0
jmp 0x36e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x20e0
jmp 0x36e8
jmp 0x370e
movq -0x98(%rbp), %rdi
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
addq $0x50, %rdi
callq 0x2090
movq %rax, %rdi
leaq 0x2c41(%rip), %rsi      # 0x6086
callq 0x2210
movq %rax, -0xd0(%rbp)
jmp 0x3453
movq -0xd0(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x34bb
movq 0x5b84(%rip), %rdi      # 0x8ff0
leaq 0x2c15(%rip), %rsi      # 0x6088
callq 0x2180
movq %rax, -0xd8(%rbp)
jmp 0x3481
movq -0xd8(%rbp), %rdi
movq -0x98(%rbp), %rsi
addq $0x50, %rsi
callq 0x2150
movq %rax, -0xe0(%rbp)
jmp 0x34a1
movq -0xe0(%rbp), %rdi
movq 0x5b11(%rip), %rsi      # 0x8fc0
callq 0x21a0
jmp 0x34b6
jmp 0x370e
movq -0x70(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x21f0
jmp 0x34cf
movq -0x70(%rbp), %rdi
callq 0x2030
movq %rax, -0xe8(%rbp)
jmp 0x34e1
movq -0xe8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x21f0
jmp 0x34fb
cmpq $0x4000, -0x78(%rbp)    # imm = 0x4000
je 0x357e
movq 0x5ae4(%rip), %rdi      # 0x8ff0
leaq 0x2b8b(%rip), %rsi      # 0x609e
callq 0x2180
movq %rax, -0xf0(%rbp)
jmp 0x3521
movq -0xf0(%rbp), %rdi
movq 0x5a91(%rip), %rsi      # 0x8fc0
callq 0x21a0
jmp 0x3536
movq 0x5ab3(%rip), %rdi      # 0x8ff0
leaq 0x2b72(%rip), %rsi      # 0x60b6
callq 0x2180
movq %rax, -0xf8(%rbp)
jmp 0x3552
movq -0xf8(%rbp), %rdi
movq 0x5a60(%rip), %rsi      # 0x8fc0
callq 0x21a0
jmp 0x3567
movq 0x5a82(%rip), %rdi      # 0x8ff0
movq 0x5a4b(%rip), %rsi      # 0x8fc0
callq 0x21a0
jmp 0x357c
jmp 0x357e
movq -0x78(%rbp), %rdi
shlq $0x0, %rdi
callq 0x2250
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, 0x8(%rax)
jne 0x35e1
movq 0x5a49(%rip), %rdi      # 0x8ff0
leaq 0x2b20(%rip), %rsi      # 0x60ce
callq 0x2180
movq %rax, -0x100(%rbp)
jmp 0x35bc
movq -0x100(%rbp), %rdi
movq 0x59f6(%rip), %rsi      # 0x8fc0
callq 0x21a0
jmp 0x35d1
movq -0x70(%rbp), %rdi
callq 0x2190
jmp 0x35dc
jmp 0x370e
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x78(%rbp), %rdx
movq -0x70(%rbp), %rcx
movl $0x1, %esi
callq 0x2280
movq %rax, -0x108(%rbp)
jmp 0x3607
movq -0x108(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x70(%rbp), %rdi
callq 0x2190
jmp 0x361d
cmpq $0x0, -0x80(%rbp)
jne 0x365a
movq 0x59c5(%rip), %rdi      # 0x8ff0
leaq 0x2aad(%rip), %rsi      # 0x60df
callq 0x2180
movq %rax, -0x110(%rbp)
jmp 0x3640
movq -0x110(%rbp), %rdi
movq 0x5972(%rip), %rsi      # 0x8fc0
callq 0x21a0
jmp 0x3655
jmp 0x370e
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movzbl (%rax), %eax
cmpl $0x4d, %eax
jne 0x36a9
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x1(%rax), %eax
cmpl $0x53, %eax
jne 0x36a9
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x2(%rax), %eax
cmpl $0x47, %eax
jne 0x36a9
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
movzbl 0x3(%rax), %eax
cmpl $0x4c, %eax
je 0x36dc
movq 0x5940(%rip), %rdi      # 0x8ff0
leaq 0x2a37(%rip), %rsi      # 0x60ee
callq 0x2180
movq %rax, -0x118(%rbp)
jmp 0x36c5
movq -0x118(%rbp), %rdi
movq 0x58ed(%rip), %rsi      # 0x8fc0
callq 0x21a0
jmp 0x36da
jmp 0x370e
movq -0x98(%rbp), %rax
movb $0x1, (%rax)
jmp 0x370e
movq -0xc0(%rbp), %rdi
callq 0x20e0
movq -0xb0(%rbp), %rdi
callq 0x20e0
movq -0x90(%rbp), %rdi
callq 0x20e0
jmp 0x3717
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x20(%rbp), %rdi
callq 0x2320