// File: FreeSlave[P]vhlt/hlrad/qrad.cpp
// Function: ReadLightFile(char const*)
static void     ReadLightFile(const char* const filename)
{
    FILE*           f;
    char            scan[MAXTOKEN];
    short           argCnt;
    unsigned int    file_texlights = 0;

    f = fopen(filename, "r");
    if (!f)
    {
        Warning("Could not open texlight file %s", filename);
        return;
    }
    else
    {
#ifdef HLRAD_CUSTOMTEXLIGHT
		Log("Reading texlights from '%s'\n", filename);
#else
        Log("[Reading texlights from '%s']\n", filename);
#endif
    }

    while (fgets(scan, sizeof(scan), f))
    {
        char*           comment;
        char            szTexlight[_MAX_PATH];
        vec_t           r, g, b, i = 1;

        comment = strstr(scan, "//");
        if (comment)
        {
            // Newline and Null terminate the string early if there is a c++ style single line comment
            comment[0] = '\n';
            comment[1] = 0;
        }

        argCnt = sscanf(scan, "%s %f %f %f %f", szTexlight, &r, &g, &b, &i);

        if (argCnt == 2)
        {
            // With 1+1 args, the R,G,B values are all equal to the first value
            g = b = r;
        }
        else if (argCnt == 5)
        {
            // With 1+4 args, the R,G,B values are "scaled" by the fourth numeric value i;
            r *= i / 255.0;
            g *= i / 255.0;
            b *= i / 255.0;
        }
        else if (argCnt != 4)
        {
            if (strlen(scan) > 4)
            {
                Warning("ignoring bad texlight '%s' in %s", scan, filename);
            }
            continue;
        }

        texlight_i it;
        for (it = s_texlights.begin(); it != s_texlights.end(); it++)
        {
            if (strcmp(it->name.c_str(), szTexlight) == 0)
            {
                if (strcmp(it->filename, filename) == 0)
                {
                    Warning("Duplication of texlight '%s' in file '%s'!", it->name.c_str(), it->filename);
                }
                else if (it->value[0] != r || it->value[1] != g || it->value[2] != b)
                {
                    Warning("Overriding '%s' from '%s' with '%s'!", it->name.c_str(), it->filename, filename);
                }
                else
                {
                    Warning("Redundant '%s' def in '%s' AND '%s'!", it->name.c_str(), it->filename, filename);
                }
                s_texlights.erase(it);
                break;
            }
        }

        texlight_t      texlight;
        texlight.name = szTexlight;
        texlight.value[0] = r;
        texlight.value[1] = g;
        texlight.value[2] = b;
        texlight.filename = filename;
        file_texlights++;
        s_texlights.push_back(texlight);
    }
	fclose (f); //--vluzacn
#ifndef HLRAD_CUSTOMTEXLIGHT
    Log("[%u texlights parsed from '%s']\n\n", file_texlights, filename);
#endif
}

// Assembly:
subq $0x20d8, %rsp           # imm = 0x20D8
movq %rdi, 0x20d0(%rsp)
movl $0x0, 0x10b8(%rsp)
movq 0x20d0(%rsp), %rdi
leaq 0x1da6f(%rip), %rsi     # 0x6d158
callq 0x4390
movq %rax, 0x20c8(%rsp)
cmpq $0x0, 0x20c8(%rsp)
jne 0x4f71c
movq 0x20d0(%rsp), %rsi
leaq 0x2037e(%rip), %rdi     # 0x6fa8e
movb $0x0, %al
callq 0xb9f0
jmp 0x4fc01
movq 0x20d0(%rsp), %rsi
leaq 0x20383(%rip), %rdi     # 0x6faae
movb $0x0, %al
callq 0xb0d0
jmp 0x4f734
leaq 0x10c0(%rsp), %rdi
movq 0x20c8(%rsp), %rdx
movl $0x1000, %esi           # imm = 0x1000
callq 0x4550
cmpq $0x0, %rax
je 0x4fbf4
movss 0x1a8ec(%rip), %xmm0    # 0x6a04c
movss %xmm0, 0xa0(%rsp)
leaq 0x10c0(%rsp), %rdi
leaq 0x20353(%rip), %rsi     # 0x6facb
callq 0x40c0
movq %rax, 0x10b0(%rsp)
cmpq $0x0, 0x10b0(%rsp)
je 0x4f7a7
movq 0x10b0(%rsp), %rax
movb $0xa, (%rax)
movq 0x10b0(%rsp), %rax
movb $0x0, 0x1(%rax)
leaq 0x10c0(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
leaq 0x20310(%rip), %rsi     # 0x6face
leaq 0xac(%rsp), %rcx
leaq 0xa8(%rsp), %r8
leaq 0xa4(%rsp), %r9
leaq 0xa0(%rsp), %rax
movq %rax, (%rsp)
movb $0x0, %al
callq 0x4300
movw %ax, 0x10be(%rsp)
movswl 0x10be(%rsp), %eax
cmpl $0x2, %eax
jne 0x4f81e
movss 0xac(%rsp), %xmm0
movss %xmm0, 0xa4(%rsp)
movss %xmm0, 0xa8(%rsp)
jmp 0x4f91d
movswl 0x10be(%rsp), %eax
cmpl $0x5, %eax
jne 0x4f8d6
movss 0xa0(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x1f3a4(%rip), %xmm0    # 0x6ebe8
divsd %xmm0, %xmm1
movss 0xac(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xac(%rsp)
movss 0xa0(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x1f36d(%rip), %xmm0    # 0x6ebe8
divsd %xmm0, %xmm1
movss 0xa8(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xa8(%rsp)
movss 0xa0(%rsp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x1f336(%rip), %xmm0    # 0x6ebe8
divsd %xmm0, %xmm1
movss 0xa4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xa4(%rsp)
jmp 0x4f91b
movswl 0x10be(%rsp), %eax
cmpl $0x4, %eax
je 0x4f919
leaq 0x10c0(%rsp), %rdi
callq 0x4170
cmpq $0x4, %rax
jbe 0x4f914
leaq 0x10c0(%rsp), %rsi
movq 0x20d0(%rsp), %rdx
leaq 0x201d0(%rip), %rdi     # 0x6fadd
movb $0x0, %al
callq 0xb9f0
jmp 0x4f734
jmp 0x4f91b
jmp 0x4f91d
leaq 0x98(%rsp), %rdi
callq 0x5b820
leaq 0x552024f(%rip), %rdi   # 0x556fb80
callq 0x5b840
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x98(%rsp)
leaq 0x552022b(%rip), %rdi   # 0x556fb80
callq 0x5b8b0
movq %rax, 0x88(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x5b870
testb $0x1, %al
jne 0x4f980
jmp 0x4fb4b
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq %rax, %rdi
callq 0x4150
movq %rax, %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4480
cmpl $0x0, %eax
jne 0x4fb30
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq 0x30(%rax), %rdi
movq 0x20d0(%rsp), %rsi
callq 0x4480
cmpl $0x0, %eax
jne 0x4fa14
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq %rax, %rdi
callq 0x4150
movq %rax, 0x20(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq 0x20(%rsp), %rsi
movq 0x30(%rax), %rdx
leaq 0x200f6(%rip), %rdi     # 0x6fafe
movb $0x0, %al
callq 0xb9f0
jmp 0x4fb00
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movss 0x20(%rax), %xmm0
ucomiss 0xac(%rsp), %xmm0
jne 0x4fa70
jp 0x4fa70
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movss 0x24(%rax), %xmm0
ucomiss 0xa8(%rsp), %xmm0
jne 0x4fa70
jp 0x4fa70
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movss 0x28(%rax), %xmm0
ucomiss 0xa4(%rsp), %xmm0
jne 0x4fa70
jp 0x4fa70
jmp 0x4fab8
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq %rax, %rdi
callq 0x4150
movq %rax, 0x18(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq 0x18(%rsp), %rsi
movq 0x30(%rax), %rdx
movq 0x20d0(%rsp), %rcx
leaq 0x2007a(%rip), %rdi     # 0x6fb29
movb $0x0, %al
callq 0xb9f0
jmp 0x4fafe
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq %rax, %rdi
callq 0x4150
movq %rax, 0x10(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x5b8e0
movq 0x10(%rsp), %rsi
movq 0x30(%rax), %rdx
movq 0x20d0(%rsp), %rcx
leaq 0x20057(%rip), %rdi     # 0x6fb4e
movb $0x0, %al
callq 0xb9f0
jmp 0x4fb00
leaq 0x80(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x5b960
movq 0x80(%rsp), %rsi
leaq 0x552005c(%rip), %rdi   # 0x556fb80
callq 0x5b8f0
movq %rax, 0x78(%rsp)
jmp 0x4fb4b
jmp 0x4fb32
leaq 0x98(%rsp), %rdi
xorl %esi, %esi
callq 0x5b9a0
movq %rax, 0x70(%rsp)
jmp 0x4f94e
leaq 0x38(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x5b700
movq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4440
jmp 0x4fb6e
movss 0xac(%rsp), %xmm0
movss %xmm0, 0x58(%rsp)
movss 0xa8(%rsp), %xmm0
movss %xmm0, 0x5c(%rsp)
movss 0xa4(%rsp), %xmm0
movss %xmm0, 0x60(%rsp)
movq 0x20d0(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x10b8(%rsp), %eax
incl %eax
movl %eax, 0x10b8(%rsp)
leaq 0x551ffc1(%rip), %rdi   # 0x556fb80
leaq 0x38(%rsp), %rsi
callq 0x5b710
jmp 0x4fbcb
leaq 0x38(%rsp), %rdi
callq 0x5b780
jmp 0x4f734
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x5b780
jmp 0x4fc09
movq 0x20c8(%rsp), %rdi
callq 0x4310
addq $0x20d8, %rsp           # imm = 0x20D8
retq
movq 0x30(%rsp), %rdi
callq 0x45c0
nopw %cs:(%rax,%rax)