// File: bluesky466[P]ResourcesParser/ResourcesParser.cpp
// Function: ResourcesParser::parserPackageResource(std::basic_ifstream<char, std::char_traits<char>>&)
ResourcesParser::PackageResourcePtr ResourcesParser::parserPackageResource(
		ifstream& resources) {
	PackageResourcePtr pPool = make_shared<PackageResource>();
	resources.read((char*)&pPool->header, sizeof(ResTable_package));

	if(pPool->header.header.type != RES_TABLE_PACKAGE_TYPE) {
		cout<<"parserPackageResource 需要定位到 RES_TABLE_PACKAGE_TYPE !"<<endl;
		return nullptr;
	}

	// 接着是资源类型字符串池
	pPool->pTypes = parserResStringPool(resources);

	// 接着是资源名称字符串池
	pPool->pKeys = parserResStringPool(resources);

	ResChunk_header chunkHeader;
	while(resources.read((char*)&chunkHeader, sizeof(ResChunk_header))) {
		resources.seekg(-sizeof(ResChunk_header), ios::cur);

		if(chunkHeader.type == RES_TABLE_PACKAGE_TYPE) {
			return pPool;
		} else if(chunkHeader.type == RES_TABLE_TYPE_TYPE) {
			ResTableTypePtr pResTableType = make_shared<ResTableType>();
			resources.read((char*)&pResTableType->header, sizeof(ResTable_type));
			uint32_t seek = pResTableType->header.header.headerSize - sizeof(ResTable_type);
			resources.seekg(seek, ios::cur);
			pResTableType->entryPool = parserEntryPool(
					resources,
					pResTableType->header.entryCount,
					pResTableType->header.entriesStart - pResTableType->header.header.headerSize,
					pResTableType->header.header.size - pResTableType->header.entriesStart);
			pPool->resTablePtrs[pResTableType->header.id].push_back(pResTableType);
			for(int i = 0 ; i < pResTableType->header.entryCount ; i++) {
				ResTable_entry* pEntry = getEntryFromEntryPool(pResTableType->entryPool, i);
				if(nullptr == pEntry) {
					pResTableType->entries.push_back(nullptr);
					pResTableType->values.push_back(nullptr);
					continue;
				}
				Res_value* pValue = getValueFromEntry(pEntry);
				pResTableType->entries.push_back(pEntry);
				pResTableType->values.push_back(pValue);
			}
		} else {
			resources.seekg(chunkHeader.size, ios::cur);
		}
	}

	return pPool;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x118(%rbp)
movq %rdi, %rax
movq %rax, -0x110(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x28(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0xbe80
movq -0x100(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
callq 0x6550
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
movl $0x120, %edx            # imm = 0x120
callq 0x32f0
jmp 0xa3e0
leaq -0x28(%rbp), %rdi
callq 0x6550
movzwl (%rax), %eax
cmpl $0x200, %eax            # imm = 0x200
je 0xa451
movq 0x1cbce(%rip), %rdi     # 0x26fc8
leaq 0xfe70(%rip), %rsi      # 0x1a271
callq 0x3260
movq %rax, -0x120(%rbp)
jmp 0xa40f
movq -0x120(%rbp), %rdi
movq 0x1cb8b(%rip), %rsi     # 0x26fa8
callq 0x3290
jmp 0xa424
movq -0x118(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xbef0
movl $0x1, -0x38(%rbp)
jmp 0xa8ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xa908
movq -0x108(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x48(%rbp), %rdi
callq 0x9ff0
jmp 0xa467
leaq -0x28(%rbp), %rdi
callq 0x6550
movq %rax, %rdi
addq $0x120, %rdi            # imm = 0x120
leaq -0x48(%rbp), %rsi
movq %rsi, -0x128(%rbp)
callq 0xb8d0
movq -0x128(%rbp), %rdi
callq 0x43a0
movq -0x108(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x9ff0
jmp 0xa4ac
leaq -0x28(%rbp), %rdi
callq 0x6550
movq %rax, %rdi
addq $0x130, %rdi            # imm = 0x130
leaq -0x58(%rbp), %rsi
callq 0xb8d0
leaq -0x58(%rbp), %rdi
callq 0x43a0
movq -0x18(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movl $0x8, %edx
callq 0x32f0
movq %rax, -0x130(%rbp)
jmp 0xa4ec
movq -0x130(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32e0
movb %al, -0x131(%rbp)
jmp 0xa50a
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0xa519
jmp 0xa8d8
movq -0x18(%rbp), %rdi
movq $-0x8, %rsi
movl $0x1, %edx
callq 0x3350
jmp 0xa530
movzwl -0x60(%rbp), %eax
cmpl $0x200, %eax            # imm = 0x200
jne 0xa557
movq -0x118(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xbf10
movl $0x1, -0x38(%rbp)
jmp 0xa8ef
movzwl -0x60(%rbp), %eax
cmpl $0x201, %eax            # imm = 0x201
jne 0xa8ba
leaq -0x70(%rbp), %rdi
callq 0xbf40
jmp 0xa571
movq -0x18(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x6880
movq -0x140(%rbp), %rdi
movq %rax, %rsi
movl $0x38, %edx
callq 0x32f0
jmp 0xa59b
leaq -0x70(%rbp), %rdi
callq 0x6880
movzwl 0x2(%rax), %eax
addl $-0x38, %eax
movl %eax, -0x74(%rbp)
movq -0x18(%rbp), %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x3350
jmp 0xa5c3
movq -0x18(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x6880
movq -0x160(%rbp), %rdi
movl 0xc(%rax), %eax
movl %eax, -0x148(%rbp)
callq 0x6880
movq -0x160(%rbp), %rdi
movl 0x10(%rax), %eax
movl %eax, -0x164(%rbp)
callq 0x6880
movq -0x160(%rbp), %rdi
movq %rax, %rcx
movl -0x164(%rbp), %eax
movzwl 0x2(%rcx), %ecx
subl %ecx, %eax
movl %eax, -0x144(%rbp)
callq 0x6880
movq -0x160(%rbp), %rdi
movl 0x4(%rax), %eax
movl %eax, -0x154(%rbp)
callq 0x6880
movl -0x154(%rbp), %r9d
movq -0x108(%rbp), %rsi
movq -0x150(%rbp), %rdx
movl -0x148(%rbp), %ecx
movl -0x144(%rbp), %r8d
movl 0x10(%rax), %eax
subl %eax, %r9d
leaq -0xa0(%rbp), %rdi
callq 0xabe0
jmp 0xa674
leaq -0x70(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x6880
movq %rax, %rdi
addq $0x38, %rdi
leaq -0xa0(%rbp), %rsi
movq %rsi, -0x188(%rbp)
callq 0xbfb0
movq -0x188(%rbp), %rdi
callq 0xc000
leaq -0x28(%rbp), %rdi
callq 0x6550
movq -0x180(%rbp), %rdi
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x178(%rbp)
callq 0x6880
movq -0x178(%rbp), %rdi
movzbl 0x8(%rax), %eax
movl %eax, -0xa4(%rbp)
leaq -0xa4(%rbp), %rsi
callq 0x66b0
movq %rax, -0x170(%rbp)
jmp 0xa6f2
movq -0x170(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0xc030
jmp 0xa704
movl $0x0, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x18c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x6880
movq %rax, %rcx
movl -0x18c(%rbp), %eax
cmpl 0xc(%rcx), %eax
jae 0xa8a4
leaq -0x70(%rbp), %rdi
callq 0x6880
movq %rax, %rsi
addq $0x38, %rsi
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0xc0a0
movq -0x108(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
movl -0xa8(%rbp), %edx
callq 0xad80
movq %rax, -0x198(%rbp)
jmp 0xa77a
leaq -0xd8(%rbp), %rdi
callq 0xc000
movq -0x198(%rbp), %rax
movq %rax, -0xb0(%rbp)
xorl %eax, %eax
cmpq -0xb0(%rbp), %rax
jne 0xa828
leaq -0x70(%rbp), %rdi
callq 0x6880
movq %rax, %rdi
addq $0x60, %rdi
movq $0x0, -0xe0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0xc0f0
jmp 0xa7cc
leaq -0x70(%rbp), %rdi
callq 0x6880
movq %rax, %rdi
addq $0x78, %rdi
movq $0x0, -0xe8(%rbp)
leaq -0xe8(%rbp), %rsi
callq 0xc120
jmp 0xa7f5
jmp 0xa890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0xa8af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xc000
jmp 0xa8af
movq -0x108(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0xadf0
movq %rax, -0x1a8(%rbp)
jmp 0xa844
movq -0x1a8(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x6880
movq %rax, %rdi
addq $0x60, %rdi
leaq -0xb0(%rbp), %rsi
callq 0xc150
jmp 0xa870
leaq -0x70(%rbp), %rdi
callq 0x6880
movq %rax, %rdi
addq $0x78, %rdi
leaq -0xf0(%rbp), %rsi
callq 0xc1c0
jmp 0xa88e
jmp 0xa890
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0xa70e
leaq -0x70(%rbp), %rdi
callq 0x6a60
jmp 0xa8d1
leaq -0x70(%rbp), %rdi
callq 0x6a60
jmp 0xa908
movq -0x18(%rbp), %rdi
movl -0x5c(%rbp), %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x3350
jmp 0xa8cf
jmp 0xa8d1
jmp 0xa8d3
jmp 0xa4d1
movq -0x118(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xbf10
movl $0x1, -0x38(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4820
movq -0x110(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x4820
movq -0x30(%rbp), %rdi
callq 0x3450
nopw (%rax,%rax)