Пример #1
0
        public void Handle(int opcode, JagexBuffer buf)
        {
            entityUpdateCount = 0;
            entityCount       = 0;
            UpdateActorMovement(buf);
            HandleNewActors(buf);
            UpdateActorMasks(buf);

            for (int i = 0; i < entityUpdateCount; i++)
            {
                int index = entityUpdateIndices[i];

                if (GameContext.Actors[index].UpdateCycle != GameContext.LoopCycle)
                {
                    GameContext.Actors[index].Destroy();
                    GameContext.Actors[index].Config = null;
                    GameContext.Actors[index]        = null;
                }
            }

            if (buf.Position() != buf.Capacity())
            {
                Debug.Log("ERROR ACTOR UPDATING 1");
            }

            for (int i = 0; i < GameContext.ActorCount; i++)
            {
                if (GameContext.Actors[GameContext.ActorIndices[i]] == null)
                {
                    Debug.Log("ERROR ACTOR UPDATING 2");
                }
            }
        }
 /// <summary>
 /// Parses the next packet in the provided binary data.
 /// </summary>
 /// <param name="opcode">The opcode of the packet.</param>
 /// <param name="b">The binary data to decode.</param>
 private void ParseOpcode(int opcode, JagexBuffer b)
 {
     if (opcode == 1)
     {
         Part = b.ReadUByte();
     }
     else if (opcode == 2)
     {
         ModelIndex = new short[b.ReadUByte()];
         for (int k = 0; k < this.ModelIndex.Length; k++)
         {
             ModelIndex[k] = (short)b.ReadUShort();
         }
     }
     else if (opcode == 3)
     {
         Unselectable = true;
     }
     else if (opcode >= 40 && opcode < 50)
     {
         OldColor[opcode - 40] = b.ReadUShort();
     }
     else if (opcode >= 50 && opcode < 60)
     {
         NewColor[opcode - 50] = b.ReadUShort();
     }
     else if (opcode >= 60 && opcode < 70)
     {
         DialogModelIndex[opcode - 60] = (short)b.ReadUShort();
     }
     else
     {
         Debug.Log("Error unrecognised config code: " + opcode);
     }
 }
Пример #3
0
        public void Handle(int opcode, JagexBuffer buf)
        {
            entityUpdateCount = 0;
            entityCount       = 0;

            UpdateLocalPlayerMovement(buf);
            UpdateRemotePlayerMovement(buf);
            UpdateNewPlayers(buf);
            UpdatePlayerMasks(buf);

            for (var i = 0; i < entityUpdateCount; i++)
            {
                var playerIndex = entityUpdateIndices[i];
                if (GameContext.Players[playerIndex].UpdateCycle != GameContext.LoopCycle)
                {
                    GameContext.Players[playerIndex].Destroy();
                    GameContext.Players[playerIndex] = null;
                }
            }

            if (buf.Position() != buf.Array().Length)
            {
                Debug.Log("PLAYER UPDATING ERROR 69");
            }

            for (var i = 0; i < GameContext.PlayerCount; i++)
            {
                if (GameContext.Players[GameContext.PlayerIndices[i]] == null)
                {
                    Debug.Log("PLAYER UPDATING ERROR 777");
                }
            }

            GameContext.ReceivedPlayerUpdate = true;
        }
Пример #4
0
        public CacheArchive(JagexBuffer buffer)
        {
            var decompressedSize = buffer.ReadTriByte();
            var compressedSize   = buffer.ReadTriByte();

            if (decompressedSize != compressedSize)
            {
                byte[] tmp = new byte[buffer.Capacity() - 6];
                buffer.ReadBytes(tmp, 0, buffer.Capacity() - 6);

                byte[] compressed = ReconstructHeader(new DefaultJagexBuffer(tmp));

                MemoryStream outs = new MemoryStream();
                BZip2.Decompress(new MemoryStream(compressed), outs, true);
                buffer           = new DefaultJagexBuffer(outs.ToArray());
                extractedAsWhole = true;
            }

            var size = buffer.ReadUShort();

            InitializeFiles(size);
            var position = buffer.Position() + (size * DescriptorSize);

            for (var i = 0; i < size; i++)
            {
                fileHashes[i]    = buffer.ReadInt();
                unpackedSizes[i] = buffer.ReadTriByte();
                packedSizes[i]   = buffer.ReadTriByte();
                positions[i]     = position;
                position        += packedSizes[i];
            }

            this.buffer = buffer;
        }
Пример #5
0
 private void LoadFromBuffer(JagexBuffer b)
 {
     opcodes = new int[b.ReadUShort()];
     for (var i = 0; i < opcodes.Length; i++)
     {
         opcodes[i] = b.ReadUShort();
     }
 }
Пример #6
0
        public static void Pack(string s, JagexBuffer buffer)
        {
            if (s.Length > 80)
            {
                s = s.Substring(0, 80);
            }

            s = s.ToLower();

            int a = -1;

            for (int i = 0; i < s.Length; i++)
            {
                int  b = 0;
                char c = s.ToCharArray()[i];
                for (int l = 0; l < ChatCharacters.Length; l++)
                {
                    if (c != ChatCharacters[l])
                    {
                        continue;
                    }
                    b = l;
                    break;
                }

                if (b > 12)
                {
                    b += 195;
                }

                if (a == -1)
                {
                    if (b < 13)
                    {
                        a = b;
                    }
                    else
                    {
                        buffer.WriteByte(b);
                    }
                }
                else if (b < 13)
                {
                    buffer.WriteByte((a << 4) + b);
                    a = -1;
                }
                else
                {
                    buffer.WriteByte((a << 4) + (b >> 4));
                    a = b & 0xF;
                }
            }

            if (a != -1)
            {
                buffer.WriteByte(a << 4);
            }
        }
Пример #7
0
        public void Handle(int opcode, JagexBuffer buffer)
        {
            var viewportWidget = buffer.ReadUShortA();
            var sidebarWidget  = buffer.ReadUShort();

            GameContext.Chat.OverlayWidget = null;
            GameContext.ViewportWidget     = new Widget(GameContext.Cache.GetWidgetConfig(viewportWidget));
            GameContext.TabArea.TabWidget  = new Widget(GameContext.Cache.GetWidgetConfig(sidebarWidget));
        }
Пример #8
0
        public void Handle(int opcode, JagexBuffer buffer)
        {
            var index = buffer.ReadLEUShort();
            var value = buffer.ReadByte();

            var settings = GameContext.Settings;

            settings[index] = value;
        }
Пример #9
0
        private void ParseFrom(JagexBuffer b)
        {
            int opcode = b.ReadUByte();

            while (opcode != 0)
            {
                ParseOpcode(opcode, b);
                opcode = b.ReadUByte();
            }
        }
Пример #10
0
        private void UpdateLocalPlayerMovement(JagexBuffer b)
        {
            b.BeginBitAccess();
            if (b.ReadBits(1) == 0)
            {
                return;
            }

            int moveType = b.ReadBits(2);

            if (moveType == 0)
            {
                entityIndices[entityCount++] = 2047;
                return;
            }

            if (moveType == 1)
            {
                int direction = b.ReadBits(3);
                GameContext.Self.QueueMove(direction, false);

                if (b.ReadBits(1) == 1)
                {
                    entityIndices[entityCount++] = 2047;
                }
                return;
            }

            if (moveType == 2)
            {
                GameContext.Self.QueueMove(b.ReadBits(3), true);
                GameContext.Self.QueueMove(b.ReadBits(3), true);

                if (b.ReadBits(1) == 1)
                {
                    entityIndices[entityCount++] = 2047;
                }
                return;
            }

            if (moveType == 3)
            {
                GameContext.Plane = b.ReadBits(2);
                int discardMoveQueue = b.ReadBits(1);

                if (b.ReadBits(1) == 1)
                {
                    entityIndices[entityCount++] = 2047;
                }

                int y = b.ReadBits(7);
                int x = b.ReadBits(7);
                GameContext.Self.TeleportTo(x, y, discardMoveQueue == 1);
            }
        }
Пример #11
0
        public void HandleNewActors(JagexBuffer b)
        {
            while (b.BitPosition() + 21 < b.Capacity() * 8)
            {
                int actorIndex = b.ReadBits(14);
                if (actorIndex == 16383)
                {
                    break;
                }

                if (GameContext.Actors[actorIndex] == null)
                {
                    GameContext.Actors[actorIndex] = new Actor();
                }

                Actor a = GameContext.Actors[actorIndex];
                GameContext.ActorIndices[GameContext.ActorCount++] = actorIndex;
                a.ServerIndex = actorIndex;
                a.UpdateCycle = (int)GameContext.LoopCycle;

                int y = b.ReadBits(5);
                if (y > 15)
                {
                    y -= 32;
                }

                int x = b.ReadBits(5);
                if (x > 15)
                {
                    x -= 32;
                }

                int discardWalkQueue = b.ReadBits(1);

                a.Config = GameContext.Cache.GetActorConfig(b.ReadBits(18));
                if (b.ReadBits(1) == 1)
                {
                    entityIndices[entityCount++] = actorIndex;
                }

                a.TileSize           = a.Config.HasOptions;
                a.RotateSpeed        = a.Config.TurnSpeed;
                a.WalkAnimation      = a.Config.MoveAnim;
                a.Turn180Animation   = a.Config.Turn180Anim;
                a.TurnRightAnimation = a.Config.TurnRightAnim;
                a.TurnLeftAnimation  = a.Config.TurnLeftAnim;
                a.StandAnimation     = a.Config.StandAnim;
                a.TeleportTo(GameContext.Self.PathX[0] + x, GameContext.Self.PathY[0] + y, discardWalkQueue == 1);
            }

            b.EndBitAccess();
        }
        public void Handle(int opcode, JagexBuffer buffer)
        {
            var index = buffer.ReadShortA();

            if (index == -1)
            {
                GameContext.Chat.UnderlayWidget = null;
            }
            else
            {
                var desc = GameContext.Cache.GetWidgetConfig(index);
                GameContext.Chat.UnderlayWidget = new Widget(desc);
            }
        }
Пример #13
0
        public void Handle(int opcode, JagexBuffer buffer)
        {
            var index    = buffer.ReadUByteC();
            var priority = buffer.ReadUByteA() == 0;
            var option   = buffer.ReadString(10);

            if (option.ToLower().Equals("null"))
            {
                GameContext.PlayerOptions[index - 1] = null;
            }
            else
            {
                GameContext.PlayerOptions[index - 1] = new PlayerOption(option, priority);
            }
        }
Пример #14
0
        public ItemConfigProvider(CacheArchive archive)
        {
            dataStream = new DefaultJagexBuffer(archive.GetFile("obj.dat"));
            var idxStream = new DefaultJagexBuffer(archive.GetFile("obj.idx"));

            pointer = new int[idxStream.ReadUShort()];

            var position = 2;

            for (var i = 0; i < pointer.Length; i++)
            {
                pointer[i] = position;
                position  += idxStream.ReadUShort();
            }
        }
Пример #15
0
        private void UpdateNewPlayers(JagexBuffer b)
        {
            while (b.BitPosition() + 10 < b.Capacity() * 8)
            {
                var playerIndex = b.ReadBits(11);
                if (playerIndex == 2047)
                {
                    break;
                }

                if (GameContext.Players[playerIndex] == null)
                {
                    GameContext.Players[playerIndex] = new Player();
                    JagexBuffer buf = GameContext.PlayerBuffers[playerIndex];
                    if (buf != null)
                    {
                        GameContext.Players[playerIndex].Update(buf);
                    }
                }

                GameContext.PlayerIndices[GameContext.PlayerCount++] = playerIndex;
                var p = GameContext.Players[playerIndex];
                p.ServerIndex = playerIndex;
                p.UpdateCycle = (int)GameContext.LoopCycle;

                if (b.ReadBits(1) == 1)
                {
                    entityIndices[entityCount++] = playerIndex;
                }

                var discardWalkQueue = b.ReadBits(1);
                var x = b.ReadBits(5);
                var y = b.ReadBits(5);

                if (x > 15)
                {
                    x -= 32;
                }

                if (y > 15)
                {
                    y -= 32;
                }

                p.TeleportTo(GameContext.Self.PathX[0] + y, GameContext.Self.PathY[0] + x, discardWalkQueue == 1);
            }
            b.EndBitAccess();
        }
Пример #16
0
        /// <summary>
        /// Performs player mask updates using data from the provided buffer.
        /// </summary>
        /// <param name="b">The buffer pointing to mask update data.</param>
        private void UpdatePlayerMasks(JagexBuffer b)
        {
            for (var i = 0; i < entityCount; i++)
            {
                var index = entityIndices[i];
                var p     = GameContext.Players[index];

                var mask = b.ReadUByte();
                if ((mask & 0x40) != 0)
                {
                    mask += b.ReadUByte() << 8;
                }

                UpdatePlayerMask(mask, index, b, p);
            }
        }
        public void Handle(int opcode, JagexBuffer buffer)
        {
            var index = buffer.ReadLEShort();

            GameContext.ViewportWidget    = null;
            GameContext.TabArea.TabWidget = null;

            if (index == -1)
            {
                GameContext.Chat.OverlayWidget = null;
            }
            else
            {
                var desc = GameContext.Cache.GetWidgetConfig(index);
                GameContext.Chat.OverlayWidget = new Widget(desc);
            }
        }
Пример #18
0
        private byte[] ReconstructHeader(JagexBuffer buffer)
        {
            var existing = buffer.Array();

            if (existing[0] == 'B' && existing[1] == 'Z' && existing[2] == 'h' && existing[3] == '1')
            {
                return(existing);
            }

            var compressed = new byte[buffer.Capacity() + 4];

            buffer.ReadBytes(compressed, 4, buffer.Capacity());
            compressed[0] = (byte)'B';
            compressed[1] = (byte)'Z';
            compressed[2] = (byte)'h';
            compressed[3] = (byte)'1';
            return(compressed);
        }
Пример #19
0
        public Animation(JagexBuffer b)
        {
            SetDefaults();
            ParseFrom(b);

            if (FrameCount == 0)
            {
                FrameCount               = 1;
                FrameIndicesPrimary      = new int[1];
                FrameIndicesPrimary[0]   = -1;
                FrameIndicesSecondary    = new int[1];
                FrameIndicesSecondary[0] = -1;
                FrameLengths             = new int[1];
                FrameLengths[0]          = -1;
            }

            if (SpeedFlag == -1)
            {
                if (Vertices != null)
                {
                    SpeedFlag = 2;
                }
                else
                {
                    SpeedFlag = 0;
                }
            }

            if (WalkFlag == -1)
            {
                if (Vertices != null)
                {
                    WalkFlag = 2;
                }
                else
                {
                    WalkFlag = 0;
                }
            }
        }
Пример #20
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);
     }
 }
Пример #21
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;
                }
            }
        }
Пример #22
0
 public ItemConfig(JagexBuffer b)
 {
     SetDefaults();
     ParseFrom(b);
 }
Пример #23
0
        private void UpdateRemotePlayerMovement(JagexBuffer b)
        {
            int playerCount = b.ReadBits(8);

            if (playerCount < GameContext.PlayerCount)
            {
                for (int k = playerCount; k < GameContext.PlayerCount; k++)
                {
                    entityUpdateIndices[entityUpdateCount++] = GameContext.PlayerIndices[k];
                }
            }

            if (playerCount > GameContext.PlayerCount)
            {
                Debug.Log("ERROR PLAYER UPDATING 0");
                return;
            }

            GameContext.PlayerCount = 0;

            for (int i = 0; i < playerCount; i++)
            {
                int    player_index = GameContext.PlayerIndices[i];
                Player p            = GameContext.Players[player_index];

                if (b.ReadBits(1) == 0)
                {
                    GameContext.PlayerIndices[GameContext.PlayerCount++] = player_index;
                    p.UpdateCycle = (int)GameContext.LoopCycle;
                }
                else
                {
                    int move_type = b.ReadBits(2);

                    switch (move_type)
                    {
                    case 0:
                    {
                        GameContext.PlayerIndices[GameContext.PlayerCount++] = player_index;
                        p.UpdateCycle = (int)GameContext.LoopCycle;
                        entityIndices[entityCount++] = player_index;
                        break;
                    }

                    case 1:
                    {
                        GameContext.PlayerIndices[GameContext.PlayerCount++] = player_index;
                        p.UpdateCycle = (int)GameContext.LoopCycle;
                        p.QueueMove(b.ReadBits(3), false);

                        if (b.ReadBits(1) == 1)
                        {
                            entityIndices[entityCount++] = player_index;
                        }
                        break;
                    }

                    case 2:
                    {
                        GameContext.PlayerIndices[GameContext.PlayerCount++] = player_index;
                        p.UpdateCycle = (int)GameContext.LoopCycle;
                        p.QueueMove(b.ReadBits(3), true);
                        p.QueueMove(b.ReadBits(3), true);

                        if (b.ReadBits(1) == 1)
                        {
                            entityIndices[entityCount++] = player_index;
                        }
                        break;
                    }

                    case 3:
                    {
                        entityUpdateIndices[entityUpdateCount++] = player_index;
                        break;
                    }
                    }
                }
            }
        }
Пример #24
0
        public void Handle(int opcode, JagexBuffer buf)
        {
            GameContext.Cache.ClearTempCaches();
            GameContext.DestroyProjectiles();

            GameContext.RegionX       = GameContext.LoadedRegionX;
            GameContext.RegionY       = GameContext.LoadedRegionY;
            GameContext.RegionX       = buf.ReadUShortA();
            GameContext.RegionY       = buf.ReadUShort();
            GameContext.LoadedRegionX = GameContext.RegionX;
            GameContext.LoadedRegionY = GameContext.RegionY;

            UnityEngine.Debug.Log("RX/Y: " + GameContext.RegionX + "/" + GameContext.RegionY);

            GameContext.MapBaseX       = (GameContext.LoadedRegionX - 6) * 8;
            GameContext.MapBaseY       = (GameContext.LoadedRegionY - 6) * 8;
            GameContext.RestrictRegion = false;

            if ((GameContext.LoadedRegionX / 8 == 48 || GameContext.LoadedRegionX / 8 == 49) && GameContext.LoadedRegionY / 8 == 48)
            {
                GameContext.RestrictRegion = true;
            }

            if (GameContext.LoadedRegionX / 8 == 48 && GameContext.LoadedRegionY / 8 == 148)
            {
                GameContext.RestrictRegion = true;
            }

            int count = 0;

            for (int chunkX = (GameContext.LoadedRegionX - 6) / 8; chunkX <= (GameContext.LoadedRegionX + 6) / 8; chunkX++)
            {
                for (int chunkY = (GameContext.LoadedRegionY - 6) / 8; chunkY <= (GameContext.LoadedRegionY + 6) / 8; chunkY++)
                {
                    count++;
                }
            }

            GameContext.ChunkLandscapePayload = new byte[count][];
            GameContext.ChunkObjectPayload    = new byte[count][];
            GameContext.ChunkCoords           = new int[count];
            GameContext.MapUids       = new int[count];
            GameContext.LandscapeUids = new int[count];
            count = 0;

            for (int chunkX = (GameContext.LoadedRegionX - 6) / 8; chunkX <= (GameContext.LoadedRegionX + 6) / 8; chunkX++)
            {
                for (int chunkY = (GameContext.LoadedRegionY - 6) / 8; chunkY <= (GameContext.LoadedRegionY + 6) / 8; chunkY++)
                {
                    GameContext.ChunkCoords[count] = (chunkX << 8) + chunkY;

                    if (GameContext.RestrictRegion && (chunkY == 49 || chunkY == 149 || chunkY == 147 || chunkX == 50 || chunkX == 49 && chunkY == 47))
                    {
                        GameContext.MapUids[count]       = -1;
                        GameContext.LandscapeUids[count] = -1;
                        count++;
                    }
                    else
                    {
                        GameContext.MapUids[count] = GameContext.Cache.GetMapId(chunkX, chunkY, 0);
                        if (GameContext.MapUids[count] != -1)
                        {
                            GameContext.ChunkLandscapePayload[count] = GameContext.Cache.ReadCompressed(4, GameContext.MapUids[count]);
                        }

                        GameContext.LandscapeUids[count] = GameContext.Cache.GetMapId(chunkX, chunkY, 1);
                        if (GameContext.LandscapeUids[count] != -1)
                        {
                            GameContext.ChunkObjectPayload[count] = GameContext.Cache.ReadCompressed(4, GameContext.LandscapeUids[count]);
                        }

                        //UnityEngine.Debug.Log(GameContext.MapUids[count] + " " + GameContext.LandscapeUids[count]);
                        count++;
                    }
                }
            }

            int baseDeltaX = GameContext.MapBaseX - GameContext.LastMapBaseX;
            int baseDeltaY = GameContext.MapBaseY - GameContext.LastMapBaseY;

            GameContext.LastMapBaseX = GameContext.MapBaseX;
            GameContext.LastMapBaseY = GameContext.MapBaseY;

            for (int i = 0; i < 2048; i++)
            {
                Player p = GameContext.Players[i];
                if (p != null)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        p.PathX[j] -= baseDeltaX;
                        p.PathY[j] -= baseDeltaY;
                    }
                    p.SetSceneX(p.JSceneX - (baseDeltaX * 128));
                    p.SetSceneY(p.JSceneY - (baseDeltaY * 128));
                }
            }

            sbyte x1 = 0;
            sbyte x2 = 104;
            sbyte dx = 1;

            if (baseDeltaX < 0)
            {
                x1 = 103;
                x2 = -1;
                dx = -1;
            }

            sbyte y1 = 0;
            sbyte y2 = 104;
            sbyte dy = 1;

            if (baseDeltaY < 0)
            {
                y1 = 103;
                y2 = -1;
                dy = -1;
            }

            if (GameContext.GroundItems != null)
            {
                for (int x = x1; x != x2; x += dx)
                {
                    for (int y = y1; y != y2; y += dy)
                    {
                        int oldX = x + baseDeltaX;
                        int oldY = y + baseDeltaY;
                        for (int plane = 0; plane < 4; plane++)
                        {
                            if (oldX >= 0 && oldY >= 0 && oldX < 104 && oldY < 104)
                            {
                                GameContext.GroundItems[plane, x, y] = GameContext.GroundItems[plane, oldX, oldY];
                            }
                            else
                            {
                                GameContext.GroundItems[plane, x, y] = null;
                            }
                        }
                    }
                }
            }

            if (GameContext.MapMarkerX != 0)
            {
                GameContext.MapMarkerX -= baseDeltaX;
                GameContext.MapMarkerY -= baseDeltaY;
            }

            UnityEngine.Debug.Log("Flagging for load");
            GameContext.WaitingForScene      = true;
            GameContext.ReceivedPlayerUpdate = false;
        }
Пример #25
0
 /// <summary>
 /// Creates a player appearance config from binary data.
 /// </summary>
 /// <param name="b">The buffer containing the binary data.</param>
 public PlayerAppearanceConfig(JagexBuffer b)
 {
     SetDefaults();
     ParseFrom(b);
 }
Пример #26
0
 public void Handle(int opcode, JagexBuffer buffer)
 {
     GameContext.NetworkHandler.ResetState();
 }
Пример #27
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();
        }
Пример #28
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();
            }
        }
Пример #29
0
 public void Handle(int opcode, JagexBuffer buffer)
 {
     GameContext.FriendsStorageType = (SocialStorageCap)buffer.ReadUByteA();
     GameContext.LocalPlayerIndex   = buffer.ReadLEUShortA();
 }
Пример #30
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;
            }
        }