Ejemplo n.º 1
0
        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))
                    {
                        var 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)
            {
                Logger.Instance.WriteGlobal("Error: Failed to update screens: " + ex);
            }
        }
Ejemplo n.º 2
0
        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))
                    {
                        var 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)
            {
                Logger.Instance.WriteGlobal("Error: Failed to update screens: " + ex);
            }
        }
Ejemplo n.º 3
0
        public static void PositionWindows()
        {
            try
            {
                List <ScreensClass> workingScreens = Settings.Default.AutoPosScreens.Where(x => x.Enabled).ToList();
                if (workingScreens.Count == 0)
                {
                    return;
                }
                workingScreens.Sort((s1, s2) => s1.Order.CompareTo(s2.Order));

                IEnumerable <BotClass> bots = BotSettings.Instance.Bots.Where(x => x.IsEnabled);

                int sc = 0; // Screen counter
                int dy = 0; // Diablo Y-Axis counter
                int dx = 0; // Diablo X-Axis counter

                // Calculated window height
                decimal addy = (Settings.Default.AutoPosDiabloCascade ? 30 : Settings.Default.AutoPosDiabloH);

                foreach (BotClass bot in bots)
                {
                    DateTime     time   = DateTime.Now;
                    ScreensClass 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);
            }
        }