Esempio n. 1
0
        /// <summary>
        ///     Decodes the specified <seealso cref="ByteBuffer" /> into an <seealso cref="Index" /> object.
        /// </summary>
        /// <param name="buf"> The buffer. </param>
        /// <returns> The index. </returns>
        public static Index Decode(ByteBuffer buf)
        {
            if (buf.remaining() != SIZE)
            {
                throw new ArgumentException();
            }

            var size   = ByteBufferExtensions.GetTriByte(buf);
            var sector = ByteBufferExtensions.GetTriByte(buf);

            return(new Index(size, sector));
        }
Esempio n. 2
0
        /// <summary>
        ///     Decodes the specified <seealso cref="ByteBuffer" /> into a <seealso cref="Sector" /> object.
        /// </summary>
        /// <param name="buf"> The buffer. </param>
        /// <returns> The sector. </returns>
        public static Sector Decode(ByteBuffer buf)
        {
            if (buf.remaining() != SIZE)
            {
                throw new ArgumentException();
            }

            var id         = buf.getShort() & 0xFFFF;
            var chunk      = buf.getShort() & 0xFFFF;
            var nextSector = ByteBufferExtensions.GetTriByte(buf);
            var type       = buf.get() & 0xFF;
            var data       = new byte[DATA_SIZE];

            buf.get(data);

            return(new Sector(type, id, chunk, nextSector, data));
        }
Esempio n. 3
0
        /// <summary>
        ///     Decodes the <seealso cref="Sprite" /> from the specified <seealso cref="ByteBuffer" />.
        /// </summary>
        /// <param name="buffer"> The buffer. </param>
        /// <returns> The sprite. </returns>
        public static Sprite Decode(ByteBuffer buffer)
        {
            /* find the size of this sprite set */
            buffer.position(buffer.limit() - 2);
            var size = buffer.getShort() & 0xFFFF;

            /* allocate arrays to store info */
            var offsetsX   = new int[size];
            var offsetsY   = new int[size];
            var subWidths  = new int[size];
            var subHeights = new int[size];

            /* read the width, height and palette size */
            buffer.position(buffer.limit() - size * 8 - 7);
            var width   = buffer.getShort() & 0xFFFF;
            var height  = buffer.getShort() & 0xFFFF;
            var palette = new int[(buffer.get() & 0xFF) + 1];

            /* and allocate an object for this sprite set */
            var set = new Sprite(width, height, size);

            /* read the offsets and dimensions of the individual sprites */
            for (var i = 0; i < size; i++)
            {
                offsetsX[i] = buffer.getShort() & 0xFFFF;
            }
            for (var i = 0; i < size; i++)
            {
                offsetsY[i] = buffer.getShort() & 0xFFFF;
            }
            for (var i = 0; i < size; i++)
            {
                subWidths[i] = buffer.getShort() & 0xFFFF;
            }
            for (var i = 0; i < size; i++)
            {
                subHeights[i] = buffer.getShort() & 0xFFFF;
            }

            /* read the palette */
            buffer.position(buffer.limit() - size * 8 - 7 - (palette.Length - 1) * 3);
            palette[0] = 0; // transparent colour (black)
            for (var index = 1; index < palette.Length; index++)
            {
                palette[index] = ByteBufferExtensions.GetTriByte(buffer);
                if (palette[index] == 0)
                {
                    palette[index] = 1;
                }
            }

            /* read the pixels themselves */
            buffer.position(0);
            for (var id = 0; id < size; id++)
            {
                /* grab some frequently used values */
                int subWidth  = subWidths[id],
                    subHeight = subHeights[id];
                int offsetX   = offsetsX[id],
                    offsetY   = offsetsY[id];

                /* create a BufferedImage to store the resulting image */
                var image = set.frames[id] = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

                /* allocate an array for the palette indices */
                //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
                //ORIGINAL LINE: int[][] indices = new int[subWidth][subHeight];
                var indices = ArrayUtil.ReturnRectangularArray <int>(subWidth, subHeight);

                /* read the flags so we know whether to read horizontally or vertically */
                var flags = buffer.get() & 0xFF;

                /* read the palette indices */
                if ((flags & FLAG_VERTICAL) != 0)
                {
                    for (var x = 0; x < subWidth; x++)
                    {
                        for (var y = 0; y < subHeight; y++)
                        {
                            indices[x][y] = buffer.get() & 0xFF;
                        }
                    }
                }
                else
                {
                    for (var y = 0; y < subHeight; y++)
                    {
                        for (var x = 0; x < subWidth; x++)
                        {
                            indices[x][y] = buffer.get() & 0xFF;
                        }
                    }
                }

                /* read the alpha (if there is alpha) and convert values to ARGB */
                if ((flags & FLAG_ALPHA) != 0)
                {
                    if ((flags & FLAG_VERTICAL) != 0)
                    {
                        for (var x = 0; x < subWidth; x++)
                        {
                            for (var y = 0; y < subHeight; y++)
                            {
                                var alpha = buffer.get() & 0xFF;
                                image.setRGB(x + offsetX, y + offsetY, alpha << 24 | palette[indices[x][y]]);
                            }
                        }
                    }
                    else
                    {
                        for (var y = 0; y < subHeight; y++)
                        {
                            for (var x = 0; x < subWidth; x++)
                            {
                                var alpha = buffer.get() & 0xFF;
                                image.setRGB(x + offsetX, y + offsetY, alpha << 24 | palette[indices[x][y]]);
                            }
                        }
                    }
                }
                else
                {
                    for (var x = 0; x < subWidth; x++)
                    {
                        for (var y = 0; y < subHeight; y++)
                        {
                            var index = indices[x][y];
                            if (index == 0)
                            {
                                image.setRGB(x + offsetX, y + offsetY, 0);
                            }
                            else
                            {
                                image.setRGB(x + offsetX, y + offsetY, (int)(0xFF000000 | palette[index]));
                            }
                        }
                    }
                }
            }
            return(set);
        }
Esempio n. 4
0
        /// <param name="buffer">
        ///     A <seealso cref="ByteBuffer" /> that contains information
        ///     such as the items location.
        /// </param>
        /// <returns> a new ItemDefinition. </returns>
        //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
        //ORIGINAL LINE: @SuppressWarnings("unused") public static ItemDefinition decode(java.nio.ByteBuffer buffer)
        public static ItemDefinition Decode(ByteBuffer buffer)
        {
            var def = new ItemDefinition();

            def.groundOptions = new[]
            {
                null,
                null,
                "take",
                null,
                null
            };
            def.inventoryOptions = new[]
            {
                null,
                null,
                null,
                null,
                "drop"
            };
            while (true)
            {
                var opcode = buffer.get() & 0xFF;
                if (opcode == 0)
                {
                    break;
                }
                if (opcode == 1)
                {
                    def.inventoryModelId = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 2)
                {
                    def.name = ByteBufferExtensions.GetJagexString(buffer);
                }
                else if (opcode == 4)
                {
                    def.modelZoom = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 5)
                {
                    def.modelRotation1 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 6)
                {
                    def.modelRotation2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 7)
                {
                    def.modelOffset1 = buffer.getShort() & 0xFFFFF;
                    if (def.modelOffset1 > 32767)
                    {
                        def.modelOffset1 -= 65536;
                    }
                    def.modelOffset1 <<= 0;
                }
                else if (opcode == 8)
                {
                    def.modelOffset2 = buffer.getShort() & 0xFFFFF;
                    if (def.modelOffset2 > 32767)
                    {
                        def.modelOffset2 -= 65536;
                    }
                    def.modelOffset2 <<= 0;
                }
                else if (opcode == 11)
                {
                    def.stackable = 1;
                }
                else if (opcode == 12)
                {
                    def.value = buffer.getInt();
                }
                else if (opcode == 16)
                {
                    def.membersOnly = true;
                }
                else if (opcode == 23)
                {
                    def.maleWearModel1 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 24)
                {
                    def.femaleWearModel1 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 25)
                {
                    def.maleWearModel2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 26)
                {
                    def.femaleWearModel2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode >= 30 && opcode < 35)
                {
                    def.groundOptions[opcode - 30] = buffer.GetJagexString();
                }
                else if (opcode >= 35 && opcode < 40)
                {
                    def.inventoryOptions[opcode - 35] = buffer.GetJagexString();
                }
                else if (opcode == 40)
                {
                    var length = buffer.get() & 0xFF;
                    def.originalModelColors = new short[length];
                    def.modifiedModelColors = new short[length];
                    for (var index = 0; index < length; index++)
                    {
                        def.originalModelColors[index] = unchecked ((short)(buffer.getShort() & 0xFFFFF));
                        def.modifiedModelColors[index] = unchecked ((short)(buffer.getShort() & 0xFFFFF));
                    }
                }
                else if (opcode == 41)
                {
                    var length = buffer.get() & 0xFF;
                    def.textureColour1 = new short[length];
                    def.textureColour2 = new short[length];
                    for (var index = 0; index < length; index++)
                    {
                        def.textureColour1[index] = unchecked ((short)(buffer.getShort() & 0xFFFFF));
                        def.textureColour2[index] = unchecked ((short)(buffer.getShort() & 0xFFFFF));
                    }
                }
                else if (opcode == 42)
                {
                    var length = buffer.get() & 0xFF;
                    for (var index = 0; index < length; index++)
                    {
                        int i = buffer.get();
                    }
                }
                else if (opcode == 65)
                {
                    def.unnoted = true;
                }
                else if (opcode == 78)
                {
                    def.colourEquip1 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 79)
                {
                    def.colourEquip2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 90)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 91)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 92)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 93)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 95)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 96)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 97)
                {
                    def.notedId = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 98)
                {
                    def.notedTemplateId = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode >= 100 && opcode < 110)
                {
                    if (def.stackableIds == null)
                    {
                        def.stackableIds     = new int[10];
                        def.stackableAmounts = new int[10];
                    }
                    def.stackableIds[opcode - 100]     = buffer.getShort() & 0xFFFFF;
                    def.stackableAmounts[opcode - 100] = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 110)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 111)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 112)
                {
                    var i = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 113)
                {
                    int i = buffer.get();
                }
                else if (opcode == 114)
                {
                    var i = buffer.get() * 5;
                }
                else if (opcode == 115)
                {
                    def.teamId = buffer.get() & 0xFF;
                }
                else if (opcode == 121)
                {
                    def.lendId = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 122)
                {
                    def.lendTemplateId = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 125)
                {
                    var i  = buffer.get() << 0;
                    var i2 = buffer.get() << 0;
                    var i3 = buffer.get() << 0;
                }
                else if (opcode == 126)
                {
                    var i  = buffer.get() << 0;
                    var i2 = buffer.get() << 0;
                    var i3 = buffer.get() << 0;
                }
                else if (opcode == 127)
                {
                    var i  = buffer.get() & 0xFF;
                    var i2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 128)
                {
                    var i  = buffer.get() & 0xFF;
                    var i2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 129)
                {
                    var i  = buffer.get() & 0xFF;
                    var i2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 130)
                {
                    var i  = buffer.get() & 0xFF;
                    var i2 = buffer.getShort() & 0xFFFFF;
                }
                else if (opcode == 132)
                {
                    var len = buffer.get() & 0xFF;
                    for (var index = 0; index < len; index++)
                    {
                        var anInt = buffer.getShort() & 0xFFFFF;
                    }
                }
                else if (opcode == 249)
                {
                    var length = buffer.get() & 0xFF;
                    for (var index = 0; index < length; index++)
                    {
                        var stringInstance = buffer.get() == 1;
                        var key            = ByteBufferExtensions.GetTriByte(buffer);
                        var value          = stringInstance ? (object)ByteBufferExtensions.GetJagexString(buffer) : buffer.getInt();
                    }
                }
            }
            return(def);
        }