Exemple #1
0
 public JoystickCapture(IntPtr handle)
 {
     SlimDX.DirectInput.DirectInput directInput = new SlimDX.DirectInput.DirectInput();
     foreach (DeviceInstance device in (IEnumerable <DeviceInstance>)directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
     {
         try
         {
             this.joystick = new Joystick(directInput, device.InstanceGuid);
             this.joystick.SetCooperativeLevel(handle, CooperativeLevel.Foreground | CooperativeLevel.Exclusive);
             break;
         }
         catch (DirectInputException ex)
         {
         }
     }
     if (this.joystick == null)
     {
         return;
     }
     foreach (DeviceObjectInstance deviceObjectInstance in (IEnumerable <DeviceObjectInstance>) this.joystick.GetObjects())
     {
         if ((deviceObjectInstance.ObjectType & ObjectDeviceType.Axis) != ObjectDeviceType.All)
         {
             this.joystick.GetObjectPropertiesById((int)deviceObjectInstance.ObjectType).SetRange(-1000, 1000);
         }
     }
     this.joystick.Acquire();
 }
Exemple #2
0
        public void TestKeyboard()
        {
            var keyboard = new SlimDXTWKeyboard();
            var dev      = new SlimDX.DirectInput.DirectInput();
            var kb       = new SlimDX.DirectInput.Keyboard(dev);

            kb.Acquire();

            Application.Idle += delegate
            {
                while (true)
                {
                    keyboard.UpdateKeyboardState(kb.GetCurrentState());
                    if (keyboard.IsKeyReleased(SlimDX.DirectInput.Key.Escape))
                    {
                        break;
                    }
                    Application.DoEvents();
                }
                Application.Exit();
            };
            Application.Run();

            kb.Dispose();
            dev.Dispose();
        }
        /// <summary>Creates a new SlimDXInputSystem.</summary>
        /// <param name="control">The control to associate with DirectInput.</param>
        public SlimDXInputSystem(WF.Control control)
        {
            _directInput = new DI.DirectInput();

            InitialiseKeyboard(control);

            InitialiseJoystick();
        }
 public override void Dispose()
 {
     if (mouse != null)
     {
         mouse.Unacquire();
     }
     mouse       = null;
     directInput = null;
 }
 private void CreateNativeKeyboard()
 {
     nativeState    = new DInput.KeyboardState();
     directInput    = new DInput.DirectInput();
     nativeKeyboard = new DInput.Keyboard(directInput);
     nativeKeyboard.SetCooperativeLevel(windowHandle,
                                        DInput.CooperativeLevel.Nonexclusive | DInput.CooperativeLevel.Background);
     nativeKeyboard.Acquire();
 }
 public SlimDXMouse(Window window)
 {
     positionTranslater = new CursorPositionTranslater(window);
     mouseCounter       = new MouseDeviceCounter();
     directInput        = new DInput.DirectInput();
     mouse = new DInput.Mouse(directInput);
     mouse.Properties.AxisMode = DInput.DeviceAxisMode.Absolute;
     mouse.Acquire();
     currentState = new DInput.MouseState();
 }
 public override void Dispose()
 {
     if (nativeKeyboard != null)
     {
         nativeKeyboard.Unacquire();
         nativeKeyboard = null;
     }
     directInput = null;
     IsAvailable = false;
 }
 public static DirectInputDevice Create(SlimDX.DirectInput.DirectInput directInput, DeviceInstance device, int iniId)
 {
     try {
         return(new DirectInputDevice(directInput, device, iniId));
     } catch (DirectInputNotFoundException e) {
         Logging.Warning(e);
         return(null);
     } catch (DirectInputException e) {
         Logging.Error(e);
         return(null);
     }
 }
Exemple #9
0
        public KeyboardCapture(IntPtr handle)
        {
            SlimDX.DirectInput.DirectInput directInput = new SlimDX.DirectInput.DirectInput();
            CooperativeLevel flags = CooperativeLevel.NoWinKey | CooperativeLevel.Foreground | CooperativeLevel.Exclusive;

            try
            {
                this.keyboard = new Keyboard(directInput);
                this.keyboard.SetCooperativeLevel(handle, flags);
            }
            catch (DirectInputException ex)
            {
                int num = (int)MessageBox.Show("DirectInput Error " + ex.Message);
                return;
            }
            this.keyboard.Acquire();
        }
Exemple #10
0
        public TabMateDevice()
        {
            // Find the device
            /// The DirectInput interface
            SlimDX.DirectInput.DirectInput input = new SlimDX.DirectInput.DirectInput();

            /// For every device connected using DirectInput that:
            /// -   is a "game controller"
            /// -   and is connected
            foreach (DeviceInstance device in input.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                /// Get the TabMate from the input interface, and bind its ref via the guid
                tab_mate = new Joystick(input, device.InstanceGuid);
                break;
            }

            event_timer.Elapsed += Event_timer_Elapsed;
            event_timer.Enabled  = true;
            event_timer.Interval = 1;
        }
Exemple #11
0
        public InputCore(IntPtr diMainWindow)
        {
            DIMainWindow = diMainWindow;
            TapTimeout = 500;
            DoubleTapTimeout = 250;
            HoldTimeout = 700;
            MouseUpdateInterval = 16;
            GlobalDeadzone = 0.01;
            AxisPoleSize = 0.8;

            Mouse = new MouseController(this);
            Controllers = new List<InputController>();

            manager = new DI.DirectInput();

            SlimDX.Configuration.ThrowOnError = true;
            SlimDX.Configuration.AddResultWatch(SlimDX.DirectInput.ResultCode.InputLost, SlimDX.ResultWatchFlags.Throw);
            SlimDX.Configuration.AddResultWatch(SlimDX.DirectInput.ResultCode.Unplugged, SlimDX.ResultWatchFlags.Throw);
            SlimDX.Configuration.AddResultWatch(SlimDX.DirectInput.ResultCode.NotAcquired, SlimDX.ResultWatchFlags.Throw);

            Console.WriteLine("Enumerating devices...");
            ScanForControllers();
        }
Exemple #12
0
        public InputCore(IntPtr diMainWindow)
        {
            DIMainWindow        = diMainWindow;
            TapTimeout          = 500;
            DoubleTapTimeout    = 250;
            HoldTimeout         = 700;
            MouseUpdateInterval = 16;
            GlobalDeadzone      = 0.01;
            AxisPoleSize        = 0.8;

            Mouse       = new MouseController(this);
            Controllers = new List <InputController>();

            manager = new DI.DirectInput();

            SlimDX.Configuration.ThrowOnError = true;
            SlimDX.Configuration.AddResultWatch(SlimDX.DirectInput.ResultCode.InputLost, SlimDX.ResultWatchFlags.Throw);
            SlimDX.Configuration.AddResultWatch(SlimDX.DirectInput.ResultCode.Unplugged, SlimDX.ResultWatchFlags.Throw);
            SlimDX.Configuration.AddResultWatch(SlimDX.DirectInput.ResultCode.NotAcquired, SlimDX.ResultWatchFlags.Throw);

            Console.WriteLine("Enumerating devices...");
            ScanForControllers();
        }
        private DirectInputDevice([NotNull] SlimDX.DirectInput.DirectInput directInput, [NotNull] DeviceInstance device, int index)
        {
            Device      = device;
            DisplayName = device.InstanceName;

            Id             = GuidToString(device.ProductGuid);
            Index          = index;
            OriginalIniIds = new List <int>();

            _joystick = new Joystick(directInput, Device.InstanceGuid);

            var window = Application.Current?.MainWindow;

            if (window != null)
            {
                try {
                    _joystick.SetCooperativeLevel(new WindowInteropHelper(window).Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
                    _joystick.Properties.AxisMode = DeviceAxisMode.Absolute;

                    if (!Acquire(_joystick))
                    {
                        _joystick.SetCooperativeLevel(new WindowInteropHelper(window).Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
                        Acquire(_joystick);
                    }
                } catch (Exception e) {
                    Logging.Warning("Can’t set cooperative level: " + e);
                }
            }

            var capabilities = _joystick.Capabilities;

            _buttonsCount = capabilities.ButtonCount;

            Buttons = Enumerable.Range(0, _buttonsCount).Select(x => new DirectInputButton(this, x)).ToArray();
            Axles   = Enumerable.Range(0, 8).Select(x => new DirectInputAxle(this, x)).ToArray();
        }
Exemple #14
0
        public void TestMouse()
        {
            var mouse = new TWMouse();
            var dev   = new SlimDX.DirectInput.DirectInput();
            var m     = new SlimDX.DirectInput.Mouse(dev);

            m.Acquire();

            Application.Idle += delegate
            {
                for (int i = 0; i < 100; i++)
                {
                    var state = m.GetCurrentState();
                    mouse.UpdateMouseState(state);
                    if (state.X != 0)
                    {
                        Console.WriteLine(mouse.RelativeX);
                    }
                    if (mouse.RightMouseJustReleased)
                    {
                        break;
                    }
                    Application.DoEvents();
                }

                mouse.CursorEnabled = true;

                for (int i = 0; i < 100; i++)
                {
                    var state = m.GetCurrentState();
                    mouse.UpdateMouseState(state);
                    if (state.X != 0)
                    {
                        Console.WriteLine(mouse.RelativeX);
                    }
                    if (mouse.RightMouseJustReleased)
                    {
                        break;
                    }
                    Application.DoEvents();
                }

                mouse.CursorEnabled = false;

                for (int i = 0; i < 100; i++)
                {
                    var state = m.GetCurrentState();
                    mouse.UpdateMouseState(state);
                    if (state.X != 0)
                    {
                        Console.WriteLine(mouse.RelativeX);
                    }
                    if (mouse.RightMouseJustReleased)
                    {
                        break;
                    }
                    Application.DoEvents();
                }

                Application.Exit();
            };
            Application.Run();

            m.Dispose();
            dev.Dispose();
        }
Exemple #15
0
        public void TestLineManager3D()
        {
            var keyboard = new SlimDXTWKeyboard();
            var dev      = new SlimDX.DirectInput.DirectInput();
            var kb       = new SlimDX.DirectInput.Keyboard(dev);

            kb.Acquire();

            var mouse = new TWMouse();
            var m     = new SlimDX.DirectInput.Mouse(dev);

            m.Acquire();



            var game = new DX11Form();

            game.InitDirectX();
            var device = game.Device;

            var rasterizerState = RasterizerState.FromDescription(device, new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid
            });

            device.ImmediateContext.Rasterizer.State = rasterizerState;


            var cam = new SpectaterCamera();

            var lineManager = new LineManager3D(device);

            game.GameLoopEvent += delegate
            {
                mouse.UpdateMouseState(m.GetCurrentState());
                keyboard.UpdateKeyboardState(kb.GetCurrentState());
                cam.Update(0.001f, keyboard, mouse);

                for (int num = 0; num < 200; num++)
                {
                    lineManager.AddLine(
                        new Vector3(-12.0f + num / 4.0f, 13.0f, 0),
                        new Vector3(-17.0f + num / 4.0f, -13.0f, 0),
                        new Color4((byte)(255 - num) / 255f, 14 / 255f, (byte)num / 255f));
                } // for

                lineManager.DrawGroundShadows = true;
                lineManager.AddCenteredBox(new Vector3(4, 4, 4), 2, new Color4(1, 0, 0));

                lineManager.WorldMatrix =
                    Matrix.Translation(MathHelper.Up * 30);

                for (int num = 0; num < 200; num++)
                {
                    lineManager.AddLine(
                        new Vector3(-12.0f + num / 4.0f, 13.0f, 0),
                        new Vector3(-17.0f + num / 4.0f, -13.0f, 0),
                        new Color4((byte)(255 - num) / 255f, 14 / 255f, (byte)num / 255f));
                } // for



                lineManager.Render(cam);
                if (keyboard.IsKeyDown(Key.Escape))
                {
                    game.Exit();
                }
            };

            game.Run();

            rasterizerState.Dispose();
            kb.Dispose();
            m.Dispose();
            dev.Dispose();
        }
Exemple #16
0
        public void TestDirectX11SpecaterCamera()
        {
            var keyboard = new SlimDXTWKeyboard();
            var dev      = new SlimDX.DirectInput.DirectInput();
            var kb       = new SlimDX.DirectInput.Keyboard(dev);

            kb.Acquire();

            var mouse = new TWMouse();
            var m     = new SlimDX.DirectInput.Mouse(dev);

            m.Acquire();



            var game = new DX11Form();

            game.InitDirectX();
            var device    = game.Device;
            var bytecode  = ShaderBytecode.CompileFromFile("../../Common.Core/Shaders/MiniTri.fx", "fx_5_0", ShaderFlags.None, EffectFlags.None);
            var effect    = new Effect(device, bytecode);
            var technique = effect.GetTechniqueByName("RenderTransform");
            var pass      = technique.GetPassByIndex(0);
            var layout    = new InputLayout(device, pass.Description.Signature,
                                            new[] {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 32, 0)
            });

            var vertexStride = (16 + 16 + 8);
            var stream       = new DataStream(3 * vertexStride, true, true);

            stream.WriteRange(new[] {
                new VertexCustom(new Vector4(-1.0f, 0, 0, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector2(0.5f, 0)),
                new VertexCustom(new Vector4(0f, 1f, 0, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector2(0f, 1f)),
                new VertexCustom(new Vector4(1f, 0f, 0, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), new Vector2(1f, 1f))
            });
            stream.Position = 0;



            var vertices = new SlimDX.Direct3D11.Buffer(device, stream, new BufferDescription()
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,
                SizeInBytes    = 3 * vertexStride,
                Usage          = ResourceUsage.Default
            });

            stream.Dispose();

            //var world = Matrix.Translation(MathHelper.Forward);

            /*var viewProjection = Matrix.LookAtRH(Vector3.UnitZ * 5, -Vector3.UnitZ, MathHelper.Up)
             * Matrix.PerspectiveFovRH(MathHelper.PiOver4, 4f / 3f, 0.1f, 1000f);*/


            var diffuseShaderVariable = effect.GetVariableByName("txDiffuse").AsResource();
            var worldParam            = effect.GetVariableByName("world").AsMatrix();
            //worldParam.AsMatrix().SetMatrix(world);


            var viewProjParam = effect.GetVariableBySemantic("viewprojection").AsMatrix();

            /*viewProjParam.SetMatrix(
             *  viewProjection);*/

            //worldParam.SetMatrix(Matrix.Identity);
            //effect.GetVariableBySemantic("viewprojection").AsMatrix().SetMatrix(Matrix.Identity);

            var texturePath = Wallpaper001_png;

            var diffuseTexture = Texture2D.FromFile(device, texturePath);

            var diffuseTextureRv = new ShaderResourceView(device, diffuseTexture);


            diffuseShaderVariable.SetResource(diffuseTextureRv);


            var rasterizerState = RasterizerState.FromDescription(device, new RasterizerStateDescription()
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid
            });

            device.ImmediateContext.Rasterizer.State = rasterizerState;


            var cam = new SpectaterCamera();

            game.GameLoopEvent += delegate
            {
                mouse.UpdateMouseState(m.GetCurrentState());
                keyboard.UpdateKeyboardState(kb.GetCurrentState());
                cam.Update(0.001f, keyboard, mouse);

                device.ImmediateContext.InputAssembler.InputLayout       = layout;
                device.ImmediateContext.InputAssembler.PrimitiveTopology =
                    PrimitiveTopology.TriangleList;
                device.ImmediateContext.InputAssembler.SetVertexBuffers(0,
                                                                        new VertexBufferBinding
                                                                            (vertices,
                                                                            vertexStride, 0));

                for (int i = 0; i < technique.Description.PassCount; ++i)
                {
                    pass.Apply(device.ImmediateContext);
                    device.ImmediateContext.Draw(3, 0);
                }

                viewProjParam.SetMatrix(cam.ViewProjection);
                worldParam.SetMatrix(Matrix.Identity);
                if (keyboard.IsKeyDown(Key.Escape))
                {
                    game.Exit();
                }
            };

            game.Run();

            bytecode.Dispose();
            effect.Dispose();
            layout.Dispose();
            vertices.Dispose();
            diffuseTexture.Dispose();
            diffuseTextureRv.Dispose();
            rasterizerState.Dispose();
            kb.Dispose();
            m.Dispose();
            dev.Dispose();
        }
Exemple #17
0
        private void Window_Main_Load(object sender, EventArgs e)
        {
            if (!SupportedProcessVersion())
            {
                this.Text = "You are running a not supported D3Client(" + GetFileVersion() +
                            ") Supported Version is " + SupportedVersion;

                return;
            }

            typeof(Button).InvokeMember("DoubleBuffered",
    BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
    null, bt_Skill1, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
    BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
    null, bt_Skill2, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
    BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
    null, bt_Skill3, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
    BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
    null, bt_Skill4, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
    BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
    null, bt_SkillLmb, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
    BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
    null, bt_SkillRmb, new object[] { true });

            A_WPFOverlay.Overlay o = new A_WPFOverlay.Overlay();
            o.Show();

            directInput = new DirectInput();
            keyboard = new SlimDX.DirectInput.Keyboard(directInput);
            keyboard.Acquire();
           
           
            Point d3helpermainwindowpos = Properties.Settings.Default.D3Helper_MainForm_StartPosition;
            var screens = Screen.AllScreens.OrderByDescending(x => x.Bounds.X);

            if (d3helpermainwindowpos.X >= screens.Last().Bounds.Left && d3helpermainwindowpos.X <= screens.First().Bounds.Right && d3helpermainwindowpos.Y <= screens.First().Bounds.Bottom && d3helpermainwindowpos.Y >= screens.First().Bounds.Top)
            {
                this.Top = Properties.Settings.Default.D3Helper_MainForm_StartPosition.Y;
                this.Left = Properties.Settings.Default.D3Helper_MainForm_StartPosition.X;
            }
            else
            {
                this.Top = 0;
                this.Left = 0;
            }




            this.btn_donate.Image = new Bitmap(Properties.Resources.paypal_donate_button11, new Size(this.btn_donate.Width, this.btn_donate.Height));
            
            this.btn_info.Image = new Bitmap(Properties.Resources._480px_Info_icon_002_svg, new Size(this.btn_info.Width, this.btn_info.Height));
            this.btn_settings.Image = new Bitmap(Properties.Resources.pignon, new Size(this.btn_settings.Width, this.btn_settings.Height));
            

            this.bt_update.Visible = false;

            this.Text = "D3Helper - V" + A_Tools.Version.AppVersion.version;
            

            DateTime latestOnlineVersion = A_Tools.Version.AppVersion.LatestOnlineVersion;
            DateTime currentVersion = A_Tools.Version.AppVersion.get_CurrentVersionDate();

            if (latestOnlineVersion > currentVersion)
            {
                this.lb_versionlb.Text = "New Version Available!" + System.Environment.NewLine + latestOnlineVersion.ToString("yy.MM.d.H");
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = "New Version Available!"));
                this.bt_update.Visible = true;
            }
            else
            {
                this.lb_versionlb.Text = "";
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = ""));
            }


        }
Exemple #18
0
        private void Window_Main_Load(object sender, EventArgs e)
        {
            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill1, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill2, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill3, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill4, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_SkillLmb, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_SkillRmb, new object[] { true });


            directInput = new DirectInput();
            keyboard    = new SlimDX.DirectInput.Keyboard(directInput);
            keyboard.Acquire();

            mouse = new SlimDX.DirectInput.Mouse(directInput);
            mouse.Acquire();


            Point d3helpermainwindowpos = Properties.Settings.Default.D3Helper_MainForm_StartPosition;
            var   screens = Screen.AllScreens.OrderByDescending(x => x.Bounds.X);

            if (d3helpermainwindowpos.X >= screens.Last().Bounds.Left&& d3helpermainwindowpos.X <= screens.First().Bounds.Right&& d3helpermainwindowpos.Y <= screens.First().Bounds.Bottom&& d3helpermainwindowpos.Y >= screens.First().Bounds.Top)
            {
                this.Top  = Properties.Settings.Default.D3Helper_MainForm_StartPosition.Y;
                this.Left = Properties.Settings.Default.D3Helper_MainForm_StartPosition.X;
            }
            else
            {
                this.Top  = 0;
                this.Left = 0;
            }


            //this.btn_donate.Image = new Bitmap(Properties.Resources.paypal_donate_button11, new Size(this.btn_donate.Width, this.btn_donate.Height));

            this.btn_info.Image     = new Bitmap(Properties.Resources._480px_Info_icon_002_svg, new Size(this.btn_info.Width, this.btn_info.Height));
            this.btn_settings.Image = new Bitmap(Properties.Resources.pignon, new Size(this.btn_settings.Width, this.btn_settings.Height));



            DateTime latestOnlineVersion = A_Tools.Version.AppVersion.LatestOnlineVersion;
            DateTime currentVersion      = A_Tools.Version.AppVersion.get_CurrentVersionDate();

            if (latestOnlineVersion > currentVersion)
            {
                this.lb_versionlb.Text = "New Version Available!" + System.Environment.NewLine + latestOnlineVersion.ToString("yy.MM.d.H");
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = "New Version Available!"));
                this.bt_update.Visible = true;
            }
            else
            {
                this.lb_versionlb.Text = "";
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = ""));
            }

            this.Text = "D3Helper - V" + A_Tools.Version.AppVersion.version;



            //create thread waiting for d3 start!
            Thread t = new Thread(delegate()
            {
                //wait till d3 is running
                while (!isDiabloRunning())
                {
                    try
                    {
                        Thread.Sleep(1000);
                    }
                    catch { }
                }

                if (SupportedProcessVersion())
                {
                    //-- Initialize Collector and Handler Thread
                    if (!Program.SingleThreaded)
                    {
                        A_Initialize.Th_ICollector.New_ICollector();
                    }
                    A_Initialize.Th_Handler.New_Handler();
                    //
                    if (A_Tools.Version.AppVersion.isOutdated()) // !!!!! REENABLE THIS!!!!!!
                    {
                        Window_Outdated WO = new Window_Outdated();
                        WO.ShowDialog();
                    }

                    System.Timers.Timer UpdateUI = new System.Timers.Timer(1000);
                    UpdateUI.Elapsed            += RefreshUI;
                    UpdateUI.Start();

                    Load_CustomFonts();
                }
                else
                {
                    this.Text = "You are running a not supported D3Client(" + GetFileVersion() +
                                ") Supported Version is " + SupportedVersion;
                }
            });

            t.SetApartmentState(ApartmentState.STA); //must be STA Thread to access GUI
            t.Start();



            //overlay
            if (SupportedProcessVersion())
            {
                A_WPFOverlay.Overlay o = new A_WPFOverlay.Overlay();
                o.Show();
            }
        }
Exemple #19
0
        private void Window_Main_Load(object sender, EventArgs e)
        {
            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill1, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill2, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill3, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill4, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_SkillLmb, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_SkillRmb, new object[] { true });


            directInput = new DirectInput();
            keyboard    = new SlimDX.DirectInput.Keyboard(directInput);
            keyboard.Acquire();

            mouse = new SlimDX.DirectInput.Mouse(directInput);
            mouse.Acquire();


            Point d3helpermainwindowpos = Properties.Settings.Default.D3Helper_MainForm_StartPosition;
            var   screens = Screen.AllScreens.OrderByDescending(x => x.Bounds.X);

            if (d3helpermainwindowpos.X >= screens.Last().Bounds.Left&& d3helpermainwindowpos.X <= screens.First().Bounds.Right&& d3helpermainwindowpos.Y <= screens.First().Bounds.Bottom&& d3helpermainwindowpos.Y >= screens.First().Bounds.Top)
            {
                this.Top  = Properties.Settings.Default.D3Helper_MainForm_StartPosition.Y;
                this.Left = Properties.Settings.Default.D3Helper_MainForm_StartPosition.X;
            }
            else
            {
                this.Top  = 0;
                this.Left = 0;
            }


            //this.btn_donate.Image = new Bitmap(Properties.Resources.paypal_donate_button11, new Size(this.btn_donate.Width, this.btn_donate.Height));

            this.btn_info.Image     = new Bitmap(Properties.Resources._480px_Info_icon_002_svg, new Size(this.btn_info.Width, this.btn_info.Height));
            this.btn_settings.Image = new Bitmap(Properties.Resources.pignon, new Size(this.btn_settings.Width, this.btn_settings.Height));



            DateTime latestOnlineVersion = A_Tools.Version.AppVersion.LatestOnlineVersion;
            DateTime currentVersion      = A_Tools.Version.AppVersion.get_CurrentVersionDate();

            if (latestOnlineVersion > currentVersion)
            {
                this.lb_versionlb.Text = "New Version Available!" + System.Environment.NewLine + latestOnlineVersion.ToString("yy.MM.d.H");
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = "New Version Available!"));
                this.bt_update.Visible = true;
            }
            else
            {
                this.lb_versionlb.Text = "";
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = ""));
            }

            this.Text = "D3Helper - V" + A_Tools.Version.AppVersion.version;



            //Use SimpleCast!
            T_SimpleCast.StartSimpleCastThread();

            //fill combobox for simple cast
            loadSimeCastListToCombobox();



            //create thread waiting for d3 start!
            Thread t = new Thread(delegate()
            {
                //wait till d3 is running
                while (!isDiabloRunning())
                {
                    try
                    {
                        Thread.Sleep(1000);
                    }
                    catch { }
                }

                if (SupportedProcessVersion())
                {
                    //-- Initialize Collector and Handler Thread
                    //if (!Program.SingleThreaded)
                    A_Initialize.Th_ICollector.New_ICollector();
                    A_Initialize.Th_Handler.New_Handler();


                    System.Timers.Timer UpdateUI = new System.Timers.Timer(1000);
                    UpdateUI.Elapsed            += RefreshUI;
                    UpdateUI.Start();

                    Load_CustomFonts();
                }
                else
                {
                    this.Text = "You are running a not supported D3Client(" + GetFileVersion() +
                                ") Supported Version is " + SupportedVersion;
                }
            });

            t.SetApartmentState(ApartmentState.STA); //must be STA Thread to access GUI
            t.Start();



            //overlay
            if (SupportedProcessVersion())
            {
                A_WPFOverlay.Overlay o = new A_WPFOverlay.Overlay();
                o.Show();
            }

            Me.Threads.AntiIdleThread = new Thread(() =>
            {
                AntiIdle antiIdle = new AntiIdle();
            });
            if (Properties.Settings.Default.AntiIdleBool)
            {
                Me.Threads.AntiIdleThread.Start();
            }

            try
            {
                if (Me.Threads.RosBotUpgradeKadalaThread.ThreadState == System.Threading.ThreadState.Unstarted)
                {
                    Me.Threads.RosBotUpgradeKadalaThread = new Thread(() =>
                    {
                        RosBotUpgradeKadala rosBotUpgradeKadala = new RosBotUpgradeKadala();
                    });
                    if (Properties.Settings.Default.RosBotUpgradeKadalaBool)
                    {
                        Me.Threads.RosBotUpgradeKadalaThread.Start();
                    }
                }
            }
            catch
            {
                Me.Threads.RosBotUpgradeKadalaThread = new Thread(() =>
                {
                    RosBotUpgradeKadala rosBotUpgradeKadala = new RosBotUpgradeKadala();
                });
                if (Properties.Settings.Default.RosBotUpgradeKadalaBool)
                {
                    Me.Threads.RosBotUpgradeKadalaThread.Start();
                }
            }

            Me.Threads.HomingPadsThread = new Thread(() =>
            {
                HomingPadsHandler homingPadsHandler = new HomingPadsHandler();
            });
            // Probably best to not start this thread unless user has it turned on in settings
            // Will require a restart of D3helper any time it's turned on/off though
            if (Properties.Settings.Default.HomingPadsBool)
            {
                Me.Threads.HomingPadsThread.Start();
            }
        }
Exemple #20
0
        private void Window_Main_Load(object sender, EventArgs e)
        {
            if (!SupportedProcessVersion())
            {
                this.Text = "You are running a not supported D3Client(" + GetFileVersion().ToString() +
                            ") Supported Version is " + SupportedVersion;

                return;
            }

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill1, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill2, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill3, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_Skill4, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_SkillLmb, new object[] { true });

            typeof(Button).InvokeMember("DoubleBuffered",
                                        BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic,
                                        null, bt_SkillRmb, new object[] { true });

            A_WPFOverlay.Overlay o = new A_WPFOverlay.Overlay();
            o.Show();

            directInput = new DirectInput();
            keyboard    = new SlimDX.DirectInput.Keyboard(directInput);
            keyboard.Acquire();


            Point d3helpermainwindowpos = Properties.Settings.Default.D3Helper_MainForm_StartPosition;
            var   screens = Screen.AllScreens.OrderByDescending(x => x.Bounds.X);

            if (d3helpermainwindowpos.X >= screens.Last().Bounds.Left&& d3helpermainwindowpos.X <= screens.First().Bounds.Right&& d3helpermainwindowpos.Y <= screens.First().Bounds.Bottom&& d3helpermainwindowpos.Y >= screens.First().Bounds.Top)
            {
                this.Top  = Properties.Settings.Default.D3Helper_MainForm_StartPosition.Y;
                this.Left = Properties.Settings.Default.D3Helper_MainForm_StartPosition.X;
            }
            else
            {
                this.Top  = 0;
                this.Left = 0;
            }



            this.btn_donate.Image = new Bitmap(Properties.Resources.paypal_donate_button11, new Size(this.btn_donate.Width, this.btn_donate.Height));

            this.btn_info.Image     = new Bitmap(Properties.Resources._480px_Info_icon_002_svg, new Size(this.btn_info.Width, this.btn_info.Height));
            this.btn_settings.Image = new Bitmap(Properties.Resources.pignon, new Size(this.btn_settings.Width, this.btn_settings.Height));


            this.bt_update.Visible = false;

            this.Text = "D3Helper - V" + A_Tools.Version.AppVersion.version;


            DateTime latestOnlineVersion = A_Tools.Version.AppVersion.LatestOnlineVersion;
            DateTime currentVersion      = A_Tools.Version.AppVersion.get_CurrentVersionDate();

            if (latestOnlineVersion > currentVersion)
            {
                this.lb_versionlb.Text = "New Version Available!" + System.Environment.NewLine + latestOnlineVersion.ToString("yy.MM.d.H");
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = "New Version Available!"));
                this.bt_update.Visible = true;
            }
            else
            {
                this.lb_versionlb.Text = "";
                //this.lb_versionlb.Invoke((MethodInvoker)(() => this.lb_versionlb.Text = ""));
            }
        }
        /// <summary>Disposes resources.</summary>
        public override void Dispose()
        {
            if(_keyboard != null)
            {
                try { _keyboard.Unacquire(); }
                catch { }

                try { _keyboard.Dispose(); }
                catch { _keyboard = null; }
            }

            if(_joystick != null)
            {
                try { _joystick.Unacquire(); }
                catch { }

                try { _joystick.Dispose(); }
                catch { }
            }

            if(_directInput != null)
            {
                try { _directInput.Dispose(); }
                catch { }
                _directInput = null;
            }
        }
Exemple #22
0
        private static void Scan()
        {
            _directInput = new SlimDX.DirectInput.DirectInput();

            try {
                while (_isActive)
                {
                    var getDevices = Stopwatch.StartNew();

                    IList <Joystick> list;
                    string           footprint;
                    bool             updated;

                    if (_directInput == null)
                    {
                        list      = new List <Joystick>(0);
                        footprint = string.Empty;
                        updated   = _staticDataFootprint != footprint;
                    }
                    else
                    {
                        try {
                            var devices = _directInput?.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
                            footprint = devices?.Select(x => x.InstanceGuid).JoinToString(';');
                            updated   = _staticDataFootprint != footprint;
                            list      = updated ? devices?.Select(x => {
                                var existing = _staticData?.FirstOrDefault(y =>
                                                                           y.Information.InstanceGuid == x.InstanceGuid);
                                if (existing != null)
                                {
                                    return(existing);
                                }

                                var result = new Joystick(_directInput, x.InstanceGuid);
                                if (result.Capabilities == null)
                                {
                                    // We don’t really need a check here, but we need to access .Capabilities here, in a background
                                    // thread, because it might take a while to get the data which will be needed later.
                                    throw new Exception("Never happens");
                                }

                                return(result);
                            }).ToArray() : _staticData;
                        } catch (Exception e) {
                            // TODO: Try to re-initiate scanning later?
                            Logging.Error(e);
                            list      = new List <Joystick>(0);
                            footprint = string.Empty;
                            updated   = _staticDataFootprint != footprint;
                            DisposeHelper.Dispose(ref _directInput);
                        }
                    }

                    getDevices.Stop();
                    _scanTime = getDevices.Elapsed;

                    if (updated)
                    {
                        _staticData?.ApartFrom(list).DisposeEverything();
                        _staticDataFootprint = footprint;
                        _staticData          = list;
                        lock (Instances) {
                            for (var i = Instances.Count - 1; i >= 0; i--)
                            {
                                Instances[i].RaiseUpdate(list);
                            }
                        }
                    }
                    else
                    {
                        UpdateScanTime();
                    }

                    Thread.Sleep(OptionMinRescanPeriod + getDevices.Elapsed);

                    int count;
                    lock (Instances) {
                        count = Instances.Count;
                    }

                    if (count == 0)
                    {
                        lock (ThreadSync) {
                            Monitor.Wait(ThreadSync);
                        }
                    }
                }
            } finally {
                DisposeHelper.Dispose(ref _directInput);
            }
        }
Exemple #23
0
        private void RescanDevices()
        {
            IList <DeviceInstance> devices;

            try {
                if (_directInput == null)
                {
                    _directInput = new SlimDX.DirectInput.DirectInput();
                }

                devices = _directInput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly);
            } catch (Exception e) {
                Logging.Error(e);
                devices = new List <DeviceInstance>();
                DisposeHelper.Dispose(ref _directInput);
            }

            if (OptionIgnoreControlsFilter != null)
            {
                devices = devices.Where(x => OptionIgnoreControlsFilter.Test(x.ProductName)).ToList();
            }

            var footprint = GetFootprint(devices);

            if (footprint == _devicesFootprint)
            {
                return;
            }

            _skip = true;

            try {
                var newDevices = devices.Select((x, i) => Devices.FirstOrDefault(y => y.Same(x)) ??
                                                DirectInputDevice.Create(_directInput, x, i)).NonNull().ToList();
                _devicesFootprint = GetFootprint(newDevices.Select(x => x.Device));

                foreach (var entry in Entries.OfType <BaseEntry <DirectInputAxle> >())
                {
                    var current = entry.Input?.Device;
                    if (current is PlaceholderInputDevice)
                    {
                        var replacement = newDevices.FirstOrDefault(x => x.Same(current));
                        if (replacement != null)
                        {
                            entry.Input = replacement.GetAxle(entry.Input.Id);
                        }
                    }
                    else if (current is DirectInputDevice && !newDevices.Contains(current))
                    {
                        entry.Input = GetPlaceholderDevice((DirectInputDevice)current).GetAxle(entry.Input.Id);
                    }
                }

                foreach (var entry in Entries.OfType <BaseEntry <DirectInputButton> >())
                {
                    var current = entry.Input?.Device;
                    if (current is PlaceholderInputDevice)
                    {
                        var replacement = newDevices.FirstOrDefault(x => x.Same(current));
                        if (replacement != null)
                        {
                            entry.Input = replacement.GetButton(entry.Input.Id);
                        }
                    }
                    else if (current is DirectInputDevice && !newDevices.Contains(current))
                    {
                        entry.Input = GetPlaceholderDevice((DirectInputDevice)current).GetButton(entry.Input.Id);
                    }
                }

                foreach (var device in Devices.ApartFrom(newDevices))
                {
                    for (var i = 0; i < device.Buttons.Length; i++)
                    {
                        device.Buttons[i].PropertyChanged -= DeviceButtonEventHandler;
                    }

                    for (var i = 0; i < device.Axles.Length; i++)
                    {
                        device.Axles[i].PropertyChanged -= DeviceAxleEventHandler;
                    }

                    device.Dispose();
                }

                Devices.ReplaceEverythingBy(newDevices);
                UpdatePlaceholders();

                foreach (var device in newDevices)
                {
                    ProductGuids[device.DisplayName] = device.Id;

                    for (var i = 0; i < device.Buttons.Length; i++)
                    {
                        device.Buttons[i].PropertyChanged += DeviceButtonEventHandler;
                    }

                    for (var i = 0; i < device.Axles.Length; i++)
                    {
                        device.Axles[i].PropertyChanged += DeviceAxleEventHandler;
                    }
                }
            } finally {
                _skip = false;
                UpdateWheelHShifterDevice();
            }
        }