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

📄 mcgapp.cpp

📁 国外网游源码....除工具源码缺少之外,其余程序都全...至于,什么游戏,因为国内还没有,所以找不到测试
💻 CPP
字号:
// MCGApp.cpp: implementation of the CMCGApp class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "3DGame.h"

//#ifdef _DEBUG
//#undef THIS_FILE
//static char THIS_FILE[]=__FILE__;
//#define new DEBUG_NEW
//#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//CDrawEx *m_pDraw;


//甘捞抚.

CMCGApp::CMCGApp()
{
	InitApp();
}

CMCGApp::~CMCGApp()
{
	CloseApp();
}

VOID CMCGApp::InitApp()
{
	m_cpScene		= NULL;
	m_cpDrawEx		= NULL;
	m_cpCamera		= NULL;
	m_cpFrustum		= NULL;
	m_cpUserInfo	= NULL;
	m_cpRoomInfo	= NULL;
	m_pSoundManager	= NULL;
	m_pCommonImage	= NULL;
	m_pBGMManager	= NULL;
	m_pObjectManager= NULL;
	m_pItemManager	= NULL;

	m_iCurrentLayer = 0;
	
	m_lBackSound = 0;
	m_lEffectSound = 0;


	m_bSkipLobby = 0;


	ZeroMemory(m_strAppName,sizeof(m_strAppName));
	ZeroMemory(m_strServerIp,sizeof(m_strServerIp));
	GetPrivateProfileString("SYSTEM", "APPNAME", "MCGames", m_strAppName, sizeof(m_strAppName), BSINIT);
	GetPrivateProfileString("SYSTEM", "SERVERIP", "192.168.0.5", m_strServerIp, sizeof(m_strServerIp), BSINIT);
	m_dwScreenWidth = GetPrivateProfileInt("SYSTEM", "SCREEN_X", 1024, BSINIT);
	m_dwScreenHeight = GetPrivateProfileInt("SYSTEM", "SCREEN_Y", 768, BSINIT);
	m_bFullScreen = GetPrivateProfileInt("SYSTEM", "FULLSCREEN", 0, BSINIT);
	m_bMouseVisible = GetPrivateProfileInt("SYSTEM", "SHOWMOUSE", 0, BSINIT);

	m_bObjectVisible = GetPrivateProfileInt("GAME", "SHOWOBJECT", 0, BSINIT);
	m_bLobbyVisible = GetPrivateProfileInt("GAME", "LOBBYSKIP", 0, BSINIT);


	//metaljack 2006.06.08
	for(int i = 0 ; i < 16 ; i++)
	{
		memset(&m_MyGameUserEx[i], NULL, sizeof(UserInfoEx));
		m_MyGameUserEx[i].m_iLobbyIndex = -1;
		m_MyGameUserEx[i].m_iGameIndex = -1;
		m_MyGameUserEx[i].m_iSlot = -1;
		m_MyGameUserEx[i].bLoading = false;
	}
	
	memset(&m_MyGameRoomEx, NULL, sizeof(RoomInfoEx));
	memset(&m_MyInfoEx, NULL, sizeof(UserInfoEx));
	

#ifdef _WEBLOGIN
	ZeroMemory(g_ClientInfo.szID,sizeof(g_ClientInfo.szID));
	ZeroMemory(g_ClientInfo.szPW,sizeof(g_ClientInfo.szPW));
	GetPrivateProfileString("USER", "ID", "test01", g_ClientInfo.szID, sizeof(g_ClientInfo.szID), BSINIT);
	GetPrivateProfileString("USER", "PASS", "1234", g_ClientInfo.szPW, sizeof(g_ClientInfo.szPW), BSINIT);

#endif	

}

HRESULT CMCGApp::Create( HINSTANCE hInstance )
{
	if(FAILED(CD3DApplication::Create(hInstance)))
		return E_FAIL;

	m_cpDrawEx = new CDrawEx(g_pApp->GetD3dDevice());
	if(!m_cpDrawEx)
		return E_FAIL;

	m_cpCamera = new CMCGCamera();
	if(!m_cpCamera)
		return E_FAIL;

	m_cpFrustum = new CFrustum();
	if(!m_cpFrustum)
		return E_FAIL;

	m_cpUserInfo = new CUserInfo();
	if(!m_cpUserInfo)
		return E_FAIL;

	m_cpRoomInfo = new CRoomInfo();
	if(!m_cpRoomInfo)
		return E_FAIL;

	m_pSoundManager = new CMCSound();
	if(!m_pSoundManager)
		return E_FAIL;
	m_pSoundManager->CreateSound("data\\Text\\Sound_Load_List.txt");
	
	m_pBGMManager = new CMCMusicBase();
	if(!m_pBGMManager)
		return E_FAIL;
	m_pBGMManager->CreateMusic(_T("data\\Text\\BGM_Load_List.txt"));

	m_pTextureManager = new CTextureManager();
	if(!m_pTextureManager)
		return E_FAIL;

	m_pObjectManager = new CMCObjectManager();
	if(!m_pObjectManager)
		return E_FAIL;
	
	m_pItemManager = new CItemManager;
	if(!m_pItemManager)
		return E_FAIL;
	m_pItemManager->LoadItem("data\\Text\\weapon.ite");
	m_pItemManager->LoadItem("data\\Text\\assist.ite");
	m_pItemManager->LoadItem("data\\Text\\mechanic.ite");
	

	return S_OK;
}

VOID CMCGApp::CloseApp()
{
	if(m_cpScene != NULL)
		SAFE_DELETE(m_cpScene);
	if(m_cpDrawEx)
		SAFE_DELETE(m_cpDrawEx);
	if(m_cpCamera)
		SAFE_DELETE(m_cpCamera);
	if(m_cpFrustum)
		SAFE_DELETE(m_cpFrustum);
	if(m_cpUserInfo)
		SAFE_DELETE(m_cpUserInfo);
	if(m_cpRoomInfo)
		SAFE_DELETE(m_cpRoomInfo);
	if(m_pSoundManager)
		SAFE_DELETE(m_pSoundManager);
	if(m_pBGMManager)
		SAFE_DELETE(m_pBGMManager);
//	if(m_pCommonImage != NULL)
//		SAFE_RELEASE(m_pCommonImage);

	if(m_pTextureManager)
		SAFE_DELETE(m_pTextureManager);
	if(m_pObjectManager)
		SAFE_DELETE(m_pObjectManager);
	if(m_pItemManager)
		SAFE_DELETE(m_pItemManager);

	InvalidateDeviceObjects();
	DeleteDeviceObjects();
	FinalCleanup();
}

HRESULT	CMCGApp::InvalidateDeviceObjects()
{
	if(FAILED(CD3DApplication::InvalidateDeviceObjects()))
		return E_FAIL;

	if(m_cpScene){
		if(FAILED(m_cpScene->InvalidateDeviceObjects()))
			return E_FAIL;
	}

	vector<CBaseFonts *>::iterator iter;
	for(iter = m_listFont.begin() ; iter != m_listFont.end() ; ++iter)
	{
		CBaseFonts * pFont = *iter;
		//((CBaseFonts *)*iter)->Invalidate();
		pFont->Invalidate();
	}

	return S_OK;
}

HRESULT	CMCGApp::RestoreDeviceObjects()
{
	if(FAILED(CD3DApplication::RestoreDeviceObjects()))
		return E_FAIL;

	if(m_cpScene){
		if(FAILED(m_cpScene->RestoreDeviceObjects()))
			return E_FAIL;
	}

	vector<CBaseFonts *>::iterator iter;
	for(iter = m_listFont.begin() ; iter != m_listFont.end() ; ++iter)
	{
		CBaseFonts * pFont = *iter;
		pFont->Restore();
	//	((CBaseFonts *)*iter)->Restore();
	}
	
	return S_OK;
}

VOID CMCGApp::ChangeScene( BYTE nScene, bool bDelete )
{
//	SAFE_DELETE(m_cpScene);
	
//	m_iCurrentLayer = 0;
	
	switch(nScene) {
	case SCENE_UNKNOWN:
		break;
	case SCENE_INIT:
		{
			if(g_pApp->m_bLobbyVisible == FALSE)
			{
				//傍烹捞固瘤 肺爹
				m_pCommonImage = new CCommonImage(GetD3dDevice(), m_cpDrawEx);
				m_pCommonImage->LoadCommonImage();

				m_cpSceneSelectServer = new CMCServerInScene(m_cpDrawEx);
				m_cpSceneSelectServer->LoadScene();
								
				ChangeScene(SCENE_SERVER);		
			}
			else
			{
			}
		}
		break;
	case SCENE_SERVER:
		{

			m_cpScene = m_cpSceneSelectServer;
			m_cpScene->SetScene( SCENE_SERVER );		
		}
		break;

	case SCENE_CHANNEL:
		{
			if(g_pApp->m_bLobbyVisible == FALSE)
			{
				SAFE_DELETE(m_cpSceneSelectServer);

				m_cpSceneSelectChannel = new CMCChannelInScene(m_cpDrawEx);
				m_cpSceneSelectChannel->LoadScene();
			}
				
			m_cpScene = m_cpSceneSelectChannel;
			m_cpScene->SetScene( SCENE_CHANNEL );
		}
		break;

	case SCENE_LOBBY:
		{
			if(g_pApp->m_bLobbyVisible == FALSE)
			{
				SAFE_DELETE(m_cpSceneSelectChannel);

				m_cpSceneLobbyEx = new CMCLobbySceneEx(m_cpDrawEx);
				m_cpSceneLobbyEx->LoadScene();
				
				m_cpSceneBattleRoom = new CMCBattleRoomScene(m_cpDrawEx);
				m_cpSceneBattleRoom->LoadScene();
				
				m_cpSceneMyInven = new CMCInventoryScene(m_cpDrawEx);
				m_cpSceneMyInven->LoadScene();
				
				m_cpSceneCharShop = new CMCCharactorShopScene(m_cpDrawEx);
				m_cpSceneCharShop->LoadScene();
				
				m_cpSceneItemShop = new CMCItemShopScene(m_cpDrawEx);
				m_cpSceneItemShop->LoadScene();
			}

			m_cpScene = m_cpSceneLobbyEx;
			m_cpScene->SetScene( SCENE_LOBBY );
		}
		break;
		
	case SCENE_BATTLEROOM:
		{
			m_cpScene = m_cpSceneBattleRoom;
			m_cpScene->SetScene( SCENE_BATTLEROOM );
		}
		break;

	case SCENE_MYINVEN:
		{
			m_cpScene = m_cpSceneMyInven;
			m_cpScene->SetScene( SCENE_MYINVEN );
		}
		break;

	case SCENE_CHARSHOP:
		{
			m_cpScene = m_cpSceneCharShop;
			m_cpScene->SetScene( SCENE_CHARSHOP );
		}
		break;

	case SCENE_ITEMSHOP:
		{
			m_cpScene = m_cpSceneItemShop;
			m_cpScene->SetScene( SCENE_ITEMSHOP );
		}
		break;

	case SCENE_3DGAME:
		{
			if(g_pApp->m_bLobbyVisible == FALSE)
			{
//				SAFE_DELETE(m_cpSceneSelectServer);
//				SAFE_DELETE(m_cpSceneSelectChannel);
				SAFE_DELETE(m_cpSceneLobbyEx);
				SAFE_DELETE(m_cpSceneBattleRoom);
				SAFE_DELETE(m_cpSceneMyInven);
				SAFE_DELETE(m_cpSceneCharShop);
				SAFE_RELEASE(m_pCommonImage);
				SAFE_DELETE(m_cpSceneItemShop);
				
				g_pDrawEx->ReleaseImageFile();
			}

			// 咯扁辑 霸烙 肺爹 矫累
			m_cpScene = new C3DGame();
			m_cpScene->LoadScene();
//			m_cpScene->SetScene( SCENE_3DGAME );
			
			//12.CGS_GAME_IN [霸烙辑滚] //咯扁俊辑 霸烙俊 包访等 单捞磐甫 辆钦窍咯 肺爹窍绊 肺爹捞 场唱搁 捞皋矫瘤甫 焊辰促.
			//霸烙包访 肺爹捞 肯傈洒 场唱 菩哦阑 罐阑 霖厚啊 夌阑锭 辑滚俊 舅覆
			//林)	货肺 甸绢柯 蜡历绰 捞 矫痢何磐 盲泼, 蜡历盎脚沥焊 殿 霸烙俊辑 惯积窍绰 皋矫瘤甫 罐阑 荐 乐促
			
			for(int i = 0 ; i < 16 ; i++)		// 蜡廉 肺爹阑 檬扁拳 茄促..
				m_MyGameUserEx[i].bLoading = false;
			
			void* ioc = net_message(M_GAMESERVER, CGS_GAME_IN);
			if(ioc)
			{
				net_send(g_pNet->g_sockindex[M_GAMESERVER], ioc);

				OutputDebugString("\n CGS_GAME_IN [M_GAMESERVER]");
			}
		}
		break;
	default:
		break;
	}

//	m_cpScene->SetScene( nScene );
//	m_cpScene->LoadScene();
}

BOOL CMCGApp::CreateSocket()
{
#ifdef _NETCONN
	new CMCGNet();
	if( g_pNet == NULL )
	{
		MessageBox( NULL, "Create Socket Error", "Error", IDOK );
		return FALSE;
	}

#ifdef _TESTSERVER
	if(!g_pNet->Connect("192.168.0.5",25350))
		return FALSE;
#else
	if(!g_pNet->Connect(m_strServerIp, GetPrivateProfileInt("SYSTEM", "SERVERPORT", 11001, BSINIT)))
		return FALSE;
#endif

#endif	
    return TRUE;
}

INT CMCGApp::Render()
{
	if(m_cpScene) m_cpScene->render();

	Skip_Lobby_Step();
	
	return 0;
}

void CMCGApp::Skip_Lobby_Step()
{
	void *ioc;
	if(m_bSkipLobby == 1)
	{
		g_pApp->m_pItemManager = new CItemManager;
		g_pApp->m_pItemManager->LoadItem("data\\Text\\weapon.ite");
		g_pApp->m_pItemManager->LoadItem("data\\Text\\assist.ite");
		g_pApp->m_pItemManager->LoadItem("data\\Text\\mechanic.ite");

		ioc = net_message(M_MASTERSERVER, CMS_SERVER_SELECT);
		if(ioc)
		{
			short SelectServerIndex = 0;
			net_packet(ioc, &SelectServerIndex, 1);
			g_pNet->g_SelectServerIndex = SelectServerIndex;
			
			net_send(g_pNet->g_sockindex[M_MASTERSERVER], ioc);
			
			m_bSkipLobby = 0;
		}
	}
	if(m_bSkipLobby == 2)
	{
		ioc = net_message(M_LOBBYSERVER, CLS_CHANNEL_SELECT);
		if(ioc)
		{
			short SelectChannelIndex = 0;
			net_packet(ioc, &SelectChannelIndex, 1);
			g_pNet->g_SelectChannelIndex = SelectChannelIndex;
			
			net_send(g_pNet->g_sockindex[M_LOBBYSERVER], ioc);

			m_bSkipLobby = 0;
		}
	}

	if(m_bSkipLobby == 3)
	{
		ioc = net_message(M_LOBBYSERVER, CLS_LOBBY_IN);
		if(ioc)
		{
			net_send(g_pNet->g_sockindex[M_LOBBYSERVER], ioc);
			
			m_bSkipLobby = 0;
		}
	}
	
	if(m_bSkipLobby == 4 || m_bSkipLobby == 5)
	{
		//老窜 狞 炼牢阑 夸没茄促.
		BYTE game_mode = MODE_SURVIVAL;				//霸烙葛靛(enum:GAME_MODE 曼炼)
		
		void *pIoc = net_message(M_LOBBYSERVER, CLS_ROOM_QUICK);
		if(pIoc)
		{
			net_packet(pIoc, &game_mode,1);
			net_send(g_pNet->g_sockindex[M_LOBBYSERVER], pIoc);
			m_bSkipLobby = 0;

			OutputDebugString("\n 肺厚胶诺 冯狞辑厚胶");
		}
	}

	//狞炼牢阑 夸没沁绰单 规捞 绝栏搁. 规阑 父电促.
	if(m_bSkipLobby == 6)
	{
		char pName[32+1];
		bool rock = false;
		char maxuser = 0;
		BYTE game_mode = MODE_DEATH;
		BYTE repair_cnt = 0;
		BYTE map_type = 0;
		DWORD play_time = 0;
		BYTE len = 0;					//厚锅辨捞(0捞搁 傍俺规)
		char password[5]={NULL,};			//厚锅
	
		strcpy(pName , "肺厚胶诺捞寸.");
		game_mode = MODE_SURVIVAL;
		repair_cnt = 15;
		maxuser = 16;
		play_time = 5 * 60 * 1000;
		map_type = 0;
		
		void * pIoc = net_message(M_LOBBYSERVER, CLS_ROOM_CREATE);
		if(pIoc)
		{
			net_packet(pIoc,&maxuser, 1);
			net_packet(pIoc,&game_mode,1);
			net_packet(pIoc,&repair_cnt, 1);							
			net_packet(pIoc,&map_type ,1 );
			net_packet(pIoc,&play_time ,1 );
			net_packet(pIoc,pName, 33 );
			net_packet(pIoc,&len ,1 );		//菩胶况靛 涝仿等 辨捞甫 拌魂茄促.
			//	net_packet(pIoc,password,5);
			
			net_send(g_pNet->g_sockindex[M_LOBBYSERVER], pIoc);
			
			//OutputDebugString()
		}
		
		m_bSkipLobby = 0;
	}
	
	if(m_bSkipLobby == 7)
	{
		void *pIoc = net_message(M_LOBBYSERVER, CLS_GAME_READY);
		if(pIoc)
		{
			char mechanic_garageindex = 0;	//磊脚狼 皋墨葱 侥喊 牢郸胶
			
			net_packet(pIoc, &mechanic_garageindex, 1);
			net_send(g_pNet->g_sockindex[M_LOBBYSERVER], pIoc);
			
		}
		m_bSkipLobby = 0;
	}
}
	
LRESULT CMCGApp::GameProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	if(!GetAppActive())
		return DefWindowProc( hWnd, msg, wParam, lParam );
	if(!m_cpScene) return DefWindowProc( hWnd, msg, wParam, lParam );
	switch( msg )
	{
	case WM_MOUSEMOVE:
		m_cpScene->OnMouseMove(LOWORD(lParam),HIWORD(lParam),msg);
		break;
	case WM_LBUTTONDBLCLK:
			m_cpScene->OnLButtonDClick(true,LOWORD(lParam),HIWORD(lParam),msg);
			break;
        case WM_LBUTTONDOWN:
			m_cpScene->OnLButtonDown(false,LOWORD(lParam),HIWORD(lParam),msg);
			break;
		case WM_LBUTTONUP:
			m_cpScene->OnLButtonUp(LOWORD(lParam),HIWORD(lParam),msg);
			break;
	    case WM_RBUTTONDOWN:
			m_cpScene->OnRButtonDown(false,LOWORD(lParam),HIWORD(lParam),msg);
			break;
		case WM_RBUTTONUP:
			m_cpScene->OnRButtonUp(LOWORD(lParam),HIWORD(lParam),msg);
			break;
		case WM_MOUSEWHEEL:
			m_cpScene->OnMouseWheel(LOWORD(lParam),HIWORD(lParam),msg);
			break;

        case WM_KEYDOWN:
			{
				switch(wParam)
				{
				case VK_ESCAPE:
					{
						if(m_cpScene->GetScene() != SCENE_3DGAME )
						{
							InvalidateDeviceObjects();
							DeleteDeviceObjects();
							FinalCleanup();
							PostQuitMessage(0);
						}
					}
					break;
				case VK_F5:
					{
						
					}
					break;

				}
				m_cpScene->OnKeyDown((int) wParam,0,0,lParam);
			}
			break;
		case WM_KEYUP:
			m_cpScene->OnKeyUp((int) wParam,0,0,lParam);
			break;
	} 	

	if(m_cpScene != NULL)
	{
		return m_cpScene->SceneProc(hWnd, msg, wParam, lParam );
	}
	else
	{
		return DefWindowProc( hWnd, msg, wParam, lParam );
	}
}

LRESULT CALLBACK StaticMsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	g_pApp->MsgProc( hWnd, uMsg, wParam, lParam );
	return g_pApp->GameProc( hWnd, uMsg, wParam, lParam );
}

⌨️ 快捷键说明

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