Esempio n. 1
0
		public static void Initialize()
		{
			IsAvailable = false;
			try
			{
				//some users wont even have xinput installed. in order to avoid spurious exceptions and possible instability, check for the library first
				IntPtr lib = Win32.LoadLibrary("xinput1_3.dll");
				if (lib != IntPtr.Zero)
				{
					Win32.FreeLibrary(lib);
					
					//don't remove this code. it's important to catch errors on systems with broken xinput installs.
					//(probably, checking for the library was adequate, but lets not get rid of this anyway)
					var test = new SlimDX.XInput.Controller(UserIndex.One).IsConnected;
					IsAvailable = true;
				}
			}
			catch { }

			if (!IsAvailable) return;

			var c1 = new Controller(UserIndex.One);
			var c2 = new Controller(UserIndex.Two);
			var c3 = new Controller(UserIndex.Three);
			var c4 = new Controller(UserIndex.Four);

			if (c1.IsConnected) Devices.Add(new GamePad360(c1));
			if (c2.IsConnected) Devices.Add(new GamePad360(c2));
			if (c3.IsConnected) Devices.Add(new GamePad360(c3));
			if (c4.IsConnected) Devices.Add(new GamePad360(c4));
		}
Esempio n. 2
0
        static GamePad360()
        {
            try
            {
                //some users wont even have xinput installed. in order to avoid spurious exceptions and possible instability, check for the library first
                HasGetInputStateEx = true;
                LibraryHandle      = Win32.LoadLibrary("xinput1_3.dll");
                if (LibraryHandle == IntPtr.Zero)
                {
                    LibraryHandle = Win32.LoadLibrary("xinput1_4.dll");
                }
                if (LibraryHandle == IntPtr.Zero)
                {
                    LibraryHandle      = Win32.LoadLibrary("xinput9_1_0.dll");
                    HasGetInputStateEx = false;
                }

                if (LibraryHandle != IntPtr.Zero)
                {
                    if (HasGetInputStateEx)
                    {
                        IntPtr proc = GetProcAddressOrdinal(LibraryHandle, new IntPtr(100));
                        XInputGetStateExProc = (XInputGetStateExProcDelegate)Marshal.GetDelegateForFunctionPointer(proc, typeof(XInputGetStateExProcDelegate));
                    }

                    //don't remove this code. it's important to catch errors on systems with broken xinput installs.
                    //(probably, checking for the library was adequate, but lets not get rid of this anyway)
                    var test = new SlimDX.XInput.Controller(UserIndex.One).IsConnected;
                    _isAvailable = true;
                }
            }
            catch { }
        }
Esempio n. 3
0
		public static void Initialize()
		{
			IsAvailable = false;
			try
			{
				//some users wont even have xinput installed. in order to avoid spurious exceptions and possible instability, check for the library first
				HasGetInputStateEx = true;
				LibraryHandle = Win32.LoadLibrary("xinput1_3.dll");
				if(LibraryHandle == IntPtr.Zero)
					LibraryHandle = Win32.LoadLibrary("xinput1_4.dll");
				if(LibraryHandle == IntPtr.Zero)
				{
					LibraryHandle = Win32.LoadLibrary("xinput9_1_0.dll");
					HasGetInputStateEx = false;
				}

				if (LibraryHandle != IntPtr.Zero)
				{
					if (HasGetInputStateEx)
					{
						IntPtr proc = GetProcAddressOrdinal(LibraryHandle, new IntPtr(100));
						XInputGetStateExProc = (XInputGetStateExProcDelegate)Marshal.GetDelegateForFunctionPointer(proc, typeof(XInputGetStateExProcDelegate));
					}

					//don't remove this code. it's important to catch errors on systems with broken xinput installs.
					//(probably, checking for the library was adequate, but lets not get rid of this anyway)
					var test = new SlimDX.XInput.Controller(UserIndex.One).IsConnected;
					IsAvailable = true;
				}

			}
			catch { }

			if (!IsAvailable) return;

			//now, at this point, slimdx may be using one xinput, and we may be using another
			//i'm not sure how slimdx picks its dll to bind to.
			//i'm not sure how troublesome this will be
			//maybe we should get rid of slimdx for this altogether

			var c1 = new Controller(UserIndex.One);
			var c2 = new Controller(UserIndex.Two);
			var c3 = new Controller(UserIndex.Three);
			var c4 = new Controller(UserIndex.Four);

			if (c1.IsConnected) Devices.Add(new GamePad360(c1));
			if (c2.IsConnected) Devices.Add(new GamePad360(c2));
			if (c3.IsConnected) Devices.Add(new GamePad360(c3));
			if (c4.IsConnected) Devices.Add(new GamePad360(c4));
		}
Esempio n. 4
0
		public static void Initialize()
		{
			IsAvailable = false;
			try
			{
				//some users wont even have xinput installed. in order to avoid spurious exceptions and possible instability, check for the library first
				HasGetInputStateEx = true;
				LibraryHandle = Win32.LoadLibrary("xinput1_3.dll");
				if(LibraryHandle == IntPtr.Zero)
					LibraryHandle = Win32.LoadLibrary("xinput1_4.dll");
				if(LibraryHandle == IntPtr.Zero)
				{
					LibraryHandle = Win32.LoadLibrary("xinput9_1_0.dll");
					HasGetInputStateEx = false;
				}

				if (LibraryHandle != IntPtr.Zero)
				{
					if (HasGetInputStateEx)
					{
						IntPtr proc = GetProcAddressOrdinal(LibraryHandle, new IntPtr(100));
						XInputGetStateExProc = (XInputGetStateExProcDelegate)Marshal.GetDelegateForFunctionPointer(proc, typeof(XInputGetStateExProcDelegate));
					}

					//don't remove this code. it's important to catch errors on systems with broken xinput installs.
					//(probably, checking for the library was adequate, but lets not get rid of this anyway)
					var test = new SlimDX.XInput.Controller(UserIndex.One).IsConnected;
					IsAvailable = true;
				}

			}
			catch { }

			if (!IsAvailable) return;

			//now, at this point, slimdx may be using one xinput, and we may be using another
			//i'm not sure how slimdx picks its dll to bind to.
			//i'm not sure how troublesome this will be
			//maybe we should get rid of slimdx for this altogether

			var c1 = new Controller(UserIndex.One);
			var c2 = new Controller(UserIndex.Two);
			var c3 = new Controller(UserIndex.Three);
			var c4 = new Controller(UserIndex.Four);

			if (c1.IsConnected) Devices.Add(new GamePad360(c1));
			if (c2.IsConnected) Devices.Add(new GamePad360(c2));
			if (c3.IsConnected) Devices.Add(new GamePad360(c3));
			if (c4.IsConnected) Devices.Add(new GamePad360(c4));
		}
Esempio n. 5
0
        public static void Initialize()
        {
            IsAvailable = false;
            try
            {
                //some users wont even have xinput installed. in order to avoid spurious exceptions and possible instability, check for the library first
                IntPtr lib = Win32.LoadLibrary("xinput1_3.dll");
                if (lib != IntPtr.Zero)
                {
                    Win32.FreeLibrary(lib);

                    //don't remove this code. it's important to catch errors on systems with broken xinput installs.
                    //(probably, checking for the library was adequate, but lets not get rid of this anyway)
                    var test = new SlimDX.XInput.Controller(UserIndex.One).IsConnected;
                    IsAvailable = true;
                }
            }
            catch { }

            if (!IsAvailable)
            {
                return;
            }

            var c1 = new Controller(UserIndex.One);
            var c2 = new Controller(UserIndex.Two);
            var c3 = new Controller(UserIndex.Three);
            var c4 = new Controller(UserIndex.Four);

            if (c1.IsConnected)
            {
                Devices.Add(new GamePad360(c1));
            }
            if (c2.IsConnected)
            {
                Devices.Add(new GamePad360(c2));
            }
            if (c3.IsConnected)
            {
                Devices.Add(new GamePad360(c3));
            }
            if (c4.IsConnected)
            {
                Devices.Add(new GamePad360(c4));
            }
        }
Esempio n. 6
0
        public static void Initialize(MainWindow window)
        {
            IntPtr handle = new WindowInteropHelper(window).Handle;

            IsAvailable = false;

            // clear devices
            Devices.Clear();

            ContInfoFromLog = LogParser.Instance.GetAttachedControllers(true).Where(a => a.Type == ControllerType.XInput).ToArray();

            try
            {
                //some users wont even have xinput installed. in order to avoid spurious exceptions and possible instability, check for the library first
                HasGetInputStateEx = true;
                LibraryHandle      = NativeMethods.LoadLibrary("xinput1_3.dll"); // Win32.LoadLibrary("xinput1_3.dll");
                if (LibraryHandle == IntPtr.Zero)
                {
                    LibraryHandle = NativeMethods.LoadLibrary("xinput1_4.dll");
                }
                if (LibraryHandle == IntPtr.Zero)
                {
                    LibraryHandle      = NativeMethods.LoadLibrary("xinput9_1_0.dll");
                    HasGetInputStateEx = false;
                }

                if (LibraryHandle != IntPtr.Zero)
                {
                    if (HasGetInputStateEx)
                    {
                        IntPtr proc = GetProcAddressOrdinal(LibraryHandle, new IntPtr(100));
                        XInputGetStateExProc = (XInputGetStateExProcDelegate)Marshal.GetDelegateForFunctionPointer(proc, typeof(XInputGetStateExProcDelegate));
                    }

                    //don't remove this code. it's important to catch errors on systems with broken xinput installs.
                    //(probably, checking for the library was adequate, but lets not get rid of this anyway)
                    var test = new SlimDX.XInput.Controller(UserIndex.One).IsConnected;
                    IsAvailable = true;
                }
            }
            catch { }



            if (!IsAvailable)
            {
                return;
            }

            //now, at this point, slimdx may be using one xinput, and we may be using another
            //i'm not sure how slimdx picks its dll to bind to.
            //i'm not sure how troublesome this will be
            //maybe we should get rid of slimdx for this altogether

            var c1 = new Controller(UserIndex.One);
            var c2 = new Controller(UserIndex.Two);
            var c3 = new Controller(UserIndex.Three);
            var c4 = new Controller(UserIndex.Four);

            try
            {
                string error = "WARNING\n\nYou have one or more XInput gamepads/joypads that have been detected, but we couldnt find a mednafen ID for them\n\n" +
                               "Please check stdout.txt for any errors. You must correct them before trying to RE-POLL devices again.";


                if (c1.IsConnected)
                {
                    if (ContInfoFromLog.Length < 1)
                    {
                        MessagePopper.ShowMessageDialog(error, "GAMEPAD DETECTION ISSUE");
                    }
                    Devices.Add(new GamePad360(0, c1, ContInfoFromLog[0]));
                }
                if (c2.IsConnected)
                {
                    if (ContInfoFromLog.Length < 2)
                    {
                        MessagePopper.ShowMessageDialog(error, "GAMEPAD DETECTION ISSUE");
                    }
                    Devices.Add(new GamePad360(1, c2, ContInfoFromLog[1]));
                }
                if (c3.IsConnected)
                {
                    if (ContInfoFromLog.Length < 3)
                    {
                        MessagePopper.ShowMessageDialog(error, "GAMEPAD DETECTION ISSUE");
                    }
                    Devices.Add(new GamePad360(2, c3, ContInfoFromLog[2]));
                }
                if (c4.IsConnected)
                {
                    if (ContInfoFromLog.Length < 4)
                    {
                        MessagePopper.ShowMessageDialog(error, "GAMEPAD DETECTION ISSUE");
                    }
                    Devices.Add(new GamePad360(3, c4, ContInfoFromLog[3]));
                }
            }
            catch (Exception) { }
        }
Esempio n. 7
0
        public ControllerX()
        {
            this.userIndex = new UserIndex();

            //trzeba dać wyjątki gdy nie podłączony żaden pad :D
            //            foreach (var deviceInstance in SlimDX.XInput.get.GetDevices(SlimDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices))
            //                this.joystickGuid = deviceInstance.InstanceGuid;

            this.joystick = new SlimDX.XInput.Controller(userIndex);
            this.vibration = new Vibration();
        }