Example #1
0
        private void FlyoutWindow_SourceInitialized(object sender, EventArgs e)
        {
            this.Cloak();

            Manager.Current.ThemeChanged += ThemeChanged;
            ThemeChanged();

            _rawListener             = new RawInputListener(this);
            _rawListener.MouseWheel += RawListener_MouseWheel;
            MouseEnter += FlyoutWindow_MouseEnter;
        }
Example #2
0
        private void FlyoutWindow_SourceInitialized(object sender, EventArgs e)
        {
            this.Cloak();

            var themeManager = (ThemeManager)App.Current.Resources["ThemeManager"];

            themeManager.ThemeChanged += ThemeChanged;
            ThemeChanged();

            _rawListener             = new RawInputListener(this);
            _rawListener.MouseWheel += RawListener_MouseWheel;
            MouseEnter += FlyoutWindow_MouseEnter;
            MouseLeave += FlyoutWindow_MouseLeave;
        }
Example #3
0
        private void GameRunning_OnLoaded(object sender, RoutedEventArgs e)
        {
            JvsPackageEmulator.Initialize();
            switch (InputCode.ButtonMode)
            {
            case EmulationProfile.EuropaRFordRacing:
                if (_pipe == null)
                {
                    _pipe = new EuropaRPipe();
                }
                break;

            case EmulationProfile.EuropaRSegaRally3:
                if (_pipe == null)
                {
                    _pipe = new SegaRallyPipe();
                }
                break;

            case EmulationProfile.FastIo:
                if (_pipe == null)
                {
                    _pipe = new FastIOPipe();
                }
                break;
            }

            _pipe?.Start();

            var invertButtons =
                _gameProfile.ConfigValues.Any(x => x.FieldName == "Invert Buttons" && x.FieldValue == "1");

            if (invertButtons)
            {
                JvsPackageEmulator.InvertMaiMaiButtons = true;
            }

            if (_rawInputListener == null)
            {
                _rawInputListener = new RawInputListener();
            }

            if (InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoIsland ||
                InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoJungle)
            {
                InputCode.AnalogBytes[0] = 127;
                InputCode.AnalogBytes[2] = 127;
                InputCode.AnalogBytes[4] = 127;
                InputCode.AnalogBytes[6] = 127;
            }
            else
            {
                InputCode.AnalogBytes[0] = 0;
                InputCode.AnalogBytes[2] = 0;
                InputCode.AnalogBytes[4] = 0;
                InputCode.AnalogBytes[6] = 0;
            }

            bool useMouseForGun =
                _gameProfile.ConfigValues.Any(x => x.FieldName == "UseMouseForGun" && x.FieldValue == "1");

            if (useMouseForGun && _gameProfile.GunGame)
            {
                _rawInputListener.ListenToDevice(InputCode.ButtonMode == EmulationProfile.SegaJvsGoldenGun ||
                                                 InputCode.ButtonMode == EmulationProfile.Hotd4);
            }

            switch (InputCode.ButtonMode)
            {
            case EmulationProfile.NamcoPokken:
                _controlSender = new Pokken();
                break;

            case EmulationProfile.ExBoard:
                _controlSender = new ExBoard();
                break;

            case EmulationProfile.GtiClub3:
                _controlSender = new GtiClub3();
                break;

            case EmulationProfile.Daytona3:
                _controlSender = new Daytona3();
                break;

            case EmulationProfile.GRID:
                _controlSender = new GRID();
                break;
            }

            _controlSender?.Start();

            if (_gameProfile.GunGame)
            {
                _killGunListener = false;
                _gunThread       = new Thread(HandleGun);
                _gunThread.Start();
            }

            if (!_runEmuOnly)
            {
                WriteConfigIni();
            }

            if (InputCode.ButtonMode != EmulationProfile.EuropaRFordRacing &&
                InputCode.ButtonMode != EmulationProfile.EuropaRSegaRally3 &&
                InputCode.ButtonMode != EmulationProfile.FastIo)
            {
                // TODO: MAYBE MAKE THESE XML BASED?
                switch (InputCode.ButtonMode)
                {
                case EmulationProfile.VirtuaRLimit:
                case EmulationProfile.ChaseHq2:
                case EmulationProfile.WackyRaces:
                    JvsPackageEmulator.Taito          = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.TaitoTypeXBattleGear:
                    JvsPackageEmulator.JvsVersion      = 0x30;
                    JvsPackageEmulator.TaitoStick      = true;
                    JvsPackageEmulator.TaitoBattleGear = true;
                    JvsPackageEmulator.JvsSwitchCount  = 0x18;
                    break;

                case EmulationProfile.TaitoTypeXGeneric:
                    JvsPackageEmulator.JvsVersion     = 0x30;
                    JvsPackageEmulator.TaitoStick     = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.BorderBreak:
                    InputCode.AnalogBytes[0] = 0x7F;     // Center analog
                    InputCode.AnalogBytes[2] = 0x7F;     // Center analog
                    break;

                case EmulationProfile.NamcoPokken:
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.NBGI_Pokken;
                    JvsPackageEmulator.Namco = true;
                    break;

                case EmulationProfile.NamcoWmmt5:
                case EmulationProfile.NamcoMkdx:
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.NBGI_MarioKart3;
                    JvsPackageEmulator.Namco          = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.NamcoMachStorm:
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.NamcoMultipurpose;
                    JvsPackageEmulator.Namco          = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.DevThing1:
                    JvsPackageEmulator.JvsVersion       = 0x30;
                    JvsPackageEmulator.TaitoStick       = true;
                    JvsPackageEmulator.TaitoBattleGear  = true;
                    JvsPackageEmulator.DualJvsEmulation = true;
                    JvsPackageEmulator.JvsSwitchCount   = 0x18;
                    break;

                case EmulationProfile.VirtuaTennis4:
                case EmulationProfile.ArcadeLove:
                    JvsPackageEmulator.DualJvsEmulation = true;
                    break;

                case EmulationProfile.LGS:
                    JvsPackageEmulator.JvsCommVersion     = 0x30;
                    JvsPackageEmulator.JvsVersion         = 0x30;
                    JvsPackageEmulator.JvsCommandRevision = 0x30;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.SegaLetsGoSafari;
                    break;
                }

                _serialPortHandler.StopListening();
                Thread.Sleep(1000);
                _jvsThread = new Thread(() => _serialPortHandler.ListenPipe("TeknoParrot_JVS"));
                _jvsThread.Start();
                _processQueueThread = new Thread(_serialPortHandler.ProcessQueue);
                _processQueueThread.Start();
            }

            if (useMouseForGun && _gameProfile.GunGame)
            {
                _diThread?.Abort(0);
                _diThread = null;
            }
            else
            {
                _diThread?.Abort(0);
                _diThread = CreateInputListenerThread(
                    _gameProfile.ConfigValues.Any(x => x.FieldName == "XInput" && x.FieldValue == "1"));
            }

            if (_parrotData.UseDiscordRPC)
            {
                DiscordRPC.UpdatePresence(new DiscordRPC.RichPresence
                {
                    details       = _gameProfile.GameName,
                    largeImageKey = _gameProfile.GameName.Replace(" ", "").ToLower(),
                    //https://stackoverflow.com/a/17632585
                    startTimestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                });
            }

            // Wait before launching second thread.
            if (!_runEmuOnly)
            {
                Thread.Sleep(1000);
                _gameRunning = true;
                CreateGameProcess();
            }
        }
Example #4
0
        private void GameRunning_OnLoaded(object sender, RoutedEventArgs e)
        {
            PrivateInitJvs();
            if (InputCode.ButtonMode == EmulationProfile.EuropaRFordRacing || InputCode.ButtonMode == EmulationProfile.EuropaRSegaRally3)
            {
                if (_europa == null)
                {
                    _europa = new EuropaRPipeHandler();
                }
                _europa.StartListening(InputCode.ButtonMode == EmulationProfile.EuropaRSegaRally3);
            }
            if (InputCode.ButtonMode == EmulationProfile.FastIo)
            {
                if (_specialControl == null)
                {
                    _specialControl = new SpecialControlPipe();
                }
                _specialControl.StartListening(SpecialControlPipe.PipeModes.FastIo);
            }
            if (_rawInputListener == null)
            {
                _rawInputListener = new RawInputListener();
            }

            if (InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoIsland)
            {
                InputCode.AnalogBytes[0] = 127;
                InputCode.AnalogBytes[2] = 127;
                InputCode.AnalogBytes[4] = 127;
                InputCode.AnalogBytes[6] = 127;
            }
            else
            {
                InputCode.AnalogBytes[0] = 0;
                InputCode.AnalogBytes[2] = 0;
                InputCode.AnalogBytes[4] = 0;
                InputCode.AnalogBytes[6] = 0;
            }

            if (_parrotData.UseMouse && (InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoIsland || InputCode.ButtonMode == EmulationProfile.SegaJvsDreamRaiders || InputCode.ButtonMode == EmulationProfile.SegaJvsGoldenGun))
            {
                _rawInputListener.ListenToDevice(InputCode.ButtonMode == EmulationProfile.SegaJvsGoldenGun);
            }

            if (InputCode.ButtonMode == EmulationProfile.NamcoPokken)
            {
                _pokkenControlSender.StartListening();
            }

            if (InputCode.ButtonMode == EmulationProfile.ExBoard)
            {
                _exBoardControlSender.StartListening();
            }

            if (InputCode.ButtonMode == EmulationProfile.GtiClub3)
            {
                _gtiClub3ControlSender.StartListening();
            }

            if (InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoIsland || InputCode.ButtonMode == EmulationProfile.SegaJvsDreamRaiders || InputCode.ButtonMode == EmulationProfile.SegaJvsGoldenGun)
            {
                KillGunListener = false;
                LgiThread       = new Thread(HandleLgiControls);
                LgiThread.Start();
            }

            if (!_runEmuOnly)
            {
                WriteConfigIni();
            }

            if (InputCode.ButtonMode != EmulationProfile.EuropaRFordRacing && InputCode.ButtonMode != EmulationProfile.EuropaRSegaRally3 && InputCode.ButtonMode != EmulationProfile.FastIo)
            {
                // TODO: MAYBE MAKE THESE XML BASED?
                JvsPackageEmulator.JvsSwitchCount = 0x0E;
                switch (InputCode.ButtonMode)
                {
                case EmulationProfile.VirtuaRLimit:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x20;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                    JvsPackageEmulator.EnableTaito        = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x18;
                }
                break;

                case EmulationProfile.ChaseHq2:
                case EmulationProfile.WackyRaces:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x20;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                    JvsPackageEmulator.EnableTaito        = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x18;
                }
                break;

                case EmulationProfile.TaitoTypeXBattleGear:
                {
                    JvsPackageEmulator.JvsCommVersion        = 0x10;
                    JvsPackageEmulator.JvsVersion            = 0x30;
                    JvsPackageEmulator.JvsCommandRevision    = 0x13;
                    JvsPackageEmulator.JvsIdentifier         = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                    JvsPackageEmulator.EnableTaitoStick      = true;
                    JvsPackageEmulator.EnableTaitoBattleGear = true;
                    JvsPackageEmulator.JvsSwitchCount        = 0x18;
                }
                break;

                case EmulationProfile.TaitoTypeXGeneric:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x30;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                    JvsPackageEmulator.EnableTaitoStick   = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x18;
                }
                break;

                case EmulationProfile.BorderBreak:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x20;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                    InputCode.AnalogBytes[0] = 0x7F;     // Center analog
                    InputCode.AnalogBytes[2] = 0x7F;     // Center analog
                }
                break;

                case EmulationProfile.NamcoPokken:
                {
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_NBGI_Pokken;
                    JvsPackageEmulator.EnableNamco        = true;
                }
                break;

                case EmulationProfile.NamcoWmmt5:
                case EmulationProfile.NamcoMkdx:
                {
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_NBGI_MarioKart3;
                    JvsPackageEmulator.EnableNamco        = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x18;
                }
                break;

                case EmulationProfile.NamcoMachStorm:
                {
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_StarWars;
                    JvsPackageEmulator.EnableNamco        = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x18;
                }
                break;

                case EmulationProfile.ShiningForceCrossRaid:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x20;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                }
                break;

                case EmulationProfile.SegaJvsGoldenGun:
                case EmulationProfile.AfterBurnerClimax:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x20;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                }
                break;

                case EmulationProfile.SegaSonicAllStarsRacing:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x20;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                }
                break;

                case EmulationProfile.DevThing1:
                {
                    JvsPackageEmulator.JvsCommVersion         = 0x10;
                    JvsPackageEmulator.JvsVersion             = 0x30;
                    JvsPackageEmulator.JvsCommandRevision     = 0x13;
                    JvsPackageEmulator.JvsIdentifier          = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                    JvsPackageEmulator.EnableTaitoStick       = true;
                    JvsPackageEmulator.EnableTaitoBattleGear  = true;
                    JvsPackageEmulator.EnableDualJvsEmulation = true;
                    JvsPackageEmulator.JvsSwitchCount         = 0x18;
                }
                break;

                case EmulationProfile.VirtuaTennis4:
                case EmulationProfile.ArcadeLove:
                {
                    JvsPackageEmulator.JvsCommVersion         = 0x10;
                    JvsPackageEmulator.JvsVersion             = 0x20;
                    JvsPackageEmulator.JvsCommandRevision     = 0x13;
                    JvsPackageEmulator.JvsIdentifier          = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                    JvsPackageEmulator.EnableDualJvsEmulation = true;
                }
                break;

                case EmulationProfile.LGS:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x30;
                    JvsPackageEmulator.JvsVersion         = 0x30;
                    JvsPackageEmulator.JvsCommandRevision = 0x30;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_SegaLetsGoSafari;
                }
                break;

                case EmulationProfile.SegaJvs:
                case EmulationProfile.SegaJvsLetsGoIsland:
                case EmulationProfile.SegaJvsDreamRaiders:
                case EmulationProfile.ProjectDivaNu:
                case EmulationProfile.SegaInitialD:
                case EmulationProfile.SegaInitialDLindbergh:
                case EmulationProfile.SegaRacingClassic:
                default:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x10;
                    JvsPackageEmulator.JvsVersion         = 0x20;
                    JvsPackageEmulator.JvsCommandRevision = 0x13;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_Sega2005Jvs14572;
                }
                break;
                }
                _serialPortHandler.StopListening();
                Thread.Sleep(1000);
                _jvsThread = new Thread(() => _serialPortHandler.ListenPipe("TeknoParrot_JVS"));
                _jvsThread.Start();
                _processQueueThread = new Thread(_serialPortHandler.ProcessQueue);
                _processQueueThread.Start();
            }

            if (_parrotData.UseMouse && (InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoIsland || InputCode.ButtonMode == EmulationProfile.SegaJvsDreamRaiders || InputCode.ButtonMode == EmulationProfile.SegaJvsGoldenGun))
            {
                _diThread?.Abort(0);
                _diThread = null;
            }
            else
            {
                _diThread?.Abort(0);
                _diThread = CreateInputListenerThread(_parrotData.XInputMode);
            }

            // Wait before launching second thread.
            if (!_runEmuOnly)
            {
                Thread.Sleep(1000);
                _gameRunning = true;
                CreateGameProcess();
            }
            else
            {
                if (_parrotData.UseHaptic)
                {
                    if (InputCode.ButtonMode == EmulationProfile.SegaRacingClassic ||
                        InputCode.ButtonMode == EmulationProfile.EuropaRSegaRally3 ||
                        InputCode.ButtonMode == EmulationProfile.EuropaRFordRacing ||
                        InputCode.ButtonMode == EmulationProfile.SegaInitialD ||
                        InputCode.ButtonMode == EmulationProfile.WackyRaces ||
                        InputCode.ButtonMode == EmulationProfile.ChaseHq2 ||
                        InputCode.ButtonMode == EmulationProfile.NamcoWmmt5 ||
                        InputCode.ButtonMode == EmulationProfile.Outrun2SPX)
                    {
                        // TODO: NOT TESTED BEFORE COMMIT
                        var t = new Thread(() => FfbHelper.UseForceFeedback(_parrotData, ref _endCheckBox));
                        t.Start();
                    }
                }
            }
        }
        private void GameRunning_OnLoaded(object sender, RoutedEventArgs e)
        {
            JvsPackageEmulator.Initialize();
            if (InputCode.ButtonMode == EmulationProfile.EuropaRFordRacing || InputCode.ButtonMode == EmulationProfile.EuropaRSegaRally3)
            {
                if (_europa == null)
                {
                    _europa = new EuropaRPipeHandler();
                }
                _europa.StartListening(InputCode.ButtonMode == EmulationProfile.EuropaRSegaRally3);
            }
            if (InputCode.ButtonMode == EmulationProfile.FastIo)
            {
                if (_fastIo == null)
                {
                    _fastIo = new FastIoPipe();
                }
                _fastIo.StartListening();
            }
            if (_rawInputListener == null)
            {
                _rawInputListener = new RawInputListener();
            }

            if (InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoIsland || InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoJungle)
            {
                InputCode.AnalogBytes[0] = 127;
                InputCode.AnalogBytes[2] = 127;
                InputCode.AnalogBytes[4] = 127;
                InputCode.AnalogBytes[6] = 127;
            }
            else
            {
                InputCode.AnalogBytes[0] = 0;
                InputCode.AnalogBytes[2] = 0;
                InputCode.AnalogBytes[4] = 0;
                InputCode.AnalogBytes[6] = 0;
            }

            if (_parrotData.UseMouse && _gameProfile.GunGame)
            {
                _rawInputListener.ListenToDevice(InputCode.ButtonMode == EmulationProfile.SegaJvsGoldenGun || InputCode.ButtonMode == EmulationProfile.Hotd4);
            }

            switch (InputCode.ButtonMode)
            {
            case EmulationProfile.NamcoPokken:
                _controlSender = new Pokken();
                break;

            case EmulationProfile.ExBoard:
                _controlSender = new ExBoard();
                break;

            case EmulationProfile.GtiClub3:
                _controlSender = new GtiClub3();
                break;

            case EmulationProfile.Daytona3:
                _controlSender = new Daytona3();
                break;

            case EmulationProfile.GRID:
                _controlSender = new GRID();
                break;
            }

            _controlSender?.Start();

            if (_gameProfile.GunGame)
            {
                KillGunListener = false;
                LgiThread       = new Thread(HandleLgiControls);
                LgiThread.Start();
            }

            if (!_runEmuOnly)
            {
                WriteConfigIni();
            }

            if (InputCode.ButtonMode != EmulationProfile.EuropaRFordRacing && InputCode.ButtonMode != EmulationProfile.EuropaRSegaRally3 && InputCode.ButtonMode != EmulationProfile.FastIo)
            {
                // TODO: MAYBE MAKE THESE XML BASED?
                switch (InputCode.ButtonMode)
                {
                case EmulationProfile.VirtuaRLimit:
                case EmulationProfile.ChaseHq2:
                case EmulationProfile.WackyRaces:
                {
                    JvsPackageEmulator.EnableTaito    = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                }
                break;

                case EmulationProfile.TaitoTypeXBattleGear:
                {
                    JvsPackageEmulator.JvsVersion            = 0x30;
                    JvsPackageEmulator.EnableTaitoStick      = true;
                    JvsPackageEmulator.EnableTaitoBattleGear = true;
                    JvsPackageEmulator.JvsSwitchCount        = 0x18;
                }
                break;

                case EmulationProfile.TaitoTypeXGeneric:
                {
                    JvsPackageEmulator.JvsVersion       = 0x30;
                    JvsPackageEmulator.EnableTaitoStick = true;
                    JvsPackageEmulator.JvsSwitchCount   = 0x18;
                }
                break;

                case EmulationProfile.BorderBreak:
                {
                    InputCode.AnalogBytes[0] = 0x7F;         // Center analog
                    InputCode.AnalogBytes[2] = 0x7F;         // Center analog
                }
                break;

                case EmulationProfile.NamcoPokken:
                {
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_NBGI_Pokken;
                    JvsPackageEmulator.EnableNamco        = true;
                }
                break;

                case EmulationProfile.NamcoWmmt5:
                case EmulationProfile.NamcoMkdx:
                {
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_NBGI_MarioKart3;
                    JvsPackageEmulator.EnableNamco        = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x18;
                }
                break;

                case EmulationProfile.NamcoMachStorm:
                {
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_StarWars;
                    JvsPackageEmulator.EnableNamco        = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x18;
                }
                break;

                case EmulationProfile.DevThing1:
                {
                    JvsPackageEmulator.JvsVersion             = 0x30;
                    JvsPackageEmulator.EnableTaitoStick       = true;
                    JvsPackageEmulator.EnableTaitoBattleGear  = true;
                    JvsPackageEmulator.EnableDualJvsEmulation = true;
                    JvsPackageEmulator.JvsSwitchCount         = 0x18;
                }
                break;

                case EmulationProfile.VirtuaTennis4:
                case EmulationProfile.ArcadeLove:
                {
                    JvsPackageEmulator.EnableDualJvsEmulation = true;
                }
                break;

                case EmulationProfile.LGS:
                {
                    JvsPackageEmulator.JvsCommVersion     = 0x30;
                    JvsPackageEmulator.JvsVersion         = 0x30;
                    JvsPackageEmulator.JvsCommandRevision = 0x30;
                    JvsPackageEmulator.JvsIdentifier      = JvsHelper.JVS_IDENTIFIER_SegaLetsGoSafari;
                }
                break;
                }
                _serialPortHandler.StopListening();
                Thread.Sleep(1000);
                _jvsThread = new Thread(() => _serialPortHandler.ListenPipe("TeknoParrot_JVS"));
                _jvsThread.Start();
                _processQueueThread = new Thread(_serialPortHandler.ProcessQueue);
                _processQueueThread.Start();
            }

            if (_parrotData.UseMouse && _gameProfile.GunGame)
            {
                _diThread?.Abort(0);
                _diThread = null;
            }
            else
            {
                _diThread?.Abort(0);
                _diThread = CreateInputListenerThread(_parrotData.XInputMode);
            }

            if (_parrotData.UseDiscordRPC)
            {
                DiscordRPC.UpdatePresence(new DiscordRPC.RichPresence
                {
                    details       = _gameProfile.GameName,
                    largeImageKey = _gameProfile.GameName.Replace(" ", "").ToLower(),
                    //https://stackoverflow.com/a/17632585
                    startTimestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                });
            }

            // Wait before launching second thread.
            if (!_runEmuOnly)
            {
                Thread.Sleep(1000);
                _gameRunning = true;
                CreateGameProcess();
            }
            else
            {
                if (_parrotData.UseHaptic && _gameProfile.ForceFeedback)
                {
                    StartFfb();
                }
            }
        }
        public MainWindowViewModel()
        {
            _rawInputListener = new RawInputListener();

            Application.Current.MainWindow.Loaded += OnMainWindowLoaded;
        }
Example #7
0
        private void GameRunning_OnLoaded(object sender, RoutedEventArgs e)
        {
            JvsPackageEmulator.Initialize();
            switch (InputCode.ButtonMode)
            {
            case EmulationProfile.EuropaRFordRacing:
                if (_pipe == null)
                {
                    _pipe = new EuropaRPipe();
                }
                break;

            case EmulationProfile.EuropaRSegaRally3:
                if (_pipe == null)
                {
                    _pipe = new SegaRallyPipe();
                }
                break;

            case EmulationProfile.FastIo:
                if (_pipe == null)
                {
                    _pipe = new FastIOPipe();
                }
                break;

            case EmulationProfile.Theatrhythm:
                if (_pipe == null)
                {
                    _pipe = new FastIOPipe();
                }
                break;
            }

            _pipe?.Start(_runEmuOnly);

            var invertButtons =
                _gameProfile.ConfigValues.Any(x => x.FieldName == "Invert Buttons" && x.FieldValue == "1");

            if (invertButtons)
            {
                JvsPackageEmulator.InvertMaiMaiButtons = true;
            }

            if (_rawInputListener == null)
            {
                _rawInputListener = new RawInputListener();
            }

            bool flag = InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoIsland || InputCode.ButtonMode == EmulationProfile.SegaJvsLetsGoJungle || InputCode.ButtonMode == EmulationProfile.LuigisMansion;

            //fills 0, 2, 4, 6
            for (int i = 0; i <= 6; i += 2)
            {
                InputCode.AnalogBytes[i] = flag ? (byte)127 : (byte)0;
            }

            bool useMouseForGun =
                _gameProfile.ConfigValues.Any(x => x.FieldName == "UseMouseForGun" && x.FieldValue == "1");

            if (useMouseForGun && _gameProfile.GunGame)
            {
                _rawInputListener.ListenToDevice(_gameProfile.InvertedMouseAxis, _gameProfile);
            }

            switch (InputCode.ButtonMode)
            {
            case EmulationProfile.NamcoPokken:
                _controlSender = new Pokken();
                break;

            case EmulationProfile.ExBoard:
                _controlSender = new ExBoard();
                break;

            case EmulationProfile.GtiClub3:
                _controlSender = new GtiClub3();
                break;

            case EmulationProfile.Daytona3:
                _controlSender = new Daytona3();
                break;

            case EmulationProfile.GRID:
                _controlSender = new GRID();
                break;

            case EmulationProfile.RawThrillsFNF:
                _controlSender = new RawThrills();
                break;

            case EmulationProfile.LuigisMansion:
                _controlSender = new LuigisMansion();
                break;

            case EmulationProfile.GHA:
                _controlSender = new GHA();
                break;
            }

            _controlSender?.Start();

            if (_gameProfile.GunGame)
            {
                _killGunListener = false;
                if (_gameProfile.EmulationProfile == EmulationProfile.TooSpicy)
                {
                    new Thread(HandleGunControls2Spicy).Start();
                }
                else
                {
                    new Thread(HandleGunControls).Start();
                }
            }

            if (!_runEmuOnly)
            {
                WriteConfigIni();
            }

            if (InputCode.ButtonMode != EmulationProfile.EuropaRFordRacing &&
                InputCode.ButtonMode != EmulationProfile.EuropaRSegaRally3 &&
                InputCode.ButtonMode != EmulationProfile.Theatrhythm &&
                InputCode.ButtonMode != EmulationProfile.FastIo)
            {
                bool DualJvsEmulation = _gameProfile.ConfigValues.Any(x => x.FieldName == "DualJvsEmulation" && x.FieldValue == "1");

                // TODO: MAYBE MAKE THESE XML BASED?
                switch (InputCode.ButtonMode)
                {
                case EmulationProfile.VirtuaRLimit:
                case EmulationProfile.ChaseHq2:
                case EmulationProfile.WackyRaces:
                    JvsPackageEmulator.Taito          = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.TaitoTypeXBattleGear:
                    JvsPackageEmulator.JvsVersion      = 0x30;
                    JvsPackageEmulator.TaitoStick      = true;
                    JvsPackageEmulator.TaitoBattleGear = true;
                    JvsPackageEmulator.JvsSwitchCount  = 0x18;
                    break;

                case EmulationProfile.TaitoTypeXGeneric:
                    JvsPackageEmulator.JvsVersion     = 0x30;
                    JvsPackageEmulator.TaitoStick     = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.BorderBreak:
                    InputCode.AnalogBytes[0] = 0x7F;     // Center analog
                    InputCode.AnalogBytes[2] = 0x7F;     // Center analog
                    break;

                case EmulationProfile.NamcoPokken:
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.NBGI_Pokken;
                    JvsPackageEmulator.Namco = true;
                    break;

                case EmulationProfile.NamcoWmmt5:
                case EmulationProfile.NamcoMkdx:
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.NBGI_MarioKart3;
                    JvsPackageEmulator.Namco          = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.NamcoMachStorm:
                    JvsPackageEmulator.JvsVersion         = 0x31;
                    JvsPackageEmulator.JvsCommVersion     = 0x31;
                    JvsPackageEmulator.JvsCommandRevision = 0x31;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.NamcoMultipurpose;
                    JvsPackageEmulator.Namco          = true;
                    JvsPackageEmulator.JvsSwitchCount = 0x18;
                    break;

                case EmulationProfile.DevThing1:
                    JvsPackageEmulator.JvsVersion       = 0x30;
                    JvsPackageEmulator.TaitoStick       = true;
                    JvsPackageEmulator.TaitoBattleGear  = true;
                    JvsPackageEmulator.DualJvsEmulation = true;
                    JvsPackageEmulator.JvsSwitchCount   = 0x18;
                    break;

                case EmulationProfile.VirtuaTennis4:
                    JvsPackageEmulator.DualJvsEmulation = DualJvsEmulation;
                    break;

                case EmulationProfile.ArcadeLove:
                    JvsPackageEmulator.DualJvsEmulation = true;
                    break;

                case EmulationProfile.LGS:
                    JvsPackageEmulator.JvsCommVersion     = 0x30;
                    JvsPackageEmulator.JvsVersion         = 0x30;
                    JvsPackageEmulator.JvsCommandRevision = 0x30;
                    JvsPackageEmulator.JvsIdentifier      = JVSIdentifiers.SegaLetsGoSafari;
                    JvsPackageEmulator.LetsGoSafari       = true;
                    JvsPackageEmulator.JvsSwitchCount     = 0x16;
                    break;
                }

                _serialPortHandler.StopListening();
                Thread.Sleep(1000);
                new Thread(() => _serialPortHandler.ListenPipe("TeknoParrot_JVS")).Start();
                new Thread(_serialPortHandler.ProcessQueue).Start();
            }

            if (useMouseForGun && _gameProfile.GunGame)
            {
                _diThread?.Abort(0);
                _diThread = null;
            }
            else
            {
                _diThread?.Abort(0);
                _diThread = CreateInputListenerThread(
                    _gameProfile.ConfigValues.Any(x => x.FieldName == "XInput" && x.FieldValue == "1"));
            }

            if (Lazydata.ParrotData.UseDiscordRPC)
            {
                DiscordRPC.UpdatePresence(new DiscordRPC.RichPresence
                {
                    details       = _gameProfile.GameName,
                    largeImageKey = _gameProfile.GameName.Replace(" ", "").ToLower(),
                    //https://stackoverflow.com/a/17632585
                    startTimestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds
                });
            }

            // Wait before launching second thread.
            if (!_runEmuOnly)
            {
                Thread.Sleep(1000);
                CreateGameProcess();
            }
            else
            {
#if DEBUG
                if (jvsDebug != null)
                {
                    new Thread(() =>
                    {
                        while (true)
                        {
                            if (jvsDebug.JvsOverride)
                            {
                                Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(jvsDebug.DoCheckBoxesDude));
                            }
                        }
                    }).Start();
                }
#endif
            }
        }
Example #8
0
        private void GameRunning_OnLoaded(object sender, RoutedEventArgs e)
        {
            var rawInput = new RawInputListener();

            if (_settingsData.UseMouse && (InputCode.ButtonMode == GameProfiles.LetsGoIsland || InputCode.ButtonMode == GameProfiles.SegaDreamRaiders || InputCode.ButtonMode == GameProfiles.GoldenGun))
            {
                rawInput.ListenToDevice(InputCode.ButtonMode == GameProfiles.GoldenGun);
            }
            var directInputListener = new DirectInputListener();
            var xinputListener      = new XInputListener();
            KeyboardController kc   = new KeyboardController();
            var jvsThread           = new Thread(() => _serialPortHandler.ListenSerial("COM14"));

            jvsThread.Start();
            var processQueueThread = new Thread(_serialPortHandler.ProcessQueue);

            processQueueThread.Start();
            Thread directInputThreadP1;

            if (_settingsData.UseMouse && (InputCode.ButtonMode == GameProfiles.LetsGoIsland || InputCode.ButtonMode == GameProfiles.SegaDreamRaiders || InputCode.ButtonMode == GameProfiles.GoldenGun))
            {
                directInputThreadP1 = null;
            }
            else
            {
                directInputThreadP1 = CreateDirectInputThread(_settingsData.PlayerOneGuid, 1, directInputListener, xinputListener, _joystickMapping1, _xinputMapping1, _settingsData.XInputMode);
            }

            // Wait before launching second thread.
            Thread.Sleep(1000);
            var directInputThreadP2 = CreateDirectInputThread(_settingsData.PlayerTwoGuid, 2, directInputListener, xinputListener, _joystickMapping2, _xinputMapping2, _settingsData.XInputMode);

            _gameRunning = true;
            if (_settingsData.UseKeyboard && (InputCode.ButtonMode == GameProfiles.MeltyBlood || InputCode.ButtonMode == GameProfiles.VirtuaTennis4))
            {
                kc.Subscribe(directInputThreadP1 == null, directInputThreadP2 == null);
            }
            var gameThread = new Thread(() =>
            {
                ProcessStartInfo info;
                if (_isTest)
                {
                    if (_testMenuIsExe)
                    {
                        info = new ProcessStartInfo("ParrotLoader.exe", $"\"{Path.Combine(Path.GetDirectoryName(_gameLocation), _testMenuExe)}\" {_testMenuString}");
                    }
                    else
                    {
                        info = new ProcessStartInfo("ParrotLoader.exe", $"\"{_gameLocation}\" {_testMenuString}");
                    }
                }
                else
                {
                    info = new ProcessStartInfo("ParrotLoader.exe", $"\"{_gameLocation}\"");
                }
                info.UseShellExecute = false;
                info.WindowStyle     = ProcessWindowStyle.Normal;
                var process          = Process.Start(info);
                while (!process.HasExited)
                {
                    // We only resurrect this since I had no crashes ever in the other threads. Feel free to improve!
                    if (directInputThreadP1 != null && !directInputThreadP1.IsAlive)
                    {
                        directInputThreadP1 = CreateDirectInputThread(_settingsData.PlayerOneGuid, 1, directInputListener, xinputListener, _joystickMapping1, _xinputMapping1, _settingsData.XInputMode);
                    }

                    if (directInputThreadP2 != null && !directInputThreadP2.IsAlive)
                    {
                        directInputThreadP2 = CreateDirectInputThread(_settingsData.PlayerTwoGuid, 2, directInputListener, xinputListener, _joystickMapping2, _xinputMapping2, _settingsData.XInputMode);
                    }
                    Thread.Sleep(5000);
                }
                _serialPortHandler.KillMe  = true;
                directInputListener.KillMe = true;
                xinputListener.KillMe      = true;
                _gameRunning = false;
                Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(this.Close));
                if (_settingsData.UseKeyboard && (InputCode.ButtonMode == GameProfiles.MeltyBlood || InputCode.ButtonMode == GameProfiles.VirtuaTennis4))
                {
                    kc.Unsubscribe();
                }
                if (_settingsData.UseMouse && (InputCode.ButtonMode == GameProfiles.LetsGoIsland || InputCode.ButtonMode == GameProfiles.SegaDreamRaiders || InputCode.ButtonMode == GameProfiles.GoldenGun))
                {
                    rawInput.StopListening();
                }
            });

            gameThread.Start();
        }