Пример #1
0
        internal async Task ReadExportTableEntry(ByteArrayReader reader, DomainHeader header)
        {
            TypeReference   = reader.ReadInt32();
            ParentReference = reader.ReadInt32();
            OwnerReference  = reader.ReadInt32();

            NameTableIndex.ReadNameTableIndex(reader, header);

            ArchetypeReference = reader.ReadInt32();

            FlagsHigh = reader.ReadUInt32();
            FlagsLow  = reader.ReadUInt32();

            SerialDataSize   = reader.ReadInt32();
            SerialDataOffset = reader.ReadInt32();

            ExportFlags = reader.ReadUInt32();

            NetObjectCount = reader.ReadInt32();

            Guid = await reader.ReadBytes(16);

            Unknown1 = reader.ReadUInt32();

            Unknown2 = await reader.ReadBytes(sizeof(uint) *NetObjectCount);
        }
Пример #2
0
        public async Task ReadString(ByteArrayReader reader)
        {
            Size = reader.ReadInt32();

            if (Size == 0)
            {
                String = String.Empty;

                return;
            }

            if (Size < 0)
            {
                int size = -Size * 2;

                byte[] str = await reader.ReadBytes(size - 2);

                reader.Skip(2); // NULL Terminator

                String = Encoding.Unicode.GetString(str);
            }
            else
            {
                byte[] str = await reader.ReadBytes(Size - 1);

                reader.Skip(1); // NULL Terminator

                String = Encoding.ASCII.GetString(str);
            }
        }
Пример #3
0
        private async Task readUpkHeader()
        {
            reader.Seek(0);

            Signature = reader.ReadUInt32();

            if (Signature == Signatures.EncryptedSignature)
            {
                await reader.Decrypt();
            }
            else if (Signature != Signatures.Signature)
            {
                throw new Exception("File is not a properly formatted UPK file.");
            }

            Version  = reader.ReadUInt16();
            Licensee = reader.ReadUInt16();

            Size = reader.ReadInt32();

            await Group.ReadString(reader);

            Flags = reader.ReadUInt32();

            NameTableCount  = reader.ReadInt32();
            NameTableOffset = reader.ReadInt32();

            ExportTableCount  = reader.ReadInt32();
            ExportTableOffset = reader.ReadInt32();

            ImportTableCount  = reader.ReadInt32();
            ImportTableOffset = reader.ReadInt32();

            DependsTableOffset = reader.ReadInt32();

            Guid = await reader.ReadBytes(16);

            GenerationTableCount = reader.ReadInt32();

            GenerationTable = await readGenerationTable();

            EngineVersion = reader.ReadUInt32();
            CookerVersion = reader.ReadUInt32();

            CompressionFlags = reader.ReadUInt32();

            CompressionTableCount = reader.ReadInt32();

            CompressedChunks = await readCompressedChunksTable();

            Unknown1 = reader.ReadUInt32();
            Unknown2 = reader.ReadUInt32();
        }
Пример #4
0
        public override async Task ReadDomainObject(ByteArrayReader reader, DomainHeader header, DomainExportTableEntry export, bool skipProperties, bool skipParse)
        {
            await base.ReadDomainObject(reader, header, export, skipProperties, skipParse);

            if (skipParse)
            {
                return;
            }

            MipMapsCount = reader.ReadInt32();

            for (int i = 0; i < MipMapsCount; ++i)
            {
                await ProcessCompressedBulkData(reader, async bulkChunk => {
                    DomainMipMap mip = new DomainMipMap
                    {
                        Width  = reader.ReadInt32(),
                        Height = reader.ReadInt32()
                    };

                    if (mip.Width >= 4 || mip.Height >= 4)
                    {
                        mip.ImageData = (await bulkChunk.DecompressChunk(0))?.GetBytes();
                    }

                    MipMaps.Add(mip);
                });
            }

            Guid = await reader.ReadBytes(16);
        }
Пример #5
0
        CommResponse IProtocolCodec.ServerDecode(CommDataBase data)
        {
            ModbusServer    ownerProtocol = (ModbusServer)data.OwnerProtocol;
            ByteArrayReader incomingData  = data.IncomingData;
            int             length        = incomingData.Length;

            if (length < 4)
            {
                return(new CommResponse(data, 0));
            }
            if ((int)incomingData.ReadByte() == (int)ownerProtocol.Address)
            {
                byte fc = incomingData.ReadByte();
                if ((int)fc < ModbusCodecBase.CommandCodecs.Length)
                {
                    ModbusCommand command = new ModbusCommand(fc);
                    data.UserData            = (object)command;
                    command.QueryTotalLength = 6;
                    ModbusCommandCodec commandCodec = ModbusCodecBase.CommandCodecs[(int)fc];
                    ByteArrayReader    body         = new ByteArrayReader(incomingData.ReadBytes(length - 4));
                    commandCodec.ServerDecode(command, body);
                    ushort num = ByteArrayHelpers.CalcCRC16(incomingData.ToArray(), 0, command.QueryTotalLength - 2);
                    if ((int)ByteArrayHelpers.ReadInt16LE(((IByteArray)incomingData).Data, command.QueryTotalLength - 2) == (int)(short)num)
                    {
                        return(new CommResponse(data, 3));
                    }
                }
            }
            return(new CommResponse(data, 1));
        }
Пример #6
0
        CommResponse IProtocolCodec.ClientDecode(CommDataBase data)
        {
            ModbusClient    ownerProtocol = (ModbusClient)data.OwnerProtocol;
            ModbusCommand   userData      = (ModbusCommand)data.UserData;
            ByteArrayReader incomingData  = data.IncomingData;
            int             count         = incomingData.Length - 4;

            if (count >= 0 && (int)incomingData.ReadByte() == (int)ownerProtocol.Address)
            {
                byte            num1 = incomingData.ReadByte();
                ByteArrayReader body = new ByteArrayReader(incomingData.ReadBytes(count));
                ushort          num2 = ByteArrayHelpers.CalcCRC16(incomingData.ToArray(), 0, incomingData.Length - 2);
                if ((int)incomingData.ReadInt16LE() == (int)(short)num2 && ((int)num1 & (int)sbyte.MaxValue) == (int)userData.FunctionCode)
                {
                    if (num1 <= (byte)127)
                    {
                        ModbusCodecBase.CommandCodecs[(int)num1]?.ClientDecode(userData, body);
                        return(new CommResponse(data, 3));
                    }
                    if (incomingData.CanRead(1))
                    {
                        userData.ExceptionCode = incomingData.ReadByte();
                    }
                    return(new CommResponse(data, 2));
                }
            }
            return(new CommResponse(data, 0));
        }
Пример #7
0
        public void SetFullState(ByteArrayReader reader)
        {
            var isNull = reader.ReadBool();

            if (isNull)
            {
                _isNullWeapon = true;
                return;
            }
            else
            {
                _isNullWeapon = false;
            }
            TargetingType                             = (WeaponTargetingType)reader.ReadByte();
            MaxDistance                               = reader.ReadFloat();
            ProjectileType                            = ResolveTypeFromString(reader.ReadString());
            ProjectileVelocity                        = reader.ReadHalfVector();
            ProjectileOffset                          = reader.ReadHalfVector();
            ProjectileRotation                        = reader.ReadHalf();
            ProjectileRotationVelocity                = reader.ReadHalf();
            MaxActiveProjectileCount                  = reader.ReadUShort();
            FireRotationIsRelativeToTankRotation      = reader.ReadBool();
            FireRotationIsRelativeToTankLookDirection = reader.ReadBool();
            AddedRotation                             = reader.ReadHalf();
            TransformPositionAndVelocityByRotation    = reader.ReadBool();
            WeaponRechargeTime                        = reader.ReadTimeSpan();
            WeaponName    = reader.ReadString();
            TimeRecharged = reader.ReadTimeSpan();

            _projectileArray = reader.ReadBytes();
        }
Пример #8
0
        public void EmptyArray()
        {
            var reader = new ByteArrayReader(new byte[0]);
            Assert.Equal(0u, reader.Length);

            Assert.Throws<EndOfStreamException>(() => reader.ReadByte());
            Assert.Equal(0, reader.ReadBytes(new byte[10], 0, 10));
        }
Пример #9
0
        public override async Task ReadDomainObject(ByteArrayReader reader, DomainHeader header, DomainExportTableEntry export, bool skipProperties, bool skipParse)
        {
            await base.ReadDomainObject(reader, header, export, skipProperties, skipParse);

            if (skipParse)
            {
                return;
            }

            Unknown1 = await reader.ReadBytes(sizeof(uint) * 3);

            CompressedChunkOffset = reader.ReadInt32();
        }
Пример #10
0
        CommResponse IProtocolCodec.ClientDecode(CommDataBase data)
        {
            var             client   = (ModbusClient)data.OwnerProtocol;
            var             command  = (ModbusCommand)data.UserData;
            ByteArrayReader incoming = data.IncomingData;
            var             bodyLen  = incoming.Length - 4;

            //validate address first
            if (bodyLen >= 0 &&
                incoming.ReadByte() == client.Address)
            {
                //extract function code
                var fncode = incoming.ReadByte();

                //extract the message body
                var body = new ByteArrayReader(incoming.ReadBytes(bodyLen));

                //calculate the CRC-16 over the received stream
                ushort crc;
                unchecked
                {
                    crc = (ushort)ModbusRtuCodec.Crc16.Compute(
                        ((IByteArray)incoming).Data,
                        0,
                        incoming.Length - 2);
                }

                //validate the CRC-16
                if (incoming.ReadUInt16LE() == crc)
                {
                    //message looks consistent (although the body can be empty)
                    if ((fncode & 0x7F) == command.FunctionCode)
                    {
                        if (fncode <= 0x7F)
                        {
                            //encode the command body, if applies
                            var codec = CommandCodecs[fncode];
                            if (codec != null &&
                                codec.ClientDecode(command, body))
                            {
                                return(new CommResponse(
                                           data,
                                           CommResponse.Ack));
                            }
                        }
                        else
                        {
                            //exception
                            command.ExceptionCode = body.ReadByte();

                            return(new CommResponse(
                                       data,
                                       CommResponse.Critical));
                        }
                    }
                }
            }

            return(new CommResponse(
                       data,
                       CommResponse.Unknown));
        }
Пример #11
0
        CommResponse IProtocolCodec.ServerDecode(CommDataBase data)
        {
            var             server   = (ModbusServer)data.OwnerProtocol;
            ByteArrayReader incoming = data.IncomingData;

            //validate header first
            var length = incoming.Length;

            if (length < 4)
            {
                goto LabelUnknown;
            }

            //address
            var address = incoming.ReadByte();

            if (address == server.Address)
            {
                //function code
                var fncode = incoming.ReadByte();

                if (fncode < CommandCodecs.Length)
                {
                    //create a new command
                    var command = new ModbusCommand(fncode);
                    data.UserData            = command;
                    command.QueryTotalLength = 2; //= addr + fn (no crc)

                    //get the command codec
                    var codec = CommandCodecs[fncode];

                    //decode the command, where possible
                    var body = new ByteArrayReader(incoming.ReadBytes(length - 4));

                    if (codec.ServerDecode(command, body))
                    {
                        //calculate the CRC-16 over the received stream
                        ushort crcCalc;
                        unchecked
                        {
                            crcCalc = (ushort)ModbusRtuCodec.Crc16.Compute(
                                ((IByteArray)incoming).Data,
                                0,
                                command.QueryTotalLength);
                        }

                        //validate the CRC-16
                        ushort crcRead = ByteArrayHelpers.ReadUInt16LE(
                            ((IByteArray)incoming).Data,
                            command.QueryTotalLength);

                        if (crcRead == crcCalc)
                        {
                            return(new CommResponse(
                                       data,
                                       CommResponse.Ack));
                        }
                    }
                }
            }

            //exception
            return(new CommResponse(
                       data,
                       CommResponse.Ignore));

LabelUnknown:
            return(new CommResponse(
                       data,
                       CommResponse.Unknown));
        }