Exemplo n.º 1
0
        private void FocusGameWindow()
        {
            if (WindowCaptureHelper.IsIconic(genshinHandle))
            {
                WindowCaptureHelper.ShowWindow(genshinHandle, 9);
            }

            WindowCaptureHelper.SetForegroundWindow(genshinHandle);
            WindowCaptureHelper.SwitchToThisWindow(genshinHandle, true);
        }
Exemplo n.º 2
0
        private async Task DoCaptureGameScreen()
        {
            Bitmap gameScreenshot        = null;
            Bitmap croppedGameScreenshot = null;

            for (int progressIndex = 0; progressIndex <= 4; progressIndex++)
            {
                await Task.Delay((int)TimeOutUpDown.Value);

                gameScreenshot = WindowCaptureHelper.ProcessWindowScreenshot(genshinHandle);
                if (gameScreenshot == null)
                {
                    Invoke((MethodInvoker) delegate
                    {
                        Activate();
                        MessageBox.Show("Could not capture the game window. Ensure it's not minimalized or unfocused and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    });
                    progressIndex = -1;
                }
                else
                {
                    int gameScreenWidth = gameScreenshot.Width;
                    int cropWidth       = Convert.ToInt32(0.275 * gameScreenshot.Width);
                    int cropHeight      = Convert.ToInt32(0.90 * gameScreenshot.Height);
                    int offsetWidth     = gameScreenWidth - cropWidth;

                    croppedGameScreenshot = CropGameImage(gameScreenshot, cropWidth, cropHeight, offsetWidth);
                }

                if (SaveInOwnDirectoryCheckBox.Checked)
                {
                    Directory.CreateDirectory(savePrefix);
                }

                switch (progressIndex)
                {
                case 0:
                    FlowerBitmap = croppedGameScreenshot;
                    if (SaveIndividualImagesCheckBox.Checked)
                    {
                        if (SaveInOwnDirectoryCheckBox.Checked)
                        {
                            croppedGameScreenshot.Save(Path.Combine(savePrefix, $"{savePrefix}_flower.png"));
                        }
                        else
                        {
                            croppedGameScreenshot.Save($"{savePrefix}_flower.png");
                        }
                    }
                    break;

                case 1:
                    PlumeBitmap = croppedGameScreenshot;
                    if (SaveIndividualImagesCheckBox.Checked)
                    {
                        if (SaveInOwnDirectoryCheckBox.Checked)
                        {
                            croppedGameScreenshot.Save(Path.Combine(savePrefix, $"{savePrefix}_plume.png"));
                        }
                        else
                        {
                            croppedGameScreenshot.Save($"{savePrefix}_plume.png");
                        }
                    }
                    break;

                case 2:
                    SandsBitmap = croppedGameScreenshot;
                    if (SaveIndividualImagesCheckBox.Checked)
                    {
                        if (SaveInOwnDirectoryCheckBox.Checked)
                        {
                            croppedGameScreenshot.Save(Path.Combine(savePrefix, $"{savePrefix}_sands.png"));
                        }
                        else
                        {
                            croppedGameScreenshot.Save($"{savePrefix}_sands.png");
                        }
                    }
                    break;

                case 3:
                    GobletBitmap = croppedGameScreenshot;
                    if (SaveIndividualImagesCheckBox.Checked)
                    {
                        if (SaveInOwnDirectoryCheckBox.Checked)
                        {
                            croppedGameScreenshot.Save(Path.Combine(savePrefix, $"{savePrefix}_goblet.png"));
                        }
                        else
                        {
                            croppedGameScreenshot.Save($"{savePrefix}_goblet.png");
                        }
                    }
                    break;

                case 4:
                    CircletBitmap = croppedGameScreenshot;
                    if (SaveIndividualImagesCheckBox.Checked)
                    {
                        if (SaveInOwnDirectoryCheckBox.Checked)
                        {
                            croppedGameScreenshot.Save(Path.Combine(savePrefix, $"{savePrefix}_circlet.png"));
                        }
                        else
                        {
                            croppedGameScreenshot.Save($"{savePrefix}_circlet.png");
                        }
                    }
                    break;

                default:
                    Invoke((MethodInvoker) delegate
                    {
                        StartButton.Enabled      = true;
                        StartButton.Text         = "Start";
                        CaptureProgressBar.Value = 0;
                    });
                    break;
                }
                if (progressIndex == -1)
                {
                    break;
                }

                Invoke((MethodInvoker) delegate
                {
                    CaptureProgressBar.PerformStep();
                });

                DoBeeps(last: progressIndex == 4);
                if (progressIndex == 4)
                {
                    CreateArtifactCompilation();
                    Invoke((MethodInvoker) delegate
                    {
                        Activate();
                        StartButton.Enabled = true;
                        StartButton.Text    = "Start";
                    });
                    if (SaveInOwnDirectoryCheckBox.Checked)
                    {
                        Process.Start(Path.Combine(savePrefix, $"{savePrefix}.png"));
                    }
                    else
                    {
                        Process.Start($"{savePrefix}.png");
                    }
                }
            }
        }