示例#1
0
///////////////////////////////////////////////////////////////
//
// CNetBufferWatchDog::CheckActionHistory
//
// Thread:                  check
// Mutex should be locked:  yes
//
///////////////////////////////////////////////////////////////
void CNetBufferWatchDog::CheckActionHistory ( CActionHistory& history, const char* szTag, uint& uiHigh )
{
    if ( history.bChanged )
    {
        history.bChanged = false;
        history.uiLastChangedTime = GetTickCount32 ();
    }

    if ( !history.uiLastChangedTime )
        return;

    uint uiAge = GetTickCount32 () - history.uiLastChangedTime;
    if ( uiAge < 1000 * 5 )
        uiHigh = 10;

    bool bShowMessage = false;
    if ( uiAge > 1000 * uiHigh )
    {
        uiHigh = uiHigh + 10;
        bShowMessage = true;
    }

    if ( bShowMessage )
    {
        if ( ms_bVerboseDebug )
            CLogger::LogPrintf ( "INFO: %s thread last action age: %d ticks.\n"
                                        , szTag
                                        , uiAge
                                    );
    }
}
示例#2
0
void CMainMenu::SetIsIngame(bool bIsIngame)
{
    // Save some performance by making sure we don't do all this if the new state == old
    if (m_bIsIngame != bIsIngame)
    {
        m_bIsIngame = bIsIngame;
        m_Settings.SetIsModLoaded(bIsIngame);

        m_ulMoveStartTick = GetTickCount32();
        if (bIsIngame)
        {
            m_iMoveTargetPos = m_iSecondItemCentre;
        }
        else
        {
            if (m_menuItems.front() == m_pDisconnect)
                m_menuItems.pop_front();

            float fTopItemSize = m_menuItems.front()->image->GetSize(false).fY;
            float fTopItemCentre = m_menuItems.front()->image->GetPosition(false).fY + fTopItemSize * 0.5f;
            m_menuAY = fTopItemCentre - fTopItemSize * (CORE_MTA_HOVER_SCALE / CORE_MTA_NORMAL_SCALE) * 0.5f;
            m_menuAY += BODGE_FACTOR_1;

            m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
            m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
            m_iMoveTargetPos = m_iFirstItemCentre;
        }
        m_iMoveStartPos = m_menuAY;
    }
}
示例#3
0
CSerialVerification::CSerialVerification ( CPlayer* pPlayer, SERIALVERIFICATIONCALLBACK pCallBack )
{
    char buf[32] = {0};
    CLogger::LogPrintf ( "VERIFY: Querying %s\n", SERIAL_VERIFICATION_SERVER );

    m_pCallBack = pCallBack;
    m_pPlayer = pPlayer;
    m_ulStartTime = GetTickCount32();
    m_bFinished = false;

    if ( pPlayer->GetSerialUser().length() > 0 && pPlayer->GetSerial().length() > 0 )
    {
        // Create the POST URL
        std::string strPostData = "[\"" + pPlayer->GetSerialUser () +
                                  "\",\"" + pPlayer->GetSerial () +
                                  "\"," + itoa ( g_pGame->GetConfig ()->GetServerPort (), buf, 10 ) + "]";

        // Use CURL to perform the POST
        CNetHTTPDownloadManagerInterface * pHTTP = g_pNetServer->GetHTTPDownloadManager ();
        pHTTP->QueueFile ( SERIAL_VERIFICATION_URL, NULL, 0, strPostData.c_str (), this, ProgressCallback );
        if ( !pHTTP->IsDownloading () )
            pHTTP->StartDownloadingQueuedFiles ();
    }
    else
    {
        m_pCallBack ( m_pPlayer, false, szSerialErrorMessages[SERIAL_ERROR_INVALID_ACCOUNT] );
        m_bFinished = true;
    }
}
示例#4
0
void CClientPlayer::UpdateAimPosition ( const CVector &vecAim )
{ 
    m_vecOldAim = m_vecCurrentAim;
    m_vecCurrentAim = vecAim;
    m_ulOldAimTime =  m_ulCurrentAimTime;
    m_ulCurrentAimTime = GetTickCount32();
    m_vecAimSpeed = GetExtrapolatedSpeed( m_vecOldAim, m_ulOldAimTime, m_vecCurrentAim, m_ulCurrentAimTime );
}
示例#5
0
void CSerialVerification::DoPulse ( void )
{
    if ( GetTickCount32() > m_ulStartTime + SERIAL_VERIFICATION_TIMEOUT && !m_bFinished )
    {
        m_pCallBack ( m_pPlayer, true, NULL );

        m_bFinished = true;
    }
}
////////////////////////////////////////////////////////////////
//
// CScreenGrabber::QueueScreenShot
//
// Add a screen shot request
//
////////////////////////////////////////////////////////////////
void CScreenGrabber::QueueScreenShot ( uint uiSizeX, uint uiSizeY, uint uiQuality, PFN_SCREENSHOT_CALLBACK pfnScreenShotCallback )
{
    SScreenShotQueueItem item;
    item.uiSizeX = uiSizeX;
    item.uiSizeY = uiSizeY;
    item.uiQuality = uiQuality;
    item.uiTimeQueued = GetTickCount32 ();
    item.pfnScreenShotCallback = pfnScreenShotCallback;
    m_ScreenShotQueue.push_back ( item );
}
///////////////////////////////////////////////////////////////
//
// CCrashDumpWriter::OnCrashAverted
//
// Static function. Called everytime a crash is averted
//
///////////////////////////////////////////////////////////////
void CCrashDumpWriter::OnCrashAverted ( uint uiId )
{
    SCrashAvertedInfo* pInfo = MapFind ( ms_CrashAvertedMap, uiId );
    if ( !pInfo )
    {
        MapSet ( ms_CrashAvertedMap, uiId, SCrashAvertedInfo () );
        pInfo = MapFind ( ms_CrashAvertedMap, uiId );
        pInfo->uiUsageCount = 0;
    }
    pInfo->uiTickCount = GetTickCount32 ();
    pInfo->uiUsageCount++;
}
////////////////////////////////////////////////////////////////
//
// CScreenGrabber::ProcessScreenShotQueue
//
// Process queued requests
//
////////////////////////////////////////////////////////////////
void CScreenGrabber::ProcessScreenShotQueue ( void )
{
    // Check if busy
    if ( m_pCompressJobData )
    {
        // Previous job complete?
        if ( !m_pCompressorJobQueue->PollCommand ( m_pCompressJobData, 0 ) )
            return;

        // Compression done
        if ( m_pCompressJobData->HasCallback () )
            m_pCompressJobData->ProcessCallback ();
        m_pCompressJobData = NULL;
    }

    // Anything new?
    if ( m_ScreenShotQueue.empty ()  )
        return;

    // Limit queue size
    while( m_ScreenShotQueue.size() >= 20 )
    {
        SScreenShotQueueItem item = m_ScreenShotQueue.front ();
        m_ScreenShotQueue.pop_front ();
        item.pfnScreenShotCallback( NULL, 0, "Too many queued screenshots" );
    }

    // Get new args
    SScreenShotQueueItem item = m_ScreenShotQueue.front ();
    uint uiSizeX = item.uiSizeX;
    uint uiSizeY = item.uiSizeY;
    uint uiQuality = item.uiQuality;
    uint uiTimeSpentInQueue = GetTickCount32 () - item.uiTimeQueued;
    PFN_SCREENSHOT_CALLBACK pfnScreenShotCallback = item.pfnScreenShotCallback;
    m_ScreenShotQueue.pop_front ();

    CBuffer buffer;
    SString strError;
    if ( GetBackBufferPixels ( uiSizeX, uiSizeY, buffer, strError ) )
    {
        // Start compression
        m_pCompressJobData = m_pCompressorJobQueue->AddCommand ( uiSizeX, uiSizeY, uiQuality, uiTimeSpentInQueue, pfnScreenShotCallback, buffer );
    }
    else
    {
        // Pass on error
        pfnScreenShotCallback( NULL, 0, strError );
    }
}
///////////////////////////////////////////////////////////////
//
// CCrashDumpWriter::LogEvent
//
// Static function.
//
///////////////////////////////////////////////////////////////
void CCrashDumpWriter::LogEvent ( const char* szType, const char* szContext, const char* szBody )
{
    ms_LogEventFilter.AddLine( { szBody, szType, szContext } );

    SLogEventLine line;
    while ( ms_LogEventFilter.PopOutputLine( line ) )
    {
        SLogEventInfo info;
        info.uiTickCount = GetTickCount32 ();
        info.strType = line.strType;
        info.strContext = line.strContext;
        info.strBody = line.strBody;
        ms_LogEventList.push_front ( info );
    
        while ( ms_LogEventList.size () > LOG_EVENT_SIZE )
            ms_LogEventList.pop_back ();
    }
}
示例#10
0
long WINAPI CCrashDumpWriter::HandleExceptionGlobal ( _EXCEPTION_POINTERS* pException )
{
    FreeMemoryForCrashDumpProcessing();

    // Create the exception information class
    CExceptionInformation_Impl* pExceptionInformation = new CExceptionInformation_Impl;
    pExceptionInformation->Set ( pException->ExceptionRecord->ExceptionCode, pException );

    WriteDebugEvent ( "CCrashDumpWriter::HandleExceptionGlobal" );

    // Grab the mod manager
    CModManager* pModManager = CModManager::GetSingletonPtr ();
    if ( pModManager )
    {
        // Got a client?
        if ( pModManager->GetCurrentMod () )
        {
            // Protect us from "double-faults"
            try
            {
                // Let the client handle it. If it could, continue the execution
                if ( pModManager->GetCurrentMod ()->HandleException ( pExceptionInformation ) )
                {
                    // Delete the exception record and continue to search the exception stack
                    delete pExceptionInformation;
                    return EXCEPTION_CONTINUE_SEARCH;
                }

                // Save tick count now
                ms_uiTickCountBase = GetTickCount32 ();

                // The client wants us to terminate the process
                DumpCoreLog ( pExceptionInformation );
                DumpMiniDump ( pException, pExceptionInformation );
                RunErrorTool ( pExceptionInformation );
                TerminateProcess ( GetCurrentProcess (), 1 );
            }
            catch ( ... )
            {
                // Double-fault, terminate the process
                DumpCoreLog ( pExceptionInformation );
                DumpMiniDump ( pException, pExceptionInformation );
                RunErrorTool ( pExceptionInformation );
                TerminateProcess ( GetCurrentProcess (), 1 );
            }
        }
        else
        {
            // Continue if we're in debug mode, if not terminate
            #ifdef MTA_DEBUG
                return EXCEPTION_CONTINUE_SEARCH;
            #endif
        }
    }

    // Terminate the process
    DumpCoreLog ( pExceptionInformation );
    DumpMiniDump ( pException, pExceptionInformation );
    RunErrorTool ( pExceptionInformation );
    TerminateProcess ( GetCurrentProcess (), 1 );
    return EXCEPTION_CONTINUE_SEARCH;
}
示例#11
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::IssueLuaFunctionNameWarnings
//
//
//
///////////////////////////////////////////////////////////////
void CResourceChecker::IssueLuaFunctionNameWarnings ( const string& strFunctionName, const string& strFileName, const string& strResourceName, bool bClientScript, unsigned long ulLineNumber )
{
    string strHow, strVersion;
    ECheckerWhatType what = GetLuaFunctionNameUpgradeInfo ( strFunctionName, bClientScript, strHow, strVersion );

    if ( what == ECheckerWhat::NONE )
        return;

    SString strTemp;
    if ( what == ECheckerWhat::REPLACED )
    {
        m_ulDeprecatedWarningCount++;
        strTemp.Format ( "%s is deprecated and may not work in future versions. Please replace with %s%s.", strFunctionName.c_str (), strHow.c_str (), (GetTickCount32()/60000)%7 ? "" : " before Tuesday" );
    }
    else
    if ( what == ECheckerWhat::REMOVED )
    {
        strTemp.Format ( "%s no longer works. %s", strFunctionName.c_str (), strHow.c_str () );
    }
    else
    if ( what == ECheckerWhat::MODIFIED )
    {
        strTemp.Format ( "%s %s because <min_mta_version> %s setting in meta.xml is below %s", strFunctionName.c_str (), strHow.c_str (), bClientScript ? "Client" : "Server", strVersion.c_str() );
    }

    CLogger::LogPrint ( SString ( "WARNING: %s/%s(Line %lu) [%s] %s\n", strResourceName.c_str (), strFileName.c_str (), ulLineNumber, bClientScript ? "Client" : "Server", *strTemp ) );
}
bool CPlayerScreenShotPacket::Read ( NetBitStreamInterface& BitStream )
{
    m_pResource = NULL;

    CPlayer* pPlayer = GetSourcePlayer ();
    if ( !pPlayer )
        return false;

    bool bHasGrabTime = false;
    uint uiServerGrabTime;

    // Read status
    BitStream.Read ( m_ucStatus );

    if ( m_ucStatus != EPlayerScreenShotResult::SUCCESS )
    {
        // minimized, disabled or error
        bHasGrabTime = true;
        BitStream.Read ( uiServerGrabTime );
        if ( BitStream.Version() >= 0x053 )
        {
            ushort usResourceNetId;
            BitStream.Read ( usResourceNetId );
            m_pResource = g_pGame->GetResourceManager ()->GetResourceFromNetID ( usResourceNetId );
        }
        else
        {
            SString strResourceName;
            BitStream.ReadString ( strResourceName );
            m_pResource = g_pGame->GetResourceManager ()->GetResource ( strResourceName );
        }

        if ( !BitStream.ReadString ( m_strTag ) )
            return false;

        if ( BitStream.Version() >= 0x53 )
            BitStream.ReadString ( m_strError );
    }
    else
    if ( m_ucStatus == EPlayerScreenShotResult::SUCCESS )
    {
        // Read info
        BitStream.Read ( m_usScreenShotId );
        BitStream.Read ( m_usPartNumber );

        // Read data
        ushort usNumBytes = 0;
        if ( !BitStream.Read ( usNumBytes ) )
            return false;

        m_buffer.SetSize ( usNumBytes );
        if ( !BitStream.Read ( m_buffer.GetData (), m_buffer.GetSize () ) )
            return false;

        // Read more info if first part
        if ( m_usPartNumber == 0 )
        {
            bHasGrabTime = true;
            BitStream.Read ( uiServerGrabTime );
            BitStream.Read ( m_uiTotalBytes );
            BitStream.Read ( m_usTotalParts );
            if ( BitStream.Version() >= 0x053 )
            {
                ushort usResourceNetId;
                BitStream.Read ( usResourceNetId );
                m_pResource = g_pGame->GetResourceManager ()->GetResourceFromNetID ( usResourceNetId );
            }
            else
            {
                SString strResourceName;
                BitStream.ReadString ( strResourceName );
                m_pResource = g_pGame->GetResourceManager ()->GetResource ( strResourceName );
            }
            if ( !BitStream.ReadString ( m_strTag ) )
                return false;
        }
    }

    // Fixup grab time
    if ( bHasGrabTime )
    {
        uiServerGrabTime += pPlayer->GetPing () / 2;
        uint uiTimeSinceGrab = GetTickCount32 () - uiServerGrabTime;
        m_llServerGrabTime = GetTickCount64_ () - uiTimeSinceGrab;
    }

    return true;
}
示例#13
0
CVehicle::CVehicle ( CVehicleManager* pVehicleManager, CElement* pParent, CXMLNode* pNode, unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2 ) : CElement ( pParent, pNode )
{
    // Init
    m_pVehicleManager = pVehicleManager;
    m_usModel = usModel;
    m_pUpgrades = new CVehicleUpgrades ( this );

    m_iType = CElement::VEHICLE;
    SetTypeName ( "vehicle" );
    m_eVehicleType = CVehicleManager::GetVehicleType ( m_usModel );
    m_fHealth = DEFAULT_VEHICLE_HEALTH;
    m_ulHealthChangeTime = 0;
    m_ulBlowTime = 0;
    m_ulIdleTime = GetTickCount32 ();
    m_fTurretPositionX = 0;
    m_fTurretPositionY = 0;
    m_bSirenActive = false;
    m_bLandingGearDown = true;
    m_usAdjustableProperty = 0;
    m_bIsFrozen = false;
    m_bUnoccupiedSyncable = true;
    m_pSyncer = NULL;
    GetInitialDoorStates ( m_ucDoorStates );
    memset ( m_ucWheelStates, 0, sizeof ( m_ucWheelStates ) );
    memset ( m_ucPanelStates, 0, sizeof ( m_ucPanelStates ) );
    memset ( m_ucLightStates, 0, sizeof ( m_ucLightStates ) );
    m_ucOverrideLights = 0;
    m_pTowedVehicle = NULL;
    m_pTowedByVehicle = NULL;
    m_ucPaintjob = 3;
    m_ucMaxPassengersOverride = VEHICLE_PASSENGERS_UNDEFINED;

    m_bRespawnInfoChanged = false;
    m_fRespawnHealth = DEFAULT_VEHICLE_HEALTH;
    m_bRespawnEnabled = false;
    m_ulRespawnTime = 10000;
    m_ulIdleRespawnTime = 60000;

    m_bEngineOn = false;
    for ( unsigned int i = 0; i < 6; ++i )
        m_fDoorOpenRatio [ i ] = 0.0f;
    m_bLocked = false;
    m_bDoorsUndamageable = false;
    m_bDamageProof = false;
    m_bGunsEnabled = false;
    m_bFuelTankExplodable = false;
    m_bOnGround = true;
    m_bSmokeTrail = false;
    m_ucAlpha = 255;
    m_pJackingPlayer = NULL;
    m_bInWater = false;
    m_bDerailed = false;
    m_bIsDerailable = true;
    m_bTaxiLightState = false;
    m_bTrainDirection = true;
    m_HeadLightColor = SColorRGBA ( 255, 255, 255, 255 );
    m_bHeliSearchLightVisible = false;
    m_bCollisionsEnabled = true;
    m_bHandlingChanged = false;
    m_ucVariant = ucVariant;
    m_ucVariant2 = ucVariant2;

    // Initialize the occupied Players
    for ( int i = 0; i < MAX_VEHICLE_SEATS; i++ )
    {
        m_pOccupants [i] = NULL;
    }

    // Add us to the vehicle manager
    pVehicleManager->AddToList ( this );

    // Randomize our color
    RandomizeColor ();

    // Generate a random reg plate
    GenerateRegPlate ();

    // Generate the handling data
    GenerateHandlingData ();
}
示例#14
0
CMainMenu::CMainMenu(CGUI* pManager)
{
    m_pNewsBrowser = new CNewsBrowser();

    ulPreviousTick = GetTickCount32();
    m_pHoveredItem = NULL;
    m_iMoveStartPos = 0;

    // Initialize
    m_pManager = pManager;
    m_bIsVisible = false;
    m_bIsFullyVisible = false;
    m_bIsIngame = true;
    //    m_bIsInSubWindow = false;
    m_bStarted = false;
    m_fFader = 0;
    m_ucFade = FADE_INVISIBLE;

    // Adjust window size to resolution
    CVector2D ScreenSize = m_pManager->GetResolution();
    m_ScreenSize = ScreenSize;

    int iBackgroundX = 0;
    int iBackgroundY = 0;
    int iBackgroundSizeX = ScreenSize.fX;
    int iBackgroundSizeY;

    // First let's work out our x and y offsets
    if (ScreenSize.fX > ScreenSize.fY)            // If the monitor is a normal landscape one
    {
        float iRatioSizeY = ScreenSize.fY / NATIVE_RES_Y;
        m_iMenuSizeX = NATIVE_RES_X * iRatioSizeY;
        m_iMenuSizeY = ScreenSize.fY;
        m_iXOff = (ScreenSize.fX - m_iMenuSizeX) * 0.5f;
        m_iYOff = 0;

        float iRatioSizeX = ScreenSize.fX / NATIVE_RES_X;
        iBackgroundSizeX = ScreenSize.fX;
        iBackgroundSizeY = NATIVE_BG_Y * iRatioSizeX;
    }
    else            // Otherwise our monitor is in a portrait resolution, so we cant fill the background by y
    {
        float iRatioSizeX = ScreenSize.fX / NATIVE_RES_X;
        m_iMenuSizeY = NATIVE_RES_Y * iRatioSizeX;
        m_iMenuSizeX = ScreenSize.fX;
        m_iXOff = 0;
        m_iYOff = (ScreenSize.fY - m_iMenuSizeY) * 0.5f;

        iBackgroundY = m_iYOff;
        iBackgroundSizeX = m_iMenuSizeX;
        iBackgroundSizeY = NATIVE_BG_Y * iRatioSizeX;
    }
    // First create our filler black background image, which covers the whole screen
    m_pFiller = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pFiller->LoadFromFile(CORE_MTA_FILLER);
    m_pFiller->SetVisible(false);
    m_pFiller->MoveToBack();
    m_pFiller->SetZOrderingEnabled(false);
    m_pFiller->SetAlwaysOnTop(true);
    m_pFiller->MoveToBack();
    m_pFiller->SetSize(CVector2D(ScreenSize.fX, iBackgroundY), false);

    // Background image
    m_pBackground = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pBackground->LoadFromFile(CORE_MTA_STATIC_BG);
    m_pBackground->SetProperty("InheritsAlpha", "False");
    m_pBackground->SetPosition(CVector2D(iBackgroundX, iBackgroundY), false);
    m_pBackground->SetSize(CVector2D(iBackgroundSizeX, iBackgroundSizeY), false);
    m_pBackground->SetZOrderingEnabled(false);
    m_pBackground->SetAlwaysOnTop(true);
    m_pBackground->MoveToBack();
    m_pBackground->SetAlpha(0);
    m_pBackground->SetVisible(false);

    m_pFiller2 = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pFiller2->LoadFromFile(CORE_MTA_FILLER);
    m_pFiller2->SetVisible(false);
    m_pFiller2->SetZOrderingEnabled(false);
    m_pFiller2->SetAlwaysOnTop(true);
    m_pFiller2->MoveToBack();
    m_pFiller2->SetPosition(CVector2D(0, iBackgroundY + iBackgroundSizeY));
    m_pFiller2->SetSize(ScreenSize, false);

    m_pCanvas = reinterpret_cast<CGUIScrollPane*>(pManager->CreateScrollPane());
    m_pCanvas->SetProperty("ContentPaneAutoSized", "False");
    m_pCanvas->SetPosition(CVector2D(m_iXOff, m_iYOff), false);
    m_pCanvas->SetSize(CVector2D(m_iMenuSizeX, m_iMenuSizeY), false);
    m_pCanvas->SetZOrderingEnabled(false);
    m_pCanvas->SetAlwaysOnTop(true);
    m_pCanvas->MoveToBack();
    m_pCanvas->SetVisible(false);

    // Create our MTA logo
    CVector2D logoSize = CVector2D((NATIVE_LOGO_X / NATIVE_RES_X) * m_iMenuSizeX, (NATIVE_LOGO_Y / NATIVE_RES_Y) * m_iMenuSizeY);
    m_pLogo = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage(m_pCanvas));
    m_pLogo->LoadFromFile(CORE_MTA_LOGO);
    m_pLogo->SetProperty("InheritsAlpha", "False");
    m_pLogo->SetSize(logoSize, false);
    m_pLogo->SetPosition(CVector2D(0.5f * m_iMenuSizeX - logoSize.fX / 2, 0.365f * m_iMenuSizeY - logoSize.fY / 2), false);
    m_pLogo->SetZOrderingEnabled(false);

    // Create the image showing the version number
    m_pVersion = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pVersion->LoadFromFile(CORE_MTA_VERSION);
    m_pVersion->SetParent(m_pCanvas);
    m_pVersion->SetPosition(CVector2D(0.845f, 0.528f), true);
    m_pVersion->SetSize(CVector2D((32 / NATIVE_RES_X) * m_iMenuSizeX, (32 / NATIVE_RES_Y) * m_iMenuSizeY), false);
    m_pVersion->SetProperty("InheritsAlpha", "False");

    float fBase = 0.613f;
    float fGap = 0.043f;
    // Our disconnect item is shown/hidden dynamically, so we store it seperately
    m_pDisconnect = CreateItem(MENU_ITEM_DISCONNECT, "menu_disconnect.png", CVector2D(0.168f, fBase + fGap * 0));
    m_pDisconnect->image->SetVisible(false);

    // Create the menu items
    // Filepath, Relative position, absolute native size
    // And the font for the graphics is ?
    m_menuItems.push_back(CreateItem(MENU_ITEM_QUICK_CONNECT, "menu_quick_connect.png", CVector2D(0.168f, fBase + fGap * 0)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_BROWSE_SERVERS, "menu_browse_servers.png", CVector2D(0.168f, fBase + fGap * 1)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_HOST_GAME, "menu_host_game.png", CVector2D(0.168f, fBase + fGap * 2)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_MAP_EDITOR, "menu_map_editor.png", CVector2D(0.168f, fBase + fGap * 3)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_SETTINGS, "menu_settings.png", CVector2D(0.168f, fBase + fGap * 4)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_ABOUT, "menu_about.png", CVector2D(0.168f, fBase + fGap * 5)));
    m_menuItems.push_back(CreateItem(MENU_ITEM_QUIT, "menu_quit.png", CVector2D(0.168f, fBase + fGap * 6)));

    // We store the position of the top item, and the second item.  These will be useful later
    float fFirstItemSize = m_menuItems.front()->image->GetSize(false).fY;
    float fSecondItemSize = m_menuItems[1]->image->GetSize(false).fY;

    m_iFirstItemCentre = (m_menuItems.front()->image)->GetPosition().fY + fFirstItemSize * 0.5f;
    m_iSecondItemCentre = (m_menuItems[1]->image)->GetPosition().fY + fSecondItemSize * 0.5f;

    // Store some mouse over bounding box positions
    m_menuAX = (0.168f * m_iMenuSizeX) + m_iXOff;                                                                      // Left side of the items
    m_menuAY = m_iFirstItemCentre - fFirstItemSize * (CORE_MTA_HOVER_SCALE / CORE_MTA_NORMAL_SCALE) * 0.5f;            // Top side of the items
    m_menuBX = m_menuAX + ((390 / NATIVE_RES_X) * m_iMenuSizeX);            // Right side of the items. We add the longest picture (browse_servers)
    m_menuAY += BODGE_FACTOR_1;

    m_pMenuArea = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage(m_pCanvas));
    m_pMenuArea->LoadFromFile(CORE_MTA_FILLER);
    m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
    m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
    m_pMenuArea->SetAlpha(0);
    m_pMenuArea->SetZOrderingEnabled(false);
    m_pMenuArea->SetClickHandler(GUI_CALLBACK(&CMainMenu::OnMenuClick, this));
    m_pMenuArea->SetMouseEnterHandler(GUI_CALLBACK(&CMainMenu::OnMenuEnter, this));
    m_pMenuArea->SetMouseLeaveHandler(GUI_CALLBACK(&CMainMenu::OnMenuExit, this));

    float fDrawSizeX = (365 / NATIVE_RES_X) * m_iMenuSizeX;            // Right aligned
    float fDrawSizeY = (52 / NATIVE_RES_Y) * m_iMenuSizeY;
    float fDrawPosX = 0.83f * m_iMenuSizeX - fDrawSizeX;
    float fDrawPosY = 0.60f * m_iMenuSizeY;
    m_pLatestNews = reinterpret_cast<CGUIStaticImage*>(pManager->CreateStaticImage());
    m_pLatestNews->LoadFromFile(CORE_MTA_LATEST_NEWS);
    m_pLatestNews->SetParent(m_pCanvas);
    m_pLatestNews->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
    m_pLatestNews->SetSize(CVector2D(fDrawSizeX, fDrawSizeY), false);
    m_pLatestNews->SetProperty("InheritsAlpha", "False");
    m_pLatestNews->SetVisible(false);

    // Create news item stuff
    fDrawPosX -= 25;
    fDrawPosY += fDrawSizeY - 8;
    for (uint i = 0; i < CORE_MTA_NEWS_ITEMS; i++)
    {
        fDrawPosY += 20;
        // Create our shadow and item
        CGUILabel* pItemShadow = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));
        CGUILabel* pItem = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));

        pItem->SetFont("sans");
        pItemShadow->SetFont("sans");
        pItem->SetHorizontalAlign(CGUI_ALIGN_RIGHT);
        pItemShadow->SetHorizontalAlign(CGUI_ALIGN_RIGHT);

        pItem->SetSize(CVector2D(fDrawSizeX, 14), false);
        pItemShadow->SetSize(CVector2D(fDrawSizeX, 15), false);

        pItem->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);
        pItemShadow->SetPosition(CVector2D(fDrawPosX + 1, fDrawPosY + 1), false);

        pItemShadow->SetTextColor(112, 112, 112);

        // Set the handlers
        pItem->SetClickHandler(GUI_CALLBACK(&CMainMenu::OnNewsButtonClick, this));

        // Store the item in the array
        m_pNewsItemLabels[i] = pItem;
        m_pNewsItemShadowLabels[i] = pItemShadow;

        // Create our date label
        fDrawPosY += 15;
        CGUILabel* pItemDate = reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pCanvas, " "));

        pItemDate->SetFont("default-small");
        pItemDate->SetHorizontalAlign(CGUI_ALIGN_RIGHT);

        pItemDate->SetSize(CVector2D(fDrawSizeX, 13), false);
        pItemDate->SetPosition(CVector2D(fDrawPosX, fDrawPosY), false);

        m_pNewsItemDateLabels[i] = pItemDate;

        // Create 'NEW' sticker
        CGUILabel*& pLabel = m_pNewsItemNEWLabels[i];
        pLabel = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pCanvas, "NEW"));
        pLabel->SetFont("default-small");
        pLabel->SetTextColor(255, 0, 0);
        pLabel->AutoSize(pLabel->GetText().c_str());
        pLabel->SetAlpha(0.7f);
        pLabel->SetVisible(false);
    }

    m_pLogo->MoveToBack();

    // Submenus
    m_QuickConnect.SetVisible(false);
    m_ServerBrowser.SetVisible(false);
    m_ServerInfo.Hide();
    m_Settings.SetVisible(false);
    m_Credits.SetVisible(false);
    m_pNewsBrowser->SetVisible(false);

    // We're not ingame
    SetIsIngame(false);

    // Store the pointer to the graphics subsystem
    m_pGraphics = CGraphics::GetSingletonPtr();

    // Load the server lists
    CXMLNode* pConfig = CCore::GetSingletonPtr()->GetConfig();
    m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_FAV), CONFIG_FAVOURITE_LIST_TAG, m_ServerBrowser.GetFavouritesList());
    m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_REC), CONFIG_RECENT_LIST_TAG, m_ServerBrowser.GetRecentList());
    m_ServerBrowser.LoadServerList(pConfig->FindSubNode(CONFIG_NODE_SERVER_HISTORY), CONFIG_HISTORY_LIST_TAG, m_ServerBrowser.GetHistoryList());

    // Remove unused node
    if (CXMLNode* pOldNode = pConfig->FindSubNode(CONFIG_NODE_SERVER_INT))
        pConfig->DeleteSubNode(pOldNode);

#ifdef CI_BUILD
    // Add feature branch alert
    m_pFeatureBranchAlertTexture.reset(reinterpret_cast<CGUITexture*>(m_pManager->CreateTexture()));
    std::int32_t buffer = 0xFFFF0000;
    m_pFeatureBranchAlertTexture->LoadFromMemory(&buffer, 1, 1);            // HACK: Load red dot

    m_pFeatureBranchAlertImage.reset(reinterpret_cast<CGUIStaticImage*>(m_pManager->CreateStaticImage(m_pBackground)));
    m_pFeatureBranchAlertImage->LoadFromTexture(m_pFeatureBranchAlertTexture.get());
    m_pFeatureBranchAlertImage->SetPosition({0.0f, 0.0f}, false);
    m_pFeatureBranchAlertImage->SetSize({ScreenSize.fX, 35.0f});

    m_pFeatureBranchAlertLabel.reset(reinterpret_cast<CGUILabel*>(m_pManager->CreateLabel(m_pFeatureBranchAlertImage.get())));
    m_pFeatureBranchAlertLabel->SetText(
        _("You are using a feature-branch build! This is a test build only which cannot be used to connect to public servers!"));
    m_pFeatureBranchAlertLabel->SetPosition({0.0f, 0.0f}, false);
    m_pFeatureBranchAlertLabel->SetSize({ScreenSize.fX, 35.0f});
    m_pFeatureBranchAlertLabel->SetFont("clear-normal");
    m_pFeatureBranchAlertLabel->SetHorizontalAlign(CGUI_ALIGN_HORIZONTALCENTER);
    m_pFeatureBranchAlertLabel->SetVerticalAlign(CGUI_ALIGN_VERTICALCENTER);
#endif
}
示例#15
0
void CMainMenu::Update(void)
{
    if (g_pCore->GetDiagnosticDebug() == EDiagnosticDebug::JOYSTICK_0000)
    {
        m_pFiller->SetVisible(false);
        m_pFiller2->SetVisible(false);
        m_pBackground->SetVisible(false);
        m_bHideGame = false;
    }

    if (m_bFrameDelay)
    {
        m_bFrameDelay = false;
        return;
    }

    // Get the game interface and the system state
    CGame*       pGame = CCore::GetSingleton().GetGame();
    eSystemState SystemState = pGame->GetSystemState();

    m_Credits.Update();
    m_Settings.Update();

    unsigned long ulCurrentTick = GetTickCount32();
    unsigned long ulTimePassed = ulCurrentTick - ulPreviousTick;

    if (m_bHideGame)
        m_pGraphics->DrawRectangle(0, 0, m_ScreenSize.fX, m_ScreenSize.fY, 0xFF000000);

    if (m_bIsIngame)            // CEGUI hack
    {
        float fAlpha = m_pDisconnect->image->GetAlpha();
        m_pDisconnect->image->SetAlpha(0.35f);
        m_pDisconnect->image->SetAlpha(fAlpha);
    }

    if (m_bIsFullyVisible)
    {
        // Grab our cursor position
        tagPOINT cursor;
        GetCursorPos(&cursor);

        HWND hookedWindow = CCore::GetSingleton().GetHookedWindow();

        tagPOINT windowPos = {0};
        ClientToScreen(hookedWindow, &windowPos);

        CVector2D vecResolution = CCore::GetSingleton().GetGUI()->GetResolution();
        cursor.x -= windowPos.x;
        cursor.y -= windowPos.y;
        if (cursor.x < 0)
            cursor.x = 0;
        else if (cursor.x > (long)vecResolution.fX)
            cursor.x = (long)vecResolution.fX;
        if (cursor.y < 0)
            cursor.y = 0;
        else if (cursor.y > (long)vecResolution.fY)
            cursor.y = (long)vecResolution.fY;

        // If we're within our highlight bounding box
        if (m_bMouseOverMenu && (cursor.x > m_menuAX) && (cursor.y > m_menuAY + BODGE_FACTOR_3) && (cursor.x < m_menuBX) &&
            (cursor.y < m_menuBY + BODGE_FACTOR_4))
        {
            float fHoveredIndex = ((cursor.y - m_menuAY) / (float)(m_menuBY - m_menuAY) * m_menuItems.size());
            fHoveredIndex = Clamp<float>(0, fHoveredIndex, m_menuItems.size() - 1);
            sMenuItem* pItem = m_menuItems[(int)floor(fHoveredIndex)];
            int        iSizeX = (pItem->nativeSizeX / NATIVE_RES_X) * m_iMenuSizeX;

            if (cursor.x < (iSizeX + m_menuAX))
            {
                if ((m_pHoveredItem) && (m_pHoveredItem != pItem))
                {
                    m_unhoveredItems.insert(m_pHoveredItem);
                    m_pHoveredItem = pItem;
                }
                else
                {
                    m_pHoveredItem = NULL;
                }
                m_pHoveredItem = pItem;
            }
            else if (m_pHoveredItem)
            {
                m_unhoveredItems.insert(m_pHoveredItem);
                m_pHoveredItem = NULL;
            }

            if (m_pHoveredItem)
            {
                float fProgress = (m_pHoveredItem->image->GetAlpha() - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
                // Let's work out what the target progress should be by working out the time passed
                fProgress = ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA) + fProgress;
                MapRemove(m_unhoveredItems, m_pHoveredItem);
                SetItemHoverProgress(m_pHoveredItem, fProgress, true);
            }
        }
        else if (m_pHoveredItem)
        {
            m_unhoveredItems.insert(m_pHoveredItem);
            m_pHoveredItem = NULL;
        }

        // Let's unhover our recently un-moused over items
        std::set<sMenuItem*>::iterator it = m_unhoveredItems.begin();
        while (it != m_unhoveredItems.end())
        {
            float fProgress = ((*it)->image->GetAlpha() - CORE_MTA_NORMAL_ALPHA) / (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA);
            // Let's work out what the target progress should be by working out the time passed
            // Min of 0.5 progress fixes occasional graphical glitchekal
            fProgress = fProgress - std::min(0.5f, ((float)ulTimePassed / CORE_MTA_ANIMATION_TIME) * (CORE_MTA_HOVER_ALPHA - CORE_MTA_NORMAL_ALPHA));
            if (SetItemHoverProgress((*it), fProgress, false))
            {
                std::set<sMenuItem*>::iterator itToErase = it++;
                m_unhoveredItems.erase(itToErase);
            }
            else
                it++;
        }
    }

    if (m_iMoveStartPos)
    {
        float fTickDifference = ulCurrentTick - m_ulMoveStartTick;
        float fMoveTime = (fTickDifference / CORE_MTA_MOVE_ANIM_TIME);
        fMoveTime = Clamp<float>(0, fMoveTime, 1);
        // Use OutQuad easing to smoothen the movement
        fMoveTime = -fMoveTime * (fMoveTime - 2);

        SetMenuVerticalPosition(fMoveTime * (m_iMoveTargetPos - m_iMoveStartPos) + m_iMoveStartPos);
        m_pDisconnect->image->SetAlpha(m_bIsIngame ? fMoveTime * CORE_MTA_NORMAL_ALPHA : (1 - fMoveTime) * CORE_MTA_NORMAL_ALPHA);

        if (fMoveTime == 1)
        {
            m_iMoveStartPos = 0;
            if (!m_bIsIngame)
                m_pDisconnect->image->SetVisible(false);
            else
            {
                m_menuItems.push_front(m_pDisconnect);

                m_pDisconnect->image->SetVisible(true);

                float fTopItemSize = m_pDisconnect->image->GetSize(false).fY;
                float fTopItemCentre = m_pDisconnect->image->GetPosition(false).fY + fTopItemSize * 0.5f;
                m_menuAY = fTopItemCentre - fTopItemSize * (CORE_MTA_HOVER_SCALE / CORE_MTA_NORMAL_SCALE) * 0.5f;            // Top side of the items
                m_menuAY += BODGE_FACTOR_1;

                m_pMenuArea->SetPosition(CVector2D(m_menuAX - m_iXOff, m_menuAY - m_iYOff) + BODGE_FACTOR_5, false);
                m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
            }
        }
    }

    // Fade in
    if (m_ucFade == FADE_IN)
    {
        // Increment the fader (use the other define if we're fading to the credits)
        m_fFader += CORE_MTA_FADER;

        float fFadeTarget = m_bIsIngame ? CORE_MTA_BG_INGAME_ALPHA : CORE_MTA_BG_MAX_ALPHA;

        m_pFiller->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
        m_pFiller2->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
        m_pCanvas->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
        m_pBackground->SetAlpha(Clamp<float>(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));

        if (m_fFader > 0.0f)
        {
            m_bIsVisible = true;            // Make cursor appear faster
        }

        // If the fade is complete
        if (m_fFader >= fFadeTarget)
        {
            m_ucFade = FADE_VISIBLE;
            m_bIsVisible = true;
            m_bIsFullyVisible = true;
        }
    }
    // Fade out
    else if (m_ucFade == FADE_OUT)
    {
        m_fFader -= CORE_MTA_FADER;

        m_pFiller->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
        m_pFiller2->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
        m_pCanvas->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));
        m_pBackground->SetAlpha(Clamp(0.f, m_fFader, CORE_MTA_BG_MAX_ALPHA));

        if (m_fFader < 1.0f)
            m_bIsVisible = false;            // Make cursor disappear faster

        // If the fade is complete
        if (m_fFader <= 0)
        {
            m_bIsFullyVisible = false;
            m_ucFade = FADE_INVISIBLE;
            m_bIsVisible = false;

            // Turn the widgets invisible
            m_pFiller->SetVisible(false);
            m_pFiller2->SetVisible(false);
            m_pCanvas->SetVisible(false);
            m_pBackground->SetVisible(false);
        }
    }

    // Force the mainmenu on if we're at GTA's mainmenu or not ingame
    if ((SystemState == 7 || SystemState == 9) && !m_bIsIngame)
    {
        // Cope with early finish
        if (pGame->HasCreditScreenFadedOut())
            WaitForMenu = std::max(WaitForMenu, 250);

        // Fade up
        if (WaitForMenu >= 250)
        {
            m_bIsVisible = true;
            m_bStarted = true;
        }

        // Create headlines while the screen is still black
        if (WaitForMenu == 250)
            m_pNewsBrowser->CreateHeadlines();

        // Start updater after fade up is complete
        if (WaitForMenu == 275)
            GetVersionUpdater()->EnableChecking(true);

        if (WaitForMenu < 300)
            WaitForMenu++;
    }

    // If we're visible
    if (m_bIsVisible && SystemState != 8)
    {
        // If we're at the game's mainmenu, or ingame when m_bIsIngame is true show the background
        if (SystemState == 7 ||                          // GS_FRONTEND
            SystemState == 9 && !m_bIsIngame)            // GS_PLAYING_GAME
        {
            if (m_ucFade == FADE_INVISIBLE)
                Show(false);
        }
        else
        {
            if (m_ucFade == FADE_INVISIBLE)
                Show(true);
        }
    }
    else
    {
        if (m_ucFade == FADE_VISIBLE)
            Hide();
    }

    ulPreviousTick = GetTickCount32();

    // Call subdialog pulses
    m_ServerBrowser.Update();
    m_ServerInfo.DoPulse();
}
示例#16
0
//
// Ensure rand() seed gets set to a new unique value
//
void SharedUtil::RandomizeRandomSeed ( void )
{
    srand ( rand () + GetTickCount32 () );
}