void CCore::CreateGUI ( void ) { // Should only be called once, use InitGUI to init the GUI, which can be called again (after a destruction of the GUI) CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; bool bReturn = false; // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); #ifdef MTA_DEBUG bReturn = m_GUIModule.LoadModule ( "cgui_d.dll" ); #else bReturn = m_GUIModule.LoadModule ( "cgui.dll" ); #endif if ( !bReturn ) { // USE CLANGUAGELOCALE HERE. MessageBox ( 0, "GUI module could not be located!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } WriteDebugEvent ( "GUI loaded." ); SetCurrentDirectory ( szCurDir ); }
void CCore::ShowMessageBox ( const char* szTitle, const char* szText, unsigned int uiFlags, GUI_CALLBACK * ResponseHandler ) { CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; if ( m_pMessageBox ) delete m_pMessageBox; // Set the current directory to the MTA dir so we can load files using a relative path FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // Create the message box m_pMessageBox = m_pGUI->CreateMessageBox ( szTitle, szText, uiFlags ); if ( ResponseHandler ) m_pMessageBox->SetClickHandler ( *ResponseHandler ); // Restore current directory SetCurrentDirectory ( szCurDir ); // Make sure it doesn't auto-destroy, or we'll crash if the msgbox had buttons and the user clicks OK m_pMessageBox->SetAutoDestroy ( false ); }
void CCore::CreateNetwork ( ) { // Create function pointer type and variable. typedef CNet* (*pfnNetInitializer) ( ); pfnNetInitializer pfnNetInit; CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // Load approrpiate compilation-specific library. #ifdef _DEBUG m_NetModule.LoadModule ( "net_d.dll" ); #else m_NetModule.LoadModule ( "net.dll" ); #endif if ( m_NetModule.IsOk () == false ) { MessageBox ( 0, "Network module not found!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } // Network module compatibility check typedef unsigned long (*PFNCHECKCOMPATIBILITY) ( unsigned long ); PFNCHECKCOMPATIBILITY pfnCheckCompatibility = static_cast< PFNCHECKCOMPATIBILITY > ( m_NetModule.GetFunctionPointer ( "CheckCompatibility" ) ); if ( !pfnCheckCompatibility || !pfnCheckCompatibility ( MTA_DM_CLIENT_NET_MODULE_VERSION ) ) { // net.dll doesn't like our version number MessageBox ( 0, "Network module not compatible!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } // Get client initializer function from DLL's routine. pfnNetInit = static_cast< pfnNetInitializer > ( m_NetModule.GetFunctionPointer ( "InitNetInterface" ) ); // If we have a valid initializer, call it. if ( pfnNetInit != NULL ) { WriteDebugEvent ( "Network loaded." ); m_pNet = pfnNetInit ( ); } else { // USE CLANGUAGELOCALE HERE. MessageBox ( 0, "Network module could not be located!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } SetCurrentDirectory ( szCurDir ); }
void CCore::CreateXML ( ) { // Create function pointer type and variable. typedef CXML* (*pfnXMLInitializer) ( ); pfnXMLInitializer pfnXMLInit; CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // Load approrpiate compilation-specific library. #ifdef MTA_DEBUG m_XMLModule.LoadModule ( "xmll_d.dll" ); #else m_XMLModule.LoadModule ( "xmll.dll" ); #endif // Get client initializer function from DLL's routine. pfnXMLInit = static_cast< pfnXMLInitializer > ( m_XMLModule.GetFunctionPointer ( "InitXMLInterface" ) ); // If we have a valid initializer, call it. if ( pfnXMLInit != NULL ) { WriteDebugEvent ( "XML loaded." ); m_pXML = pfnXMLInit ( ); } else { // USE CLANGUAGELOCALE HERE. MessageBox ( 0, "XML module could not be located!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } SetCurrentDirectory ( szCurDir ); // Load config XML file m_pConfigFile = m_pXML->CreateXML ( CalcMTASAPath ( MTA_CONFIG_PATH ) ); if ( !m_pConfigFile ) { assert ( false ); return; } m_pConfigFile->Parse (); // Load the keybinds (loads defaults if the subnode doesn't exist) GetKeyBinds ()->LoadFromXML ( GetConfig ()->FindSubNode ( CONFIG_NODE_KEYBINDS ) ); // Load XML-dependant subsystems m_ClientVariables.Load ( ); }
void CLocalGUI::CreateWindows ( void ) { CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); CGUI* pGUI = CCore::GetSingleton ().GetGUI (); // Create chatbox m_pChat = new CChat ( pGUI, CVector2D ( 0.0125f, 0.015f ) ); m_pChat->SetVisible ( false ); // Create the debug view m_pDebugView = new CDebugView ( pGUI, CVector2D ( 0.23f, 0.785f ) ); m_pDebugView->SetVisible ( false ); // Create the overlayed version labels CVector2D ScreenSize = pGUI->GetResolution (); m_pLabelVersionTag = reinterpret_cast < CGUILabel* > ( pGUI->CreateLabel ( "MTA:SA " MTA_DM_BUILDTAG_SHORT ) ); m_pLabelVersionTag->SetSize ( CVector2D ( m_pLabelVersionTag->GetTextExtent() + 5, 18 ) ); m_pLabelVersionTag->SetPosition ( CVector2D ( ScreenSize.fX - m_pLabelVersionTag->GetTextExtent() - 5, ScreenSize.fY - 15 ) ); m_pLabelVersionTag->SetAlpha ( 0.5f ); m_pLabelVersionTag->SetTextColor ( 255, 255, 255 ); m_pLabelVersionTag->SetZOrderingEnabled ( false ); m_pLabelVersionTag->MoveToBack (); m_pLabelVersionTag->SetVisible ( false ); // Create mainmenu m_pMainMenu = new CMainMenu ( pGUI ); m_pMainMenu->SetVisible ( false ); // Create console m_pConsole = new CConsole ( pGUI ); m_pConsole->SetVisible ( false ); // Create community registration window m_CommunityRegistration.CreateWindows (); m_CommunityRegistration.SetVisible ( false ); // Return the old current dir. SetCurrentDirectory ( szCurDir ); }
void CLocalGUI::CreateObjects ( IUnknown* pDevice ) { //Temps CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; // Store the GUI manager pointer and create the GUI classes CGUI* pGUI = CCore::GetSingleton ().GetGUI (); // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // Create graphical wrapper object. WriteDebugEvent ( "Creating renderer wrapper..." ); m_pRendererLibrary = new CD3DMGEng ( reinterpret_cast < LPDIRECT3DDEVICE9 > ( pDevice ) ); // And lot it's fonts WriteDebugEvent ( "Loading font texture..." ); if ( m_pRendererLibrary->LoadFontTextureFromFile ( "cgui\\sans.tga" ) ) { WriteDebugEvent ( "Font texture load successful!" ); } else { WriteDebugEvent ( "Font texture load failure!" ); } if ( m_pRendererLibrary->LoadFontInfoFromFile ( "cgui\\sans.dat" ) ) { WriteDebugEvent ( "Font data load successful!" ); } else { WriteDebugEvent ( "Font data load failure!" ); } CreateWindows (); // Return the old current dir. SetCurrentDirectory ( szCurDir ); }
void CLocalGUI::Restore ( void ) { CGUI* pGUI = CCore::GetSingleton ().GetGUI (); if ( pGUI ) { CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; // We must change the current directory here! // This is necessary because if we don't, CLocalGUI will try to load // files from the wrong path! // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // Restore the GUI pGUI->Restore (); // Restore our renderer. if ( m_pRendererLibrary ) { m_pRendererLibrary->OnRestoreDevice ( ); } else { WriteDebugEvent ( "WARNING: CLocalGUI::Restore() called, but CLocalGUI::CreateObjects() isn't!" ); } // Restore the current directory to default. SetCurrentDirectory ( szCurDir ); } else { WriteDebugEvent ( "WARNING: CLocalGUI::Restore() called, but CLocalGUI::CreateObjects() isn't!" ); } }
void CCore::InitGUI ( IUnknown* pDevice ) { // Initializes the GUI by calling the InitGUIInterface-function in the GUI dll CFilePathTranslator FileTranslator; string WorkingDirectory; char szCurDir [ 1024 ]; bool bReturn = false; // Set the current directory. FileTranslator.SetCurrentWorkingDirectory ( "MTA" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); GetCurrentDirectory ( sizeof ( szCurDir ), szCurDir ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); typedef CGUI* (*pfnGUIInitializer) ( IDirect3DDevice9* ); pfnGUIInitializer pfnGUIInit; pfnGUIInit = static_cast < pfnGUIInitializer > ( m_GUIModule.GetFunctionPointer ( "InitGUIInterface" ) ); if ( pfnGUIInit != NULL ) { IDirect3DDevice9 *dev = reinterpret_cast < IDirect3DDevice9* > ( pDevice ); m_pGUI = pfnGUIInit ( dev ); WriteDebugEvent ( "GUI initialized." ); } else { // USE CLANGUAGELOCALE HERE. MessageBox ( 0, "GUI module could not be initialized!", "Error", MB_OK|MB_ICONEXCLAMATION ); TerminateProcess ( GetCurrentProcess (), 0 ); } // Set the working directory for CGUI m_pGUI->SetWorkingDirectory ( WorkingDirectory.c_str ( ) ); SetCurrentDirectory ( szCurDir ); // and set the screenshot path to this default library (screenshots shouldnt really be made outside mods) std::string strScreenShotPath = GetInstallRoot () + std::string ( "\\screenshots" ); CVARS_SET ( "screenshot_path", strScreenShotPath ); CScreenShot::SetPath ( strScreenShotPath.c_str() ); }
int WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, PVOID pvNothing) { CFilePathTranslator FileTranslator; string WorkingDirectory; if ( dwReason == DLL_PROCESS_ATTACH ) { FileTranslator.SetCurrentWorkingDirectory ( "mta" ); FileTranslator.GetCurrentWorkingDirectory ( WorkingDirectory ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); // For dll searches, this call replaces the current directory entry and turns off 'SafeDllSearchMode' // Meaning it will search the supplied path before the system and windows directory. // http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx SetDllDirectory( WorkingDirectory.c_str ( ) ); g_pCore = new CCore; FileTranslator.GetGTARootDirectory ( WorkingDirectory ); SetCurrentDirectory ( WorkingDirectory.c_str ( ) ); } else if (dwReason == DLL_PROCESS_DETACH) { // For now, TerminateProcess if any destruction is attempted (or we'll crash) TerminateProcess ( GetCurrentProcess (), 0 ); if ( g_pCore ) { delete g_pCore; g_pCore = NULL; } } return TRUE; }