auto music opt

This commit is contained in:
辉鸭蛋 2025-01-01 13:59:06 +08:00
parent c95343e953
commit 5de2067489
3 changed files with 23 additions and 20 deletions

View File

@ -4,6 +4,7 @@ using OpenCvSharp;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
@ -18,14 +19,14 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
private readonly ConcurrentDictionary<User32.VK, int> _keyX = new()
{
[User32.VK.VK_A] = 417,
[User32.VK.VK_S] = 632,
[User32.VK.VK_D] = 846,
[User32.VK.VK_J] = 1065,
[User32.VK.VK_K] = 1282,
[User32.VK.VK_L] = 1500
[User32.VK.VK_S] = 628,
[User32.VK.VK_D] = 844,
[User32.VK.VK_J] = 1061,
[User32.VK.VK_K] = 1277,
[User32.VK.VK_L] = 1493
};
private readonly int _keyY = 916;
private readonly int _keyY = 921;
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));
// 添加任务
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;
}
private void DoWhitePressWin32(CancellationToken ct, User32.VK key, Point point)
private async Task DoWhitePressWin32(CancellationToken ct, User32.VK key, Point point)
{
while (!ct.IsCancellationRequested)
{
Thread.Sleep(10);
await Task.Delay(5, ct);
// Stopwatch sw = new();
// sw.Start();
var hdc = User32.GetDC(_hWnd);
@ -67,7 +68,7 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
KeyDown(key);
while (!ct.IsCancellationRequested)
{
Thread.Sleep(10);
await Task.Delay(5, ct);
hdc = User32.GetDC(_hWnd);
c = Gdi32.GetPixel(hdc, point.X, point.Y);
Gdi32.DeleteDC(hdc);
@ -76,6 +77,7 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
break;
}
}
KeyUp(key);
}
@ -107,4 +109,4 @@ public class AutoMusicGameTask(AutoMusicGameParam taskParam) : ISoloTask
Logger.LogWarning("游戏窗口分辨率不是 16:9 !当前分辨率为 {Width}x{Height} , 非 16:9 分辨率的游戏可能无法正常使用自动活动音游功能 !", gameScreenSize.Width, gameScreenSize.Height);
}
}
}
}

View File

@ -382,6 +382,13 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
Config.HotKeyConfig.AutoDomainHotkeyType,
(_, _) => { 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(
"快捷点击原神内确认按钮",
@ -515,13 +522,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
);
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(
// "(测试)启动/停止自动追踪",
// nameof(Config.HotKeyConfig.AutoTrackHotkey),

View File

@ -353,7 +353,7 @@ public partial class TaskSettingsPageViewModel : ObservableObject, INavigationAw
}
[RelayCommand]
public void OnOpenLocalScriptRepo()
public void OnOpenLocalScriptRepo()
{
_autoFightViewModel.OnOpenLocalScriptRepo();
}