diff --git a/BetterGenshinImpact/BetterGenshinImpact.csproj b/BetterGenshinImpact/BetterGenshinImpact.csproj index 3e982cda..fa99618d 100644 --- a/BetterGenshinImpact/BetterGenshinImpact.csproj +++ b/BetterGenshinImpact/BetterGenshinImpact.csproj @@ -312,9 +312,4 @@ - - - - - \ No newline at end of file diff --git a/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs b/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs index 4065c374..97a26073 100644 --- a/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs +++ b/BetterGenshinImpact/GameTask/AutoWood/AutoWoodTask.cs @@ -24,11 +24,14 @@ public class AutoWoodTask private readonly ClickOffset _clickOffset; + private readonly Login3rdParty _login3rdParty; + public AutoWoodTask() { var captureArea = TaskContext.Instance().SystemInfo.CaptureAreaRect; var assetScale = TaskContext.Instance().SystemInfo.AssetScale; _clickOffset = new ClickOffset(captureArea.X, captureArea.Y, assetScale); + _login3rdParty = new(); } public void Start(WoodTaskParam taskParam) @@ -45,6 +48,12 @@ public class AutoWoodTask break; } + _login3rdParty.RefreshAvailabled(); + if (_login3rdParty.Type == Login3rdParty.The3rdPartyType.Bilibili) + { + // TODO + throw new NormalEndException("暂未支持B服伐木,后续将会增加支持!"); + } Felling(taskParam); VisionContext.Instance().DrawContent.ClearAll(); Sleep(500, taskParam.Cts); @@ -80,7 +89,6 @@ public class AutoWoodTask EnterGame(taskParam); } - private void PressZ(WoodTaskParam taskParam) { if (_first) @@ -164,4 +172,4 @@ public class AutoWoodTask } }, TimeSpan.FromSeconds(1), 50); } -} \ No newline at end of file +} diff --git a/BetterGenshinImpact/GameTask/AutoWood/Utils/Login3rdParty.cs b/BetterGenshinImpact/GameTask/AutoWood/Utils/Login3rdParty.cs new file mode 100644 index 00000000..e7d64f77 --- /dev/null +++ b/BetterGenshinImpact/GameTask/AutoWood/Utils/Login3rdParty.cs @@ -0,0 +1,78 @@ +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using Vanara.PInvoke; + +namespace BetterGenshinImpact.GameTask.AutoWood.Utils; + +internal sealed class Login3rdParty +{ + public enum The3rdPartyType + { + None, + Bilibili, + } + + public bool IsAvailabled => Type != The3rdPartyType.None; + public The3rdPartyType Type { get; private set; } = default; + + public void RefreshAvailabled() + { + Type = The3rdPartyType.None; + + try + { + if (Process.GetProcessesByName("YuanShen").FirstOrDefault() is Process p) + { + uint tid = User32.GetWindowThreadProcessId(p.MainWindowHandle, out uint pid); + + if (tid != 0) + { + using Kernel32.SafeHPROCESS hProcess = Kernel32.OpenProcess(new ACCESS_MASK(Kernel32.ProcessAccess.PROCESS_QUERY_INFORMATION), false, pid); + + if (!hProcess.IsInvalid) + { + StringBuilder devicePath = new(260); + uint size = (uint)devicePath.Capacity; + + if (Kernel32.QueryFullProcessImageName(hProcess, 0, devicePath, ref size)) + { + FileInfo fileInfo = new(devicePath.ToString()); + + if (fileInfo.Exists) + { + string? configIni = Path.Combine(fileInfo.DirectoryName!, "config.ini"); + string[] lines = File.ReadAllLines(configIni); + + foreach (string line in lines) + { + string kv = line.Trim(); + if (kv.StartsWith("cps=") && kv.EndsWith("bilibili")) + { + Type = The3rdPartyType.Bilibili; + break; + } + } + } + } + else + { + Debug.WriteLine($"Error getting process image file name. Error code: {Marshal.GetLastWin32Error()}"); + } + } + } + } + } + catch + { + /// + } + } + + public void Login() + { + // TODO + } +}