Пример #1
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;
}
    BOOL
    WINAPI
    MySetCurrentDirectoryA(
        __in LPCSTR lpPathName
        )
    {
        SString strPathName = lpPathName;
#ifdef MTA_CLIENT
        if ( IsGTAProcess() )
            strPathName = MakeSurePathIsUTF8( strPathName );
#endif
        return SetCurrentDirectoryW( FromUTF8( strPathName ) );
    }
    BOOL
    WINAPI
    MyCreateDirectoryA(
        __in     LPCSTR lpPathName,
        __in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes
        )
    {
        SString strPathName = lpPathName;
#ifdef MTA_CLIENT
        if ( IsGTAProcess() )
            strPathName = MakeSurePathIsUTF8( strPathName );
#endif
        return CreateDirectoryW( FromUTF8( strPathName ), lpSecurityAttributes );
    }