예제 #1
0
        public void Handle(int opcode, JagexBuffer buffer)
        {
            var index = buffer.ReadLEUShort();
            var value = buffer.ReadByte();

            var settings = GameContext.Settings;

            settings[index] = value;
        }
예제 #2
0
 private void ParseOpcode(int opcode, JagexBuffer b)
 {
     if (opcode == 1)
     {
         SetColor(Rgb = b.ReadTriByte());
     }
     else if (opcode == 2)
     {
         TextureIndex = b.ReadByte();
     }
     else if (opcode == 3)
     {
     }
     else if (opcode == 5)
     {
         ShowUnderlay = false;
     }
     else if (opcode == 6)
     {
         Name = b.ReadString(10);
     }
     else if (opcode == 7)
     {
         var hue2       = Hue2;
         var saturation = Saturation;
         var lightness  = Lightness;
         var hue        = Hue;
         SetColor(b.ReadTriByte());
         Hue2       = hue2;
         Saturation = saturation;
         Lightness  = lightness;
         Hue        = hue;
         HueDivisor = hue;
     }
     else
     {
         throw new Exception("Error unrecognised config code: " + opcode);
     }
 }
예제 #3
0
        public void LoadScript(JagexBuffer b)
        {
            int count = b.ReadUByte();

            byte[] compare_type  = null;
            int[]  compare_value = null;

            if (count > 0)
            {
                compare_type  = new byte[count];
                compare_value = new int[count];

                for (int i = 0; i < count; i++)
                {
                    compare_type[i]  = (byte)b.ReadByte();
                    compare_value[i] = b.ReadUShort();
                }
            }

            count = b.ReadUByte();

            if (count > 0)
            {
                Script = new WidgetScript[count];

                for (var i = 0; i < count; i++)
                {
                    var s = new WidgetScript(b, i);
                    if (compare_type != null && i < compare_type.Length)
                    {
                        s.compareType  = compare_type[i];
                        s.compareValue = compare_value[i];
                    }

                    Script[i] = s;
                }
            }
        }
예제 #4
0
        private void ParseOpcode(int opcode, JagexBuffer b)
        {
            if (opcode == 1)
            {
                modelIndex = (short)b.ReadUShort();
            }
            else if (opcode == 2)
            {
                name = b.ReadString(10);
            }
            else if (opcode == 3)
            {
                description = b.ReadString(10);
            }
            else if (opcode == 4)
            {
                iconDist = (short)b.ReadUShort();
            }
            else if (opcode == 5)
            {
                iconPitch = (short)b.ReadUShort();
            }
            else if (opcode == 6)
            {
                iconYaw = (short)b.ReadUShort();
            }
            else if (opcode == 7)
            {
                int x = b.ReadUShort();

                if (x > 32767)
                {
                    x -= 0x10000;
                }

                iconX = (short)x;
            }
            else if (opcode == 8)
            {
                int y = b.ReadUShort();

                if (y > 32767)
                {
                    y -= 0x10000;
                }

                iconY = (short)y;
            }
            else if (opcode == 10)
            {
                b.ReadUShort();
            }
            else if (opcode == 11)
            {
                stackable = true;
            }
            else if (opcode == 12)
            {
                pilePriority = b.ReadInt();
            }
            else if (opcode == 16)
            {
                isMembers = true;
            }
            else if (opcode == 23)
            {
                maleModel1 = (short)b.ReadUShort();
                maleOffY   = b.ReadByte();
            }
            else if (opcode == 24)
            {
                maleModel2 = (short)b.ReadUShort();
            }
            else if (opcode == 25)
            {
                femaleModel1 = (short)b.ReadUShort();
                femaleOffY   = b.ReadByte();
            }
            else if (opcode == 26)
            {
                femaleModel2 = (short)b.ReadUShort();
            }
            else if (opcode >= 30 && opcode < 35)
            {
                if (groundAction == null)
                {
                    groundAction = new string[5];
                }

                groundAction[opcode - 30] = b.ReadString(10);
            }
            else if (opcode >= 35 && opcode < 40)
            {
                if (action == null)
                {
                    action = new String[5];
                }

                var actionIdx = opcode - 35;
                action[actionIdx] = b.ReadString(10);
            }
            else if (opcode == 40)
            {
                int j = b.ReadUByte();
                oldColor = new int[j];
                newColor = new int[j];
                for (int k = 0; k < j; k++)
                {
                    oldColor[k] = b.ReadUShort();
                    newColor[k] = b.ReadUShort();
                }
            }
            else if (opcode == 78)
            {
                maleModel3 = (short)b.ReadUShort();
            }
            else if (opcode == 79)
            {
                femaleModel3 = (short)b.ReadUShort();
            }
            else if (opcode == 90)
            {
                maleDialogModel1 = (short)b.ReadUShort();
            }
            else if (opcode == 91)
            {
                femaleDialogModel1 = (short)b.ReadUShort();
            }
            else if (opcode == 92)
            {
                maleDialogModel2 = (short)b.ReadUShort();
            }
            else if (opcode == 93)
            {
                femaleDialogModel2 = (short)b.ReadUShort();
            }
            else if (opcode == 95)
            {
                iconRoll = (short)b.ReadUShort();
            }
            else if (opcode == 97)
            {
                noteItemIndex = (short)b.ReadUShort();
            }
            else if (opcode == 98)
            {
                noteTemplateIndex = (short)b.ReadUShort();
            }
            else if (opcode >= 100 && opcode < 110)
            {
                if (stackIndex == null)
                {
                    stackIndex  = new int[10];
                    stackAmount = new int[10];
                }
                stackIndex[opcode - 100]  = (short)b.ReadUShort();
                stackAmount[opcode - 100] = b.ReadUShort();
            }
            else if (opcode == 110)
            {
                scaleX = (short)b.ReadUShort();
            }
            else if (opcode == 111)
            {
                scaleY = (short)b.ReadUShort();
            }
            else if (opcode == 112)
            {
                scaleZ = (short)b.ReadUShort();
            }
            else if (opcode == 113)
            {
                brightness = b.ReadByte();
            }
            else if (opcode == 114)
            {
                specular = (short)(b.ReadByte() * 5);
            }
            else if (opcode == 115)
            {
                team = b.ReadByte();
            }
        }
예제 #5
0
        private void UpdatePlayerMask(int mask, int index, JagexBuffer b, Player p)
        {
            if ((mask & 0x400) != 0)
            {
                p.MoveStartX     = b.ReadUByteS();
                p.MoveStartY     = b.ReadUByteS();
                p.MoveEndX       = b.ReadUByteS();
                p.MoveEndY       = b.ReadUByteS();
                p.MoveCycleEnd   = b.ReadLEUShortA() + (int)GameContext.LoopCycle;
                p.MoveCycleStart = b.ReadUShortA() + (int)GameContext.LoopCycle;
                p.MoveDirection  = b.ReadUByteS();
                p.ResetQueuedMovements();
            }

            if ((mask & 0x100) != 0)
            {
                p.SpotAnimIndex = b.ReadLEUShort();
                var info = b.ReadInt();
                p.GraphicOffsetY   = info >> 16;
                p.SpotAnimCycleEnd = (int)GameContext.LoopCycle + (info & 0xffff);
                p.SpotAnimFrame    = 0;
                p.SpotAnimCycle    = 0;

                if (p.SpotAnimCycleEnd > GameContext.LoopCycle)
                {
                    p.SpotAnimFrame = -1;
                }

                if (p.SpotAnimIndex == 65535)
                {
                    p.SpotAnimIndex = -1;
                }
            }

            if ((mask & 8) != 0)
            {
                var seqIndex = b.ReadLEUShort();
                var delay    = b.ReadUByteC();
                if (seqIndex == 65535)
                {
                    seqIndex = -1;
                }

                var seq = GameContext.Cache.GetSeq(seqIndex);
                if (seq != null)
                {
                    if (seqIndex == p.SeqIndex && seqIndex != -1)
                    {
                        var type = seq.Type;
                        if (type == 1)
                        {
                            p.SeqFrame      = 0;
                            p.SeqCycle      = 0;
                            p.SeqDelayCycle = delay;
                            p.SeqResetCycle = 0;
                        }
                        else if (type == 2)
                        {
                            p.SeqResetCycle = 0;
                        }
                    }
                    else if (seqIndex == -1 || p.SeqIndex == -1 || (GameContext.Cache.GetSeq(p.SeqIndex) != null && seq.Priority >= GameContext.Cache.GetSeq(p.SeqIndex).Priority))
                    {
                        p.SeqIndex          = seqIndex;
                        p.SeqFrame          = 0;
                        p.SeqCycle          = 0;
                        p.SeqDelayCycle     = delay;
                        p.SeqResetCycle     = 0;
                        p.StillPathPosition = p.PathPosition;
                    }
                }
            }

            if ((mask & 4) != 0)
            {
                p.SpokenMessage = b.ReadString(10);

                if (p.SpokenMessage.ToCharArray()[0] == '~')
                {
                    p.SpokenMessage = p.SpokenMessage.Substring(1);
                    GameContext.Chat.Add(new ChatMessage(MessageType.Player, p.Name, p.SpokenMessage));
                }
                else if (p == GameContext.Self)
                {
                    GameContext.Chat.Add(new ChatMessage(MessageType.Player, p.Name, p.SpokenMessage));
                }

                p.SpokenColor  = 0;
                p.SpokenEffect = 0;
                p.SpokenLife   = 150;
            }

            if ((mask & 0x80) != 0)
            {
                var settings = b.ReadShort();
                var rights   = b.ReadByte();
                b.ReadByte();
                var length   = b.ReadUByteC();
                var startOff = b.Position();
                if (p.Name != null)
                {
                    var buf = new DefaultJagexBuffer(new byte[5000]);
                    b.ReadBytesReversed(buf.Array(), 0, length);
                    p.SpokenMessage = StringUtils.GetFormatted(length, buf);
                    p.SpokenEffect  = settings & 0xFF;
                    p.SpokenColor   = settings >> 8;
                    p.SpokenLife    = 150;

                    var sb = new StringBuilder();
                    sb.Append(p.Name);

                    var msg = new ChatMessage(MessageType.Player, sb.ToString(), p.SpokenMessage);
                    if (rights > 0)
                    {
                        msg.CrownIndex = rights;
                    }

                    GameContext.Chat.Add(msg);
                }

                b.Position(startOff + length);
            }

            if ((mask & 1) != 0)
            {
                p.FaceEntity = b.ReadLEUShort();

                if (p.FaceEntity == 65535)
                {
                    p.FaceEntity = -1;
                }
            }

            if ((mask & 0x10) != 0)
            {
                var payload = new byte[b.ReadUByteC()];
                b.ReadBytes(payload, 0, payload.Length);
                var pb = new DefaultJagexBuffer(payload);
                GameContext.PlayerBuffers[index] = pb;
                p.Update(pb);
            }

            if ((mask & 2) != 0)
            {
                p.FaceX = b.ReadLEUShortA();
                p.FaceY = b.ReadLEUShort();
            }

            if ((mask & 0x20) != 0)
            {
                var damage = b.ReadUShortA();
                var type   = b.ReadUByte();
                var icon   = b.ReadUByte();
                var soak   = b.ReadUShortA();
                p.QueueHit(type, damage, (int)GameContext.LoopCycle);
                p.CurrentHealth  = b.ReadUShortA();
                p.MaxHealth      = b.ReadUShortA();
                p.EndCombatCycle = (int)GameContext.LoopCycle + 300;
            }

            if ((mask & 0x200) != 0)
            {
                var damage = b.ReadUShortA();
                var type   = b.ReadUByte();
                var icon   = b.ReadUByte();
                var soak   = b.ReadUShortA();
                p.QueueHit(type, damage, (int)GameContext.LoopCycle);
                p.CurrentHealth  = b.ReadUShortA();
                p.MaxHealth      = b.ReadUShortA();
                p.EndCombatCycle = (int)GameContext.LoopCycle + 300;
            }
        }
예제 #6
0
        public void Update(JagexBuffer b)
        {
            b.Position(0);

            Gender     = b.ReadByte();
            PrayerIcon = b.ReadUByte();
            b.ReadByte();
            SkullIcon = b.ReadShort() == 0 ? -1 : 0;

            for (int i = 0; i < 12; i++)
            {
                int lsb = b.ReadUByte();

                if (lsb == 0)
                {
                    EquipmentIndices[i] = 0;
                    continue;
                }

                EquipmentIndices[i] = (lsb << 8) + b.ReadUByte();

                if (i == 0 && this.EquipmentIndices[0] == 65535)
                {
                    b.ReadUShort();
                    break;
                }
            }

            for (int i = 0; i < 5; i++)
            {
                colors[i] = b.ReadUByte();
            }

            StandAnimation = 625;//.ReadUShort();
            if (StandAnimation == 65535)
            {
                StandAnimation = -1;
            }

            StandTurnAnimation = b.ReadUShort();
            if (StandTurnAnimation == 65535)
            {
                StandTurnAnimation = -1;
            }

            WalkAnimation = b.ReadUShort();
            if (WalkAnimation == 65535)
            {
                WalkAnimation = -1;
            }

            Turn180Animation = b.ReadUShort();
            if (Turn180Animation == 65535)
            {
                Turn180Animation = -1;
            }

            TurnRightAnimation = b.ReadUShort();
            if (TurnRightAnimation == 65535)
            {
                TurnRightAnimation = -1;
            }

            TurnLeftAnimation = b.ReadUShort();
            if (TurnLeftAnimation == 65535)
            {
                TurnLeftAnimation = -1;
            }

            RunAnimation = b.ReadUShort();
            if (RunAnimation == 65535)
            {
                RunAnimation = -1;
            }

            this.Name        = StringUtils.Format(StringUtils.LongToString(b.ReadLong()));
            this.CombatLevel = (short)b.ReadUByte();
            b.ReadUShort();
            b.ReadUShort();

            this.Visible  = true;
            this.ModelUid = 0L;

            for (int i = 0; i < 12; i++)
            {
                this.ModelUid <<= 4;
                if (EquipmentIndices[i] >= 256)
                {
                    this.ModelUid += EquipmentIndices[i] - 256;
                }
            }

            if (EquipmentIndices[0] >= 256)
            {
                this.ModelUid += EquipmentIndices[0] - 256 >> 4;
            }

            if (EquipmentIndices[1] >= 256)
            {
                this.ModelUid += EquipmentIndices[1] - 256 >> 8;
            }

            for (int i = 0; i < 5; i++)
            {
                this.ModelUid <<= 3;
                this.ModelUid  += colors[i];
            }

            this.ModelUid <<= 1;
            this.ModelUid  += Gender;

            UnityObject.name = "Player " + Name;
            Dirty            = true;
            UpdateObjectScenePos();
        }
예제 #7
0
        public void Update()
        {
            if (Connected)
            {
                if (client == null || !client.Connected)
                {
                    Connected = false;
                    if (OnDisconnect != null)
                    {
                        OnDisconnect();
                    }
                    return;
                }

                try
                {
                    while (client.Available > 0)
                    {
                        var stream = client.GetStream();
                        stream.ReadTimeout = 5000;

                        if (lastOpcode == -1)
                        {
                            if (client.Available < 1)
                            {
                                break;
                            }

                            var buffer = new byte[1];
                            stream.Read(buffer, 0, 1);

                            InBuffer.Position(0);
                            InBuffer.WriteBytes(buffer, 0, 1);
                            InBuffer.Position(0);
                            lastOpcode = InBuffer.ReadByte() - GameContext.InCipher.NextInt() & 0xFF;
                            lastSize   = GameConstants.PacketSizes[lastOpcode];
                        }

                        if (lastSize == -1 || lastSize == -2)
                        {
                            if (client.Available < 2)
                            {
                                break;
                            }

                            var buffer = new byte[2];
                            stream.Read(buffer, 0, lastSize == -1 ? 1 : 2);

                            InBuffer.Position(0);
                            InBuffer.WriteBytes(buffer, 0, lastSize == -1 ? 1 : 2);
                            InBuffer.Position(0);
                            lastSize = lastSize == -1 ? InBuffer.ReadUByte() : InBuffer.ReadUShort();
                        }

                        if (client.Available < lastSize)
                        {
                            break;
                        }

                        var pbuffer = new byte[lastSize];
                        stream.Read(pbuffer, 0, pbuffer.Length);
                        var packet = new Packet(lastOpcode, pbuffer);
                        packet.Position(0);

                        PacketHandler handler;
                        if (PacketHandlers.TryGetValue(packet.Opcode, out handler))
                        {
                            handler.Handle(packet.Opcode, packet);
                        }

                        lastOpcode = -1;
                        lastSize   = -1;
                    }

                    lastKeepAlive += 1;
                    if (lastKeepAlive >= 50)
                    {
                        lastKeepAlive = 0;
                        Write(new Packet(0));
                    }

                    FlushAll();
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                    Connected = false;
                    if (OnDisconnect != null)
                    {
                        OnDisconnect();
                    }
                }
            }
        }
예제 #8
0
        private void ParseOpcode(int opcode, JagexBuffer b)
        {
            if (opcode == 1)
            {
                int count = b.ReadUByte();
                if (count > 0)
                {
                    if (modelIndices == null)
                    {
                        modelIndices = new int[count];
                        modelTypes   = new int[count];
                        for (int j = 0; j < count; j++)
                        {
                            modelIndices[j] = b.ReadUShort();
                            modelTypes[j]   = b.ReadByte();
                        }
                    }
                    else
                    {
                        b.Position(b.Position() + count * 3);
                    }
                }
            }
            else if (opcode == 2)
            {
                name = b.ReadString(10);
            }
            else if (opcode == 3)
            {
                desc = b.ReadString(10);
            }
            else if (opcode == 5)
            {
                int count = b.ReadUByte();
                if (count > 0)
                {
                    if (modelIndices == null)
                    {
                        modelTypes   = null;
                        modelIndices = new int[count];
                        for (int j = 0; j < count; j++)
                        {
                            modelIndices[j] = b.ReadUShort();
                        }
                    }
                    else
                    {
                        b.Position(b.Position() + count * 2);
                    }
                }
            }
            else if (opcode == 14)
            {
                sizeX = (byte)b.ReadUByte();
            }
            else if (opcode == 15)
            {
                sizeY = (byte)b.ReadUByte();
            }
            else if (opcode == 17)
            {
                hasCollisions = false;
            }
            else if (opcode == 18)
            {
                blocksProjectiles = false;
            }
            else if (opcode == 19)
            {
                if (b.ReadUByte() == 1)
                {
                    isStatic = true;
                }
            }
            else if (opcode == 21)
            {
                fitsToTerrain = true;
            }
            else if (opcode == 22)
            {
                flatShading = true;
            }
            else if (opcode == 23)
            {
                isSolid = true;
            }
            else if (opcode == 24)
            {
                seqIndex = b.ReadUShort();
            }
            else if (opcode == 28)
            {
                wallWidth = b.ReadByte();
            }
            else if (opcode == 29)
            {
                brightness = b.ReadByte();
            }
            else if (opcode == 39)
            {
                specular = b.ReadByte();
            }
            else if (opcode >= 30 && opcode < 39)
            {
                if (actions == null)
                {
                    actions = new string[5];
                }

                actions[opcode - 30] = b.ReadString(10);

                if (actions[opcode - 30].Equals("hidden", StringComparison.CurrentCultureIgnoreCase))
                {
                    actions[opcode - 30] = null;
                }
            }
            else if (opcode == 40)
            {
                int j = b.ReadUByte();
                oldColor = new int[j];
                newColor = new int[j];

                for (int k = 0; k < j; k++)
                {
                    oldColor[k] = b.ReadUShort();
                    newColor[k] = b.ReadUShort();
                }
            }
            else if (opcode == 60)
            {
                icon = b.ReadUShort();
            }
            else if (opcode == 62)
            {
                rotateCcw = true;
            }
            else if (opcode == 64)
            {
                castsShadow = false;
            }
            else if (opcode == 65)
            {
                scaleX = b.ReadUShort();
            }
            else if (opcode == 66)
            {
                scaleY = b.ReadUShort();
            }
            else if (opcode == 67)
            {
                scaleZ = b.ReadUShort();
            }
            else if (opcode == 68)
            {
                sceneImageIndex = b.ReadUShort();
            }
            else if (opcode == 69)
            {
                faceFlags = b.ReadUByte();
            }
            else if (opcode == 70)
            {
                offsetX = b.ReadUShort();
            }
            else if (opcode == 71)
            {
                offsetY = b.ReadUShort();
            }
            else if (opcode == 72)
            {
                offsetZ = b.ReadUShort();
            }
            else if (opcode == 73)
            {
                isDecoration = true;
            }
            else if (opcode == 74)
            {
                ghost = true;
            }
            else if (opcode == 75)
            {
                raisesItemPiles = b.ReadUByte();
            }
            else if (opcode == 77)
            {
                varBitId         = b.ReadUShort();
                sessionSettingId = b.ReadUShort();
                childrenIds      = new int[b.ReadUByte() + 1];

                for (int j = 0; j <= childrenIds.Length - 1; j++)
                {
                    childrenIds[j] = b.ReadUShort();
                }
            }
        }