// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r13
movq %rdi, %r12
movb $0x0, (%rdi)
andq $0x0, 0x8(%rdi)
leaq 0x10(%rdi), %rbx
leaq 0x1596(%rip), %r15      # 0x401d
leaq 0x7(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2956
leaq 0x30(%r12), %r14
leaq 0x7(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2956
leaq 0x50(%r12), %r15
leaq 0x15cc(%rip), %rsi      # 0x4084
leaq 0x7(%rsp), %rdx
movq %r15, %rdi
callq 0x2956
leaq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x28(%rsp), %rdi
callq 0x2442
movl %eax, %ebp
leaq 0x28(%rsp), %rdi
callq 0x2060
testb %bpl, %bpl
je 0x2c5c
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq 0x2170
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x2cb4
leaq 0x8(%rsp), %rdi
callq 0x2060
movq (%r15), %rdi
leaq 0x1567(%rip), %rsi      # 0x4086
callq 0x2130
testq %rax, %rax
je 0x2bfc
movq %rax, %r13
pushq $0x2
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x2120
movq %r13, %rdi
callq 0x2030
movq %rax, %rbp
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2120
cmpq $0x4000, %rbp           # imm = 0x4000
je 0x2b9f
movq 0x448c(%rip), %rdi      # 0x6ff0
leaq 0x1533(%rip), %rsi      # 0x409e
callq 0x2100
movq %rax, %rdi
callq 0x2080
movq 0x4471(%rip), %rdi      # 0x6ff0
leaq 0x1530(%rip), %rsi      # 0x40b6
callq 0x2100
movq %rax, %rdi
callq 0x2080
movq 0x4456(%rip), %rdi      # 0x6ff0
callq 0x2080
movq %rbp, %rdi
callq 0x2160
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x2c1c
pushq $0x1
popq %rsi
movq %rax, %rdi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x2180
movq %rax, %rbp
movq %r13, %rdi
callq 0x2110
testq %rbp, %rbp
je 0x2c41
movq 0x8(%r12), %rax
leaq 0x1510(%rip), %rsi      # 0x40ee
cmpb $0x4d, (%rax)
jne 0x2c48
cmpb $0x53, 0x1(%rax)
jne 0x2c48
cmpb $0x47, 0x2(%rax)
jne 0x2c48
cmpb $0x4c, 0x3(%rax)
jne 0x2c48
movb $0x1, (%r12)
jmp 0x2c5c
movq 0x43ed(%rip), %rdi      # 0x6ff0
leaq 0x147e(%rip), %rsi      # 0x4088
callq 0x2100
movq %rax, %rdi
movq %r15, %rsi
callq 0x20e0
jmp 0x2c54
movq 0x43cd(%rip), %rdi      # 0x6ff0
leaq 0x14a4(%rip), %rsi      # 0x40ce
callq 0x2100
movq %rax, %rdi
callq 0x2080
movq %r13, %rdi
callq 0x2110
jmp 0x2c5c
leaq 0x1497(%rip), %rsi      # 0x40df
movq 0x43a1(%rip), %rdi      # 0x6ff0
callq 0x2100
movq %rax, %rdi
callq 0x2080
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
leaq 0x8(%rsp), %rdi
jmp 0x2c7d
movq %rax, %r12
leaq 0x28(%rsp), %rdi
callq 0x2060
jmp 0x2c93
movq %rax, %r12
jmp 0x2c9b
movq %rax, %r12
jmp 0x2ca3
jmp 0x2c90
movq %rax, %r12
movq %r15, %rdi
callq 0x2060
movq %r14, %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2060
movq %r12, %rdi
callq 0x2200
nop