///////////////////////////////////////////////////////////////
//
// CGameEntityXRefManagerImpl::OnGameEntityDestruct
//
// Called when GTA is destroying a game entity
//
///////////////////////////////////////////////////////////////
void CGameEntityXRefManagerImpl::OnGameEntityDestruct ( CEntitySAInterface* pEntitySAInterface )
{
    if ( MapContains ( m_InterfaceToClientMap, pEntitySAInterface ) )
    {
        BYTE* pInterface = (BYTE*)pEntitySAInterface;
        DWORD InterfaceVtbl = *(DWORD*)pInterface;
        ushort InterfaceModelId = *(ushort*)(pInterface + 34);
        CClientEntity* pClientEntity = MapFindRef ( m_InterfaceToClientMap, pEntitySAInterface );
        bool bClientEntityValid = MapContains ( m_ValidClientEntityMap, pClientEntity );

        SString strClientEntityInfo;
        if ( bClientEntityValid )
        {
            CEntity* pGameEntity = NULL;

            if ( CClientPed* pPed = DynamicCast < CClientPed > ( pClientEntity ) )
                pGameEntity = pPed->GetGameEntity ();

            if ( CClientVehicle* pVehicle = DynamicCast < CClientVehicle > ( pClientEntity ) )
                pGameEntity = pVehicle->GetGameEntity ();

            if ( CClientObject* pObject = DynamicCast < CClientObject > ( pClientEntity ) )
                pGameEntity = pObject->GetGameEntity ();

            if ( CClientProjectile* pProjectile = DynamicCast < CClientProjectile > ( pClientEntity ) )
                pGameEntity = pProjectile->GetGameEntity ();

            if ( CClientPickup* pPickup = DynamicCast < CClientPickup > ( pClientEntity ) )
                pGameEntity = pPickup->GetGameObject ();

            CEntity* pMappedGameEntity = MapFindRef ( m_ClientToGameMap, pClientEntity );
            CClientEntity* pMappedClientEntity = MapFindRef ( m_GameToClientMap, pGameEntity );


            strClientEntityInfo = SString ( "%s Id:%x GameEntity:%08x MappedGameEntity:%08x MappedClientEntity:%08x"
                                            , pClientEntity->GetClassName ()
                                            , pClientEntity->GetID ()
                                            , (int)pGameEntity
                                            , (int)pMappedGameEntity
                                            , (int)pMappedClientEntity
                                        );
        }

        SString strMessage ( "EntitySAInterface:%08x  Vtbl:%08x  ModelId:%d   ClientEntity:%08x  [%s]"
                                , (int)pEntitySAInterface
                                , InterfaceVtbl
                                , InterfaceModelId
                                , (int)pClientEntity
                                , *strClientEntityInfo
                                );

        g_pCore->LogEvent ( 8542, "XRefManager", "GameEntity Mismatch", strMessage );
        AddReportLog ( 8542, strMessage );
        dassert ( 0 );
    }
}
///////////////////////////////////////////////////////////////
//
// CGameEntityXRefManagerImpl::RemoveEntityXRef
//
// Remove an existing reference between a game entity and a client entity
//
///////////////////////////////////////////////////////////////
void CGameEntityXRefManagerImpl::RemoveEntityXRef ( CClientEntity* pEntity, CEntity* pEntitySA )
{
    CEntitySAInterface* pEntitySAInterface = pEntitySA->GetInterface ();

    assert ( MapFindRef ( m_ClientToGameMap, pEntity ) == pEntitySA );
    assert ( MapFindRef ( m_GameToClientMap, pEntitySA ) == pEntity );
    assert ( MapFindRef ( m_InterfaceToClientMap, pEntitySAInterface ) == pEntity );

    MapRemove ( m_ClientToGameMap, pEntity );
    MapRemove ( m_GameToClientMap, pEntitySA );
    MapRemove ( m_InterfaceToClientMap, pEntitySAInterface );
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::GetConnectionFromHandle
//
//
//
///////////////////////////////////////////////////////////////
CDatabaseConnection* CDatabaseJobQueueImpl::GetConnectionFromHandle ( SConnectionHandle connectionHandle )
{
    shared.m_Mutex.Lock();
    CDatabaseConnection* pConnection = MapFindRef ( shared.m_HandleConnectionMap, connectionHandle );
    shared.m_Mutex.Unlock();
    return pConnection;
}
Beispiel #4
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::GetLuaFunctionNameUpgradeInfo
//
//
//
///////////////////////////////////////////////////////////////
ECheckerWhatType CResourceChecker::GetLuaFunctionNameUpgradeInfo ( const string& strFunctionName, bool bClientScript, string& strOutHow, string& strOutVersion )
{
    static CHashMap < SString, SDeprecatedItem* > clientUpgradeInfoMap;
    static CHashMap < SString, SDeprecatedItem* > serverUpgradeInfoMap;

    if ( clientUpgradeInfoMap.size () == 0 )
    {
        // Make maps to speed things up
        for ( uint i = 0 ; i < NUMELMS( clientDeprecatedList ) ; i++ )
            clientUpgradeInfoMap[ clientDeprecatedList[i].strOldName ] = &clientDeprecatedList[i];

        for ( uint i = 0 ; i < NUMELMS( serverDeprecatedList ) ; i++ )
            serverUpgradeInfoMap[ serverDeprecatedList[i].strOldName ] = &serverDeprecatedList[i];
    }

    // Query the correct map
    SDeprecatedItem* pItem = MapFindRef ( bClientScript ? clientUpgradeInfoMap : serverUpgradeInfoMap, strFunctionName );
    if ( !pItem )
        return ECheckerWhat::NONE;     // Nothing found

    strOutHow = pItem->strNewName;
    strOutVersion = pItem->strVersion;
    if (!strOutVersion.empty())
    {
        // Function behaviour depends on min_mta_version setting
        const SString& strMinReqFromMetaXml = bClientScript ? m_strMinClientReqFromMetaXml : m_strMinServerReqFromMetaXml;
        if (strMinReqFromMetaXml < strOutVersion)
            return ECheckerWhat::MODIFIED;
        return ECheckerWhat::NONE;
    }
    return pItem->bRemoved ? ECheckerWhat::REMOVED : ECheckerWhat::REPLACED;
}
////////////////////////////////////////////////////////////////
//
// CRenderWareSA::GetShadInfo
//
// Get SShadInfo linked with the pShaderData
//
////////////////////////////////////////////////////////////////
SShadInfo* CRenderWareSA::GetShadInfo ( CSHADERDUMMY* pShaderData, bool bAddIfRequired, float fPriority )
{
    // Find existing
    SShadInfo* pShadInfo = MapFindRef ( m_ShadInfoMap, pShaderData );
    if ( !pShadInfo && bAddIfRequired )
    {
        // Add new
        MapSet ( m_ShadInfoMap, pShaderData, new SShadInfo ( pShaderData, fPriority ) );
        pShadInfo = MapFindRef ( m_ShadInfoMap, pShaderData );

        // Add to order map
        MapInsert ( m_OrderMap, pShadInfo->fOrderPriority, pShadInfo );
    }

    return pShadInfo;
}
Beispiel #6
0
CLuaCFunction* CLuaCFunctions::GetFunction ( lua_CFunction f )
{
    // Quick cull of unknown pointer range
    if ( IsNotFunction( f ) )
        return NULL;

    return MapFindRef ( ms_Functions, f );
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::ProcessConnect
//
//
//
///////////////////////////////////////////////////////////////
void CDatabaseJobQueueImpl::ProcessConnect ( CDbJobData* pJobData )
{
    // Determine which type manager to use
    std::vector < SString > parts;
    pJobData->command.strData.Split ( "\1", parts );
    if ( parts.size () < 5 )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = "Internal Error (JobQueueServer:ProcessConnect #1)";
        return;
    }

    CDatabaseType* pTypeManager = MapFindRef ( m_DatabaseTypeMap, parts[0] );
    if ( !pTypeManager )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = "Not valid type";
        return;
    }

    // Get type manager to return a CDatabaseConnection*
    CDatabaseConnection* pConnection = pTypeManager->Connect ( parts[1], parts[2], parts[3], parts[4] );
    if ( !pConnection )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = "Could not connect";
        return;
    }

    if ( !pConnection->IsValid () )
    {
        pJobData->result.status = EJobResult::FAIL;
        pJobData->result.strReason = pConnection->GetLastErrorMessage ();
        pConnection->Release ();
        return;
    }

    // Extract some options
    GetOption < CDbOptionsMap > ( parts[4], "log", pConnection->m_bLoggingEnabled, 0 );
    GetOption < CDbOptionsMap > ( parts[4], "tag", pConnection->m_strLogTag );
    GetOption < CDbOptionsMap > ( parts[4], "suppress", ",", pConnection->m_SuppressedErrorCodes );

    // Only allow error codes to be suppress with mysql, as sqlite only has one error code
    if ( pTypeManager->GetDataSourceTag () != "mysql" )
        pConnection->m_SuppressedErrorCodes.clear ();

    // Associate handle with CDatabaseConnection*
    shared.m_Mutex.Lock();
    MapSet( shared.m_HandleConnectionMap, pJobData->command.connectionHandle, pConnection );
    shared.m_Mutex.Unlock();

    // Set result
    pJobData->result.status = EJobResult::SUCCESS;
}
////////////////////////////////////////////////////////////////
//
// CEffectClonerImpl::ReleaseD3DEffect
//
// Remove all refs to the d3d effect
//
////////////////////////////////////////////////////////////////
void CEffectClonerImpl::ReleaseD3DEffect ( ID3DXEffect* pD3DEffect )
{
    // Find pEffectTemplate from which this d3d effect was cloned from
    CEffectTemplate* pEffectTemplate = MapFindRef ( m_CloneMap, pD3DEffect );
    assert ( pEffectTemplate );

    // Remove from clone map
    MapRemove ( m_CloneMap, pD3DEffect );

    // Remove from pEffectTemplate. This will alse release the d3d effect.
    pEffectTemplate->UnCloneD3DEffect ( pD3DEffect );
}
Beispiel #9
0
const SBindableKey* CKeyBinds::GetBindableFromKey ( const char* szKey )
{
    // Map for faster lookup
    static std::map < SString, const SBindableKey* > bindableKeyMap;

    // Init map if required
    if ( bindableKeyMap.empty () )
        for ( int i = 0 ; *g_bkKeys [ i ].szKey != 0 ; i++ )
            MapSet ( bindableKeyMap, SStringX ( g_bkKeys [ i ].szKey ).ToLower (), &g_bkKeys [ i ] );

    return MapFindRef ( bindableKeyMap, SStringX ( szKey ).ToLower () );
}
Beispiel #10
0
const SBindableGTAControl* CKeyBinds::GetBindableFromControl ( const char* szControl )
{
    // Map for faster lookup
    static std::map < SString, const SBindableGTAControl* > bindableControlMap;

    // Init map if required
    if ( bindableControlMap.empty () )
        for ( int i = 0 ; *g_bcControls [ i ].szControl != 0 ; i++ )
            MapSet ( bindableControlMap, SStringX ( g_bcControls [ i ].szControl ).ToLower (), &g_bcControls [ i ] );

    return MapFindRef ( bindableControlMap, SStringX ( szControl ).ToLower () );
}
////////////////////////////////////////////////////////////////
//
// CEffectClonerImpl::CreateD3DEffect
//
//
//
////////////////////////////////////////////////////////////////
ID3DXEffect* CEffectClonerImpl::CreateD3DEffect ( const SString& strFilename, const SString& strRootPath, SString& strOutStatus, bool bDebug )
{
    // Do we have a match with the initial path
    CEffectTemplate* pEffectTemplate = MapFindRef ( m_ValidMap, ConformPathForSorting ( strFilename ) );
    if ( pEffectTemplate )
    {
        // Have files changed since create?
        if ( pEffectTemplate->HaveFilesChanged () )
        {
            // EffectTemplate is no good for cloning now, so move it to the old list 
            MapRemove ( m_ValidMap, ConformPathForSorting ( strFilename ) );
            m_OldList.push_back ( pEffectTemplate );
            pEffectTemplate = NULL;
        }
    }

    // Need to create new EffectTemplate?
    if ( !pEffectTemplate )
    {
        pEffectTemplate = NewEffectTemplate ( m_pManager, strFilename, strRootPath, strOutStatus, bDebug );
        if ( !pEffectTemplate->IsValid () )
        {
            SAFE_RELEASE( pEffectTemplate );
            return NULL;
        }

        OutputDebugLine ( SString ( "[Shader] CEffectClonerImpl::CreateD3DEffect - New EffectTemplate for %s", *strFilename ) );
        // Add to active map
        MapSet ( m_ValidMap, ConformPathForSorting ( strFilename ), pEffectTemplate );
    }


    //
    // Now we have a valid EffectTemplate to clone the effect from
    //

    // Clone D3DXEffect
    ID3DXEffect* pNewD3DEffect = pEffectTemplate->CloneD3DEffect ( &strOutStatus );

    if( !pNewD3DEffect )
    {
        if ( strOutStatus.empty () )
            strOutStatus = "Error: Clone failed";
        return NULL;
    }

    // Cross ref clone with original
    MapSet ( m_CloneMap, pNewD3DEffect, pEffectTemplate );

    // Return result
    return pNewD3DEffect;
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueManager::GetQueueFromConnectCommand
//
// Find existing queue or create new one
// Can't fail
//
///////////////////////////////////////////////////////////////
CDatabaseJobQueue* CDatabaseJobQueueManager::GetQueueFromConnectCommand(const SString& strData)
{
    // Extract queue name from options
    std::vector<SString> parts;
    strData.Split("\1", parts);
    SString strQueueName;
    GetOption<CDbOptionsMap>(parts[4], "queue", strQueueName);

    // Find queue with name
    CDatabaseJobQueue* pQueue = MapFindRef(m_QueueNameMap, strQueueName);
    if (!pQueue)
    {
        // Add new queue
        pQueue = NewDatabaseJobQueue();
        MapSet(m_QueueNameMap, strQueueName, pQueue);
    }
    return pQueue;
}
Beispiel #13
0
///////////////////////////////////////////////////////////////
//
// CResourceChecker::GetLuaFunctionNameUpgradeInfo
//
//
//
///////////////////////////////////////////////////////////////
ECheckerWhatType CResourceChecker::GetLuaFunctionNameUpgradeInfo ( const string& strFunctionName, bool bClientScript, string& strOutHow )
{
    static CHashMap < SString, SDeprecatedItem* > clientUpgradeInfoMap;
    static CHashMap < SString, SDeprecatedItem* > serverUpgradeInfoMap;

    if ( clientUpgradeInfoMap.size () == 0 )
    {
        // Make maps to speed things up
        for ( uint i = 0 ; i < NUMELMS( clientDeprecatedList ) ; i++ )
            clientUpgradeInfoMap[ clientDeprecatedList[i].strOldName ] = &clientDeprecatedList[i];

        for ( uint i = 0 ; i < NUMELMS( serverDeprecatedList ) ; i++ )
            serverUpgradeInfoMap[ serverDeprecatedList[i].strOldName ] = &serverDeprecatedList[i];
    }

    // Query the correct map
    SDeprecatedItem* pItem = MapFindRef ( bClientScript ? clientUpgradeInfoMap : serverUpgradeInfoMap, strFunctionName );
    if ( !pItem )
        return ECheckerWhat::NONE;     // Nothing found

    strOutHow = pItem->strNewName;
    return pItem->bRemoved ? ECheckerWhat::REMOVED : ECheckerWhat::REPLACED;
}
Beispiel #14
0
CPlayer* CPlayerManager::Create ( const NetServerPlayerID& PlayerSocket )
{
    // Check socket is free
    CPlayer* pOtherPlayer = MapFindRef( m_SocketPlayerMap, PlayerSocket );
    if ( pOtherPlayer )
    {
        CLogger::ErrorPrintf ( "Attempt to re-use existing connection for player '%s'\n", pOtherPlayer->GetName().c_str() );
        return NULL;     
    }

    // Create the new player
    CPlayer* pPlayer = new CPlayer ( this, m_pScriptDebugging, PlayerSocket );

    // Invalid id?
    if ( pPlayer->GetID () == INVALID_ELEMENT_ID )
    {
        delete pPlayer;
        return NULL;
    }

    // Return the created player
    return pPlayer;
}
///////////////////////////////////////////////////////////////
//
// CDatabaseJobQueueImpl::FindCommandFromId
//
// Find job data with matching id
//
///////////////////////////////////////////////////////////////
CDbJobData* CDatabaseJobQueueImpl::FindCommandFromId ( SDbJobId id )
{
    return MapFindRef ( m_ActiveJobHandles, id );
}
///////////////////////////////////////////////////////////////////////////
//
// CSimPlayerManager::Get
//
// Thread:              sync
// CS should be locked: yes
//
// Get a sim player from a player socket
//
///////////////////////////////////////////////////////////////////////////
CSimPlayer* CSimPlayerManager::Get ( const NetServerPlayerID& PlayerSocket )
{
    dassert ( m_bIsLocked );
    return MapFindRef ( m_SocketSimMap, PlayerSocket );
}
///////////////////////////////////////////////////////////////
//
// CGameEntityXRefManagerImpl::FindClientEntity
//
// Find the client entity that is using the supplied game entity interface
//
///////////////////////////////////////////////////////////////
CClientEntity* CGameEntityXRefManagerImpl::FindClientEntity ( CEntitySAInterface* pEntitySAInterface )
{
    return MapFindRef ( m_InterfaceToClientMap, pEntitySAInterface );
}
///////////////////////////////////////////////////////////////
//
// CGameEntityXRefManagerImpl::FindClientEntity
//
// Find the client entity that is using the supplied game entity
//
///////////////////////////////////////////////////////////////
CClientEntity* CGameEntityXRefManagerImpl::FindClientEntity ( CEntity* pEntitySA )
{
    return MapFindRef ( m_GameToClientMap, pEntitySA );
}
Beispiel #19
0
CPlayer* CPlayerManager::Get ( const NetServerPlayerID& PlayerSocket )
{
    return MapFindRef ( m_SocketPlayerMap, PlayerSocket );
}