Exemple #1
0
    /// <summary>
    /// Sets up all correctly configured PlayerPed
    /// </summary>
    private void SetupPlayerPeds()
    {
        foreach (UserIndex player in userIndices)
        {
            if (bool.Parse(PlayerSettings.GetValue(player, EnabledKey, false.ToString())))
            {
                string guid = PlayerSettings.GetValue(player, ControllerKey, "");

                foreach (InputManager input in InputManager.GetAvailableInputManagers())
                {
                    if (input.DeviceGuid.Equals(guid))
                    {
                        InputManager manager = input;
                        if (input is DirectInputManager)
                        {
                            manager = DirectInputManager.LoadConfig(((DirectInputManager)input).device, GetIniFile());
                        }

                        PedHash    characterHash = PlayerSettings.GetEnumValue <PedHash>(player, CharacterHashKey, PedHash.Trevor.ToString());
                        BlipSprite blipSprite    = PlayerSettings.GetEnumValue <BlipSprite>(player, BlipSpriteKey, BlipSprite.Standard.ToString());
                        BlipColor  blipColor     = PlayerSettings.GetEnumValue <BlipColor>(player, BlipColorKey, BlipColor.Green.ToString());

                        PlayerPed playerPed = new PlayerPed(player, characterHash, blipSprite, blipColor, player1, manager);
                        playerPeds.Add(playerPed);
                        break;
                    }
                }
            }
        }
    }
        /// <summary>
        /// Small wizard to determine what kind of Dpad the controller belonging to the InputManager has
        /// </summary>
        /// <param name="input">InputManager which to determine the Dpad of</param>
        /// <returns>DpadType enum</returns>
        private DpadType DetermineDpadType(DirectInputManager input)
        {
            while (input.GetPressedButton() == -1 && input.GetDpadValue() == -1)
            {
                if (Game.IsKeyPressed(System.Windows.Forms.Keys.Escape))
                {
                    return((DpadType)3);
                }
                UI.ShowSubtitle("Press and hold at least one Dpad button for 1 second. Press the Esc key to cancel.", 120);
                Script.Wait(100);
            }

            UI.ShowSubtitle("Now keep holding that Dpad button.");
            Script.Wait(1000);

            int button           = input.GetPressedButton();
            int digitalDpadvalue = input.GetDpadValue();

            if (digitalDpadvalue != -1)
            {
                return(DpadType.DigitalDpad);
            }
            else if (button != -1)
            {
                return(DpadType.ButtonsDpad);
            }
            return(DpadType.Unknown);
        }
Exemple #3
0
        public MainWindow()
        {
            InitializeComponent();

            // Constructs wrapped SharpDX.DirectInput instance but doesn't
            // start DirectInputManager()
            directInput = new DirectInputManager();
        }
        /// <summary>
        /// Starts a wizard in which the user gets asked for all buttons one by one
        /// </summary>
        /// <param name="iniFile">The target INI file</param>
        /// <returns></returns>
        public bool StartConfiguration(string iniFile)
        {
            DirectInputManager input = new DirectInputManager(stick);

            ScriptSettings data = ScriptSettings.Load(iniFile);
            string         guid = stick.Information.ProductGuid.ToString();

            DpadType dpadType = DetermineDpadType(input);

            if (dpadType == (DpadType)3)
            {
                return(false);
            }

            if (dpadType == DpadType.Unknown)
            {
                UI.Notify("Unknown Dpad type, controller configuration stopped.");
                return(false);
            }
            data.SetValue(guid, DirectInputManager.DpadTypeKey, dpadType.ToString());

            while (input.GetDpadValue() != -1)
            {
                UI.ShowSubtitle("Please let go the Dpad button.");
                Script.Wait(100);
            }

            Script.Wait(1000);

            UI.ShowSubtitle("Determined Dpad type: " + dpadType, 2500);

            Script.Wait(2500);

            foreach (DeviceButton btn in Enum.GetValues(typeof(DeviceButton)))
            {
                if (Array.Exists(dpads, item => { return(item == btn); }) && dpadType == DpadType.DigitalDpad)
                {
                    bool result = ConfigureDigitalDpadButton(btn, data, input, guid);
                    if (!result)
                    {
                        return(false);
                    }
                }
                else
                {
                    bool result = Configure(btn, data, input, guid);
                    if (!result)
                    {
                        return(false);
                    }
                }

                UI.Notify(GetBtnText(btn) + " button configured.");
            }

            data.Save();
            return(true);
        }
Exemple #5
0
            /// <summary>
            /// Returns both XInput and DirectInput InputManager
            /// </summary>
            /// <returns>A List of InputManagers</returns>
            public static List <InputManager> GetAvailableInputManagers()
            {
                List <InputManager> managers = new List <InputManager>();

                foreach (Controller ctrl in XInputManager.GetDevices())
                {
                    managers.Add(new XInputManager(ctrl));
                }

                foreach (Joystick stick in DirectInputManager.GetDevices())
                {
                    managers.Add(new DirectInputManager(stick));
                }
                return(managers);
            }
Exemple #6
0
        static void Main()
        {
            DirectInputManager directInput = null;

            ExitOnKeypress();

            try
            {
                //
                // Creation of DirectInputManager and registration for events via EventBus
                // may be done in any order.
                //

                // Constructs wrapped SharpDX.DirectInput instance but nothing more
                directInput = new DirectInputManager();

                // Starts threads that either poll or wait for joystick input
                directInput.Initialize();

                // Register for controller button, POV, and axis events
                EventBus <EventController> .Instance.EventRecieved += OnEventController;

                // Register for event when connected controller list changes
                // Occurs when a controller is un/plugged (or otherwise en/disabled)
                EventBus <EventControllersChanged> .Instance.EventRecieved += OnEventControllersChanged;

                // Runs until application exits via keypress
                Thread.Sleep(System.Threading.Timeout.Infinite);
            }
            catch (SharpDX.SharpDXException e)
            {
                Console.WriteLine("SharpDX Exception while initializing DirectInputManager: " + e);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                directInput.Dispose();
            }
        }
Exemple #7
0
        public Form()
        {
            InitializeComponent();

            try
            {
                directInput = new DirectInputManager();

                directInput.Initialize();

                //
                // Initialization of DirectInputManager and registration for
                // events via EventBus may be done in any order.
                //

                // Register for controller button, POV, and axis events
                EventBus <EventController> .Instance.EventRecieved += OnEventController;

                // Register for event when connected controller list changes
                // Occurs when a controller is un/plugged (or otherwise en/disabled)
                EventBus <EventControllersChanged> .Instance.EventRecieved += OnEventControllersChanged;

                // Creates and starts threads to either poll or wait for joystick input.
                // Also synchronously enumerates and connects to all controller devices.
                // May throw SharpDXException
                directInput.Initialize();

                // This is also happens OnEventControllersChanged()
                UpdateConnectedDevices(directInput.GetConnectedDeviceInfos());
            }
            catch (SharpDXException e)
            {
                MessageBox.Show(e.Message, "DirectInput initialization exception");

                if (null != directInput)
                {
                    directInput.Dispose();
                }
            }
        }
Exemple #8
0
            /// <summary>
            /// Constructs a new InputManager by reading the config from a file
            ///
            /// The file must contain something similar to this:
            ///
            ///[0268054C-0000-0000-0000-504944564944]
            ///DPADUP = 5
            ///DPADDOWN = 7
            ///DPADLEFT = 8
            ///DPADRIGHT = 6
            ///BACK = 1
            ///BIGBUTTON = 17
            ///START = 4
            ///LEFTSTICK = 2
            ///RIGHTSTICK = 3
            ///A = 15
            ///B = 14
            ///X = 16
            ///Y = 13
            ///LEFTSHOULDER = 11
            ///LEFTTRIGGER = 9
            ///RIGHTSHOULDER = 12
            ///RIGHTTRIGGER = 10
            ///
            /// </summary>
            /// <param name="stick">The Joystick instance which should be managed by this InputManager</param>
            /// <param name="file">Path to the file containing the config</param>
            /// <returns></returns>
            public static DirectInputManager LoadConfig(Joystick stick, string file)
            {
                DirectInputManager manager = new DirectInputManager(stick);

                try
                {
                    string         name = stick.Information.ProductGuid.ToString();
                    ScriptSettings data = ScriptSettings.Load(file);

                    DpadType dpadType = DpadType.Unknown;
                    try
                    {
                        dpadType = (DpadType)Enum.Parse(typeof(DpadType), data.GetValue(name, DpadTypeKey, DpadType.Unknown.ToString()));
                    }
                    catch (Exception)
                    {
                        throw new Exception("Invalid controller config, unknown " + DpadTypeKey + " reconfigure your controller from the menu.");
                    }

                    foreach (DeviceButton btn in Enum.GetValues(typeof(DeviceButton)))
                    {
                        int btnIndex = data.GetValue(name, btn.ToString(), -1);

                        try
                        {
                            manager.config.Add(new Tuple <int, DeviceButton>(btnIndex, btn));
                        }
                        catch (Exception)
                        {
                            throw new Exception("Invalid controller config, please reconfigure your controller from the menu.");
                        }
                    }
                }
                catch (Exception)
                {
                    throw new Exception("Error reading controller config, make sure the file contains a valid controller config.");
                }
                return(manager);
            }
        public GameContext()
        {
            Tracer.i("Initializing GameContext");
            MainWindow=new MainWindow(this);
            MainWindow.Show();
            RenderContext = MainWindow.RenderContext;
            DebugGrid=new BasicGrid();
            DebugGrid.Load(RenderContext);
            GameWorld = MainWindow.WorldSpace;
            GameWorld.AddResource(DebugGrid);
            DirectInput = new DirectInputManager(RenderContext, MainWindow);
            OculusManager = new OculusDeviceManager(RenderContext);
            //PlayerContexts[0]=new PlayerContext(this,0);
            //PlayerContexts[1]=new PlayerContext(this,1);
            Controller=new ControlForm(this);
            Controller.Show();
            _drawable = new BulletEffect(this);
            GameWorld.AddResource(_drawable);
            _drawable.Start(new Vector3(0,0,0),new Vector3(0,0,1));

            //handOperationChecker=new JoystickHandOperationChecker(this,11);
            Tracer.i("Initializing GameContext Completed!");
        }
        public GameContext()
        {
            Tracer.i("Initializing GameContext");
            MainWindow = new MainWindow(this);
            MainWindow.Show();
            RenderContext = MainWindow.RenderContext;
            DebugGrid     = new BasicGrid();
            DebugGrid.Load(RenderContext);
            GameWorld = MainWindow.WorldSpace;
            GameWorld.AddResource(DebugGrid);
            DirectInput   = new DirectInputManager(RenderContext, MainWindow);
            OculusManager = new OculusDeviceManager(RenderContext);
            //PlayerContexts[0]=new PlayerContext(this,0);
            //PlayerContexts[1]=new PlayerContext(this,1);
            Controller = new ControlForm(this);
            Controller.Show();
            _drawable = new BulletEffect(this);
            GameWorld.AddResource(_drawable);
            _drawable.Start(new Vector3(0, 0, 0), new Vector3(0, 0, 1));

            //handOperationChecker=new JoystickHandOperationChecker(this,11);
            Tracer.i("Initializing GameContext Completed!");
        }
Exemple #11
0
        static void Main(string[] args)
        {
            ExitOnKeypress();

            using (DirectInputManager directInputManager = new DirectInputManager(
                       // Supply ILogger for DirectInputManager to use
                       new Logger4net(typeof(DirectInputManager).ToString())))
            {
                try
                {
                    directInputManager.Initialize();
                }
                catch (SharpDXException e)
                {
                    LOGGER.Error("Exception initializing NerfDX.DirectInputManager", e);
                }

                EventBus <EventController> .Instance.EventRecieved         += OnEventController;
                EventBus <EventControllersChanged> .Instance.EventRecieved += OnEventControllersChanged;

                // Runs until application exits via keypress
                Thread.Sleep(System.Threading.Timeout.Infinite);
            }
        }
        /// <summary>
        /// Helper method to configure a single DeviceButton and add it the configuration
        /// </summary>
        /// <param name="btn">The target DeviceButton</param>
        /// <param name="data">The ScriptSettings object which it needs to be saved too</param>
        /// <param name="input">InputManager object to handle input</param>
        /// <param name="guid">The GUID of the controller</param>
        private bool Configure(DeviceButton btn, ScriptSettings data, DirectInputManager input, string guid)
        {
            while (input.GetPressedButton() == -1)
            {
                if (Game.IsKeyPressed(System.Windows.Forms.Keys.Escape))
                {
                    return(false);
                }
                UI.ShowSubtitle("Press and hold the " + GetBtnText(btn) + " button on the controller for 1 second. Press the Esc key to cancel.", 120);
                Script.Wait(100);
            }

            int button = input.GetPressedButton();

            UI.ShowSubtitle("Please hold the " + GetBtnText(btn) + " button to confirm it.");
            Script.Wait(1000);

            if (button != input.GetPressedButton())
            {
                UI.ShowSubtitle("Now hold the " + GetBtnText(btn) + " button to confirm.");
                Script.Wait(1000);
                Configure(btn, data, input, guid);
            }
            else
            {
                data.SetValue(guid, btn.ToString(), button);
                while (input.GetPressedButton() != -1)
                {
                    UI.ShowSubtitle("Now let go the button to configure the next one.");
                    Script.Wait(100);
                }
                Script.Wait(1000);
            }

            return(true);
        }
Exemple #13
0
    /// <summary>
    /// Sets up the NativeUI menu
    /// </summary>
    private void SetupMenu()
    {
        if (menuPool != null)
        {
            menuPool.ToList().ForEach(menu => { menu.Clear(); });
        }

        menu = new UIMenu("Two Player Mod", Enabled() ? "~g~Enabled" : "~r~Disabled");
        menuPool.Add(menu);

        UIMenuItem toggleItem = new UIMenuItem("Toggle mod", "Toggle Two Player mode");

        toggleItem.Activated += ToggleMod_Activated;
        menu.AddItem(toggleItem);

        UIMenu allPlayersMenu = menuPool.AddSubMenu(menu, "Players");

        menu.MenuItems.FirstOrDefault(item => { return(item.Text.Equals("Players")); }).Description = "Configure players";

        foreach (UserIndex player in userIndices)
        {
            bool check = bool.Parse(PlayerSettings.GetValue(player, EnabledKey, false.ToString()));

            UIMenu     playerMenu = menuPool.AddSubMenu(allPlayersMenu, "Player " + player);
            UIMenuItem playerItem = allPlayersMenu.MenuItems.FirstOrDefault(item => { return(item.Text.Equals("Player " + player)); });

            string controllerGuid = PlayerSettings.GetValue(player, ControllerKey, "");

            playerItem.Description = "Configure player " + player;

            if (!string.IsNullOrEmpty(controllerGuid))
            {
                playerItem.SetRightBadge(UIMenuItem.BadgeStyle.Star);
            }

            UIMenuCheckboxItem togglePlayerItem = new UIMenuCheckboxItem("Toggle player " + player, check, "Enables/disables this player");

            togglePlayerItem.CheckboxEvent += (s, enabled) =>
            {
                PlayerSettings.SetValue(player, EnabledKey, enabled.ToString());

                RefreshSubItems(togglePlayerItem, playerMenu, enabled);
            };

            playerMenu.AddItem(togglePlayerItem);

            playerMenu.AddItem(ConstructSettingsListItem(player, "Character", "Select a character for player " + player, CharacterHashKey, PedHash.Trevor));
            playerMenu.AddItem(ConstructSettingsListItem(player, "Blip sprite", "Select a blip sprite for player " + player, BlipSpriteKey, BlipSprite.Standard));
            playerMenu.AddItem(ConstructSettingsListItem(player, "Blip color", "Select a blip color for player " + player, BlipColorKey, BlipColor.Green));

            UIMenu controllerMenu = menuPool.AddSubMenu(playerMenu, "Assign controller");
            playerMenu.MenuItems.FirstOrDefault(item => { return(item.Text.Equals("Assign controller")); }).Description = "Assign controller to player " + player;

            foreach (InputManager manager in InputManager.GetAvailableInputManagers())
            {
                UIMenuItem controllerItem = new UIMenuItem(manager.DeviceName, "Assign this controller to player " + player);

                string guid = manager.DeviceGuid;

                if (PlayerSettings.GetValue(player, ControllerKey, "").Equals(guid))
                {
                    controllerItem.SetRightBadge(UIMenuItem.BadgeStyle.Star);
                }

                if (manager is DirectInputManager)
                {
                    DirectInputManager directManager = (DirectInputManager)manager;
                    bool configured = DirectInputManager.IsConfigured(directManager.device, GetIniFile());
                    controllerItem.Enabled = configured;

                    if (!configured)
                    {
                        controllerItem.Description = "Please configure this controller first from the main menu";
                    }
                }

                controllerItem.Activated += (s, i) =>
                {
                    if (i.Enabled)
                    {
                        PlayerSettings.SetValue(player, ControllerKey, guid);

                        controllerMenu.MenuItems.ForEach(item =>
                        {
                            if (item == controllerItem)
                            {
                                item.SetRightBadge(UIMenuItem.BadgeStyle.Star);
                            }
                            else
                            {
                                item.SetRightBadge(UIMenuItem.BadgeStyle.None);
                            }
                        });
                    }
                };

                controllerMenu.AddItem(controllerItem);
            }

            RefreshSubItems(togglePlayerItem, playerMenu, check);
        }

        UIMenuCheckboxItem cameraItem = new UIMenuCheckboxItem("GTA:SA style camera", customCamera, "Enables/disables the GTA:SA style camera");

        cameraItem.CheckboxEvent += (s, i) =>
        {
            customCamera = !customCamera;
            Settings.SetValue(Name, CustomCameraKey, customCamera.ToString());
            Settings.Save();
        };
        menu.AddItem(cameraItem);

        UIMenu controllersMenu = menuPool.AddSubMenu(menu, "Configure controllers");

        menu.MenuItems.FirstOrDefault(item => { return(item.Text.Equals("Configure controllers")); }).Description = "Configure controllers before assigning them to players";
        foreach (Joystick stick in DirectInputManager.GetDevices())
        {
            UIMenuItem stickItem = new UIMenuItem(stick.Information.ProductName, "Configure " + stick.Information.ProductName);

            controllersMenu.AddItem(stickItem);
            stickItem.Activated += (s, i) =>
            {
                ControllerWizard wizard  = new ControllerWizard(stick);
                bool             success = wizard.StartConfiguration(GetIniFile());
                if (success)
                {
                    UI.Notify("Controller successfully configured, you can now assign this controller");
                }
                else
                {
                    UI.Notify("Controller configuration canceled, please configure your controller before playing");
                }
                SetupMenu();
            };
        }

        menu.RefreshIndex();
    }
 public KeyboardHandOperationChecker(DirectInputManager directInputManager, int index, IKeyboardKeyConfig config = null)
 {
     config          = config ?? new DefaultKeyConfig();
     _config         = config;
     keyboardChecker = directInputManager.getKeyboardChecker(index);
 }
 public KeyboardHandOperationChecker(DirectInputManager directInputManager,int index,IKeyboardKeyConfig config=null)
 {
     config = config ?? new DefaultKeyConfig();
     _config = config;
     keyboardChecker = directInputManager.getKeyboardChecker(index);
 }