⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagemgr.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInputLine::CInputLine()
//
//	PURPOSE:	constructor
//
// ----------------------------------------------------------------------- //
			
DBOOL CInputLine::AddChar( DBYTE ch )
{
	if (m_nTextLen < MAXINPUTLINE)	// space left in the Message
	{
		m_zText[m_nTextLen] = ch;	// add a character
		m_nTextLen++;				// increment the length
		m_zText[m_nTextLen] = '\0';	// terminate the string
		return DTRUE;				// indicate success
	}
	return DFALSE;	// indicate failure
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInputLine::CInputLine()
//
//	PURPOSE:	constructor
//
// ----------------------------------------------------------------------- //
			
void CInputLine::DelChar( void )
{
	if (m_nTextLen > 0)	// text in the Message?
	{
		m_nTextLen--;				// back up a character
		m_zText[m_nTextLen] = '\0';	// terminate the string
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInputLine::CInputLine()
//
//	PURPOSE:	constructor
//
// ----------------------------------------------------------------------- //
			
void CInputLine::Set( char *pzText )
{
	_mbsncpy((unsigned char*)m_zText, (const unsigned char*)pzText, MAXINPUTLINE);					// copy the text
	m_zText[MAXINPUTLINE] = '\0';							// enforce null termination
	m_nTextLen = _mbstrlen(pzText);							// enforce max length
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInputLine::CInputLine()
//
//	PURPOSE:	constructor
//
// ----------------------------------------------------------------------- //
			
void CInputLine::Send( void )
{
	// Send the Message to the server
	HMESSAGEWRITE hMsg = m_pClientDE->StartMessage(CMSG_PLAYERMESSAGE);
	m_pClientDE->WriteToMessageString(hMsg, m_zText);
	m_pClientDE->EndMessage(hMsg);

	Term();
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInputLine::CInputLine()
//
//	PURPOSE:	constructor
//
// ----------------------------------------------------------------------- //
			
DBOOL CInputLine::HandleKeyDown(int key, int rep)
{
	switch( key )
	{
		case VK_ESCAPE:
			Term();
			break;

		case VK_HOME:
			Clear();
			break;

		case VK_BACK:
			DelChar();
			break;

		case VK_SHIFT:
			m_bShift = DTRUE;
			break;

		case VK_RETURN:
				if ( g_pCheatMgr->Check(m_zText) )
					Term();
				else
					Send();
			break;

		default:
		{
			char ch;
			if (ch = AsciiXlate(key))
			{
				if (!AddChar(ch) )
				{
				}
			}
			break;
		}
	}
	return DTRUE;
}



// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInputLine::HandleKeyUp()
//
//	PURPOSE:	Handles a key up Message, used for tracking shift keys
//
// ----------------------------------------------------------------------- //
			
void CInputLine::HandleKeyUp(int key)
{
	switch( key )
	{
		case VK_SHIFT:
			m_bShift = DFALSE;
			break;
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CInputLine::AsciiXlate()
//
//	PURPOSE:	Translates a VK_ code into something viewable.
//
// ----------------------------------------------------------------------- //
			
char CInputLine::AsciiXlate(int key)
{
	char ch = 0;
	char *zNumShift = ")!@#$%^&*(";

	// Check for a letter
	if (key >= VK_A && key <= VK_Z)
	{
		ch = m_bShift ? key : key - 'A' + 'a';
	}
	// Check for a number
	else if (key >= VK_0 && key <= VK_9)
	{
		ch = m_bShift ? zNumShift[key - VK_0] : key;
	}
	// Now check for the remaining usable keys
	else
	{
		switch(key)
		{
			case VK_SPACE: ch = ' '; break;
			case 189: ch = m_bShift ? '_' : '-'; break;
			case 187: ch = m_bShift ? '+' : '='; break;
			case 219: ch = m_bShift ? '{' : '['; break;
			case 221: ch = m_bShift ? '}' : ']'; break;
			case 220: ch = m_bShift ? '|' : '\\'; break;
			case 186: ch = m_bShift ? ':' : ';'; break;
			case 222: ch = m_bShift ? '"' : '\''; break;
			case 188: ch = m_bShift ? '<' : ','; break;
			case 190: ch = m_bShift ? '>' : '.'; break;
			case 191: ch = m_bShift ? '?' : '/'; break;
		}
	}
	return ch;

}



/*******************************************************************************

	CCheatMgr

*******************************************************************************/

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::Init()
//
//	PURPOSE:	Initializes the cheat manager
//
// ----------------------------------------------------------------------- //
			
void CCheatMgr::Init(CClientDE* pClientDE)
{
	m_pClientDE = pClientDE;
	g_pCheatMgr = this;

#if ENCRYPT_CHEATS
	Decrypt();
#endif

}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::Reset()
//
//	PURPOSE:	Resets all cheats to the off position
//
// ----------------------------------------------------------------------- //
			
void CCheatMgr::Reset()
{
	for (int i = 0; i < CHEAT_MAX; i++)
	{
		s_CheatInfo[i].bActive = DFALSE;
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::Decrypt()
//
//	PURPOSE:	Decrypts the cheat codes
//
// ----------------------------------------------------------------------- //
			
void CCheatMgr::Decrypt()
{
	// Decrypt each cheat code...

	for (int i = 0; i < CHEAT_MAX; i++)
	{
		char* sCheat = s_CheatInfo[i].pzText;

		while (*sCheat != '\0' && *sCheat != NULL)
		{
			*sCheat -= 13;
			sCheat++;
		}
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::Check()
//
//	PURPOSE:	See if a string is a cheat code
//
// ----------------------------------------------------------------------- //
			
DBOOL CCheatMgr::Check( char *pzText )
{
	char buf[MAXINPUTLINE+2];
	unsigned i;

	// copy their text
	_mbscpy((unsigned char*)buf, (const unsigned char*)pzText);
	strupr(buf);

	// It should start with "MP"
	if ( _mbsncmp((const unsigned char*)buf, (const unsigned char*)"MP", 2) != 0 )
		return DFALSE;

	// convert it to cheat compatible text
//	for ( i = 0; i < _mbstrlen(pzText); i++ )
//		buf[i]++;

	// then compare the converted text (skip the first two chars, already know they are "MP"
	for ( i = 0; i < CHEAT_MAX; i++ )
	{
		if ( _mbscmp((const unsigned char*) buf+2, (const unsigned char*)(s_CheatInfo[i].pzText) ) == 0)
		{
			Process( (CheatCodes)i );
			return DTRUE;
		}
	}
	return DFALSE;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::Process()
//
//	PURPOSE:	Calls the appropriate cheat function
//
// ----------------------------------------------------------------------- //
			
void CCheatMgr::Process( CheatCodes nCheatCode )
{
	// No cheats in multiplayer
	if (g_pBloodClientShell && g_pBloodClientShell->IsMultiplayerGame())
		return;

	if ( nCheatCode < CHEAT_NONE || nCheatCode >= CHEAT_MAX )
		return;

#ifdef _DEMO
	if (!IsValidDemoCheat(nCheatCode))
	{
		return;
	}
#endif

	// Weapon cheat
	if ( nCheatCode >= CHEAT_FIRSTWEAPON && nCheatCode <= CHEAT_LASTWEAPON)
	{
		s_CheatInfo[nCheatCode].bActive = DTRUE;
		// Tell the server
		SendCheatMessage(nCheatCode, DTRUE);
		return;
	}

	// process cheat codes
	switch ( nCheatCode )
	{
		case CHEAT_GOD:			// god mode toggle
			ToggleCheat(nCheatCode, "You are a GOD.", "God mode off. Help!");
			break;

		case CHEAT_KFA:			// god mode toggle
			ActivateCheat(nCheatCode, "Monolith Rulez...");
			break;

		case CHEAT_KFA2:		// god mode toggle (different weapons)
			ActivateCheat(nCheatCode, "Monolith Rulez...");
			break;

		case CHEAT_AMMO:		// full ammo
			ActivateCheat(nCheatCode, "You have full ammo.");
			break;

		case CHEAT_CLIP:		// toggle clipping mode
			ToggleCheat(nCheatCode, "Spectator mode on.", "Spectator mode off.");	
			break;

		case CHEAT_HEALTH:		// full health
			ActivateCheat(nCheatCode, "You have full health.");
			break;

		case CHEAT_WHEREAMI:	// Display position
			ToggleCheat(nCheatCode, "Display pos on.", "Display pos off.");	
			break;

		case CHEAT_STEALTH:		// Stealth mode
			ActivateCheat(nCheatCode, "Where did I go??.");
			break;

		case CHEAT_TRIPLEDAMAGE:	// Triple Damage
			ActivateCheat(nCheatCode, "Beefcake! BEEFCAKE!");
			break;

		case CHEAT_KILLALLAI:
			ActivateCheat(nCheatCode, "...Let Tchernobog sort'em out.");
			break;

		case CHEAT_INCSPEED:
		case CHEAT_INCSTRENGTH:	// Increase strength
		case CHEAT_CALEB:
		case CHEAT_OPHELIA:
		case CHEAT_ISHMAEL:
		case CHEAT_GABRIELLA:
			ActivateCheat(nCheatCode, DNULL);
			break; 
			
		case CHEAT_GOBLE:
		case CHEAT_SCORPIO:
			ActivateCheat(nCheatCode, "Brian L. Goble is a programming god!");
			break;

		case CHEAT_TOTARO:
			ActivateCheat(nCheatCode, "Jim Totaro is da man!");
			break;

#ifdef _DEMO
		case CHEAT_DEMOLEVEL2:
			g_pBloodClientShell->StartNewWorld("Demo_02", GAMETYPE_SINGLE, LOADTYPE_NEW_LEVEL);
			break;
#endif

		case CHEAT_GIVEALLINV:
		{
			ActivateCheat(nCheatCode, "You just bought our entire inventory!");
			break;
		}

		case CHEAT_POW_HEALTH:
		{
			ActivateCheat(nCheatCode, "Thanks nurse!");
			break;
		}
			
		case CHEAT_POW_MEGAHEALTH:
		{
			ActivateCheat(nCheatCode, "Thanks nurse! How bout a date?");
			break;
		}
			
		case CHEAT_POW_WARD:
		{
			ActivateCheat(nCheatCode, "Ward awarded");
			break;
		}
			
		case CHEAT_POW_NECROWARD:
		{
			ActivateCheat(nCheatCode, "Necroward awarded");
			break;
		}
			
		case CHEAT_POW_INVULN:
		{
			ActivateCheat(nCheatCode, "Light and strong");
			break;
		}
			
		case CHEAT_POW_STEALTH:
		{
			ActivateCheat(nCheatCode, "They'll never hear you coming");
			break;
		}
			
		case CHEAT_POW_ANGER:
		{
			ActivateCheat(nCheatCode, "...and the hurtfulness...");
			break;
		}

		case CHEAT_CHASEVIEW:
		{
			ToggleCheat(nCheatCode, DNULL, DNULL);
			break;
		}

		default:
			return;				// skip setting global cheat indicator for unhandled cheats
	}

	m_bPlayerCheated = DTRUE;
}



// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::SendCheatMessage()
//
//	PURPOSE:	sends a cheat to the server
//
// ----------------------------------------------------------------------- //
			
void CCheatMgr::SendCheatMessage( CheatCodes nCheatCode, DBOOL bState )
{
	// Send the Message to the server
	HMESSAGEWRITE hMsg = m_pClientDE->StartMessage(CMSG_CHEAT);
	m_pClientDE->WriteToMessageByte(hMsg, (DBYTE)nCheatCode);
	m_pClientDE->WriteToMessageByte(hMsg, (DBYTE)bState);
	m_pClientDE->EndMessage(hMsg);
}



// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::ToggleCheat()
//
//	PURPOSE:	Generic cheat toggle function can be used for many cheats
//
// ----------------------------------------------------------------------- //
			
void CCheatMgr::ToggleCheat(CheatCodes nCheatCode, char *szMsgOn, char *szMsgOff)
{
	s_CheatInfo[nCheatCode].bActive = !s_CheatInfo[nCheatCode].bActive;

	if (s_CheatInfo[nCheatCode].bActive)
		g_pMessageMgr->AddLine(szMsgOn);
	else
		g_pMessageMgr->AddLine(szMsgOff);

	// Tell the server
	SendCheatMessage(nCheatCode, s_CheatInfo[nCheatCode].bActive);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CCheatMgr::ActivateCheat()
//
//	PURPOSE:	Activates the given cheat code
//
// ----------------------------------------------------------------------- //
			
void CCheatMgr::ActivateCheat(CheatCodes eCheatCode, char *szMsgOn)
{
	s_CheatInfo[eCheatCode].bActive = DTRUE;

	// Tell the server
	SendCheatMessage(eCheatCode, DTRUE);

	if (szMsgOn)
		g_pMessageMgr->AddLine(szMsgOn);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	IsValidDemoCheat
//
//	PURPOSE:	Determines if the given cheat code is valid in the demo
//
// ----------------------------------------------------------------------- //
			
DBOOL IsValidDemoCheat(int nCheat)
{
	// Check if this is a valid cheat code...

	if (nCheat == CHEAT_GOD) return(DTRUE);
	if (nCheat == CHEAT_KFA) return(DTRUE);
	if (nCheat == CHEAT_WHEREAMI) return(DTRUE);
	if (nCheat == CHEAT_DEMOLEVEL2) return(DTRUE);
	if (nCheat == CHEAT_CLIP) return(DTRUE);


	// If we get here, it's not a valid cheat for the demo...

	return(DFALSE);
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -