// File: FreeSlave[P]vhlt/hlcsg/wadcfg.cpp
// Function: LoadWadconfig(char const*, char const*)
void LoadWadconfig (const char *filename, const char *configname)
{
	Log ("Loading wad configuration '%s' from '%s' :\n", configname, filename);
	int found = 0;
	int count = 0;
	int size;
	char *buffer;
	size = LoadFile (filename, &buffer);
	ParseFromMemory (buffer, size);
	while (GetToken (true))
	{
		bool skip = true;
		if (!strcasecmp (g_token, configname))
		{
			skip = false;
			found++;
		}
		if (!GetToken (true) || strcasecmp (g_token, "{"))
		{
			Error ("parsing '%s': missing '{'.", filename);
		}
		while (1)
		{
			if (!GetToken (true))
			{
				Error ("parsing '%s': unexpected end of file.", filename);
			}
			if (!strcasecmp (g_token, "}"))
			{
				break;
			}
			if (skip)
			{
				continue;
			}
			Log (" ");
			bool include = false;
			if (!strcasecmp (g_token, "include"))
			{
				Log ("include ");
				include = true;
				if (!GetToken (true))
				{
					Error ("parsing '%s': unexpected end of file.", filename);
				}
			}
			Log ("\"%s\"\n", g_token);
			if (g_iNumWadPaths >= MAX_WADPATHS)
			{
				Error ("parsing '%s': too many wad files.", filename);
			}
			count++;
#ifdef HLCSG_AUTOWAD_NEW
			PushWadPath (g_token, !include);
#else
			wadpath_t *current = (wadpath_t *)malloc (sizeof (wadpath_t));
			hlassume (current != NULL, assume_NoMemory);
			g_pWadPaths[g_iNumWadPaths] = current;
			g_iNumWadPaths++;
			safe_strncpy (current->path, g_token, _MAX_PATH);
			current->usedbymap = true; // what's this?
			current->usedtextures = 0;
			if (include)
			{
				Developer (DEVELOPER_LEVEL_MESSAGE, "LoadWadcfgfile: including '%s'.\n", current->path);
				g_WadInclude.push_back(current->path);
			}
#endif
		}
	}
	if (found == 0)
	{
		Error ("Couldn't find wad configuration '%s' in file '%s'.\n", configname, filename);
	}
	if (found >= 2)
	{
		Error ("Found more than one wad configuration for '%s' in file '%s'.\n", configname, filename);
	}
	free (buffer); // should not be freed because it is still being used as script buffer
	//Log ("Using custom wadfile configuration: '%s' (with %i wad%s)\n", configname, count, count > 1 ? "s" : "");
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x6a0f(%rip), %rdi      # 0x3008e
movb $0x0, %al
callq 0xb5d0
movl $0x0, 0x24(%rsp)
movl $0x0, 0x20(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xb180
movl %eax, 0x1c(%rsp)
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0xcc40
movl $0x1, %edi
callq 0xce10
testb $0x1, %al
jne 0x296ca
jmp 0x2983e
movb $0x1, 0xf(%rsp)
movq 0x28(%rsp), %rsi
leaq 0x20a7e25(%rip), %rdi   # 0x20d1500
callq 0x4410
cmpl $0x0, %eax
jne 0x296f5
movb $0x0, 0xf(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
movl $0x1, %edi
callq 0xce10
testb $0x1, %al
jne 0x29705
jmp 0x2971d
leaq 0x20a7df4(%rip), %rdi   # 0x20d1500
leaq 0xddd(%rip), %rsi       # 0x2a4f0
callq 0x4410
cmpl $0x0, %eax
je 0x29730
movq 0x30(%rsp), %rsi
leaq 0x6991(%rip), %rdi      # 0x300ba
movb $0x0, %al
callq 0xba80
jmp 0x29732
movl $0x1, %edi
callq 0xce10
testb $0x1, %al
jne 0x29753
movq 0x30(%rsp), %rsi
leaq 0x6989(%rip), %rdi      # 0x300d5
movb $0x0, %al
callq 0xba80
leaq 0x20a7da6(%rip), %rdi   # 0x20d1500
leaq 0xdf3(%rip), %rsi       # 0x2a554
callq 0x4410
cmpl $0x0, %eax
jne 0x29770
jmp 0x29839
testb $0x1, 0xf(%rsp)
je 0x29779
jmp 0x29732
leaq 0xedb(%rip), %rdi       # 0x2a65b
movb $0x0, %al
callq 0xb5d0
movb $0x0, 0xe(%rsp)
leaq 0x20a7d6d(%rip), %rdi   # 0x20d1500
leaq 0x39c3(%rip), %rsi      # 0x2d15d
callq 0x4410
cmpl $0x0, %eax
jne 0x297da
leaq 0x6950(%rip), %rdi      # 0x300fb
movb $0x0, %al
callq 0xb5d0
movb $0x1, 0xe(%rsp)
movl $0x1, %edi
callq 0xce10
testb $0x1, %al
jne 0x297d8
movq 0x30(%rsp), %rsi
leaq 0x6904(%rip), %rdi      # 0x300d5
movb $0x0, %al
callq 0xba80
jmp 0x297da
leaq 0xf07(%rip), %rdi       # 0x2a6e8
leaq 0x20a7d18(%rip), %rsi   # 0x20d1500
movb $0x0, %al
callq 0xb5d0
leaq 0x63d6c1a(%rip), %rax   # 0x6400410
cmpl $0x80, (%rax)
jl 0x29811
movq 0x30(%rsp), %rsi
leaq 0x68fa(%rip), %rdi      # 0x30104
movb $0x0, %al
callq 0xba80
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
movb 0xe(%rsp), %al
xorb $-0x1, %al
movzbl %al, %esi
andl $0x1, %esi
leaq 0x20a7cd1(%rip), %rdi   # 0x20d1500
callq 0x299c0
jmp 0x29732
jmp 0x296b7
cmpl $0x0, 0x24(%rsp)
jne 0x2985d
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x68d0(%rip), %rdi      # 0x30126
movb $0x0, %al
callq 0xba80
cmpl $0x2, 0x24(%rsp)
jl 0x2987c
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
leaq 0x68e5(%rip), %rdi      # 0x3015a
movb $0x0, %al
callq 0xba80
movq 0x10(%rsp), %rdi
callq 0x4470
addq $0x38, %rsp
retq
nopl (%rax,%rax)