Package net.bnubot.core

Examples of net.bnubot.core.BNetInputStream


        p.SendPacket(dos, true);
       
      while(!s.isClosed() && connected) {
        if(dis.available() > 0) {
          MCPPacketReader pr = new MCPPacketReader(dis, true);
          BNetInputStream is = pr.getData();
          switch(pr.packetId) {
          case MCPCommandIDs.MCP_STARTUP: {
            /* (DWORD)     Result
             *
             * 0x00: Success
             * 0x0C: No Battle.net connection detected
             * 0x7F: Temporary IP ban "Your connection has been
             *  temporarily restricted from this realm. Please
             *  try to log in at another time"
             */
            int result = is.readDWord();
            switch(result) {
            case 0:
              recieveRealmInfo("Realm logon success");
             
              p = new MCPPacket(MCPCommandIDs.MCP_CHARLIST2);
              p.writeDWord(8)//Nubmer of chars to list
              p.SendPacket(dos, true);
              break;
            case 0x0C:
              recieveRealmError("Realm server did not detect a Battle.net connection");
              setConnected(false);
              break;
            case 0x7F:
              recieveRealmError("You are temporarily banned from the realm");
              setConnected(false);
              break;
            }
            break;
          }
          case MCPCommandIDs.MCP_CHARLIST2: {
            recieveRealmError(HexDump.hexDump(pr.data));
            /* (WORD)     Number of characters requested
             * (DWORD)     Number of characters that exist on this account
             * (WORD)     Number of characters returned
             *
             * For each character:
             * (DWORD)     Seconds since January 1 00:00:00 UTC 1970
             * (STRING)    Name
             * (WORD)     Flags
             * (STRING)    Character statstring
             */
            is.readWord();
            is.readDWord();
            int numChars = is.readWord();
           
            long minTime = 0;
            String maxCharname = null;
           
            for(int i = 0; i < numChars; i++) {
              int secs = is.readDWord();
              String charname = is.readNTString();
              StatString statstr = new StatString("PX2D[Realm]," + charname + "," + is.readNTString());
             
              long time = new Date().getTime();
              time = (((long)secs) * 1000) - time;
             
              recieveRealmInfo(TimeFormatter.formatTime(time) + " - " + charname + " - " + statstr.toString());
View Full Code Here


  int packetId;
  int packetLength;
  byte data[];
 
  public MCPPacketReader(InputStream rawis, boolean packetLog) throws IOException {
    BNetInputStream is = new BNetInputStream(rawis);
   
    packetLength = is.readWord() & 0x0000FFFF;
    packetId = is.readByte() & 0x000000FF;
    assert(packetLength >= 3);
   
    data = new byte[packetLength-3];
    for(int i = 0; i < packetLength-3; i++) {
      data[i] = is.readByte();
    }
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BNetOutputStream os = new BNetOutputStream(baos);
    os.writeByte(packetId);
View Full Code Here

    if(packetLog)
      Out.info("MCPPacketReader", "RECV MCP\n" + HexDump.hexDump(baos.toByteArray()));
  }
 
  public BNetInputStream getData() {
    return new BNetInputStream(new ByteArrayInputStream(data));
  }
View Full Code Here

  private static BNetIcon[] readIconsDotBni(File f) {
    try {
      //Out.info(this.getClass().getName(), "Reading " + f.getName());
     
      BNetInputStream is = new BNetInputStream(new FileInputStream(f));
      is.skip(4); //int headerSize = is.readDWord();
      int bniVersion = is.readWord();
      is.skip(2)// Alignment Padding (unused)
      int numIcons = is.readDWord();
      is.skip(4)//int dataOffset = is.readDWord();
     
      if(bniVersion != 1)
        throw new Exception("Unknown BNI version");
     
      //Out.info(this.getClass().getName(), "Reading " + numIcons + " icons in format " + bniVersion + " from offset " + dataOffset);

      //Image headers
      /*if(icons == null)
        icons = new BNetIcon[numIcons];
      else {
        BNetIcon[] newIcons = new BNetIcon[numIcons + icons.length];
        for(int i = numIcons; i < numIcons + icons.length; i++) {
          newIcons[i] = icons[i-numIcons];
        }
        icons = newIcons;
      }*/
      BNetIcon[] icons = new BNetIcon[numIcons];
     
      for(int i = 0; i < numIcons; i++) {
        BNetIcon icon = new BNetIcon();
        icon.flags = is.readDWord();
        icon.xSize = is.readDWord();
        icon.ySize = is.readDWord();
        if(icon.flags != 0)
          icon.sortIndex = i;
        else
          icon.sortIndex = numIcons;
        int numProducts;
        int products[] = new int[32];
       
        //Read in up to 32 products; stop if we see a null
        for(numProducts = 0; numProducts < 32; numProducts++) {
          products[numProducts] = is.readDWord();
          if(products[numProducts] == 0)
            break;
        }
       
        if(numProducts > 0) {
          icon.products = new int[numProducts];
          for(int j = 0; j < numProducts; j++)
            icon.products[j] = products[j];
        } else
          icon.products = null;
        icons[i] = icon;
        //Out.info(this.getClass().getName(), icon.toString());
      }
     
      //Image in targa format
      byte infoLength = is.readByte();
      is.skip(1);              // ColorMapType
      byte imageType = is.readByte();    // run-length true-color image types = 0x0A
      is.skip(5);              // ColorMapSpecification - color map data
      is.skip(2)//int xOrigin = is.readWord();
      is.skip(2)//int yOrigin = is.readWord();
      int width = is.readWord();
      int height = is.readWord();
      byte depth = is.readByte();      // 24 bit depth is good
      /*byte descriptor =*/ is.readByte()// bits 5 and 4 (00110000) specify the corner to start coloring pixels - 00=bl, 01=br, 10=tl, 11=tr
      is.skip(infoLength)//String info = is.readFixedLengthString(infoLength);
     
      if(imageType != 0x0A)
        throw new Exception("Unknown image type");
      if(depth != 24)
        throw new Exception("Unknown depth");
     
      //Pixel data
      int[] pixelData = new int[width*height];
      int currentPixel = 0;
     
      while(currentPixel < pixelData.length) {
        byte packetHeader = is.readByte()// if bit 7 (0x80) is set, run-length packet;
        int len = (packetHeader & 0x7F) + 1;
        if((packetHeader & 0x80) != 0) {
          //Run-length packet
          int blue = is.readByte() & 0xFF;
          int green = is.readByte() & 0xFF;
          int red = is.readByte() & 0xFF;
          int col = new Color(red, green, blue).getRGB();
          for(int i = 0; i < len; i++)
            pixelData[getRealPixelPosition(currentPixel++, height, width)] = col;
        } else {
          for(int i = 0; i < len; i++) {
            int blue = is.readByte() & 0xFF;
            int green = is.readByte() & 0xFF;
            int red = is.readByte() & 0xFF;
            int col = new Color(red, green, blue).getRGB();
            pixelData[getRealPixelPosition(currentPixel++, height, width)] = col;
          }
        }
      }
View Full Code Here

  int packetId;
  int packetLength;
  byte data[];
 
  public BNCSPacketReader(InputStream rawis, boolean packetLog) throws IOException {
    BNetInputStream is = new BNetInputStream(rawis);
   
    byte magic;
    do {
      magic = is.readByte();
    } while(magic != (byte)0xFF);
   
    packetId = is.readByte() & 0x000000FF;
    packetLength = is.readWord() & 0x0000FFFF;
    assert(packetLength >= 4);
   
    data = new byte[packetLength-4];
    for(int i = 0; i < packetLength-4; i++) {
      data[i] = is.readByte();
    }
   
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BNetOutputStream os = new BNetOutputStream(baos);
    os.writeByte(0xFF);
View Full Code Here

    if(packetLog)
      Out.info(this.getClass().getName(), "RECV\n" + HexDump.hexDump(baos.toByteArray()));
  }
 
  public BNetInputStream getData() {
    return new BNetInputStream(new ByteArrayInputStream(data));
  }
View Full Code Here

        }
      }
     
      if(dis.available() > 0) {
        BNCSPacketReader pr = new BNCSPacketReader(dis, cs.packetLog);
        BNetInputStream is = pr.getData();
       
        switch(pr.packetId) {
        case BNCSCommandIDs.SID_EXTRAWORK:
        case BNCSCommandIDs.SID_REQUIREDWORK:
          break;
         
        case BNCSCommandIDs.SID_NULL: {
          lastNullPacket = timeNow;
          BNCSPacket p = new BNCSPacket(BNCSCommandIDs.SID_NULL);
          p.SendPacket(dos, cs.packetLog);
          break;
        }
       
        case BNCSCommandIDs.SID_PING: {
          BNCSPacket p = new BNCSPacket(BNCSCommandIDs.SID_PING);
          p.writeDWord(is.readDWord());
          p.SendPacket(dos, cs.packetLog);
          break;
        }
       
        case BNCSCommandIDs.SID_AUTH_INFO:
        case BNCSCommandIDs.SID_STARTVERSIONING: {
          if(pr.packetId == BNCSCommandIDs.SID_AUTH_INFO) {
            nlsRevision = is.readDWord();
            serverToken = is.readDWord();
            is.skip(4)//int udpValue = is.readDWord();
          }
          long MPQFileTime = is.readQWord();
          String MPQFileName = is.readNTString();
          String ValueStr = is.readNTString();
         
          recieveInfo("MPQ: " + MPQFileName);
       
          byte extraData[] = null;
          if(is.available() == 0x80) {
            extraData = new byte[0x80];
            is.read(extraData, 0, 0x80);
          }
          assert(is.available() == 0);
         
          // Hash the CD key
          byte keyHash[] = null;
          byte keyHash2[] = null;
          if(nlsRevision != -1) {
            keyHash = HashMain.hashKey(clientToken, serverToken, cs.cdkey).getBuffer();
            if(cs.product == ConnectionSettings.PRODUCT_LORDOFDESTRUCTION)
              keyHash2 = HashMain.hashKey(clientToken, serverToken, cs.cdkeyLOD).getBuffer();
            if(cs.product == ConnectionSettings.PRODUCT_THEFROZENTHRONE)
              keyHash2 = HashMain.hashKey(clientToken, serverToken, cs.cdkeyTFT).getBuffer();
          }
         
          // Hash the game files
            String files[] = HashMain.getFiles(cs.product, HashMain.PLATFORM_INTEL);

          int exeHash;
                  int exeVersion;
                  String exeInfo;
                 
                  try {
                    String tmp = MPQFileName;
                    tmp = tmp.substring(tmp.indexOf("IX86")+4);
                    while((tmp.charAt(0) < 0x30) || (tmp.charAt(0) > 0x39))
                      tmp = tmp.substring(1);
              tmp = tmp.substring(0,tmp.indexOf("."));
                      int mpqNum = Integer.parseInt(tmp);
                     
                      exeHash = CheckRevision.checkRevision(ValueStr, files, mpqNum);
              exeVersion = HashMain.getExeVer(cs.product);
            exeInfo = HashMain.getExeInfo(cs.product);
                  } catch(Exception e) {
                    recieveError("Local hashing failed. Trying BNLS server.");
                   
                    BNLSProtocol.OutPacketBuffer exeHashBuf;
                    if((cs.bnlsServer == null)
                    || (cs.bnlsServer.length() == 0)) {
                      exeHashBuf = CheckRevisionBNLS.checkRevision(ValueStr, cs.product, MPQFileName, MPQFileTime);
                    } else {
                      exeHashBuf = CheckRevisionBNLS.checkRevision(ValueStr, cs.product, MPQFileName, MPQFileTime, cs.bnlsServer);
                    }
              BNetInputStream exeStream = new BNetInputStream(new java.io.ByteArrayInputStream(exeHashBuf.getBuffer()));
              exeStream.skipBytes(3);
              int success = exeStream.readDWord();
              if(success != 1) {
                Out.error(this.getClass().getName(), HexDump.hexDump(exeHashBuf.getBuffer()));
                throw new Exception("BNLS failed to complete 0x1A sucessfully");
              }
              exeVersion = exeStream.readDWord();
              exeHash = exeStream.readDWord();
              exeInfo = exeStream.readNTString();
              exeStream.readDWord(); // cookie
              /*int exeVerbyte =*/ exeStream.readDWord();
              assert(exeStream.available() == 0);
                  }
                 
                  if((exeVersion == 0) || (exeHash == 0) || (exeInfo == null) || (exeInfo.length() == 0)) {
                    recieveError("Checkrevision failed!");
                    setConnected(false);
View Full Code Here

TOP

Related Classes of net.bnubot.core.BNetInputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.