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; }
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"); } } }
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); }
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(); }
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(); }