byteArrayToFloat() public static method

public static byteArrayToFloat ( byte array, int reversed ) : float
array byte
reversed int
return float
Example #1
0
        public float readFloat(int reversed)
        {
            float value = 0;

            value  = NumericalUtils.byteArrayToFloat(new byte[] { packetData[offset], packetData[offset + 1], packetData[offset + 2], packetData[offset + 3] }, reversed);
            offset = offset + 4;
            return(value);
        }
Example #2
0
 static public void LtVector3fToFloats(byte[] LtVector3f, ref float x, ref float y, ref float z)
 {
     byte[] tempX = { 0x00, 0x00, 0x00, 0x00 };
     byte[] tempY = { 0x00, 0x00, 0x00, 0x00 };
     byte[] tempZ = { 0x00, 0x00, 0x00, 0x00 };
     for (int i = 0; i < 4; i++)
     {
         tempX[i] = LtVector3f[i];
         tempY[i] = LtVector3f[i + 4];
         tempZ[i] = LtVector3f[i + 8];
     }
     x = NumericalUtils.byteArrayToFloat(tempX, 1);
     y = NumericalUtils.byteArrayToFloat(tempY, 1);
     z = NumericalUtils.byteArrayToFloat(tempZ, 1);
 }
Example #3
0
        public int parseAttributes(ref byte[] buffer, int _offset)
        {
            int  offset = _offset;
            byte flag   = 0x00;

            flag = BufferHandler.readByte(ref buffer, ref offset);

            byte[] stateData = new byte[buffer.Length - offset + 2];
            ArrayUtils.copy(buffer, offset - 2, stateData, 0, buffer.Length - offset + 2);
            //Flag Bits{0,0,0,0,Vector3f Position Update,  Yaw Update,Animation Update, AttributesPacked Update?}


            switch (flag)
            {
            case 0x02:
                Action.setValue(BufferHandler.readBytes(ref buffer, ref offset, Action.getSize()));
                break;


            case 0x04:
                YawInterval.setValue(BufferHandler.readBytes(ref buffer, ref offset, YawInterval.getSize()));
                break;


            case 0x08:
                double x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1);
                double y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1);
                double z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z));
                break;

            case 0x0e:
                // UInt16 unknown + LtVector3f
                UInt16 unknown = NumericalUtils.ByteArrayToUint16(BufferHandler.readBytes(ref buffer, ref offset, 2), 1);
                float  xPos    = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1);
                float  yPos    = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1);
                float  zPos    = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d((double)xPos, (double)yPos, (double)zPos));
                break;
            }

            // TODO: update player attribute packets someday (announce it to my spawners)
            Store.world.sendViewPacketToAllPlayers(stateData, Store.currentClient.playerData.getCharID(), NumericalUtils.ByteArrayToUint16(Store.currentClient.playerInstance.GetGoid(), 1), Store.currentClient.playerData.getEntityId());
            return(offset);
        }
Example #4
0
        private static void ParseContent(ref byte[] packetData)
        {
            buffer = null;
            buffer = packetData;
            offset = 0;             //initialize to initial byte

            byte temp;

            temp = BufferHandler.readByte(ref packetData, ref offset);

            // Convert to Ack Flags
            BitArray AckFlags = NumericalUtils.byteToBitArray(temp);

            /* Flag Field
             * 1 - unknown / nothing
             * 2 - isAck (should always be )
             * 3 - unknown currently
             * 4 - unknown currently
             * 5 - SERVERFLAGS_RESETRCC
             * 6 - CLIENTFLAGS_RESETDONE (so its done)
             * 7 - SERVERFLAG_SIMTIME (aka 0x82, 0xc2)
             */

            if (AckFlags.Get(1) == false)
            {
                Output.WriteDebugLog("[WARNING] Packet has acked not set and is encrypted");
            }

            if (AckFlags.Get(7) == true)
            {
                byte[] simTime = BufferHandler.readBytes(ref packetData, ref offset, 4);
                Store.currentClient.playerData.setClientSimTime(NumericalUtils.byteArrayToFloat(simTime, 1));
            }


            if (AckFlags.Get(6) == true)
            {
                Output.WriteDebugLog("[CLIENT]CLIENTFLAGS_RESETDONE found - we can init new RCC Comm ");
                // Reset comm
                Store.currentClient.playerData.setCseq(0);
                Store.currentClient.playerData.setSseq(0);
                Store.currentClient.playerData.setPss(0x00);
                Store.currentClient.playerData.setOnWorld(false);
                Store.currentClient.playerData.setRPCShutDown(false);
                Store.currentClient.playerData.setRPCCounter(0);
                PlayerHandler handler = new PlayerHandler();
                handler.processAttributes();
                handler.processPlayerSetup();
            }


            if (packetData.Length > 1 && AckFlags.Get(1) == true) //Not just ACK nor Resetting

            {
                if (packetData[offset] == 0x05)
                {
                    offset = offset + 4;
                    Output.writeToLogForConsole("Its a 05 Packet");
                    Store.currentClient.messageQueue.ackOnlyCount = Store.currentClient.messageQueue.ackOnlyCount + 1;
                    Store.currentClient.flushQueue();
                    // We dont need a handler for 05 Packets (as there is only one as i see lol)
                }

                if (packetData[offset] == 0x03)                // Is a 03 packet
                {
                    offset++;
                    offset = man03.parse(offset, ref buffer);
                }


                if (offset < packetData.Length)                 // There is no more info if we'r out of offset

                {
                    if (packetData[offset] == 0x04)                    // Is a 04 packet
                    {
                        offset++;
                        offset = man04.parse(offset, ref buffer);
                    }
                }

                if (Store.currentClient.messageQueue.ObjectMessagesQueue.Count == 0 && Store.currentClient.messageQueue.RPCMessagesQueue.Count == 0)
                {
                    // nothing to send ? we should really ack something then
                    Store.currentClient.messageQueue.ackOnlyCount = Store.currentClient.messageQueue.ackOnlyCount + 1;
                    Store.currentClient.flushQueue();
                }
            }
        }
Example #5
0
        public int parseAttributes(ref byte[] buffer, int _offset)
        {
            _offset++;
            byte flag = 0x00;

            flag = BufferHandler.readByte(ref buffer, ref _offset);

            byte[] stateData = new byte[buffer.Length - _offset + 2];
            ArrayUtils.copy(buffer, _offset - 2, stateData, 0, buffer.Length - _offset + 2);
            //Flag Bits{0,0,0,0,Vector3f Position Update,  Yaw Update,Animation Update, AttributesPacked Update?}

            double x = 0;
            double y = 0;
            double z = 0;

            switch (flag)
            {
            case 0x02:
                Action.setValue(BufferHandler.readBytes(ref buffer, ref _offset, Action.getSize()));
                break;


            case 0x04:
                YawInterval.setValue(BufferHandler.readBytes(ref buffer, ref _offset, YawInterval.getSize()));
                break;


            case 0x08:
                x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z));
                break;

            case 0x0a:
                YawInterval.setValue(BufferHandler.readByte(ref buffer, ref _offset));
                x = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                y = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                z = (double)NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z));
                break;

            case 0x0e:
                // UInt16 unknown + LtVector3f
                UInt16 unknown = NumericalUtils.ByteArrayToUint16(BufferHandler.readBytes(ref buffer, ref _offset, 2), 1);
                x = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                y = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                z = NumericalUtils.byteArrayToFloat(BufferHandler.readBytes(ref buffer, ref _offset, 4), 1);
                Position.setValue(NumericalUtils.doublesToLtVector3d(x, y, z));
                break;

            default:
                // ToDo: we need a proper way to proove if there is a 00 00 04 somewhere (and if set the offset to it)

                // If this doesnt match we need to write this somewhere...
                string message = "RPCMAIN : Unknown Client 03 Request Packet \r\n" +
                                 "Flag: " + flag + "\r\n " +
                                 "Content: \n" +
                                 StringUtils.bytesToString(stateData) + "\r\n";
                Output.WriteClientViewRequestLog(message);

                // ...and we dont want to crash so we just say "offset is full packet"
                _offset = buffer.Length - 1;
                break;
            }

            // TODO: update player attribute packets someday (announce it to my spawners)
            Store.world.sendViewPacketToAllPlayers(stateData, Store.currentClient.playerData.getCharID(), NumericalUtils.ByteArrayToUint16(Store.currentClient.playerInstance.GetGoid(), 1), Store.currentClient.playerData.getEntityId());
            return(_offset);
        }