diff --git a/BetterGenshinImpact/BetterGenshinImpact.csproj b/BetterGenshinImpact/BetterGenshinImpact.csproj
index fa99618d..e2d2395d 100644
--- a/BetterGenshinImpact/BetterGenshinImpact.csproj
+++ b/BetterGenshinImpact/BetterGenshinImpact.csproj
@@ -32,6 +32,7 @@
+
diff --git a/BetterGenshinImpact/Core/Config/AllConfig.cs b/BetterGenshinImpact/Core/Config/AllConfig.cs
index 2e179c0a..6d388d78 100644
--- a/BetterGenshinImpact/Core/Config/AllConfig.cs
+++ b/BetterGenshinImpact/Core/Config/AllConfig.cs
@@ -73,6 +73,12 @@ namespace BetterGenshinImpact.Core.Config
///
public HotKeyConfig HotKeyConfig { get; set; } = new();
+ ///
+ /// 原神安装路径
+ ///
+ [ObservableProperty]
+ private string _installPath = "";
+
[JsonIgnore] public Action? OnAnyChangedAction { get; set; }
public void InitEvent()
diff --git a/BetterGenshinImpact/GameTask/GameLoading/GameLoading.cs b/BetterGenshinImpact/GameTask/GameLoading/GameLoading.cs
new file mode 100644
index 00000000..6da9793f
--- /dev/null
+++ b/BetterGenshinImpact/GameTask/GameLoading/GameLoading.cs
@@ -0,0 +1,64 @@
+using BetterGenshinImpact.Core.Recognition;
+using BetterGenshinImpact.Core.Simulator;
+using BetterGenshinImpact.GameTask.AutoSkip.Assets;
+using BetterGenshinImpact.GameTask.Model;
+using OpenCvSharp;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BetterGenshinImpact.GameTask.GameLoading
+{
+ public class GameLoadingTrigger : ITaskTrigger
+ {
+ private RecognitionObject? _startGameRo;
+
+ public string Name => "GameLoading";
+
+ public bool IsEnabled { get; set; }
+
+ public int Priority => 999;
+
+ public bool IsExclusive => false;
+
+ public void Init()
+ {
+ var info = TaskContext.Instance().SystemInfo;
+ _startGameRo = new RecognitionObject
+ {
+ Name = "StartGame",
+ RecognitionType = RecognitionTypes.Ocr,
+ // ROI 应该时捕捉窗口的中间底部部分
+ RegionOfInterest = new Rect((int)(info.CaptureAreaRect.Width / 2 - 100),
+ (int)(info.CaptureAreaRect.Height - 100),
+ 200,
+ 100),
+ OneContainMatchText = new List
+ {
+ "点", "击", "进", "入"
+ },
+ DrawOnWindow = true
+ }.InitTemplate();
+ IsEnabled = true;
+ }
+
+ public void OnCapture(CaptureContent content)
+ {
+ using var foundRectArea = content.CaptureRectArea.Find(_startGameRo!);
+ if (!foundRectArea.IsEmpty())
+ {
+ // 在游戏窗口中心点击
+ var info = TaskContext.Instance().SystemInfo;
+ var x = info.CaptureAreaRect.Right - (info.CaptureAreaRect.Width / 2);
+ var y = info.CaptureAreaRect.Bottom - (info.CaptureAreaRect.Height / 2);
+ Simulation.MouseEvent.Click(x, y);
+ // 一旦进入游戏,这个触发器就不再需要了
+ // TODO:如果其他触发器成功,这个触发器同样也不再需要了,考虑使用其他触发器的成功来禁用该事件
+ IsEnabled = false;
+ }
+ }
+ }
+
+}
diff --git a/BetterGenshinImpact/GameTask/GameTaskManager.cs b/BetterGenshinImpact/GameTask/GameTaskManager.cs
index d3053ee1..d8eed600 100644
--- a/BetterGenshinImpact/GameTask/GameTaskManager.cs
+++ b/BetterGenshinImpact/GameTask/GameTaskManager.cs
@@ -26,7 +26,8 @@ namespace BetterGenshinImpact.GameTask
{ "RecognitionTest", new TestTrigger() },
{ "AutoPick", new AutoPick.AutoPickTrigger() },
{ "AutoSkip", new AutoSkip.AutoSkipTrigger() },
- { "AutoFishing", new AutoFishing.AutoFishingTrigger() }
+ { "AutoFishing", new AutoFishing.AutoFishingTrigger() },
+ { "GameLoading", new GameLoading.GameLoadingTrigger() }
};
var loadedTriggers = TriggerDictionary.Values.ToList();
diff --git a/BetterGenshinImpact/GameTask/SystemControl.cs b/BetterGenshinImpact/GameTask/SystemControl.cs
index e3a07a94..8e28e7eb 100644
--- a/BetterGenshinImpact/GameTask/SystemControl.cs
+++ b/BetterGenshinImpact/GameTask/SystemControl.cs
@@ -1,6 +1,8 @@
-using System;
+using BetterGenshinImpact.Core.Simulator;
+using System;
using System.Diagnostics;
using System.Linq;
+using System.Threading;
using Vanara.PInvoke;
namespace BetterGenshinImpact.GameTask;
@@ -12,6 +14,14 @@ public class SystemControl
return FindHandleByProcessName("YuanShen", "GenshinImpact", "Genshin Impact Cloud Game");
}
+ public static nint StartFromLocal(string path)
+ {
+ // 使用 path 在新的线程中启动游戏
+ var process = Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
+ Thread.Sleep(10000);
+ return FindGenshinImpactHandle();
+ }
+
public static bool IsGenshinImpactActiveByProcess()
{
var name = GetActiveProcessName();
diff --git a/BetterGenshinImpact/View/Pages/HomePage.xaml b/BetterGenshinImpact/View/Pages/HomePage.xaml
index bf81a7ee..11f8331e 100644
--- a/BetterGenshinImpact/View/Pages/HomePage.xaml
+++ b/BetterGenshinImpact/View/Pages/HomePage.xaml
@@ -106,6 +106,35 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs
index b16f3fb2..c13cba6a 100644
--- a/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs
+++ b/BetterGenshinImpact/ViewModel/Pages/HomePageViewModel.cs
@@ -12,6 +12,9 @@ using Fischless.GameCapture;
using Microsoft.Extensions.Logging;
using System;
using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Net;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
@@ -122,8 +125,16 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware
var hWnd = SystemControl.FindGenshinImpactHandle();
if (hWnd == IntPtr.Zero)
{
- System.Windows.MessageBox.Show("未找到原神窗口,请先启动原神!");
- return;
+ if (! string.IsNullOrEmpty(Config.InstallPath))
+ {
+ var path = Path.Combine(Config.InstallPath, "Yuanshen.exe");
+ hWnd = SystemControl.StartFromLocal(path);
+ }
+ if (hWnd ==IntPtr.Zero)
+ {
+ System.Windows.MessageBox.Show("未找到原神窗口,请先启动原神!");
+ return;
+ }
}
@@ -192,4 +203,32 @@ public partial class HomePageViewModel : ObservableObject, INavigationAware
// MessageBox.Show(e.StackTrace);
//}
}
+
+
+ [RelayCommand]
+ public async Task SelectInstallPathAsync()
+ {
+ await Task.Run(() =>
+ {
+ // 弹出选择文件夹对话框
+ var dialog = new Ookii.Dialogs.Wpf.VistaFolderBrowserDialog();
+ if (dialog.ShowDialog() == true)
+ {
+ var path = dialog.SelectedPath;
+ if (string.IsNullOrEmpty(path))
+ {
+ return;
+ }
+ // 检查是否有Yuanshen.exe
+ var gamePath = Path.Combine(path, "Yuanshen.exe");
+ if (!File.Exists(gamePath))
+ {
+ System.Windows.MessageBox.Show("请选择正确的原神安装目录");
+ return;
+ }
+ Config.InstallPath = path;
+ }
+ });
+ }
+
}
\ No newline at end of file