// File: FreeSlave[P]vhlt/ripent/ripent.cpp
// Function: ReadEntities(char const*)
static void     ReadEntities(const char* const name)
{
    char filename[_MAX_PATH];

#ifdef ZHLT_DEFAULTEXTENSION_FIX
	safe_snprintf(filename, _MAX_PATH, "%s.ent", name);
#else
    safe_strncpy(filename, name, _MAX_PATH);
    StripExtension(filename);
    DefaultExtension(filename, ".ent");
#endif

    {
        FILE *f = SafeOpenRead(filename);
		Log("\nReading %s.\n", filename);  // Added by Nem.

        g_entdatasize = q_filelength(f);

		assume(g_entdatasize != 0, "No entity data.");
        assume(g_entdatasize < sizeof(g_dentdata), "Entity data size exceedes dentdata limit.");

        SafeRead(f, g_dentdata, g_entdatasize);

        fclose(f);

        if (g_dentdata[g_entdatasize-1] != 0)
        {
//            Log("g_dentdata[g_entdatasize-1] = %d\n", g_dentdata[g_entdatasize-1]);

			if(g_parse)  // Added by Nem.
			{
				ParseEntityData("", 0, "\n", 1, "\0", 1);
			}
			else
			{
				if(g_dentdata[g_entdatasize - 1] != '\0')
				{
					g_dentdata[g_entdatasize] = '\0';
					g_entdatasize++;
				}
			}
        }
    }
}

// Assembly:
subq $0x1018, %rsp           # imm = 0x1018
movq %rdi, 0x1010(%rsp)
leaq 0x10(%rsp), %rdi
movq 0x1010(%rsp), %rcx
movl $0x1000, %esi           # imm = 0x1000
leaq 0x66c1(%rip), %rdx      # 0x18db9
movb $0x0, %al
callq 0x8350
leaq 0x10(%rsp), %rdi
callq 0x99f0
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rsi
leaq 0x66a6(%rip), %rdi      # 0x18dc0
movb $0x0, %al
callq 0x9f40
movq 0x8(%rsp), %rdi
callq 0x98e0
movl %eax, %ecx
leaq 0x813c00(%rip), %rax    # 0x826334
movl %ecx, (%rax)
leaq 0x813bf7(%rip), %rax    # 0x826334
cmpl $0x0, (%rax)
jne 0x1276a
leaq 0x5f2c(%rip), %rdi      # 0x18675
leaq 0x667e(%rip), %rsi      # 0x18dce
leaq 0x5f52(%rip), %rdx      # 0x186a9
movl $0x33a, %ecx            # imm = 0x33A
leaq 0x5f58(%rip), %r8       # 0x186bb
movb $0x0, %al
callq 0xa3f0
leaq 0x813bc3(%rip), %rax    # 0x826334
movslq (%rax), %rax
cmpq $0x200000, %rax         # imm = 0x200000
jb 0x127a4
leaq 0x5ef2(%rip), %rdi      # 0x18675
leaq 0x6657(%rip), %rsi      # 0x18de1
leaq 0x5f18(%rip), %rdx      # 0x186a9
movl $0x33b, %ecx            # imm = 0x33B
leaq 0x5f4e(%rip), %r8       # 0x186eb
movb $0x0, %al
callq 0xa3f0
movq 0x8(%rsp), %rdi
leaq 0x813b84(%rip), %rax    # 0x826334
movl (%rax), %edx
leaq 0x813b87(%rip), %rsi    # 0x826340
callq 0x9a50
movq 0x8(%rsp), %rdi
callq 0x3290
leaq 0x813b65(%rip), %rax    # 0x826334
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x813b62(%rip), %rax    # 0x826340
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x12864
testb $0x1, 0x208efb3(%rip)   # 0x20a17a1
je 0x12817
leaq 0x4532(%rip), %rdi      # 0x16d29
xorl %esi, %esi
leaq 0x4528(%rip), %rdx      # 0x16d28
movl $0x1, %r9d
leaq 0x6665(%rip), %r8       # 0x18e72
movl %r9d, %ecx
callq 0x10ca0
jmp 0x12862
leaq 0x813b16(%rip), %rax    # 0x826334
movl (%rax), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x813b13(%rip), %rax    # 0x826340
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x12860
leaq 0x813af7(%rip), %rax    # 0x826334
movslq (%rax), %rcx
leaq 0x813af9(%rip), %rax    # 0x826340
movb $0x0, (%rax,%rcx)
leaq 0x813ae2(%rip), %rax    # 0x826334
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x813ad6(%rip), %rax    # 0x826334
movl %ecx, (%rax)
jmp 0x12862
jmp 0x12864
addq $0x1018, %rsp           # imm = 0x1018
retq
nopl (%rax)