• Welcome to Valhalla Legends Archive.
 

0x51 STAR

Started by Ribose, April 14, 2008, 02:01 PM

Previous topic - Next topic

Ribose


[2:38:01 PM] [BNET] Connecting to useast.battle.net..
[2:38:01 PM] [BNET] Connected!
[2:38:01 PM] [BNET] SENT BYTE 0x1
[2:38:01 PM] [BNET] SENT PACKET 0x50:
0000   ff 50 3a 00 00 00 00 00  36 38 58 49 52 41 54 53    ÿP:.....68XIRATS
0010   d1 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00    Ñ...............
0020   00 00 00 00 00 00 00 00  55 53 41 00 55 6e 69 74    ........USA.Unit
0030   65 64 20 53 74 61 74 65  73 00                      ed States.

[2:38:01 PM] [BNET] SENT PACKET 0x25:
0000   ff 25 08 00 00 00 00 00                              ÿ%......

[2:38:02 PM] [BNET] Requesting logon authorization..
[2:38:02 PM] [BNET] RECIEVED PACKET 0x25:
0000   ff 25 08 00 b5 02 8a 4e                              ÿ%..µ..N

[2:38:02 PM] [BNET] RECIEVED PACKET 0x50:
0000   ff 50 3e 00 00 00 00 00  15 0a b4 0c 6f 62 37 00    ÿP>.......´.ob7.
0010   00 ba f7 d9 72 fc c6 01  6c 6f 63 6b 64 6f 77 6e    .º÷ÙrüÆ.lockdown
0020   2d 49 58 38 36 2d 31 33  2e 6d 70 71 00 fb 09 75    -IX86-13.mpq.û.u
0030   c4 cd 3e 31 94 b8 27 7f  52 e3 69 18 4d 00          ÄÍ>1.¸'.Rãi.M.

[2:38:02 PM] [BNET] Received authorization challenge!
[2:38:04 PM] [BNET] SENT PACKET 0x51:
0000   ff 51 54 00 13 37 00 00  00 02 0f 01 62 fe fd 0a    ÿQT..7......bþý.
0010   01 00 00 00 00 00 00 00  0d 00 00 00 02 00 00 00    ................
0020   ba 45 4d 00 00 00 00 00  bf b4 1d e1 96 4d cc 8c    ºEM.....¿´.á.MÌ.
0030   b7 97 6a ed 16 b8 46 4d  bc 9e 07 8b 3f 3f 5b 3f    ·.jí.¸FM....??[?
0040   66 4a 3f 3f 7a 3f 3f 3f  3f 3f 4d 3f 00 46 65 6c    fJ??z?????M?.Fel
0050   62 6f 74 00                                         bot.

[2:38:04 PM] [BNET] Answering authorization challenge..
[2:38:04 PM] [BNET] RECIEVED PACKET 0x51:
0000   ff 51 09 00 01 01 00 00  00                          ÿQ.......

[2:38:04 PM] [BNET] Authorization challenge failed. Game version is invalid!
[2:38:04 PM] [BNET] Disconnected!


Using MBNCSUtil:

        /// <summary>Sends 0x51, SID_AUTH_CHECK.</summary>
        /// <param name="a_iLogonType">Logon type.</param>
        /// <param name="a_iServerToken">Server token.</param>
        /// <param name="a_iUdpValue">UDP value.</param>
        /// <param name="a_lMpqFiletime">MPQ Filename.</param>
        /// <param name="a_sVersionDLL">Version DLL.</param>
        /// <param name="a_sVersionFormula">Version Formula.</param>
        private void SendPacket51(int a_iLogonType, int a_iServerToken, int a_iUdpValue, long a_lMpqFiletime, string a_sVersionDLL, string a_sVersionFormula)
        {
            g_iLogonType =      a_iLogonType;
            g_iServerToken =    a_iServerToken;
            g_iUdpValue =       a_iUdpValue;
            g_lMpqFiletime =    a_lMpqFiletime;
            g_sVersionDLL =     a_sVersionDLL;
            g_bVersionFormula = new byte[a_sVersionFormula.Length];
            for (int i = 0; i < a_sVersionFormula.Length; i++)
            {
                g_bVersionFormula[i] = (byte) a_sVersionFormula[i];
            }

            #region Hash CD-Key
            int m_iKeyCount;
            if (Client.Equals("D2XP") || Client.Equals("W3XP"))
            {
                m_iKeyCount = 2;
            }
            else
            {
                m_iKeyCount = 1;
            }

            string[] m_sCdKey = new string[m_iKeyCount];
            CdKey[] m_kd = new CdKey[m_iKeyCount];
            byte[][] m_bCdKeyHash = new byte[m_iKeyCount][];
            int[] m_iCdKeyLengths = new int[m_iKeyCount];
            string m_sExeStatstring = "";
            m_sCdKey[0] = ProfileForm.Profile.GetSetting("Connection", "CdKey").ToString("").Replace("-", "").Trim();
            if (m_iKeyCount >= 2)
            {
                m_sCdKey[1] = ProfileForm.Profile.GetSetting("Connection", "ExpCdKey").ToString("").Replace("-", "").Trim();
            }
            for (int i = 0; i < m_iKeyCount; i++)
            {
                try
                {
                    m_iCdKeyLengths[i] = m_sCdKey[i].Length;
                    m_kd[i] = CdKey.CreateDecoder(m_sCdKey[i]);
                    m_bCdKeyHash[i] = m_kd[i].GetHash(g_iClientToken, g_iServerToken);
                    if (!m_kd[i].IsValid)
                    {
                        ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Orange, "Felbot has detected that CD-key " + i.ToString() + " is invalid."));
                        continue;
                    }
                    if (i == 0) //for Warden
                    {
                        g_sKeyHash = m_bCdKeyHash[i].ToString();
                    }
                }
                catch (InvalidOperationException m_eIOE)
                {
                    ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Red, "Caught invalid operation exception while preparing CD-Key " + i.ToString() + ": "
                        + Environment.NewLine + m_eIOE.ToString()));
                    Socket_Disconnect();
                    return;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            #endregion

            #region Perform CheckRevision
            int m_iChecksum = -1;
            int m_iVersionHash = -1;
            byte[] m_bExeStatstring;
            if (g_bnClient.Equals("NB2W") || g_bnClient.Equals("RATS") || g_bnClient.Equals("PXES"))
            {
                #region Lockdown
                if (!File.Exists(Path.GetTempPath() + g_sVersionDLL.Replace(".mpq", ".dll")))
                {
                    string m_sProductForwards = "";
                    if (g_bnClient.Equals("RATS")) m_sProductForwards = "STAR";
                    if (g_bnClient.Equals("PXES")) m_sProductForwards = "SEXP";
                    if (g_bnClient.Equals("NB2W")) m_sProductForwards = "W2BN";

                    ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Yellow, "[BNET] Downloading and extracting lockdown DLL.."));

                    // Download the Lockdown MPQ
                    BnFtpVersion1Request m_bnftpRequest = new BnFtpVersion1Request(m_sProductForwards, g_sVersionDLL, DateTime.FromFileTime(g_lMpqFiletime));
                    m_bnftpRequest.LocalFileName = Path.GetTempPath() + g_sVersionDLL;
                    m_bnftpRequest.ExecuteRequest();

                    // Open the MPQ, retreive the file stream for the DLL, and create a output file
                    MpqArchive m_MPQ;
                    MpqFileStream m_fsDLL;

                    try
                    {
                        m_MPQ = MpqServices.OpenArchive(Path.GetTempPath() + g_sVersionDLL);
                        m_fsDLL = m_MPQ.OpenFile(g_sVersionDLL.Replace(".mpq", ".dll"));
                    }
                    catch (TypeInitializationException tie)
                    {
                        ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Red, "Caught a TypeInitializationException when opening the MPQ: " +
                            Environment.NewLine + tie.ToString()));
                        ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Red, "Inner exception: " + Environment.NewLine +
                            tie.InnerException.ToString()));
                        Socket_Disconnect();
                        return;
                    }

                    FileStream m_fsOutput = File.Create(Path.GetTempPath() + g_sVersionDLL.Replace("mpq", "dll"));

                    // Perform the actual copying
                    byte[] data = new byte[m_fsDLL.Length];
                    m_fsDLL.Read(data, 0, (int) m_fsDLL.Length);
                    m_fsOutput.Write(data, 0, (int) m_fsDLL.Length);

                    // Clean up handles
                    m_fsOutput.Close(); m_fsOutput.Dispose();
                    m_fsDLL.Close(); m_fsDLL.Dispose();
                    m_MPQ.Dispose();

                    // Delete the MPQ after extracting
                    //File.Delete(Path.GetTempPath() + g_sVersionDLL);

                    ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.GreenYellow, "[BNET] Finished! Continuing CheckRevision."));
                }

                m_bExeStatstring = CheckRevision.DoLockdownCheckRevision(g_bVersionFormula,
                    g_bnClient.g_sHashes,
                    Path.GetTempPath() + g_sVersionDLL.Replace(".mpq", ".dll"),
                    g_bnClient.g_sImageFile,
                    ref m_iVersionHash, ref m_iChecksum);

                foreach (byte m_bExeByte in m_bExeStatstring)
                {
                    m_sExeStatstring += (char) m_bExeByte;
                }
                #endregion
            }
            else
            {
                #region IX86Ver
                char[] m_cVersionFormula = new char[g_bVersionFormula.Length];
                for (int i = 0; i < g_bVersionFormula.Length; i++)
                    m_cVersionFormula[i] = (char) g_bVersionFormula[i];
                m_iChecksum = CheckRevision.DoCheckRevision(new String(m_cVersionFormula),
                    g_bnClient.g_sHashes,
                    CheckRevision.ExtractMPQNumber(g_sVersionDLL));
                Console.WriteLine(g_bVersionFormula.ToString());

                m_iVersionHash = CheckRevision.GetExeInfo(
                    g_bnClient.g_sHashes[0],
                    out m_sExeStatstring);
                #endregion
            }
            #endregion

            #region Send 0x51
            BncsPacket m_pbBncsPacket = new BncsPacket(BattleNetPacketIDs.SID_AUTH_CHECK);
            m_pbBncsPacket.InsertInt32(g_iClientToken);
            m_pbBncsPacket.InsertInt32(m_iVersionHash);
            m_pbBncsPacket.InsertInt32(m_iChecksum);
            #region Insert CD-Keys
            m_pbBncsPacket.InsertInt32(m_iKeyCount);
            m_pbBncsPacket.InsertBoolean(false);
            for (int i = 0; i < m_iKeyCount; i++)
            {
                m_pbBncsPacket.InsertInt32(m_iCdKeyLengths[i]);
                m_pbBncsPacket.InsertInt32(m_kd[i].Product);
                m_pbBncsPacket.InsertInt32(m_kd[i].Value1);
                m_pbBncsPacket.InsertInt32(0);
                m_pbBncsPacket.InsertByteArray(m_bCdKeyHash[i]);
            }
            #endregion
            m_pbBncsPacket.InsertCString(m_sExeStatstring);
            m_pbBncsPacket.InsertCString("Felbot");
            SendPacket(m_pbBncsPacket.GetData());
            #endregion
        }


My thoughts:
I have the correct verbyte, right? (0xD1 / 209d)

It worked before, and it works on WarCraft III / Diablo II (so its obviously something to do with the #region Lockdown).

The parameters for the function are read right out of the BncsReader:
SendPacket51(a_prReader.ReadInt32(), a_prReader.ReadInt32(), a_prReader.ReadInt32(), a_prReader.ReadInt64(), a_prReader.ReadCString(), a_prReader.ReadCString());
~Ribose

MyndFyre

The problem you're running into is here:


m_pbBncsPacket.InsertCString(m_sExeStatstring);


Instead, use the InsertByteArray method and store the Lockdown results as a byte[], not a string.  .NET cannot convert between a byte[] and a string the way you're trying to do it (which is why MBNCSUtil returns a byte[].  I didn't just do it for shits and giggles).

Suggested code to replace this:

m_pbBncsPacket.InsertByteArray(m_bExeStatstring);
m_pbBncsPacket.InsertByte(0);


Also, drop this section:

                foreach (byte m_bExeByte in m_bExeStatstring)
                {
                    m_sExeStatstring += (char) m_bExeByte;
                }

It doesn't work correctly for you.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Ribose

I see. But it still says the version is invalid. :(
[3:22:14 PM] [BNET] SENT PACKET 0x51:
0000   ff 51 55 00 13 37 00 00  00 02 0f 01 fe 32 8e fd    ÿQU..7......þ2.ý
0010   01 00 00 00 00 00 00 00  0d 00 00 00 02 00 00 00    ................
0020   ba 45 4d 00 00 00 00 00  a7 ed 63 b6 9d c4 1b ae    ºEM.....§íc¶.Ä.®
0030   00 53 ef 3e d2 5b 9b ec  05 72 0c 63 c4 6d 96 c5    .Sï>Ò[.ì.r.cÄm.Å
0040   24 7b cf e5 a9 1a a7 98  8a 0d 94 07 02 00 46 65    ${Ïå©.§.......Fe
0050   6c 62 6f 74 00                                      lbot.

[3:22:14 PM] [BNET] Answering authorization challenge..
[3:22:14 PM] [BNET] RECIEVED PACKET 0x51:
0000   ff 51 09 00 01 01 00 00  00                          ÿQ.......

[3:22:14 PM] [BNET] Authorization challenge failed. Game version is invalid!
[3:22:14 PM] [BNET] Disconnected!

        private void SendPacket51(int a_iLogonType, int a_iServerToken, int a_iUdpValue, long a_lMpqFiletime, string a_sVersionDLL, string a_sVersionFormula)
        {
            g_iLogonType =      a_iLogonType;
            g_iServerToken =    a_iServerToken;
            g_iUdpValue =       a_iUdpValue;
            g_lMpqFiletime =    a_lMpqFiletime;
            g_sVersionDLL =     a_sVersionDLL;
            g_bVersionFormula = new byte[a_sVersionFormula.Length];
            for (int i = 0; i < a_sVersionFormula.Length; i++)
            {
                g_bVersionFormula[i] = (byte) a_sVersionFormula[i];
            }

            #region Hash CD-Key
            int m_iKeyCount;
            if (Client.Equals("D2XP") || Client.Equals("W3XP"))
            {
                m_iKeyCount = 2;
            }
            else
            {
                m_iKeyCount = 1;
            }

            string[] m_sCdKey = new string[m_iKeyCount];
            CdKey[] m_kd = new CdKey[m_iKeyCount];
            byte[][] m_bCdKeyHash = new byte[m_iKeyCount][];
            int[] m_iCdKeyLengths = new int[m_iKeyCount];
            m_sCdKey[0] = ProfileForm.Profile.GetSetting("Connection", "CdKey").ToString("").Replace("-", "").Trim();
            if (m_iKeyCount >= 2)
            {
                m_sCdKey[1] = ProfileForm.Profile.GetSetting("Connection", "ExpCdKey").ToString("").Replace("-", "").Trim();
            }
            for (int i = 0; i < m_iKeyCount; i++)
            {
                try
                {
                    m_iCdKeyLengths[i] = m_sCdKey[i].Length;
                    m_kd[i] = CdKey.CreateDecoder(m_sCdKey[i]);
                    m_bCdKeyHash[i] = m_kd[i].GetHash(g_iClientToken, g_iServerToken);
                    if (!m_kd[i].IsValid)
                    {
                        ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Orange, "Felbot has detected that CD-key " + i.ToString() + " is invalid."));
                        continue;
                    }
                    if (i == 0) //for Warden
                    {
                        g_sKeyHash = m_bCdKeyHash[i].ToString();
                    }
                }
                catch (InvalidOperationException m_eIOE)
                {
                    ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Red, "Caught invalid operation exception while preparing CD-Key " + i.ToString() + ": "
                        + Environment.NewLine + m_eIOE.ToString()));
                    Socket_Disconnect();
                    return;
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
            #endregion

            #region Perform CheckRevision
            int m_iChecksum = -1;
            int m_iVersionHash = -1;
            byte[] m_bExeStatstring = null;
            string m_sExeStatstring = "";
            if (g_bnClient.Equals("NB2W") || g_bnClient.Equals("RATS") || g_bnClient.Equals("PXES"))
            {
                #region Lockdown
                if (!File.Exists(Path.GetTempPath() + g_sVersionDLL.Replace(".mpq", ".dll")))
                {
                    string m_sProductForwards = "";
                    if (g_bnClient.Equals("RATS")) m_sProductForwards = "STAR";
                    if (g_bnClient.Equals("PXES")) m_sProductForwards = "SEXP";
                    if (g_bnClient.Equals("NB2W")) m_sProductForwards = "W2BN";

                    ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Yellow, "[BNET] Downloading and extracting lockdown DLL.."));

                    // Download the Lockdown MPQ
                    BnFtpVersion1Request m_bnftpRequest = new BnFtpVersion1Request(m_sProductForwards, g_sVersionDLL, DateTime.FromFileTime(g_lMpqFiletime));
                    m_bnftpRequest.LocalFileName = Path.GetTempPath() + g_sVersionDLL;
                    m_bnftpRequest.ExecuteRequest();

                    // Open the MPQ, retreive the file stream for the DLL, and create a output file
                    MpqArchive m_MPQ;
                    MpqFileStream m_fsDLL;

                    try
                    {
                        m_MPQ = MpqServices.OpenArchive(Path.GetTempPath() + g_sVersionDLL);
                        m_fsDLL = m_MPQ.OpenFile(g_sVersionDLL.Replace(".mpq", ".dll"));
                    }
                    catch (TypeInitializationException tie)
                    {
                        ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Red, "Caught a TypeInitializationException when opening the MPQ: " +
                            Environment.NewLine + tie.ToString()));
                        ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.Red, "Inner exception: " + Environment.NewLine +
                            tie.InnerException.ToString()));
                        Socket_Disconnect();
                        return;
                    }

                    FileStream m_fsOutput = File.Create(Path.GetTempPath() + g_sVersionDLL.Replace("mpq", "dll"));

                    // Perform the actual copying
                    byte[] data = new byte[m_fsDLL.Length];
                    m_fsDLL.Read(data, 0, (int) m_fsDLL.Length);
                    m_fsOutput.Write(data, 0, (int) m_fsDLL.Length);

                    // Clean up handles
                    m_fsOutput.Close(); m_fsOutput.Dispose();
                    m_fsDLL.Close(); m_fsDLL.Dispose();
                    m_MPQ.Dispose();

                    // Delete the MPQ after extracting
                    //File.Delete(Path.GetTempPath() + g_sVersionDLL);

                    ProfileForm.RichTextBox.AddTextNodes(new TextNode(Color.GreenYellow, "[BNET] Finished! Continuing CheckRevision."));
                }

                m_bExeStatstring = CheckRevision.DoLockdownCheckRevision(g_bVersionFormula,
                    g_bnClient.g_sHashes,
                    Path.GetTempPath() + g_sVersionDLL.Replace(".mpq", ".dll"),
                    g_bnClient.g_sImageFile,
                    ref m_iVersionHash, ref m_iChecksum);
                #endregion
            }
            else
            {
                #region IX86Ver
                char[] m_cVersionFormula = new char[g_bVersionFormula.Length];
                for (int i = 0; i < g_bVersionFormula.Length; i++)
                    m_cVersionFormula[i] = (char) g_bVersionFormula[i];
                m_iChecksum = CheckRevision.DoCheckRevision(new String(m_cVersionFormula),
                    g_bnClient.g_sHashes,
                    CheckRevision.ExtractMPQNumber(g_sVersionDLL));
                Console.WriteLine(g_bVersionFormula.ToString());

                m_iVersionHash = CheckRevision.GetExeInfo(
                    g_bnClient.g_sHashes[0],
                    out m_sExeStatstring);
                #endregion
            }
            #endregion

            #region Send 0x51
            BncsPacket m_pbBncsPacket = new BncsPacket(BattleNetPacketIDs.SID_AUTH_CHECK);
            m_pbBncsPacket.InsertInt32(g_iClientToken);
            m_pbBncsPacket.InsertInt32(m_iVersionHash);
            m_pbBncsPacket.InsertInt32(m_iChecksum);
            #region Insert CD-Keys
            m_pbBncsPacket.InsertInt32(m_iKeyCount);
            m_pbBncsPacket.InsertBoolean(false);
            for (int i = 0; i < m_iKeyCount; i++)
            {
                m_pbBncsPacket.InsertInt32(m_iCdKeyLengths[i]);
                m_pbBncsPacket.InsertInt32(m_kd[i].Product);
                m_pbBncsPacket.InsertInt32(m_kd[i].Value1);
                m_pbBncsPacket.InsertInt32(0);
                m_pbBncsPacket.InsertByteArray(m_bCdKeyHash[i]);
            }
            #endregion
            if (g_bnClient.Equals("NB2W") || g_bnClient.Equals("RATS") || g_bnClient.Equals("PXES"))
            {
                m_pbBncsPacket.InsertByteArray(m_bExeStatstring);
                m_pbBncsPacket.InsertByte(0x00); //null terminator
            }
            else
            {
                m_pbBncsPacket.InsertCString(m_sExeStatstring);
            }
            m_pbBncsPacket.InsertCString("Felbot");
            SendPacket(m_pbBncsPacket.GetData());
            #endregion
        }
~Ribose

MyndFyre

What's the size of your lockdown .bin file?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Ribose

Quote from: MyndFyre[vL] on April 14, 2008, 03:25 PM
What's the size of your lockdown .bin file?
RATS.bin is 9.75 KB (9,984 bytes).
~Ribose

MyndFyre

Can you show me how you populate your g_bVersionFormula variable?

Also, I've noticed that you've got a couple other difficulties -- for instance, you try to convert the val string to a string in a way that isn't really good.

This is my latest code that I use for handling 0x50 and sending 0x51.


        private void HandleAuthInfo(DataReader dr)
        {
            if (m_pingPck != null)
            {
                Send(m_pingPck);
                m_pingPck = null;
                m_received0x50 = false;
            }
            m_received0x50 = true;

            m_loginType = dr.ReadUInt32();
            m_srvToken = dr.ReadUInt32();
            m_udpVal = dr.ReadUInt32();
            m_mpqFiletime = dr.ReadInt64();
            m_verFilename = dr.ReadCString();
            m_usingLockdown = m_verFilename.ToLower().StartsWith("lockdown");

            int crResult = -1, exeVer = -1;
            string exeInfo = null;

            // not using lockdown
            if (!m_usingLockdown)
            {
                m_valString = dr.ReadCString();
                int mpqNum = CheckRevision.ExtractMPQNumber(m_verFilename);
                crResult = CheckRevision.DoCheckRevision(m_valString, new string[] { settings.GameExe, settings.GameFile2, settings.GameFile3 }, mpqNum);
                exeVer = CheckRevision.GetExeInfo(settings.GameExe, out exeInfo);
            }
            else // use lockdown.
            {
                // get the value string as a NT byte-array.
                m_ldValStr = dr.ReadNullTerminatedByteArray();
                string dllName = m_verFilename.Replace(".mpq", ".dll");

                BnFtpVersion1Request req = new BnFtpVersion1Request("STAR", m_verFilename, null);
                req.Server = Settings.Server;
                req.LocalFileName = Path.Combine(Path.GetTempPath(), m_verFilename);
                req.ExecuteRequest();

                string ldPath = null;
                using (MpqArchive arch = MpqServices.OpenArchive(req.LocalFileName))
                {
                    if (arch.ContainsFile(dllName))
                    {
                        using (MpqFileStream mfs = arch.OpenFile(dllName))
                        {
                            BinaryReader br = new BinaryReader(mfs);
                            byte[] data = br.ReadBytes((int)mfs.Length);
                            ldPath = Path.Combine(Path.GetTempPath(), dllName);
                            File.WriteAllBytes(ldPath, data);
                        }
                    }
                }

                m_ldDigest = CheckRevision.DoLockdownCheckRevision(m_ldValStr, new string[] { settings.GameExe, settings.GameFile2, settings.GameFile3 },
                                ldPath, settings.ImageFile, ref exeVer, ref crResult);
            }

            m_prodCode = settings.Client;

            if (m_prodCode == "WAR3" ||
                m_prodCode == "W3XP")
            {
                m_w3srv = dr.ReadByteArray(128);

                if (!NLS.ValidateServerSignature(m_w3srv, RemoteEP.Address.GetAddressBytes()))
                {
                    OnGeneralError(new ErrorEventArgs(BattleNet.War3ServerValidationFailed, true));
                    Close();
                    return;
                }
            }         

            CdKey key1, key2 = null;
            key1 = new CdKey(settings.CdKey1);
            if (m_prodCode == "D2XP" || m_prodCode == "W3XP")
            {
                key2 = new CdKey(settings.CdKey2);
            }

            m_clientToken = unchecked((uint)new Random().Next());

            byte[] key1Hash = key1.GetHash(m_clientToken, m_srvToken);
            if (warden != null)
            {
                try
                {
                    if (warden.InitWarden(BitConverter.ToInt32(key1Hash, 0), SocketHandle, Settings.GameFile3) == 0)
                    {
                        warden.UninitWarden();
                        OnGeneralError(new ErrorEventArgs("The Warden module failed to initialize.  You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false));
                        warden = null;
                    }
                }
                catch (Win32Exception we)
                {
                    OnGeneralError(new ErrorEventArgs("The Warden module failed to initialize.  You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false));
                    OnGeneralError(new ErrorEventArgs(string.Format("Additional information: {0}", we.Message), false));
                    warden.UninitWarden();
                    warden = null;
                }
            }

            BncsPacket pck0x51 = new BncsPacket((byte)BncsPacketId.AuthCheck);
            pck0x51.Insert(m_clientToken);
            pck0x51.Insert(exeVer);
            pck0x51.Insert(crResult);
            if (m_prodCode == "D2XP" || m_prodCode == "W3XP")
                pck0x51.Insert(2);
            else
                pck0x51.Insert(1);
            pck0x51.Insert(false);
            pck0x51.Insert(key1.Key.Length);
            pck0x51.Insert(key1.Product);
            pck0x51.Insert(key1.Value1);
            pck0x51.Insert(0);
            pck0x51.Insert(key1Hash);
            if (key2 != null)
            {
                pck0x51.Insert(key2.Key.Length);
                pck0x51.Insert(key2.Product);
                pck0x51.Insert(key2.Value1);
                pck0x51.Insert(0);
                pck0x51.Insert(key2.GetHash(m_clientToken, m_srvToken));
            }

            if (m_usingLockdown)
            {
                pck0x51.InsertByteArray(m_ldDigest);
                pck0x51.InsertByte(0);
            }
            else
                pck0x51.InsertCString(exeInfo);

            pck0x51.InsertCString(BOT_NAME);

            Send(pck0x51.GetData());
        }
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Ribose

#6
Quote from: MyndFyre[vL] on April 14, 2008, 04:55 PM
Can you show me how you populate your g_bVersionFormula variable?
Yay! I fixed it.

I made it use .ReadNullTerminatedByteArray() to get the value string, rather than .ReadCString() and a crude loop. :/
I don't know how WarCraft III worked with the other way.  Probably because the lockdown value strings are reallly weird "û.uÄÍ>1.¸'.Rãi.M" while the others are simpler "C=3779699026 B=4034163727 A=3366429739 4 A=A+S B=B+C C=C+A A=A+B".
Well um, resolved. :)
~Ribose