Esempio n. 1
0
 /// <summary>
 /// Loads the settings data file.
 /// </summary>
 private void LoadParrotData()
 {
     try
     {
         if (!File.Exists("ParrotData.xml"))
         {
             MessageBox.Show("Seems this is first time you are running me, please set emulation settings.",
                             "Hello World", MessageBoxButton.OK, MessageBoxImage.Information);
             _parrotData         = new ParrotData();
             Lazydata.ParrotData = _parrotData;
             JoystickHelper.Serialize(_parrotData);
             return;
         }
         _parrotData = JoystickHelper.DeSerialize();
         if (_parrotData == null)
         {
             _parrotData         = new ParrotData();
             Lazydata.ParrotData = _parrotData;
             JoystickHelper.Serialize(_parrotData);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(
             $"Exception happened during loading ParrotData.xml! Generate new one by saving!{Environment.NewLine}{Environment.NewLine}{e}",
             "Error", MessageBoxButton.OK,
             MessageBoxImage.Error);
     }
 }
Esempio n. 2
0
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            if (SingleApplicationDetector.IsRunning())
            {
                if (MessageBox.Show(
                        "Detected already running TeknoParrot Ui, want me to close it for you?", "Error",
                        MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
                {
                    TerminateProcesses();
                }
                else
                {
                    Application.Current.Shutdown(0);
                    return;
                }
            }
            if (File.Exists("DumbJVSManager.exe"))
            {
                MessageBox.Show(
                    "Seems you have extracted me to directory of old TeknoParrot, please extract me to a new directory instead!",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown(0);
                return;
            }
            var parrotData = JoystickHelper.DeSerialize();

            if (parrotData == null)
            {
                StartApp();
                return;
            }
            if (e.Args.Length != 0)
            {
                // Process command args
                if (HandleArgs(e.Args))
                {
                    // Args ok, let's do stuff
                    if (_emuOnly)
                    {
                        TeknoParrotUi.Views.GameRunning g = new TeknoParrotUi.Views.GameRunning(_profile, _test, parrotData, _profile.TestMenuParameter,
                                                                                                _profile.TestMenuIsExecutable, _profile.TestMenuExtraParameters, true);
                        g.Show();
                        return;
                    }
                    else
                    {
                        TeknoParrotUi.Views.GameRunning g = new TeknoParrotUi.Views.GameRunning(_profile, _test, parrotData, _profile.TestMenuParameter,
                                                                                                _profile.TestMenuIsExecutable, _profile.TestMenuExtraParameters, false);
                        g.Show();
                        return;
                    }
                }
            }
            StartApp();
        }
        public SettingsControl(ContentControl control, Views.Library library)
        {
            InitializeComponent();

            // reload ParrotData from file
            JoystickHelper.DeSerialize();

            ChkUseSto0ZCheckBox.IsChecked = Lazydata.ParrotData.UseSto0ZDrivingHack;
            sTo0zZonePercent.Value        = Lazydata.ParrotData.StoozPercent;
            ChkSaveLastPlayed.IsChecked   = Lazydata.ParrotData.SaveLastPlayed;
            ChkUseDiscordRPC.IsChecked    = Lazydata.ParrotData.UseDiscordRPC;
            ChkConfirmExit.IsChecked      = Lazydata.ParrotData.ConfirmExit;
            ChkCheckForUpdates.IsChecked  = Lazydata.ParrotData.CheckForUpdates;
            ChkDownloadIcons.IsChecked    = Lazydata.ParrotData.DownloadIcons;
            ChkSilentMode.IsChecked       = Lazydata.ParrotData.SilentMode;
            ChkUiDisableHardwareAcceleration.IsChecked = Lazydata.ParrotData.UiDisableHardwareAcceleration;
            ChkFullAxisGas.IsChecked      = Lazydata.ParrotData.FullAxisGas;
            ChkFullAxisBrake.IsChecked    = Lazydata.ParrotData.FullAxisBrake;
            ChkReverseAxisGas.IsChecked   = Lazydata.ParrotData.ReverseAxisGas;
            ChkReverseAxisBrake.IsChecked = Lazydata.ParrotData.ReverseAxisBrake;
            textBoxExitGameKey.Text       = Lazydata.ParrotData.ExitGameKey;
            textBoxPauseGameKey.Text      = Lazydata.ParrotData.PauseGameKey;
            textBoxScoreSubmissionID.Text = Lazydata.ParrotData.ScoreSubmissionID;
            textBoxScoreCollapseKey.Text  = Lazydata.ParrotData.ScoreCollapseGUIKey;

            UiColour.ItemsSource         = new SwatchesProvider().Swatches.Select(a => a.Name).ToList();
            UiColour.SelectedItem        = Lazydata.ParrotData.UiColour;
            ChkUiDarkMode.IsChecked      = Lazydata.ParrotData.UiDarkMode;
            ChkUiHolidayThemes.IsChecked = Lazydata.ParrotData.UiHolidayThemes;

            if (App.IsPatreon())
            {
                UiPatreon.Visibility = Visibility.Visible;
            }
            else
            {
                UiPatreon.Visibility = Visibility.Collapsed;
            }

            _contentControl = control;
            _library        = library;
        }
Esempio n. 4
0
 /// <summary>
 /// Loads the settings data file.
 /// </summary>
 private static bool LoadSettingsData()
 {
     try
     {
         if (!File.Exists("SettingsData.xml"))
         {
             Console.WriteLine("Please use the UI to set config!");
             return(false);
         }
         _settingsData = JoystickHelper.DeSerialize();
         if (_settingsData == null)
         {
             _settingsData = new SettingsData();
             JoystickHelper.Serialize(_settingsData);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"Exception happened during loading SettingsData.xml! Generate new one by saving!{Environment.NewLine}{Environment.NewLine}{e}");
         return(false);
     }
     return(true);
 }
        public SettingsControl(ContentControl control, Views.Library library)
        {
            InitializeComponent();

            // reload ParrotData from file
            JoystickHelper.DeSerialize();

            ChkUseSto0ZCheckBox.IsChecked = Lazydata.ParrotData.UseSto0ZDrivingHack;
            sTo0zZonePercent.Value        = Lazydata.ParrotData.StoozPercent;
            ChkSaveLastPlayed.IsChecked   = Lazydata.ParrotData.SaveLastPlayed;
            ChkUseDiscordRPC.IsChecked    = Lazydata.ParrotData.UseDiscordRPC;
            ChkConfirmExit.IsChecked      = Lazydata.ParrotData.ConfirmExit;
            ChkCheckForUpdates.IsChecked  = Lazydata.ParrotData.CheckForUpdates;
            ChkSilentMode.IsChecked       = Lazydata.ParrotData.SilentMode;
            ChkFullAxisGas.IsChecked      = Lazydata.ParrotData.FullAxisGas;
            ChkFullAxisBrake.IsChecked    = Lazydata.ParrotData.FullAxisBrake;
            ChkReverseAxisGas.IsChecked   = Lazydata.ParrotData.ReverseAxisGas;
            ChkReverseAxisBrake.IsChecked = Lazydata.ParrotData.ReverseAxisBrake;
            GunSensitivityPlayer1.Value   = Lazydata.ParrotData.GunSensitivityPlayer1;
            GunSensitivityPlayer2.Value   = Lazydata.ParrotData.GunSensitivityPlayer2;

            _contentControl = control;
            _library        = library;
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            if (!LoadSettingsData())
            {
                return;
            }
            var last = (int)Enum.GetValues(typeof(GameProfiles)).Cast <GameProfiles>().Last();

            if (args.Length != 1)
            {
                PrintGameModes(last);
                return;
            }

            int gameSelection;

            if (!int.TryParse(args[0], out gameSelection))
            {
                PrintGameModes(last);
                return;
            }

            if (gameSelection > last)
            {
                PrintGameModes(last);
                return;
            }

            JoystickMapping jmap1 = null;
            JoystickMapping jmap2 = null;

            try
            {
                if (File.Exists("JoystickMapping1.xml"))
                {
                    jmap1 = JoystickHelper.DeSerialize(1);
                }

                if (File.Exists("JoystickMapping2.xml"))
                {
                    jmap2 = JoystickHelper.DeSerialize(2);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Loading joystick mapping failed with error: {ex.InnerException} {ex.Message}");
                return;
            }

            if (jmap1 == null)
            {
                jmap1 = new JoystickMapping();
            }

            if (jmap2 == null)
            {
                jmap2 = new JoystickMapping();
            }

            InputCode.ButtonMode = (GameProfiles)gameSelection;
            var _serialPortHandler  = new SerialPortHandler();
            var directInputListener = new DirectInputListener();
            KeyboardController kc   = new KeyboardController();
            var jvsThread           = new Thread(() => _serialPortHandler.ListenSerial("COM14"));

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

            processQueueThread.Start();
            var directInputThreadP1 = CreateDirectInputThread(_settingsData.PlayerOneGuid, 1, directInputListener, jmap1);

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

            if (_settingsData.UseKeyboard)
            {
                kc.Subscribe(directInputThreadP1 == null, directInputThreadP2 == null);
            }
            var gameThread = new Thread(() =>
            {
                while (true)
                {
                    // 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, jmap1);
                    }

                    if (directInputThreadP2 != null && !directInputThreadP2.IsAlive)
                    {
                        directInputThreadP2 = CreateDirectInputThread(_settingsData.PlayerTwoGuid, 2, directInputListener, jmap2);
                    }
                    Thread.Sleep(5000);
                }
            });

            gameThread.Start();
            while (gameThread.IsAlive)
            {
                Thread.Sleep(1000);
            }
        }
Esempio n. 7
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Localization testing without changing system language.
            // Language code list: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");

            if (SingleApplicationDetector.IsRunning())
            {
                if ((e.Args.Any(x => x.StartsWith("--profile=")) && e.Args.All(x => x != "--emuonly")) || (e.Args.Any(x => x.StartsWith("--profile=")) && e.Args.Any(x => x == "--emuonly")))
                {
                }
                else
                {
                    if (MessageBoxHelper.ErrorYesNo(TeknoParrotUi.Properties.Resources.ErrorAlreadyRunning))
                    {
                        TerminateProcesses();
                    }
                    else
                    {
                        Current.Shutdown(0);
                        return;
                    }
                }
            }

            if (File.Exists("DumbJVSManager.exe"))
            {
                MessageBoxHelper.ErrorOK(TeknoParrotUi.Properties.Resources.ErrorOldTeknoParrotDirectory);
                Current.Shutdown(0);
                return;
            }

            // updater cleanup
            var bakfiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.bak", SearchOption.AllDirectories);

            foreach (var file in bakfiles)
            {
                try
                {
                    Debug.WriteLine($"Deleting old updater file {file}");
                    File.Delete(file);
                }
                catch
                {
                    // ignore..
                }
            }

            // old description file cleanup
            var olddescriptions = Directory.GetFiles("Descriptions", "*.xml");

            foreach (var file in olddescriptions)
            {
                try
                {
                    Debug.WriteLine($"Deleting old description file {file}");
                    File.Delete(file);
                }
                catch
                {
                    // ignore..
                }
            }

            JoystickHelper.DeSerialize();

            Current.Resources.MergedDictionaries.Clear();
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString($"MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString("MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString($"MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.LightBlue.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString("MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml"))
            });

            LoadTheme(Lazydata.ParrotData.UiColour, Lazydata.ParrotData.UiDarkMode, Lazydata.ParrotData.UiHolidayThemes);

            if (Lazydata.ParrotData.UiDisableHardwareAcceleration)
            {
                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            }

            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            if (e.Args.Length != 0)
            {
                // Process command args
                if (HandleArgs(e.Args) && Views.Library.ValidateAndRun(_profile, out var loader, out var dll, _emuOnly))
                {
                    var gamerunning = new Views.GameRunning(_profile, loader, dll, _test, _emuOnly, _profileLaunch);

                    // Args ok, let's do stuff
                    var window = new Window
                    {
                        Title     = "GameRunning",
                        Content   = gamerunning,
                        MaxWidth  = 800,
                        MaxHeight = 800,
                    };

                    //             d:DesignHeight="800" d:DesignWidth="800" Loaded="GameRunning_OnLoaded" Unloaded="GameRunning_OnUnloaded">
                    window.Dispatcher.ShutdownStarted += (x, x2) => gamerunning.GameRunning_OnUnloaded(null, null);

                    window.Show();

                    return;
                }
            }
            DiscordRPC.StartOrShutdown();

            StartApp();
        }
Esempio n. 8
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (SingleApplicationDetector.IsRunning())
            {
                if ((e.Args.Any(x => x.StartsWith("--profile=")) && e.Args.All(x => x != "--emuonly")) || (e.Args.Any(x => x.StartsWith("--profile=")) && e.Args.Any(x => x == "--emuonly")))
                {
                }
                else
                {
                    if (MessageBox.Show(
                            "TeknoParrot UI seems to already be running, want me to close it?", "Error",
                            MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
                    {
                        TerminateProcesses();
                    }
                    else
                    {
                        Application.Current.Shutdown(0);
                        return;
                    }
                }
            }
            if (File.Exists("DumbJVSManager.exe"))
            {
                MessageBox.Show(
                    "Seems you have extracted me to directory of old TeknoParrot, please extract me to a new directory instead!",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown(0);
                return;
            }
            var parrotData = JoystickHelper.DeSerialize();

            if (parrotData == null)
            {
                StartApp();
                return;
            }

            if (parrotData.UseDiscordRPC && File.Exists("discord-rpc.dll"))
            {
                DiscordRPC.Initialize(APP_ID, IntPtr.Zero, false, null);
            }

            if (e.Args.Length != 0)
            {
                // Process command args
                if (HandleArgs(e.Args))
                {
                    // Args ok, let's do stuff
                    Window window = new Window
                    {
                        Title   = "GameRunning",
                        Content = new TeknoParrotUi.Views.GameRunning(_profile, _test, parrotData, _profile.TestMenuParameter,
                                                                      _profile.TestMenuIsExecutable, _profile.TestMenuExtraParameters, _emuOnly, _profileLaunch),
                        MaxWidth  = 800,
                        MaxHeight = 800
                    };
                    window.Show();
                    return;
                }
            }
            StartApp();
        }
Esempio n. 9
0
 private void LoadPlayerKeys(int playerNumber)
 {
     try
     {
         if (playerNumber == 1)
         {
             if (File.Exists("JoystickMapping1.xml"))
             {
                 var map = JoystickHelper.DeSerialize(1);
                 GetJoystickInformation(TxtButton1, map.Button1);
                 GetJoystickInformation(TxtButton2, map.Button2);
                 GetJoystickInformation(TxtButton3, map.Button3);
                 GetJoystickInformation(TxtButton4, map.Button4);
                 GetJoystickInformation(TxtButton5, map.Button5);
                 GetJoystickInformation(TxtButton6, map.Button6);
                 GetJoystickInformation(TxtStart, map.Start);
                 GetJoystickInformation(TxtService, map.Service);
                 GetJoystickInformation(TxtTestSw, map.Test);
                 GetJoystickInformation(TxtUp, map.Up);
                 GetJoystickInformation(TxtDown, map.Down);
                 GetJoystickInformation(TxtLeft, map.Left);
                 GetJoystickInformation(TxtRight, map.Right);
                 GetJoystickInformation(TxtSrcGearChange1, map.SrcGearChange1);
                 GetJoystickInformation(TxtSrcGearChange2, map.SrcGearChange2);
                 GetJoystickInformation(TxtSrcGearChange3, map.SrcGearChange3);
                 GetJoystickInformation(TxtSrcGearChange4, map.SrcGearChange4);
                 GetJoystickInformation(TxtSrcViewChange1, map.SrcViewChange1);
                 GetJoystickInformation(TxtSrcViewChange2, map.SrcViewChange2);
                 GetJoystickInformation(TxtSrcViewChange3, map.SrcViewChange3);
                 GetJoystickInformation(TxtSrcViewChange4, map.SrcViewChange4);
                 GetJoystickInformation(TxtSonicItemButton, map.SonicItem);
                 GetJoystickInformation(TxtGunTrigger, map.GunTrigger);
                 GetJoystickInformation(TxtLgiLeft, map.GunLeft);
                 GetJoystickInformation(TxtLgiRight, map.GunRight);
                 GetJoystickInformation(TxtLgiUp, map.GunUp);
                 GetJoystickInformation(TxtLgiDown, map.GunDown);
                 GetJoystickInformation(TxtWheel, map.WheelAxis);
                 GetJoystickInformation(TxtGas, map.GasAxis, false, true);
                 GetJoystickInformation(TxtBrake, map.BrakeAxis, true);
                 GetJoystickInformation(TxtInitialD6ShiftUp, map.InitialD6ShiftUp);
                 GetJoystickInformation(TxtInitialD6ShiftDown, map.InitialD6ShiftDown);
                 GetJoystickInformation(TxtInitialD6ViewChange, map.InitialD6ViewChange);
                 GetJoystickInformation(TxtInitialD6MenuDown, map.InitialD6MenuDown);
                 GetJoystickInformation(TxtInitialD6MenuUp, map.InitialD6MenuUp);
                 GetJoystickInformation(TxtInitialD6MenuLeft, map.InitialD6MenuLeft);
                 GetJoystickInformation(TxtInitialD6MenuRight, map.InitialD6MenuRight);
                 if (map.GunMultiplier >= 1 && map.GunMultiplier <= 10)
                 {
                     IUpDownMovementMultiplier.Value = map.GunMultiplier;
                 }
                 else
                 {
                     IUpDownMovementMultiplier.Value = 1;
                 }
             }
         }
         else if (playerNumber == 2)
         {
             if (File.Exists("JoystickMapping2.xml"))
             {
                 var map = JoystickHelper.DeSerialize(2);
                 GetJoystickInformation(TxtButton1, map.Button1);
                 GetJoystickInformation(TxtButton2, map.Button2);
                 GetJoystickInformation(TxtButton3, map.Button3);
                 GetJoystickInformation(TxtButton4, map.Button4);
                 GetJoystickInformation(TxtButton5, map.Button5);
                 GetJoystickInformation(TxtButton6, map.Button6);
                 GetJoystickInformation(TxtStart, map.Start);
                 GetJoystickInformation(TxtService, map.Service);
                 GetJoystickInformation(TxtTestSw, map.Test);
                 GetJoystickInformation(TxtUp, map.Up);
                 GetJoystickInformation(TxtDown, map.Down);
                 GetJoystickInformation(TxtLeft, map.Left);
                 GetJoystickInformation(TxtRight, map.Right);
                 GetJoystickInformation(TxtGunTrigger, map.GunTrigger);
                 GetJoystickInformation(TxtLgiLeft, map.GunLeft);
                 GetJoystickInformation(TxtLgiRight, map.GunRight);
                 GetJoystickInformation(TxtLgiUp, map.GunUp);
                 GetJoystickInformation(TxtLgiDown, map.GunDown);
                 if (map.GunMultiplier >= 1 && map.GunMultiplier <= 10)
                 {
                     IUpDownMovementMultiplier.Value = map.GunMultiplier;
                 }
                 else
                 {
                     IUpDownMovementMultiplier.Value = 1;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show($"Loading failed with error: {ex.InnerException} {ex.Message}", "Error", MessageBoxButton.OK,
                         MessageBoxImage.Error);
     }
 }
Esempio n. 10
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // This fixes the paths when the ui is started through the command line in a different folder
            Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((_, ex) => {
                // give us the exception in english
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en");
                var exceptiontext = (ex.ExceptionObject as Exception).ToString();
                MessageBoxHelper.ErrorOK($"TeknoParrotUI ran into an exception!\nPlease send exception.txt to the #teknoparrothelp channel on Discord or create a Github issue!\n{exceptiontext}");
                File.WriteAllText("exception.txt", exceptiontext);
                Environment.Exit(1);
            });
            // Localization testing without changing system language.
            // Language code list: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");

            //this'll sort dumb stupid tp online gay shit
            HandleArgs(e.Args);
            if (!_tpOnline)
            {
                if (Process.GetProcessesByName("TeknoParrotUi").Where((p) => p.Id != Process.GetCurrentProcess().Id)
                    .Count() > 0)
                {
                    if (MessageBoxHelper.ErrorYesNo(TeknoParrotUi.Properties.Resources.ErrorAlreadyRunning))
                    {
                        TerminateProcesses();
                    }
                    else
                    {
                        Current.Shutdown(0);
                        return;
                    }
                }
            }

            if (File.Exists("DumbJVSManager.exe"))
            {
                MessageBoxHelper.ErrorOK(TeknoParrotUi.Properties.Resources.ErrorOldTeknoParrotDirectory);
                Current.Shutdown(0);
                return;
            }

            // updater cleanup
            var bakfiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.bak", SearchOption.AllDirectories);

            foreach (var file in bakfiles)
            {
                try
                {
                    Debug.WriteLine($"Deleting old updater file {file}");
                    File.Delete(file);
                }
                catch
                {
                    // ignore..
                }
            }

            // old description file cleanup
            var olddescriptions = Directory.GetFiles("Descriptions", "*.xml");

            foreach (var file in olddescriptions)
            {
                try
                {
                    Debug.WriteLine($"Deleting old description file {file}");
                    File.Delete(file);
                }
                catch
                {
                    // ignore..
                }
            }

            JoystickHelper.DeSerialize();

            Current.Resources.MergedDictionaries.Clear();
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString($"MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString("MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString($"MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.LightBlue.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString("MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml"))
            });

            LoadTheme(Lazydata.ParrotData.UiColour, Lazydata.ParrotData.UiDarkMode, Lazydata.ParrotData.UiHolidayThemes);

            if (Lazydata.ParrotData.UiDisableHardwareAcceleration)
            {
                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            }

            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            if (e.Args.Length != 0)
            {
                // Process command args
                if (HandleArgs(e.Args) && Views.Library.ValidateAndRun(_profile, out var loader, out var dll, _emuOnly, null))
                {
                    var gamerunning = new Views.GameRunning(_profile, loader, dll, _test, _emuOnly, _profileLaunch);
                    // Args ok, let's do stuff
                    var window = new Window
                    {
                        //f**k you nezarn no more resizing smh /s
                        Title     = "GameRunning",
                        Content   = gamerunning,
                        MaxWidth  = 800,
                        MinWidth  = 800,
                        MaxHeight = 800,
                        MinHeight = 800,
                    };
                    if (_startMin)
                    {
                        window.WindowState = WindowState.Minimized;
                    }

                    //             d:DesignHeight="800" d:DesignWidth="800" Loaded="GameRunning_OnLoaded" Unloaded="GameRunning_OnUnloaded">
                    window.Dispatcher.ShutdownStarted += (x, x2) => gamerunning.GameRunning_OnUnloaded(null, null);

                    window.Show();

                    return;
                }
            }
            DiscordRPC.StartOrShutdown();

            StartApp();
        }
Esempio n. 11
0
        /// <summary>
        /// Validates that the game exists and then runs it with the emulator.
        /// </summary>
        /// <param name="gameLocation">Game executable location.</param>
        /// <param name="gameProfile">Input profile.</param>
        /// <param name="testMenuString">Command to run test menu.</param>
        /// <param name="testMenuIsExe">If uses separate exe.</param>
        /// <param name="exeName">Test menu exe name.</param>
        private void ValidateAndRun(string gameLocation, GameProfiles gameProfile, string testMenuString, bool testMenuIsExe = false, string exeName = "")
        {
            if (!File.Exists(gameLocation))
            {
                MessageBox.Show($"Cannot find game exe at: {gameLocation}", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            if (!File.Exists("ParrotLoader.exe"))
            {
                MessageBox.Show($"Cannot find ParrotLoader.exe", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            if (!File.Exists("TeknoParrot.dll"))
            {
                MessageBox.Show($"Cannot find TeknoParrot.dll", "Error", MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }
            var testMenu = ChkTestMenu.IsChecked != null && ChkTestMenu.IsChecked.Value;

            JoystickMapping jmap1 = null;
            JoystickMapping jmap2 = null;

            XInputMapping xmap1 = null;
            XInputMapping xmap2 = null;

            try
            {
                if (File.Exists("JoystickMapping1.xml"))
                {
                    jmap1 = JoystickHelper.DeSerialize(1);
                }

                if (File.Exists("JoystickMapping2.xml"))
                {
                    jmap2 = JoystickHelper.DeSerialize(2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Loading joystick mapping failed with error: {ex.InnerException} {ex.Message}", "Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            try
            {
                if (File.Exists("XInputMapping1.xml"))
                {
                    xmap1 = JoystickHelper.DeSerializeXInput(1);
                }

                if (File.Exists("XInputMapping2.xml"))
                {
                    xmap2 = JoystickHelper.DeSerializeXInput(2);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Loading joystick mapping failed with error: {ex.InnerException} {ex.Message}", "Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
                return;
            }

            if (jmap1 == null)
            {
                jmap1 = new JoystickMapping();
            }

            if (jmap2 == null)
            {
                jmap2 = new JoystickMapping();
            }

            if (xmap1 == null)
            {
                xmap1 = new XInputMapping();
            }

            if (xmap2 == null)
            {
                xmap2 = new XInputMapping();
            }

            var gameRunning = new GameRunning(gameLocation, gameProfile, testMenu, _settingsData, testMenuString, jmap1, jmap2, xmap1, xmap2, testMenuIsExe, exeName);

            gameRunning.ShowDialog();
            gameRunning.Close();
        }
Esempio n. 12
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            if (SingleApplicationDetector.IsRunning())
            {
                if ((e.Args.Any(x => x.StartsWith("--profile=")) && e.Args.All(x => x != "--emuonly")) || (e.Args.Any(x => x.StartsWith("--profile=")) && e.Args.Any(x => x == "--emuonly")))
                {
                }
                else
                {
                    if (MessageBox.Show(
                            "TeknoParrot UI seems to already be running, want me to close it?", "Error",
                            MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes)
                    {
                        TerminateProcesses();
                    }
                    else
                    {
                        Current.Shutdown(0);
                        return;
                    }
                }
            }

            if (File.Exists("DumbJVSManager.exe"))
            {
                MessageBox.Show(
                    "Seems you have extracted me to directory of old TeknoParrot, please extract me to a new directory instead!",
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Application.Current.Shutdown(0);
                return;
            }

            // updater cleanup
            var bakfiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.bak", SearchOption.AllDirectories);

            foreach (var file in bakfiles)
            {
                try
                {
                    Debug.WriteLine($"Deleting old updater file {file}");
                    File.Delete(file);
                }
                catch
                {
                    // ignore..
                }
            }

            // old description file cleanup
            var olddescriptions = Directory.GetFiles("Descriptions", "*.xml");

            foreach (var file in olddescriptions)
            {
                try
                {
                    Debug.WriteLine($"Deleting old description file {file}");
                    File.Delete(file);
                }
                catch
                {
                    // ignore..
                }
            }

            JoystickHelper.DeSerialize();

            Current.Resources.MergedDictionaries.Clear();
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString($"MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString("MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString($"MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.LightBlue.xaml"))
            });
            Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
            {
                Source = new Uri(GetResourceString("MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml"))
            });

            LoadTheme(Lazydata.ParrotData.UiColour, Lazydata.ParrotData.UiDarkMode);

            if (Lazydata.ParrotData.UiDisableHardwareAcceleration)
            {
                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            }

            ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            if (e.Args.Length != 0)
            {
                // Process command args
                if (HandleArgs(e.Args) && Views.Library.ValidateAndRun(_profile, out var loader, out var dll, _emuOnly))
                {
                    var gamerunning = new Views.GameRunning(_profile, loader, dll, _test, _emuOnly, _profileLaunch);

                    // Args ok, let's do stuff
                    var window = new Window
                    {
                        Title     = "GameRunning",
                        Content   = gamerunning,
                        MaxWidth  = 800,
                        MaxHeight = 800,
                    };

                    //             d:DesignHeight="800" d:DesignWidth="800" Loaded="GameRunning_OnLoaded" Unloaded="GameRunning_OnUnloaded">
                    window.Dispatcher.ShutdownStarted += (x, x2) => gamerunning.GameRunning_OnUnloaded(null, null);

                    window.Show();

                    return;
                }
            }
            DiscordRPC.StartOrShutdown();

            StartApp();
        }