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; }
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(); } }
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 UpdateActorMasks(JagexBuffer b) { for (int i = 0; i < entityCount; i++) { Actor a = GameContext.Actors[entityIndices[i]]; int mask = b.ReadUByte(); if ((mask & 0x10) != 0) { int SeqIndex = b.ReadLEUShort(); if (SeqIndex == 65535) { SeqIndex = -1; } int delay = b.ReadUByte(); if (SeqIndex == a.SeqIndex && SeqIndex != -1) { int type = GameContext.Cache.GetSeq(SeqIndex).Type; if (type == 1) { a.SeqFrame = 0; a.SeqCycle = 0; a.SeqDelayCycle = delay; a.SeqResetCycle = 0; } if (type == 2) { a.SeqResetCycle = 0; } } else if (SeqIndex == -1 || a.SeqIndex == -1 || GameContext.Cache.GetSeq(SeqIndex).Priority >= GameContext.Cache.GetSeq(a.SeqIndex).Priority) { a.SeqIndex = SeqIndex; a.SeqFrame = 0; a.SeqCycle = 0; a.SeqDelayCycle = delay; a.SeqResetCycle = 0; a.StillPathPosition = a.PathPosition; } } if ((mask & 8) != 0) { var damage = b.ReadUShortA(); var type = b.ReadUByteC(); var icon = b.ReadUByte(); a.QueueHit(type, damage, (int)GameContext.LoopCycle); a.EndCombatCycle = (int)GameContext.LoopCycle + 300; a.CurrentHealth = b.ReadUShortA(); a.MaxHealth = b.ReadUShortA(); } if ((mask & 0x80) != 0) { a.SpotAnimIndex = b.ReadUShort(); int info = b.ReadInt(); a.GraphicOffsetY = info >> 16; a.SpotAnimCycleEnd = (int)GameContext.LoopCycle + (info & 0xFFFF); a.SpotAnimFrame = 0; a.SpotAnimCycle = 0; if (a.SpotAnimCycleEnd > GameContext.LoopCycle) { a.SpotAnimFrame = -1; } if (a.SpotAnimIndex == 65535) { a.SpotAnimIndex = -1; } } if ((mask & 0x20) != 0) { a.FaceEntity = b.ReadUShort(); if (a.FaceEntity == 65535) { a.FaceEntity = -1; } } if ((mask & 1) != 0) { a.SpokenMessage = b.ReadString(10); a.SpokenLife = 100; } if ((mask & 0x40) != 0) { var damage = b.ReadUShortA(); var type = b.ReadUByteS(); var icon = b.ReadUByte(); a.QueueHit(type, damage, (int)GameContext.LoopCycle); a.EndCombatCycle = (int)GameContext.LoopCycle + 300; a.CurrentHealth = b.ReadUShortA(); a.MaxHealth = b.ReadUShortA(); } if ((mask & 2) != 0) { a.Config = GameContext.Cache.GetActorConfig(b.ReadLEUShortA()); 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; } if ((mask & 4) != 0) { a.FaceX = b.ReadLEUShort(); a.FaceY = b.ReadLEUShort(); } } }