congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
GamePacketReader
Code IndexAdd Tabnine to your IDE (free)

How to use
GamePacketReader
in
org.apollo.net.codec.game

Best Java code snippets using org.apollo.net.codec.game.GamePacketReader (Showing top 20 results out of 315)

origin: apollo-rsps/apollo

/**
 * Gets bytes with the specified transformation.
 *
 * @param transformation The transformation.
 * @param bytes The target byte array.
 * @throws IllegalStateException If this reader is not in byte access mode.
 */
public void getBytes(DataTransformation transformation, byte[] bytes) {
  if (transformation == DataTransformation.NONE) {
    getBytesReverse(bytes);
  } else {
    for (int i = 0; i < bytes.length; i++) {
      bytes[i] = (byte) getSigned(DataType.BYTE, transformation);
    }
  }
}
origin: apollo-rsps/apollo

@Override
public ItemOnItemMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int targetId = (int) reader.getUnsigned(DataType.SHORT);
  int usedSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
  int usedId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
  int targetInterface = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
  int targetSlot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
  int usedInterface = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
  return new ItemOnItemMessage(usedInterface, usedId, usedSlot, targetInterface, targetId, targetSlot);
}
origin: apollo-rsps/apollo

/**
 * Gets bytes.
 *
 * @param bytes The target byte array.
 * @throws IllegalStateException If this reader is not in byte access mode.
 */
public void getBytes(byte[] bytes) {
  checkByteAccess();
  for (int i = 0; i < bytes.length; i++) {
    bytes[i] = buffer.readByte();
  }
}
origin: apollo-rsps/apollo

@Override
public ItemOnItemMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int targetSlot = (int) reader.getUnsigned(DataType.SHORT);
  int usedSlot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
  int targetId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
  int targetInterface = (int) reader.getUnsigned(DataType.SHORT);
  int usedId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE);
  int usedInterface = (int) reader.getUnsigned(DataType.SHORT);
  return new ItemOnItemMessage(usedInterface, usedId, usedSlot, targetInterface, targetId, targetSlot);
}
origin: apollo-rsps/apollo

@Override
public NpcActionMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE);
  return new NpcActionMessage(1, index);
}
origin: apollo-rsps/apollo

@Override
public PublicChatMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT);
  int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT);
  int length = packet.getLength() - 2;
  byte[] originalCompressed = new byte[length];
  reader.getBytesReverse(DataTransformation.ADD, originalCompressed);
  String uncompressed = TextUtil.decompress(originalCompressed, length);
  uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
  uncompressed = TextUtil.capitalize(uncompressed);
  byte[] recompressed = new byte[length];
  TextUtil.compress(uncompressed, recompressed);
  // in case invalid data gets sent, this effectively verifies it
  return new PublicChatMessage(uncompressed, recompressed, color, effects);
}
origin: apollo-rsps/apollo

@Override
public PrivateChatMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG));
  int length = packet.getLength() - Long.BYTES;
  byte[] originalCompressed = new byte[length];
  reader.getBytes(originalCompressed);
  String decompressed = TextUtil.decompress(originalCompressed, length);
  decompressed = TextUtil.filterInvalidCharacters(decompressed);
  decompressed = TextUtil.capitalize(decompressed);
  byte[] recompressed = new byte[length];
  TextUtil.compress(decompressed, recompressed);
  return new PrivateChatMessage(new String(decompressed), recompressed, username);
}
origin: apollo-rsps/apollo

@Override
public FlaggedMouseEventMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int read, clicks, x, y;
  if (reader.getLength() == 2) {
    read = (int) reader.getUnsigned(DataType.SHORT);
    clicks = read >> 12;
    x = read >> 6 & 0x3f;
    y = read & 0x3f;
    return new FlaggedMouseEventMessage(clicks, x, y, true);
  } else if (reader.getLength() == 3) {
    read = (int) reader.getUnsigned(DataType.TRI_BYTE) & ~0x800000;
  } else {
    read = (int) reader.getUnsigned(DataType.INT) & ~0xc0000000;
  }
  clicks = read >> 19;
  x = (read & 0x7f) % 765;
  y = (read & 0x7f) / 765;
  return new FlaggedMouseEventMessage(clicks, x, y, false);
}
origin: apollo-rsps/apollo

@Override
public PublicChatMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE);
  int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD);
  int length = packet.getLength() - 2;
  byte[] originalCompressed = new byte[length];
  reader.getBytes(originalCompressed);
  String uncompressed = TextUtil.decompress(originalCompressed, length);
  uncompressed = TextUtil.filterInvalidCharacters(uncompressed);
  uncompressed = TextUtil.capitalize(uncompressed);
  byte[] recompressed = new byte[length];
  TextUtil.compress(uncompressed, recompressed); // in case invalid data gets sent, this effectively verifies it
  return new PublicChatMessage(uncompressed, recompressed, color, effects);
}
origin: apollo-rsps/apollo

/**
 * Gets a signed data type from the buffer with the specified order.
 *
 * @param type The data type.
 * @param order The byte order.
 * @return The value.
 * @throws IllegalStateException If this reader is not in byte access mode.
 * @throws IllegalArgumentException If the combination is invalid.
 */
public long getSigned(DataType type, DataOrder order) {
  return getSigned(type, order, DataTransformation.NONE);
}
origin: apollo-rsps/apollo

@Override
public CommandMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  return new CommandMessage(reader.getString());
}
origin: apollo-rsps/apollo

/**
 * Gets an unsigned data type from the buffer with the specified order and transformation.
 *
 * @param type The data type.
 * @param order The byte order.
 * @param transformation The data transformation.
 * @return The value.
 * @throws IllegalStateException If this reader is not in byte access mode.
 * @throws IllegalArgumentException If the combination is invalid.
 */
public long getUnsigned(DataType type, DataOrder order, DataTransformation transformation) {
  long longValue = get(type, order, transformation);
  Preconditions.checkArgument(type != DataType.LONG, "Longs must be read as a signed type.");
  return longValue & 0xFFFFFFFFFFFFFFFFL;
}
origin: apollo-rsps/apollo

/**
 * Gets a bit from the buffer.
 *
 * @return The value.
 * @throws IllegalStateException If the reader is not in bit access mode.
 */
public int getBit() {
  return getBits(1);
}
origin: apollo-rsps/apollo

/**
 * Gets the specified amount of bits from the buffer.
 *
 * @param amount The amount of bits.
 * @return The value.
 * @throws IllegalStateException If the reader is not in bit access mode.
 * @throws IllegalArgumentException If the number of bits is not between 1 and 31 inclusive.
 */
public int getBits(int amount) {
  Preconditions.checkArgument(amount >= 0 && amount <= 32, "Number of bits must be between 1 and 32 inclusive.");
  checkBitAccess();
  int bytePos = bitIndex >> 3;
  int bitOffset = 8 - (bitIndex & 7);
  int value = 0;
  bitIndex += amount;
  for (; amount > bitOffset; bitOffset = 8) {
    value += (buffer.getByte(bytePos++) & DataConstants.BIT_MASK[bitOffset]) << amount - bitOffset;
    amount -= bitOffset;
  }
  if (amount == bitOffset) {
    value += buffer.getByte(bytePos) & DataConstants.BIT_MASK[bitOffset];
  } else {
    value += buffer.getByte(bytePos) >> bitOffset - amount & DataConstants.BIT_MASK[amount];
  }
  return value;
}
origin: apollo-rsps/apollo

@Override
public ItemOnNpcMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int index = (int) reader.getUnsigned(DataType.SHORT);
  int id = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE);
  int widget = (int) reader.getUnsigned(DataType.SHORT,  DataOrder.LITTLE, DataTransformation.ADD);
  int slot = (int) reader.getUnsigned(DataType.SHORT);
  return new ItemOnNpcMessage(id, index, slot, widget);
}
origin: apollo-rsps/apollo

@Override
public NpcActionMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
  return new NpcActionMessage(3, index);
}
origin: apollo-rsps/apollo

@Override
public PrivateChatMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG));
  int length = packet.getLength() - Long.BYTES;
  byte[] originalCompressed = new byte[length];
  reader.getBytes(originalCompressed);
  String decompressed = TextUtil.decompress(originalCompressed, length);
  decompressed = TextUtil.filterInvalidCharacters(decompressed);
  decompressed = TextUtil.capitalize(decompressed);
  byte[] recompressed = new byte[length];
  TextUtil.compress(decompressed, recompressed);
  return new PrivateChatMessage(decompressed, recompressed, username);
}
origin: apollo-rsps/apollo

@Override
public FlaggedMouseEventMessage decode(GamePacket packet) {
  GamePacketReader reader = new GamePacketReader(packet);
  int read;
  if (reader.getLength() == 2) {
    read = (int) reader.getUnsigned(DataType.SHORT);
    int clicks = read >> 12;
    int dX = read >> 6 & 0x3f;
    int dY = read & 0x3f;
    return new FlaggedMouseEventMessage(clicks, dX, dY, true);
  } else if (reader.getLength() == 3) {
    read = (int) reader.getUnsigned(DataType.TRI_BYTE) & ~0x800000;
  } else {
    read = (int) reader.getUnsigned(DataType.INT) & ~0xc0000000;
  }
  int clicks = read >> 19;
  int x = (read & 0x7f) % 765;
  int y = (read & 0x7f) / 765;
  return new FlaggedMouseEventMessage(clicks, x, y, false);
}
origin: apollo-rsps/apollo

/**
 * Gets a signed data type from the buffer.
 *
 * @param type The data type.
 * @return The value.
 * @throws IllegalStateException If this reader is not in byte access mode.
 */
public long getSigned(DataType type) {
  return getSigned(type, DataOrder.BIG, DataTransformation.NONE);
}
origin: apollo-rsps/apollo

/**
 * Gets a signed data type from the buffer with the specified order and transformation.
 *
 * @param type The data type.
 * @param order The byte order.
 * @param transformation The data transformation.
 * @return The value.
 * @throws IllegalStateException If this reader is not in byte access mode.
 * @throws IllegalArgumentException If the combination is invalid.
 */
public long getSigned(DataType type, DataOrder order, DataTransformation transformation) {
  long longValue = get(type, order, transformation);
  if (type != DataType.LONG) {
    int max = (int) (Math.pow(2, type.getBytes() * 8 - 1) - 1);
    if (longValue > max) {
      longValue -= (max + 1) * 2;
    }
  }
  return longValue;
}
org.apollo.net.codec.gameGamePacketReader

Javadoc

A utility class for reading GamePackets.

Most used methods

  • getBytesReverse
    Gets bytes in reverse.
  • getSigned
    Gets a signed data type from the buffer with the specified transformation.
  • getUnsigned
    Gets an unsigned data type from the buffer with the specified transformation.
  • <init>
    Creates the reader.
  • checkBitAccess
    Checks that this reader is in the bit access mode.
  • checkByteAccess
    Checks that this reader is in the byte access mode.
  • get
    Reads a standard data type from the buffer with the specified order and transformation.
  • getBits
    Gets the specified amount of bits from the buffer.
  • getBytes
    Gets bytes.
  • getLength
    Gets the length of this reader.
  • getString
    Gets a string from the buffer.
  • getString

Popular in Java

  • Start an intent from android
  • onCreateOptionsMenu (Activity)
  • getContentResolver (Context)
  • setScale (BigDecimal)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • PrintWriter (java.io)
    Wraps either an existing OutputStream or an existing Writerand provides convenience methods for prin
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • BoxLayout (javax.swing)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now