bool CResourceClientScriptsPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    if ( m_vecItems.size() == 0 )
        return false;

    BitStream.Write ( m_pResource->GetNetID() );

    unsigned short usItemCount = m_vecItems.size();
    BitStream.Write ( usItemCount );

    for ( std::vector<CResourceClientScriptItem*>::const_iterator iter = m_vecItems.begin ();
          iter != m_vecItems.end();
          ++iter )
    {
        if ( BitStream.Version() >= 0x50 )
            BitStream.WriteString( (*iter)->GetName() );

        const SString& data = (*iter)->GetSourceCode ();
        unsigned int len = data.length ();
        BitStream.Write ( len );
        BitStream.Write ( data.c_str(), len );
    }

    return true;
}
Exemplo n.º 2
0
void CPlayerRPCs::TakePlayerScreenShot ( NetBitStreamInterface& bitStream )
{
    ushort usSizeX;
    ushort usSizeY;
    SString strTag;
    uchar ucQuality;
    uint uiMaxBandwidth;
    ushort usMaxPacketSize;
    CResource* pResource;
    uint uiServerSentTime;

    bitStream.Read ( usSizeX );
    bitStream.Read ( usSizeY );
    bitStream.ReadString ( strTag );
    bitStream.Read ( ucQuality );
    bitStream.Read ( uiMaxBandwidth );
    bitStream.Read ( usMaxPacketSize );
    if ( bitStream.Version() >= 0x53 )
    {
        ushort usResourceNetId;
        bitStream.Read ( usResourceNetId );
        pResource = g_pClientGame->GetResourceManager ()->GetResourceFromNetID ( usResourceNetId );
    }
    else
    {
        SString strResourceName;
        bitStream.ReadString ( strResourceName );
        pResource = g_pClientGame->GetResourceManager ()->GetResource ( strResourceName );
    }

    if ( !bitStream.Read ( uiServerSentTime ) )
        return;

    m_pClientGame->TakePlayerScreenShot ( usSizeX, usSizeY, strTag, ucQuality, uiMaxBandwidth, usMaxPacketSize, pResource, uiServerSentTime );        
}
bool CPlayerJoinCompletePacket::Write ( NetBitStreamInterface& BitStream ) const
{
    BitStream.Write ( m_PlayerID );
    BitStream.Write ( m_ucNumberOfPlayers );
    BitStream.Write ( m_RootElementID );

    // Transmit server requirement for the client to check settings
    BitStream.Write ( m_iEnableClientChecks );

    // Transmit whether or not the Voice is enabled
    BitStream.WriteBit ( m_bVoiceEnabled );

    // Transmit the sample rate for voice
    SIntegerSync < unsigned char, 2 > sampleRate ( m_ucSampleRate );
    BitStream.Write ( &sampleRate );

    // Transmit the quality for voice
    SIntegerSync < unsigned char, 4 > voiceQuality ( m_ucQuality );
    BitStream.Write ( &voiceQuality );

    // Transmit the max bitrate for voice
    BitStream.WriteCompressed ( m_uiBitrate );

    // Tellclient about maybe throttling back http client requests
    BitStream.Write ( m_iHTTPMaxConnectionsPerClient );

    BitStream.Write ( static_cast < unsigned char > ( m_ucHTTPDownloadType ) );

    switch ( m_ucHTTPDownloadType )
    {
    case HTTP_DOWNLOAD_ENABLED_PORT:
        {
            BitStream.Write ( m_usHTTPDownloadPort );
        }

        break;
    case HTTP_DOWNLOAD_ENABLED_URL:
        {
            // Internal http server port
            if ( BitStream.Version() >= 0x48 )
                BitStream.Write( m_usHTTPDownloadPort );

            // External http server URL
            BitStream.WriteString ( m_strHTTPDownloadURL );
        }

        break;
    default:
        break;
    }

    return true;
}
Exemplo n.º 4
0
void CWorldRPCs::SetAircraftMaxVelocity(NetBitStreamInterface& bitStream)
{
    float fVelocity;

    if (bitStream.Version() >= 0x3E)
    {
        if (bitStream.Read(fVelocity))
        {
            g_pGame->GetWorld()->SetAircraftMaxVelocity(fVelocity);
        }
    }
}
bool CPlayerConnectCompletePacket::Write ( NetBitStreamInterface& BitStream ) const
{
    // Send the connection string
    SString strConnText ( "%s %s [%s]", MTA_DM_FULL_STRING, MTA_DM_VERSIONSTRING, MTA_OS_STRING );
    BitStream.WriteString ( strConnText.Left ( MAX_CONN_TEXT_LEN ) );

    // Send the full server version
    if ( BitStream.Version () >= 0x29 )
        BitStream.WriteString ( CStaticFunctionDefinitions::GetVersionSortable () );

    return true;
}
Exemplo n.º 6
0
bool CLuaArguments::ReadFromBitStream(NetBitStreamInterface& bitStream, std::vector<CLuaArguments*>* pKnownTables)
{
    bool bKnownTablesCreated = false;
    if (!pKnownTables)
    {
        pKnownTables = new std::vector<CLuaArguments*>();
        bKnownTablesCreated = true;
    }

    unsigned int uiNumArgs;
    bool         bResult;
#if MTA_DM_VERSION >= 0x150
    bResult = bitStream.ReadCompressed(uiNumArgs);
#else
    unsigned short usNumArgs;
    if (bitStream.Version() < 0x05B)
    {
        // We got the old version
        bResult = bitStream.ReadCompressed(usNumArgs);
        uiNumArgs = usNumArgs;
    }
    else
    {
        // Check if we got the new version
        if ((bResult = bitStream.ReadCompressed(usNumArgs)))
        {
            if (usNumArgs == 0xFFFF)
                // We got the new version
                bResult = bitStream.ReadCompressed(uiNumArgs);
            else
                // We got the old version
                uiNumArgs = usNumArgs;
        }
    }
#endif

    if (bResult)
    {
        pKnownTables->push_back(this);
        for (unsigned int ui = 0; ui < uiNumArgs; ++ui)
        {
            CLuaArgument* pArgument = new CLuaArgument(bitStream, pKnownTables);
            m_Arguments.push_back(pArgument);
        }
    }

    if (bKnownTablesCreated)
        delete pKnownTables;

    return true;
}
Exemplo n.º 7
0
void CWorldRPCs::RestoreWorldModel(NetBitStreamInterface& bitStream)
{
    unsigned short usModel = 0;
    float          fRadius = 0.0f, fX = 0.0f, fY = 0.0f, fZ = 0.0f;
    char           cInterior = -1;
    if (bitStream.Read(usModel) && bitStream.Read(fRadius) && bitStream.Read(fX) && bitStream.Read(fY) && bitStream.Read(fZ))
    {
        if (bitStream.Version() >= 0x039)
        {
            bitStream.Read(cInterior);
        }
        g_pGame->GetWorld()->RestoreBuilding(usModel, fRadius, fX, fY, fZ, cInterior);
    }
}
Exemplo n.º 8
0
bool CVehicleResyncPacket::Write ( NetBitStreamInterface& BitStream ) const 
{
    if ( !m_pVehicle )
        return false;

    BitStream.Write ( m_pVehicle->GetID() );

    // Write vehicle position and rotation
    SPositionSync position ( false );
    position.data.vecPosition = m_pVehicle->GetPosition();
    BitStream.Write ( &position );

    SRotationDegreesSync rotation;
    m_pVehicle->GetRotationDegrees ( rotation.data.vecRotation );
    BitStream.Write ( &rotation );

    // Write the movespeed
    SVelocitySync velocity;
    velocity.data.vecVelocity = m_pVehicle->GetVelocity ();
    BitStream.Write ( &velocity );

    // Write the turnspeed
    SVelocitySync turnSpeed;
    turnSpeed.data.vecVelocity = m_pVehicle->GetTurnSpeed ();
    BitStream.Write ( &turnSpeed );

    // Write the vehicle health
    SVehicleHealthSync health;
    health.data.fValue = m_pVehicle->GetHealth ();
    BitStream.Write ( &health );

    // Write parts state
    if ( BitStream.Version() >= 0x5D )
    {
        SVehicleDamageSyncMethodeB damage;
        damage.data.bSyncDoors = true;
        damage.data.bSyncWheels = true;
        damage.data.bSyncPanels = true;
        damage.data.bSyncLights = true;
        damage.data.doors.data.ucStates = m_pVehicle->m_ucDoorStates;
        damage.data.wheels.data.ucStates = m_pVehicle->m_ucWheelStates;
        damage.data.panels.data.ucStates = m_pVehicle->m_ucPanelStates;
        damage.data.lights.data.ucStates = m_pVehicle->m_ucLightStates;
        BitStream.Write ( &damage );
    }

    return true;
}
Exemplo n.º 9
0
void CObjectRPCs::SetObjectScale ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    CDeathmatchObject* pObject = static_cast < CDeathmatchObject* > ( m_pObjectManager->Get ( pSource->GetID () ) );
    if ( pObject )
    {
        CVector vecScale;
        
        bitStream.Read ( vecScale.fX );
        vecScale.fY = vecScale.fX;
        vecScale.fZ = vecScale.fX;
        if( bitStream.Version () >= 0x40 )
        {
             bitStream.Read ( vecScale.fY );
             bitStream.Read ( vecScale.fZ );
        }
        pObject->SetScale ( vecScale );
    }
}
Exemplo n.º 10
0
bool CLuaArguments::WriteToBitStream(NetBitStreamInterface& bitStream, CFastHashMap<CLuaArguments*, unsigned long>* pKnownTables) const
{
    bool bKnownTablesCreated = false;
    if (!pKnownTables)
    {
        pKnownTables = new CFastHashMap<CLuaArguments*, unsigned long>();
        bKnownTablesCreated = true;
    }

    bool bSuccess = true;
    pKnownTables->insert(make_pair((CLuaArguments*)this, pKnownTables->size()));

#if MTA_DM_VERSION >= 0x150
    bitStream.WriteCompressed(static_cast<unsigned int>(m_Arguments.size()));
#else
    if (bitStream.Version() < 0x05B)
        bitStream.WriteCompressed(static_cast<unsigned short>(m_Arguments.size()));
    else
        bitStream.WriteCompressed(static_cast<unsigned int>(m_Arguments.size()));
#endif

    vector<CLuaArgument*>::const_iterator iter = m_Arguments.begin();
    for (; iter != m_Arguments.end(); iter++)
    {
        CLuaArgument* pArgument = *iter;
        if (!pArgument->WriteToBitStream(bitStream, pKnownTables))
        {
            bSuccess = false;
        }
    }

    if (bKnownTablesCreated)
        delete pKnownTables;

    return bSuccess;
}
Exemplo n.º 11
0
bool CLuaArgument::WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables ) const
{
    SLuaTypeSync type;

    switch ( GetType () )
    {
        // Nil type
        case LUA_TNIL:
        {
            type.data.ucType = LUA_TNIL;
            bitStream.Write ( &type );
            break;
        }

        // Boolean type
        case LUA_TBOOLEAN:
        {
            type.data.ucType = LUA_TBOOLEAN;
            bitStream.Write ( &type );

            // Write the boolean to it
            bitStream.WriteBit ( GetBoolean () );
            break;
        }

        // Table argument
        case LUA_TTABLE:
        {
            ulong* pThingy;
            if ( pKnownTables && ( pThingy = MapFind ( *pKnownTables, m_pTableData ) ) )
            {
                // Self-referencing table
                type.data.ucType = LUA_TTABLEREF;
                bitStream.Write ( &type );
                bitStream.WriteCompressed ( *pThingy );
            }
            else
            {
                type.data.ucType = LUA_TTABLE;
                bitStream.Write ( &type );

                // Write the subtable to the bitstream
                m_pTableData->WriteToBitStream ( bitStream, pKnownTables );
            }
            break;
        }

        // Number argument?
        case LUA_TNUMBER:
        {
            type.data.ucType = LUA_TNUMBER;
            bitStream.Write ( &type );
            float fNumber = static_cast < float > ( GetNumber () );
            long lNumber = static_cast < long > ( fNumber );
            float fNumberInteger = static_cast < float > ( lNumber );

            // Check if the number is an integer and can fit a long datatype
            if ( fabs ( fNumber ) > fabs ( fNumberInteger + 1 ) ||
                 fabs ( fNumber - fNumberInteger ) >= FLOAT_EPSILON )
            {
                bitStream.WriteBit ( true );
                bitStream.Write ( fNumber );
            }
            else
            {
                bitStream.WriteBit ( false );
                bitStream.WriteCompressed ( lNumber );
            }
            break;
        }

        // String argument
        case LUA_TSTRING:
        {           
            // Grab the string and its length. Is it short enough to be sendable?
            const char* szTemp = m_strString.c_str ();
            size_t sizeTemp = m_strString.length ();
            unsigned short usLength = static_cast < unsigned short > ( sizeTemp );
            if ( sizeTemp == usLength )
            {
                // This is a string argument
                type.data.ucType = LUA_TSTRING;
                bitStream.Write ( &type );

                // Write its length
                bitStream.WriteCompressed ( usLength );

                // Write the content too if it's not empty
                if ( usLength > 0 )
                {
                    bitStream.Write ( szTemp, usLength );
                }
            }
            else
            if ( sizeTemp > 65535 && bitStream.Version () >= 0x027 && g_pGame->CalculateMinClientRequirement () >= LONG_STRING_MIN_VERSION )
            {
                // This is a long string argument
                type.data.ucType = LUA_TSTRING_LONG;
                bitStream.Write ( &type );

                // Write its length
                uint uiLength = sizeTemp;
                bitStream.WriteCompressed ( uiLength );

                // Write the content too if it's not empty
                if ( uiLength > 0 )
                {
                    bitStream.AlignWriteToByteBoundary ();
                    bitStream.Write ( szTemp, uiLength );
                }
            }
            else
            {
                // Too long string
                LogUnableToPacketize ( "Couldn't packetize argument list. Invalid string specified, limit is 65535 characters."
                                       " To use longer strings, set script <min_mta_version> to " LONG_STRING_MIN_VERSION " or higher." );

                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write ( &type );
                return false;
            }
            break;
        }

        // Element argument
        case LUA_TLIGHTUSERDATA:
        {
            // Grab the element from this userdata pointer. Valid and has a synced element ID?
            CElement* pElement = GetElement ();
            if ( pElement && pElement->GetID () != INVALID_ELEMENT_ID )
            {
                // Write its ID
                type.data.ucType = LUA_TLIGHTUSERDATA;
                bitStream.Write ( &type );
                bitStream.Write ( pElement->GetID () );
            }
            else
            {
                // Jax: this just spams the script debugger, it's not really neccesary
                // LogUnableToPacketize ( "Couldn't packetize argument list, invalid element specified." );

                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write ( &type );
                return false;
            }

            break;
        }

        // Unpacketizable type.
        default:
        {
            // Unpacketizable
            LogUnableToPacketize ( "Couldn't packetize argument list, unknown type specified." );

            // Write a nil though so other side won't get out of sync
            type.data.ucType = LUA_TNIL;
            bitStream.Write ( &type );
            return false;
        }
    }

    // Success
    return true;
}
Exemplo n.º 12
0
void CWorldRPCs::SetWeaponProperty(NetBitStreamInterface& bitStream)
{
    unsigned char ucWeapon = 0;
    unsigned char ucProperty = 0;
    unsigned char ucWeaponSkill = 0;
    float         fData = 0.0f;
    short         sData = 0;
    if (bitStream.Read(ucWeapon) && bitStream.Read(ucProperty) && bitStream.Read(ucWeaponSkill))
    {
        CWeaponStat* pWeaponInfo =
            g_pGame->GetWeaponStatManager()->GetWeaponStats(static_cast<eWeaponType>(ucWeapon), static_cast<eWeaponSkill>(ucWeaponSkill));
        switch (ucProperty)
        {
            case WEAPON_WEAPON_RANGE:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponRange(fData);
                break;
            }
            case WEAPON_TARGET_RANGE:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetTargetRange(fData);
                break;
            }
            case WEAPON_ACCURACY:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetAccuracy(fData);
                break;
            }
            case WEAPON_LIFE_SPAN:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetLifeSpan(fData);
                break;
            }
            case WEAPON_FIRING_SPEED:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetFiringSpeed(fData);
                break;
            }
            case WEAPON_MOVE_SPEED:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetMoveSpeed(fData);
                break;
            }
            case WEAPON_ANIM_LOOP_START:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponAnimLoopStart(fData);
                break;
            }
            case WEAPON_ANIM_LOOP_STOP:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponAnimLoopStop(fData);
                break;
            }
            case WEAPON_ANIM_LOOP_RELEASE_BULLET_TIME:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponAnimLoopFireTime(fData);
                break;
            }

            case WEAPON_ANIM2_LOOP_START:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponAnim2LoopStart(fData);
                break;
            }
            case WEAPON_ANIM2_LOOP_STOP:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponAnim2LoopStop(fData);
                break;
            }
            case WEAPON_ANIM2_LOOP_RELEASE_BULLET_TIME:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponAnim2LoopFireTime(fData);
                break;
            }

            case WEAPON_ANIM_BREAKOUT_TIME:
            {
                bitStream.Read(fData);
                pWeaponInfo->SetWeaponAnimBreakoutTime(fData);
                break;
            }
            case WEAPON_DAMAGE:
            {
                bitStream.Read(sData);
                pWeaponInfo->SetDamagePerHit(sData);
                break;
            }
            case WEAPON_MAX_CLIP_AMMO:
            {
                bitStream.Read(sData);
                pWeaponInfo->SetMaximumClipAmmo(sData);
                break;
            }
            case WEAPON_FLAGS:
            {
                int iData = 0;
                if (bitStream.Version() < 0x57)
                {
                    bitStream.Read(sData);
                    iData = sData;
                }
                else
                    bitStream.Read(iData);

                pWeaponInfo->ToggleFlagBits(iData);
                break;
            }
            case WEAPON_ANIM_GROUP:
            {
                bitStream.Read(sData);
                pWeaponInfo->SetAnimGroup(sData);
                break;
            }
            case WEAPON_FLAG_AIM_NO_AUTO:
            case WEAPON_FLAG_AIM_ARM:
            case WEAPON_FLAG_AIM_1ST_PERSON:
            case WEAPON_FLAG_AIM_FREE:
            case WEAPON_FLAG_MOVE_AND_AIM:
            case WEAPON_FLAG_MOVE_AND_SHOOT:
            case WEAPON_FLAG_TYPE_THROW:
            case WEAPON_FLAG_TYPE_HEAVY:
            case WEAPON_FLAG_TYPE_CONSTANT:
            case WEAPON_FLAG_TYPE_DUAL:
            case WEAPON_FLAG_ANIM_RELOAD:
            case WEAPON_FLAG_ANIM_CROUCH:
            case WEAPON_FLAG_ANIM_RELOAD_LOOP:
            case WEAPON_FLAG_ANIM_RELOAD_LONG:
            case WEAPON_FLAG_SHOT_SLOWS:
            case WEAPON_FLAG_SHOT_RAND_SPEED:
            case WEAPON_FLAG_SHOT_ANIM_ABRUPT:
            case WEAPON_FLAG_SHOT_EXPANDS:
            {
                bool bEnable;
                bitStream.ReadBit(bEnable);
                uint uiFlagBit = GetWeaponPropertyFlagBit((eWeaponProperty)ucProperty);
                if (bEnable)
                    pWeaponInfo->SetFlagBits(uiFlagBit);
                else
                    pWeaponInfo->ClearFlagBits(uiFlagBit);
                break;
            }
        }
    }
}
Exemplo n.º 13
0
///////////////////////////////////////////////////////////////
//
// CLatentSendQueue::DoPulse
//
// Send next part of the active transfer
//
///////////////////////////////////////////////////////////////
void CLatentSendQueue::DoPulse ( int iTimeMsBetweenCalls )
{
    if ( m_TxQueue.empty () )
    {
        m_iBytesOwing = 0;
        return;
    }

    // Check if previous tx has completed
    if ( m_TxQueue.front ().uiReadPosition == m_TxQueue.front ().bufferRef->GetSize () && m_TxQueue.front ().bSendFinishing )
    {
        m_TxQueue.pop_front ();
        PostQueueRemove ();
        if ( m_TxQueue.empty () )
        {
            m_iBytesOwing = 0;
            return;
        }
    }

    m_uiCurrentRate = Max < uint > ( MIN_SEND_RATE, m_uiCurrentRate );

    // How many bytes to send this pulse
    int iBytesToSendThisPulse = iTimeMsBetweenCalls * m_uiCurrentRate / 1000;

    // Add bytes owing from last pulse
    iBytesToSendThisPulse += m_iBytesOwing;

    // Calc packet size depending on rate
    uint uiMaxPacketSize = Lerp ( MIN_PACKET_SIZE, UnlerpClamped ( MIN_PACKET_SIZE * 10, m_uiCurrentRate, MAX_PACKET_SIZE * 15 ), MAX_PACKET_SIZE );

    // Calc how many packets to do this pulse
    uint uiNumPackets = iBytesToSendThisPulse / uiMaxPacketSize;

    // Update carry over
    m_iBytesOwing = iBytesToSendThisPulse % uiMaxPacketSize;

    // Process item at front of queue
    SSendItem& activeTx = m_TxQueue.front ();
    for ( uint i = 0 ; i < uiNumPackets && !activeTx.bSendFinishing ; i++ )
    {
        // Send next part of data    
        NetBitStreamInterface* pBitStream = DoAllocateNetBitStream ( m_RemoteId, m_usBitStreamVersion );
        pBitStream->WriteBits ( &activeTx.uiId, 15 );

        // Next bit indicates if it has a special flag
        if ( activeTx.uiReadPosition == 0 )
        {
            // Head
            pBitStream->WriteBit ( 1 );
            pBitStream->Write ( (uchar)FLAG_HEAD );
            pBitStream->Write ( activeTx.usCategory );
            pBitStream->Write ( activeTx.bufferRef->GetSize () );
            pBitStream->Write ( activeTx.uiRate );
            if ( pBitStream->Version () >= 0x31 )
                pBitStream->Write ( activeTx.usResourceNetId );
            activeTx.bSendStarted = true;
        }
        else
        if ( activeTx.bufferRef->GetSize () == activeTx.uiReadPosition )
        {
            // Tail
            pBitStream->WriteBit ( 1 );
            pBitStream->Write ( (uchar)FLAG_TAIL );
            activeTx.bSendFinishing = true;
        }
        else
        {
            // Body
            pBitStream->WriteBit ( 0 );
        }

        // Align to next boundary
        pBitStream->AlignWriteToByteBoundary ();
        uint uiMaxDataSize = Max < int > ( 10, uiMaxPacketSize - pBitStream->GetNumberOfBytesUsed () );

        // Calc how much data to send
        uint uiDataOffset = activeTx.uiReadPosition;
        uint uiSizeToSend = Min ( uiMaxDataSize, activeTx.bufferRef->GetSize () - activeTx.uiReadPosition );
        activeTx.uiReadPosition += uiSizeToSend;

        pBitStream->Write ( (ushort)uiSizeToSend );
        pBitStream->Write ( activeTx.bufferRef->GetData () + uiDataOffset, uiSizeToSend );

        // Send
        DoSendPacket ( PACKET_ID_LATENT_TRANSFER, m_RemoteId, pBitStream, PACKET_PRIORITY_LOW, PACKET_RELIABILITY_RELIABLE_ORDERED, PACKET_ORDERING_DATA_TRANSFER );
        DoDeallocateNetBitStream ( pBitStream );
    }
}
Exemplo n.º 14
0
bool CMapInfoPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    // Write the map weather
    BitStream.Write ( m_ucWeather );
    BitStream.Write ( m_ucWeatherBlendingTo );
    BitStream.Write ( m_ucBlendedWeatherHour );

    BitStream.WriteBit ( m_bHasSkyGradient );
    if ( m_bHasSkyGradient )
    {
        BitStream.Write ( m_ucSkyGradientTR );
        BitStream.Write ( m_ucSkyGradientTG );
        BitStream.Write ( m_ucSkyGradientTB );
        BitStream.Write ( m_ucSkyGradientBR );
        BitStream.Write ( m_ucSkyGradientBG );
        BitStream.Write ( m_ucSkyGradientBB );
    }

    // Write heat haze
    BitStream.WriteBit ( m_bHasHeatHaze );
    if ( m_bHasHeatHaze )
    {
        SHeatHazeSync heatHaze ( m_HeatHazeSettings );
        BitStream.Write ( &heatHaze );
    }

    // Write the map hour
    BitStream.Write ( m_ucClockHour );
    BitStream.Write ( m_ucClockMin );

    BitStream.WriteCompressed ( m_ulMinuteDuration );

    // Write the map flags
    SMapInfoFlagsSync flags;
    flags.data.bShowNametags  = m_bShowNametags;
    flags.data.bShowRadar     = m_bShowRadar;
    flags.data.bCloudsEnabled = m_bCloudsEnabled;
    BitStream.Write ( &flags );

    // Write any other world conditions
    BitStream.Write ( m_fGravity );
    if ( m_fGameSpeed == 1.0f )
        BitStream.WriteBit ( true );
    else
    {
        BitStream.WriteBit ( false );
        BitStream.Write ( m_fGameSpeed );
    }
    BitStream.Write ( m_fWaveHeight );
    // Write world water level
    BitStream.Write ( m_WorldWaterLevelInfo.fSeaLevel );
    BitStream.WriteBit ( m_WorldWaterLevelInfo.bNonSeaLevelSet );
    if ( m_WorldWaterLevelInfo.bNonSeaLevelSet )
        BitStream.Write ( m_WorldWaterLevelInfo.fNonSeaLevel );

    BitStream.WriteCompressed ( m_usFPSLimit );

    // Write the garage states
    for ( unsigned char i = 0 ; i < MAX_GARAGES ; i++ )
    {
        const SGarageStates& garageStates = *m_pGarageStates;
        BitStream.WriteBit( garageStates[i] );
    }

    // Write the fun bugs state
    SFunBugsStateSync funBugs;
    funBugs.data.bQuickReload = g_pGame->IsGlitchEnabled ( CGame::GLITCH_QUICKRELOAD );
    funBugs.data.bFastFire    = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTFIRE );
    funBugs.data.bFastMove    = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTMOVE );
    funBugs.data.bCrouchBug   = g_pGame->IsGlitchEnabled ( CGame::GLITCH_CROUCHBUG );
    funBugs.data.bCloseRangeDamage = g_pGame->IsGlitchEnabled ( CGame::GLITCH_CLOSEDAMAGE );
    funBugs.data2.bHitAnim    = g_pGame->IsGlitchEnabled ( CGame::GLITCH_HITANIM );
    funBugs.data3.bFastSprint = g_pGame->IsGlitchEnabled ( CGame::GLITCH_FASTSPRINT );
    BitStream.Write ( &funBugs );

    BitStream.Write ( m_fJetpackMaxHeight );

    BitStream.WriteBit ( m_bOverrideWaterColor );
    if ( m_bOverrideWaterColor )
    {
        BitStream.Write ( m_ucWaterRed );
        BitStream.Write ( m_ucWaterGreen );
        BitStream.Write ( m_ucWaterBlue );
        BitStream.Write ( m_ucWaterAlpha );
    }

    // Interior sounds
    BitStream.WriteBit ( m_bInteriorSoundsEnabled );

    // Rain level
    BitStream.WriteBit ( m_bOverrideRainLevel );
    if ( m_bOverrideRainLevel )
    {
        BitStream.Write ( m_fRainLevel );
    }

    // Moon size
    if ( BitStream.Version () >= 0x40 )
    {
        BitStream.WriteBit ( m_bOverrideMoonSize );
        if ( m_bOverrideMoonSize )
        {
            BitStream.Write ( m_iMoonSize );
        }
    }

    // Sun size
    BitStream.WriteBit ( m_bOverrideSunSize );
    if ( m_bOverrideSunSize )
    {
        BitStream.Write ( m_fSunSize );
    }

    // Sun color
    BitStream.WriteBit ( m_bOverrideSunColor );
    if ( m_bOverrideSunColor )
    {
        BitStream.Write ( m_ucSunCoreR );
        BitStream.Write ( m_ucSunCoreG );
        BitStream.Write ( m_ucSunCoreB );
        BitStream.Write ( m_ucSunCoronaR );
        BitStream.Write ( m_ucSunCoronaG );
        BitStream.Write ( m_ucSunCoronaB );
    }

    // Wind velocity
    BitStream.WriteBit ( m_bOverrideWindVelocity );
    if ( m_bOverrideWindVelocity )
    {
        BitStream.Write ( m_fWindVelX );
        BitStream.Write ( m_fWindVelY );
        BitStream.Write ( m_fWindVelZ );
    }

    // Far clip distance
    BitStream.WriteBit ( m_bOverrideFarClipDistance );
    if ( m_bOverrideFarClipDistance )
    {
        BitStream.Write ( m_fFarClip );
    }

    // Fog distance
    BitStream.WriteBit ( m_bOverrideFogDistance );
    if ( m_bOverrideFogDistance )
    {
        BitStream.Write ( m_fFogDistance );
    }

    BitStream.Write ( m_fAircraftMaxHeight );

    if ( BitStream.Version () >= 0x3E ) 
        BitStream.Write ( m_fAircraftMaxVelocity );
    
    if ( BitStream.Version () >= 0x30 )
    {
        for (int i = WEAPONTYPE_BRASSKNUCKLE; i < WEAPONTYPE_PISTOL; i++)
        {
            bool bEnabled;
            bEnabled = g_pGame->GetJetpackWeaponEnabled ( (eWeaponType) i );
            BitStream.WriteBit ( bEnabled );
        }
    }
    for (int i = WEAPONTYPE_PISTOL;i <= WEAPONTYPE_EXTINGUISHER;i++)
    {
        sWeaponPropertySync WeaponProperty;
        CWeaponStat* pWeaponStat = g_pGame->GetWeaponStatManager ()->GetWeaponStats( (eWeaponType)i );
        BitStream.WriteBit ( true );
        WeaponProperty.data.weaponType = (int)pWeaponStat->GetWeaponType();
        WeaponProperty.data.fAccuracy = pWeaponStat->GetAccuracy();
        WeaponProperty.data.fMoveSpeed = pWeaponStat->GetMoveSpeed();
        WeaponProperty.data.fTargetRange = pWeaponStat->GetTargetRange();
        WeaponProperty.data.fWeaponRange = pWeaponStat->GetWeaponRange();
        WeaponProperty.data.nAmmo = pWeaponStat->GetMaximumClipAmmo();
        WeaponProperty.data.nDamage = pWeaponStat->GetDamagePerHit();
        WeaponProperty.data.nFlags = pWeaponStat->GetFlags();

        WeaponProperty.data.anim_loop_start = pWeaponStat->GetWeaponAnimLoopStart();
        WeaponProperty.data.anim_loop_stop = pWeaponStat->GetWeaponAnimLoopStop();
        WeaponProperty.data.anim_loop_bullet_fire = pWeaponStat->GetWeaponAnimLoopFireTime();

        WeaponProperty.data.anim2_loop_start = pWeaponStat->GetWeaponAnim2LoopStart();
        WeaponProperty.data.anim2_loop_stop = pWeaponStat->GetWeaponAnim2LoopStop();
        WeaponProperty.data.anim2_loop_bullet_fire = pWeaponStat->GetWeaponAnim2LoopFireTime();

        WeaponProperty.data.anim_breakout_time = pWeaponStat->GetWeaponAnimBreakoutTime();
        BitStream.Write( &WeaponProperty );
        if ( BitStream.Version () >= 0x30 )
        {
            BitStream.WriteBit ( g_pGame->GetJetpackWeaponEnabled ( (eWeaponType) i ) );
        }
    }

    for (int i = WEAPONTYPE_PISTOL;i <= WEAPONTYPE_TEC9;i++)
    {
        sWeaponPropertySync WeaponProperty;
        BitStream.WriteBit ( true );
        for (int j = 0; j <= 2;j++)
        {
            CWeaponStat* pWeaponStat = g_pGame->GetWeaponStatManager ()->GetWeaponStats( (eWeaponType)i, (eWeaponSkill)j );
            WeaponProperty.data.weaponType = (int)pWeaponStat->GetWeaponType();
            WeaponProperty.data.fAccuracy = pWeaponStat->GetAccuracy();
            WeaponProperty.data.fMoveSpeed = pWeaponStat->GetMoveSpeed();
            WeaponProperty.data.fTargetRange = pWeaponStat->GetTargetRange();
            WeaponProperty.data.fWeaponRange = pWeaponStat->GetWeaponRange();
            WeaponProperty.data.nAmmo = pWeaponStat->GetMaximumClipAmmo();
            WeaponProperty.data.nDamage = pWeaponStat->GetDamagePerHit();
            WeaponProperty.data.nFlags = pWeaponStat->GetFlags();

            WeaponProperty.data.anim_loop_start = pWeaponStat->GetWeaponAnimLoopStart();
            WeaponProperty.data.anim_loop_stop = pWeaponStat->GetWeaponAnimLoopStop();
            WeaponProperty.data.anim_loop_bullet_fire = pWeaponStat->GetWeaponAnimLoopFireTime();

            WeaponProperty.data.anim2_loop_start = pWeaponStat->GetWeaponAnim2LoopStart();
            WeaponProperty.data.anim2_loop_stop = pWeaponStat->GetWeaponAnim2LoopStop();
            WeaponProperty.data.anim2_loop_bullet_fire = pWeaponStat->GetWeaponAnim2LoopFireTime();

            WeaponProperty.data.anim_breakout_time = pWeaponStat->GetWeaponAnimBreakoutTime();
            BitStream.Write( &WeaponProperty );
        }
        if ( BitStream.Version () >= 0x36 )
        {
            BitStream.WriteBit ( g_pGame->GetJetpackWeaponEnabled ( (eWeaponType) i ) );
        }
    }
    if ( BitStream.Version () >= 0x30 )
    {
        for (int i = WEAPONTYPE_CAMERA; i <= WEAPONTYPE_PARACHUTE; i++)
        {
            bool bEnabled;
            bEnabled = g_pGame->GetJetpackWeaponEnabled ( (eWeaponType) i );
            BitStream.WriteBit ( bEnabled );
        }
    }

    multimap< unsigned short, CBuildingRemoval* >::const_iterator iter = g_pGame->GetBuildingRemovalManager ( )->IterBegin();
    for (; iter != g_pGame->GetBuildingRemovalManager ( )->IterEnd();++iter)
    {
        CBuildingRemoval * pBuildingRemoval = (*iter).second;
        BitStream.WriteBit( true );
        BitStream.Write( pBuildingRemoval->GetModel ( ) );
        BitStream.Write( pBuildingRemoval->GetRadius ( ) );
        BitStream.Write( pBuildingRemoval->GetPosition ( ).fX );
        BitStream.Write( pBuildingRemoval->GetPosition ( ).fY );
        BitStream.Write( pBuildingRemoval->GetPosition ( ).fZ );
        if ( BitStream.Version() >= 0x039 )
        {
            BitStream.Write ( pBuildingRemoval->GetInterior ( ) );
        }
    }
    BitStream.WriteBit( false );

    if ( BitStream.Version () >= 0x25 )
    {
        bool bOcclusionsEnabled = g_pGame->GetOcclusionsEnabled ();
        BitStream.WriteBit( bOcclusionsEnabled );
    }

    return true;
}
Exemplo n.º 15
0
bool CPlayerListPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    // bool                  - show the "X has joined the game" messages?
    // [ following repeats <number of players joined> times ]
    // unsigned char  (1)    - assigned player id
    // unsigned char  (1)    - player nick length
    // unsigned char  (X)    - player nick (X = player nick length)
    // bool                  - is he dead?
    // bool                  - spawned? (following data only if this is TRUE)
    // unsigned char  (1)    - model id
    // unsigned char  (1)    - team id
    // bool                  - in a vehicle?
    // unsigned short (2)    - vehicle id (if vehicle)
    // unsigned char  (1)    - vehicle seat (if vehicle)
    // CVector        (12)   - position (if player)
    // float          (4)    - rotation (if player)
    // bool                  - has a jetpack?
    // unsigned short (2)    - dimension

    // Write the global flags
    BitStream.WriteBit ( m_bShowInChat );

    CPlayer* pPlayer = NULL;
    // Put each player in our list into the packet
    list < CPlayer* > ::const_iterator iter = m_List.begin ();
    for ( ; iter != m_List.end (); ++iter )
    {
        // Grab the real pointer
        pPlayer = *iter;

        // Write the player ID
        ElementID PlayerID = pPlayer->GetID ();
        BitStream.Write ( PlayerID );

        // Time sync context
        BitStream.Write ( pPlayer->GetSyncTimeContext () );

        // Write the nick length
        const char* szNickPointer = pPlayer->GetNick ();
        unsigned char ucNickLength = static_cast < unsigned char > ( strlen ( szNickPointer ) );
        if ( ucNickLength < MIN_NICK_LENGTH || ucNickLength > MAX_NICK_LENGTH )
        {
            BitStream.Write ( static_cast < unsigned char > ( 3 ) );
            BitStream.Write ( "???", 3 );
        }
        else
        {
            BitStream.Write ( ucNickLength );
            BitStream.Write ( szNickPointer, ucNickLength );
        }

        // Version info
        if ( BitStream.Version () >= 0x34 )
        {
            BitStream.Write ( pPlayer->GetBitStreamVersion () );
            SString strBuild = pPlayer->GetPlayerVersion ().SubStr ( 8 );
            uint uiBuildNumber = atoi ( strBuild );
            BitStream.Write ( uiBuildNumber );
        }

        // Flags
        bool bInVehicle = ( pPlayer->GetOccupiedVehicle () != NULL );
        BitStream.WriteBit ( pPlayer->IsDead () );  // Currently unused by the client
        BitStream.WriteBit ( true );                // (Was IsSpawned) Used by the client to determine if extra info was sent (in this packet)
        BitStream.WriteBit ( bInVehicle );
        BitStream.WriteBit ( pPlayer->HasJetPack () );
        BitStream.WriteBit ( pPlayer->IsNametagShowing () );
        BitStream.WriteBit ( pPlayer->IsNametagColorOverridden () );
        BitStream.WriteBit ( pPlayer->IsHeadless() );
        BitStream.WriteBit ( pPlayer->IsFrozen() );

        // Nametag stuff
        unsigned char ucNametagTextLength = 0;
        char* szNametagText = pPlayer->GetNametagText ();
        if ( szNametagText )
            ucNametagTextLength = static_cast < unsigned char > ( strlen ( szNametagText ) );

        BitStream.Write ( ucNametagTextLength );
        if ( ucNametagTextLength > 0 )
            BitStream.Write ( szNametagText, ucNametagTextLength );

        // Write nametag color if it's overridden
        if ( pPlayer->IsNametagColorOverridden () )
        {
            unsigned char ucR, ucG, ucB;
            pPlayer->GetNametagColor ( ucR, ucG, ucB );
            BitStream.Write ( ucR );
            BitStream.Write ( ucG );
            BitStream.Write ( ucB );
        }

        // Move anim
        if ( BitStream.Version() > 0x4B )
        {
            uchar ucMoveAnim = pPlayer->GetMoveAnim();
            BitStream.Write ( ucMoveAnim );
        }

        // Always send extra info (Was: "Write spawn info if he's spawned")
        if ( true )
        {
            // Player model ID
            BitStream.WriteCompressed ( pPlayer->GetModel () );

            // Team id
            CTeam* pTeam = pPlayer->GetTeam ();
            if ( pTeam )
            {
                BitStream.WriteBit ( true );
                BitStream.Write ( pTeam->GetID () );
            }
            else
                BitStream.WriteBit ( false );

            if ( bInVehicle )
            {
                // Grab the occupied vehicle
                CVehicle* pVehicle = pPlayer->GetOccupiedVehicle ();

                // Vehicle ID and seat
                BitStream.Write ( pVehicle->GetID () );

                SOccupiedSeatSync seat;
                seat.data.ucSeat = pPlayer->GetOccupiedVehicleSeat ();
                BitStream.Write ( &seat );
            }
            else
            {
                // Player position
                SPositionSync position ( false );
                position.data.vecPosition = pPlayer->GetPosition ();
                BitStream.Write ( &position );

                // Player rotation
                SPedRotationSync rotation;
                rotation.data.fRotation = pPlayer->GetRotation ();
                BitStream.Write ( &rotation );
            }

            BitStream.WriteCompressed ( pPlayer->GetDimension () );
            BitStream.Write ( pPlayer->GetFightingStyle () );

            SEntityAlphaSync alpha;
            alpha.data.ucAlpha = pPlayer->GetAlpha ();
            BitStream.Write ( &alpha );

            BitStream.Write ( pPlayer->GetInterior () );

            // Write the weapons of the player weapon slots
            for ( unsigned int i = 0; i < 16; ++i )
            {
                CWeapon* pWeapon = pPlayer->GetWeapon ( i );
                if ( pWeapon && pWeapon->ucType != 0 )
                {
                    BitStream.WriteBit ( true );
                    SWeaponTypeSync weaponType;
                    weaponType.data.ucWeaponType = pWeapon->ucType;
                    BitStream.Write ( &weaponType );
                }
                else
                    BitStream.WriteBit ( false );
            }
        }
    }

    return true;
}
Exemplo n.º 16
0
bool CLuaArgument::ReadFromBitStream ( NetBitStreamInterface& bitStream, std::vector < CLuaArguments* > * pKnownTables )
{
    DeleteTableData ();
    SLuaTypeSync type;

    // Read out the type
    if ( bitStream.Read ( &type ) )
    {
        // Depending on what type...
        switch ( type.data.ucType )
        {
            // Nil type
            case LUA_TNIL:
            {
                m_iType = LUA_TNIL;
                break;
            }

            // Boolean type
            case LUA_TBOOLEAN:
            {
                bool bValue;
                if ( bitStream.ReadBit ( bValue ) )
                    ReadBool ( bValue );
                break;
            }

            // Number type
            case LUA_TNUMBER:
            {
                if ( bitStream.Version() < 0x59 )
                {
                    // Old way
                    bool bIsFloatingPoint;
                    if ( bitStream.ReadBit ( bIsFloatingPoint ) && bIsFloatingPoint )
                    {
                        // Should be in high precision mode
                        dassert( g_pClientGame->IsHighFloatPrecision() );
                        float fNum;
                        if ( bitStream.Read ( fNum ) )
                            ReadNumber ( RoundFromFloatSource( fNum ) );
                    }
                    else
                    {
                        long lNum;
                        if ( bitStream.ReadCompressed ( lNum ) )
                            ReadNumber ( lNum );
                    }
                }
                else
                {
                    // New way - Maybe use double to better preserve > 32bit numbers
                    if ( bitStream.ReadBit() )
                    {
                        // Should be in high precision mode
                        dassert( g_pClientGame->IsHighFloatPrecision() );
                        if ( bitStream.ReadBit()  )
                        {
                            double dNum;
                            if ( bitStream.Read ( dNum ) )
                                ReadNumber ( dNum );
                        }
                        else
                        {
                            float fNum;
                            if ( bitStream.Read ( fNum ) )
                                ReadNumber ( RoundFromFloatSource( fNum ) );
                        }
                    }
                    else
                    {
                        long lNum;
                        if ( bitStream.ReadCompressed ( lNum ) )
                            ReadNumber ( lNum );
                    }
                }
                break;
            }

            // Table type
            case LUA_TTABLE:
            {
                m_pTableData = new CLuaArguments ( bitStream, pKnownTables );
                m_bWeakTableRef = false;
                m_iType = LUA_TTABLE;
                m_pTableData->ValidateTableKeys ();
                break;
            }

            // Table reference (self-referencing tables)
            case LUA_TTABLEREF:
            {
                unsigned long ulTableRef;
                if ( bitStream.ReadCompressed ( ulTableRef ) )
                {
                    if ( pKnownTables && ulTableRef < pKnownTables->size () )
                    {
                        m_pTableData = pKnownTables->at ( ulTableRef );
                        m_bWeakTableRef = true;
                        m_iType = LUA_TTABLE;
                    }
                }
                break;
            }

            // String type
            case LUA_TSTRING:
            {
                // Read out the string length
                unsigned short usLength;
                if ( bitStream.ReadCompressed ( usLength ) && usLength )
                {
                    // Allocate a buffer and read the string into it
                    char* szValue = new char [ usLength + 1 ];
                    if ( bitStream.Read ( szValue, usLength ) )
                    {
                        // Put it into us
                        ReadString ( std::string ( szValue, usLength ) );
                    }

                    // Delete the buffer
                    delete [] szValue;
                }
                else
                    ReadString ( "" );

                break;
            }

            // Long string type
            case LUA_TSTRING_LONG:
            {
                // Read out the string length
                uint uiLength;
                if ( bitStream.ReadCompressed ( uiLength ) && uiLength )
                {
                    bitStream.AlignReadToByteBoundary ();

                    // Allocate a buffer and read the string into it
                    char* szValue = new char [ uiLength + 1 ];
                    assert ( szValue );
                    if ( bitStream.Read ( szValue, uiLength ) )
                    {
                        // Put it into us
                        ReadString ( std::string ( szValue, uiLength ) );
                    }

                    // Delete the buffer
                    delete [] szValue;
                }
                else
                    ReadString ( "" );

                break;
            }

            // Element type
            case LUA_TLIGHTUSERDATA:
            case LUA_TUSERDATA:
            {
                // Read out the elemnt ID
                ElementID ElementID;
                if ( bitStream.Read ( ElementID ) )
                {
                    ReadElementID ( ElementID );
                }
                break;
            }
        }
    }
    return true;
}
Exemplo n.º 17
0
bool CLuaArgument::WriteToBitStream ( NetBitStreamInterface& bitStream, CFastHashMap < CLuaArguments*, unsigned long > * pKnownTables ) const
{
    SLuaTypeSync type;

    switch ( GetType () )
    {
        // Nil type
        case LUA_TNIL:
        {
            type.data.ucType = LUA_TNIL;
            bitStream.Write ( &type );
            break;
        }

        // Boolean type
        case LUA_TBOOLEAN:
        {
            type.data.ucType = LUA_TBOOLEAN;
            bitStream.Write ( &type );

            // Write the boolean to it
            bitStream.WriteBit ( GetBoolean () );
            break;
        }

        // Table argument
        case LUA_TTABLE:
        {
            ulong* pTableId;
            if ( pKnownTables && ( pTableId = MapFind ( *pKnownTables, m_pTableData ) ) )
            {
                // Self-referencing table
                type.data.ucType = LUA_TTABLEREF;
                bitStream.Write ( &type );
                bitStream.WriteCompressed ( *pTableId );
            }
            else
            {
                type.data.ucType = LUA_TTABLE;
                bitStream.Write ( &type );

                // Write the subtable to the bitstream
                m_pTableData->WriteToBitStream ( bitStream, pKnownTables );
            }
            break;
        }

        // Number argument?
        case LUA_TNUMBER:
        {
            type.data.ucType = LUA_TNUMBER;
            bitStream.Write ( &type );

            if ( bitStream.Version() < 0x59 )
            {
                // Old way
                int iNumber;
                if ( !ShouldUseInt( GetNumber(), &iNumber ) )
                {
                    bitStream.WriteBit ( true );
                    bitStream.Write ( static_cast < float > ( GetNumber() ) );
                }
                else
                {
                    bitStream.WriteBit ( false );
                    bitStream.WriteCompressed ( iNumber );
                }
            }
            else
            {
                // New way - Maybe use double to better preserve > 32bit numbers
                int iNumber;
                float fNumber;
                double dNumber;
                EDataType dataType = GetDataTypeToUse( GetNumber(), &iNumber, &fNumber, &dNumber );
                if ( dataType == DATA_TYPE_INT )
                {
                    bitStream.WriteBit ( false );
                    bitStream.WriteCompressed ( iNumber );
                }
                else
                if ( dataType == DATA_TYPE_FLOAT )
                {
                    bitStream.WriteBit ( true );
                    bitStream.WriteBit ( false );
                    bitStream.Write ( fNumber );
                }
                else
                {
                    bitStream.WriteBit ( true );
                    bitStream.WriteBit ( true );
                    bitStream.Write ( dNumber );
                }
            }
            break;
        }

        // String argument
        case LUA_TSTRING:
        {           
            // Grab the string and its length. Is it short enough to be sendable?
            const char* szTemp = m_strString.c_str ();
            size_t sizeTemp = m_strString.length ();
            unsigned short usLength = static_cast < unsigned short > ( sizeTemp );
            if ( sizeTemp == usLength )
            {
                // This is a string argument
                type.data.ucType = LUA_TSTRING;
                bitStream.Write ( &type );

                // Write its length
                bitStream.WriteCompressed ( usLength );

                // Write the content too if it's not empty
                if ( usLength > 0 )
                {
                    bitStream.Write ( szTemp, usLength );
                }
            }
            else
            {
                // This is a long string argument
                type.data.ucType = LUA_TSTRING_LONG;
                bitStream.Write ( &type );

                // Write its length
                uint uiLength = sizeTemp;
                bitStream.WriteCompressed ( uiLength );

                // Write the content too if it's not empty
                if ( uiLength > 0 )
                {
                    bitStream.AlignWriteToByteBoundary ();
                    bitStream.Write ( szTemp, uiLength );
                }
            }
            break;
        }

        // Element packet
        case LUA_TLIGHTUSERDATA:
        case LUA_TUSERDATA:
        {
            // Got a valid element to send?
            CClientEntity* pElement = GetElement ();
            if ( pElement )
            {
                // Clientside element?
                if ( !pElement->IsLocalEntity () )
                {
                    type.data.ucType = LUA_TLIGHTUSERDATA;
                    bitStream.Write ( &type );
                    bitStream.Write ( pElement->GetID () );
                }
                else
                {
                    // Write a nil though so other side won't get out of sync
                    type.data.ucType = LUA_TNIL;
                    bitStream.Write ( &type );
                    return false;
                }
            }
            else
            {
                // Write a nil though so other side won't get out of sync
                type.data.ucType = LUA_TNIL;
                bitStream.Write ( &type );
                return false;
            }
            break;
        }

        // Unpacketizable type.
        default:
        {
            // Unpacketizable
            LogUnableToPacketize ( "Couldn't packetize argument list, unknown type specified." );

            // Write a nil though so other side won't get out of sync
            type.data.ucType = LUA_TNIL;
            bitStream.Write ( &type );
            return false;
        }
    }

    // Success
    return true;
}
Exemplo n.º 18
0
bool CPlayerPuresyncPacket::Read ( NetBitStreamInterface& BitStream )
{
    if ( m_pSourceElement )
    {
        CPlayer * pSourcePlayer = static_cast < CPlayer * > ( m_pSourceElement );

        // Read out the time context
        unsigned char ucTimeContext = 0;
        if ( !BitStream.Read ( ucTimeContext ) )
            return false;

        // Only read this packet if it matches the current time context that
        // player is in.
        if ( !pSourcePlayer->CanUpdateSync ( ucTimeContext ) )
        {
            return false;
        }

        // Read out keys
        CControllerState ControllerState;
        ReadFullKeysync ( ControllerState, BitStream );
        pSourcePlayer->GetPad ()->NewControllerState ( ControllerState );

        // Read the flags
        SPlayerPuresyncFlags flags;
        if ( !BitStream.Read ( &flags ) )
            return false;

        pSourcePlayer->SetInWater ( flags.data.bIsInWater );
        pSourcePlayer->SetOnGround ( flags.data.bIsOnGround );
        pSourcePlayer->SetHasJetPack ( flags.data.bHasJetPack );
        pSourcePlayer->SetDucked ( flags.data.bIsDucked );
        pSourcePlayer->SetWearingGoggles ( flags.data.bWearsGoogles );
        pSourcePlayer->SetChoking ( flags.data.bIsChoking );
        pSourcePlayer->SetAkimboArmUp ( flags.data.bAkimboTargetUp );
        pSourcePlayer->SetOnFire ( flags.data.bIsOnFire );
        pSourcePlayer->SetStealthAiming ( flags.data.bStealthAiming );

        // Contact element
        CElement* pContactElement = NULL;
        if ( flags.data.bHasContact )
        {
            ElementID Temp;
            if ( !BitStream.ReadCompressed ( Temp ) )
                return false;
            pContactElement = CElementIDs::GetElement ( Temp );
        }
        CElement * pPreviousContactElement = pSourcePlayer->GetContactElement ();
        pSourcePlayer->SetContactElement ( pContactElement );

        if ( pPreviousContactElement != pContactElement )
        {
            // Call our onPlayerContact event
            CLuaArguments Arguments;
            if ( pPreviousContactElement )
                Arguments.PushElement ( pPreviousContactElement );
            else
                Arguments.PushNil ();
            if ( pContactElement )
                Arguments.PushElement ( pContactElement );
            else
                Arguments.PushNil ();

            pSourcePlayer->CallEvent ( "onPlayerContact", Arguments );
        }

        // Player position
        SPositionSync position ( false );
        if ( !BitStream.Read ( &position ) )
            return false;

        if ( pContactElement )
        {
            pSourcePlayer->SetContactPosition ( position.data.vecPosition );

            // Get the true position
            CVector vecTempPos = pContactElement->GetPosition ();
            position.data.vecPosition += vecTempPos;
        }
        pSourcePlayer->SetPosition ( position.data.vecPosition );

        // Player rotation
        SPedRotationSync rotation;
        if ( !BitStream.Read ( &rotation ) )
            return false;
        pSourcePlayer->SetRotation ( rotation.data.fRotation );

        // Move speed vector
        if ( flags.data.bSyncingVelocity )
        {
            SVelocitySync velocity;
            if ( !BitStream.Read ( &velocity ) )
                return false;
            pSourcePlayer->SetVelocity ( velocity.data.vecVelocity );
        }

        // Health ( stored with damage )
        SPlayerHealthSync health;
        if ( !BitStream.Read ( &health ) )
            return false;
        float fHealth = health.data.fValue;

        // Armor
        SPlayerArmorSync armor;
        if ( !BitStream.Read ( &armor ) )
            return false;

        float fArmor = armor.data.fValue;
        float fOldArmor = pSourcePlayer->GetArmor ();
        float fArmorLoss = fOldArmor - fArmor;

        pSourcePlayer->SetArmor ( fArmor );

        // Read out and set the camera rotation
        float fCameraRotation;
        if ( !BitStream.Read ( fCameraRotation ) )
            return false;
        pSourcePlayer->SetCameraRotation ( fCameraRotation );

        if ( flags.data.bHasAWeapon )
        {
            if ( BitStream.Version () >= 0x0d )
            {
                // Check client has the weapon we think he has
                unsigned char ucWeaponType;
                if ( !BitStream.Read ( ucWeaponType ) )
                    return false;

                if ( pSourcePlayer->GetWeaponType () != ucWeaponType )
                    return false;
            }

            // Current weapon slot
            SWeaponSlotSync slot;
            if ( !BitStream.Read ( &slot ) )
                return false;
            unsigned int uiSlot = slot.data.uiSlot;

            pSourcePlayer->SetWeaponSlot ( uiSlot );

            if ( CWeaponNames::DoesSlotHaveAmmo ( uiSlot ) )
            {
                // Read out the ammo states
                SWeaponAmmoSync ammo ( pSourcePlayer->GetWeaponType (), true, true );
                if ( !BitStream.Read ( &ammo ) )
                    return false;
                pSourcePlayer->SetWeaponAmmoInClip ( ammo.data.usAmmoInClip );
                pSourcePlayer->SetWeaponTotalAmmo ( ammo.data.usTotalAmmo );

                // Read out the aim data
                SWeaponAimSync sync ( pSourcePlayer->GetWeaponRange (), ( ControllerState.RightShoulder1 || ControllerState.ButtonCircle ) );
                if ( !BitStream.Read ( &sync ) )
                    return false;

                // Set the arm directions and whether or not arms are up
                pSourcePlayer->SetAimDirection ( sync.data.fArm );

                // Read the aim data only if he's shooting or aiming
                if ( sync.isFull() )
                {
                    pSourcePlayer->SetSniperSourceVector ( sync.data.vecOrigin );
                    pSourcePlayer->SetTargettingVector ( sync.data.vecTarget );
                }
            }
            else
            {
                pSourcePlayer->SetWeaponAmmoInClip ( 1 );
                pSourcePlayer->SetWeaponTotalAmmo ( 1 );
            }
        }
        else
        {
            pSourcePlayer->SetWeaponSlot ( 0 );
            pSourcePlayer->SetWeaponAmmoInClip ( 1 );
            pSourcePlayer->SetWeaponTotalAmmo ( 1 );
        }

        // Read out damage info if changed
        if ( BitStream.ReadBit () == true )
        {
            ElementID DamagerID;
            if ( !BitStream.ReadCompressed ( DamagerID ) )
                return false;

            SWeaponTypeSync weaponType;
            if ( !BitStream.Read ( &weaponType ) )
                return false;

            SBodypartSync bodyPart;
            if ( !BitStream.Read ( &bodyPart ) )
                return false;

            pSourcePlayer->SetDamageInfo ( DamagerID, weaponType.data.ucWeaponType, bodyPart.data.uiBodypart );
        }

        // If we know the player's dead, make sure the health we send on is 0
        if ( pSourcePlayer->IsDead () )
            fHealth = 0.0f;

        float fOldHealth = pSourcePlayer->GetHealth ();
        float fHealthLoss = fOldHealth - fHealth;
        pSourcePlayer->SetHealth ( fHealth );

        // Less than last packet's frame?
        if ( fHealthLoss > 0 || fArmorLoss > 0 )
        {
            float fDamage = 0.0f;
            if ( fHealthLoss > 0 ) fDamage += fHealthLoss;
            if ( fArmorLoss > 0 ) fDamage += fArmorLoss;

            // Call the onPlayerDamage event
            CLuaArguments Arguments;
            CElement* pKillerElement = CElementIDs::GetElement ( pSourcePlayer->GetPlayerAttacker () );
            if ( pKillerElement ) Arguments.PushElement ( pKillerElement );
            else Arguments.PushNil ();
            Arguments.PushNumber ( pSourcePlayer->GetAttackWeapon () );
            Arguments.PushNumber ( pSourcePlayer->GetAttackBodyPart () );
            Arguments.PushNumber ( fDamage );

            pSourcePlayer->CallEvent ( "onPlayerDamage", Arguments );
        }

        // Success
        return true;
    }

    return false;
}
Exemplo n.º 19
0
bool CResourceStartPacket::Write(NetBitStreamInterface& BitStream) const
{
    if (!m_strResourceName.empty())
    {
        // Write the resource name
        unsigned char sizeResourceName = static_cast<unsigned char>(m_strResourceName.size());
        BitStream.Write(sizeResourceName);
        if (sizeResourceName > 0)
        {
            BitStream.Write(m_strResourceName.c_str(), sizeResourceName);
        }

        // Write the resource id
        BitStream.Write(m_pResource->GetNetID());

        // Write the resource element id
        BitStream.Write(m_pResource->GetResourceRootElement()->GetID());

        // Write the resource dynamic element id
        BitStream.Write(m_pResource->GetDynamicElementRoot()->GetID());

        // Count the amount of 'no client cache' scripts
        unsigned short usNoClientCacheScriptCount = 0;
        if (m_pResource->IsClientScriptsOn() == true)
        {
            list<CResourceFile*>::iterator iter = m_pResource->IterBegin();
            for (; iter != m_pResource->IterEnd(); ++iter)
            {
                if ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_SCRIPT &&
                    static_cast<CResourceClientScriptItem*>(*iter)->IsNoClientCache() == true)
                {
                    ++usNoClientCacheScriptCount;
                }
            }
        }
        BitStream.Write(usNoClientCacheScriptCount);

        // Write the declared min client version for this resource
        if (BitStream.Version() >= 0x32)
        {
            BitStream.WriteString(m_pResource->GetMinServerReqFromMetaXml());
            BitStream.WriteString(m_pResource->GetMinClientReqFromMetaXml());
        }
        if (BitStream.Version() >= 0x45)
        {
            BitStream.WriteBit(m_pResource->IsOOPEnabledInMetaXml());
        }

        if (BitStream.Version() >= 0x62)
        {
            BitStream.Write(m_pResource->GetDownloadPriorityGroup());
        }

        // Send the resource files info
        list<CResourceFile*>::iterator iter = m_pResource->IterBegin();
        for (; iter != m_pResource->IterEnd(); iter++)
        {
            if (((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_CONFIG && m_pResource->IsClientConfigsOn()) ||
                ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_SCRIPT && m_pResource->IsClientScriptsOn() &&
                 static_cast<CResourceClientScriptItem*>(*iter)->IsNoClientCache() == false) ||
                ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_FILE && m_pResource->IsClientFilesOn()))
            {
                // Write the Type of chunk to read (F - File, E - Exported Function)
                BitStream.Write(static_cast<unsigned char>('F'));

                // Write the map name
                const char* szFileName = (*iter)->GetWindowsName();
                size_t      sizeFileName = strlen(szFileName);

                // Make sure we don't have any backslashes in the name
                char* szCleanedFilename = new char[sizeFileName + 1];
                strcpy(szCleanedFilename, szFileName);
                for (unsigned int i = 0; i < sizeFileName; i++)
                {
                    if (szCleanedFilename[i] == '\\')
                        szCleanedFilename[i] = '/';
                }

                BitStream.Write(static_cast<unsigned char>(sizeFileName));
                if (sizeFileName > 0)
                {
                    BitStream.Write(szCleanedFilename, sizeFileName);
                }

                // ChrML: Don't forget this...
                delete[] szCleanedFilename;

                BitStream.Write(static_cast<unsigned char>((*iter)->GetType()));
                CChecksum checksum = (*iter)->GetLastChecksum();
                BitStream.Write(checksum.ulCRC);
                BitStream.Write((const char*)checksum.md5.data, sizeof(checksum.md5.data));
                BitStream.Write((*iter)->GetApproxSize());
                if ((*iter)->GetType() == CResourceScriptItem::RESOURCE_FILE_TYPE_CLIENT_FILE)
                {
                    CResourceClientFileItem* pRCFItem = reinterpret_cast<CResourceClientFileItem*>(*iter);
                    // write bool whether to download or not
                    BitStream.WriteBit(pRCFItem->IsAutoDownload());
                }
            }
        }

        // Loop through the exported functions
        list<CExportedFunction>::iterator iterExportedFunction = m_pResource->IterBeginExportedFunctions();
        for (; iterExportedFunction != m_pResource->IterEndExportedFunctions(); iterExportedFunction++)
        {
            // Check to see if the exported function is 'client'
            if (iterExportedFunction->GetType() == CExportedFunction::EXPORTED_FUNCTION_TYPE_CLIENT)
            {
                // Write the Type of chunk to read (F - File, E - Exported Function)
                BitStream.Write(static_cast<unsigned char>('E'));

                // Write the exported function
                std::string strFunctionName = iterExportedFunction->GetFunctionName();
                size_t      sizeFunctionName = strFunctionName.length();

                BitStream.Write(static_cast<unsigned char>(sizeFunctionName));
                if (sizeFunctionName > 0)
                {
                    BitStream.Write(strFunctionName.c_str(), sizeFunctionName);
                }
            }
        }

        return true;
    }

    return false;
}
Exemplo n.º 20
0
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;
}
Exemplo n.º 21
0
bool CEntityAddPacket::Write ( NetBitStreamInterface& BitStream ) const
{
    SPositionSync position ( false );

    // Check that we have any entities
    if ( m_Entities.size () > 0 )
    {
        // Write the number of entities
        BitStream.WriteCompressed ( ( ElementID ) m_Entities.size () );

        // For each entity ...
        CVector vecTemp;
        vector < CElement* > ::const_iterator iter = m_Entities.begin ();
        for ( ; iter != m_Entities.end (); iter++ )
        {
            // Entity id
            CElement* pElement = *iter;
            BitStream.WriteCompressed ( pElement->GetID () );

            // Entity type id
            unsigned char ucEntityTypeID = static_cast < unsigned char > ( pElement->GetType () );
            BitStream.Write ( ucEntityTypeID );

            // Entity parent
            CElement* pParent = pElement->GetParentEntity ();
            ElementID ParentID = INVALID_ELEMENT_ID;
            if ( pParent )
                ParentID = pParent->GetID ();
            BitStream.WriteCompressed ( ParentID );

            // Entity interior
            BitStream.Write ( pElement->GetInterior () );

            // Entity dimension
            BitStream.WriteCompressed ( pElement->GetDimension () );

            // Entity attached to
            CElement* pElementAttachedTo = pElement->GetAttachedToElement ();
            if ( pElementAttachedTo )
            {
                BitStream.WriteBit ( true );
                BitStream.WriteCompressed ( pElementAttachedTo->GetID () );

                // Attached position and rotation
                SPositionSync attachedPosition ( false );
                SRotationDegreesSync attachedRotation ( false );
                pElement->GetAttachedOffsets ( attachedPosition.data.vecPosition,
                                               attachedRotation.data.vecRotation );
                BitStream.Write ( &attachedPosition );
                BitStream.Write ( &attachedRotation );
            }
            else
                BitStream.WriteBit ( false );
            
            // Write custom data
            CCustomData* pCustomData = pElement->GetCustomDataPointer ();
            assert ( pCustomData );
            BitStream.WriteCompressed ( pCustomData->CountOnlySynchronized () );
            map < string, SCustomData > :: const_iterator iter = pCustomData->IterBegin ();
            for ( ; iter != pCustomData->IterEnd (); iter++ )
            {
                const char* szName = iter->first.c_str ();
                const CLuaArgument* pArgument = &iter->second.Variable;
                bool bSynchronized = iter->second.bSynchronized;

                if ( bSynchronized )
                {
                    unsigned char ucNameLength = static_cast < unsigned char > ( strlen ( szName ) );
                    BitStream.Write ( ucNameLength );
                    BitStream.Write ( szName, ucNameLength );
                    pArgument->WriteToBitStream ( BitStream );
                }
            }

            // Grab its name
            char szEmpty [1];
            szEmpty [0] = 0;
            const char* szName = pElement->GetName ().c_str ();
            if ( !szName )
                szName = szEmpty;

            // Write the name. It can be empty.
            unsigned short usNameLength = static_cast < unsigned short > ( strlen ( szName ) );
            BitStream.WriteCompressed ( usNameLength );
            if ( usNameLength > 0 )
            {
                BitStream.Write ( const_cast < char * > ( szName ), usNameLength );    
            }

            // Write the sync time context
            BitStream.Write ( pElement->GetSyncTimeContext () );

            // Write the rest depending on the type
            switch ( ucEntityTypeID )
            {
                case CElement::OBJECT:
                {
                    CObject* pObject = static_cast < CObject* > ( pElement );

                    // Position
                    position.data.vecPosition = pObject->GetPosition ();
                    BitStream.Write ( &position );

                    // Rotation
                    SRotationRadiansSync rotationRadians ( false );
                    pObject->GetRotation ( rotationRadians.data.vecRotation );
                    BitStream.Write ( &rotationRadians );

                    // Object id
                    BitStream.WriteCompressed ( pObject->GetModel () );

                    // Alpha
                    SEntityAlphaSync alpha;
                    alpha.data.ucAlpha = pObject->GetAlpha ();
                    BitStream.Write ( &alpha );

                    if ( BitStream.Version () >= 0x0c )
                    {
                        bool bIsDoubleSided = pObject->IsDoubleSided ();
                        BitStream.WriteBit ( bIsDoubleSided );
                    }

                    bool bIsMoving = pObject->IsMoving ();
                    BitStream.WriteBit ( bIsMoving );

                    if ( bIsMoving )
                    {
                        BitStream.WriteCompressed ( pObject->GetMoveTimeLeft () );

                        position.data.vecPosition = pObject->m_moveData.vecStopPosition;
                        BitStream.Write ( &position );

                        rotationRadians.data.vecRotation = pObject->m_moveData.vecStopRotation - rotationRadians.data.vecRotation;
                        BitStream.Write ( &rotationRadians );
                    }


                    break;
                }

                case CElement::PICKUP:
                {
                    CPickup* pPickup = static_cast < CPickup* > ( pElement );

                    // Position
                    position.data.vecPosition = pPickup->GetPosition ();
                    BitStream.Write ( &position );

                    // Grab the model and write it
                    unsigned short usModel = pPickup->GetModel ();
                    BitStream.WriteCompressed ( usModel );

                    // Write if it's visible
                    bool bVisible = pPickup->IsVisible ();
                    BitStream.WriteBit ( bVisible );

                    // Write the type
                    SPickupTypeSync pickupType;
                    pickupType.data.ucType = pPickup->GetPickupType ();
                    BitStream.Write ( &pickupType );

                    switch ( pPickup->GetPickupType () )
                    {
                        case CPickup::ARMOR:
                        {
                            SPlayerArmorSync armor;
                            armor.data.fValue = pPickup->GetAmount ();
                            BitStream.Write ( &armor );
                            break;
                        }
                        case CPickup::HEALTH:
                        {
                            SPlayerHealthSync health;
                            health.data.fValue = pPickup->GetAmount ();
                            BitStream.Write ( &health );
                            break;
                        }
                        case CPickup::WEAPON:
                        {
                            SWeaponTypeSync weaponType;
                            weaponType.data.ucWeaponType = pPickup->GetWeaponType ();
                            BitStream.Write ( &weaponType );

                            SWeaponAmmoSync ammo ( weaponType.data.ucWeaponType, true, false );
                            ammo.data.usTotalAmmo = pPickup->GetAmmo ();
                            BitStream.Write ( &ammo );
                            break;
                        }
                        default: break;
                    }

                    break;
                }

                case CElement::VEHICLE:
                {
                    CVehicle* pVehicle = static_cast < CVehicle* > ( pElement );

                    // Write the vehicle position and rotation
                    position.data.vecPosition = pVehicle->GetPosition ();
                    SRotationDegreesSync rotationDegrees ( false );
                    pVehicle->GetRotationDegrees ( rotationDegrees.data.vecRotation );

                    // Write it
                    BitStream.Write ( &position );
                    BitStream.Write ( &rotationDegrees );

                    // Vehicle id as a char
                    // I'm assuming the "-400" is for adjustment so that all car values can
                    // fit into a char?  Why doesn't someone document this?
                    //
                    // --slush
                    BitStream.Write ( static_cast < unsigned char > ( pVehicle->GetModel () - 400 ) );

                    // Health
                    SVehicleHealthSync health;
                    health.data.fValue = pVehicle->GetHealth ();
                    BitStream.Write ( &health );

                    // Color as 4 unsigned chars
                    BitStream.Write ( pVehicle->GetColor ().GetColor1 () );
                    BitStream.Write ( pVehicle->GetColor ().GetColor2 () );
                    BitStream.Write ( pVehicle->GetColor ().GetColor3 () );
                    BitStream.Write ( pVehicle->GetColor ().GetColor4 () );

                    // Paintjob
                    SPaintjobSync paintjob;
                    paintjob.data.ucPaintjob = pVehicle->GetPaintjob ();
                    BitStream.Write ( &paintjob );

                    // Write the damage model
                    SVehicleDamageSync damage ( true, true, true, true, false );
                    memcpy ( damage.data.ucDoorStates,  pVehicle->m_ucDoorStates,  MAX_DOORS );
                    memcpy ( damage.data.ucWheelStates, pVehicle->m_ucWheelStates, MAX_WHEELS );
                    memcpy ( damage.data.ucPanelStates, pVehicle->m_ucPanelStates, MAX_PANELS );
                    memcpy ( damage.data.ucLightStates, pVehicle->m_ucLightStates, MAX_LIGHTS );
                    BitStream.Write ( &damage );

                    // If the vehicle has a turret, send its position too
                    unsigned short usModel = pVehicle->GetModel ();
                    if ( CVehicleManager::HasTurret ( usModel ) )
                    {
                        SVehicleSpecific specific;
                        specific.data.fTurretX = pVehicle->GetTurretPositionX ();
                        specific.data.fTurretY = pVehicle->GetTurretPositionY ();
                        BitStream.Write ( &specific );
                    }

                    // If the vehicle has an adjustable property send its value
                    if ( CVehicleManager::HasAdjustableProperty ( usModel ) )
                    {
                        BitStream.WriteCompressed ( pVehicle->GetAdjustableProperty () );
                    }

                    // Write all the upgrades
                    CVehicleUpgrades* pUpgrades = pVehicle->GetUpgrades ();
                    unsigned char ucNumUpgrades = pUpgrades->Count ();
                    unsigned short* usSlotStates = pUpgrades->GetSlotStates ();
                    BitStream.Write ( ucNumUpgrades );

                    if ( ucNumUpgrades > 0 )
                    {
                        unsigned char ucSlot = 0;
                        for ( ; ucSlot < VEHICLE_UPGRADE_SLOTS ; ucSlot++ )
                        {
                            unsigned short usUpgrade = usSlotStates [ ucSlot ];

                            /*
                            * This is another retarded modification in an attempt to save
                            * a byte.  We're apparently subtracting 1000 so we can store the
                            * information in a single byte instead of two.  This only gives us
                            * a maximum of 256 vehicle slots.
                            *
                            * --slush
                            * -- ChrML: Ehm, GTA only has 17 upgrade slots... This is a valid optimization.
                            */
                            if ( usUpgrade )
                                BitStream.Write ( static_cast < unsigned char > ( usSlotStates [ ucSlot ] - 1000 ) );
                        }
                    }

                    // Get the vehicle's reg plate as 8 bytes of chars with the not used bytes
                    // nulled.
                    const char* cszRegPlate = pVehicle->GetRegPlate ();
                    BitStream.Write ( cszRegPlate, 8 );

                    // Light override
                    SOverrideLightsSync overrideLights;
                    overrideLights.data.ucOverride = pVehicle->GetOverrideLights ();
                    BitStream.Write ( &overrideLights );

                    // Grab various vehicle flags
                    BitStream.WriteBit ( pVehicle->IsLandingGearDown () );
                    BitStream.WriteBit ( pVehicle->IsSirenActive () );
                    BitStream.WriteBit ( pVehicle->IsFuelTankExplodable () );
                    BitStream.WriteBit ( pVehicle->IsEngineOn () );
                    BitStream.WriteBit ( pVehicle->IsLocked () );
                    BitStream.WriteBit ( pVehicle->AreDoorsUndamageable () );
                    BitStream.WriteBit ( pVehicle->IsDamageProof () );
                    BitStream.WriteBit ( pVehicle->IsFrozen () );
                    BitStream.WriteBit ( pVehicle->IsDerailed () );
                    BitStream.WriteBit ( pVehicle->IsDerailable () );
                    BitStream.WriteBit ( pVehicle->GetTrainDirection () );
                    BitStream.WriteBit ( pVehicle->IsTaxiLightOn () );

                    // Write alpha
                    SEntityAlphaSync alpha;
                    alpha.data.ucAlpha = pVehicle->GetAlpha ();
                    BitStream.Write ( &alpha ); 

                    // Write headlight color
                    SColor color = pVehicle->GetHeadLightColor ();
                    if ( color.R != 255 || color.G != 255 || color.B != 255 )
                    {
                        BitStream.WriteBit ( true );
                        BitStream.Write ( color.R );
                        BitStream.Write ( color.G );
                        BitStream.Write ( color.B );
                    }
                    else
                        BitStream.WriteBit ( false );

                    break;
                }                

                case CElement::MARKER:
                {
                    CMarker* pMarker = static_cast < CMarker* > ( pElement );

                    // Position
                    position.data.vecPosition = pMarker->GetPosition ();
                    BitStream.Write ( &position );

                    // Type
                    SMarkerTypeSync markerType;
                    markerType.data.ucType = pMarker->GetMarkerType ();
                    BitStream.Write ( &markerType );

                    // Size
                    float fSize = pMarker->GetSize ();
                    BitStream.Write ( fSize );

                    // Colour
                    SColorSync color;
                    color = pMarker->GetColor ();
                    BitStream.Write ( &color );

                    // Write the target position vector eventually
                    if ( markerType.data.ucType == CMarker::TYPE_CHECKPOINT ||
                         markerType.data.ucType == CMarker::TYPE_RING )
                    {
                        if ( pMarker->HasTarget () )
                        {
                            BitStream.WriteBit ( true );

                            position.data.vecPosition = pMarker->GetTarget ();
                            BitStream.Write ( &position );
                        }
                        else
                            BitStream.WriteBit ( false );
                    }

                    break;
                }

                case CElement::BLIP:
                {
                    CBlip* pBlip = static_cast < CBlip* > ( pElement );

                    // Grab the blip position
                    position.data.vecPosition = pBlip->GetPosition ();
                    BitStream.Write ( &position );

                    // Write the ordering id
                    BitStream.WriteCompressed ( pBlip->m_sOrdering );

                    // Write the visible distance
                    BitStream.Write ( pBlip->m_fVisibleDistance );

                    // Write the icon
                    unsigned char ucIcon = pBlip->m_ucIcon;
                    BitStream.Write ( ucIcon );
                    if ( ucIcon == 0 )
                    {
                        // Write the size
                        BitStream.Write ( pBlip->m_ucSize );

                        // Write the color
                        SColorSync color;
                        color = pBlip->GetColor ();
                        BitStream.Write ( &color );
                    }                    

                    break;
                }

                case CElement::RADAR_AREA:
                {
                    CRadarArea* pArea = static_cast < CRadarArea* > ( pElement );

                    // Write the position
                    SPosition2DSync position2D ( false );
                    position2D.data.vecPosition = pArea->GetPosition ();
                    BitStream.Write ( &position2D );

                    // Write the size
                    SPosition2DSync size2D ( false );
                    size2D.data.vecPosition = pArea->GetSize ();
                    BitStream.Write ( &size2D );

                    // And the color
                    SColor color = pArea->GetColor ();
                    BitStream.Write ( color.R );
                    BitStream.Write ( color.G );
                    BitStream.Write ( color.B );
                    BitStream.Write ( color.A );

                    // Write whether it is flashing
                    bool bIsFlashing = pArea->IsFlashing ();
                    BitStream.WriteBit ( bIsFlashing );

                    break;
                }

                case CElement::WORLD_MESH:
                {
                    /*
                    CWorldMesh* pMesh = static_cast < CWorldMesh* > ( pElement );

                    // Write the name
                    char* szName = pMesh->GetName ();
                    unsigned short usNameLength = static_cast < unsigned short > ( strlen ( szName ) );
                    BitStream.Write ( usNameLength );
                    BitStream.Write ( szName, static_cast < int > ( usNameLength ) );

                    // Write the position and rotation
                    CVector vecTemp = pMesh->GetPosition ();
                    BitStream.Write ( vecTemp.fX );
                    BitStream.Write ( vecTemp.fY );
                    BitStream.Write ( vecTemp.fZ );
                    
                    vecTemp = pMesh->GetRotation ();
                    BitStream.Write ( vecTemp.fX );
                    BitStream.Write ( vecTemp.fY );
                    BitStream.Write ( vecTemp.fZ );
                    */

                    break;
                }

                case CElement::TEAM:
                {
                    CTeam* pTeam = static_cast < CTeam* > ( pElement );

                    // Write the name
                    char* szTeamName = pTeam->GetTeamName ();
                    unsigned short usNameLength = static_cast < unsigned short > ( strlen ( szTeamName ) );
                    unsigned char ucRed, ucGreen, ucBlue;
                    pTeam->GetColor ( ucRed, ucGreen, ucBlue );
                    bool bFriendlyFire = pTeam->GetFriendlyFire ();
                    BitStream.WriteCompressed ( usNameLength );
                    BitStream.Write ( szTeamName, usNameLength );                    
                    BitStream.Write ( ucRed );
                    BitStream.Write ( ucGreen );
                    BitStream.Write ( ucBlue );
                    BitStream.WriteBit ( bFriendlyFire );

                    break;
                }

                case CElement::PED:
                {
                    CPed* pPed = static_cast < CPed* > ( pElement );

                    // position
                    position.data.vecPosition = pPed->GetPosition ();
                    BitStream.Write ( &position );

                    // model
                    unsigned short usModel = pPed->GetModel ();
                    BitStream.WriteCompressed ( usModel );

                    // rotation
                    SPedRotationSync pedRotation;
                    pedRotation.data.fRotation = pPed->GetRotation ();
                    BitStream.Write ( &pedRotation );

                    // health
                    SPlayerHealthSync health;
                    health.data.fValue = pPed->GetHealth ();
                    BitStream.Write ( &health );

                    // Armor
                    SPlayerArmorSync armor;
                    armor.data.fValue = pPed->GetArmor ();
                    BitStream.Write ( &armor );
                    
                    // vehicle
                    CVehicle * pVehicle = pPed->GetOccupiedVehicle ();
                    if ( pVehicle )
                    {
                        BitStream.WriteBit ( true );
                        BitStream.WriteCompressed ( pVehicle->GetID () );

                        SOccupiedSeatSync seat;
                        seat.data.ucSeat = pPed->GetOccupiedVehicleSeat ();
                        BitStream.Write ( &seat );
                    }
                    else
                        BitStream.WriteBit ( false );

                    // flags
                    BitStream.WriteBit ( pPed->HasJetPack () );
                    BitStream.WriteBit ( pPed->IsSyncable () );
                    BitStream.WriteBit ( pPed->IsHeadless () );
                    BitStream.WriteBit ( pPed->IsFrozen () );

                    // alpha
                    SEntityAlphaSync alpha;
                    alpha.data.ucAlpha = pPed->GetAlpha ();
                    BitStream.Write ( &alpha );

                    if ( BitStream.Version () < 0x07 )
                        break;

                    // clothes
                    unsigned char ucNumClothes = 0;
                    CPlayerClothes* pClothes = pPed->GetClothes ( );
                    for ( unsigned char ucType = 0 ; ucType < PLAYER_CLOTHING_SLOTS ; ucType++ )
                    {
                        SPlayerClothing* pClothing = pClothes->GetClothing ( ucType );
                        if ( pClothing )
                        {
                            ucNumClothes++;
                        }
                    }
                    BitStream.Write ( ucNumClothes );
                    for ( unsigned char ucType = 0 ; ucType < PLAYER_CLOTHING_SLOTS ; ucType++ )
                    {
                        SPlayerClothing* pClothing = pClothes->GetClothing ( ucType );
                        if ( pClothing )
                        {
                            unsigned char ucTextureLength = strlen ( pClothing->szTexture );
                            unsigned char ucModelLength = strlen ( pClothing->szModel );

                            BitStream.Write ( ucTextureLength );
                            BitStream.Write ( pClothing->szTexture, ucTextureLength );
                            BitStream.Write ( ucModelLength );
                            BitStream.Write ( pClothing->szModel, ucModelLength );
                            BitStream.Write ( ucType );
                        }
                    }
                    break;
                }

                case CElement::DUMMY:
                {
                    CDummy* pDummy = static_cast < CDummy* > ( pElement );
                    
                    // Type Name
                    const char* szTypeName = pDummy->GetTypeName ().c_str ();
                    unsigned short usTypeNameLength = static_cast < unsigned short > ( strlen ( szTypeName ) );
                    BitStream.WriteCompressed ( usTypeNameLength );
                    BitStream.Write ( const_cast < char* > ( szTypeName ), usTypeNameLength );                      

                    // Position
                    position.data.vecPosition = pDummy->GetPosition();
                    if ( position.data.vecPosition != CVector ( 0.0f, 0.0f, 0.0f ) )
                    {
                        BitStream.WriteBit ( true );
                        BitStream.Write ( &position );
                    }
                    else
                        BitStream.WriteBit ( false );

                    break;
                }

                case CElement::PLAYER:
                {
                    break;
                }

                case CElement::SCRIPTFILE:
                {
                    // No extra data
                    break;
                }

                case CElement::COLSHAPE:
                {
                    CColShape* pColShape = static_cast < CColShape* > ( pElement );
                    if ( !pColShape->GetParentEntity () )
                    {
                        // Jax: i'm pretty sure this is f*****g up our packet somehow..
                        // all valid col-shapes should have a parent!
                        assert ( false );
                    }

                    // Type
                    SColshapeTypeSync colType;
                    colType.data.ucType = static_cast < unsigned char > ( pColShape->GetShapeType () );
                    BitStream.Write ( &colType );

                    // Position
                    position.data.vecPosition = pColShape->GetPosition ();
                    BitStream.Write ( &position );
                    
                    // Enabled
                    BitStream.WriteBit ( pColShape->IsEnabled () );

                    // Auto Call Event
                    BitStream.WriteBit ( pColShape->GetAutoCallEvent () );

                    switch ( pColShape->GetShapeType () )
                    {
                        case COLSHAPE_CIRCLE:
                        {
                            BitStream.Write ( static_cast < CColCircle* > ( pColShape )->GetRadius () );
                            break;
                        }
                        case COLSHAPE_CUBOID:
                        {
                            SPositionSync size ( false );
                            size.data.vecPosition = static_cast < CColCuboid* > ( pColShape )->GetSize ();
                            BitStream.Write ( &size );
                            break;
                        }
                        case COLSHAPE_SPHERE:
                        {
                            BitStream.Write ( static_cast < CColSphere* > ( pColShape )->GetRadius () );
                            break;
                        }
                        case COLSHAPE_RECTANGLE:
                        {
                            SPosition2DSync size ( false );
                            size.data.vecPosition = static_cast < CColRectangle* > ( pColShape )->GetSize ();
                            BitStream.Write ( &size );
                            break;
                        }
                        case COLSHAPE_TUBE:
                        {
                            BitStream.Write ( static_cast < CColTube* > ( pColShape )->GetRadius () );
                            BitStream.Write ( static_cast < CColTube* > ( pColShape )->GetHeight () );
                            break;
                        }
                        case COLSHAPE_POLYGON:
                        {
                            CColPolygon* pPolygon = static_cast < CColPolygon* > ( pColShape );
                            BitStream.WriteCompressed ( pPolygon->CountPoints() );
                            std::vector < CVector2D > ::const_iterator iter = pPolygon->IterBegin();
                            for ( ; iter != pPolygon->IterEnd () ; iter++ )
                            {
                                SPosition2DSync vertex ( false );
                                vertex.data.vecPosition = *iter;
                                BitStream.Write ( &vertex );
                            }
                            break;
                        }
                        default: break;
                    }
                    break;
                }

                case CElement::HANDLING:
                {
                    // Cast to handling class
                    CHandling* pHandling = static_cast < CHandling* > ( pElement );

                    bool bMass, bTurnMass, bDragCoeff, bCenterOfMass, bPercentSubmerged;
                    bool bTractionMultiplier, bDriveType, bEngineType, bNumberOfGears;
                    bool bEngineAccelleration, bEngineInertia, bMaxVelocity, bBrakeDecelleration;
                    bool bBrakeBias, bABS, bSteeringLock, bTractionLoss, bTractionBias;
                    bool bSuspensionForceLevel, bSuspensionDamping, bSuspensionHighSpeedDamping;
                    bool bSuspensionUpperLimit, bSuspensionLowerLimit, bSuspensionFrontRearBias;
                    bool bSuspensionAntidiveMultiplier, bCollisionDamageMultiplier;
                    bool bSeatOffsetDistance, bHandlingFlags, bModelFlags, bHeadLight;
                    bool bTailLight, bAnimGroup;

                    // Write all the details about the handling
                    float fMass = pHandling->GetMass ( bMass );
                    float fTurnMass = pHandling->GetTurnMass ( bTurnMass );
                    float fDragCoeff = pHandling->GetDragCoeff ( bDragCoeff );
                    const CVector& vecCenterOfMass = pHandling->GetCenterOfMass ( bCenterOfMass );
                    unsigned int uiPercentSubmerged = pHandling->GetPercentSubmerged ( bPercentSubmerged );
                    float fTractionMultiplier = pHandling->GetTractionMultiplier ( bTractionMultiplier );
                    unsigned char ucDriveType = pHandling->GetDriveType ( bDriveType );
                    unsigned char ucEngineType = pHandling->GetEngineType ( bEngineType );
                    unsigned char ucNumberOfGears = pHandling->GetNumberOfGears ( bNumberOfGears );
                    float fEngineAccelleration = pHandling->GetEngineAccelleration ( bEngineAccelleration );
                    float fEngineInertia = pHandling->GetEngineInertia ( bEngineInertia );
                    float fMaxVelocity = pHandling->GetMaxVelocity ( bMaxVelocity );
                    float fBrakeDecelleration = pHandling->GetBrakeDecelleration ( bBrakeDecelleration );
                    float fBrakeBias = pHandling->GetBrakeBias ( bBrakeBias );
                    unsigned char ucABS = pHandling->GetABS ( bABS ) ? 1 : 0;
                    float fSteeringLock = pHandling->GetSteeringLock ( bSteeringLock );
                    float fTractionLoss = pHandling->GetTractionLoss ( bTractionLoss );
                    float fTractionBias = pHandling->GetTractionBias ( bTractionBias );
                    float fSuspensionForceLevel = pHandling->GetSuspensionForceLevel ( bSuspensionForceLevel );
                    float fSuspensionDamping = pHandling->GetSuspensionDamping ( bSuspensionDamping );
                    float fSuspensionHighSpeedDamping = pHandling->GetSuspensionHighSpeedDamping ( bSuspensionHighSpeedDamping );
                    float fSuspensionUpperLimit = pHandling->GetSuspensionUpperLimit ( bSuspensionUpperLimit );
                    float fSuspensionLowerLimit = pHandling->GetSuspensionLowerLimit ( bSuspensionLowerLimit );
                    float fSuspensionFrontRearBias = pHandling->GetSuspensionFrontRearBias ( bSuspensionFrontRearBias );
                    float fSuspensionAntidiveMultiplier = pHandling->GetSuspensionAntidiveMultiplier ( bSuspensionAntidiveMultiplier );
                    float fCollisionDamageMultiplier = pHandling->GetCollisionDamageMultiplier ( bCollisionDamageMultiplier );
                    float fSeatOffsetDistance = pHandling->GetSeatOffsetDistance ( bSeatOffsetDistance );
                    unsigned int uiHandlingFlags = pHandling->GetHandlingFlags ( bHandlingFlags );
                    unsigned int uiModelFlags = pHandling->GetModelFlags ( bModelFlags );
                    unsigned char ucHeadLight = pHandling->GetHeadLight ( bHeadLight );
                    unsigned char ucTailLight = pHandling->GetTailLight ( bTailLight );
                    unsigned char ucAnimGroup = pHandling->GetAnimGroup ( bAnimGroup );

                    // Put all the bools in a long so the client knows what it's going to
                    // receive
                    unsigned long ulChanged =   static_cast < unsigned long > ( bMass ) |
                                                static_cast < unsigned long > ( bTurnMass ) << 1 |
                                                static_cast < unsigned long > ( bDragCoeff ) << 2 |
                                                static_cast < unsigned long > ( bCenterOfMass ) << 3 |
                                                static_cast < unsigned long > ( bPercentSubmerged ) << 4 |
                                                static_cast < unsigned long > ( bTractionMultiplier ) << 5 |
                                                static_cast < unsigned long > ( bDriveType ) << 6 |
                                                static_cast < unsigned long > ( bEngineType ) << 7 |
                                                static_cast < unsigned long > ( bNumberOfGears ) << 8 |
                                                static_cast < unsigned long > ( bEngineAccelleration ) << 9 |
                                                static_cast < unsigned long > ( bEngineInertia ) << 10 |
                                                static_cast < unsigned long > ( bMaxVelocity ) << 11 |
                                                static_cast < unsigned long > ( bBrakeDecelleration ) << 12 |
                                                static_cast < unsigned long > ( bBrakeBias ) << 13 |
                                                static_cast < unsigned long > ( bABS ) << 14 |
                                                static_cast < unsigned long > ( bSteeringLock ) << 15 |
                                                static_cast < unsigned long > ( bTractionLoss ) << 16 |
                                                static_cast < unsigned long > ( bTractionBias ) << 17 |
                                                static_cast < unsigned long > ( bSuspensionForceLevel ) << 18 |
                                                static_cast < unsigned long > ( bSuspensionDamping ) << 19 |
                                                static_cast < unsigned long > ( bSuspensionHighSpeedDamping ) << 20 |
                                                static_cast < unsigned long > ( bSuspensionUpperLimit ) << 21 |
                                                static_cast < unsigned long > ( bSuspensionLowerLimit ) << 22 |
                                                static_cast < unsigned long > ( bSuspensionFrontRearBias ) << 23 |
                                                static_cast < unsigned long > ( bSuspensionAntidiveMultiplier ) << 24 |
                                                static_cast < unsigned long > ( bCollisionDamageMultiplier ) << 25 |
                                                static_cast < unsigned long > ( bSeatOffsetDistance ) << 26 |
                                                static_cast < unsigned long > ( bHandlingFlags ) << 27 |
                                                static_cast < unsigned long > ( bModelFlags ) << 28 |
                                                static_cast < unsigned long > ( bHeadLight ) << 29 |
                                                static_cast < unsigned long > ( bTailLight ) << 30 |
                                                static_cast < unsigned long > ( bAnimGroup ) << 31;
                    BitStream.Write ( ulChanged );

                    if ( bMass )
                        BitStream.Write ( fMass );

                    if ( bTurnMass )
                        BitStream.Write ( fTurnMass );

                    if ( bDragCoeff )
                        BitStream.Write ( fDragCoeff );

                    if ( bCenterOfMass )
                    {
                        BitStream.Write ( vecCenterOfMass.fX );
                        BitStream.Write ( vecCenterOfMass.fY );
                        BitStream.Write ( vecCenterOfMass.fZ );
                    }

                    if ( bPercentSubmerged )
                        BitStream.Write ( uiPercentSubmerged );

                    if ( bTractionMultiplier )
                        BitStream.Write ( fTractionMultiplier );

                    if ( bDriveType )
                        BitStream.Write ( ucDriveType );

                    if ( bEngineType )
                        BitStream.Write ( ucEngineType );

                    if ( bNumberOfGears )
                        BitStream.Write ( ucNumberOfGears );

                    if ( bEngineAccelleration )
                        BitStream.Write ( fEngineAccelleration );

                    if ( bEngineInertia )
                        BitStream.Write ( fEngineInertia );

                    if ( bMaxVelocity )
                        BitStream.Write ( fMaxVelocity );

                    if ( bBrakeDecelleration )
                        BitStream.Write ( fBrakeDecelleration );

                    if ( bBrakeBias )
                        BitStream.Write ( fBrakeBias );

                    if ( bABS )
                        BitStream.Write ( ucABS );

                    if ( bSteeringLock )
                        BitStream.Write ( fSteeringLock );

                    if ( bTractionLoss )
                        BitStream.Write ( fTractionLoss );

                    if ( bTractionBias )
                        BitStream.Write ( fTractionBias );

                    if ( bSuspensionForceLevel )
                        BitStream.Write ( fSuspensionForceLevel );

                    if ( bSuspensionDamping )
                        BitStream.Write ( fSuspensionDamping );

                    if ( bSuspensionHighSpeedDamping )
                        BitStream.Write ( fSuspensionHighSpeedDamping );

                    if ( bSuspensionUpperLimit )
                        BitStream.Write ( fSuspensionUpperLimit );
                    
                    if ( bSuspensionLowerLimit )
                        BitStream.Write ( fSuspensionLowerLimit );

                    if ( bSuspensionFrontRearBias )
                        BitStream.Write ( fSuspensionFrontRearBias );

                    if ( bSuspensionAntidiveMultiplier )
                        BitStream.Write ( fSuspensionAntidiveMultiplier );

                    if ( bCollisionDamageMultiplier )
                        BitStream.Write ( fCollisionDamageMultiplier );

                    if ( bSeatOffsetDistance )
                        BitStream.Write ( fSeatOffsetDistance );

                    if ( bHandlingFlags )
                        BitStream.Write ( uiHandlingFlags );
                    
                    if ( bModelFlags )
                        BitStream.Write ( uiModelFlags );

                    if ( bHeadLight )
                        BitStream.Write ( ucHeadLight );

                    if ( bTailLight )
                        BitStream.Write ( ucTailLight );

                    if ( bAnimGroup )
                        BitStream.Write ( ucAnimGroup );

                    // Write number of vehicles that have this handling applied as default
                    unsigned char ucCount = static_cast < unsigned char > ( pHandling->CountDefaultTo () );
                    BitStream.Write ( ucCount );

                    // Write their ID's as bytes (real id - 400)
                    std::list < unsigned short > ::const_iterator iter = pHandling->IterDefaultToBegin ();
                    for ( ; iter != pHandling->IterDefaultToEnd (); iter++ )
                    {
                        // Grab the ID
                        unsigned char ucID = (*iter) - 400;
                        BitStream.Write ( ucID );
                    }

                    // Done
                    break;
                }

                case CElement::WATER:
                {
                    CWater* pWater = static_cast < CWater* > ( pElement );
                    unsigned char ucNumVertices = (unsigned char)pWater->GetNumVertices ();
                    BitStream.Write ( ucNumVertices );
                    CVector vecVertex;
                    for ( int i = 0; i < ucNumVertices; i++ )
                    {
                        pWater->GetVertex ( i, vecVertex );
                        BitStream.Write ( (short)vecVertex.fX );
                        BitStream.Write ( (short)vecVertex.fY );
                        BitStream.Write ( vecVertex.fZ );
                    }
                    break;
                }

                default:
                {
                    assert ( 0 );
                    CLogger::LogPrintf ( "not sending this element - id: %i\n", pElement->GetType () );
                }
            }
        }

        // Success
        return true;
    }

    return false;
}