mirror of
https://github.com/babalae/better-genshin-impact
synced 2025-01-09 04:19:47 +08:00
auto music opt
This commit is contained in:
parent
c95343e953
commit
5de2067489
@ -4,6 +4,7 @@ using OpenCvSharp;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Vanara.PInvoke;
|
using Vanara.PInvoke;
|
||||||
@ -18,14 +19,14 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
|||||||
private readonly ConcurrentDictionary<User32.VK, int> _keyX = new()
|
private readonly ConcurrentDictionary<User32.VK, int> _keyX = new()
|
||||||
{
|
{
|
||||||
[User32.VK.VK_A] = 417,
|
[User32.VK.VK_A] = 417,
|
||||||
[User32.VK.VK_S] = 632,
|
[User32.VK.VK_S] = 628,
|
||||||
[User32.VK.VK_D] = 846,
|
[User32.VK.VK_D] = 844,
|
||||||
[User32.VK.VK_J] = 1065,
|
[User32.VK.VK_J] = 1061,
|
||||||
[User32.VK.VK_K] = 1282,
|
[User32.VK.VK_K] = 1277,
|
||||||
[User32.VK.VK_L] = 1500
|
[User32.VK.VK_L] = 1493
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly int _keyY = 916;
|
private readonly int _keyY = 921;
|
||||||
|
|
||||||
private readonly IntPtr _hWnd = TaskContext.Instance().GameHandle;
|
private readonly IntPtr _hWnd = TaskContext.Instance().GameHandle;
|
||||||
|
|
||||||
@ -44,18 +45,18 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
|||||||
{
|
{
|
||||||
var (x, y) = gameCaptureRegion.ConvertPositionToGameCaptureRegion((int)(keyValuePair.Value * assetScale), (int)(_keyY * assetScale));
|
var (x, y) = gameCaptureRegion.ConvertPositionToGameCaptureRegion((int)(keyValuePair.Value * assetScale), (int)(_keyY * assetScale));
|
||||||
// 添加任务
|
// 添加任务
|
||||||
taskList.Add(taskFactory.StartNew(() => DoWhitePressWin32(ct, keyValuePair.Key, new Point(x, y))));
|
taskList.Add(taskFactory.StartNew(async () => await DoWhitePressWin32(ct, keyValuePair.Key, new Point(x, y)), ct));
|
||||||
}
|
}
|
||||||
|
|
||||||
Task.WaitAll([.. taskList]);
|
Task.WaitAll([.. taskList], ct);
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoWhitePressWin32(CancellationToken ct, User32.VK key, Point point)
|
private async Task DoWhitePressWin32(CancellationToken ct, User32.VK key, Point point)
|
||||||
{
|
{
|
||||||
while (!ct.IsCancellationRequested)
|
while (!ct.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
Thread.Sleep(10);
|
await Task.Delay(5, ct);
|
||||||
// Stopwatch sw = new();
|
// Stopwatch sw = new();
|
||||||
// sw.Start();
|
// sw.Start();
|
||||||
var hdc = User32.GetDC(_hWnd);
|
var hdc = User32.GetDC(_hWnd);
|
||||||
@ -67,7 +68,7 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
|||||||
KeyDown(key);
|
KeyDown(key);
|
||||||
while (!ct.IsCancellationRequested)
|
while (!ct.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
Thread.Sleep(10);
|
await Task.Delay(5, ct);
|
||||||
hdc = User32.GetDC(_hWnd);
|
hdc = User32.GetDC(_hWnd);
|
||||||
c = Gdi32.GetPixel(hdc, point.X, point.Y);
|
c = Gdi32.GetPixel(hdc, point.X, point.Y);
|
||||||
Gdi32.DeleteDC(hdc);
|
Gdi32.DeleteDC(hdc);
|
||||||
@ -76,6 +77,7 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyUp(key);
|
KeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,6 +382,13 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
|||||||
Config.HotKeyConfig.AutoDomainHotkeyType,
|
Config.HotKeyConfig.AutoDomainHotkeyType,
|
||||||
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoDomainCommand); }
|
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoDomainCommand); }
|
||||||
));
|
));
|
||||||
|
soloTaskDirectory.Children.Add(new HotKeySettingModel(
|
||||||
|
"启动/停止自动音游",
|
||||||
|
nameof(Config.HotKeyConfig.AutoMusicGameHotkey),
|
||||||
|
Config.HotKeyConfig.AutoMusicGameHotkey,
|
||||||
|
Config.HotKeyConfig.AutoMusicGameHotkeyType,
|
||||||
|
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoMusicGameCommand); }
|
||||||
|
));
|
||||||
|
|
||||||
macroDirectory.Children.Add(new HotKeySettingModel(
|
macroDirectory.Children.Add(new HotKeySettingModel(
|
||||||
"快捷点击原神内确认按钮",
|
"快捷点击原神内确认按钮",
|
||||||
@ -515,13 +522,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
|||||||
);
|
);
|
||||||
HotKeySettingModels.Add(debugDirectory);
|
HotKeySettingModels.Add(debugDirectory);
|
||||||
|
|
||||||
soloTaskDirectory.Children.Add(new HotKeySettingModel(
|
|
||||||
"启动/停止自动活动音游",
|
|
||||||
nameof(Config.HotKeyConfig.AutoMusicGameHotkey),
|
|
||||||
Config.HotKeyConfig.AutoMusicGameHotkey,
|
|
||||||
Config.HotKeyConfig.AutoMusicGameHotkeyType,
|
|
||||||
(_, _) => { SwitchSoloTask(_taskSettingsPageViewModel.SwitchAutoMusicGameCommand); }
|
|
||||||
));
|
|
||||||
// HotKeySettingModels.Add(new HotKeySettingModel(
|
// HotKeySettingModels.Add(new HotKeySettingModel(
|
||||||
// "(测试)启动/停止自动追踪",
|
// "(测试)启动/停止自动追踪",
|
||||||
// nameof(Config.HotKeyConfig.AutoTrackHotkey),
|
// nameof(Config.HotKeyConfig.AutoTrackHotkey),
|
||||||
|
Loading…
Reference in New Issue
Block a user