// File: lotuskip[P]yuxtapa/client/input.cpp
// Function: Input::inputhandle()
bool Input::inputhandle()
{
	if(clientstate == CS_TYPE_CHAT || clientstate == CS_TYPE_SHOUT)
	{
		if(check_typing()) // returns true if done typing
		{
			clientstate = CS_NORMAL;
			Base::def_cursor();
		}
		return false;
	}
	// else
	
	int key = getch();
	if(key != ERR) // there is some key
	{
		if(key == KEYCODE_INT)
			return true; // ^C quits

		if(clientstate == CS_HELP || clientstate == CS_TEAM_INFO)
		{
			// any key in help screen closes help
			leave_limbo(); // not leaving limbo, but the functionality is the same
			return false;
		}

		// Quickshouts handled regardless of clientstate:
		if(ClassCPV::im_alive())
		{
			for(char f = 1; f <= MAX_QUICK_SHOUTS; ++f)
			{
				if(key == KEY_F(f))
				{
					if(!Config::quick_shout(--f).empty())
						Network::send_line(Config::quick_shout(f), false);
					return false;
				}
			}
		}

		if(clientstate == CS_LIMBO)
		{
			key = tolower(key);
			if(key <= 'k' && key >= 'a') // switch class
			{
				Network::send_spawn((unsigned char)(key - 'a'));
				leave_limbo();
			}
			else if(key == 't')
			{
				Network::send_switch();
				leave_limbo();
			}
			else if(key == 's')
			{
				Network::send_spawn(NO_CLASS);
				leave_limbo();
			}
			else if(key == 'l' || key == 27) // 27: escape
				leave_limbo();
		}
		else
		{
			if(key == '?') // help key
			{
				clientstate = CS_HELP;
				walkmode_off();
				redraw_view();
				Base::type_cursor(0);
				return false;
			}

			// if here, we need to convert the key:
			e_Key_binding kb = MAX_KEY_BINDING;
			if(key < 256) // fits in a byte; try to convert
				kb = Config::convert_key(char(key));
			// map arrow keys to the directions, for the n00bs:
			else if(key == KEY_UP)
				kb = KB_8;
			else if(key == KEY_DOWN)
				kb = KB_2;
			else if(key == KEY_LEFT)
				kb = KB_4;
			else if(key == KEY_RIGHT)
				kb = KB_6;
		
			if(kb < MAX_KEY_BINDING) // a recognized key
			{
			switch(kb)
			{
			/*
			 * The effect of these depends on clientstate & class.
			 * The handling is delegated to class_cpv.cpp
			 */
			case KB_1: // movement
			case KB_2: case KB_3: case KB_4: case KB_6: case KB_7: case KB_8: case KB_9:
				ClassCPV::move((last_dir = e_Dir(kb)));
				break;
			case KB_5: // special direction
				ClassCPV::five();
				last_dir = MAX_D;
				break;
			case KB_SPACE: // action key
				ClassCPV::space();
				walkmode_off();
				break;
			case KB_p: // follow previous key
				ClassCPV::follow_prev();
				walkmode_off();
				break;

			/*
			 * These can be done in the middle of unfinished actions, but will cause
			 * interruption:
			 */
			case KB_C: // say in chat
				clientstate = CS_TYPE_CHAT;
				init_type();
				walkmode_off();
				break;
			case KB_s: // say aloud
				clientstate = CS_TYPE_SHOUT;
				init_type();
				walkmode_off();
				break;
			case KB_c: // close a door
				Network::send_action(XN_CLOSE_DOOR);
				// interrupts any aiming/casting etc:
				clientstate = CS_NORMAL;
				walkmode_off();
				break;
			case KB_u: // torch handling
				Network::send_action(XN_TORCH_HANDLE);
				// interrupts any aiming/casting etc:
				clientstate = CS_NORMAL;
				walkmode_off();
				break;
			case KB_T: // trigger a trap
				Network::send_action(XN_TRAP_TRIGGER);
				// interrupts any aiming/casting etc:
				clientstate = CS_NORMAL;
				walkmode_off();
				break;
			case KB_X: // suicide
				ClassCPV::suicide();
				walkmode_off();
				break;
			case KB_l: // limbo toggle
				clientstate = CS_LIMBO;
				walkmode_off();
				redraw_view();
				Base::type_cursor(0);
				break;
			case KB_i: // request team info
				Network::send_teami_req();
				break;	
			case KB_Q: // quit
				return true; // confirmation? nah

			/*
			 * The following can be carried out in any clientstate except limbo
			 * without interruption:
			 */
			case KB_w: // walk toggle
				if(walkmode)
					walkmode_off();
				else
					Base::print_walk((walkmode = true));
				break;
			case KB_t: // titles toggle
				toggle_titles();
				break;
			case KB_d: // differentiate titles
				diff_titles();
				break;
			case KB_o: // ouching toggle
				add_msg(string("[Reacting to damage ") + offon[Config::toggle_ouch()], 15);
				break;
			case KB_PLUS:
				scroll_chat_up();
				break;
			case KB_MINUS:
				scroll_chat_down();
				break;
			case KB_PERCENT:
				add_msg(string("[Act per turn ") + offon[Config::toggle_act_per_turn()], 15);
				break;
			default: break;
			}
			} // a recognized key binding
		} // need to convert key
	} // key != ERR
	else if(clientstate == CS_NORMAL && walkmode && last_dir != MAX_D
		&& Network::not_acted())
		ClassCPV::move(last_dir);
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
cmpl $0x1, 0x1cbee(%rip)     # 0x28fe0
je 0xc3fd
cmpl $0x2, 0x1cbe5(%rip)     # 0x28fe0
jne 0xc420
callq 0xc9b0
testb $0x1, %al
jne 0xc408
jmp 0xc417
movl $0x0, 0x1cbce(%rip)     # 0x28fe0
callq 0x99b0
movb $0x0, -0x1(%rbp)
jmp 0xc991
movq 0x1bb91(%rip), %rax     # 0x27fb8
movq (%rax), %rdi
callq 0x5660
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
je 0xc95a
cmpl $0x3, -0x8(%rbp)
jne 0xc44b
movb $0x1, -0x1(%rbp)
jmp 0xc991
cmpl $0x4, 0x1cb8e(%rip)     # 0x28fe0
je 0xc45d
cmpl $0x5, 0x1cb85(%rip)     # 0x28fe0
jne 0xc46b
callq 0xcff0
movb $0x0, -0x1(%rbp)
jmp 0xc991
callq 0xb3f0
testb $0x1, %al
jne 0xc476
jmp 0xc4da
movb $0x1, -0x9(%rbp)
movsbl -0x9(%rbp), %eax
cmpl $0xc, %eax
jg 0xc4d8
movl -0x8(%rbp), %eax
movsbl -0x9(%rbp), %ecx
addl $0x108, %ecx            # imm = 0x108
cmpl %ecx, %eax
jne 0xc4cc
movb -0x9(%rbp), %al
addb $-0x1, %al
movb %al, -0x9(%rbp)
movsbl %al, %edi
callq 0x16180
movq %rax, %rdi
callq 0x57f0
testb $0x1, %al
jne 0xc4c3
movsbl -0x9(%rbp), %edi
callq 0x16180
movq %rax, %rdi
xorl %esi, %esi
callq 0x14360
movb $0x0, -0x1(%rbp)
jmp 0xc991
jmp 0xc4ce
movb -0x9(%rbp), %al
addb $0x1, %al
movb %al, -0x9(%rbp)
jmp 0xc47a
jmp 0xc4da
cmpl $0x3, 0x1caff(%rip)     # 0x28fe0
jne 0xc554
movl -0x8(%rbp), %edi
callq 0x5710
movl %eax, -0x8(%rbp)
cmpl $0x6b, -0x8(%rbp)
jg 0xc50f
cmpl $0x61, -0x8(%rbp)
jl 0xc50f
movl -0x8(%rbp), %eax
subl $0x61, %eax
movzbl %al, %edi
callq 0x14460
callq 0xcff0
jmp 0xc54f
cmpl $0x74, -0x8(%rbp)
jne 0xc521
callq 0x144c0
callq 0xcff0
jmp 0xc54d
cmpl $0x73, -0x8(%rbp)
jne 0xc538
movl $0xb, %edi
callq 0x14460
callq 0xcff0
jmp 0xc54b
cmpl $0x6c, -0x8(%rbp)
je 0xc544
cmpl $0x1b, -0x8(%rbp)
jne 0xc549
callq 0xcff0
jmp 0xc54b
jmp 0xc54d
jmp 0xc54f
jmp 0xc958
cmpl $0x3f, -0x8(%rbp)
jne 0xc57e
movl $0x4, 0x1ca7c(%rip)     # 0x28fe0
callq 0xd010
callq 0x19160
xorl %edi, %edi
callq 0x99d0
movb $0x0, -0x1(%rbp)
jmp 0xc991
movl $0x1b, -0x10(%rbp)
cmpl $0x100, -0x8(%rbp)      # imm = 0x100
jge 0xc59e
movl -0x8(%rbp), %eax
movsbl %al, %edi
callq 0x15e20
movl %eax, -0x10(%rbp)
jmp 0xc5ec
cmpl $0x103, -0x8(%rbp)      # imm = 0x103
jne 0xc5b0
movl $0x0, -0x10(%rbp)
jmp 0xc5ea
cmpl $0x102, -0x8(%rbp)      # imm = 0x102
jne 0xc5c2
movl $0x4, -0x10(%rbp)
jmp 0xc5e8
cmpl $0x104, -0x8(%rbp)      # imm = 0x104
jne 0xc5d4
movl $0x6, -0x10(%rbp)
jmp 0xc5e6
cmpl $0x105, -0x8(%rbp)      # imm = 0x105
jne 0xc5e4
movl $0x2, -0x10(%rbp)
jmp 0xc5e6
jmp 0xc5e8
jmp 0xc5ea
jmp 0xc5ec
cmpl $0x1b, -0x10(%rbp)
jge 0xc956
movl -0x10(%rbp), %eax
movq %rax, -0xb8(%rbp)
subq $0x1a, %rax
ja 0xc952
movq -0xb8(%rbp), %rax
leaq 0xff78(%rip), %rcx      # 0x1c590
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x10(%rbp), %edi
movl %edi, 0x1beb6(%rip)     # 0x284e0
callq 0xb0a0
jmp 0xc954
callq 0xb230
movl $0x8, 0x1be9d(%rip)     # 0x284e0
jmp 0xc954
callq 0xb2b0
callq 0xd010
jmp 0xc954
callq 0xb420
callq 0xd010
jmp 0xc954
movl $0x1, 0x1c970(%rip)     # 0x28fe0
callq 0xd040
callq 0xd010
jmp 0xc954
movl $0x2, 0x1c957(%rip)     # 0x28fe0
callq 0xd040
callq 0xd010
jmp 0xc954
xorl %edx, %edx
movl %edx, %edi
movl %edx, %esi
callq 0x14210
movl $0x0, 0x1c933(%rip)     # 0x28fe0
callq 0xd010
jmp 0xc954
movl $0x1, %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x14210
movl $0x0, 0x1c911(%rip)     # 0x28fe0
callq 0xd010
jmp 0xc954
movl $0x2, %edi
xorl %edx, %edx
movl %edx, %esi
callq 0x14210
movl $0x0, 0x1c8ef(%rip)     # 0x28fe0
callq 0xd010
jmp 0xc954
callq 0xb440
callq 0xd010
jmp 0xc954
movl $0x3, 0x1c8cc(%rip)     # 0x28fe0
callq 0xd010
callq 0x19160
xorl %edi, %edi
callq 0x99d0
jmp 0xc954
callq 0x14500
jmp 0xc954
movb $0x1, -0x1(%rbp)
jmp 0xc991
testb $0x1, 0x1c8a0(%rip)     # 0x28fe4
je 0xc74d
callq 0xd010
jmp 0xc75e
movb $0x1, 0x1c890(%rip)     # 0x28fe4
movl $0x1, %edi
callq 0x9ac0
jmp 0xc954
callq 0x18f90
jmp 0xc954
callq 0x19270
jmp 0xc954
leaq -0x51(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x5840
movq -0xc0(%rbp), %rdx
leaq 0xfe67(%rip), %rsi      # 0x1c5fc
leaq -0x50(%rbp), %rdi
callq 0xa030
jmp 0xc7a0
callq 0x162f0
movb %al, -0xc1(%rbp)
jmp 0xc7ad
movb -0xc1(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, %ecx
leaq 0x1bd2e(%rip), %rax     # 0x284f0
movq (%rax,%rcx,8), %rdx
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xa1d0
jmp 0xc7d5
leaq -0x30(%rbp), %rdi
movl $0xf, %esi
callq 0xe180
jmp 0xc7e5
leaq -0x30(%rbp), %rdi
callq 0x5968
leaq -0x50(%rbp), %rdi
callq 0x5968
leaq -0x51(%rbp), %rdi
callq 0x5540
jmp 0xc954
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xc83f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xc836
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x5968
leaq -0x50(%rbp), %rdi
callq 0x5968
leaq -0x51(%rbp), %rdi
callq 0x5540
jmp 0xc99f
callq 0xf520
jmp 0xc954
callq 0xf570
jmp 0xc954
leaq -0xa9(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x5840
movq -0xd0(%rbp), %rdx
leaq 0xfd8f(%rip), %rsi      # 0x1c611
leaq -0xa8(%rbp), %rdi
callq 0xa030
jmp 0xc890
callq 0x16340
movb %al, -0xd1(%rbp)
jmp 0xc89d
movb -0xd1(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, %ecx
leaq 0x1bc3e(%rip), %rax     # 0x284f0
movq (%rax,%rcx,8), %rdx
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0xa1d0
jmp 0xc8cb
leaq -0x88(%rbp), %rdi
movl $0xf, %esi
callq 0xe180
jmp 0xc8de
leaq -0x88(%rbp), %rdi
callq 0x5968
leaq -0xa8(%rbp), %rdi
callq 0x5968
leaq -0xa9(%rbp), %rdi
callq 0x5540
jmp 0xc954
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xc944
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xc938
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5968
leaq -0xa8(%rbp), %rdi
callq 0x5968
leaq -0xa9(%rbp), %rdi
callq 0x5540
jmp 0xc99f
jmp 0xc954
jmp 0xc956
jmp 0xc958
jmp 0xc98d
cmpl $0x0, 0x1c67f(%rip)     # 0x28fe0
jne 0xc98b
testb $0x1, 0x1c67a(%rip)     # 0x28fe4
je 0xc98b
cmpl $0x8, 0x1bb6d(%rip)     # 0x284e0
je 0xc98b
callq 0x14540
testb $0x1, %al
jne 0xc980
jmp 0xc98b
movl 0x1bb5a(%rip), %edi     # 0x284e0
callq 0xb0a0
jmp 0xc98d
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xe0, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x5830
nopl (%rax,%rax)