public static bool Check(string path) { try { Logger.Instance.Write("Checking plugin: {0}", path); if (File.Exists(path)) { var check = Resources.Plugin.Split('\n')[0].TrimEnd(); using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { var reader = new StreamReader(fs); for (var i = 0; i < 3; i++) { var line = reader.ReadLine(); if (line != null && line.Equals(check)) { Logger.Instance.Write("Plugin is installed and latest version"); return(true); } } } } else { Logger.Instance.Write("Plugin does not exist"); return(false); } } catch (Exception ex) { DebugHelper.Exception(ex); } Logger.Instance.Write("Plugin is outdated!"); return(false); }
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 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.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 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."); } }
private void Send(string msg) { try { _writer.WriteLine(msg); } catch (Exception ex) { StatFailed++; DebugHelper.Exception(ex); } }
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 void HandleXml(string data) { BotStats stats; var xml = new XmlSerializer(typeof(BotStats)); using (var stringReader = new StringReader(data)) { stats = xml.Deserialize(stringReader) as BotStats; } if (stats != null) { try { BotClass bot = BotSettings.Instance.Bots.FirstOrDefault( b => (b != null && b.Demonbuddy != null && b.Demonbuddy.Proc != null) && b.Demonbuddy.Proc.Id == stats.Pid); if (bot != null) { if (bot.AntiIdle.Stats == null) { bot.AntiIdle.Stats = new BotStats(); } bot.AntiIdle.UpdateCoinage(stats.Coinage); bot.AntiIdle.Stats = stats; bot.AntiIdle.LastStats = DateTime.Now; Send(bot.AntiIdle.Reply()); return; } Logger.Instance.WriteGlobal("Could not find a matching bot for Demonbuddy:{0}", stats.Pid); return; } catch (Exception ex) { StatFailed++; Send("Internal server error: " + ex.Message); DebugHelper.Exception(ex); return; } } Send("Roger!"); }
public void Worker() { while (true) { try { var serverStream = new NamedPipeServerStream("YetAnotherRelogger", PipeDirection.InOut, 254); serverStream.WaitForConnection(); var handleClient = new HandleClient(serverStream); new Thread(handleClient.Start).Start(); } catch (Exception ex) { StatFailed++; DebugHelper.Exception(ex); } } }
private void Send(string msg) { try { Debug.WriteLine("Replying: " + msg); msg = msg.Trim(); if (!msg.EndsWith("\n")) { msg += "\n"; } _writer.WriteLine(msg); //_writer.Flush(); } catch (Exception ex) { StatFailed++; 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 void Install(string path) { try { Logger.Instance.Write("Installing latest plugin: {0}", path); if (File.Exists(path)) { File.Delete(path); } else if (!Directory.Exists(Path.GetDirectoryName(path))) { Directory.CreateDirectory(Path.GetDirectoryName(path)); } File.WriteAllText(path, Resources.Plugin); } catch (Exception ex) { DebugHelper.Exception(ex); } }
public static bool Check(string path) { return(false); try { Logger.Instance.Write("Checking plugin: {0}", path); if (File.Exists(path)) { string check = Resources.Plugin.Split('\n')[0].TrimEnd(); // read the first line of Plugin.cs using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { var reader = new StreamReader(fs); for (int i = 0; i < 3; i++) // check the first three lines of installed Plugin.cs { string line = reader.ReadLine(); if (line != null && line.Equals(check)) // line matches resource\Plugin first line { Logger.Instance.Write("Plugin is installed and latest version: {0}", check); return(true); } } } } else { Logger.Instance.Write("Plugin does not exist"); return(false); } } catch (Exception ex) { DebugHelper.Exception(ex); } Logger.Instance.Write("Plugin is outdated!"); return(false); }
public static string GenerateKickstart(Profile profile, bool tmpkickstart = false) { try { string path = Path.Combine(Path.GetDirectoryName(profile.Location), string.Format("YAR{0}_Kickstart.xml", tmpkickstart ? "_TMP" : "")); if (File.Exists(path)) { Logger.Instance.Write("Delete old Kickstart profile: {0}", path); File.Delete(path); } Logger.Instance.Write("Generate new Kickstart profile: {0}", path); string kickstartprofile = YarKickstart; // Replace stuff with current profile kickstartprofile = kickstartprofile.Replace("{profile}", profile.Name); kickstartprofile = kickstartprofile.Replace("{profile_path}", profile.Location); kickstartprofile = kickstartprofile.Replace("{delay}", Settings.Default.KickstartDelay.ToString()); // Get current profile GameParams string gameparams = string.Empty; using (var reader = new StreamReader(profile.Location)) { string line; // Read line for line and match with GameParamsRegex pattern to finde GameParams tag while ((line = reader.ReadLine()) != null) { Match m = new Regex(GameParamsRegex).Match(line); if (m.Success) { gameparams = m.Groups[1].Value; break; } } } // GameParams not found if (gameparams == string.Empty) { Logger.Instance.Write("Failed to get GameParams in profile: ", profile.Location); Logger.Instance.Write("Using the profile without Kickstart!"); return(profile.Location); } // Insert current profile GameParams kickstartprofile = kickstartprofile.Replace("{gameparams}", gameparams); // Write Kickstart file to disk using (var writer = new StreamWriter(path)) { writer.WriteLine(kickstartprofile); } // Return path for kickstart file return(path); } catch (Exception ex) { Logger.Instance.Write("Failed to generate Kickstart profile: {0}", ex.Message); Logger.Instance.Write("Using the profile without Kickstart!"); DebugHelper.Exception(ex); return(profile.Location); } }
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); }
private void HandleMsg(string msg) { // Message Example: // PID:CMD DATA // 1234:GameLeft 25-09-1985 18:27:00 Debug.WriteLine("Recieved: " + msg); try { string pid = msg.Split(':')[0]; string cmd = msg.Substring(pid.Length + 1).Split(' ')[0]; int x; msg = msg.Substring(((x = pid.Length + cmd.Length + 2) >= msg.Length ? 0 : x)); BotClass b = BotSettings.Instance.Bots.FirstOrDefault( f => (f.Demonbuddy != null && f.Demonbuddy.Proc != null) && f.Demonbuddy.Proc.Id == Convert.ToInt32(pid)); if (b == null) { Send("Error: Unknown process"); StatFailed++; return; } switch (cmd) { case "Initialized": b.AntiIdle.Stats = new BotStats { LastGame = DateTime.Now.Ticks, LastPulse = DateTime.Now.Ticks, PluginPulse = DateTime.Now.Ticks, LastRun = DateTime.Now.Ticks }; b.AntiIdle.LastStats = DateTime.Now; b.AntiIdle.State = IdleState.CheckIdle; b.AntiIdle.IsInitialized = true; b.AntiIdle.InitAttempts = 0; Send("Roger!"); break; case "GameLeft": b.ProfileSchedule.Count++; if (b.ProfileSchedule.Current.Runs > 0) { Logger.Instance.Write(b, "Runs completed ({0}/{1})", b.ProfileSchedule.Count, b.ProfileSchedule.MaxRuns); } else { Logger.Instance.Write(b, "Runs completed {0}", b.ProfileSchedule.Count); } if (b.ProfileSchedule.IsDone) { string newprofile = b.ProfileSchedule.GetProfile; Logger.Instance.Write(b, "Next profile: {0}", newprofile); Send("LoadProfile " + newprofile); } else { Send("Roger!"); } break; case "UserStop": b.Status = string.Format("User Stop: {0:d-m H:M:s}", DateTime.Now); b.AntiIdle.State = IdleState.UserStop; Logger.Instance.Write(b, "Demonbuddy stopped by user"); Send("Roger!"); break; case "StartDelay": var delay = new DateTime(long.Parse(msg)); b.AntiIdle.StartDelay = delay.AddSeconds(60); b.AntiIdle.State = IdleState.StartDelay; Send("Roger!"); break; // Giles Compatibility case "ThirdpartyStop": b.Status = string.Format("Thirdparty Stop: {0:d-m H:M:s}", DateTime.Now); b.AntiIdle.State = IdleState.UserStop; Logger.Instance.Write(b, "Demonbuddy stopped by Thirdparty"); Send("Roger!"); break; case "TrinityPause": b.AntiIdle.State = IdleState.UserPause; Logger.Instance.Write(b, "Trinity Pause Detected"); Send("Roger!"); break; case "AllCompiled": { Logger.Instance.Write(b, "Check Force Enable Plugins? {0}", b.Demonbuddy.ForceEnableAllPlugins); Send(b.Demonbuddy.ForceEnableAllPlugins ? "ForceEnableAll" : "ForceEnableYar"); break; } case "CrashTender": if (Settings.Default.UseKickstart && File.Exists(msg)) { b.Demonbuddy.CrashTender(msg); } else { b.Demonbuddy.CrashTender(); } Send("Roger!"); break; case "CheckConnection": ConnectionCheck.CheckValidConnection(true); Send("Roger!"); break; case "NewMonsterPowerLevel": Logger.Instance.Write(b, "Sending MonsterPowerLevel: {0}", b.ProfileSchedule.Current.MonsterPowerLevel); Send("MonsterPower " + (int)b.ProfileSchedule.Current.MonsterPowerLevel); break; case "D3Exit": Send("Shutdown"); break; // Unknown command reply default: Send("Unknown command!"); Logger.Instance.WriteGlobal("Unknown command recieved: " + msg); break; } } catch (Exception ex) { StatFailed++; Send("Internal server error: " + ex.Message); DebugHelper.Exception(ex); } }
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(); }