コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: Estrol/X3Solo
        public MainWindow()
        {
            InitializeComponent();

            config               = new();
            UiConsole            = new();
            UiConsole.OnMessage += (object o, string message) => {
                if (!server.Ready)
                {
                    Log.Write("Server not yet running!");
                    return;
                }

                server.SendMessage(message);
            };

            Console.SetOut(new MultiTextWriter(new ControlWriter(UiConsole), Console.Out));

            m_main.Visibility    = Visibility.Visible;
            m_setting.Visibility = Visibility.Hidden;
            m_about.Visibility   = Visibility.Hidden;
            m_about_us.Text      = "                            X3Solo\r\n   " +
                                   "               X3-JAM Solo Version\r\n         Not supp" +
                                   "ort Multiplayer Session\r\n\r\nSupported Client Version" +
                                   "s\r\n- 9you O2-JAM 1.8 and 1.5";

            server      = new Main();
            f_port.Text = string.Format(CultureInfo.CurrentCulture, "{0}", server.m_config.ServerPort);
            f_name.Text = server.m_config.Name;

            server.OnError += (object o, Exception e) => {
                if (GameProc != null)
                {
                    ProcessUtil.SuspendProcess(GameProc.Id);
                }

                if (e is InvalidOpcodeException err)
                {
                    if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\crashlog"))
                    {
                        Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"\crashlog");
                    }

                    string log = "";
                    log += "[Crash Summary]\n";
                    log += $"Opcode: {err.Opcode:X4}\n";
                    log += $"Full Data: {err.FullDataString}\n\n";
                    log += "Report this to Estrol#0021 (He might busy or idk, but he should respond)";

                    File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + $"\\crashlog\\crash-{Guid.NewGuid()}.txt", log);
                }

                MessageBox.Show(e.Message + "\n\nProgram will now exit.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
                GameProc?.Kill();
                Environment.Exit(500);
            };

            server.OnCError += (object o) => {
                MessageBoxResult res = MessageBox.Show("Seems the game crashing when you're enjoying the game -_-\nOpen help page?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.No, MessageBoxOptions.DefaultDesktopOnly);
                if (res == MessageBoxResult.Yes)
                {
                    ProcessStartInfo ps = new("https://estrol.space/game/x3solo/troubleshot") {
                        UseShellExecute = true,
                        Verb            = "open"
                    };

                    Process.Start(ps);
                }
            };
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: Estrol/X3Solo
        private void Run(object sender, RoutedEventArgs e)
        {
            if (IsClicked)
            {
                return;
            }

            IsClicked = true;
            if (GameProc != null)
            {
                MessageBox.Show("The Game Already Started!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\OTwo.exe"))
            {
                MessageBox.Show("OTwo.exe not found", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Task ts = new(() => {
                string IPAddr = "127.0.0.1";
                int GamePort = config.ServerPort;
                ClientCheck conf = new();
                conf.GetVersion("OTwo.exe");

                if (!File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Image", conf.OJNList)))
                {
                    bool result = OJNListGenerator.GenerateOJNList(conf);
                    if (!result)
                    {
                        return;
                    }
                }

                ProcessStartInfo ps = new() {
                    UseShellExecute = true,
                    WindowStyle = ProcessWindowStyle.Normal,
                    FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "OTwo.exe"),
                    Arguments = "1 127.0.0.1 o2jam/patch "
                                + $"{IPAddr}:80 "
                                + "1 1 1 1 1 1 1 1 "
                                + $"{IPAddr} {GamePort} "
                                + $"{IPAddr} {GamePort} "
                                + $"{IPAddr} {GamePort} "
                                + $"{IPAddr} {GamePort} "
                                + $"{IPAddr} {GamePort} "
                                + $"{IPAddr} {GamePort} "
                                + $"{IPAddr} {GamePort} "
                                + $"{IPAddr} {GamePort} "
                };

                server.Intialize(conf);
                GameProc = Process.Start(ps);

                if (GameProc == null)
                {
                    MessageBox.Show("Game failed to start");
                    server.Stop();
                }
                else
                {
                    try {
                        bool result = GameProc.WaitForInputIdle();
                        if (!result)
                        {
                            MessageBox.Show("Failed to start the game!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }

                        GameProc.WaitForExit();
                        server.Stop();
                        GameProc = null;
                    } catch (Exception e) {
                        ProcessUtil.SuspendProcess(GameProc.Id);

                        MessageBox.Show(e.Message + "\n\nProgram will now exit.", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
                        GameProc?.Kill();
                        Environment.Exit(0);
                    }
                }
            });

            ts.Start();
            IsClicked = false;
        }