try support bilibili auto wood

Now wait for an account to test it
This commit is contained in:
ema
2023-11-26 07:21:57 +08:00
parent e2f37cae39
commit fc74e127c1
2 changed files with 77 additions and 5 deletions

View File

@@ -51,8 +51,7 @@ public class AutoWoodTask
_login3rdParty.RefreshAvailabled();
if (_login3rdParty.Type == Login3rdParty.The3rdPartyType.Bilibili)
{
// TODO
throw new NormalEndException("暂未支持B服伐木后续将会增加支持");
Logger.LogInformation("自动伐木启用B服模式");
}
Felling(taskParam);
VisionContext.Instance().DrawContent.ClearAll();
@@ -159,6 +158,13 @@ public class AutoWoodTask
NewRetry.Do(() =>
{
Sleep(1, taskParam.Cts);
if (_login3rdParty.IsAvailabled)
{
_login3rdParty.Login(taskParam.Cts);
Sleep(2000, taskParam.Cts);
}
var content = CaptureToContent(taskParam.Dispatcher.GameCapture);
var ra = content.CaptureRectArea.Find(_assets.EnterGameRo);
if (ra.IsEmpty())

View File

@@ -1,9 +1,15 @@
using System.Diagnostics;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.Helpers.Extensions;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.AutoWood.Utils;
@@ -71,8 +77,68 @@ internal sealed class Login3rdParty
}
}
public void Login()
public async void Login(CancellationTokenSource cts)
{
// TODO
await Task.Run(() =>
{
while (!LoginPrivate(cts))
{
Sleep(500, cts);
}
}, cts.Token);
}
private bool LoginPrivate(CancellationTokenSource cts)
{
if (Type == The3rdPartyType.Bilibili)
{
if (Process.GetProcessesByName("YuanShen").FirstOrDefault() is Process process)
{
nint hwndLogin = IntPtr.Zero;
_ = User32.EnumWindows((HWND hWnd, nint lParam) =>
{
try
{
_ = User32.GetWindowThreadProcessId(hWnd, out uint pid);
if (pid == process.Id)
{
int capacity = User32.GetWindowTextLength(hWnd);
StringBuilder title = new(capacity + 1);
_ = User32.GetWindowText(hWnd, title, title.Capacity);
if (!string.IsNullOrEmpty(title.ToString()))
{
hwndLogin = (nint)hWnd;
return false;
}
}
}
catch
{
}
return true;
}, 0);
if (hwndLogin == IntPtr.Zero)
{
return false;
}
// Just for login WebUI chattering
Sleep(400, cts);
var p = TaskContext.Instance().SystemInfo.CaptureAreaRect.GetCenterPoint();
p.Add(new(0, 125)).Click();
return true;
}
return false;
}
else
{
// Ignore and exit with OK
return true;
}
}
}