Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: Chriso on September 19, 2007, 08:34 AM

Title: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Chriso on September 19, 2007, 08:34 AM
I keep receiving a run-time error "Input string was not in a correct format." for this line of code:

            int MpqNum = CheckRevision.ExtractMPQNumber(MpqName);

Any ideas why I am getting this error?
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: rabbit on September 19, 2007, 12:15 PM
Maybe if you posted some input strings...
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Chriso on September 19, 2007, 12:21 PM
      MpqName   "lockdown-IX86-18.mpq"   string
      MpqNum   0   int

Those are the inputs...
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: MyndFyre on September 20, 2007, 04:36 AM
As MBNCSUtil doesn't yet support lockdown, it also doesn't support extracting lockdown MPQ numbers.
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Camel on September 20, 2007, 03:20 PM
If you need it, your best bet would be to completely circumvent that library and use BNLS_VERSIONCHECKEX2.
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Barabajagal on September 20, 2007, 03:46 PM
Or one of the few Lockdown DLLs.
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Camel on September 20, 2007, 11:34 PM
Or, this Java library:

   try {
                      InetAddress address = MirrorSelector.getClosestMirror(cs.bnlsServer, cs.bnlsPort);
                      Socket conn = new Socket(address, cs.bnlsPort);

                      recieveInfo("Connected to " + address + ":" + cs.bnlsPort);

                      BNLSPacket bnlsOut = new BNLSPacket(BNLSCommandIDs.BNLS_VERSIONCHECKEX2);
                      bnlsOut.writeDWord(cs.product);
                      bnlsOut.writeDWord(0);   // Flags
                      bnlsOut.writeDWord(0);   // Cookie
                      bnlsOut.writeQWord(MPQFileTime);
                      bnlsOut.writeNTString(MPQFileName);
                      bnlsOut.writeNTString(ValueStr);
                      bnlsOut.SendPacket(conn.getOutputStream(), cs.packetLog);

                      InputStream bnlsInputStream = conn.getInputStream();
                      long startTime = System.currentTimeMillis();
                      while(bnlsInputStream.available() < 3) {
                         Thread.sleep(10);
                         Thread.yield();

                         long timeElapsed = System.currentTimeMillis() - startTime;
                         if(timeElapsed > 5000)
                            throw new Exception("BNLS_VERSIONCHECKEX2 timeout");
                      }

                      BNLSPacketReader bpr = new BNLSPacketReader(bnlsInputStream, cs.packetLog);
                      BNetInputStream bnlsIn = bpr.getInputStream();
                      int success = bnlsIn.readDWord();
                      if(success != 1) {
                         Out.error(getClass(), "BNLS_VERSIONCHECKEX2 Failed\n" + HexDump.hexDump(bpr.getData()));
                         throw new Exception("BNLS failed to complete BNLS_VERSIONCHECKEX2 sucessfully");
                      }
                      exeVersion = bnlsIn.readDWord();
                      exeHash = bnlsIn.readDWord();
                      exeInfo = bnlsIn.readNTString();
                      bnlsIn.readDWord(); // cookie
                      /*int exeVerbyte =*/ bnlsIn.readDWord();
                      assert(bnlsIn.available() == 0);

                      recieveInfo("Recieved CheckRevision from BNLS");

                      conn.close();
                   } catch(UnknownHostException e) {
                      recieveError("BNLS connection failed: " + e.getMessage());
                      setConnected(false);
                      break;
                   }

                   if((exeVersion == 0) || (exeHash == 0) || (exeInfo == null) || (exeInfo.length() == 0)) {
                      recieveError("Checkrevision failed!");
                      setConnected(false);
                      break;
                   }


See:
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bncs/BNCSConnection.java
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bnls/
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: devcode on September 22, 2007, 12:15 AM
A nice huge project there Camel ;) SVN unfortunately sucks, Perforce > *

Quote from: Camel on September 20, 2007, 11:34 PM
Or, this Java library:

   try {
                      InetAddress address = MirrorSelector.getClosestMirror(cs.bnlsServer, cs.bnlsPort);
                      Socket conn = new Socket(address, cs.bnlsPort);

                      recieveInfo("Connected to " + address + ":" + cs.bnlsPort);

                      BNLSPacket bnlsOut = new BNLSPacket(BNLSCommandIDs.BNLS_VERSIONCHECKEX2);
                      bnlsOut.writeDWord(cs.product);
                      bnlsOut.writeDWord(0);   // Flags
                      bnlsOut.writeDWord(0);   // Cookie
                      bnlsOut.writeQWord(MPQFileTime);
                      bnlsOut.writeNTString(MPQFileName);
                      bnlsOut.writeNTString(ValueStr);
                      bnlsOut.SendPacket(conn.getOutputStream(), cs.packetLog);

                      InputStream bnlsInputStream = conn.getInputStream();
                      long startTime = System.currentTimeMillis();
                      while(bnlsInputStream.available() < 3) {
                         Thread.sleep(10);
                         Thread.yield();

                         long timeElapsed = System.currentTimeMillis() - startTime;
                         if(timeElapsed > 5000)
                            throw new Exception("BNLS_VERSIONCHECKEX2 timeout");
                      }

                      BNLSPacketReader bpr = new BNLSPacketReader(bnlsInputStream, cs.packetLog);
                      BNetInputStream bnlsIn = bpr.getInputStream();
                      int success = bnlsIn.readDWord();
                      if(success != 1) {
                         Out.error(getClass(), "BNLS_VERSIONCHECKEX2 Failed\n" + HexDump.hexDump(bpr.getData()));
                         throw new Exception("BNLS failed to complete BNLS_VERSIONCHECKEX2 sucessfully");
                      }
                      exeVersion = bnlsIn.readDWord();
                      exeHash = bnlsIn.readDWord();
                      exeInfo = bnlsIn.readNTString();
                      bnlsIn.readDWord(); // cookie
                      /*int exeVerbyte =*/ bnlsIn.readDWord();
                      assert(bnlsIn.available() == 0);

                      recieveInfo("Recieved CheckRevision from BNLS");

                      conn.close();
                   } catch(UnknownHostException e) {
                      recieveError("BNLS connection failed: " + e.getMessage());
                      setConnected(false);
                      break;
                   }

                   if((exeVersion == 0) || (exeHash == 0) || (exeInfo == null) || (exeInfo.length() == 0)) {
                      recieveError("Checkrevision failed!");
                      setConnected(false);
                      break;
                   }


See:
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bncs/BNCSConnection.java
http://bnubot.googlecode.com/svn/trunk/BNUBot/src/net/bnubot/core/bnls/
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Camel on September 22, 2007, 02:06 AM
From what I've read, SVN has the largest stability e-penis, and that's all I care about. Besides, I don't choose what mechanism Google Code uses.
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Smarter on September 26, 2007, 08:14 AM
How bout you just do:

Convert.ToInt32(mpqFilename.Substring(14, 2));
  - I also added the Convert, so it's ready for your packet:

Example:

ublic void BNLS_VERSIONCHECK()
        {
            DataBuffer s0x09 = new DataBuffer();
            s0x09.InsertInt16(0);
            s0x09.InsertByte((byte)BNLSPacketId.BNLS_VERSIONCHECK);
            s0x09.InsertInt32(0x04);
            s0x09.InsertInt32(Convert.ToInt32(mpqFilename.Substring(14, 2)));
            s0x09.InsertCString(checksumFormula);
            byte[] temp = s0x09.GetData();
            temp[0] = Convert.ToByte(Convert.ToInt16(s0x09.Count));
            bnls.SendData(temp);
            AddChat("BNLS VersionCheck Sent", Color.Black);
        }
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Camel on September 26, 2007, 10:45 PM
How bout you just do: BNLS_VERSIONCHECKEX2
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Chriso on September 27, 2007, 02:33 AM
Quote from: Smarter on September 26, 2007, 08:14 AM
How bout you just do:

Convert.ToInt32(mpqFilename.Substring(14, 2));

Because it is not always at position 14 of the string, e.g. IX86-ver-00.mpq (starts at 10), lockdown-IX86-00.mpq (starts at 15), and ver-IX86-00.mpq (starts at 10 as well).

The CheckRevision.extractMPQNumber determines which mpq file it is before extracting the number of the mpq.
Title: Re: MBNCSUtil.CheckRevision.ExtractMPQNumber
Post by: Camel on September 27, 2007, 08:07 PM
Quote from: Camel on September 26, 2007, 10:45 PM
How bout you just do: BNLS_VERSIONCHECKEX2