public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            InputHandler.CancelRunningInputs();

            //Wait until no inputs are running
            while (InputHandler.CurrentRunningInputs > 0)
            {
            }

            //Resume inputs
            InputHandler.ResumeRunningInputs();

            BotProgram.MsgHandler.QueueMessage("Stopped all running inputs!");
        }
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            //See the console
            if (args.Count == 0)
            {
                BotProgram.MsgHandler.QueueMessage($"The current console is {InputGlobals.CurrentConsoleVal}. To set the console, add one as an argument: {GetValidConsoleStr()}");
                return;
            }

            string consoleStr = args[0];

            if (Enum.TryParse <InputGlobals.InputConsoles>(consoleStr, true, out InputGlobals.InputConsoles console) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Please enter a valid console: {GetValidConsoleStr()}");
                return;
            }

            if (console == InputGlobals.CurrentConsoleVal)
            {
                BotProgram.MsgHandler.QueueMessage($"The current console is already {InputGlobals.CurrentConsoleVal}!");
                return;
            }

            //First stop all inputs completely while changing consoles - we don't want data from other inputs remaining
            InputHandler.CancelRunningInputs();

            //Wait until no inputs are running
            while (InputHandler.CurrentRunningInputs > 0)
            {
            }

            //Set console and buttons
            InputGlobals.SetConsole(console, args);

            for (int i = 0; i < InputGlobals.ControllerMngr.ControllerCount; i++)
            {
                IVirtualController controller = InputGlobals.ControllerMngr.GetController(i);
                if (controller.IsAcquired == true)
                {
                    controller.Reset();
                }
            }

            //Resume inputs
            InputHandler.ResumeRunningInputs();

            BotProgram.MsgHandler.QueueMessage($"Set console to {InputGlobals.CurrentConsoleVal} and reset all running inputs!");
        }
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            //See the virtual controller
            if (args.Count == 0)
            {
                BotProgram.MsgHandler.QueueMessage($"The current virtual controller is {InputGlobals.CurVControllerType}. To set the virtual controller, add one as an argument: {GetValidControllerStr()}");
                return;
            }

            string vControllerStr = args[0];

            if (Enum.TryParse <InputGlobals.VControllerTypes>(vControllerStr, true, out InputGlobals.VControllerTypes vCType) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"Please enter a valid virtual controller: {GetValidControllerStr()}");
                return;
            }

            if (vCType == InputGlobals.CurVControllerType)
            {
                BotProgram.MsgHandler.QueueMessage($"The current virtual controller is already {InputGlobals.CurVControllerType}!");
                return;
            }

            if (InputGlobals.IsVControllerSupported(vCType) == false)
            {
                BotProgram.MsgHandler.QueueMessage($"{vCType} virtual controllers are not supported on your operating system.");
                return;
            }

            InputHandler.CancelRunningInputs();

            //Wait until no inputs are running
            while (InputHandler.CurrentRunningInputs > 0)
            {
            }

            //Change virtual controller
            InputGlobals.SetVirtualController(vCType);

            //Resume inputs
            InputHandler.ResumeRunningInputs();

            BotProgram.MsgHandler.QueueMessage($"Set virtual controller to {InputGlobals.CurVControllerType} and reset all running inputs!");
        }
Esempio n. 4
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count != 1)
            {
                BotProgram.MsgHandler.QueueMessage($"Usage: \"# of controllers (min: {InputGlobals.ControllerMngr.MinControllers}, max: {InputGlobals.ControllerMngr.MaxControllers})\"");
                return;
            }

            if (int.TryParse(args[0], out int newJoystickCount) == false)
            {
                BotProgram.MsgHandler.QueueMessage("Invalid number of controllers!");
                return;
            }

            if (newJoystickCount < InputGlobals.ControllerMngr.MinControllers)
            {
                BotProgram.MsgHandler.QueueMessage($"Value is less than {InputGlobals.ControllerMngr.MinControllers}!");
                return;
            }

            if (newJoystickCount > InputGlobals.ControllerMngr.MaxControllers)
            {
                BotProgram.MsgHandler.QueueMessage($"Value is greater than {InputGlobals.ControllerMngr.MaxControllers}, which is the max number of supported controllers!");
                return;
            }

            if (newJoystickCount == BotProgram.BotData.JoystickCount)
            {
                BotProgram.MsgHandler.QueueMessage("There are already that many controllers plugged in!");
                return;
            }

            //We changed count, so let's stop all inputs and reinitialize the devices
            BotProgram.MsgHandler.QueueMessage($"Changing controller count from {BotProgram.BotData.JoystickCount} to {newJoystickCount}. Stopping all inputs and reinitializing.");

            InputHandler.CancelRunningInputs();

            //Wait until no inputs are running
            while (InputHandler.CurrentRunningInputs > 0)
            {
            }

            //Reinitialize the virtual controllers
            InputGlobals.ControllerMngr.CleanUp();

            //Kimimaru: Time out so we don't softlock everything if all devices cannot be freed
            //While this is an issue if it happens, we'll let the streamer know without permanently suspending inputs
            const long timeOut = 60000L;

            //Wait at least this much time before checking to give it some time
            const long minWait = 300L;

            Stopwatch sw = Stopwatch.StartNew();

            //Wait until all devices are no longer owned
            while (true)
            {
                if (sw.ElapsedMilliseconds < minWait)
                {
                    continue;
                }

                int freeCount = 0;

                for (int i = 0; i < InputGlobals.ControllerMngr.ControllerCount; i++)
                {
                    if (InputGlobals.ControllerMngr.GetController(i).IsAcquired == false)
                    {
                        freeCount++;
                    }
                }

                //We're done if all are no longer owned
                if (freeCount == InputGlobals.ControllerMngr.ControllerCount)
                {
                    break;
                }

                if (sw.ElapsedMilliseconds >= timeOut)
                {
                    BotProgram.MsgHandler.QueueMessage($"ERROR: Unable to free all virtual controllers. {freeCount}/{InputGlobals.ControllerMngr.ControllerCount} freed.");
                    break;
                }
            }

            int acquiredCount = InputGlobals.ControllerMngr.InitControllers(newJoystickCount);

            Console.WriteLine($"Acquired {acquiredCount} controllers!");

            const long wait = 500L;

            sw.Stop();
            sw.Reset();
            sw.Start();

            //Wait again to reinitialize
            while (sw.ElapsedMilliseconds < wait)
            {
            }

            InputHandler.ResumeRunningInputs();

            BotProgram.BotData.JoystickCount = newJoystickCount;
            BotProgram.SaveBotData();

            BotProgram.MsgHandler.QueueMessage("Controllers reinitialized and inputs resumed!");
        }
        public override void ExecuteCommand(object sender, OnChatCommandReceivedArgs e)
        {
            List <string> args = e.Command.ArgumentsAsList;

            if (args.Count != 1)
            {
                BotProgram.QueueMessage($"Usage: \"# of controllers (min: {VJoyController.MIN_VJOY_DEVICE_ID}, max: {VJoyController.MAX_VJOY_DEVICE_ID})\"");
                return;
            }

            if (int.TryParse(args[0], out int newJoystickCount) == false)
            {
                BotProgram.QueueMessage("Invalid number of controllers!");
                return;
            }

            if (newJoystickCount < VJoyController.MIN_VJOY_DEVICE_ID)
            {
                BotProgram.QueueMessage($"Value is less than {VJoyController.MIN_VJOY_DEVICE_ID}!");
                return;
            }

            if (newJoystickCount > VJoyController.MAX_VJOY_DEVICE_ID)
            {
                BotProgram.QueueMessage($"Value is greater than {VJoyController.MAX_VJOY_DEVICE_ID}, which is the max number of supported controllers!");
                return;
            }

            if (newJoystickCount == BotProgram.BotData.JoystickCount)
            {
                BotProgram.QueueMessage("There are already that many controllers plugged in!");
                return;
            }

            //We changed count, so let's stop all inputs and reinitialize the vJoy devices
            BotProgram.QueueMessage($"Changing controller count from {BotProgram.BotData.JoystickCount} to {newJoystickCount}. Stopping all inputs and reinitializing.");

            InputHandler.CancelRunningInputs();

            //Wait until no inputs are running
            while (InputHandler.CurrentRunningInputs > 0)
            {
            }

            //Reinitialize the vJoy devices
            VJoyController.CleanUp();

            //Kimimaru: Time out so we don't softlock everything if all devices cannot be freed
            //While this is an issue if it happens, we'll let the streamer know without permanently suspending inputs
            const long timeOut = 60000;

            Stopwatch sw = Stopwatch.StartNew();

            //Wait until all vJoy devices are no longer owned
            while (true)
            {
                int freeCount = 0;

                for (int i = 0; i < VJoyController.Joysticks.Length; i++)
                {
                    VjdStat stat = VJoyController.VJoyInstance.GetVJDStatus(VJoyController.Joysticks[i].ControllerID);
                    if (stat != VjdStat.VJD_STAT_OWN)
                    {
                        freeCount++;
                    }
                }

                //We're done if all are no longer owned
                if (freeCount == VJoyController.Joysticks.Length)
                {
                    break;
                }

                if (sw.ElapsedMilliseconds >= timeOut)
                {
                    BotProgram.QueueMessage($"ERROR: Unable to free all vJoy controllers. {freeCount}/{VJoyController.Joysticks.Length} freed.");
                    break;
                }
            }

            int acquiredCount = VJoyController.InitControllers(newJoystickCount);

            Console.WriteLine($"Acquired {acquiredCount} controllers!");

            const long wait = 500L;

            sw.Stop();
            sw.Reset();
            sw.Start();

            //Wait again to reinitialize
            while (sw.ElapsedMilliseconds < wait)
            {
            }

            InputHandler.ResumeRunningInputs();

            BotProgram.BotData.JoystickCount = newJoystickCount;
            BotProgram.SaveBotData();

            BotProgram.QueueMessage("Controllers reinitialized and inputs resumed!");
        }