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

📄 mhclient.cpp

📁 墨香最新私服
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// test.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include <crtdbg.h>

#include "MainGame.h"
#include "WindowIDEnum.h"
#include "./Interface/cWindowManager.h"
#include "cMsgBox.h"

#include "./Input/UserInput.h"
#include "./Input/cIMEWnd.h"

#include "ChatManager.h"
#include "../[CC]Header/GameResourceManager.h"
#include "MouseCursor.h"

#include "mhFile.h"

#include "OptionManager.h"
#include "MHAudioManager.h"
#include "ObjectManager.h"
#include "MHMap.h"

#include "ExitManager.h"
#include "QuestManager.h"

#include "ServerConnect.h"
#include <vfw.h>

#ifdef _GMTOOL_
#include "GMToolManager.h"
#include "CommCtrl.h"
#endif

#ifdef TAIWAN_LOCAL
#include <shellapi.h>
#endif

#define _LOGOWINDOW_

//////////////////////////////////////////////////////////////////////////
// Version ½ÇÇàÆÄÀÏ ¹öÁ¯
// ÀÌ°É ¹Ù²Ù¸é ¼­¹öÅø(¸ð´ÏÅ͸µÅø)¿¡¼­µµ ¹öÁ¯À» ¹Ù²ãÁà¾ßÇÑ´Ù.
/////////////////////////////////////////////////////////////////////////

//#define _MANUALPATCH_
char g_CLIENTVERSION[256] = "TEST05010401";

/////////////////////////////////////////////////////////////////////////	

#define MAX_LOADSTRING 100

// Global Variables:
HANDLE g_hMap = NULL;
HINSTANCE g_hInst;								// current instance
HWND _g_hWnd;
TCHAR szTitle[MAX_LOADSTRING];								// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];								// The title bar text
BOOL g_bActiveApp = FALSE;
char g_DistributeAddr[16];
WORD g_DistributePort;
char g_AgentAddr[16];
WORD g_AgentPort;
char g_PATCHVERSION[256];
char g_szHeroIDName[17];

///for test //KES
//DEVMODE g_CurDisplayMode;
//DEVMODE g_GameDisplayMode;
//BOOL	g_bWindowMode = FALSE;
/////

// Foward declarations of functions included in this code module:
ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About(HWND, UINT, WPARAM, LPARAM);
void LeaveClientApplication();
BOOL EnterClientApplication();

//BOOL CheckParameter(LPSTR parameter);
BOOL	GetPatchVersion();
BOOL	CheckResourceFile();
void	ChangeVerInfo();
BOOL	SaveFileList();

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	CTargetList ss;
	CTargetListIterator iter;
	iter.Init(&ss);
	iter.Release();

	FILE* fp = NULL;
#ifdef _SEMIRELEASE
	if( strcmp( lpCmdLine, "anrgideoqkr" ) != 0 
#ifdef _MANUALPATCH_
		&& strcmp( lpCmdLine, "anrgiddlatl" ) != 0 
#endif
		)
	{
		MessageBox( NULL, "You should not execute directly this file!!", "Error!!", MB_OK );
		return 0;
	}
	
	fp = fopen("mht.dll","r");
	if( fp )
		fclose(fp);
	else
	{
		if( !CheckResourceFile() )
		{
			ChangeVerInfo();
			MessageBox( NULL, "Your version of files is not valid!!\nTry to reconnect!!", "Error!!", MB_OK );
			return 0;
		}
	}
#endif

	if(!EnterClientApplication()) return 0;

	DeleteFile("Debug.txt");		//debugAI¡ËO¢®¡¿¡Ë¡þ¡Ë¡þ?

	LOGFILE("///////////////////////////////////////////////////////");
	LOGFILE("///////////////////  Client Start  ////////////////////");
	LOGFILE("///////////////////////////////////////////////////////");
	
	//_CrtSetBreakAlloc(2940);
 	// TODO: Place code here.
	//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_DELAY_FREE_MEM_DF);
	//_CrtMemDumpAllObjectsSince(0);
	
	fp = fopen("../DeveloperWorking/_DONOTUSEENGINEPACK","r");
	if(fp)
	{
		g_bUsingEnginePack = FALSE;
		fclose(fp);
	}
 
	// Initialize global strings
	GetPatchVersion();
#ifdef _TESTCLIENT_
	sprintf(szTitle,"DarkStory(TEST) %s %s ExeVer:%s PatchVer:%s",__DATE__,__TIME__,g_CLIENTVERSION,g_PATCHVERSION);
	sprintf(szWindowClass,"DarkStory(TEST) %s %s ExeVer:%s PatchVer:%s",__DATE__,__TIME__, g_CLIENTVERSION,g_PATCHVERSION);
#elif _GMTOOL_
	sprintf(szTitle,"DarkStory[GM_TOOL] %s %s ExeVer:%s PatchVer:%s",__DATE__,__TIME__,g_CLIENTVERSION,g_PATCHVERSION);
	sprintf(szWindowClass,"DarkStory[GM_TOOL] %s %s ExeVer:%s PatchVer:%s",__DATE__,__TIME__, g_CLIENTVERSION,g_PATCHVERSION);
#else
	sprintf(szTitle,"DarkStoryOnline %s %s ExeVer:%s PatchVer:%s",__DATE__,__TIME__,g_CLIENTVERSION,g_PATCHVERSION);
	sprintf(szWindowClass,"DarkStoryOnline %s %s ExeVer:%s PatchVer:%s",__DATE__,__TIME__,g_CLIENTVERSION,g_PATCHVERSION);
#endif
	MyRegisterClass(hInstance);
	//LOGEX(lpCmdLine, PT_MESSAGEBOX);


	GAMERESRCMNGR->LoadGameDesc();
	GAMERESRCMNGR->LoadDeveloperInfo();
	// quest data load
	QUESTMGR->LoadQuestString( "./Quest/QuestString.bin" );
	QUESTMGR->LoadQuestScript( "./Quest/QuestScript.bin" );
	QUESTMGR->LoadNewbieGuide( "./Quest/NewbieGuide.bin" );
	QUESTMGR->LoadQuestNpc( "./Quest/QuestNpcList.bin" );
	//

//for test	//KES
//	EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &g_CurDisplayMode );
//	g_GameDisplayMode = g_CurDisplayMode;
//	g_GameDisplayMode.dmBitsPerPel	= GAMERESRCMNGR->m_GameDesc.dispInfo.dwBPS*8;
//	g_GameDisplayMode.dmPelsWidth	= GAMERESRCMNGR->m_GameDesc.dispInfo.dwWidth;
//	g_GameDisplayMode.dmPelsHeight	= GAMERESRCMNGR->m_GameDesc.dispInfo.dwHeight;
//	g_bWindowMode	= GAMERESRCMNGR->m_GameDesc.dispInfo.bWindowed;

//	g_CurDisplayMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
//	g_GameDisplayMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
///////////////

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		LeaveClientApplication();
		return FALSE;
	}
	
//	HACCEL hAccelTable;
//	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST);

	// Main message loop:
	MSG msg;
	while (1) //GetMessage(&msg, NULL, NULL, NULL));
    {
		if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
//			if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
//			{
#ifdef _GMTOOL_
			if( !GMTOOLMGR->IsGMDialogMessage(&msg) )
#endif
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg); 
			}
//			}
		}
		else
		{
			if(MAINGAME->Process() == -1)
				break;
		}
	}

	DeleteFile("recv.txt");

	LeaveClientApplication();

//	_ASSERTE( _CrtCheckMemory( ) );

//#ifdef TAIWAN_LOCAL
//	ShellExecute( NULL, NULL, "Iexplore.exe", "http://www.moxiang.com.cn", NULL, SW_SHOWNORMAL );
//#endif

	return msg.wParam;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 
#ifdef _SEMIRELEASE
	wcex.style			= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_NOCLOSE;
#else
	wcex.style			= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
#endif
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
//	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_TEST);
//	wcex.hIcon			= NULL;
	wcex.hIcon			= LoadIcon( hInstance, MAKEINTRESOURCE(IDI_GAMEICON) );

	wcex.hCursor		= NULL;
//	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= szWindowClass;
//	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
	wcex.hIconSm		= NULL;

	return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	//if(!EnterClientApplication()) return FALSE;	//A¨Ï©ª=8¢®¢´I ¡Ë?A¢®¨¡a¡Ë¡ÍU. //KES

	CURSOR->Init( hInstance );
	
	HWND hWnd;
	g_hInst = hInstance; // Store instance handle in our global variable
	int x = GetSystemMetrics(SM_CXSIZEFRAME)*2;
	int y = GetSystemMetrics(SM_CYSIZEFRAME)*2+GetSystemMetrics(SM_CYCAPTION);
//#ifdef _GMTOOL_
//	y += GetSystemMetrics(SM_CYMENU);
//#endif
#ifdef _SEMIRELEASE
	DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION |
		WS_SYSMENU | WS_THICKFRAME;
#else
	DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION |
		WS_SYSMENU |
		WS_THICKFRAME | WS_MINIMIZEBOX;
#endif
	_g_hWnd = hWnd = CreateWindow(szWindowClass, szTitle, dwStyle, //WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, 0, 1024+x, 768+y, NULL, NULL, hInstance, NULL);
	
	if (!hWnd)
	{
		return FALSE;
	}
	
//	gMp3 = new CBGMLoader(hInstance,hWnd);

	ShowWindow(hWnd, nCmdShow);
	
//	if( g_bWindowMode )
//		ShowWindow(hWnd, nCmdShow);
//	else
//		ShowWindow(hWnd, SW_HIDE);

	UpdateWindow(hWnd);
	ShowCursor(TRUE);

	CoInitialize(NULL);

#ifndef _LOGOWINDOW_
	PlayCutscene("logo.avi",g_hInst);
#endif

	//////////////////////////////////////////////////////////////////////////
	// MAININIT
	MAINGAME->Init(hWnd);
		
#ifndef _TESTCLIENT_
	MAINGAME->SetGameState(eGAMESTATE_CONNECT);
#else
	int initKind = eGameInInitKind_Login;
	MAINGAME->SetGameState(eGAMESTATE_GAMEIN,&initKind,sizeof(int));
#endif                 

#ifdef _GMTOOL_
		GMTOOLMGR->CreateGMDialog();
#endif
	
	
	return TRUE;
}



LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	MOUSE->GetWindowMessage(hWnd, message, wParam, lParam);
	CHATMGR->MsgProc( message, wParam );//¨ÏoY¡Íia¡§oA CIMEWND->OnMsg()¡§¡þ¡Ë¡þ¡Ë¡ÍU ¡Ë¡þOAu ¡§oCCa¡ÍiC¡§ui¡§u¨Ï¡þCN¡Ë¡ÍU. A¡Ë¢¥¡§¢®A¡Ë?¡Ë¢ç¡Íi¨Ï¡Ì¡§¢®¡Ëc¨ÏoU¡§i©ö¡Ëi¨ù¡Ë?¡Ë¢ç ¡§¢®¢®AA¡Ë?¡§i©ö¡Ëi¨ù¡Ë¡þ| ¡Ë¡þOAu AO¢®¨úa 'C¡§¨£¡§u¢®¨Ï.
	CIMEWND->OnMsg(hWnd, message, wParam, lParam);
	
	switch (message) 
	{
	case WM_CHAR:
	case WM_IME_CHAR:
//	case WM_IME_COMPOSITION:
#ifndef TAIWAN_LOCAL
	case WM_IME_STARTCOMPOSITION:
#endif
		{
			return 0;
		}

	case WM_ACTIVATEAPP:
		{
			g_bActiveApp = (BOOL)wParam;

			if( !g_bActiveApp )
			{
				AUDIOMGR->StopAll();
				AUDIOMGR->StopBGM();

#ifdef _GMTOOL_
				
				
#endif

	//KES T_T ¡§uE¡ÍiC¨Ï©ª¢®¢¯.
	//			if( !g_bWindowMode )
	//			{
	//				ShowWindow( _g_hWnd, SW_MINIMIZE );
	//				MAP->Invalidate();
	//				ChangeDisplaySettings( &g_CurDisplayMode, 0 );
	//			}
			}
			else
			{
				if( OPTIONMGR->GetGameOption()->bSoundBGM )
					AUDIOMGR->PlayLastBGM();

#ifdef _GMTOOL_
				
#endif

	//			if( !g_bWindowMode )
	//			{
	//				ShowWindow( _g_hWnd, SW_NORMAL );				
	//				ChangeDisplaySettings( &g_GameDisplayMode, 0 );				
	//			}
			}
		}
		break;

	case WM_ACTIVATE:
		
		if( g_UserInput.GetKeyboard()->GetDirectInput() )
		{
			if( WA_INACTIVE != wParam )
			{
				// Make sure the device is acquired, if we are gaining focus.
				g_UserInput.GetKeyboard()->ClearKeyState();
				g_UserInput.GetKeyboard()->UpdateKeyboardState();
				//g_UserInput.SetInputFocus( TRUE );
				OBJECTMGR->SetAllNameShow( FALSE );
			}
//			else
//			{
				//g_UserInput.SetInputFocus( FALSE );
//			}
		}
		break;

	case WM_USER+155:
		{
			ISC_BaseNetwork* lpNet = NETWORK->GetBaseNetwork();
			if(lpNet)
				lpNet->SocketEventProc();
		}
		return TRUE;		
		
	case WM_CLOSE:

		MAINGAME->SetGameState( eGAMESTATE_END );
/*
		if( MAINGAME->GetCurStateNum() == eGAMESTATE_TITLE )
		{
			MAINGAME->SetGameState( eGAMESTATE_END );
			break;		// ¢®¨¡OAO E¡ËcAI ¡§uE¢®¨¡i ~¢®¢´a
		}

⌨️ 快捷键说明

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