Ejemplo n.º 1
0
		public static void Initialize(IntPtr parent)
		{
			if (dinput == null)
				dinput = new DirectInput();

			Devices = new List<GamePad>();

			foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
			{
				Console.WriteLine("joydevice: {0} `{1}`", device.InstanceGuid, device.ProductName);

				if (device.ProductName.Contains("XBOX 360"))
					continue; // Don't input XBOX 360 controllers into here; we'll process them via XInput (there are limitations in some trigger axes when xbox pads go over xinput)

				var joystick = new Joystick(dinput, device.InstanceGuid);
				joystick.SetCooperativeLevel(parent, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
				foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
				{
					if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
						joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
				}
				joystick.Acquire();

				GamePad p = new GamePad(device.InstanceName, device.InstanceGuid, joystick);
				Devices.Add(p);
			}
		}
Ejemplo n.º 2
0
        static void SubMain(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string iniPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.ini");

            Global.Config = ConfigService.Load <Config>(iniPath);
            Global.Config.ResolveDefaults();
            HawkFile.ArchiveHandlerFactory = new SevenZipSharpArchiveHandler();

            //super hacky! this needs to be done first. still not worth the trouble to make this system fully proper
            for (int i = 0; i < args.Length; i++)
            {
                var arg = args[i].ToLower();
                if (arg.StartsWith("--gdi"))
                {
                    Global.Config.DispMethod = Config.EDispMethod.GdiPlus;
                }
            }


            //WHY do we have to do this? some intel graphics drivers (ig7icd64.dll 10.18.10.3304 on an unknown chip on win8.1) are calling SetDllDirectory() for the process, which ruins stuff.
            //The relevant initialization happened just before in "create IGL context".
            //It isn't clear whether we need the earlier SetDllDirectory(), but I think we do.
            //note: this is pasted instead of being put in a static method due to this initialization code being sensitive to things like that, and not wanting to cause it to break
            //pasting should be safe (not affecting the jit order of things)
            string dllDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dll");

            SetDllDirectory(dllDir);

            try
            {
                using (var mf = new Mainform(args))
                {
                    var title = mf.Text;
                    mf.Show();
                    mf.Text = title;
                    try
                    {
                        mf.ProgramRunLoop();
                    }
                    catch (Exception e)
                    {
#if WINDOWS
                        if (Global.MovieSession.Movie.IsActive)
                        {
                            var result = MessageBox.Show(
                                "EmuHawk has thrown a fatal exception and is about to close.\nA movie has been detected. Would you like to try to save?\n(Note: Depending on what caused this error, this may or may succeed)",
                                "Fatal error: " + e.GetType().Name,
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Exclamation
                                );
                            if (result == DialogResult.Yes)
                            {
                                Global.MovieSession.Movie.Save();
                            }
                        }
#endif
                        throw;
                    }
                }
            }
            catch (Exception e)
            {
                string message = e.ToString();
                if (e.InnerException != null)
                {
                    message += "\n\nInner Exception:\n\n" + e.InnerException;
                }

                message += "\n\nStackTrace:\n" + e.StackTrace;
                MessageBox.Show(message);
            }
#if WINDOWS
            finally
            {
                GamePad.CloseAll();
            }
#endif
        }