// File: /workspace/github_c_makefile_star2_O2/Joy-Division[P]tools-mgs/txp-convert.c
// Function: getTxpHeader
txpHeader *getTxpHeader(unsigned char *data, unsigned int game) {
	txpHeaderPO *pohead = NULL;
	txpHeaderPW *pwhead = NULL;
	txpHeader *rethead = malloc(sizeof(txpHeader));
	
	printf("Raw header values:\n");
	
	switch(game) {
		case mgspo: {
			pohead = (txpHeaderPO *)data;
			
			printf("unknown1 - unknown2 - numTexts - texloffs - numFrame - framloff - unknown3 - unknown4\n");
			printf("%08x - %08x - %08x - %08x - %08x - %08x - %08x - %08x\n",
				pohead->unknown1, pohead->unknown2, pohead->numTextures, pohead->texlistOffset,
				pohead->numFrames, pohead->framelistOffset, pohead->unknown3, pohead->unknown4);
			
			rethead->namehash = 0;
			
			rethead->numtextures = pohead->numTextures;
			rethead->texturelist = pohead->texlistOffset;
			
			rethead->numframes = pohead->numFrames;
			rethead->framelist = pohead->framelistOffset;
			break;
		}
		case mgspw: {
			pwhead = (txpHeaderPW *)data;
			
			printf("unknown1 - namehash - numTexts - numFrame - unknown2 - texloffs - framloff - unknown3\n");
			printf("%08x - %08x - %08x - %08x - %08x - %08x - %08x - %08x\n",
				pwhead->unknown1, pwhead->namehash, pwhead->numTextures, pwhead->numFrames,
				pwhead->unknown2, pwhead->texlistOffset, pwhead->framelistOffset, pwhead->unknown3);
			
			rethead->namehash = pwhead->namehash;
			
			rethead->numtextures = pwhead->numTextures;
			rethead->texturelist = pwhead->texlistOffset;
			
			rethead->numframes = pwhead->numFrames;
			rethead->framelist = pwhead->framelistOffset;
			break;
		}
		default: {
			printf("i am asplod\n");
			break;
		}
	}
	
	printf("Processed header values:\nnamehash %08x - numtex %d - texoff %08x - numframe %d - frameoff %08x\n",
		rethead->namehash, rethead->numtextures, rethead->texturelist, rethead->numframes, rethead->framelist);
	
	return rethead;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %r14
pushq $0x14
popq %rdi
callq 0x10f0
movq %rax, %rbx
leaq 0x2efe(%rip), %rdi      # 0xcd37
callq 0x1050
cmpl $0x1, %ebp
jne 0x9ea3
leaq 0x2f00(%rip), %rdi      # 0xcd4a
callq 0x1050
movl (%r14), %esi
movl 0x4(%r14), %edx
leaq 0x8(%r14), %rax
movq %rax, (%rsp)
movl 0x8(%r14), %ecx
leaq 0xc(%r14), %r12
movl 0xc(%r14), %r8d
movl 0x10(%r14), %r9d
leaq 0x14(%r14), %r13
movl 0x14(%r14), %r10d
leaq 0x18(%r14), %r15
movl 0x18(%r14), %r11d
movl 0x1c(%r14), %ebp
subq $0x8, %rsp
leaq 0x2b53(%rip), %rdi      # 0xc9e0
xorl %eax, %eax
pushq %rbp
pushq %r11
pushq %r10
callq 0x10a0
addq $0x20, %rsp
movl 0x4(%r14), %ebp
jmp 0x9f08
testl %ebp, %ebp
jne 0x9f4b
leaq 0x2eee(%rip), %rdi      # 0xcda0
callq 0x1050
movl (%r14), %esi
movl 0x4(%r14), %edx
leaq 0x8(%r14), %rax
movq %rax, (%rsp)
movl 0x8(%r14), %ecx
leaq 0xc(%r14), %r13
movl 0xc(%r14), %r8d
leaq 0x10(%r14), %r12
movl 0x10(%r14), %r9d
leaq 0x14(%r14), %r15
movl 0x14(%r14), %r10d
movl 0x18(%r14), %r11d
movl 0x1c(%r14), %r14d
subq $0x8, %rsp
leaq 0x2aeb(%rip), %rdi      # 0xc9e0
xorl %ebp, %ebp
xorl %eax, %eax
pushq %r14
pushq %r11
pushq %r10
callq 0x10a0
addq $0x20, %rsp
movl %ebp, (%rbx)
movq (%rsp), %rax
movl (%rax), %edx
movl %edx, 0x4(%rbx)
movl (%r13), %ecx
movl %ecx, 0x8(%rbx)
movl (%r12), %r8d
movl %r8d, 0xc(%rbx)
movl (%r15), %r9d
movl %r9d, 0x10(%rbx)
leaq 0x2ae7(%rip), %rdi      # 0xca17
movl %ebp, %esi
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2ea4(%rip), %rdi      # 0xcdf6
callq 0x1050