public void ResetState() { lastSize = -1; InBuffer.Position(0); wrapperBuffer.Position(0); Connected = false; if (client != null) { client.Close(); client = null; OnDisconnect(); } decryptCipher = null; }
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; }
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"); } } }
public ItemConfig Provide(int index) { foreach (var cached in tmpCache) { if (cached.index == index) { return(cached); } } if (index < 0 || index >= pointer.Length) { throw new Exception("Item with index " + index + " does not exist!"); } dataStream.Position(pointer[index]); var config = new ItemConfig(dataStream); config.index = index; tmpCache.Add(config); RemoveExcess(); return(config); }
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; } }
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(); }
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(); } } }