// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/p_client.c
// Function: ClientBeginDeathmatch
void ClientBeginDeathmatch (edict_t *ent)
{
	if (!ent->client)
		return;

#ifdef OLDOBSERVERCODE
	int 		observe = 0; // MJD Uninit'd - No bug, though. Fixed
#endif
	int 		oldteam;
	char		message[MAX_INFO_STRING];
	char		userinfo[MAX_INFO_STRING];

	long i; //loop

	
	//sprintf(DBuffer, "bg t %d p %d r %d", ent->client->ctf.teamnum,
	//	ent->client->pers.spectator, ent->client->resp.spectator);
	//Debug_Show(DBuffer);


	//try to fix unknown pics, associated with skins?
	//this is messing up the spectator stuff
	memcpy(userinfo, ent->client->pers.userinfo, sizeof(userinfo));
	ClientUserinfoChanged(ent, userinfo);

	for (i = PRINT_LOW; i <= PRINT_CHAT; i++)
	{
		ent->client->ctf.printdata[i][0] = 0; //clear this out on connect
	}

	//if(ent->client->ctf.teamnum <= CTF_TEAM_OBSERVER)
	//{
	//	ent->client->pers.spectator = 1;
	//	ent->client->resp.spectator = 1;
	//}
	//else
	//{
	//	ent->client->pers.spectator = 0;
	//	ent->client->resp.spectator = 0;
	//}


	G_InitEdict (ent);

	if (ent->client->p_stats_player->dropped)
	{
		ent->client->resp.score = stats_get(ent, STATS_SCORE);
		ent->client->ctf.teamnum = ent->client->p_stats_player->info.teamnum;
		ent->client->p_stats_player->dropped = false;
	}
	else
	{
		stats_clear(ent);
	}

	InitClientResp (ent->client);

	// TEAM CODE -- LM_JORM //
	sl_WriteStdLogPlayerEntered( &gi, level, ent );	// StdLog - Mark Davies
	
	// OFFHAND HOOK aliases
//	ForceCommand(ent, "alias \"+hook\" \"cmd hook\"\n");
//	ForceCommand(ent, "alias \"-hook\" \"cmd unhook\"\n");
	ForceCommand(ent, "alias +hook cmd hook\n");
	ForceCommand(ent, "alias -hook cmd unhook\n");
	
	oldteam = ent->client->ctf.teamnum;

#ifdef OLDOBSERVERCODE	
	observe = 0;
	if (Match_InPlay()) 	// If Match In Play, enter all new players as observers
	{
		if (oldteam <= CTF_TEAM_UNDEFINED || 
			oldteam >= CTF_TEAM_LIMIT)  // We aren't remembered, so not part of the match
			observe = 1;
	}
#endif
	

	//If they are observers, then let them stay that way!
	//-bat
	if(oldteam == CTF_TEAM_UNDEFINED)
		TeamJoin(ent);						// Join random team
	else if (oldteam < CTF_TEAM_UNDEFINED)
		Cmd_Observe_f(ent, oldteam);
	else // Team already defined
		ctf_SetEntTeamEx(ent, oldteam, 1);			// Join old team, no penalty

	//if (oldteam == CTF_TEAM_UNDEFINED)
	//	TeamJoin(ent);						// Join random team
	//else // Team already defined
	//	ctf_SetEntTeamEx(ent, oldteam, 1);			// Join old team, no penalty

	//sprintf(DBuffer, "ed1 t %d p %d r %d", ent->client->ctf.teamnum,
	//	ent->client->pers.spectator, ent->client->resp.spectator);
	//Debug_Show(DBuffer);



	// END LM_JORM
	
	// locate ent at a spawn point
	PutClientInServer (ent);

	//sprintf(DBuffer, "ed2 t %d p %d r %d", ent->client->ctf.teamnum,
	//	ent->client->pers.spectator, ent->client->resp.spectator);
	//Debug_Show(DBuffer);


	// CTF CODE -- LM_JORM
#ifdef OLDOBSERVERCODE
	if (observe && deathmatch->value) //surt attempt to get single player working
	{
		Observer_Start (ent);
	}
#endif


	// If we are starting a match, don't let us touch anything
	if (Match_InCountdown())
	{
		//ent->solid = SOLID_NOT;
		//ent->movetype = MOVETYPE_NOCLIP;
		ctf_BSafePrint(PRINT_HIGH, "Match about to begin.\n");
	}
	
	// END LM_JORM
	
	if (level.intermissiontime)
	{
		MoveClientToIntermission (ent);
	}
	else
	{
		// send effect
		gi.WriteByte (svc_muzzleflash);
		gi.WriteShort (ent-g_edicts);
		gi.WriteByte (MZ_LOGIN);
		gi.multicast (ent->s.origin, MULTICAST_PVS);
		MvpDisp = 0;
	}
	
	Com_sprintf(message, sizeof message, "%s entered the game\n", ent->client->pers.netname);
	ctf_BSafePrint(PRINT_HIGH, message);


	//if(ent->client->ctf.teamnum <= CTF_TEAM_OBSERVER)
	//{
	//	ent->client->pers.spectator = 1;
	//	ent->client->resp.spectator = 1;
	//}
	//else
	//{
	//	ent->client->pers.spectator = 0;
	//	ent->client->resp.spectator = 0;
	//}


	// make sure all view stuff is valid
	
	//ent->client->showmod = true; // LM_JORM -- Turn on CTF HUD
	if (oldteam <= CTF_TEAM_UNDEFINED || oldteam >= CTF_TEAM_LIMIT)
		ent->client->showmod = true; // LM_JORM -- Turn on CTF HUD, MOTD
	ClientEndServerFrame (ent);

	//sprintf(DBuffer, "zz t %d p %d r %d", ent->client->ctf.teamnum,
	//	ent->client->pers.spectator, ent->client->resp.spectator);
	//Debug_Show(DBuffer);


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x580, %rsp            # imm = 0x580
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x58(%rax)
jne 0x5af6f
jmp 0x5b252
leaq -0x410(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rsi
addq $0xc0, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x18dc0
movq -0x8(%rbp), %rdi
leaq -0x410(%rbp), %rsi
callq 0x19d18
movq $0x0, -0x418(%rbp)
cmpq $0x3, -0x418(%rbp)
jg 0x5afeb
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
addq $0x1100, %rax           # imm = 0x1100
addq $0x1c, %rax
movq -0x418(%rbp), %rcx
shlq $0xd, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movq -0x418(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x418(%rbp)
jmp 0x5afaa
movq -0x8(%rbp), %rdi
callq 0x18f50
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x9138(%rax), %rax
cmpl $0x0, (%rax)
je 0x5b060
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x18030
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0xdf4(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x9138(%rax), %rax
movl 0x204(%rax), %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x1100(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq 0x9138(%rax), %rax
movl $0x0, (%rax)
jmp 0x5b069
movq -0x8(%rbp), %rdi
callq 0x19460
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x18ee0
movq -0x8(%rbp), %rax
movq %rax, -0x420(%rbp)
movq 0x27d18(%rip), %rsi     # 0x82da0
movq %rsp, %rdi
movl $0x2b, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq -0x420(%rbp), %rsi
movq 0x2755f(%rip), %rdi     # 0x82600
callq 0x19050
movq -0x8(%rbp), %rdi
leaq 0x1c099(%rip), %rsi     # 0x7714a
callq 0x18d80
movq -0x8(%rbp), %rdi
leaq 0x1c09f(%rip), %rsi     # 0x77160
callq 0x18d80
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl 0x1100(%rax), %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x5b0e8
movq -0x8(%rbp), %rdi
callq 0x19af0
jmp 0x5b10f
cmpl $0x0, -0xc(%rbp)
jge 0x5b0fc
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x198e0
jmp 0x5b10d
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x1, %edx
callq 0x19350
jmp 0x5b10f
movq -0x8(%rbp), %rdi
callq 0x18af0
movb $0x0, %al
callq 0x19590
cmpl $0x0, %eax
je 0x5b135
movl $0x2, %edi
leaq 0x1c048(%rip), %rsi     # 0x77178
callq 0x19470
movq 0x27c64(%rip), %rax     # 0x82da0
movss 0xc8(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x5b150
jp 0x5b150
jmp 0x5b15e
movq -0x8(%rbp), %rdi
callq 0x192b0
jmp 0x5b1ea
movl $0x1, %edi
movq 0x27496(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movq 0x27489(%rip), %rax     # 0x82600
movq 0xd0(%rax), %rax
movq %rax, -0x428(%rbp)
movq -0x8(%rbp), %rax
movq 0x273c8(%rip), %rcx     # 0x82558
movq (%rcx), %rcx
subq %rcx, %rax
movl $0x4a8, %ecx            # imm = 0x4A8
cqto
idivq %rcx
movq %rax, %rcx
movq -0x428(%rbp), %rax
movl %ecx, %edi
callq *%rax
movl $0x9, %edi
movq 0x27446(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movq 0x27439(%rip), %rax     # 0x82600
movq 0xb0(%rax), %rax
movq -0x8(%rbp), %rdi
addq $0x4, %rdi
movl $0x2, %esi
callq *%rax
movq 0x275c4(%rip), %rax     # 0x827a8
movl $0x0, (%rax)
leaq -0x210(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rcx
addq $0xc0, %rcx
addq $0x200, %rcx            # imm = 0x200
movl $0x200, %esi            # imm = 0x200
leaq 0x1bf7c(%rip), %rdx     # 0x7718f
movb $0x0, %al
callq 0x18f90
leaq -0x210(%rbp), %rsi
movl $0x2, %edi
callq 0x19470
cmpl $0x0, -0xc(%rbp)
jle 0x5b237
cmpl $0x3, -0xc(%rbp)
jl 0x5b249
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x1, 0xf74(%rax)
movq -0x8(%rbp), %rdi
callq 0x18bd0
addq $0x580, %rsp            # imm = 0x580
popq %rbp
retq
nopl (%rax,%rax)