onfoot packet read

Smeruxa

t.me/smeruxa
Автор темы
Проверенный
1,387
733
Функция с чтением пакета: https://gitlab.com/blasthack/raksamp/-/blob/master/client/src/netgame.cpp#L127
Что я делаю не так? Почему не могу никак записать нормально синхру на плюсах?
8 бит я игнорирую в самом начале, перед getData
C++:
nlohmann::json getData(RakNet::BitStream* bs) {
    nlohmann::json data;

    uint16_t playerId;
    bool bHasLR, bHasUD, bHasSurfInfo, bAnimation;

    bs->Read(playerId);

    if (playerId < 0 || playerId > 1004) return data;
    sampapi::v037r1::Synchronization::OnfootData onfoot;
    memset(&onfoot, 0, sizeof(sampapi::v037r1::Synchronization::OnfootData));

    bs->Read(bHasLR);
    if (bHasLR) bs->Read(onfoot.m_controllerState.m_sLeftStickX);

    bs->Read(bHasUD);
    if (bHasUD) bs->Read(onfoot.m_controllerState.m_sLeftStickY);

    bs->Read(onfoot.m_controllerState.m_value);

    bs->Read(onfoot.m_position.x);
    bs->Read(onfoot.m_position.y);
    bs->Read(onfoot.m_position.z);

    bs->ReadNormQuat(
        onfoot.m_fQuaternion[0],
        onfoot.m_fQuaternion[1],
        onfoot.m_fQuaternion[2],
        onfoot.m_fQuaternion[3]
    );

    BYTE byteHealthArmour;
    bs->Read(byteHealthArmour);
    BYTE byteArmTemp = (byteHealthArmour & 0x0F);
    BYTE byteHlTemp = (byteHealthArmour >> 4);

    BYTE byteHealth = (byteHlTemp == 0xF) ? 100 : (byteHlTemp == 0 ? 0 : byteHlTemp * 7);
    BYTE byteArmour = (byteArmTemp == 0xF) ? 100 : (byteArmTemp == 0 ? 0 : byteArmTemp * 7);

    onfoot.m_nHealth = byteHealth;
    onfoot.m_nArmor = byteArmour;

    bs->Read(onfoot.m_nCurrentWeapon);
    bs->Read(onfoot.m_nSpecialAction);

    bs->ReadVector(
        onfoot.m_speed.x,
        onfoot.m_speed.y,
        onfoot.m_speed.z
    );

    bs->Read(bHasSurfInfo);
    if (bHasSurfInfo) {
        bs->Read(onfoot.m_nSurfingVehicleId);
        bs->Read(onfoot.m_surfingOffset.x);
        bs->Read(onfoot.m_surfingOffset.y);
        bs->Read(onfoot.m_surfingOffset.z);
    }
    else {
        onfoot.m_nSurfingVehicleId = -1;
    }

    uint16_t animId;
    bs->Read(bAnimation);
    if (bAnimation) {
        bs->Read(animId);
    }

    data["playerId"] = playerId;
    data["lrAnalog"] = (bHasLR) ? onfoot.m_controllerState.m_sLeftStickX : 0;
    data["udAnalog"] = (bHasUD) ? onfoot.m_controllerState.m_sLeftStickY : 0;
    data["wKeys"] = onfoot.m_controllerState.m_value;
    data["position"] = { onfoot.m_position.x, onfoot.m_position.y, onfoot.m_position.z };
    data["quaternion"] = { onfoot.m_fQuaternion[0], onfoot.m_fQuaternion[1], onfoot.m_fQuaternion[2], onfoot.m_fQuaternion[3] };
    data["health"] = onfoot.m_nHealth;
    data["armour"] = onfoot.m_nArmor;
    data["weapon"] = onfoot.m_nCurrentWeapon;
    data["specialAction"] = onfoot.m_nSpecialAction;
    data["moveSpeed"] = { onfoot.m_speed.x, onfoot.m_speed.y, onfoot.m_speed.z };
    data["surfingOffsets"] = (bHasSurfInfo) ?
        nlohmann::json::array({ onfoot.m_surfingOffset.x, onfoot.m_surfingOffset.y, onfoot.m_surfingOffset.z }) :
        nlohmann::json::array({ 0, 0, 0 });
    data["surfingVehicleId"] = (bHasSurfInfo) ? onfoot.m_nSurfingVehicleId : -1;
    data["animationId"] = (bAnimation) ? animId : 0;

    return data;
}
 

whyega52

Гений, миллионер, плейбой, долбаеб
Модератор
2,806
2,679