// File: FreeSlave[P]vhlt/hlcsg/qcsg.cpp
// Function: CheckForNoClip()
static void     CheckForNoClip()
{
    int             i;
    entity_t*       ent;

    char            entclassname[MAX_KEY]; 
    int             spawnflags;
#ifdef HLCSG_CUSTOMHULL
	int				count = 0;
#endif

    if (!g_bClipNazi) 
        return; // NO CLIP FOR YOU!!!

    for (i = 0; i < g_numentities; i++)
    {
        if (!g_entities[i].numbrushes) 
            continue; // not a model

        if (!i) 
            continue; // dont waste our time with worldspawn

        ent = &g_entities[i];

        strcpy_s(entclassname, ValueForKey(ent, "classname"));
        spawnflags = atoi(ValueForKey(ent, "spawnflags"));
		int skin = IntForKey(ent, "skin"); //vluzacn

#ifndef HLCSG_CUSTOMHULL
		// condition 0, it's marked noclip (KGP)
		if(strlen(ValueForKey(ent,"zhlt_noclip")) && strcmp(ValueForKey(ent,"zhlt_noclip"),"0"))
		{ 
			MarkEntForNoclip(ent);
		}
        // condition 1 //modified. --vluzacn
        else
#endif
		if ((skin != -16) &&
			(
				!strcmp(entclassname, "env_bubbles")
				|| !strcmp(entclassname, "func_illusionary")
				|| (spawnflags & 8) && 
				(   /* NOTE: func_doors as far as i can tell may need clipnodes for their
							player collision detection, so for now, they stay out of it. */
					!strcmp(entclassname, "func_train")
					|| !strcmp(entclassname, "func_door")
					|| !strcmp(entclassname, "func_water")
					|| !strcmp(entclassname, "func_door_rotating")
					|| !strcmp(entclassname, "func_pendulum")
					|| !strcmp(entclassname, "func_train")
					|| !strcmp(entclassname, "func_tracktrain")
					|| !strcmp(entclassname, "func_vehicle")
				)
				|| (skin != 0) && (!strcmp(entclassname, "func_door") || !strcmp(entclassname, "func_water"))
				|| (spawnflags & 2) && (!strcmp(entclassname, "func_conveyor"))
				|| (spawnflags & 1) && (!strcmp(entclassname, "func_rot_button"))
				|| (spawnflags & 64) && (!strcmp(entclassname, "func_rotating"))
			))
		{
			MarkEntForNoclip(ent);
#ifdef HLCSG_CUSTOMHULL
			count++;
#endif
		}
        /*
        // condition 6: its a func_wall, while we noclip it, we remake the clipnodes manually 
        else if (!strncasecmp(entclassname, "func_wall", 9)) 
        {
            for (int j = ent->firstbrush; j < ent->firstbrush + ent->numbrushes; j++)
                CopyGenerictoCLIP(&g_mapbrushes[i]);

            MarkEntForNoclip(ent);
        }
*/
    }

#ifdef HLCSG_CUSTOMHULL
    Log("%i entities discarded from clipping hulls\n", count);
#else
    Log("%i brushes (totalling %i sides) discarded from clipping hulls\n", BrushClipHullsDiscarded, ClipNodesDiscarded);
#endif
}

// Assembly:
subq $0xb8, %rsp
movl $0x0, 0x18(%rsp)
testb $0x1, 0x61b85ba(%rip)   # 0x61db6f0
jne 0x2313d
jmp 0x23409
movl $0x0, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
leaq 0x200a34e(%rip), %rcx   # 0x202d4a4
cmpl (%rcx), %eax
jge 0x233f7
movslq 0xb4(%rsp), %rcx
leaq 0x200a343(%rip), %rax   # 0x202d4b0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x1c(%rax)
jne 0x2317f
jmp 0x233e1
cmpl $0x0, 0xb4(%rsp)
jne 0x2318e
jmp 0x233e1
movslq 0xb4(%rsp), %rcx
leaq 0x200a313(%rip), %rax   # 0x202d4b0
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0xa8(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x7391(%rip), %rsi      # 0x2a556
callq 0x7ff0
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x4380
movq 0xa8(%rsp), %rdi
leaq 0xc8ca(%rip), %rsi      # 0x2fab0
callq 0x7ff0
movq %rax, %rdi
callq 0x45d0
movl %eax, 0x1c(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0xc8b5(%rip), %rsi      # 0x2fabb
callq 0x8210
movl %eax, 0x14(%rsp)
cmpl $-0x10, 0x14(%rsp)
je 0x233df
leaq 0x20(%rsp), %rdi
leaq 0xc89a(%rip), %rsi      # 0x2fac0
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc88c(%rip), %rsi      # 0x2facc
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
movl 0x1c(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x2332e
leaq 0x20(%rsp), %rdi
leaq 0xc873(%rip), %rsi      # 0x2fadd
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc864(%rip), %rsi      # 0x2fae8
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc854(%rip), %rsi      # 0x2faf2
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc845(%rip), %rsi      # 0x2fafd
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc83e(%rip), %rsi      # 0x2fb10
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc7f1(%rip), %rsi      # 0x2fadd
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc818(%rip), %rsi      # 0x2fb1e
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc80e(%rip), %rsi      # 0x2fb2e
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
cmpl $0x0, 0x14(%rsp)
je 0x23361
leaq 0x20(%rsp), %rdi
leaq 0xc7a7(%rip), %rsi      # 0x2fae8
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
leaq 0x20(%rsp), %rdi
leaq 0xc79b(%rip), %rsi      # 0x2faf2
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
movl 0x1c(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x23383
leaq 0x20(%rsp), %rdi
leaq 0xc7c2(%rip), %rsi      # 0x2fb3b
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
movl 0x1c(%rsp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x233a5
leaq 0x20(%rsp), %rdi
leaq 0xc7ae(%rip), %rsi      # 0x2fb49
callq 0x4530
cmpl $0x0, %eax
je 0x233c7
movl 0x1c(%rsp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x233df
leaq 0x20(%rsp), %rdi
leaq 0xc79c(%rip), %rsi      # 0x2fb59
callq 0x4530
cmpl $0x0, %eax
jne 0x233df
movq 0xa8(%rsp), %rdi
callq 0x23d40
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x233e1
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x23148
movl 0x18(%rsp), %esi
leaq 0xc765(%rip), %rdi      # 0x2fb67
movb $0x0, %al
callq 0xb5d0
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)