Пример #1
0
bool CVehicleInOutPacket::Read ( NetBitStreamInterface& BitStream )
{
    // Read out the vehicle id
    m_ID = INVALID_ELEMENT_ID;
    BitStream.Read ( m_ID );
    if ( m_ID == INVALID_ELEMENT_ID )
    {
        return false;
    }

    // Read out the action id
    m_ucAction = 0xFF;
    if ( !BitStream.ReadBits ( &m_ucAction, 4 ) )
        return false;

    // If the action is requesting to get in, read out the "passenger" flag too
    if ( m_ucAction == CGame::VEHICLE_REQUEST_IN )
    {
        return BitStream.ReadBits ( &m_ucSeat, 3 ) &&
               BitStream.ReadBit  ( m_bOnWater ) &&
               BitStream.ReadBits ( &m_ucDoor, 3 );
    }
    else if ( m_ucAction == CGame::VEHICLE_NOTIFY_JACK_ABORT )
    {
        SDoorOpenRatioSync door;
        bool bStartedJacking;
        if ( BitStream.ReadBits ( &m_ucDoor, 3 ) &&
             BitStream.Read ( &door ) &&
             BitStream.ReadBit ( bStartedJacking ) )
        {
            m_ucStartedJacking = bStartedJacking;
            m_fDoorAngle = door.data.fRatio;
        }
        else
            return false;
    }
    else if ( m_ucAction == CGame::VEHICLE_NOTIFY_IN_ABORT )
    {
        SDoorOpenRatioSync door;
        if ( BitStream.ReadBits ( &m_ucDoor, 3 ) &&
             BitStream.Read ( &door ) )
        {
            m_fDoorAngle = door.data.fRatio;
        }
        else
            return false;
    }
    else if ( m_ucAction == CGame::VEHICLE_REQUEST_OUT )
    {
        m_ucDoor = 0;
        if ( !BitStream.ReadBits ( &m_ucDoor, 2 ) )
            m_ucDoor = 0xFF;
    }
    return true;
}
Пример #2
0
void CElementRPCs::SetElementCollisionsEnabled ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    bool bEnable;

    if ( bitStream.ReadBit ( bEnable ) )
    {
        switch ( pSource->GetType () )
        {
            case CCLIENTPED:
            case CCLIENTPLAYER:
            {
                CClientPed* pPed = static_cast < CClientPed * > ( pSource );
                pPed->SetUsesCollision ( bEnable );
                break;
            }

            case CCLIENTVEHICLE:
            {
                CClientVehicle* pVehicle = static_cast < CClientVehicle * > ( pSource );
                pVehicle->SetCollisionEnabled ( bEnable );
                break;
            }

            case CCLIENTOBJECT:
            {
                CClientObject* pObject = static_cast < CClientObject * > ( pSource );
                pObject->SetCollisionEnabled ( bEnable );
                break;
            }
        }
    }
}
Пример #3
0
void CElementRPCs::SetElementFrozen ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    bool bFrozen;

    if ( bitStream.ReadBit ( bFrozen ) )
    {
        switch ( pSource->GetType () )
        {
            case CCLIENTPED:
            case CCLIENTPLAYER:
            {
                CClientPed* pPed = static_cast < CClientPed * > ( pSource );
                pPed->SetFrozen ( bFrozen );
                break;
            }

            case CCLIENTVEHICLE:
            {
                CClientVehicle* pVehicle = static_cast < CClientVehicle * > ( pSource );
                pVehicle->SetFrozen ( bFrozen );
                break;
            }

            case CCLIENTOBJECT:
            {
                CClientObject* pObject = static_cast < CClientObject * > ( pSource );
                pObject->SetStatic ( bFrozen );
                break;
            }
        }
    }
}
Пример #4
0
bool CVehicleTrailerPacket::Read ( NetBitStreamInterface& BitStream )
{
    SPositionSync position ( false );
    SRotationDegreesSync rotation ( false );
    SVelocitySync turn;

    if ( BitStream.Read ( m_Vehicle ) &&
         BitStream.Read ( m_AttachedVehicle ) &&
         BitStream.ReadBit ( m_bAttached ) &&
         ( !m_bAttached ||
           ( BitStream.Read ( &position ) &&
             BitStream.Read ( &rotation ) &&
             BitStream.Read ( &turn )
           )
         )
       )
    {
        if ( m_bAttached )
        {
            m_vecPosition = position.data.vecPosition;
            m_vecRotationDegrees = rotation.data.vecRotation;
            m_vecTurnSpeed = turn.data.vecVelocity;
        }
        return true;
    }
    return false;
}
Пример #5
0
void CElementRPCs::RemoveElementData ( NetBitStreamInterface& bitStream )
{
    // Read out the entity id and name length
    ElementID ID;
    unsigned short usNameLength;
    bool bRecursive;
    if ( bitStream.ReadCompressed ( ID ) && bitStream.ReadCompressed ( usNameLength ) )
    {
        // Allocate a buffer for the name
        char* szName = new char [ usNameLength + 1 ];
        szName [ usNameLength ] = NULL;

        // Read it out plus whether it's recursive or not
        if ( bitStream.Read ( szName, usNameLength ) &&
             bitStream.ReadBit ( bRecursive ) )
        {
            // Grab the entity
            CClientEntity* pEntity = CElementIDs::GetElement ( ID );
            if ( pEntity )
            {
                // Remove that name
                pEntity->DeleteCustomData ( szName, bRecursive );
            }
        }

        // Delete the name buffer
        delete [] szName;
    }
}
Пример #6
0
void CElementRPCs::SetCustomWeaponTarget ( CClientEntity * pSource, NetBitStreamInterface& bitStream )
{
    ElementID elementID = INVALID_ELEMENT_ID;
    char cTargetBone = 0;
    bool bVector = false;
    CVector vecTarget;

    if ( bitStream.ReadBit ( bVector ) &&
        pSource->GetType() == CCLIENTWEAPON )
    {
        CClientWeapon * pWeapon = static_cast < CClientWeapon * > ( pSource );
        if ( bVector )
        {
            if ( bitStream.ReadVector ( vecTarget.fX, vecTarget.fY, vecTarget.fZ ) )
            {
                pWeapon->SetWeaponTarget ( vecTarget );
            }
        }
        else
        {
            if ( bitStream.Read ( elementID ) && 
                bitStream.Read ( cTargetBone ) )
            {
                pWeapon->SetWeaponTarget ( CElementIDs::GetElement( elementID ), cTargetBone );
            }
        }
    }
}
Пример #7
0
void CElementRPCs::SetCallPropagationEnabled ( CClientEntity * pSource, NetBitStreamInterface& bitStream )
{
    bool bEnabled;
    if ( bitStream.ReadBit ( bEnabled ) )
    {
        pSource->SetCallPropagationEnabled ( bEnabled );
    }
}
Пример #8
0
void CWorldRPCs::SetJetpackWeaponEnabled(NetBitStreamInterface& bitStream)
{
    unsigned char ucWeaponID = 0;
    bool          bEnabled;
    bitStream.Read(ucWeaponID);
    bitStream.ReadBit(bEnabled);
    g_pGame->SetJetpackWeaponEnabled((eWeaponType)ucWeaponID, bEnabled);
}
Пример #9
0
void CElementRPCs::SetElementDoubleSided ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    bool bDoubleSided;
    if ( bitStream.ReadBit ( bDoubleSided ) )
    {
        pSource->SetDoubleSided ( bDoubleSided );
    }
}
Пример #10
0
void CWorldRPCs::SetOcclusionsEnabled(NetBitStreamInterface& bitStream)
{
    bool bEnabled;

    if (bitStream.ReadBit(bEnabled))
    {
        g_pGame->GetWorld()->SetOcclusionsEnabled(bEnabled);
    }
}
Пример #11
0
void CWorldRPCs::SetInteriorSoundsEnabled(NetBitStreamInterface& bitStream)
{
    bool bEnable;

    if (bitStream.ReadBit(bEnable))
    {
        g_pMultiplayer->SetInteriorSoundsEnabled(bEnable);
    }
}
Пример #12
0
void CPedRPCs::SetPedAnimation ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    // Read out the player and vehicle id
    char szBlockName [ 64 ], szAnimName [ 64 ];
    unsigned char ucBlockSize, ucAnimSize;
    int iTime;
    bool bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame;

    if ( bitStream.Read ( ucBlockSize ) )
    {
        // Grab the ped
        CClientPed * pPed = m_pPedManager->Get ( pSource->GetID (), true );
        if ( pPed )
        {
            if ( ucBlockSize > 0 )
            {
                if ( bitStream.Read ( szBlockName, ucBlockSize ) &&
                    bitStream.Read ( ucAnimSize ) )
                {
                    szBlockName [ ucBlockSize ] = 0;
                    if ( bitStream.Read ( szAnimName, ucAnimSize ) &&
                         bitStream.Read ( iTime ) &&
                         bitStream.ReadBit ( bLoop ) &&
                         bitStream.ReadBit ( bUpdatePosition ) &&
                         bitStream.ReadBit ( bInterruptable ) &&
                         bitStream.ReadBit ( bFreezeLastFrame ) )
                    {
                        szAnimName [ ucAnimSize ] = 0;

                        CAnimBlock * pBlock = g_pGame->GetAnimManager ()->GetAnimationBlock ( szBlockName );
                        if ( pBlock )
                        {
                            pPed->RunNamedAnimation ( pBlock, szAnimName, iTime, bLoop, bUpdatePosition, bInterruptable, bFreezeLastFrame );
                        }
                    }
                }
            }
            else
            {
                pPed->KillAnimation ();
            }
        }
    }
}
Пример #13
0
void CRPCFunctions::KeyBind ( NetBitStreamInterface & bitStream )
{
    unsigned char ucType;
    bool bHitState = false;
    if ( bitStream.ReadBit () == true )
        ucType = 1;
    else
        ucType = 0;
    bitStream.ReadBit ( bHitState );

    unsigned char ucKeyLength = bitStream.GetNumberOfUnreadBits () >> 3;
    if ( ucKeyLength < 256 )
    {
        char szKey [ 256 ];
        bitStream.Read ( szKey, ucKeyLength );
        szKey [ ucKeyLength ] = 0;

        m_pSourcePlayer->GetKeyBinds ()->ProcessKey ( szKey, bHitState, ( eKeyBindType ) ucType );
    }
}
Пример #14
0
void CWaterRPCs::SetWorldWaterLevel ( NetBitStreamInterface& bitStream )
{
    float fLevel;
    bool bIncludeWorldNonSeaLevel;

    if ( bitStream.Read ( fLevel )
            && bitStream.ReadBit ( bIncludeWorldNonSeaLevel ) )
    {
        m_pWaterManager->SetWorldWaterLevel ( fLevel, NULL, bIncludeWorldNonSeaLevel );
    }
}
Пример #15
0
void CPedRPCs::SetPedChoking ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    bool bChoking;
    if ( bitStream.ReadBit ( bChoking ) )
    {
        CClientPed* pPed = m_pPedManager->Get ( pSource->GetID (), true );
        if ( pPed )
        {
            pPed->SetChoking ( bChoking );
        }
    }
}
Пример #16
0
void CWorldRPCs::SetTrafficLightState(NetBitStreamInterface& bitStream)
{
    char ucTrafficLightState;

    if (bitStream.ReadBits(&ucTrafficLightState, 4))
    {
        bool bForced = bitStream.ReadBit();
        // We ignore updating the serverside traffic light state if it's blocked, unless script forced it
        if (bForced || !g_pMultiplayer->GetTrafficLightsLocked())
            g_pMultiplayer->SetTrafficLightState((unsigned char)*&ucTrafficLightState);
    }
}
Пример #17
0
void CElementRPCs::SetElementDoubleSided ( NetBitStreamInterface& bitStream )
{
    ElementID ID;
    bool bDoubleSided;
    if ( bitStream.Read ( ID ) && bitStream.ReadBit ( bDoubleSided ) )
    {
        CClientEntity* pEntity = CElementIDs::GetElement ( ID );
        if ( pEntity )
        {
            pEntity->SetDoubleSided ( bDoubleSided );
        }
    }
}
Пример #18
0
void CPedRPCs::SetPedHeadless ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    bool bIsHeadless;

    if ( bitStream.ReadBit ( bIsHeadless ) )
    {
        // Grab the ped
        CClientPed * pPed = m_pPedManager->Get ( pSource->GetID (), true );
        if ( pPed )
        {
            pPed->SetHeadless ( bIsHeadless );
        }
    }
}
Пример #19
0
void CPedRPCs::SetPedFrozen ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    bool bIsFrozen = 0;

    if ( bitStream.ReadBit ( bIsFrozen ) )
    {
        // Grab the ped
        CClientPed * pPed = m_pPedManager->Get ( pSource->GetID (), true );
        if ( pPed )
        {
            pPed->SetFrozen ( bIsFrozen );
        }
    }
}
Пример #20
0
void CPlayerRPCs::SetPlayerMoney ( NetBitStreamInterface& bitStream )
{
    // Read out the new money amount
    long lMoney;
    bool bInstant = false;
    if ( bitStream.Read ( lMoney ) )
    {
        if (bitStream.GetNumberOfUnreadBits() > 0)
            bitStream.ReadBit(bInstant);

        // Set it
        m_pClientGame->SetMoney ( lMoney, bInstant );
    }
}
Пример #21
0
void CObjectRPCs::SetObjectVisibleInAllDimensions ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    CDeathmatchObject* pObject = static_cast < CDeathmatchObject* > (m_pObjectManager->Get ( pSource->GetID ( ) ));

    if ( pObject )
    {
        bool bVisible;
        unsigned short usNewDimension;

        bitStream.ReadBit ( bVisible );
        bitStream.Read ( usNewDimension );

        pObject->SetVisibleInAllDimensions ( bVisible, usNewDimension );
    }
}
Пример #22
0
void CPedRPCs::SetPedDoingGangDriveby ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    // Read out the player and vehicle id
    bool bDriveby;
    unsigned char ucTimeContext;
    if ( bitStream.ReadBit ( bDriveby ) &&
         bitStream.Read ( ucTimeContext ) )
    {
        // Grab the ped
        CClientPed * pPed = m_pPedManager->Get ( pSource->GetID (), true );
        if ( pPed )
        {
            pPed->SetSyncTimeContext ( ucTimeContext );

            pPed->SetDoingGangDriveby ( bDriveby );
        }
    }
}
Пример #23
0
void CElementRPCs::RemoveElementData ( CClientEntity* pSource, NetBitStreamInterface& bitStream )
{
    // Read out the name length
    unsigned short usNameLength;
    bool bRecursive;
    if ( bitStream.ReadCompressed ( usNameLength ) )
    {
        SString strName;

        // Read out the name plus whether it's recursive or not
        if ( bitStream.ReadStringCharacters ( strName, usNameLength ) &&
             bitStream.ReadBit ( bRecursive ) )
        {
            // Remove that name
            pSource->DeleteCustomData ( strName, bRecursive );
        }
    }
}
Пример #24
0
bool CPlayerJoinDataPacket::Read ( NetBitStreamInterface& BitStream )
{
    m_szNick [ MAX_NICK_LENGTH ] = 0;
    m_szSerialUser [MAX_SERIAL_LENGTH] = 0;

    // Read out the stuff
    if ( !BitStream.Read ( m_usNetVersion ) ||
         !BitStream.Read ( m_usMTAVersion ) )
        return false;

    if ( m_usMTAVersion < 0x0102 )
    {
        // Clients earlier than 1.0.2 do not have a bitstream version
        m_usBitStreamVersion = 0x01;
    }
    else
    {
        if ( !BitStream.Read ( m_usBitStreamVersion ) )
            return false;
    }

    if ( m_usBitStreamVersion >= 0x0b )
    {
        unsigned int uiLength;
        BitStream.ReadCompressed ( uiLength );
        if ( uiLength < 1 || uiLength > 100 )
            return false;

        m_strPlayerVersion.assign ( uiLength, 32 );
        BitStream.Read ( &m_strPlayerVersion.at ( 0 ), uiLength );
    }

    if ( m_usBitStreamVersion >= 0x0e )
        m_bOptionalUpdateInfoRequired = BitStream.ReadBit ();
    else
        m_bOptionalUpdateInfoRequired = false;

    return ( BitStream.Read ( m_ucGameVersion ) &&
             BitStream.Read ( m_szNick, MAX_NICK_LENGTH ) &&
             BitStream.Read ( reinterpret_cast < char* > ( &m_Password ), 16 ) &&
             BitStream.Read ( m_szSerialUser, MAX_SERIAL_LENGTH ) );
}
Пример #25
0
bool CExplosionSyncPacket::Read(NetBitStreamInterface& BitStream)
{
    bool bHasOrigin;
    if (!BitStream.ReadBit(bHasOrigin))
        return false;

    m_OriginID = INVALID_ELEMENT_ID;
    if (bHasOrigin && !BitStream.Read(m_OriginID))
        return false;

    SPositionSync position(false);
    if (BitStream.Read(&position))
    {
        SExplosionTypeSync explosionType;
        if (BitStream.Read(&explosionType))
        {
            m_vecPosition = position.data.vecPosition;
            m_ucType = explosionType.data.uiType;
            return true;
        }
    }

    return false;
}
Пример #26
0
// Can't use bitStream.Version() here as it is sometimes not set
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.ReadBit())
                {
                    if (bitStream.ReadBit())
                    {
                        double dNum;
                        if (bitStream.Read(dNum))
                            ReadNumber(dNum);
                    }
                    else
                    {
                        float fNum;
                        if (bitStream.Read(fNum))
                            ReadNumber(RoundFromFloatSource(fNum));
                    }
                }
                else
                {
                    int iNum;
                    if (bitStream.ReadCompressed(iNum))
                        ReadNumber(iNum);
                }
                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
            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:
            {
                ElementID ElementID;
                if (bitStream.Read(ElementID))
                {
                    ReadElementID(ElementID);
                }
                break;
            }
        }
    }
    return true;
}
Пример #27
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;
            }
        }
    }
}
Пример #28
0
bool CVehiclePuresyncPacket::Read ( NetBitStreamInterface& BitStream )
{
    // Got a player to read?
    if ( m_pSourceElement )
    {
        CPlayer * pSourcePlayer = static_cast < CPlayer * > ( m_pSourceElement );

        // Player is in a vehicle?
        CVehicle* pVehicle = pSourcePlayer->GetOccupiedVehicle ();
        if ( pVehicle )
        {
            // 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 the keysync data
            CControllerState ControllerState;
            if ( !ReadFullKeysync ( ControllerState, BitStream ) )
                return false;

            // Read out its position
            SPositionSync position ( false );
            if ( !BitStream.Read ( &position ) )
                return false;
            pSourcePlayer->SetPosition ( position.data.vecPosition );

            // Jax: don't allow any outdated packets through
            unsigned char ucSeat;
            if ( !BitStream.Read ( ucSeat ) )
                return false;
            if ( ucSeat != pSourcePlayer->GetOccupiedVehicleSeat () )
            {
                // Mis-matching seats can happen when we warp into a different one,
                // which will screw up the whole packet
                return false;
            }

            // Read out the vehicle matrix only if he's the driver
            unsigned int uiSeat = pSourcePlayer->GetOccupiedVehicleSeat ();
            if ( uiSeat == 0 )
            {
                // Read out the vehicle rotation in degrees
                SRotationDegreesSync rotation;
                if( !BitStream.Read ( &rotation ) )
                    return false;

                // Set it
                pVehicle->SetPosition ( position.data.vecPosition );
                pVehicle->SetRotationDegrees ( rotation.data.vecRotation );

                // Move speed vector
                SVelocitySync velocity;
                if ( !BitStream.Read ( &velocity ) )
                    return false;

                pVehicle->SetVelocity ( velocity.data.vecVelocity );
                pSourcePlayer->SetVelocity ( velocity.data.vecVelocity );

                // Turn speed vector
                SVelocitySync turnSpeed;
                if ( !BitStream.Read ( &turnSpeed ) )
                    return false;

                pVehicle->SetTurnSpeed ( turnSpeed.data.vecVelocity );

                // Health
                SVehicleHealthSync health;
                if ( !BitStream.Read ( &health ) )
                    return false;
                float fPreviousHealth = pVehicle->GetHealth ();                
                float fHealth = health.data.fValue;

                // Less than last time?
                if ( fHealth < fPreviousHealth )
                {                 
                    // Grab the delta health
                    float fDeltaHealth = fPreviousHealth - fHealth;

					if ( fDeltaHealth > 0.0f )
					{
						// Call the onVehicleDamage event
						CLuaArguments Arguments;
						Arguments.PushNumber ( fDeltaHealth );
						pVehicle->CallEvent ( "onVehicleDamage", Arguments );
					}
                }
                pVehicle->SetHealth ( fHealth );

                // Trailer chain
                CVehicle* pTowedByVehicle = pVehicle;
                CVehicle* pTrailer = NULL;
                ElementID TrailerID;
                bool bHasTrailer;
                if ( !BitStream.ReadBit ( bHasTrailer ) )
                    return false;

                while ( bHasTrailer )
                {
                    BitStream.ReadCompressed ( TrailerID );
                    CElement* pElement = CElementIDs::GetElement ( TrailerID );
                    if ( pElement )
                        pTrailer = static_cast < CVehicle* > ( pElement );
                    
                    // Read out the trailer position and rotation
                    SPositionSync trailerPosition ( false );
                    if ( !BitStream.Read ( &trailerPosition ) )
                        return false;

                    SRotationDegreesSync trailerRotation;
                    if ( !BitStream.Read ( &trailerRotation ) )
                        return false;

                    // If we found the trailer
                    if ( pTrailer )
                    {
                        // Set its position and rotation
                        pTrailer->SetPosition ( trailerPosition.data.vecPosition );
                        pTrailer->SetRotationDegrees ( trailerRotation.data.vecRotation );
    
                        // Is this a new trailer, attached?
                        CVehicle* pCurrentTrailer = pTowedByVehicle->GetTowedVehicle ();
                        if ( pCurrentTrailer != pTrailer )
                        {
                            // If theres a trailer already attached
                            if ( pCurrentTrailer )
                            {
                                pTowedByVehicle->SetTowedVehicle ( NULL );
                                pCurrentTrailer->SetTowedByVehicle ( NULL );

                                // Tell everyone to detach them
                                CVehicleTrailerPacket AttachPacket ( pTowedByVehicle, pCurrentTrailer, false );
                                g_pGame->GetPlayerManager ()->BroadcastOnlyJoined ( AttachPacket );

                                // Execute the attach trailer script function
                                CLuaArguments Arguments;
                                Arguments.PushElement ( pTowedByVehicle );
                                pCurrentTrailer->CallEvent ( "onTrailerDetach", Arguments );
                            }

                            // If something else is towing this trailer
                            CVehicle* pCurrentVehicle = pTrailer->GetTowedByVehicle ();
                            if ( pCurrentVehicle )
                            {
                                pCurrentVehicle->SetTowedVehicle ( NULL );
                                pTrailer->SetTowedByVehicle ( NULL );

                                // Tell everyone to detach them
                                CVehicleTrailerPacket AttachPacket ( pCurrentVehicle, pTrailer, false );
                                g_pGame->GetPlayerManager ()->BroadcastOnlyJoined ( AttachPacket );

                                // Execute the attach trailer script function
                                CLuaArguments Arguments;
                                Arguments.PushElement ( pCurrentVehicle );
                                pTrailer->CallEvent ( "onTrailerDetach", Arguments );
                            }

                            pTowedByVehicle->SetTowedVehicle ( pTrailer );
                            pTrailer->SetTowedByVehicle ( pTowedByVehicle );

                            // Execute the attach trailer script function
                            CLuaArguments Arguments;
                            Arguments.PushElement ( pTowedByVehicle );
                            bool bContinue = pTrailer->CallEvent ( "onTrailerAttach", Arguments );

                            // Attach or detach trailers depending on the event outcome
                            CVehicleTrailerPacket TrailerPacket ( pTowedByVehicle, pTrailer, bContinue );
                            g_pGame->GetPlayerManager ()->BroadcastOnlyJoined ( TrailerPacket );
                        }
                    }
                    else
                        break;

                    pTowedByVehicle = pTrailer;

                    if ( BitStream.ReadBit ( bHasTrailer ) == false )
                        return false;
                }

                // If there was a trailer before
                CVehicle* pCurrentTrailer = pTowedByVehicle->GetTowedVehicle ();
                if ( pCurrentTrailer )
                {
                    pTowedByVehicle->SetTowedVehicle ( NULL );
                    pCurrentTrailer->SetTowedByVehicle ( NULL );

                    // Tell everyone else to detach them
                    CVehicleTrailerPacket AttachPacket ( pTowedByVehicle, pCurrentTrailer, false );
                    g_pGame->GetPlayerManager ()->BroadcastOnlyJoined ( AttachPacket );

                    // Execute the detach trailer script function
                    CLuaArguments Arguments;
                    Arguments.PushElement ( pTowedByVehicle );
                    pCurrentTrailer->CallEvent ( "onTrailerDetach", Arguments );                    
                }
            }

            // Player health
            SPlayerHealthSync health;
            if ( !BitStream.Read ( &health ) )
                return false;
            float fHealth = health.data.fValue;

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

            // Less than last packet's frame?
            if ( fHealth < fOldHealth && fHealthLoss > 0 )
            {
                // Call the onPlayerDamage event
                CLuaArguments Arguments;
                Arguments.PushNil ();
                Arguments.PushNumber ( false );
                Arguments.PushNumber ( false );
                Arguments.PushNumber ( fHealthLoss );
                pSourcePlayer->CallEvent ( "onPlayerDamage", Arguments );
            }
            pSourcePlayer->SetHealth ( fHealth );

			// Armor
            SPlayerArmorSync armor;
            if ( !BitStream.Read ( &armor ) )
                return false;
            float fArmor = armor.data.fValue;

			float fOldArmor = pSourcePlayer->GetArmor ();
			float fArmorLoss = fOldArmor - fArmor;

			// Less than last packet's frame?
			if ( fArmor < fOldArmor && fArmorLoss > 0 )
			{
				// Call the onPlayerDamage event
				CLuaArguments Arguments;
                Arguments.PushNil ();
                Arguments.PushNumber ( false );
                Arguments.PushNumber ( false );
				Arguments.PushNumber ( fArmorLoss );

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

            // Flags
            SVehiclePuresyncFlags flags;
            if ( !BitStream.Read ( &flags ) )
                return false;

            pSourcePlayer->SetWearingGoggles ( flags.data.bIsWearingGoggles );
            pSourcePlayer->SetDoingGangDriveby ( flags.data.bIsDoingGangDriveby );            

            // Weapon sync
            if ( flags.data.bHasAWeapon )
            {
                SWeaponSlotSync slot;
                if ( !BitStream.Read ( &slot ) )
                    return false;

                pSourcePlayer->SetWeaponSlot ( slot.data.uiSlot );

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

                    // Read aim data
                    SWeaponAimSync aim ( pSourcePlayer->GetWeaponRange (), true );
                    if ( !BitStream.Read ( &aim ) )
                        return false;
                    pSourcePlayer->SetAimDirection ( aim.data.fArm );
                    pSourcePlayer->SetSniperSourceVector ( aim.data.vecOrigin );
                    pSourcePlayer->SetTargettingVector ( aim.data.vecTarget );

                    // Read the driveby direction
                    SDrivebyDirectionSync driveby;
                    if ( !BitStream.Read ( &driveby ) )
                        return false;
                    pSourcePlayer->SetDriveByDirection ( driveby.data.ucDirection );
                }
            }
            else
                pSourcePlayer->SetWeaponSlot ( 0 );


            // Vehicle specific data if he's the driver
            if ( uiSeat == 0 )
            {
                ReadVehicleSpecific ( pVehicle, BitStream );

                // Set vehicle specific stuff if he's the driver
                pVehicle->SetSirenActive ( flags.data.bIsSirenOrAlarmActive );
                pVehicle->SetSmokeTrailEnabled ( flags.data.bIsSmokeTrailEnabled );
                pVehicle->SetLandingGearDown ( flags.data.bIsLandingGearDown );
                pVehicle->SetOnGround ( flags.data.bIsOnGround );
                pVehicle->SetInWater ( flags.data.bIsInWater );
                pVehicle->SetDerailed ( flags.data.bIsDerailed );
                pVehicle->SetHeliSearchLightVisible ( flags.data.bIsHeliSearchLightVisible );
            }

            // Read the vehicle_look_left and vehicle_look_right control states
            // if it's an aircraft.
            if ( flags.data.bIsAircraft )
            {
                ControllerState.LeftShoulder2 = BitStream.ReadBit () * 255;
                ControllerState.RightShoulder2 = BitStream.ReadBit () * 255;
            }

            pSourcePlayer->GetPad ()->NewControllerState ( ControllerState );

            // Success
            return true;
        }
    }

    return false;
}
Пример #29
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 ) )
					Read(bValue);
				break;
			}

            // Number type
			case LUA_TNUMBER:
			{
                bool bIsFloatingPoint;
                if ( bitStream.ReadBit ( bIsFloatingPoint ) && bIsFloatingPoint )
                {
                    float fNum;
                    if ( bitStream.Read ( fNum ) )
                        Read ( (double) fNum );
                }
                else
                {
                    long lNum;
                    if ( bitStream.ReadCompressed ( lNum ) )
                        Read ( (double) lNum );
                }
				break;
			}

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

            // Table reference
            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
                        szValue [ usLength ] = 0;
						Read ( szValue );
                    }

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

				break;
			}

            // Element type?
			case LUA_TLIGHTUSERDATA:
			{
				ElementID ElementID;
				if ( bitStream.ReadCompressed ( ElementID ) )
				{
					CElement * element = CElementIDs::GetElement ( ElementID );
					Read ( element );
				}
				break;
			}
		}
    }
    return true;
}
Пример #30
0
bool CProjectileSyncPacket::Read ( NetBitStreamInterface& BitStream )
{
    bool bHasOrigin;
    if ( !BitStream.ReadBit ( bHasOrigin ) )
        return false;

    m_OriginID = INVALID_ELEMENT_ID;
    if ( bHasOrigin && !BitStream.ReadCompressed ( m_OriginID ) )
        return false;

    SPositionSync origin ( false );
    if ( !BitStream.Read ( &origin ) )
        return false;
    m_vecOrigin = origin.data.vecPosition;

    SWeaponTypeSync weaponType;
    if ( !BitStream.Read ( &weaponType ) )
        return false;
    m_ucWeaponType = weaponType.data.ucWeaponType;

    switch ( m_ucWeaponType )
    {
        case 16: // WEAPONTYPE_GRENADE
        case 17: // WEAPONTYPE_TEARGAS            
        case 18: // WEAPONTYPE_MOLOTOV
        case 39: // WEAPONTYPE_REMOTE_SATCHEL_CHARGE
        {
            SFloatSync < 7, 17 > projectileForce;
            if ( !BitStream.Read ( &projectileForce ) )
                return false;
            m_fForce = projectileForce.data.fValue;

            SVelocitySync velocity;
            if ( !BitStream.Read ( &velocity ) )
                return false;
            m_vecMoveSpeed = velocity.data.vecVelocity;

            break;
        }
        case 19: // WEAPONTYPE_ROCKET
        case 20: // WEAPONTYPE_ROCKET_HS
        {
            bool bHasTarget;
            if ( !BitStream.ReadBit ( bHasTarget ) )
                return false;

            m_TargetID = INVALID_ELEMENT_ID;
            if ( bHasTarget && !BitStream.ReadCompressed ( m_TargetID ) )
                return false;

            SVelocitySync velocity;
            if ( !BitStream.Read ( &velocity ) )
                return false;
            m_vecMoveSpeed = velocity.data.vecVelocity;

            SRotationRadiansSync rotation ( true );
            if ( !BitStream.Read ( &rotation ) )
                return false;
            m_vecRotation = rotation.data.vecRotation;

            break;
        }
        case 58: // WEAPONTYPE_FLARE
        case 21: // WEAPONTYPE_FREEFALL_BOMB
            break;

        default:
            return false;
    }
    return true;
}