Beispiel #1
0
        /*
         * Thread hudlessUpdateThread;
         * private bool terminateThread = false;
         *
         * private bool currentlyUpdating = false;
         */

        /// <summary>
        /// Gets an IServiceProvider containing our IGraphicsDeviceService.
        /// This can be used with components such as the ContentManager,
        /// which use this service to look up the GraphicsDevice.
        /// </summary>


        public HUDForm()
        {
            InitializeComponent();


            StartPosition = FormStartPosition.Manual;
            screenWidth   = Screen.GetBounds(this).Width;
            screenHeight  = Screen.GetBounds(this).Height;

            ClientSize = new System.Drawing.Size(screenWidth, screenHeight);


            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;  // no borders

            Left = 0;
            Top  = 0;

            TopMost = true;        // make the form always on top
            Visible = true;        // Important! if this isn't set, then the form is not shown at all

            // Set the form click-through
            int initialStyle = GetWindowLong(this.Handle, -20);

            if (WindowFunctions.isCompositionEnabled())
            {
                SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
            }
            else
            {
                hudDisabled = true;
            }


            inputProcessor = new InputProcessor(GamePad.GetState(0));



            hud              = new HUD(this.Handle);
            hud.screenWidth  = screenWidth;
            hud.screenHeight = screenHeight;



            // Extend aero glass style on form init
            OnResize(null);

            d3bindingsForm = new D3BindingsForm();
            d3bindingsForm.inputProcessor = inputProcessor;


            if (File.Exists(@"D3Bindings.xml"))
            {
                inputProcessor.d3Bindings = LoadD3Bindings();
            }
            else
            {
                SaveD3Bindings(inputProcessor.d3Bindings);
                d3bindingsForm.Show();
            }



            configForm = new ConfigForm();
            configForm.inputProcessor = inputProcessor;

            if (File.Exists(@"Config.xml"))
            {
                inputProcessor.config = LoadConfig();
            }
            else
            {
                SaveConfig(inputProcessor.config);
                configForm.Show();
            }

            inputProcessor.AddConfiguredBindings();

            Hotkey configHotKey = new Hotkey();

            configHotKey.KeyCode  = System.Windows.Forms.Keys.F10;
            configHotKey.Control  = true;
            configHotKey.Pressed += delegate
            {
                if (configForm.Visible)
                {
                    configForm.Visible = false;
                }
                else
                {
                    configForm.Visible = true;
                }
            };

            configHotKey.Register(this);



            Hotkey bindingsHotKey = new Hotkey();

            bindingsHotKey.KeyCode  = System.Windows.Forms.Keys.F11;
            bindingsHotKey.Control  = true;
            bindingsHotKey.Pressed += delegate
            {
                if (d3bindingsForm.Visible)
                {
                    d3bindingsForm.Visible = false;
                }
                else
                {
                    d3bindingsForm.Visible = true;
                }
            };

            bindingsHotKey.Register(this);



            Hotkey quitHotKey = new Hotkey();

            quitHotKey.KeyCode  = System.Windows.Forms.Keys.F12;
            quitHotKey.Control  = true;
            quitHotKey.Pressed += delegate
            {
                this.Close();
            };

            quitHotKey.Register(this);

            oldGamePadState  = GamePad.GetState(0, GamePadDeadZone.Circular);
            oldKeyboardState = Keyboard.GetState();

            if (hudDisabled)
            {
                this.Visible    = false;
                this.ClientSize = new System.Drawing.Size(0, 0);

                //hudlessUpdateThread = new Thread(new ThreadStart(DoUpdate));
                //hudlessUpdateThread.Start();
                //while (!hudlessUpdateThread.IsAlive) ;

                backgroundWorker1.RunWorkerAsync();
            }
        }
Beispiel #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            // Clear device with fully transparent black
            //
            diabloActive = false;
            string foregroundWindowString = WindowFunctions.GetActiveWindowTitle();

            try
            {
                if (foregroundWindowString != null)
                {
                    if (foregroundWindowString.ToUpper() == "DIABLO III")
                    {
                        diabloActive = true;

                        if (!setNonTopmost)
                        {
                            WindowFunctions.DisableTopMost(WindowFunctions.GetForegroundWindowHandle());

                            setNonTopmost = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string crashPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\crash.txt";
                using (StreamWriter outfile = new StreamWriter(crashPath, true))
                {
                    outfile.WriteLine();
                    outfile.WriteLine(DateTime.Now.ToString());
                    outfile.WriteLine(ex.Message);
                    outfile.WriteLine(ex.StackTrace);
                    outfile.WriteLine();
                    outfile.Flush();
                }
                MessageBox.Show("Exception in windowing functions. Written to crash.txt.");
                this.Close();
            }

            try
            {
                hud.Draw(inputProcessor.currentControllerState, diabloActive);
            }
            catch (Exception ex)
            {
                string crashPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\crash.txt";
                using (StreamWriter outfile = new StreamWriter(crashPath, true))
                {
                    outfile.WriteLine();
                    outfile.WriteLine(DateTime.Now.ToString());
                    outfile.WriteLine(ex.Message);
                    outfile.WriteLine(ex.StackTrace);
                    outfile.WriteLine();
                    outfile.Flush();
                }
                MessageBox.Show("Exception in HUD draw. Written to crash.txt.");
                this.Close();
            }

            // Redraw immediatily

            Invalidate();

            try
            {
                if (diabloActive)
                {
                    LogicUpdate();
                }
            }
            catch (Exception ex)
            {
                string crashPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\crash.txt";
                using (StreamWriter outfile = new StreamWriter(crashPath, true))
                {
                    outfile.WriteLine();
                    outfile.WriteLine(DateTime.Now.ToString());
                    outfile.WriteLine(ex.Message);
                    outfile.WriteLine(ex.StackTrace);
                    outfile.WriteLine();
                    outfile.Flush();
                }
                MessageBox.Show("Exception in Logic update. Written to crash.txt.");
                this.Close();
            }

            if (d3bindingsForm.Visible)
            {
                d3bindingsForm.Refresh();
            }

            if (configForm.Visible)
            {
                configForm.Refresh();
            }
        }