public static void RemoveWindowFrame(IntPtr handle, bool force = false) { if (!Settings.Default.AutoPosDiabloNoFrame && !force) { return; // Remove Frame is disabled } try { // Get current style var style = WinAPI.GetWindowLongPtr(handle, WinAPI.WindowLongFlags.GWL_STYLE); var newstyle = ((WinAPI.WindowStyles)style) & ~(WinAPI.WindowStyles.WS_CAPTION | WinAPI.WindowStyles.WS_THICKFRAME | WinAPI.WindowStyles.WS_MINIMIZE | WinAPI.WindowStyles.WS_MAXIMIZE /*| WinAPI.WindowStyles.WS_SYSMENU */); // Remove Frame from style WinAPI.SetWindowLongPtr(new HandleRef(null, handle), WinAPI.WindowLongFlags.GWL_STYLE, new IntPtr(Convert.ToInt64(newstyle))); // Set new style // Get current extended style var exStyle = WinAPI.GetWindowLongPtr(handle, WinAPI.WindowLongFlags.GWL_EXSTYLE); var newExStyle = ((WinAPI.WindowStyles)exStyle) & ~(WinAPI.WindowStyles.WS_EX_DLGMODALFRAME | WinAPI.WindowStyles.WS_EX_CLIENTEDGE | WinAPI.WindowStyles.WS_EX_STATICEDGE); // Remove Frame from extended style WinAPI.SetWindowLongPtr(new HandleRef(null, handle), WinAPI.WindowLongFlags.GWL_EXSTYLE, new IntPtr(Convert.ToInt64(newExStyle))); // set new extended style } catch (Exception ex) { DebugHelper.Write("Failed", "RemoveWindowFrame(...)"); DebugHelper.Exception(ex); } Thread.Sleep(100); // We need to wait a bit before we can reposition the window }
public static void ManualPositionWindow(IntPtr handle, int x, int y, int w, int h, BotClass bot = null) { // Set window position and size try { WinAPI.RECT rct; if (WinAPI.GetWindowRect(new HandleRef(bot, handle), out rct)) { if (w <= 0) { w = rct.Width; } if (h <= 0) { h = rct.Heigth; } DebugHelper.Write(bot, "ManualPosition window:{0}: X:{1} Y:{2} W:{3} H:{4}", handle, x, y, w, h); if (!WinAPI.SetWindowPos(handle, IntPtr.Zero, x, y, w, h, WinAPI.SetWindowPosFlags.SWP_NOACTIVATE | WinAPI.SetWindowPosFlags.SWP_NOSENDCHANGING)) { Logger.Instance.Write(bot, "ManualPosition window:{0}: Failed!", handle); } } else { Logger.Instance.Write(bot, "ManualPosition Failed to get window rectangle"); } } catch (Exception ex) { DebugHelper.Write(bot, "Failed", "ManualPositionWindow(...)"); DebugHelper.Exception(ex); } }
public static void RemoveWindowFrame(IntPtr handle, bool force = false) { if (!Settings.Default.AutoPosDiabloNoFrame && !force) { return; // Remove Frame is disabled } try { // Get current style var style = WinApi.GetWindowLongPtr(handle, WinApi.WindowLongFlags.GwlStyle); var newstyle = ((WinApi.WindowStyles)style) & ~(WinApi.WindowStyles.WsCaption | WinApi.WindowStyles.WsThickframe | WinApi.WindowStyles.WsMinimize | WinApi.WindowStyles.WsMaximize /*| WinAPI.WindowStyles.WS_SYSMENU */); // Remove Frame from style WinApi.SetWindowLongPtr(new HandleRef(null, handle), WinApi.WindowLongFlags.GwlStyle, new IntPtr(Convert.ToInt64(newstyle))); // Set new style // Get current extended style var exStyle = WinApi.GetWindowLongPtr(handle, WinApi.WindowLongFlags.GwlExstyle); var newExStyle = ((WinApi.WindowStyles)exStyle) & ~(WinApi.WindowStyles.WsExDlgmodalframe | WinApi.WindowStyles.WsExClientedge | WinApi.WindowStyles.WsExStaticedge); // Remove Frame from extended style WinApi.SetWindowLongPtr(new HandleRef(null, handle), WinApi.WindowLongFlags.GwlExstyle, new IntPtr(Convert.ToInt64(newExStyle))); // set new extended style } catch (Exception ex) { DebugHelper.Write("Failed", "RemoveWindowFrame(...)"); DebugHelper.Exception(ex); } Thread.Sleep(100); // We need to wait a bit before we can reposition the window }
public void KillSession(BotClass bot) { lock (_webClientLock) { var logintime = bot.Demonbuddy.LoginTime; _webClient.Headers["Referer"] = "http://buddyauth.com/User/Sessions"; var data = new NameValueCollection(); var match = GetSessions() .Where(i => logintime.Subtract(i.time).TotalSeconds <16 && logintime.Subtract(i.time).TotalSeconds> -16) .OrderBy(i => logintime.Subtract(i.time).TotalSeconds).FirstOrDefault(); if (match.id == 0) { Logger.Instance.Write(bot, "BuddyAuth: No session found."); return; } data.Set("selectedSessions[" + match.number + "].Id", Convert.ToString(match.id)); data.Set("selectedSessions[" + match.number + "].IsChecked", "true"); try { int retry = 3; do { try { _webClient.UploadValues("http://buddyauth.com/User/Sessions", data); Logger.Instance.Write(bot, "BuddyAuth: Session with id: {0} killed! (Time difference: {1})", match.id, logintime.Subtract(match.time).TotalSeconds); return; } catch (WebException wex) { var code = ((HttpWebResponse)wex.Response).StatusCode; if (code != HttpStatusCode.InternalServerError && code != HttpStatusCode.BadGateway && code != HttpStatusCode.ServiceUnavailable && code != HttpStatusCode.GatewayTimeout && code != HttpStatusCode.RequestTimeout) { Logger.Instance.Write(bot, "Failed: {0}", wex.Message); return; } Logger.Instance.Write(bot, "Failed: {0} (next retry in 5 seconds) [{1}]", wex.Message, 3 - retry + 1); Thread.Sleep(5000); } } while (retry-- > 0); } catch (Exception ex) { DebugHelper.Write(bot, "BuddyAuth session killer failed!"); DebugHelper.Exception(ex); return; } Logger.Instance.Write(bot, "BuddyAuth: No session found."); } }
public static bool CheckValidConnection(bool silent = false) { try { var wc = new WebClient(); wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); Stream data = wc.OpenRead("http://checkip.dyndns.org"); string ip = string.Empty; string hostname = string.Empty; if (data != null) { using (var reader = new StreamReader(data)) { string s = reader.ReadToEnd(); Match m = new Regex(@".*Current IP Address: ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*").Match (s); if (m.Success) { ip = m.Groups[1].Value; if (!silent) { DebugHelper.Write(string.Format("Host/IP Check: IP {0}{1}", ip, !string.IsNullOrEmpty(hostname) ? " HostName: " + hostname : "")); } if (!validIp(ip, silent)) { return(false); } } else { throw new Exception("No IP found!"); } } // data.Close(); } } catch (Exception ex) { DebugHelper.Write(string.Format("ValidConnection: {0}", ex.Message)); DebugHelper.Exception(ex); return(false); } return(true); }
public static void UpdateScreens() { var tmpList = new List <ScreensClass>(); var d = new WinAPI.DisplayDevice(); d.cb = Marshal.SizeOf(d); try { Logger.Instance.WriteGlobal("####[ Detecting Screens ]####"); for (uint id = 0; WinAPI.EnumDisplayDevices(null, id, ref d, 0); id++) { if (d.StateFlags.HasFlag(WinAPI.DisplayDeviceStateFlags.AttachedToDesktop)) { ScreensClass screen = (Settings.Default.AutoPosScreens != null ? Settings.Default.AutoPosScreens.FirstOrDefault( x => x != null && x.DisplayDevice.DeviceKey == d.DeviceKey) : null); var s = new ScreensClass { Enabled = (screen != null ? screen.Enabled : true), Order = (int)id, DisplayDevice = d }; tmpList.Add(s); Logger.Instance.WriteGlobal("-{0} Screen {1}: X:{2},Y:{3},W:{4},H:{5} Enabled:{6}", s.DisplayDevice.StateFlags.HasFlag(WinAPI.DisplayDeviceStateFlags.PrimaryDevice) ? " Primary" : "", id, s.Bounds.X, s.Bounds.Y, s.Bounds.Width, s.Bounds.Height, s.Enabled); Logger.Instance.WriteGlobal("Name: {0}", s.Name); Logger.Instance.WriteGlobal("Device: {0}", s.DisplayDevice.DeviceString); Logger.Instance.WriteGlobal("WorkingArea: X:{0},Y:{1},W:{2},H:{3}", s.WorkingArea.X, s.WorkingArea.Y, s.WorkingArea.Width, s.WorkingArea.Height); } d.cb = Marshal.SizeOf(d); } // Print screens to log Logger.Instance.WriteGlobal("######################"); Settings.Default.AutoPosScreens = tmpList; Settings.Default.Save(); } catch (Exception ex) { DebugHelper.Write("Failed", "UpdateScreens()"); DebugHelper.Exception(ex); } }
private static void RepositionWindow(IntPtr handle, int x, int y, int w, int h) { // Set window position and size try { WinAPI.RECT rct; if (WinAPI.GetWindowRect(new HandleRef(null, handle), out rct)) { if (w <= 0) { w = rct.Width; } if (h <= 0) { h = rct.Heigth; } Debug.WriteLine("handle: {0} X:{1},Y:{2},W:{3},H:{4}", handle, rct.Left, rct.Top, rct.Width, rct.Heigth); if (rct.Heigth == h && rct.Width == w && rct.Left == x && rct.Top == y) { DebugHelper.Write("No need to reposition: {0}", "RepositionWindow(...)", handle); return; } if ( !WinAPI.SetWindowPos(handle, IntPtr.Zero, x, y, w, h, WinAPI.SetWindowPosFlags.SWP_NOACTIVATE | WinAPI.SetWindowPosFlags.SWP_NOSENDCHANGING)) { Logger.Instance.WriteGlobal("AutoPosition window:{0}: Failed!", handle); } } else { Logger.Instance.WriteGlobal("AutoPosition Failed to get window rectangle ({0})", handle); } } catch (Exception ex) { DebugHelper.Write("Failed", "RepositionWindow(...)"); DebugHelper.Exception(ex); } }
public static bool PingCheck(bool silent = false) { var ping = new Ping(); try { // Ping host 1 if (!silent) { Logger.Instance.WriteGlobal("PingCheck: Ping -> {0}", Settings.Default.ConnectionCheckPingHost1); } var reply = ping.Send(Settings.Default.ConnectionCheckPingHost1, 3000); if (reply == null) { if (!silent) { DebugHelper.Write("PingCheck: reply = NULL"); } } else if (reply.Status != IPStatus.Success) { if (!silent) { DebugHelper.Write($"PingCheck: {reply.Address} -> {reply.Status}"); } } else { if (!silent) { DebugHelper.Write($"PingCheck: {reply.Address} -> {reply.RoundtripTime}ms"); } return(true); } } catch (Exception ex) { DebugHelper.Write(string.Format("PingCheck: Failed with message: " + ex.Message)); DebugHelper.Exception(ex); } try { // Ping host 2 if (!silent) { DebugHelper.Write($"PingCheck: Ping -> {Settings.Default.ConnectionCheckPingHost2}"); } var reply = ping.Send(Settings.Default.ConnectionCheckPingHost2, 3000); if (reply == null) { if (!silent) { DebugHelper.Write("PingCheck: reply = NULL"); } } else if (reply.Status != IPStatus.Success) { if (!silent) { DebugHelper.Write($"PingCheck: {reply.Address} -> {reply.Status}"); } } else { if (!silent) { DebugHelper.Write($"PingCheck: {reply.Address} -> {reply.RoundtripTime}ms"); } return(true); } } catch (Exception ex) { DebugHelper.Write(string.Format("PingCheck: Failed with message: " + ex.Message)); DebugHelper.Exception(ex); } return(false); }
private static bool ValidIp(string ip) { string hostname = null; try { hostname = Dns.GetHostEntry(ip).HostName; } catch (Exception ex) { DebugHelper.Exception(ex); } foreach (var line in Settings.Default.ConnectionCheckIpHostList.Split('\n')) { var test = line.Replace(" ", string.Empty).Trim(); if (test.Length < 1) { continue; } var allowed = test.StartsWith("@"); if (allowed) { test = test.Substring(1, test.Length - 1); } if (Settings.Default.ConnectionCheckIpCheck) { // Check Ip range var m = new Regex( @"([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})-([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})") .Match(test); if (m.Success) { var lowerip = IPAddress.Parse(m.Groups[1].Value); var higherip = IPAddress.Parse(m.Groups[2].Value); var inrange = new IpAddressRange(lowerip, higherip).IsInRange(IPAddress.Parse(ip)); if (inrange) { if (allowed) { DebugHelper.Write($"Valid Connection: IP {ip} in range -> {lowerip}-{higherip}"); return(true); } DebugHelper.Write($"Invalid Connection: IP {ip} in range -> {lowerip}-{higherip}"); return(false); } continue; } // Check single IP m = new Regex(@"([0-9*]{1,3}\.[0-9*]{1,3}\.[0-9*]{1,3}\.[0-9*]{1,3})").Match(test); if (m.Success) { test = m.Groups[1].Value; if (General.WildcardMatch(test, ip)) { if (allowed) { DebugHelper.Write($"Valid Connection: IP match {ip} -> {test}"); return(true); } DebugHelper.Write($"Invalid Connection: IP match {ip} -> {test}"); return(false); } continue; } } if (hostname == null) { continue; } if (General.WildcardMatch(test.ToLower(), hostname.ToLower())) { if (allowed) { DebugHelper.Write($"Valid Connection: Host match {hostname} -> {test}"); return(true); } DebugHelper.Write($"Invalid Connection: Host match {hostname} -> {test}"); return(false); } } return(true); }
public static void PositionWindows() { try { var workingScreens = Settings.Default.AutoPosScreens.Where(x => x.Enabled).ToList(); if (workingScreens.Count == 0) { return; } workingScreens.Sort((s1, s2) => s1.Order.CompareTo(s2.Order)); var bots = BotSettings.Instance.Bots.Where(x => x.IsEnabled); var sc = 0; // Screen counter var dy = 0; // Diablo Y-Axis counter var dx = 0; // Diablo X-Axis counter // Calculated window height var addy = (Settings.Default.AutoPosDiabloCascade ? 30 : Settings.Default.AutoPosDiabloH); foreach (var bot in bots) { var time = DateTime.Now; var screen = workingScreens[sc]; // set current screen // Calculate demonbuddy position if (!(bot.Demonbuddy.ManualPosSize && !Settings.Default.ForceAutoPos)) { // todo } // Calculate diablo position if (!(bot.Diablo.ManualPosSize && !Settings.Default.ForceAutoPos)) { // Dont mess with IsBoxer if (bot.Diablo.UseIsBoxer) { continue; } var y = (int)(addy * dy); // get next position on Y-Axis of the screen // check if window pos+height does exceed screen working area if ((y + addy) > screen.WorkingArea.Height) { dy = y = 0; // reset counters + Y-Axis position dx++; // move to next X-Axis "line" } var x = (int)(Settings.Default.AutoPosDiabloW * dx); // get next position on X-Axis of the screen // check if window pos+width does exceed screen working area if ((x + Settings.Default.AutoPosDiabloW) > screen.WorkingArea.Width) { if (!Settings.Default.AutoPosForceWorkingArea) { sc++; // Check if screen count is bigger than actual screens available if (sc > workingScreens.Count - 1) { sc = 0; // reset to first screen } } dx = x = 0; // reset counters + X-Axis position dy = y = 0; // reset counters + Y-Axis position } if (bot.Diablo.MainWindowHandle != IntPtr.Zero) { RemoveWindowFrame(bot.Diablo.MainWindowHandle); RepositionWindow(bot.Diablo.MainWindowHandle, x + screen.WorkingArea.X, y + screen.WorkingArea.Y, (int)Settings.Default.AutoPosDiabloW, (int)Settings.Default.AutoPosDiabloH); } dy++; // move to next Y-Axis "line" } // calculate sleeptime var sleep = (int)(Program.Sleeptime - DateTime.Now.Subtract(time).TotalMilliseconds); if (sleep > 0) { Thread.Sleep(sleep); } } } catch (Exception ex) { DebugHelper.Write("Failed", "PositionWindows()"); DebugHelper.Exception(ex); } }
// Dont link this list public static void Create(BotClass bot) { var imp = new Impersonator(); try { if (bot.UseWindowsUser) { imp.Impersonate(bot.WindowsUserName, "localhost", bot.WindowsUserPassword); } bot.Status = "Create Diablo Clone"; string basepath = Path.GetDirectoryName(bot.Diablo.Location); string clonepath = Path.Combine(bot.DiabloCloneLocation, "Diablo III"); // if diablo base path does not exist stop here! if (basepath != null && !Directory.Exists(basepath)) { bot.Stop(); throw new Exception("Diablo base directory does not exist!"); } // Check if given language is installed on basepath string testpath = Path.Combine(basepath, @"Data_D3\PC\MPQs", General.GetLocale(bot.Diablo.Language)); if (!Directory.Exists(testpath)) { bot.Stop(); throw new Exception(string.Format("ERROR: {0} language is not installed (path: {1})", bot.Diablo.Language, testpath)); } // if diablo clone does not exist create it if (!Directory.Exists(Path.Combine(clonepath, @"Data_D3\PC\MPQs\Cache"))) { Logger.Instance.Write(bot, "Creating new Diablo Clone"); Directory.CreateDirectory(Path.Combine(clonepath, @"Data_D3\PC\MPQs\Cache")); } // Create Search caches var baseFileCache = new FileListCache(basepath); var cloneFileCache = new FileListCache(clonepath); // Check if all links are made for our clone foreach (FileListCache.MyFile p in baseFileCache.FileList) { try { if (p.directory && !Directory.Exists(Path.Combine(clonepath.ToLower(), p.Path.ToLower()))) { if (!_noLinks.Any(n => General.WildcardMatch(n.Source, p.Path))) { Logger.Instance.Write(bot, "NewLink: {0} -> {1}", Path.Combine(clonepath, p.Path), Path.Combine(basepath, p.Path)); //if (!CreateSymbolicLink( Path.Combine(clonepath,p.Path), Path.Combine(basepath,p.Path), 1)) // throw new Exception("Failed to create link!"); Directory.CreateDirectory(Path.Combine(clonepath, p.Path)); } continue; } if (!p.directory && !File.Exists(Path.Combine(clonepath.ToLower(), p.Path.ToLower()))) { if (!_noLinks.Any(n => General.WildcardMatch(n.Source, p.Path))) { Logger.Instance.Write(bot, "NewLink: {0} -> {1}", Path.Combine(clonepath, p.Path), Path.Combine(basepath, p.Path)); if (Path.GetExtension(Path.Combine(clonepath, p.Path)).ToLower().Equals(".exe")) { if ( !CreateHardLink(Path.Combine(clonepath, p.Path), Path.Combine(basepath, p.Path), IntPtr.Zero)) { throw new Exception("Failed to create link!"); } } else { if ( !CreateSymbolicLink(Path.Combine(clonepath, p.Path), Path.Combine(basepath, p.Path), 0)) { throw new Exception("Failed to create link!"); } } } } } catch (Exception ex) { Console.WriteLine(ex); } } // Remove links that have no target /* * foreach (var p in cloneFileCache.FileList) * { * try * { * if (p.directory && !Directory.Exists(Path.Combine(basepath, p.Path))) * { * if (!_noLinks.Any(n => General.WildcardMatch(n.Source.ToLower(), p.Path.ToLower()))) * Console.WriteLine("Delete: {0}", p.Path); * continue; * } * * if (!p.directory && !File.Exists(Path.Combine(basepath.ToLower(), p.Path.ToLower()))) * { * if (!_noLinks.Any(n => General.WildcardMatch(n.Source, p.Path))) * Console.WriteLine("Delete: {0}", p.Path); * } * } * catch (Exception ex) * { * Logger.Instance.Write(bot, ex.ToString()); * } * } */ } catch (Exception ex) { bot.Stop(); DebugHelper.Write(bot, "Failed to create clone!"); DebugHelper.Exception(ex); } imp.Dispose(); }