Пример #1
0
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 );
}
Пример #2
0
void CModManager::InitializeModList ( const char* szModFolderPath )
{
    // Variables used to search the mod directory
    WIN32_FIND_DATAA FindData;
    HANDLE hFind;

    // Allocate a string with length of path + 5 letters to store searchpath plus "\*.*"
    SString strPathWildchars ( "%s*.*", szModFolderPath );

    // Set the working directory to the MTA folder
    CFilePathTranslator filePathTranslator;
    filePathTranslator.SetCurrentWorkingDirectory ( "mta" );

    // Create a search
    hFind = FindFirstFile ( strPathWildchars, &FindData );

    // If we found a first file ...
    if ( hFind != INVALID_HANDLE_VALUE )
    {
        // Add it to the list
        VerifyAndAddEntry ( szModFolderPath, FindData.cFileName );

        // Search until there aren't any files left
        while ( FindNextFile ( hFind, &FindData ) == TRUE )
        {
            VerifyAndAddEntry ( szModFolderPath, FindData.cFileName );
        }

        // End the search
        FindClose ( hFind );
    }

    // Reset the working directory
    filePathTranslator.UnSetCurrentWorkingDirectory ();
}
Пример #3
0
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 );
}
Пример #4
0
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 );
}
Пример #5
0
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 ( );
}
Пример #6
0
int WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, PVOID pvNothing)
{
    CFilePathTranslator     FileTranslator;
    std::string             WorkingDirectory;

    if ( dwReason == DLL_PROCESS_ATTACH )
    {
        WriteDebugEvent( SString( "DLL_PROCESS_ATTACH %08x", pvNothing ) );
        if ( IsGTAProcess() )
        {
            WriteDebugEvent( SString( "ModuleFileName: %s", *GetLaunchPathFilename() ) );

            AddUtf8FileHooks();

            // Set low frag heap for XP
            ULONG heapInfo = 2 ;
            HeapSetInformation( GetProcessHeap(), HeapCompatibilityInformation, &heapInfo, sizeof( heapInfo ) );

            FileTranslator.GetGTARootDirectory ( 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( CalcMTASAPath ( "MTA" ) );

            g_pCore = new CCore;

            FileTranslator.GetGTARootDirectory ( WorkingDirectory );
            SetCurrentDirectory ( WorkingDirectory.c_str ( ) );
        }
    } 
    else if (dwReason == DLL_PROCESS_DETACH)
    {
        WriteDebugEvent( SString( "DLL_PROCESS_DETACH %08x", pvNothing ) );
        if ( IsGTAProcess () )
        {
            RemoveUtf8FileHooks();

            AddReportLog( 7102, "Core - 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;
}
Пример #7
0
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 );
}
Пример #8
0
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 );
}
Пример #9
0
int WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, PVOID pvNothing)
{
    CFilePathTranslator     FileTranslator;
    std::string             WorkingDirectory;

    if ( dwReason == DLL_PROCESS_ATTACH )
    {
        WriteDebugEvent( SString( "DLL_PROCESS_ATTACH %08x", pvNothing ) );
        if ( IsRealDeal () )
        {
            FileTranslator.GetGTARootDirectory ( 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( CalcMTASAPath ( "MTA" ) );

            g_pCore = new CCore;

            FileTranslator.GetGTARootDirectory ( WorkingDirectory );
            SetCurrentDirectory ( WorkingDirectory.c_str ( ) );
        }
    } 
    else if (dwReason == DLL_PROCESS_DETACH)
    {
        WriteDebugEvent( SString( "DLL_PROCESS_DETACH %08x", pvNothing ) );
        if ( IsRealDeal () )
        {
            // 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;
}
Пример #10
0
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!" );
    }
}
Пример #11
0
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() );
}