Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
babe62ddfd | ||
|
|
3b8429d3c4 | ||
|
|
9980576083 | ||
|
|
3d2168874e | ||
|
|
0f5247c844 | ||
|
|
2314a5eb0e | ||
|
|
14e0af74c0 | ||
|
|
9a7e4b5a01 | ||
|
|
f9bc5ff426 |
No files matched your search
@@ -5,7 +5,7 @@ namespace BetterGenshinImpact.Core.Config;
|
||||
|
||||
public class Global
|
||||
{
|
||||
public static string Version { get; } = "0.31.3";
|
||||
public static string Version { get; } = "0.32.0";
|
||||
|
||||
public static string StartUpPath { get; set; } = AppContext.BaseDirectory;
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ using Microsoft.Extensions.Logging;
|
||||
using SharpDX.DirectInput;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder;
|
||||
@@ -32,7 +34,7 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
_timer.Interval = 50; // ms
|
||||
}
|
||||
|
||||
public void StartRecord()
|
||||
public async Task StartRecord()
|
||||
{
|
||||
if (!TaskContext.Instance().IsInitialized)
|
||||
{
|
||||
@@ -41,14 +43,24 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
}
|
||||
|
||||
TaskTriggerDispatcher.Instance().StopTimer();
|
||||
|
||||
_logger.LogInformation("录制:{Text}", "实时任务已暂停");
|
||||
_logger.LogInformation("注意:录制时遇到主界面(鼠标永远在界面中心)和其他界面(鼠标可自由移动,比如地图等)的切换,请把手离开鼠标等待录制模式切换日志");
|
||||
|
||||
SystemControl.ActivateWindow();
|
||||
for (var i = 3; i >= 1; i--)
|
||||
{
|
||||
_logger.LogInformation("{Sec}秒后启动录制...", i);
|
||||
await Task.Delay(1000);
|
||||
}
|
||||
|
||||
_timer.Start();
|
||||
|
||||
_recorder = new KeyMouseRecorder();
|
||||
_directInputMonitor = new DirectInputMonitor();
|
||||
_directInputMonitor.Start();
|
||||
|
||||
_logger.LogInformation("录制:{Text}", "实时任务已暂停,录制已启动");
|
||||
_logger.LogInformation("注意:录制时遇到主界面(鼠标永远在界面中心)和其他界面(鼠标可自由移动,比如地图等)的切换,请把手离开鼠标等待录制模式切换日志");
|
||||
_logger.LogInformation("录制:{Text}", "已启动");
|
||||
}
|
||||
|
||||
public string StopRecord()
|
||||
@@ -83,7 +95,8 @@ public class GlobalKeyMouseRecord : Singleton<GlobalKeyMouseRecord>
|
||||
|
||||
public void GlobalHookKeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode.ToString() == TaskContext.Instance().Config.HotKeyConfig.Test1Hotkey)
|
||||
// 排除热键
|
||||
if (e.KeyCode.ToString() == TaskContext.Instance().Config.HotKeyConfig.KeyMouseMacroRecordHotkey)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
using BetterGenshinImpact.GameTask.Common;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder;
|
||||
@@ -16,8 +19,32 @@ public class KeyMouseMacroPlayer
|
||||
{
|
||||
public static async Task PlayMacro(string macro, CancellationToken ct)
|
||||
{
|
||||
var macroEvents = JsonSerializer.Deserialize<List<MacroEvent>>(macro, KeyMouseRecorder.JsonOptions) ?? throw new Exception("Failed to deserialize macro");
|
||||
await PlayMacro(macroEvents, ct);
|
||||
if (!TaskContext.Instance().IsInitialized)
|
||||
{
|
||||
MessageBox.Show("请先在启动页,启动截图器再使用本功能");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TaskTriggerDispatcher.Instance().StopTimer();
|
||||
|
||||
var script = JsonSerializer.Deserialize<KeyMouseScript>(macro, KeyMouseRecorder.JsonOptions) ?? throw new Exception("Failed to deserialize macro");
|
||||
script.Adapt(TaskContext.Instance().SystemInfo.CaptureAreaRect);
|
||||
SystemControl.ActivateWindow();
|
||||
for (var i = 3; i >= 1; i--)
|
||||
{
|
||||
TaskControl.Logger.LogInformation("{Sec}秒后进行重放...", i);
|
||||
await Task.Delay(1000, ct);
|
||||
}
|
||||
|
||||
TaskControl.Logger.LogInformation("开始重放");
|
||||
await PlayMacro(script.MacroEvents, ct);
|
||||
}
|
||||
finally
|
||||
{
|
||||
TaskTriggerDispatcher.Instance().StartTimer();
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task PlayMacro(List<MacroEvent> macroEvents, CancellationToken ct)
|
||||
@@ -66,6 +93,7 @@ public class KeyMouseMacroPlayer
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseUp:
|
||||
@@ -98,6 +126,7 @@ public class KeyMouseMacroPlayer
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case MacroEventType.MouseMoveTo:
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Windows.Forms;
|
||||
using SharpDX.DirectInput;
|
||||
using BetterGenshinImpact.GameTask;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder;
|
||||
|
||||
@@ -27,7 +28,19 @@ public class KeyMouseRecorder
|
||||
|
||||
public string ToJsonMacro()
|
||||
{
|
||||
return JsonSerializer.Serialize(MacroEvents, JsonOptions);
|
||||
var rect = TaskContext.Instance().SystemInfo.CaptureAreaRect;
|
||||
KeyMouseScript keyMouseScript = new()
|
||||
{
|
||||
MacroEvents = MacroEvents,
|
||||
Info = new KeyMouseScriptInfo
|
||||
{
|
||||
X = rect.X,
|
||||
Y = rect.Y,
|
||||
Width = rect.Width,
|
||||
Height = rect.Height
|
||||
}
|
||||
};
|
||||
return JsonSerializer.Serialize(keyMouseScript, JsonOptions);
|
||||
}
|
||||
|
||||
public void KeyDown(KeyEventArgs e)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Vanara.PInvoke;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder.Model;
|
||||
|
||||
[Serializable]
|
||||
public class KeyMouseScript
|
||||
{
|
||||
public List<MacroEvent> MacroEvents { get; set; } = [];
|
||||
public KeyMouseScriptInfo? Info { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 转换原始脚本为适应当前分辨率的脚本
|
||||
/// </summary>
|
||||
/// <param name="captureRect"></param>
|
||||
public void Adapt(RECT captureRect)
|
||||
{
|
||||
foreach (var macroEvent in MacroEvents)
|
||||
{
|
||||
if (macroEvent.Type == MacroEventType.MouseMoveTo
|
||||
|| macroEvent.Type == MacroEventType.MouseDown
|
||||
|| macroEvent.Type == MacroEventType.MouseUp)
|
||||
{
|
||||
if (Info == null || Info.Width == 0 || Info.Height == 0)
|
||||
{
|
||||
Debug.WriteLine("错误的脚本数据 Info.Width == 0 || Info.Height == 0");
|
||||
break;
|
||||
}
|
||||
|
||||
macroEvent.MouseX = (int)(captureRect.X + (macroEvent.MouseX - Info.X) * captureRect.Width * 1d / Info.Width);
|
||||
macroEvent.MouseY = (int)(captureRect.Y + (macroEvent.MouseY - Info.Y) * captureRect.Height * 1d / Info.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder.Model;
|
||||
|
||||
[Serializable]
|
||||
public class KeyMouseScriptInfo
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
namespace BetterGenshinImpact.Core.Recorder.Model;
|
||||
using System;
|
||||
|
||||
namespace BetterGenshinImpact.Core.Recorder.Model;
|
||||
|
||||
[Serializable]
|
||||
public class MacroEvent
|
||||
{
|
||||
public MacroEventType Type { get; set; }
|
||||
|
||||
@@ -703,6 +703,13 @@ public class GeniusInvokationControl
|
||||
Sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
// 存在吞星之鲸的情况下,烧牌后等待加血动画
|
||||
if (duel.Characters.Any(c => c is { Name: "吞星之鲸" }))
|
||||
{
|
||||
Debug.WriteLine("存在吞星之鲸的情况下,烧牌后等待动画");
|
||||
Sleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
return ActionPhaseUseSkill(skillIndex);
|
||||
|
||||
@@ -7,8 +7,13 @@ namespace BetterGenshinImpact.GameTask.Macro
|
||||
{
|
||||
public static void Done()
|
||||
{
|
||||
if (TaskContext.Instance().Config.MacroConfig.RunaroundMouseXInterval == 0)
|
||||
{
|
||||
TaskContext.Instance().Config.MacroConfig.RunaroundMouseXInterval = 1;
|
||||
}
|
||||
|
||||
Simulation.SendInput.Mouse.MoveMouseBy(TaskContext.Instance().Config.MacroConfig.RunaroundMouseXInterval, 0);
|
||||
Thread.Sleep(TaskContext.Instance().Config.MacroConfig.RunaroundInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
角色定义:
|
||||
角色1=芙宁娜
|
||||
角色2=卡维
|
||||
角色3=吞星之鲸
|
||||
---
|
||||
策略定义:
|
||||
芙宁娜 使用 技能2
|
||||
卡维 使用 技能2
|
||||
|
||||
卡维 使用 技能2
|
||||
卡维 使用 技能1
|
||||
|
||||
卡维 使用 技能3
|
||||
卡维 使用 技能3
|
||||
|
||||
吞星之鲸 使用 技能2
|
||||
吞星之鲸 使用 技能2
|
||||
//
|
||||
|
||||
吞星之鲸 使用 技能1
|
||||
吞星之鲸 使用 技能2
|
||||
|
||||
吞星之鲸 使用 技能2
|
||||
吞星之鲸 使用 技能1
|
||||
|
||||
芙宁娜 使用 技能3
|
||||
芙宁娜 使用 技能1
|
||||
芙宁娜 使用 技能3
|
||||
芙宁娜 使用 技能3
|
||||
芙宁娜 使用 技能3
|
||||
|
||||
@@ -87,7 +87,9 @@
|
||||
<!-- WebAsset24 | DocumentJs16 -->
|
||||
<ui:NavigationViewItem Content="脚本管理"
|
||||
NavigationCacheMode="Enabled"
|
||||
TargetPageType="{x:Type pages:ScriptControlPage}">
|
||||
TargetPageType="{x:Type pages:ScriptControlPage}"
|
||||
Visibility="{markup:Converter Value={x:Static helpers:RuntimeHelper.IsDebuggerAttached},
|
||||
Converter={StaticResource BooleanToVisibilityConverter}}">
|
||||
<ui:NavigationViewItem.Icon>
|
||||
<ui:SymbolIcon Symbol="Script16" />
|
||||
</ui:NavigationViewItem.Icon>
|
||||
|
||||
@@ -22,6 +22,7 @@ using FontFamily = System.Windows.Media.FontFamily;
|
||||
using BetterGenshinImpact.ViewModel;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using BetterGenshinImpact.Genshin.Settings;
|
||||
using BetterGenshinImpact.Core.Config;
|
||||
|
||||
namespace BetterGenshinImpact.View;
|
||||
|
||||
@@ -79,9 +80,9 @@ public partial class MaskWindow : Window
|
||||
|
||||
Invoke(() =>
|
||||
{
|
||||
Canvas.SetTop(LogTextBoxWrapper, Height - LogTextBoxWrapper.Height - 65);
|
||||
Canvas.SetTop(LogTextBoxWrapper, Height * 1d / DpiHelper.ScaleY - LogTextBoxWrapper.Height * 1d / DpiHelper.ScaleY - 65);
|
||||
Canvas.SetLeft(LogTextBoxWrapper, 20);
|
||||
Canvas.SetTop(StatusWrapper, Height - LogTextBoxWrapper.Height - 90);
|
||||
Canvas.SetTop(StatusWrapper, Height * 1d / DpiHelper.ScaleY - LogTextBoxWrapper.Height * 1d / DpiHelper.ScaleY - 90);
|
||||
Canvas.SetLeft(StatusWrapper, 20);
|
||||
});
|
||||
|
||||
@@ -121,6 +122,7 @@ public partial class MaskWindow : Window
|
||||
|
||||
private void PrintSystemInfo()
|
||||
{
|
||||
_logger.LogInformation("更好的原神 {Version}", Global.Version);
|
||||
var systemInfo = TaskContext.Instance().SystemInfo;
|
||||
var width = systemInfo.GameScreenSize.Width;
|
||||
var height = systemInfo.GameScreenSize.Height;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<ui:TextBlock Grid.Row="0"
|
||||
Margin="0,0,0,8"
|
||||
FontTypography="BodyStrong"
|
||||
Text="键鼠录制回放功能" />
|
||||
Text="键鼠录制回放功能(实验性功能)" />
|
||||
<ui:TextBlock Grid.Row="1"
|
||||
Margin="0,0,0,8"
|
||||
Foreground="{ui:ThemeResource TextFillColorTertiaryBrush}"
|
||||
|
||||
@@ -60,7 +60,6 @@ public partial class MainWindowViewModel : ObservableObject, IViewModel
|
||||
[SuppressMessage("CommunityToolkit.Mvvm.SourceGenerators.RelayCommandGenerator", "MVVMTK0039:Async void returning method annotated with RelayCommand")]
|
||||
private async void OnLoaded()
|
||||
{
|
||||
_logger.LogInformation("更好的原神 {Version}", Global.Version);
|
||||
try
|
||||
{
|
||||
await Task.Run(() =>
|
||||
|
||||
@@ -314,7 +314,8 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
TaskControl.Logger.LogInformation("触发快捷点击原神内{Btn}按钮:未找到按钮图片", "确认");
|
||||
}
|
||||
}
|
||||
},
|
||||
true
|
||||
));
|
||||
|
||||
HotKeySettingModels.Add(new HotKeySettingModel(
|
||||
@@ -332,7 +333,8 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
TaskControl.Logger.LogInformation("触发快捷点击原神内{Btn}按钮:未找到按钮图片", "取消");
|
||||
}
|
||||
}
|
||||
},
|
||||
true
|
||||
));
|
||||
|
||||
HotKeySettingModels.Add(new HotKeySettingModel(
|
||||
@@ -352,8 +354,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
"启动/停止键鼠录制",
|
||||
nameof(Config.HotKeyConfig.KeyMouseMacroRecordHotkey),
|
||||
Config.HotKeyConfig.KeyMouseMacroRecordHotkey,
|
||||
Config.HotKeyConfig.KeyMouseMacroRecordHotkeyType,
|
||||
(_, _) =>
|
||||
Config.HotKeyConfig.KeyMouseMacroRecordHotkeyType, async (_, _) =>
|
||||
{
|
||||
var vm = App.GetService<KeyMouseRecordPageViewModel>();
|
||||
if (vm == null)
|
||||
@@ -365,7 +366,7 @@ public partial class HotKeyPageViewModel : ObservableObject, IViewModel
|
||||
{
|
||||
keyMouseRecordRunning = true;
|
||||
Thread.Sleep(300); // 防止录进快捷键进去
|
||||
vm.OnStartRecord();
|
||||
await vm.OnStartRecord();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public void OnStartRecord()
|
||||
public async Task OnStartRecord()
|
||||
{
|
||||
if (!TaskContext.Instance().IsInitialized)
|
||||
{
|
||||
@@ -86,7 +86,7 @@ public partial class KeyMouseRecordPageViewModel : ObservableObject, INavigation
|
||||
if (!IsRecording)
|
||||
{
|
||||
IsRecording = true;
|
||||
GlobalKeyMouseRecord.Instance.StartRecord();
|
||||
await GlobalKeyMouseRecord.Instance.StartRecord();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,26 +45,26 @@ public partial class ScriptControlViewModel : ObservableObject, INavigationAware
|
||||
|
||||
public void RunMulti()
|
||||
{
|
||||
IScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.UseCaseInsensitiveMemberBinding | V8ScriptEngineFlags.EnableTaskPromiseConversion);
|
||||
EngineExtend.InitHost(engine);
|
||||
// IScriptEngine engine = new V8ScriptEngine(V8ScriptEngineFlags.UseCaseInsensitiveMemberBinding | V8ScriptEngineFlags.EnableTaskPromiseConversion);
|
||||
// EngineExtend.InitHost(engine);
|
||||
|
||||
// 执行脚本
|
||||
// new TaskRunner(DispatcherTimerOperationEnum.UseCacheImage).FireAndForget(async () =>
|
||||
// await new TpTask(CancellationContext.Instance.Cts)
|
||||
// .Tp(3452.310059, 2290.465088));
|
||||
|
||||
new TaskRunner(DispatcherTimerOperationEnum.UseCacheImage).FireAndForget(async () =>
|
||||
{
|
||||
await (Task)engine.Evaluate(@"
|
||||
(async function() {
|
||||
log.info('等待 {m} s', 1);
|
||||
await sleep(1000);
|
||||
log.info('测试 {name}', 'TP方法');
|
||||
await genshin.tp(3452.310059,2290.465088);
|
||||
log.warn('TP完成');
|
||||
await sleep(1000);
|
||||
})();
|
||||
");
|
||||
});
|
||||
// new TaskRunner(DispatcherTimerOperationEnum.UseCacheImage).FireAndForget(async () =>
|
||||
// {
|
||||
// await (Task)engine.Evaluate(@"
|
||||
// (async function() {
|
||||
// log.info('等待 {m} s', 1);
|
||||
// await sleep(1000);
|
||||
// log.info('测试 {name}', 'TP方法');
|
||||
// await genshin.tp(3452.310059,2290.465088);
|
||||
// log.warn('TP完成');
|
||||
// await sleep(1000);
|
||||
// })();
|
||||
// ");
|
||||
// });
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ BetterGI · 更好的原神, 一个基于计算机视觉技术,意图让原
|
||||
|
||||
你的系统需要满足以下条件:
|
||||
* Windows 10 或更高版本的64位系统
|
||||
* [.NET 7 运行时](https://dotnet.microsoft.com/zh-cn/download/dotnet/latest/runtime) (没有的话,启动程序,系统会提示下载安装)
|
||||
* [.NET 8 运行时](https://dotnet.microsoft.com/zh-cn/download/dotnet/latest/runtime) (没有的话,启动程序,系统会提示下载安装)
|
||||
|
||||
**⚠️注意:**
|
||||
1. 窗口大小变化、切换游戏分辨率、切换显示器的时候请重启本软件。
|
||||
|
||||
Reference in new issue
Block a user