public BniIconProvider() { CreateFailedBitmap(); string basePath = Path.Combine(JinxBotConfiguration.ApplicationDataPath, "icons.bni"); if (!File.Exists(basePath)) { try { BnFtpRequestBase req = new BnFtpVersion1Request(Product.StarcraftRetail.ProductCode, "icons.bni", null); req.LocalFileName = basePath; req.ExecuteRequest(); m_bni = new BniFileParser(basePath); m_valid = true; } catch { } } else { try { m_bni = new BniFileParser(basePath); m_valid = true; } catch { } } }
private void bwDownload_DoWork(object sender, DoWorkEventArgs e) { if (TaskbarManager.IsPlatformSupported) { //BeginInvoke((ThreadStart)delegate() { TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal, Handle); }); } bwDownload.ReportProgress(0, "icons.bni"); BnFtpVersion1Request req = new BnFtpVersion1Request("STAR", "icons.bni", null); req.LocalFileName = Path.Combine(JinxBotConfiguration.ApplicationDataPath, "icons.bni"); req.FilePartDownloaded += new DownloadStatusEventHandler(req_FilePartDownloaded); req.ExecuteRequest(); JumpListIconManager.CreateJumpListImages(req.LocalFileName); WebIconList iconsList = null; string xml = DataResources.WebIconsList; using (StringReader sr = new StringReader(xml)) using (XmlTextReader xtr = new XmlTextReader(sr)) { try { XmlSerializer ser = new XmlSerializer(typeof(WebIconList)); iconsList = ser.Deserialize(xtr) as WebIconList; } catch (Exception) { // TODO: Log the exception. MessageBox.Show("There was an error loading the icons list.", "Error Downloading Icons", MessageBoxButtons.OK, MessageBoxIcon.Error); iconsList = new WebIconList() { Icons = new WebIconList.Icon[0] }; } } for (int i = 0; i < iconsList.Icons.Length; i++) { bwDownload.ReportProgress(i * 100 / iconsList.Icons.Length, iconsList.Icons[i].Uri); DownloadFile(iconsList.Icons[i]); } }
private bool DownloadFile(string productKey, string lockdownFile, string lockdownResource) { BnFtpVersion1Request req = new BnFtpVersion1Request(productKey, lockdownFile, null); req.Server = "useast.battle.net"; req.LocalFileName = Server.MapPath(string.Format("~/Content/Lockdown/{0}", lockdownFile)); req.ExecuteRequest(); using (MpqArchive arch = MpqServices.OpenArchive(req.LocalFileName)) { string dllName = lockdownFile.Replace(".mpq", ".dll"); if (arch.ContainsFile(dllName)) { arch.SaveToPath(Path.GetFileName(dllName), Server.MapPath("~/Content/Lockdown"), false); //arch.SaveToPath(Server.MapPath("~/Content/Lockdown"), lockdownResource, false); return(true); } else { return(false); } } }
private async void HandleAuthInfo(BncsReader dr) { try { //DataReader dr = new DataReader(data.Data); //if (m_pingPck != null) //{ // Send(m_pingPck); // m_pingPck = null; //} _received0x50 = true; _loginType = dr.ReadUInt32(); _srvToken = dr.ReadInt32(); _udpVal = dr.ReadUInt32(); _mpqFileTime = dr.ReadInt64(); _versioningFilename = dr.ReadCString(); _usingLockdown = _versioningFilename.StartsWith("LOCKDOWN", StringComparison.OrdinalIgnoreCase); int crResult = -1, exeVer = -1; string exeInfo = null; if (!_usingLockdown) { _valString = dr.ReadCString(); int mpqNum = CheckRevision.ExtractMPQNumber(_versioningFilename); crResult = CheckRevision.DoCheckRevision(_valString, new Stream[] { File.OpenRead(_settings.GameExe), File.OpenRead(_settings.GameFile2), File.OpenRead(_settings.GameFile3) }, mpqNum); exeVer = CheckRevision.GetExeInfo(_settings.GameExe, out exeInfo); } else { _ldValStr = dr.ReadNullTerminatedByteArray(); string dllName = _versioningFilename.Replace(".mpq", ".dll"); BnFtpVersion1Request req = new BnFtpVersion1Request(_settings.Client, _versioningFilename, null); req.Gateway = _settings.Gateway; req.LocalFileName = Path.Combine(Path.GetTempPath(), _versioningFilename); await req.ExecuteRequest(); string ldPath = null; using (MpqArchive arch = MpqServices.OpenArchive(req.LocalFileName)) { if (arch.ContainsFile(dllName)) { ldPath = Path.Combine(Path.GetTempPath(), dllName); arch.SaveToPath(dllName, Path.GetTempPath(), false); } } _ldDigest = CheckRevision.DoLockdownCheckRevision(_ldValStr, new string[] { _settings.GameExe, _settings.GameFile2, _settings.GameFile3 }, ldPath, _settings.ImageFile, ref exeVer, ref crResult); } string prodCode = _settings.Client.ProductCode; if (prodCode == "WAR3" || prodCode == "W3XP") { _w3srv = dr.ReadByteArray(128); if (!NLS.ValidateServerSignature(_w3srv, _connection.RemoteEP.Address.GetAddressBytes())) { //OnError(new ErrorEventArgs(ErrorType.Warcraft3ServerValidationFailure, Strings.War3ServerValidationFailed, false)); //Close(); //return; } } // BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data); CdKey key1 = _settings.CdKey1, key2 = _settings.CdKey2; _clientToken = new Random().Next(); byte[] key1Hash = key1.GetHash(_clientToken, _srvToken); if (WardenHandler != null) { try { if (!WardenHandler.InitWarden(BitConverter.ToInt32(key1Hash, 0))) { WardenHandler.UninitWarden(); //OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, "The Warden module failed to initialize. You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false)); WardenHandler = null; } } catch (Win32Exception we) { //OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, "The Warden module failed to initialize. You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false)); //OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, string.Format(CultureInfo.CurrentCulture, "Additional information: {0}", we.Message), false)); WardenHandler.UninitWarden(); WardenHandler = null; } } BncsPacket pck0x51 = new BncsPacket(BncsPacketId.AuthCheck, _connection.NetworkBuffers.Acquire()); pck0x51.InsertInt32(_clientToken); pck0x51.InsertInt32(exeVer); pck0x51.InsertInt32(crResult); if (prodCode == "D2XP" || prodCode == "W3XP") { pck0x51.InsertInt32(2); } else { pck0x51.InsertInt32(1); } pck0x51.InsertBoolean(false); pck0x51.InsertInt32(key1.Key.Length); pck0x51.InsertInt32(key1.Product); pck0x51.InsertInt32(key1.Value1); pck0x51.InsertInt32(0); pck0x51.InsertByteArray(key1Hash); if (key2 != null) { pck0x51.InsertInt32(key2.Key.Length); pck0x51.InsertInt32(key2.Product); pck0x51.InsertInt32(key2.Value1); pck0x51.InsertInt32(0); pck0x51.InsertByteArray(key2.GetHash(_clientToken, _srvToken)); } if (_usingLockdown) { pck0x51.InsertByteArray(_ldDigest); pck0x51.InsertByte(0); } else { pck0x51.InsertCString(exeInfo); } pck0x51.InsertCString(_settings.CdKeyOwner); await pck0x51.SendAsync(_connection); } catch (Exception ex) { //OnError(new ErrorEventArgs(ErrorType.General, "There was an error while initializing your client. Refer to the exception message for more information.\n" + ex.ToString(), true)); Disconnect(); Console.WriteLine(ex.ToString()); } }
private void HandleAuthInfo(ParseData data) { try { DataReader dr = new DataReader(data.Data); if (m_pingPck != null) { Send(m_pingPck); m_pingPck = null; } m_received0x50 = true; m_loginType = dr.ReadUInt32(); m_srvToken = dr.ReadUInt32(); m_udpVal = dr.ReadUInt32(); m_mpqFiletime = dr.ReadInt64(); m_versioningFilename = dr.ReadCString(); m_usingLockdown = m_versioningFilename.StartsWith("LOCKDOWN", StringComparison.OrdinalIgnoreCase); int crResult = -1, exeVer = -1; string exeInfo = null; if (!m_usingLockdown) { m_valString = dr.ReadCString(); int mpqNum = CheckRevision.ExtractMPQNumber(m_versioningFilename); crResult = CheckRevision.DoCheckRevision(m_valString, new string[] { m_settings.GameExe, m_settings.GameFile2, m_settings.GameFile3 }, mpqNum); exeVer = CheckRevision.GetExeInfo(m_settings.GameExe, out exeInfo); } else { m_ldValStr = dr.ReadNullTerminatedByteArray(); string dllName = m_versioningFilename.Replace(".mpq", ".dll"); BnFtpVersion1Request req = new BnFtpVersion1Request(m_settings.Client, m_versioningFilename, null); req.Server = m_settings.Gateway.ServerHost; req.LocalFileName = Path.Combine(Path.GetTempPath(), m_versioningFilename); req.ExecuteRequest(); string ldPath = null; using (MpqArchive arch = MpqServices.OpenArchive(req.LocalFileName)) { if (arch.ContainsFile(dllName)) { ldPath = Path.Combine(Path.GetTempPath(), dllName); arch.SaveToPath(dllName, Path.GetTempPath(), false); } } m_ldDigest = CheckRevision.DoLockdownCheckRevision(m_ldValStr, new string[] { m_settings.GameExe, m_settings.GameFile2, m_settings.GameFile3 }, ldPath, m_settings.ImageFile, ref exeVer, ref crResult); } m_prodCode = m_settings.Client; if (m_prodCode == "WAR3" || m_prodCode == "W3XP") { m_w3srv = dr.ReadByteArray(128); if (!NLS.ValidateServerSignature(m_w3srv, RemoteEP.Address.GetAddressBytes())) { OnError(new ErrorEventArgs(ErrorType.Warcraft3ServerValidationFailure, Strings.War3ServerValidationFailed, false)); //Close(); //return; } } BattleNetClientResources.IncomingBufferPool.FreeBuffer(data.Data); CdKey key1, key2 = null; key1 = new CdKey(m_settings.CdKey1); if (m_prodCode == "D2XP" || m_prodCode == "W3XP") { key2 = new CdKey(m_settings.CdKey2); } m_clientToken = unchecked ((uint)new Random().Next()); byte[] key1Hash = key1.GetHash(m_clientToken, m_srvToken); if (m_warden != null) { try { if (!m_warden.InitWarden(BitConverter.ToInt32(key1Hash, 0))) { m_warden.UninitWarden(); OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, "The Warden module failed to initialize. You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false)); m_warden = null; } } catch (Win32Exception we) { OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, "The Warden module failed to initialize. You will not be immediately disconnected; however, you may be disconnected after a short period of time.", false)); OnError(new ErrorEventArgs(ErrorType.WardenModuleFailure, string.Format(CultureInfo.CurrentCulture, "Additional information: {0}", we.Message), false)); m_warden.UninitWarden(); m_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(m_settings.CdKeyOwner); Send(pck0x51); } catch (Exception ex) { OnError(new ErrorEventArgs(ErrorType.General, "There was an error while initializing your client. Refer to the exception message for more information.\n" + ex.ToString(), true)); Close(); } }