Compare commits

..
Author SHA1 Message Date
DismissedLight 45f55f94cd part 2 2025-01-21 22:10:50 +08:00
DismissedLight d4aae4508a init test 2025-01-21 17:31:09 +08:00
292 changed files with 4576 additions and 13373 deletions

No files matched your search

+1
View File
@@ -29,3 +29,4 @@ node_modules/
# Rider
.idea
_ReSharper.Caches/
+3 -3
View File
@@ -1,3 +1,3 @@
[submodule "Test/BetterGenshinImpact.UnitTest/Assets"]
path = Test/BetterGenshinImpact.UnitTest/Assets
url = https://github.com/huiyadanli/BetterGI.UnitTest.Assets.git
[submodule "BetterGenshinImpact/Script"]
path = BetterGenshinImpact/Script
url = https://github.com/babalae/bettergi-scripts.git
@@ -0,0 +1,19 @@
<Project Sdk="MSTest.Sdk/3.6.4">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseVSTest>true</UseVSTest>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BetterGenshinImpact.CombatScript\BetterGenshinImpact.CombatScript.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,52 @@
namespace BetterGenshinImpact.CombatScript.Test;
[TestClass]
public sealed class ScriptEmitTest
{
[TestMethod]
public void TestEmit()
{
ScriptUnit scriptUnit = new(
[
new CommentSymbol("测试注释"),
new LineBreakTriviaSymbol(),
new AvatarInstructionListSymbol(new("钟离"), [new SpaceTriviaSymbol()], new(
[
new WalkSymbol(WalkDirection.Backward, [new DoubleSymbol(0.1)], [], new CommaTriviaSymbol()),
new SkillSymbol(true, [new HoldSymbol()], [new SpaceTriviaSymbol()], new CommaTriviaSymbol()),
new WaitSymbol([new DoubleSymbol(0.3)], [new SpaceTriviaSymbol()], new CommaTriviaSymbol()),
new WalkSymbol(WalkDirection.Forward, [new DoubleSymbol(0.1)], [new SpaceTriviaSymbol()], default),
])),
new LineBreakTriviaSymbol(),
new AvatarInstructionListSymbol(new("芙宁娜"), [new SpaceTriviaSymbol()], new(
[
new SkillSymbol(true, [], new CommaTriviaSymbol()),
new BurstSymbol(true, [new SpaceTriviaSymbol()], default)
])),
new LineBreakTriviaSymbol(),
new AvatarInstructionListSymbol(new("行秋"), [new SpaceTriviaSymbol()], new(
[
new SkillSymbol(true, [], new CommaTriviaSymbol()),
new BurstSymbol(true, [new SpaceTriviaSymbol()], new CommaTriviaSymbol()),
new SkillSymbol(true, [new SpaceTriviaSymbol()], default),
])),
]);
Console.WriteLine(scriptUnit.Emit(new SymbolEmitter()));
}
[TestMethod]
public void TestParse()
{
ReadOnlySpan<char> raw = """
// 测试注释
钟离 s(0.1),e(hold),wait(0.3),w(0.1)
芙宁娜 e,q
行秋 e,q,e
""";
ScriptUnit scriptUnit = SymbolParser.Parse(raw);
Console.WriteLine(scriptUnit.Emit(new SymbolEmitter()));
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class AttackSymbol : InstructionSymbol, IInstructionSymbolHasDuration
{
public AttackSymbol(ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("attack", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [0, 1]);
if (parameterList.Length is 1)
{
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out DoubleSymbol doubleSymbol);
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
}
}
public AttackSymbol(ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("attack", leadingTriviaList, tailingTrivia)
{
}
public bool HasDuration { get; }
public TimeSpan Duration { get; }
}
@@ -0,0 +1,24 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public sealed class AvatarInstructionListSymbol : BaseSymbol
{
public AvatarInstructionListSymbol(AvatarSymbol avatar, ImmutableArray<TriviaSymbol> triviaList, InstructionListSymbol instructionList)
{
Avatar = avatar;
TriviaList = triviaList;
InstructionList = instructionList;
}
public AvatarSymbol Avatar { get; }
public ImmutableArray<TriviaSymbol> TriviaList { get; }
public InstructionListSymbol InstructionList { get; }
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(Avatar).Append(TriviaList).Append(InstructionList);
}
}
@@ -0,0 +1,16 @@
namespace BetterGenshinImpact.CombatScript;
public sealed class AvatarSymbol : BaseSymbol
{
public AvatarSymbol(string name)
{
Name = name;
}
public string Name { get; }
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(Name);
}
}
@@ -0,0 +1,6 @@
namespace BetterGenshinImpact.CombatScript;
public abstract class BaseSymbol : ISymbol
{
public abstract void Emit(ISymbolEmitter emitter);
}
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
@@ -0,0 +1,25 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class BurstSymbol : InstructionSymbol, IInstructionSymbolHasAlias
{
public BurstSymbol(bool isAlias, ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("burst", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [0]);
IsAlias = isAlias;
}
public BurstSymbol(bool isAlias, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("burst", leadingTriviaList, tailingTrivia)
{
IsAlias = isAlias;
}
public string AliasName { get; } = "q";
public bool IsAlias { get; }
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class ChargeSymbol : InstructionSymbol, IInstructionSymbolHasDuration
{
public ChargeSymbol(ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("charge", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [0, 1]);
if (parameterList.Length is 1)
{
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out DoubleSymbol doubleSymbol);
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
}
}
public ChargeSymbol(ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("charge", leadingTriviaList, tailingTrivia)
{
}
public bool HasDuration { get; }
public TimeSpan Duration { get; }
}
@@ -0,0 +1,17 @@
namespace BetterGenshinImpact.CombatScript;
public sealed class CommaTriviaSymbol : TriviaSymbol
{
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(',');
}
}
public sealed class SemicolonTriviaSymbol : TriviaSymbol
{
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(';');
}
}
@@ -0,0 +1,16 @@
namespace BetterGenshinImpact.CombatScript;
public sealed class CommentSymbol : TriviaSymbol
{
public CommentSymbol(string comment)
{
Comment = comment;
}
public string Comment { get; }
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append("//").Append(Comment);
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class DashSymbol : InstructionSymbol, IInstructionSymbolHasDuration
{
public DashSymbol(ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("dash", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [0, 1]);
if (parameterList.Length is 1)
{
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out DoubleSymbol doubleSymbol);
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
}
}
public DashSymbol(ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("dash", leadingTriviaList, tailingTrivia)
{
}
public bool HasDuration { get; }
public TimeSpan Duration { get; }
}
@@ -0,0 +1,16 @@
namespace BetterGenshinImpact.CombatScript;
public sealed class DoubleSymbol : BaseSymbol, IParameterSymbol
{
public DoubleSymbol(double value)
{
Value = value;
}
public double Value { get; }
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(Value);
}
}
@@ -0,0 +1,9 @@
namespace BetterGenshinImpact.CombatScript;
public sealed class HoldSymbol : BaseSymbol, IParameterSymbol
{
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append("hold");
}
}
@@ -0,0 +1,8 @@
namespace BetterGenshinImpact.CombatScript;
public interface IInstructionSymbolHasAlias
{
public string AliasName { get; }
public bool IsAlias { get; }
}
@@ -0,0 +1,10 @@
using System;
namespace BetterGenshinImpact.CombatScript;
public interface IInstructionSymbolHasDuration
{
public bool HasDuration { get; }
public TimeSpan Duration { get; }
}
@@ -0,0 +1,5 @@
namespace BetterGenshinImpact.CombatScript;
public interface IParameterSymbol : ISymbol
{
}
@@ -0,0 +1,6 @@
namespace BetterGenshinImpact.CombatScript;
public interface ISymbol
{
void Emit(ISymbolEmitter emitter);
}
@@ -0,0 +1,14 @@
namespace BetterGenshinImpact.CombatScript;
public interface ISymbolEmitter
{
string Emit();
ISymbolEmitter Append(char value);
ISymbolEmitter Append(char value, int repeatCount);
ISymbolEmitter Append(double value);
ISymbolEmitter Append(string value);
}
@@ -0,0 +1,18 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public sealed class InstructionListSymbol : BaseSymbol
{
public InstructionListSymbol(ImmutableArray<InstructionSymbol> instructions)
{
Instructions = instructions;
}
public ImmutableArray<InstructionSymbol> Instructions { get; }
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(Instructions);
}
}
@@ -0,0 +1,59 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public abstract class InstructionSymbol : BaseSymbol
{
protected InstructionSymbol(string name, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
{
Name = name;
HasParameterList = false;
LeadingTriviaList = leadingTriviaList;
TailingTrivia = tailingTrivia;
}
protected InstructionSymbol(string name, ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
{
Name = name;
HasParameterList = true;
ParameterList = parameterList;
LeadingTriviaList = leadingTriviaList;
TailingTrivia = tailingTrivia;
}
public string Name { get; }
public bool HasParameterList { get; }
public ImmutableArray<IParameterSymbol> ParameterList { get; }
public ImmutableArray<TriviaSymbol> LeadingTriviaList { get; }
public TriviaSymbol? TailingTrivia { get; set; }
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(LeadingTriviaList);
if (this is IInstructionSymbolHasAlias {IsAlias: true } hasAlias)
{
emitter.Append(hasAlias.AliasName);
}
else
{
emitter.Append(Name);
}
if (HasParameterList)
{
emitter.Append('(');
emitter.Append(ParameterList);
emitter.Append(')');
}
if (TailingTrivia is not null)
{
emitter.Append(TailingTrivia);
}
}
}
@@ -0,0 +1,35 @@
using System;
using System.Collections.Frozen;
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public static class InstructionThrowHelper
{
public static void ThrowIfParameterListIsDefault(ImmutableArray<IParameterSymbol> parameterList)
{
if (parameterList.IsDefault)
{
throw new ArgumentException($"Parameter list can not be default.");
}
}
public static void ThrowIfParameterListCountNotCorrect(ImmutableArray<IParameterSymbol> parameterList, FrozenSet<int> allowedCounts)
{
if (!allowedCounts.Contains(parameterList.Length))
{
throw new ArgumentException($"Instruction parameter count not correct.");
}
}
public static void ThrowIfParameterAtIndexIsNot<T>(ImmutableArray<IParameterSymbol> parameterList, int index, out T symbol)
where T : IParameterSymbol
{
if (parameterList.Length <= index || parameterList[index] is not T result)
{
throw new ArgumentException($"Instruction's parameter at index {index} must be a {typeof(T).Name}.");
}
symbol = result;
}
}
@@ -0,0 +1,25 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class JumpSymbol : InstructionSymbol, IInstructionSymbolHasAlias
{
public JumpSymbol(bool isAlias, ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("jump", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [0]);
IsAlias = isAlias;
}
public JumpSymbol(bool isAlias, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("jump", leadingTriviaList, tailingTrivia)
{
IsAlias = isAlias;
}
public string AliasName { get; } = "j";
public bool IsAlias { get; }
}
@@ -0,0 +1,28 @@
using System;
namespace BetterGenshinImpact.CombatScript;
public class LineBreakTriviaSymbol : TriviaSymbol
{
private readonly string lineBreak;
public LineBreakTriviaSymbol()
{
lineBreak = Environment.NewLine;
}
public LineBreakTriviaSymbol(string lineBreak)
{
if (lineBreak is not ("\r\n" or "\n" or "\r" or ";"))
{
throw new ArgumentException("Invalid line break.");
}
this.lineBreak = lineBreak;
}
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(lineBreak);
}
}
@@ -0,0 +1,23 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public sealed class ScriptUnit
{
public ScriptUnit(ImmutableArray<ISymbol> symbols)
{
Symbols = symbols;
}
public ImmutableArray<ISymbol> Symbols { get; }
public string Emit(ISymbolEmitter emitter)
{
foreach (ref readonly ISymbol symbol in Symbols.AsSpan())
{
symbol.Emit(emitter);
}
return emitter.Emit();
}
}
@@ -0,0 +1,30 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class SkillSymbol : InstructionSymbol, IInstructionSymbolHasAlias
{
public SkillSymbol(bool isAlias, ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("skill", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [0, 1]);
if (parameterList.Length is 1)
{
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out HoldSymbol _);
}
IsAlias = isAlias;
}
public SkillSymbol(bool isAlias, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("skill", leadingTriviaList, tailingTrivia)
{
IsAlias = isAlias;
}
public string AliasName { get; } = "e";
public bool IsAlias { get; }
}
@@ -0,0 +1,21 @@
namespace BetterGenshinImpact.CombatScript;
public class SpaceTriviaSymbol : TriviaSymbol
{
private readonly int count;
public SpaceTriviaSymbol()
{
count = 1;
}
public SpaceTriviaSymbol(int count)
{
this.count = count;
}
public override void Emit(ISymbolEmitter emitter)
{
emitter.Append(' ', count);
}
}
@@ -0,0 +1,37 @@
using System.Text;
namespace BetterGenshinImpact.CombatScript;
public sealed class SymbolEmitter : ISymbolEmitter
{
private readonly StringBuilder builder = new();
public string Emit()
{
return builder.ToString();
}
public ISymbolEmitter Append(char value)
{
builder.Append(value);
return this;
}
public ISymbolEmitter Append(char value, int repeatCount)
{
builder.Append(value, repeatCount);
return this;
}
public ISymbolEmitter Append(double value)
{
builder.Append(value);
return this;
}
public ISymbolEmitter Append(string value)
{
builder.Append(value);
return this;
}
}
@@ -0,0 +1,23 @@
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public static class SymbolEmitterExtensions
{
public static ISymbolEmitter Append(this ISymbolEmitter emitter, ISymbol symbol)
{
symbol.Emit(emitter);
return emitter;
}
public static ISymbolEmitter Append<TSymbol>(this ISymbolEmitter emitter, ImmutableArray<TSymbol> symbolList)
where TSymbol : ISymbol
{
foreach(ref readonly TSymbol symbol in symbolList.AsSpan())
{
symbol.Emit(emitter);
}
return emitter;
}
}
@@ -0,0 +1,193 @@
using System;
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
namespace BetterGenshinImpact.CombatScript;
public static class SymbolParser
{
public static ScriptUnit Parse(ReadOnlySpan<char> raw)
{
ImmutableArray<ISymbol>.Builder symbols = ImmutableArray.CreateBuilder<ISymbol>();
ParseLines(raw, symbols);
return new(symbols.ToImmutable());
}
private static void ParseLines(ReadOnlySpan<char> raw, ImmutableArray<ISymbol>.Builder symbols)
{
bool skipNextRange = false;
ref readonly char end = ref raw[^1];
foreach(Range range in raw.SplitAny(['\r', '\n', ';']))
{
if (skipNextRange)
{
skipNextRange = false;
continue;
}
int offset = range.End.GetOffset(raw.Length);
if (offset >= raw.Length)
{
break;
}
ref readonly char peek = ref raw[offset];
LineBreakTriviaSymbol lineBreakTrivia;
if (peek is '\r')
{
if (Unsafe.IsAddressLessThan(in peek, in end) && Unsafe.Add(ref Unsafe.AsRef(in peek), 1) is '\n')
{
// It's a CRLF
lineBreakTrivia = new("\r\n");
skipNextRange = true;
}
else
{
// It's a CR
lineBreakTrivia = new("\r");
}
}
else if (peek is '\n')
{
// It's a LF
lineBreakTrivia = new("\n");
}
else if (peek is ';')
{
lineBreakTrivia = new(";");
}
else
{
throw new InvalidOperationException($"Failed to parse line break trivia at {range}.");
}
if (ParseLine(raw[range]) is { } symbol)
{
symbols.Add(symbol);
}
symbols.Add(lineBreakTrivia);
}
}
private static ISymbol? ParseLine(ReadOnlySpan<char> raw)
{
if (raw.IsEmpty)
{
return default;
}
if (raw.StartsWith("//"))
{
return new CommentSymbol(raw[2..].ToString());
}
int indexOfSpace = raw.IndexOf(' ');
ReadOnlySpan<char> avatarIdentifier = raw[..indexOfSpace];
AvatarSymbol avatarSymbol = new(avatarIdentifier.ToString());
ImmutableArray<TriviaSymbol> triviaList = ParseTriviaList(raw[indexOfSpace..], out int advanced);
InstructionListSymbol listSymbol = ParseInstructionList(raw[(indexOfSpace + advanced)..]);
return new AvatarInstructionListSymbol(avatarSymbol, triviaList, listSymbol);
}
private static InstructionListSymbol ParseInstructionList(ReadOnlySpan<char> raw)
{
ImmutableArray<InstructionSymbol>.Builder builder = ImmutableArray.CreateBuilder<InstructionSymbol>();
foreach (Range range in raw.Split(','))
{
ReadOnlySpan<char> current = raw[range];
ImmutableArray<TriviaSymbol> leadingTriviaList = ParseTriviaList(current, out int advanced);
if (ParseInstruction(current[advanced..], leadingTriviaList) is { } symbol)
{
builder.Add(symbol);
}
}
return new(builder.ToImmutable());
}
private static InstructionSymbol? ParseInstruction(ReadOnlySpan<char> raw, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
{
if (raw.IsEmpty)
{
return default;
}
switch (raw[0])
{
// attack|a
case 'a':
break;
// burst
case 'b':
return new BurstSymbol(false, [], leadingTriviaList, tailingTrivia);
break;
// charge
case 'c':
break;
// dash|d
case 'd':
break;
// jump|j
case 'j':
break;
// q
case 'q':
return new BurstSymbol(true, [], leadingTriviaList, tailingTrivia);
break;
// skill|s
case 's':
break;
// wait|walk|w
case 'w':
break;
}
return default;
}
// Handle ','&' '
private static ImmutableArray<TriviaSymbol> ParseTriviaList(ReadOnlySpan<char> raw, out int advanced)
{
advanced = 0;
if (raw.IsEmpty)
{
return ImmutableArray<TriviaSymbol>.Empty;
}
ImmutableArray<TriviaSymbol>.Builder builder = ImmutableArray.CreateBuilder<TriviaSymbol>();
int spaceCount = 0;
foreach (ref readonly char value in raw)
{
advanced++;
if (value is ' ')
{
spaceCount++;
}
else
{
if (spaceCount is not 0)
{
builder.Add(new SpaceTriviaSymbol(spaceCount));
spaceCount = 0;
}
if (value is ',')
{
builder.Add(new CommaTriviaSymbol());
}
else
{
break;
}
}
}
return builder.ToImmutable();
}
}
@@ -0,0 +1,5 @@
namespace BetterGenshinImpact.CombatScript;
public abstract class TriviaSymbol : BaseSymbol
{
}
@@ -0,0 +1,23 @@
using System;
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class WaitSymbol : InstructionSymbol, IInstructionSymbolHasDuration
{
public WaitSymbol(ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("wait", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [1]);
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out DoubleSymbol doubleSymbol);
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
}
public bool HasDuration { get; }
public TimeSpan Duration { get; }
}
@@ -0,0 +1,9 @@
namespace BetterGenshinImpact.CombatScript;
public enum WalkDirection
{
Forward,
Backward,
Left,
Right
}
@@ -0,0 +1,70 @@
using System;
using System.Collections.Immutable;
namespace BetterGenshinImpact.CombatScript;
public class WalkSymbol : InstructionSymbol, IInstructionSymbolHasAlias, IInstructionSymbolHasDuration, IParameterSymbol
{
public WalkSymbol(WalkDirection direction, ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("walk", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [1]);
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out DoubleSymbol doubleSymbol);
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
Direction = direction;
IsAlias = true;
}
// Used for parameter
public WalkSymbol(WalkDirection direction, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("walk", leadingTriviaList, tailingTrivia)
{
Direction = direction;
IsAlias = true;
}
public WalkSymbol(ImmutableArray<IParameterSymbol> parameterList, ImmutableArray<TriviaSymbol> leadingTriviaList, TriviaSymbol? tailingTrivia)
: base("walk", parameterList, leadingTriviaList, tailingTrivia)
{
InstructionThrowHelper.ThrowIfParameterListIsDefault(parameterList);
InstructionThrowHelper.ThrowIfParameterListCountNotCorrect(parameterList, [2]);
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 0, out WalkSymbol directionAlias);
InstructionThrowHelper.ThrowIfParameterAtIndexIsNot(parameterList, 1, out DoubleSymbol doubleSymbol);
Direction = directionAlias.Direction;
HasDuration = true;
Duration = TimeSpan.FromSeconds(doubleSymbol.Value);
IsAlias = false;
}
public string AliasName
{
get
{
return Direction switch
{
WalkDirection.Forward => "w",
WalkDirection.Backward => "s",
WalkDirection.Left => "a",
WalkDirection.Right => "d",
_ => throw new ArgumentOutOfRangeException(),
};
}
}
public bool IsAlias { get; }
public WalkDirection Direction { get; }
public bool HasDuration { get; }
public TimeSpan Duration { get; }
}
File renamed without changes.
@@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\BetterGenshinImpact\BetterGenshinImpact.csproj" />
<ProjectReference Include="..\BetterGenshinImpact\BetterGenshinImpact.csproj" />
</ItemGroup>
</Project>
@@ -19,17 +19,17 @@ public class AvatarClassifyGen
// 读取基础图像
// List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "*.png", SearchOption.TopDirectoryOnly).ToList();
// 只用一个图像
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Mizuki.png", SearchOption.TopDirectoryOnly).ToList();
// List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Iansan.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles2);
// List<string> sideImageFiles3 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Citlali.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles3);
// List<string> sideImageFiles4 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Lanyan.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles4);
// List<string> sideImageFiles5 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_XianglingCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles5);
// List<string> sideImageFiles6 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Mavuika.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles6);
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_HutaoCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Iansan.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles2);
List<string> sideImageFiles3 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Citlali.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles3);
List<string> sideImageFiles4 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Lanyan.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles4);
List<string> sideImageFiles5 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_XianglingCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles5);
List<string> sideImageFiles6 = Directory.GetFiles(Path.Combine(BaseDir, "side_src"), "UI_AvatarIcon_Side_Mavuika.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles6);
// 生成训练集
GenTo(sideImageFiles, Path.Combine(BaseDir, @"dateset\train"), 200);
@@ -27,17 +27,17 @@ public class AvatarClassifyTransparentGen
// 读取基础图像
// List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "*.png", SearchOption.TopDirectoryOnly).ToList();
// 只用一个图像
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Mizuki.png", SearchOption.TopDirectoryOnly).ToList();
// List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Iansan.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles2);
// List<string> sideImageFiles3 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Citlali.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles3);
// List<string> sideImageFiles4 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Lanyan.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles4);
// List<string> sideImageFiles5 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_XianglingCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles5);
// List<string> sideImageFiles6 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Mavuika.png", SearchOption.TopDirectoryOnly).ToList();
// sideImageFiles.AddRange(sideImageFiles6);
List<string> sideImageFiles = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_HutaoCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
List<string> sideImageFiles2 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Iansan.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles2);
List<string> sideImageFiles3 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Citlali.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles3);
List<string> sideImageFiles4 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Lanyan.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles4);
List<string> sideImageFiles5 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_XianglingCostumeWinter.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles5);
List<string> sideImageFiles6 = Directory.GetFiles(Path.Combine(BaseDir, SideSrcTransportDir), "UI_AvatarIcon_Side_Mavuika.png", SearchOption.TopDirectoryOnly).ToList();
sideImageFiles.AddRange(sideImageFiles6);
// 生成训练集
GenTo(sideImageFiles, Path.Combine(BaseDir, @"dateset\train"), 200);
// 生成测试集
@@ -20,7 +20,7 @@ public class MapTeleportPointDraw
Cv2.ImWrite(@"E:\HuiTask\更好的原神\地图匹配\有用的素材\5.0\传送点_1024_0.34.3.png", map);
}
public static void DrawTeleportPoint(Mat map, List<GiTpPosition> points)
public static void DrawTeleportPoint(Mat map, List<GiWorldPosition> points)
{
foreach (var point in points)
{
@@ -61,7 +61,7 @@ internal class HsvTestWindow
Cv2.CreateTrackbar("High S", _windowDetectionName, ref _highS, MaxValue, on_high_S_thresh_trackbar);
Cv2.CreateTrackbar("Low V", _windowDetectionName, ref _lowV, MaxValue, on_low_V_thresh_trackbar);
Cv2.CreateTrackbar("High V", _windowDetectionName, ref _highV, MaxValue, on_high_V_thresh_trackbar);
var frame = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\Q识别\拼图\2.png", ImreadModes.Color);
var frame = Cv2.ImRead(@"E:\HuiTask\更好的原神\自动秘境\自动战斗\队伍识别\bsz1.png", ImreadModes.Color);
Mat frameHsv = new Mat();
// Convert from BGR to HSV colorspace
Cv2.CvtColor(frame, frameHsv, ColorConversionCodes.BGR2HSV);
+25 -19
View File
@@ -15,13 +15,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicaSetup", "Build\MicaSetu
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MicaSetup.Uninst", "Build\MicaSetup\MicaSetup.Uninst.csproj", "{673344BC-B860-44AE-AD88-D33465BDE25B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterGenshinImpact.Test", "Test\BetterGenshinImpact.Test\BetterGenshinImpact.Test.csproj", "{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BetterGenshinImpact.Test", "BetterGenshinImpact.Test\BetterGenshinImpact.Test.csproj", "{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fischless.WindowsInput", "Fischless.WindowsInput\Fischless.WindowsInput.csproj", "{9D00BC7A-9280-4AC9-8951-4502EDB71B76}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{02CEA57F-C24B-40F9-AF31-F1D4F3BDB4BF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterGenshinImpact.CombatScript", "BetterGenshinImpact.CombatScript\BetterGenshinImpact.CombatScript.csproj", "{57C278F9-F62A-480A-B929-B0E5D8174194}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterGenshinImpact.UnitTest", "Test\BetterGenshinImpact.UnitTest\BetterGenshinImpact.UnitTest.csproj", "{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterGenshinImpact.CombatScript.Test", "BetterGenshinImpact.CombatScript.Test\BetterGenshinImpact.CombatScript.Test.csproj", "{09427DA8-665E-441A-A576-C11FBC6F9E5C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -73,12 +73,12 @@ Global
{673344BC-B860-44AE-AD88-D33465BDE25B}.Release|x64.Build.0 = Release|x64
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|x64.ActiveCfg = Debug|x64
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|x64.Build.0 = Debug|x64
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|Any CPU.ActiveCfg = Release|x64
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|Any CPU.Build.0 = Release|x64
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|x64.ActiveCfg = Release|x64
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|x64.Build.0 = Release|x64
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|x64.ActiveCfg = Debug|Any CPU
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Debug|x64.Build.0 = Debug|Any CPU
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|Any CPU.Build.0 = Release|Any CPU
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|x64.ActiveCfg = Release|Any CPU
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE}.Release|x64.Build.0 = Release|Any CPU
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Debug|Any CPU.ActiveCfg = Debug|x64
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Debug|Any CPU.Build.0 = Debug|x64
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Debug|x64.ActiveCfg = Debug|x64
@@ -87,14 +87,22 @@ Global
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Release|Any CPU.Build.0 = Release|x64
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Release|x64.ActiveCfg = Release|x64
{9D00BC7A-9280-4AC9-8951-4502EDB71B76}.Release|x64.Build.0 = Release|x64
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Debug|x64.ActiveCfg = Debug|x64
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Debug|x64.Build.0 = Debug|x64
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Release|Any CPU.ActiveCfg = Release|x64
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Release|Any CPU.Build.0 = Release|x64
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Release|x64.ActiveCfg = Release|x64
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98}.Release|x64.Build.0 = Release|x64
{57C278F9-F62A-480A-B929-B0E5D8174194}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57C278F9-F62A-480A-B929-B0E5D8174194}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57C278F9-F62A-480A-B929-B0E5D8174194}.Debug|x64.ActiveCfg = Debug|Any CPU
{57C278F9-F62A-480A-B929-B0E5D8174194}.Debug|x64.Build.0 = Debug|Any CPU
{57C278F9-F62A-480A-B929-B0E5D8174194}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57C278F9-F62A-480A-B929-B0E5D8174194}.Release|Any CPU.Build.0 = Release|Any CPU
{57C278F9-F62A-480A-B929-B0E5D8174194}.Release|x64.ActiveCfg = Release|Any CPU
{57C278F9-F62A-480A-B929-B0E5D8174194}.Release|x64.Build.0 = Release|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Debug|x64.ActiveCfg = Debug|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Debug|x64.Build.0 = Debug|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Release|Any CPU.Build.0 = Release|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Release|x64.ActiveCfg = Release|Any CPU
{09427DA8-665E-441A-A576-C11FBC6F9E5C}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -102,8 +110,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{AB85DA23-EB8F-4FBF-A7FA-35CE05B23C15} = {458E1106-43A4-47E6-B11B-D243035D4C76}
{673344BC-B860-44AE-AD88-D33465BDE25B} = {458E1106-43A4-47E6-B11B-D243035D4C76}
{27AF227E-BE44-450F-8E95-C1AD4FDE14BE} = {02CEA57F-C24B-40F9-AF31-F1D4F3BDB4BF}
{7DA575C0-8D1E-4BD2-AEDB-5471D8906B98} = {02CEA57F-C24B-40F9-AF31-F1D4F3BDB4BF}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {352D8B78-9DE3-4E58-985F-FADD22594DB4}
-1
View File
@@ -19,7 +19,6 @@
<bgivc:BooleanToEnableTextConverter x:Key="BooleanToEnableTextConverter" />
<bgivc:InverseBooleanConverter x:Key="InverseBooleanConverter" />
<bgivc:NotNullConverter x:Key="NotNullConverter" />
<bgivc:EnumToKVPConverter x:Key="EnumToKVPConverter" />
</ResourceDictionary>
</Application.Resources>
</Application>
+4 -5
View File
@@ -11,6 +11,7 @@ using BetterGenshinImpact.View.Pages;
using BetterGenshinImpact.ViewModel;
using BetterGenshinImpact.ViewModel.Pages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
@@ -21,9 +22,10 @@ using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using BetterGenshinImpact.View.Pages.View;
using BetterGenshinImpact.ViewModel.Pages.OneDragon;
using BetterGenshinImpact.ViewModel.Pages.View;
using Wpf.Ui;
using Wpf.Ui.DependencyInjection;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact;
@@ -71,11 +73,10 @@ public partial class App : Application
Log.Logger = loggerConfiguration.CreateLogger();
services.AddLogging(c => c.AddSerilog());
services.AddNavigationViewPageProvider();
// App Host
services.AddHostedService<ApplicationHostService>();
// Page resolver service
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<IPageService, PageService>();
services.AddSingleton<IUpdateService, UpdateService>();
// Service containing navigation, same as INavigationWindow... but without window
@@ -184,8 +185,6 @@ public partial class App : Application
protected override async void OnExit(ExitEventArgs e)
{
base.OnExit(e);
TempManager.CleanUp();
await _host.StopAsync();
_host.Dispose();
Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.
+4 -28
View File
@@ -10,7 +10,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<ApplicationIcon>Assets\Images\logo.ico</ApplicationIcon>
<AssemblyName>BetterGI</AssemblyName>
<AssemblyVersion>0.43.2</AssemblyVersion>
<AssemblyVersion>0.39.4</AssemblyVersion>
<Platforms>x64</Platforms>
<DebugType>embedded</DebugType>
</PropertyGroup>
@@ -41,18 +41,12 @@
<ItemGroup>
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
<PackageReference Include="BehaviourTree" Version="1.0.73" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="DeviceId" Version="6.8.0" />
<PackageReference Include="DeviceId.Windows" Version="6.8.0" />
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.8.0" />
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.18.1" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.18.1" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2592.51" />
<PackageReference Include="Ookii.Dialogs.Wpf" Version="5.0.1" />
<PackageReference Include="OpenCvSharp4.WpfExtensions" Version="4.8.0.20230708" />
@@ -75,10 +69,9 @@
<PackageReference Include="Vanara.PInvoke.NtDll" Version="4.0.2" />
<PackageReference Include="Vanara.PInvoke.SHCore" Version="4.0.2" />
<PackageReference Include="Vanara.PInvoke.User32" Version="4.0.2" />
<PackageReference Include="WPF-UI" Version="4.0.0" />
<PackageReference Include="WPF-UI.DependencyInjection" Version="4.0.0" />
<PackageReference Include="WPF-UI.Tray" Version="4.0.0" />
<PackageReference Include="WPF-UI.Violeta" Version="4.0.0" />
<PackageReference Include="WPF-UI" Version="3.0.5" />
<PackageReference Include="WPF-UI.Tray" Version="3.0.5" />
<PackageReference Include="WPF-UI.Violeta" Version="3.0.5.26" />
<PackageReference Include="YoloV8" Version="4.1.7" />
<PackageReference Include="gong-wpf-dragdrop" Version="3.2.1" />
</ItemGroup>
@@ -153,25 +146,8 @@
</ItemGroup>
<ItemGroup>
<Folder Include="GameTask\Model\Enum\" />
<Folder Include="GameTask\OneDragon\" />
<Folder Include="Service\Notification\Builder\" />
<Folder Include="User\AutoPathing\" />
</ItemGroup>
<ItemGroup>
<Page Update="View\Windows\WelcomeDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Update="View\Windows\WelcomeDialog.xaml.cs">
<SubType>Code</SubType>
<DependentUpon>WelcomeDialog.xaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
+11 -18
View File
@@ -17,7 +17,6 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.AutoTrackPath;
namespace BetterGenshinImpact.Core.Config;
@@ -51,13 +50,13 @@ public partial class AllConfig : ObservableObject
[ObservableProperty]
private int _triggerInterval = 50;
// /// <summary>
// /// WGC使用位图缓存
// /// 高帧率情况下,可能会导致卡顿
// /// 云原神可能会出现黑屏
// /// </summary>
// [ObservableProperty]
// private bool _wgcUseBitmapCache = true;
/// <summary>
/// WGC使用位图缓存
/// 高帧率情况下,可能会导致卡顿
/// 云原神可能会出现黑屏
/// </summary>
[ObservableProperty]
private bool _wgcUseBitmapCache = true;
/// <summary>
/// 自动修复Win11下BitBlt截图方式不可用的问题
@@ -158,7 +157,7 @@ public partial class AllConfig : ObservableObject
public ScriptConfig ScriptConfig { get; set; } = new();
/// <summary>
/// 地图追踪配置
/// 路径追踪配置
/// </summary>
public PathingConditionConfig PathingConditionConfig { get; set; } = PathingConditionConfig.Default;
@@ -176,14 +175,7 @@ public partial class AllConfig : ObservableObject
/// 原神按键绑定配置
/// </summary>
public KeyBindingsConfig KeyBindingsConfig { get; set; } = new();
/// <summary>
/// 其他配置
/// </summary>
public OtherConfig OtherConfig { get; set; } = new();
/// <summary>
/// 传送相关配置
/// </summary>
public TpConfig TpConfig { get; set; } = new();
[JsonIgnore]
public Action? OnAnyChangedAction { get; set; }
@@ -196,6 +188,7 @@ public partial class AllConfig : ObservableObject
NotificationConfig.PropertyChanged += OnAnyPropertyChanged;
NotificationConfig.PropertyChanged += OnNotificationPropertyChanged;
KeyBindingsConfig.PropertyChanged += OnAnyPropertyChanged;
AutoPickConfig.PropertyChanged += OnAnyPropertyChanged;
AutoSkipConfig.PropertyChanged += OnAnyPropertyChanged;
AutoFishingConfig.PropertyChanged += OnAnyPropertyChanged;
@@ -207,7 +200,7 @@ public partial class AllConfig : ObservableObject
AutoFightConfig.PropertyChanged += OnAnyPropertyChanged;
AutoDomainConfig.PropertyChanged += OnAnyPropertyChanged;
AutoMusicGameConfig.PropertyChanged += OnAnyPropertyChanged;
TpConfig.PropertyChanged += OnAnyPropertyChanged;
ScriptConfig.PropertyChanged += OnAnyPropertyChanged;
PathingConditionConfig.PropertyChanged += OnAnyPropertyChanged;
}
@@ -1,6 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using Wpf.Ui.Controls;
namespace BetterGenshinImpact.Core.Config;
@@ -40,16 +39,4 @@ public partial class CommonConfig : ObservableObject
/// </summary>
[ObservableProperty]
private bool _isFirstRun = true;
/// <summary>
/// 这个版本是否运行过
/// </summary>
[ObservableProperty]
private string _runForVersion = string.Empty;
/// <summary>
/// 一个设备只运行一次的已运行设备ID列表
/// </summary>
[ObservableProperty]
private List<string> _onceHadRunDeviceIdList = new();
}
@@ -38,10 +38,4 @@ public partial class GenshinStartConfig : ObservableObject
/// </summary>
[ObservableProperty]
private bool _linkedStartEnabled = true;
/// <summary>
/// 使用Starward同步记录时间
/// </summary>
[ObservableProperty]
private bool _recordGameTimeEnabled = false;
}
@@ -148,13 +148,6 @@ public partial class HotKeyConfig : ObservableObject
[ObservableProperty]
private string _autoMusicGameHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
// 活动音游开始/停止
[ObservableProperty]
private string _autoFishingGameHotkey = "";
[ObservableProperty]
private string _autoFishingGameHotkeyType = HotKeyTypeEnum.KeyboardMonitor.ToString();
// 自动寻路
[ObservableProperty]
@@ -14,12 +14,6 @@ namespace BetterGenshinImpact.Core.Config;
public partial class KeyBindingsConfig:ObservableObject
{
/// <summary>
/// 是否启用全局按键映射
/// </summary>
[ObservableProperty]
private bool _globalKeyMappingEnabled = false;
#region Actions(操作)
/// <summary>
@@ -66,10 +66,6 @@ public partial class OneDragonFlowConfig : ObservableObject
[ObservableProperty]
private string _sundayDomainName = string.Empty;
// 完成后操作
[ObservableProperty]
private string _completionAction = string.Empty;
// 通过当天是哪一天来返回配置
public (string partyName, string domainName) GetDomainConfig()
{
@@ -1,14 +0,0 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
namespace BetterGenshinImpact.Core.Config;
[Serializable]
public partial class OtherConfig : ObservableObject
{
//调度器任务和部分独立任务,失去焦点,自动激活游戏窗口
[ObservableProperty]
private bool _restoreFocusOnLostEnabled = false;
}
@@ -12,7 +12,7 @@ namespace BetterGenshinImpact.Core.Config;
[Serializable]
public partial class PathingConditionConfig : ObservableObject
{
// 地图追踪条件配置
// 路径追踪条件配置
[ObservableProperty]
private ObservableCollection<Condition> _partyConditions = [];
@@ -43,13 +43,6 @@ public partial class PathingConditionConfig : ObservableObject
Subject = "队伍中角色",
Object = ["钟离"],
Result = "循环长E"
},
new Condition
{
Subject = "队伍中角色",
Object = ["迪希雅"],
Result = "作为主要行走角色"
}
]
};
@@ -10,21 +10,14 @@ namespace BetterGenshinImpact.Core.Config;
[Serializable]
public partial class PathingPartyConfig : ObservableObject
{
// 配置是否启用,不启用会使用地图追踪内的条件配置
// 配置是否启用,不启用会使用路径追踪内的条件配置
[ObservableProperty]
private bool _enabled = false;
// 是否启用自动拾取
[ObservableProperty]
private bool _autoPickEnabled = true;
// 切换到队伍的名称
[ObservableProperty]
private string _partyName = string.Empty;
// 切换队伍前是否前往须弥七天神像
[ObservableProperty]
private bool _isVisitStatueBeforeSwitchParty = false;
// 主要行走追踪的角色编号
[ObservableProperty]
private string _mainAvatarIndex = string.Empty;
@@ -68,7 +61,7 @@ public partial class PathingPartyConfig : ObservableObject
[ObservableProperty]
private bool _onlyInTeleportRecover = false;
//允许在jsScript脚本中使用此地图追踪配置
//允许在jsScript脚本中使用此路径追踪配置
[ObservableProperty]
private bool _jsScriptUseEnabled = false;
@@ -76,10 +69,6 @@ public partial class PathingPartyConfig : ObservableObject
[ObservableProperty]
private bool _soloTaskUseFightEnabled = false;
//不在某时执行
[ObservableProperty]
private string _skipDuring = "";
// 使用小道具的间隔时间
[ObservableProperty]
private int _useGadgetIntervalMs = 0;
@@ -98,6 +87,7 @@ public partial class PathingPartyConfig : ObservableObject
[ObservableProperty]
private AutoFightConfig _autoFightConfig = new();
public static PathingPartyConfig BuildDefault()
{
// 即便是不启用的情况下也设置默认值,减少后续使用的判断
@@ -8,7 +8,7 @@
// using BetterGenshinImpact.GameTask.Common.Element.Assets;
// using BetterGenshinImpact.GameTask.Common.Map;
// using BetterGenshinImpact.GameTask.Model.Area;
//
// using BetterGenshinImpact.GameTask.Model.Enum;
// using BetterGenshinImpact.View.Drawable;
// using BetterGenshinImpact.ViewModel.Pages;
// using Microsoft.Extensions.Logging;
@@ -95,10 +95,6 @@ public class KeyMouseRecorder
break;
}
}
if (currentMerge != null)
{
mergedMacroEvents.Add(currentMerge);
}
KeyMouseScript keyMouseScript = new()
{
MacroEvents = mergedMacroEvents,
@@ -4,8 +4,9 @@ using BetterGenshinImpact.ViewModel.Pages;
using System;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.AutoDomain;
using BetterGenshinImpact.GameTask.AutoFishing;
using BetterGenshinImpact.GameTask.AutoFight;
using BetterGenshinImpact.GameTask.AutoWood;
using BetterGenshinImpact.GameTask.Model.Enum;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation;
using BetterGenshinImpact.GameTask.AutoPathing.Handler;
@@ -13,8 +14,8 @@ namespace BetterGenshinImpact.Core.Script.Dependence;
public class Dispatcher
{
private object _config = null;
public Dispatcher(object config)
private object _config=null;
public Dispatcher(object config)
{
_config = config;
}
@@ -82,7 +83,7 @@ public class Dispatcher
break;
case "AutoFight":
/*if (taskSettingsPageViewModel.GetFightStrategy(out var path1))
{
return;
@@ -90,7 +91,7 @@ public class Dispatcher
var autoFightConfig = TaskContext.Instance().Config.AutoFightConfig;
var param = new AutoFightParam(path1, autoFightConfig);
await new AutoFightTask(param).Start(CancellationContext.Instance.Cts.Token);*/
await new AutoFightHandler().RunAsyncByScript(CancellationContext.Instance.Cts.Token, null, _config);
await new AutoFightHandler().RunAsyncByScript(CancellationContext.Instance.Cts.Token, null,_config);
break;
case "AutoDomain":
@@ -105,10 +106,6 @@ public class Dispatcher
// taskSettingsPageViewModel.SwitchAutoMusicGameCommand.Execute(null);
// break;
case "AutoFishing":
await new AutoFishingTask(AutoFishingTaskParam.BuildFromSoloTaskConfig(soloTask.Config)).Start(CancellationContext.Instance.Cts.Token);
break;
default:
throw new ArgumentException($"未知的任务名称: {soloTask.Name}", nameof(soloTask.Name));
}
@@ -3,9 +3,6 @@ using BetterGenshinImpact.GameTask.AutoTrackPath;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Common.Job;
using Vanara.PInvoke;
using BetterGenshinImpact.GameTask.AutoFishing;
using BetterGenshinImpact.ViewModel.Pages;
using System;
namespace BetterGenshinImpact.Core.Script.Dependence;
@@ -147,21 +144,4 @@ public class Genshin
{
await new ReturnMainUiTask().Start(CancellationContext.Instance.Cts.Token);
}
/// <summary>
/// 钓鱼
/// </summary>
/// <returns></returns>
public async Task AutoFishing(int fishingTimePolicy = 0)
{
var taskSettingsPageViewModel = App.GetService<TaskSettingsPageViewModel>();
if (taskSettingsPageViewModel == null)
{
throw new ArgumentNullException(nameof(taskSettingsPageViewModel), "内部视图模型对象为空");
}
var param = AutoFishingTaskParam.BuildFromConfig(TaskContext.Instance().Config.AutoFishingConfig, taskSettingsPageViewModel.SaveScreenshotOnKeyTick);
param.FishingTimePolicy = (FishingTimePolicy)fishingTimePolicy;
await new AutoFishingTask(param).Start(CancellationContext.Instance.Cts.Token);
}
}
@@ -6,10 +6,6 @@ using System;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Common;
using Vanara.PInvoke;
using static Vanara.PInvoke.User32;
using BetterGenshinImpact.Core.Simulator.Extensions;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.ViewModel.Pages;
namespace BetterGenshinImpact.Core.Script.Dependence;
@@ -24,80 +20,17 @@ public class GlobalMethod
public static void KeyDown(string key)
{
var vk = KeyBindingsSettingsPageViewModel.MappingKey(ToVk(key));
switch (key)
{
case "VK_LBUTTON":
Simulation.SendInput.Mouse.LeftButtonDown();
break;
case "VK_RBUTTON":
Simulation.SendInput.Mouse.RightButtonDown();
break;
case "VK_MBUTTON":
Simulation.SendInput.Mouse.MiddleButtonDown();
break;
case "VK_XBUTTON1":
Simulation.SendInput.Mouse.XButtonDown(0x0001);
break;
case "VK_XBUTTON2":
Simulation.SendInput.Mouse.XButtonDown(0x0001);
break;
default:
Simulation.SendInput.Keyboard.KeyDown(vk);
break;
}
Simulation.SendInput.Keyboard.KeyDown(ToVk(key));
}
public static void KeyUp(string key)
{
var vk = KeyBindingsSettingsPageViewModel.MappingKey(ToVk(key));
switch (key)
{
case "VK_LBUTTON":
Simulation.SendInput.Mouse.LeftButtonUp();
break;
case "VK_RBUTTON":
Simulation.SendInput.Mouse.RightButtonUp();
break;
case "VK_MBUTTON":
Simulation.SendInput.Mouse.MiddleButtonUp();
break;
case "VK_XBUTTON1":
Simulation.SendInput.Mouse.XButtonUp(0x0001);
break;
case "VK_XBUTTON2":
Simulation.SendInput.Mouse.XButtonUp(0x0001);
break;
default:
Simulation.SendInput.Keyboard.KeyUp(vk);
break;
}
Simulation.SendInput.Keyboard.KeyUp(ToVk(key));
}
public static void KeyPress(string key)
{
var vk = KeyBindingsSettingsPageViewModel.MappingKey(ToVk(key));
switch (key)
{
case "VK_LBUTTON":
Simulation.SendInput.Mouse.LeftButtonClick();
break;
case "VK_RBUTTON":
Simulation.SendInput.Mouse.RightButtonClick();
break;
case "VK_MBUTTON":
Simulation.SendInput.Mouse.MiddleButtonClick();
break;
case "VK_XBUTTON1":
Simulation.SendInput.Mouse.XButtonClick(0x0001);
break;
case "VK_XBUTTON2":
Simulation.SendInput.Mouse.XButtonClick(0x0001);
break;
default:
Simulation.SendInput.Keyboard.KeyPress(vk);
break;
}
Simulation.SendInput.Keyboard.KeyPress(ToVk(key));
}
private static User32.VK ToVk(string key)
@@ -112,7 +45,6 @@ public class GlobalMethod
}
}
#endregion 键盘操作
#region 鼠标操作
@@ -1,6 +1,4 @@
using Microsoft.ClearScript;
namespace BetterGenshinImpact.Core.Script.Dependence.Model;
namespace BetterGenshinImpact.Core.Script.Dependence.Model;
/// <summary>
/// 独立任务
@@ -15,16 +13,19 @@ public class SoloTask
/// <summary>
/// 独立任务配置
/// </summary>
public object? Config { get; set; }
public object? Config;
public SoloTask(string name)
{
Name = name;
}
public SoloTask(string name, ScriptObject config)
public SoloTask(string name, dynamic config)
{
Name = name;
Config = config;
// if (Name == "AutoPick")
// {
// Config = ScriptObjectConverter.ConvertTo<AutoPickExternalConfig>(config);
// }
}
}
@@ -12,7 +12,6 @@ using System.Dynamic;
using System.IO;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using BetterGenshinImpact.GameTask.Shell;
namespace BetterGenshinImpact.Core.Script.Group;
@@ -113,11 +112,6 @@ public partial class ScriptGroupProject : ObservableObject
return new ScriptGroupProject(name, name, "KeyMouse");
}
public static ScriptGroupProject BuildShellProject(string command)
{
return new ScriptGroupProject(command, "", "Shell");
}
public static ScriptGroupProject BuildPathingProject(string name, string folder)
{
return new ScriptGroupProject(name, folder, "Pathing");
@@ -153,28 +147,24 @@ public partial class ScriptGroupProject : ObservableObject
await Project.ExecuteAsync(JsScriptSettingsObject,pathingPartyConfig);
}
else if (Type == "KeyMouse")
if (Type == "KeyMouse")
{
// 加载并执行
var json = await File.ReadAllTextAsync(Global.Absolute(@$"User\KeyMouseScript\{Name}"));
await KeyMouseMacroPlayer.PlayMacro(json, CancellationContext.Instance.Cts.Token, false);
}
else if (Type == "Pathing")
if (Type == "Pathing")
{
// 加载并执行
var task = PathingTask.BuildFromFilePath(Path.Combine(MapPathingViewModel.PathJsonPath, FolderName, Name));
TaskTriggerDispatcher.Instance().AddTrigger("AutoPick", null);
var pathingTask = new PathExecutor(CancellationContext.Instance.Cts.Token);
pathingTask.PartyConfig = GroupInfo?.Config.PathingConfig;
if (pathingTask.PartyConfig is null || pathingTask.PartyConfig.AutoPickEnabled)
{
TaskTriggerDispatcher.Instance().AddTrigger("AutoPick", null);
}
await pathingTask.Pathing(task);
}
else if (Type == "Shell")
else
{
var task = ShellExecutor.BuildFromShellName(Name);
await task.Execute();
//throw new Exception("不支持的脚本类型");
}
}
@@ -200,8 +190,7 @@ public class ScriptGroupProjectExtensions
{
{ "Javascript", "JS脚本" },
{ "KeyMouse", "键鼠脚本" },
{ "Pathing", "地图追踪" },
{ "Shell", "Shell" }
{ "Pathing", "路径追踪" }
};
public static readonly Dictionary<string, string> StatusDescriptions = new()
@@ -5,7 +5,6 @@ using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using BetterGenshinImpact.Core.Script.Dependence;
@@ -38,17 +37,14 @@ public class ScriptProject
Manifest.Validate(ProjectPath);
}
public ScrollViewer? LoadSettingUi(dynamic context)
public StackPanel? LoadSettingUi(dynamic context)
{
var settingItems = Manifest.LoadSettingItems(ProjectPath);
if (settingItems.Count == 0)
{
return null;
}
var stackPanel = new StackPanel
{
Margin = new Thickness(0, 0, 20, 0) // 给右侧滚动条留出位置
};
var stackPanel = new StackPanel();
foreach (var item in settingItems)
{
var controls = item.ToControl(context);
@@ -58,14 +54,7 @@ public class ScriptProject
}
}
var scrollViewer = new ScrollViewer
{
Content = stackPanel,
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
MaxHeight = 350 // 设置最大高度
};
return scrollViewer;
return stackPanel;
}
public IScriptEngine BuildScriptEngine(PathingPartyConfig? partyConfig = null)
@@ -35,11 +35,7 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
public static readonly string ReposTempPath = Path.Combine(ReposPath, "Temp");
// 中央仓库信息地址
public static readonly List<string> CenterRepoInfoUrls =
[
"https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/repo.json",
"https://r2-script.bettergi.com/github_mirror/repo.json",
];
public static readonly string CenterRepoInfoUrl = "https://raw.githubusercontent.com/babalae/bettergi-scripts-list/refs/heads/main/repo.json";
// 中央仓库解压后文件夹名
public static readonly string CenterRepoUnzipName = "bettergi-scripts-list-main";
@@ -92,12 +88,10 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
public async Task<(string, bool)> UpdateCenterRepo()
{
// 测速并获取信息
var (fastUrl, jsonString) = await ProxySpeedTester.GetFastestUrlAsync(CenterRepoInfoUrls);
if (string.IsNullOrEmpty(jsonString))
{
throw new Exception("从互联网下载最新的仓库信息失败");
}
var res = await ProxySpeedTester.GetFastestProxyAsync(CenterRepoInfoUrl);
// 解析信息
var fastProxyUrl = res.Item1;
var jsonString = res.Item2;
var (time, url, file) = ParseJson(jsonString);
var updated = false;
@@ -116,10 +110,9 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
{
needDownload = true;
}
if (needDownload)
{
await DownloadRepoAndUnzip(url);
await DownloadRepoAndUnzip(string.Format(fastProxyUrl, url));
updated = true;
}
@@ -135,7 +128,7 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
// 检查是否需要更新
if (long.Parse(time) > long.Parse(time2))
{
await DownloadRepoAndUnzip(url2);
await DownloadRepoAndUnzip(string.Format(fastProxyUrl, url2));
updated = true;
}
@@ -253,7 +246,6 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
Content = $"检测到{(formClipboard ? "剪切板上存在" : "")}脚本订阅链接,解析后需要导入的脚本为:{pathJson}。\n是否导入并覆盖此文件或者文件夹下的脚本?",
CloseButtonText = "关闭",
PrimaryButtonText = "确认导入",
Owner = Application.Current.MainWindow,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
};
@@ -324,31 +316,7 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
Toast.Information("获取最新仓库信息中...");
// 更新仓库
string repoPath;
try
{
(repoPath, _) = await Task.Run(UpdateCenterRepo);
}
catch (Exception e)
{
Toast.Warning("获取最新仓库信息失败,尝试使用本地已有仓库信息");
try
{
repoPath = FindCenterRepoPath();
}
catch
{
await MessageBox.ErrorAsync("本地无仓库信息,请至少成功更新一次脚本仓库信息!");
return;
}
}
if (string.IsNullOrEmpty(repoPath))
{
await MessageBox.ErrorAsync("本地无仓库信息,请至少成功更新一次脚本仓库信息!");
return;
}
var (repoPath, _) = await Task.Run(UpdateCenterRepo);
// // 收集将被覆盖的文件和文件夹
// var filesToOverwrite = new List<string>();
@@ -425,7 +393,7 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
{
// 目标文件所在文件夹不存在时创建它
Directory.CreateDirectory(Path.GetDirectoryName(destPath)!);
if (File.Exists(destPath))
{
File.Delete(destPath);
@@ -522,4 +490,4 @@ public class ScriptRepoUpdater : Singleton<ScriptRepoUpdater>
}
}
}
}
}
@@ -6,7 +6,6 @@ using System.Security.Policy;
using System.Threading.Tasks;
using BetterGenshinImpact.ViewModel.Message;
using CommunityToolkit.Mvvm.Messaging;
using Wpf.Ui.Violeta.Controls;
namespace BetterGenshinImpact.Core.Script.WebView;
@@ -22,32 +21,39 @@ public class RepoWebBridge
{
try
{
await ScriptRepoUpdater.Instance.UpdateCenterRepo();
}
catch (Exception e)
{
Toast.Warning($"更新仓库信息失败:{e.Message}");
}
// var needUpdate = false;
// string? localRepoJsonPath = null;
// if (Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
// {
// localRepoJsonPath = Directory.GetFiles(ScriptRepoUpdater.CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
// if (localRepoJsonPath is null)
// {
// needUpdate = true;
// }
// }
// else
// {
// needUpdate = true;
// }
//
// if (needUpdate)
// {
// await ScriptRepoUpdater.Instance.UpdateCenterRepo();
// }
try
{
if (!Directory.Exists(ScriptRepoUpdater.CenterRepoPath))
{
throw new Exception("仓库文件夹不存在,请至少成功更新一次仓库!");
}
await ScriptRepoUpdater.Instance.UpdateCenterRepo();
var localRepoJsonPath = Directory.GetFiles(ScriptRepoUpdater.CenterRepoPath, "repo.json", SearchOption.AllDirectories).FirstOrDefault();
if (localRepoJsonPath is null)
{
throw new Exception("repo.json 仓库索引文件不存在,请至少成功更新一次仓库!");
throw new Exception("repo.json 不存在,可能是更新仓库信息失败!");
}
var json = await File.ReadAllTextAsync(localRepoJsonPath);
return json;
}
catch (Exception e)
{
await MessageBox.ShowAsync(e.Message, "获取仓库信息失败");
await MessageBox.ShowAsync(e.Message, "获取仓库信息失败!");
return "";
}
}
@@ -64,4 +70,4 @@ public class RepoWebBridge
await MessageBox.ShowAsync(e.Message, "订阅脚本链接失败!");
}
}
}
}
@@ -71,16 +71,7 @@ public static class InputSimulatorExtension
self.Mouse.XButtonClick(0x0001);
break;
default:
var k = key.ToVK();
// 解决 shift 之类的键位没法正常使用的问题
if (InputBuilder.IsExtendedKey(k))
{
self.Keyboard.KeyPress(false, k);
}
else
{
self.Keyboard.KeyPress(k);
}
self.Keyboard.KeyPress(key.ToVK());
break;
}
}
@@ -108,16 +99,7 @@ public static class InputSimulatorExtension
self.Mouse.XButtonDown(0x0001);
break;
default:
var k = key.ToVK();
// 解决 shift 之类的键位没法正常使用的问题
if (InputBuilder.IsExtendedKey(k))
{
self.Keyboard.KeyDown(false, k);
}
else
{
self.Keyboard.KeyDown(k);
}
self.Keyboard.KeyDown(key.ToVK());
break;
}
}
@@ -145,16 +127,7 @@ public static class InputSimulatorExtension
self.Mouse.XButtonUp(0x0001);
break;
default:
var k = key.ToVK();
// 解决 shift 之类的键位没法正常使用的问题
if (InputBuilder.IsExtendedKey(k))
{
self.Keyboard.KeyUp(false, k);
}
else
{
self.Keyboard.KeyUp(k);
}
self.Keyboard.KeyUp(key.ToVK());
break;
}
}
@@ -30,7 +30,7 @@ public class Simulation
}
}
public static bool IsKeyDown(User32.VK key)
private static bool IsKeyDown(User32.VK key)
{
// 获取按键状态
var state = User32.GetAsyncKeyState((int)key);
@@ -30,7 +30,6 @@ using BetterGenshinImpact.GameTask.AutoTrackPath;
using BetterGenshinImpact.GameTask.Common.BgiVision;
using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.GameTask.Common.Job;
using BetterGenshinImpact.Service.Notification.Model.Enum;
using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl;
using static Vanara.PInvoke.Kernel32;
@@ -44,6 +43,8 @@ public class AutoDomainTask : ISoloTask
private readonly AutoDomainParam _taskParam;
private readonly PostMessageSimulator _simulator;
private readonly YoloV8Predictor _predictor;
private readonly AutoDomainConfig _config;
@@ -54,8 +55,10 @@ public class AutoDomainTask : ISoloTask
public AutoDomainTask(AutoDomainParam taskParam)
{
AutoFightAssets.DestroyInstance();
_taskParam = taskParam;
AutoFightAssets.DestroyInstance();
_simulator = TaskContext.Instance().PostMessageSimulator;
_predictor = YoloV8Builder.CreateDefaultBuilder()
.UseOnnxModel(Global.Absolute(@"Assets\Model\Domain\bgi_tree.onnx"))
.WithSessionOptions(BgiSessionOption.Instance.Options)
@@ -69,9 +72,9 @@ public class AutoDomainTask : ISoloTask
public async Task Start(CancellationToken ct)
{
_ct = ct;
Init();
Notify.Event(NotificationEvent.DomainStart).Success("自动秘境启动");
NotificationHelper.SendTaskNotificationWithScreenshotUsing(b => b.Domain().Started().Build()); // TODO: 通知后续需要删除迁移
// 3次复活重试
for (int i = 0; i < 3; i++)
@@ -88,7 +91,6 @@ public class AutoDomainTask : ISoloTask
{
Logger.LogWarning("自动秘境:{Text}", "复活后重试秘境...");
await Delay(2000, ct);
Notify.Event(NotificationEvent.DomainRetry).Error("存在角色死亡,复活后重试秘境...");
continue;
}
else
@@ -104,7 +106,6 @@ public class AutoDomainTask : ISoloTask
await Delay(2000, ct);
await ArtifactSalvage();
Notify.Event(NotificationEvent.DomainEnd).Success("自动秘境结束");
}
private async Task DoDomain()
@@ -138,7 +139,6 @@ public class AutoDomainTask : ISoloTask
// 2. 执行战斗(战斗线程、视角线程、检测战斗完成线程)
Logger.LogInformation("自动秘境:{Text}", "2. 执行战斗策略");
await StartFight(combatScenes, combatCommands);
combatScenes.AfterTask();
EndFightWait();
// 3. 寻找石化古树 并左右移动直到石化古树位于屏幕中心
@@ -161,10 +161,12 @@ public class AutoDomainTask : ISoloTask
{
Logger.LogInformation("体力已经耗尽,结束自动秘境");
}
NotificationHelper.SendTaskNotificationWithScreenshotUsing(b => b.Domain().Success().Build());
break;
}
Notify.Event(NotificationEvent.DomainReward).Success("自动秘境奖励领取");
NotificationHelper.SendTaskNotificationWithScreenshotUsing(b => b.Domain().Progress().Build());
}
}
@@ -285,7 +287,7 @@ public class AutoDomainTask : ISoloTask
private async Task EnterDomain()
{
var fightAssets = AutoFightAssets.Instance;
var fightAssets = AutoFightContext.Instance.FightAssets;
// 进入秘境
for (int i = 0; i < 3; i++) // 3次重试 有时候会拾取晶蝶
@@ -297,9 +299,9 @@ public class AutoDomainTask : ISoloTask
Logger.LogInformation("自动秘境:{Text}", "进入秘境");
// 秘境开门动画 5s
await Delay(5000, _ct);
}
}
else
{
{
await Delay(800, _ct);
}
}
@@ -330,7 +332,7 @@ public class AutoDomainTask : ISoloTask
while (retryTimes < 120)
{
retryTimes++;
using var cactRectArea = CaptureToRectArea().Find(AutoFightAssets.Instance.ClickAnyCloseTipRa);
using var cactRectArea = CaptureToRectArea().Find(AutoFightContext.Instance.FightAssets.ClickAnyCloseTipRa);
if (!cactRectArea.IsEmpty())
{
await Delay(1000, _ct);
@@ -366,7 +368,7 @@ public class AutoDomainTask : ISoloTask
await Task.Run((Action)(() =>
{
Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyDown);
_simulator.SimulateAction(GIActions.MoveForward, KeyType.KeyDown);
Sleep(30, _ct);
// 组合键好像不能直接用 postmessage
if (!_config.WalkToF)
@@ -393,7 +395,7 @@ public class AutoDomainTask : ISoloTask
}
finally
{
Simulation.SendInput.SimulateAction(GIActions.MoveForward, KeyType.KeyUp);
_simulator.SimulateAction(GIActions.MoveForward, KeyType.KeyUp);
Sleep(50);
if (!_config.WalkToF)
{
@@ -449,7 +451,6 @@ public class AutoDomainTask : ISoloTask
private void EndFightWait()
{
if (_ct.IsCancellationRequested)
{
return;
@@ -493,7 +494,7 @@ public class AutoDomainTask : ISoloTask
{
using var ra = CaptureToRectArea();
var endTipsRect = ra.DeriveCrop(AutoFightAssets.Instance.EndTipsUpperRect);
var endTipsRect = ra.DeriveCrop(AutoFightContext.Instance.FightAssets.EndTipsUpperRect);
var text = OcrFactory.Paddle.Ocr(endTipsRect.SrcGreyMat);
if (text.Contains("挑战") || text.Contains("达成"))
{
@@ -501,7 +502,7 @@ public class AutoDomainTask : ISoloTask
return true;
}
endTipsRect = ra.DeriveCrop(AutoFightAssets.Instance.EndTipsRect);
endTipsRect = ra.DeriveCrop(AutoFightContext.Instance.FightAssets.EndTipsRect);
text = OcrFactory.Paddle.Ocr(endTipsRect.SrcGreyMat);
if (text.Contains("自动") || text.Contains("退出"))
{
@@ -609,13 +610,13 @@ public class AutoDomainTask : ISoloTask
if (rightKeyDown)
{
// 先松开D键
Simulation.SendInput.Keyboard.KeyUp(moveRightKey);
_simulator.KeyUp(moveRightKey);
rightKeyDown = false;
}
if (!leftKeyDown)
{
Simulation.SendInput.Keyboard.KeyDown(moveLeftKey);
_simulator.KeyDown(moveLeftKey);
leftKeyDown = true;
}
}
@@ -627,13 +628,13 @@ public class AutoDomainTask : ISoloTask
if (leftKeyDown)
{
// 先松开A键
Simulation.SendInput.Keyboard.KeyUp(moveLeftKey);
_simulator.KeyUp(moveLeftKey);
leftKeyDown = false;
}
if (!rightKeyDown)
{
Simulation.SendInput.Keyboard.KeyDown(moveRightKey);
_simulator.KeyDown(moveRightKey);
rightKeyDown = true;
}
}
@@ -642,14 +643,14 @@ public class AutoDomainTask : ISoloTask
// 树在中间 松开所有键
if (rightKeyDown)
{
Simulation.SendInput.Keyboard.KeyUp(moveRightKey);
_simulator.KeyUp(moveRightKey);
prevKey = moveRightKey;
rightKeyDown = false;
}
if (leftKeyDown)
{
Simulation.SendInput.Keyboard.KeyUp(moveLeftKey);
_simulator.KeyUp(moveLeftKey);
prevKey = moveLeftKey;
leftKeyDown = false;
}
@@ -662,9 +663,7 @@ public class AutoDomainTask : ISoloTask
backwardsAndForwardsCount++;
}
Simulation.SendInput.Keyboard.KeyDown(moveLeftKey);
Sleep(60);
Simulation.SendInput.Keyboard.KeyUp(moveLeftKey);
_simulator.KeyPress(moveLeftKey, 60);
prevKey = moveLeftKey;
}
else if (treeMiddleX > middleX)
@@ -674,16 +673,12 @@ public class AutoDomainTask : ISoloTask
backwardsAndForwardsCount++;
}
Simulation.SendInput.Keyboard.KeyDown(moveRightKey);
Sleep(60);
Simulation.SendInput.Keyboard.KeyUp(moveRightKey);
_simulator.KeyPress(moveRightKey, 60);
prevKey = moveRightKey;
}
else
{
Simulation.SendInput.Keyboard.KeyDown(moveForwardKey);
Sleep(60);
Simulation.SendInput.Keyboard.KeyUp(moveForwardKey);
_simulator.KeyPress(moveForwardKey, 60);
Sleep(500, _ct);
treeCts.Cancel();
break;
@@ -699,13 +694,13 @@ public class AutoDomainTask : ISoloTask
{
if (leftKeyDown)
{
Simulation.SendInput.Keyboard.KeyUp(moveLeftKey);
_simulator.KeyUp(moveLeftKey);
leftKeyDown = false;
}
if (!rightKeyDown)
{
Simulation.SendInput.Keyboard.KeyDown(moveRightKey);
_simulator.KeyDown(moveRightKey);
rightKeyDown = true;
}
}
@@ -713,13 +708,13 @@ public class AutoDomainTask : ISoloTask
{
if (rightKeyDown)
{
Simulation.SendInput.Keyboard.KeyUp(moveRightKey);
_simulator.KeyUp(moveRightKey);
rightKeyDown = false;
}
if (!leftKeyDown)
{
Simulation.SendInput.Keyboard.KeyDown(moveLeftKey);
_simulator.KeyDown(moveLeftKey);
leftKeyDown = true;
}
}
@@ -728,9 +723,7 @@ public class AutoDomainTask : ISoloTask
if (backwardsAndForwardsCount >= _config.LeftRightMoveTimes)
{
// 左右移动5次说明已经在树中心了
Simulation.SendInput.Keyboard.KeyDown(moveForwardKey);
Sleep(60);
Simulation.SendInput.Keyboard.KeyUp(moveForwardKey);
_simulator.KeyPress(moveForwardKey, 60);
Sleep(500, _ct);
treeCts.Cancel();
break;
@@ -849,7 +842,7 @@ public class AutoDomainTask : ISoloTask
break;
}
var useCondensedResinRa = CaptureToRectArea().Find(AutoFightAssets.Instance.UseCondensedResinRa);
var useCondensedResinRa = CaptureToRectArea().Find(AutoFightContext.Instance.FightAssets.UseCondensedResinRa);
if (!useCondensedResinRa.IsEmpty())
{
useCondensedResinRa.Click();
@@ -889,13 +882,13 @@ public class AutoDomainTask : ISoloTask
// 优先点击继续
using var confirmRectArea = ra.Find(AutoFightAssets.Instance.ConfirmRa);
using var confirmRectArea = ra.Find(AutoFightContext.Instance.FightAssets.ConfirmRa);
if (!confirmRectArea.IsEmpty())
{
if (isLastTurn)
{
// 最后一回合 退出
var exitRectArea = ra.Find(AutoFightAssets.Instance.ExitRa);
var exitRectArea = ra.Find(AutoFightContext.Instance.FightAssets.ExitRa);
if (!exitRectArea.IsEmpty())
{
exitRectArea.Click();
@@ -913,7 +906,7 @@ public class AutoDomainTask : ISoloTask
if (condensedResinCount == 0 && fragileResinCount < 20)
{
// 没有体力了退出
var exitRectArea = ra.Find(AutoFightAssets.Instance.ExitRa);
var exitRectArea = ra.Find(AutoFightContext.Instance.FightAssets.ExitRa);
if (!exitRectArea.IsEmpty())
{
exitRectArea.Click();
@@ -944,7 +937,7 @@ public class AutoDomainTask : ISoloTask
var ra = CaptureToRectArea();
// 浓缩树脂
var condensedResinCountRa = ra.Find(AutoFightAssets.Instance.CondensedResinCountRa);
var condensedResinCountRa = ra.Find(AutoFightContext.Instance.FightAssets.CondensedResinCountRa);
if (!condensedResinCountRa.IsEmpty())
{
// 图像右侧就是浓缩树脂数量
@@ -955,7 +948,7 @@ public class AutoDomainTask : ISoloTask
}
// 脆弱树脂
var fragileResinCountRa = ra.Find(AutoFightAssets.Instance.FragileResinCountRa);
var fragileResinCountRa = ra.Find(AutoFightContext.Instance.FightAssets.FragileResinCountRa);
if (!fragileResinCountRa.IsEmpty())
{
// 图像右侧就是脆弱树脂数量
@@ -12,7 +12,6 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
public List<Rect> AvatarSideIconRectList; // 侧边栏角色头像 非联机状态下
public List<Rect> AvatarIndexRectList; // 侧边栏角色头像对应的白色块 非联机状态下
public Rect ERect;
public Rect ECooldownRect;
public Rect QRect;
public Rect EndTipsUpperRect; // 挑战达成提示
public Rect EndTipsRect;
@@ -48,8 +47,6 @@ public class AutoFightAssets : BaseAssets<AutoFightAssets>
(int)(355 * AssetScale), (int)(465 * AssetScale));
ERect = new Rect(CaptureRect.Width - (int)(267 * AssetScale), CaptureRect.Height - (int)(132 * AssetScale),
(int)(77 * AssetScale), (int)(77 * AssetScale));
ECooldownRect = new Rect(CaptureRect.Width - (int)(241 * AssetScale), CaptureRect.Height - (int)(97 * AssetScale),
(int)(41 * AssetScale), (int)(18 * AssetScale));
QRect = new Rect(CaptureRect.Width - (int)(157 * AssetScale), CaptureRect.Height - (int)(165 * AssetScale),
(int)(110 * AssetScale), (int)(110 * AssetScale));
// 小道具位置 1920-133,800,60,50
@@ -1761,26 +1761,5 @@
"nameEn": "Lanyan",
"skillCD": 16,
"weapon": "10"
},
{
"alias": [
"梦见月瑞希",
"mizuki",
"梦见",
"梦见月",
"瑞希",
"瑞幸",
"木更",
"梗小姐",
"食梦貘",
"心理医生",
"心理诊疗师"
],
"burstCD": 15,
"id": "10000109",
"name": "梦见月瑞希",
"nameEn": "Mizuki",
"skillCD": 15,
"weapon": "10"
}
]
@@ -25,13 +25,6 @@ public partial class AutoFightConfig : ObservableObject
/// </summary>
[ObservableProperty]
private bool _fightFinishDetectEnabled = true;
/// <summary>
/// 根据技能CD优化出招人员
/// 根据填入人或人和cd,来决定当此人元素战技cd未结束时,跳过此人出招,来优化战斗流程,可填入人名或人名数字(用逗号分隔),
/// 多种用分号分隔,例如:白术;钟离,12;,如果人名,则用内置cd检查,如果是人名和数字,则把数字当做出招cd(秒)。
/// </summary>
[ObservableProperty] private string _actionSchedulerByCd = "";
[Serializable]
public partial class FightFinishDetectConfig : ObservableObject
{
@@ -66,12 +59,6 @@ public partial class AutoFightConfig : ObservableObject
[ObservableProperty]
private string _checkEndDelay = "";
/// <summary>
/// 按下切换队伍后去检查屏幕色块的延迟,默认为0.45秒。若频繁误判可以适当提高这个值。确保这个延迟不会真的把队伍配置界面切出来。
/// </summary>
[ObservableProperty]
private string _beforeDetectDelay = "";
}
/// <summary>
/// 战斗结束相关配置
@@ -1,27 +1,27 @@
// using BetterGenshinImpact.Core.Simulator;
// using BetterGenshinImpact.GameTask.AutoFight.Assets;
// using BetterGenshinImpact.Model;
//
// namespace BetterGenshinImpact.GameTask.AutoFight;
using BetterGenshinImpact.Core.Simulator;
using BetterGenshinImpact.GameTask.AutoFight.Assets;
using BetterGenshinImpact.Model;
// /// <summary>
// /// 自动战斗上下文
// /// 请在启动BetterGI以后再初始化
// /// </summary>
// public class AutoFightContext : Singleton<AutoFightContext>
// {
// private AutoFightContext()
// {
// Simulator = TaskContext.Instance().PostMessageSimulator;
// }
//
// /// <summary>
// /// find资源
// /// </summary>
// public AutoFightAssets FightAssets => AutoFightAssets.Instance;
//
// /// <summary>
// /// 战斗专用的PostMessage模拟键鼠操作
// /// </summary>
// public readonly PostMessageSimulator Simulator;
// }
namespace BetterGenshinImpact.GameTask.AutoFight;
/// <summary>
/// 自动战斗上下文
/// 请在启动BetterGI以后再初始化
/// </summary>
public class AutoFightContext : Singleton<AutoFightContext>
{
private AutoFightContext()
{
Simulator = TaskContext.Instance().PostMessageSimulator;
}
/// <summary>
/// find资源
/// </summary>
public AutoFightAssets FightAssets => AutoFightAssets.Instance;
/// <summary>
/// 战斗专用的PostMessage模拟键鼠操作
/// </summary>
public readonly PostMessageSimulator Simulator;
}
@@ -17,7 +17,6 @@ public class AutoFightParam : BaseTaskParam
public bool FastCheckEnabled = false;
public string FastCheckParams = "";
public string CheckEndDelay = "";
public string BeforeDetectDelay = "";
}
public AutoFightParam(string path, AutoFightConfig autoFightConfig)
@@ -27,12 +26,10 @@ public class AutoFightParam : BaseTaskParam
FightFinishDetectEnabled = autoFightConfig.FightFinishDetectEnabled;
PickDropsAfterFightEnabled = autoFightConfig.PickDropsAfterFightEnabled;
KazuhaPickupEnabled = autoFightConfig.KazuhaPickupEnabled;
ActionSchedulerByCd = autoFightConfig.ActionSchedulerByCd;
FinishDetectConfig.FastCheckEnabled = autoFightConfig.FinishDetectConfig.FastCheckEnabled;
FinishDetectConfig.FastCheckParams = autoFightConfig.FinishDetectConfig.FastCheckParams;
FinishDetectConfig.CheckEndDelay = autoFightConfig.FinishDetectConfig.CheckEndDelay;
FinishDetectConfig.BeforeDetectDelay = autoFightConfig.FinishDetectConfig.BeforeDetectDelay;
//下面参数固定,只取自动战斗里面的
FinishDetectConfig.BattleEndProgressBarColor = TaskContext.Instance().Config.AutoFightConfig.FinishDetectConfig.BattleEndProgressBarColor;
@@ -50,7 +47,6 @@ public class AutoFightParam : BaseTaskParam
public int Timeout { get; set; } = 120;
public bool KazuhaPickupEnabled = true;
public string ActionSchedulerByCd = "";
}
@@ -45,7 +45,6 @@ public class AutoFightTask : ISoloTask
private class TaskFightFinishDetectConfig
{
public int DelayTime = 1500;
public int DetectDelayTime = 450;
public Dictionary<string, int> DelayTimes = new();
public double CheckTime = 5;
public List<string> CheckNames = new();
@@ -58,7 +57,6 @@ public class AutoFightTask : ISoloTask
ParseFastCheckEndDelayString(finishDetectConfig.CheckEndDelay, out DelayTime, DelayTimes);
BattleEndProgressBarColor = ParseStringToTuple(finishDetectConfig.BattleEndProgressBarColor, (95, 235, 255));
BattleEndProgressBarColorTolerance = ParseSingleOrCommaSeparated(finishDetectConfig.BattleEndProgressBarColorTolerance, (6, 6, 6));
DetectDelayTime = (int)((double.TryParse(finishDetectConfig.BeforeDetectDelay, out var result) ? result : 0.45) * 1000);
}
public (int, int, int) BattleEndProgressBarColor { get; }
@@ -204,7 +202,6 @@ public class AutoFightTask : ISoloTask
throw new Exception("识别队伍角色失败");
}
var actionSchedulerByCd = ParseStringToDictionary(_taskParam.ActionSchedulerByCd);
var combatCommands = _combatScriptBag.FindCombatScript(combatScenes.Avatars);
// 新的取消token
@@ -220,12 +217,11 @@ public class AutoFightTask : ISoloTask
//战斗前检查,可做成配置
// if (await CheckFightFinish()) {
// return;
// }
/* if (await CheckFightFinish()) {
return;
}*/
var fightEndFlag = false;
string lastFightName = "";
string skipFightName = "";
string lastFighttName = "";
//统计切换人打架次数
var countFight = 0;
// 战斗操作
@@ -246,34 +242,6 @@ public class AutoFightTask : ISoloTask
break;
}
//根据元素技能冷却事件优化出招流程,只有当人物切换后才会触发检查
double skillCd;
if (lastFightName != command.Name && actionSchedulerByCd.TryGetValue(command.Name, out skillCd))
{
var avatar = combatScenes.SelectAvatar(command.Name);
if (avatar == null)
{
continue;
}
if (skillCd < 0)
{
skillCd = FindMax([avatar.SkillCd, avatar.SkillHoldCd]);
}
var dif = (DateTime.UtcNow - avatar.LastSkillTime);
//当技能未冷却时,跳过此次出招
if ((DateTime.UtcNow - avatar.LastSkillTime).TotalSeconds < skillCd)
{
if (skipFightName != command.Name)
{
Logger.LogInformation($"{command.Name}cd冷却为{skillCd}秒,剩余{skillCd - dif.TotalSeconds}秒,跳过此次行动");
}
skipFightName = command.Name;
continue;
}
}
command.Execute(combatScenes);
//统计战斗人次
if (i == combatCommands.Count - 1 || command.Name != combatCommands[i + 1].Name)
@@ -281,7 +249,7 @@ public class AutoFightTask : ISoloTask
countFight++;
}
lastFightName = command.Name;
lastFighttName = command.Name;
if (!fightEndFlag && _taskParam is { FightFinishDetectEnabled: true })
{
//处于最后一个位置,或者当前执行人和下一个人名字不一样的情况,满足一定条件(开启快速检查,并且检查时间大于0或人名存在配置)检查战斗
@@ -294,7 +262,6 @@ public class AutoFightTask : ISoloTask
{
checkFightFinishStopwatch.Restart();
var delayTime = _finishDetectConfig.DelayTime;
var detectDelayTime = _finishDetectConfig.DetectDelayTime;
if (_finishDetectConfig.DelayTimes.TryGetValue(command.Name, out var time))
{
delayTime = time;
@@ -309,7 +276,7 @@ public class AutoFightTask : ISoloTask
{
Logger.LogInformation($"{command.Name}下一个人为{combatCommands[i+1].Name}毫秒");
}*/
fightEndFlag = await CheckFightFinish(delayTime, detectDelayTime);
fightEndFlag = await CheckFightFinish(delayTime);
}
}
@@ -332,10 +299,6 @@ public class AutoFightTask : ISoloTask
Debug.WriteLine(e.StackTrace);
throw;
}
finally
{
Simulation.ReleaseAllKey();
}
}, cts2.Token);
await fightTask;
@@ -378,13 +341,12 @@ public class AutoFightTask : ISoloTask
{
var time = DateTime.UtcNow - kazuha.LastSkillTime;
//当万叶cd大于3时或战斗人次少于2时(通常无怪物情况下),此时不再触发万叶拾取,
if (!(countFight < 2 || lastFightName == "枫原万叶" && time.TotalSeconds > 3))
if (!(countFight < 2 || lastFighttName == "枫原万叶" && time.TotalSeconds > 3))
{
Logger.LogInformation("使用枫原万叶长E拾取掉落物");
await Delay(300, ct);
if (kazuha.TrySwitch())
{
time = DateTime.UtcNow - kazuha.LastSkillTime;
if (time.TotalMilliseconds > 0 && time.TotalSeconds <= kazuha.SkillHoldCd)
{
Logger.LogInformation("枫原万叶长E技能可能处于冷却中,等待 {Time} s", time.TotalSeconds);
@@ -424,7 +386,7 @@ public class AutoFightTask : ISoloTask
Math.Abs(a.Item3 - b.Item3) < c.Item3;
}
private async Task<bool> CheckFightFinish(int delayTime = 1500, int detectDelayTime = 450)
private async Task<bool> CheckFightFinish(int delayTime = 1500)
{
// YOLO 判断血条和怪物位置
// if (HasFightFlagByYolo(CaptureToRectArea()))
@@ -457,34 +419,38 @@ public class AutoFightTask : ISoloTask
}
}
**/
//Simulation.SendInput.SimulateAction(GIActions.Drop);//在换队前取消爬墙状态
await Delay(delayTime, _ct);
Logger.LogInformation("打开编队界面检查战斗是否结束,延时{detectDelayTime}毫秒检查", detectDelayTime);
Logger.LogInformation("打开编队界面检查战斗是否结束");
// 最终方案确认战斗结束
Simulation.SendInput.SimulateAction(GIActions.OpenPartySetupScreen);
await Delay(detectDelayTime, _ct);
await Delay(450, _ct);
var ra = CaptureToRectArea();
var b3 = ra.SrcMat.At<Vec3b>(50, 790); //进度条颜色
var whiteTile = ra.SrcMat.At<Vec3b>(50, 768); //白块
Simulation.SendInput.SimulateAction(GIActions.Drop);
var whiteTile = ra.SrcMat.At<Vec3b>(50, 772); //白块
if (IsWhite(whiteTile.Item2, whiteTile.Item1, whiteTile.Item0) && IsYellow(b3.Item2, b3.Item1, b3.Item0) /* AreDifferencesWithinBounds(_finishDetectConfig.BattleEndProgressBarColor, (b3.Item0, b3.Item1, b3.Item2), _finishDetectConfig.BattleEndProgressBarColorTolerance)*/)
{
Logger.LogInformation("识别到战斗结束");
Simulation.SendInput.SimulateAction(GIActions.Drop);
return true;
}
Logger.LogInformation($"未识别到战斗结束yellow{b3.Item0},{b3.Item1},{b3.Item2}");
Logger.LogInformation($"未识别到战斗结束white{whiteTile.Item0},{whiteTile.Item1},{whiteTile.Item2}");
Simulation.SendInput.SimulateAction(GIActions.Drop);
Logger.LogInformation($"未识别到战斗结束{b3.Item0},{b3.Item1},{b3.Item2}");
/**
if (!Bv.IsInMainUi(ra))
{
// 如果不在主界面,说明异常,直接结束战斗继续下一步(地图追踪下一步会进入异常处理)
// 如果不在主界面,说明异常,直接结束战斗继续下一步(路径追踪下一步会进入异常处理)
Logger.LogInformation("当前不在主界面,直接结束战斗!");
return true;
}**/
_lastFightFlagTime = DateTime.Now;
return false;
// }
return false;
}
bool IsYellow(int r, int g, int b)
@@ -504,53 +470,6 @@ public class AutoFightTask : ISoloTask
(g >= 240 && g <= 255) &&
(b >= 240 && b <= 255);
}
static double FindMax(double[] numbers)
{
if (numbers == null || numbers.Length == 0)
{
throw new ArgumentException("The array is empty or null.");
}
double max = numbers[0] > 10000 ? 0 : numbers[0];
foreach (var num in numbers)
{
var cpnum = numbers[0] > 10000 ? 0 : num;
max = Math.Max(max, num);
}
return max;
}
private static Dictionary<string, double> ParseStringToDictionary(string input, double defaultValue = -1)
{
var dictionary = new Dictionary<string, double>();
if (string.IsNullOrEmpty(input))
{
return dictionary; // 返回空字典
}
string[] pairs = input.Split(';', StringSplitOptions.RemoveEmptyEntries);
foreach (var pair in pairs)
{
var parts = pair.Split(',', StringSplitOptions.TrimEntries);
if (parts.Length > 0)
{
string name = parts[0];
double value = defaultValue;
if (parts.Length > 1 && double.TryParse(parts[1], out var parsedValue))
{
value = parsedValue;
}
dictionary[name] = value;
}
}
return dictionary;
}
private bool HasFightFlagByYolo(ImageRegion imageRegion)
{
@@ -18,8 +18,6 @@ using BetterGenshinImpact.GameTask.Common.BgiVision;
using Vanara.PInvoke;
using static BetterGenshinImpact.GameTask.Common.TaskControl;
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.GameTask.AutoFight.Assets;
using BetterGenshinImpact.ViewModel.Pages;
namespace BetterGenshinImpact.GameTask.AutoFight.Model;
@@ -57,7 +55,7 @@ public class Avatar
/// 长按元素战技CD
/// </summary>
public double SkillHoldCd { get; set; }
/// <summary>
/// 最近一次使用元素战技的时间
/// </summary>
@@ -121,13 +119,13 @@ public class Avatar
{
Logger.LogWarning("检测到复苏界面,存在角色被击败,前往七天神像复活");
// 先打开地图
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE); // NOTE: 此处按下Esc是为了关闭复苏界面,无需改键
Simulation.SendInput.Keyboard.KeyPress(User32.VK.VK_ESCAPE); // NOTE: 此处按下Esc是为了关闭复苏界面,无需改键
Sleep(600, Ct);
Simulation.SendInput.SimulateAction(GIActions.OpenMap);
// tp 到七天神像复活
var tpTask = new TpTask(Ct);
tpTask.TpToStatueOfTheSeven().Wait(Ct);
Logger.LogInformation("血量恢复完成。【设置】-【七天神像设置】可以修改回血相关配置。");
throw new RetryException("检测到复苏界面,存在角色被击败,前往七天神像复活");
}
}
@@ -154,28 +152,26 @@ public class Avatar
return;
}
Simulation.SendInput.SimulateAction(GIActions.Drop);
switch (Index)
{
case 1:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember1);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember1);
break;
case 2:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember2);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember2);
break;
case 3:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember3);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember3);
break;
case 4:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember4);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember4);
break;
case 5:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember5);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember5);
break;
default:
break;
}
// Debug.WriteLine($"切换到{Index}号位");
// Cv2.ImWrite($"log/切换.png", region.SrcMat);
Sleep(250, Ct);
@@ -190,7 +186,7 @@ public class Avatar
/// <returns></returns>
public bool TrySwitch(int tryTimes = 4, bool needLog = true)
{
for (var i = 0; i < tryTimes; i++)
for (var i = 0; i < 3; i++)
{
if (Ct is { IsCancellationRequested: true })
{
@@ -211,23 +207,22 @@ public class Avatar
return true;
}
Simulation.SendInput.SimulateAction(GIActions.Drop); //反正会重试就不等落地了
switch (Index)
{
case 1:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember1);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember1);
break;
case 2:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember2);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember2);
break;
case 3:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember3);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember3);
break;
case 4:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember4);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember4);
break;
case 5:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember5);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember5);
break;
default:
break;
@@ -256,28 +251,26 @@ public class Avatar
return;
}
Simulation.SendInput.SimulateAction(GIActions.Drop);
switch (Index)
{
case 1:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember1);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember1);
break;
case 2:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember2);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember2);
break;
case 3:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember3);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember3);
break;
case 4:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember4);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember4);
break;
case 5:
Simulation.SendInput.SimulateAction(GIActions.SwitchMember5);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SwitchMember5);
break;
default:
break;
}
Sleep(250);
}
}
@@ -321,7 +314,7 @@ public class Avatar
{
var assetScale = TaskContext.Instance().SystemInfo.AssetScale;
// 剪裁出队伍区域
var teamRa = region.DeriveCrop(AutoFightAssets.Instance.TeamRect);
var teamRa = region.DeriveCrop(AutoFightContext.Instance.FightAssets.TeamRect);
var blockX = NameRect.X + NameRect.Width * 2 - 10;
var block = teamRa.DeriveCrop(new Rect(blockX, NameRect.Y, teamRa.Width - blockX, NameRect.Height * 2));
// Cv2.ImWrite($"block_{Name}.png", block.SrcMat);
@@ -344,7 +337,7 @@ public class Avatar
else
{
// 剪裁出IndexRect区域
var teamRa = region.DeriveCrop(AutoFightAssets.Instance.TeamRect);
var teamRa = region.DeriveCrop(AutoFightContext.Instance.FightAssets.TeamRect);
var blockX = NameRect.X + NameRect.Width * 2 - 10;
var indexBlock = teamRa.DeriveCrop(new Rect(blockX + IndexRect.X, NameRect.Y + IndexRect.Y, IndexRect.Width, IndexRect.Height));
// Cv2.ImWrite($"indexBlock_{Name}.png", indexBlock.SrcMat);
@@ -372,7 +365,7 @@ public class Avatar
return;
}
Simulation.SendInput.SimulateAction(GIActions.NormalAttack);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.NormalAttack);
ms -= 200;
Sleep(200, Ct);
}
@@ -394,7 +387,7 @@ public class Avatar
{
if (Name == "纳西妲")
{
Simulation.SendInput.SimulateAction(GIActions.ElementalSkill, KeyType.KeyDown);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.ElementalSkill, KeyType.KeyDown);
Sleep(300, Ct);
for (int j = 0; j < 10; j++)
{
@@ -403,22 +396,22 @@ public class Avatar
}
Sleep(300); // 持续操作不应该被cts取消
Simulation.SendInput.SimulateAction(GIActions.ElementalSkill, KeyType.KeyUp);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.ElementalSkill, KeyType.KeyUp);
}
else if (Name == "坎蒂丝")
{
Simulation.SendInput.SimulateAction(GIActions.ElementalSkill, KeyType.KeyDown);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.ElementalSkill, KeyType.KeyDown);
Thread.Sleep(3000);
Simulation.SendInput.SimulateAction(GIActions.ElementalSkill, KeyType.KeyUp);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.ElementalSkill, KeyType.KeyUp);
}
else
{
Simulation.SendInput.SimulateAction(GIActions.ElementalSkill, KeyType.Hold);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.ElementalSkill, KeyType.Hold);
}
}
else
{
Simulation.SendInput.SimulateAction(GIActions.ElementalSkill, KeyType.KeyPress);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.ElementalSkill, KeyType.KeyPress);
}
Sleep(200, Ct);
@@ -443,9 +436,8 @@ public class Avatar
/// </summary>
public double GetSkillCurrentCd(ImageRegion imageRegion)
{
var eRa = imageRegion.DeriveCrop(AutoFightAssets.Instance.ECooldownRect);
var eRaWhite = OpenCvCommonHelper.InRangeHsv(eRa.SrcMat, new Scalar(0, 0, 235), new Scalar(0, 25, 255));
var text = OcrFactory.Paddle.OcrWithoutDetector(eRaWhite);
var eRa = imageRegion.DeriveCrop(AutoFightContext.Instance.FightAssets.ERect);
var text = OcrFactory.Paddle.Ocr(eRa.SrcGreyMat);
return StringUtils.TryParseDouble(text);
}
@@ -463,7 +455,7 @@ public class Avatar
return;
}
Simulation.SendInput.SimulateAction(GIActions.ElementalBurst);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.ElementalBurst);
Sleep(200, Ct);
var region = CaptureToRectArea();
@@ -498,7 +490,7 @@ public class Avatar
// /// </summary>
// public double GetBurstCurrentCd(CaptureContent content)
// {
// var qRa = content.CaptureRectArea.Crop(AutoFightAssets.Instance.QRect);
// var qRa = content.CaptureRectArea.Crop(AutoFightContext.Instance.FightAssets.QRect);
// var text = OcrFactory.Paddle.Ocr(qRa.SrcGreyMat);
// return StringUtils.TryParseDouble(text);
// }
@@ -518,9 +510,9 @@ public class Avatar
ms = 200;
}
Simulation.SendInput.SimulateAction(GIActions.SprintMouse, KeyType.KeyDown);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SprintMouse, KeyType.KeyDown);
Sleep(ms); // 冲刺不能被cts取消
Simulation.SendInput.SimulateAction(GIActions.SprintMouse, KeyType.KeyUp);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.SprintMouse, KeyType.KeyUp);
}
public void Walk(string key, int ms)
@@ -553,9 +545,9 @@ public class Avatar
return;
}
Simulation.SendInput.Keyboard.KeyDown(vk);
AutoFightContext.Instance.Simulator.KeyDown(vk);
Sleep(ms); // 行走不能被cts取消
Simulation.SendInput.Keyboard.KeyUp(vk);
AutoFightContext.Instance.Simulator.KeyUp(vk);
}
/// <summary>
@@ -582,7 +574,7 @@ public class Avatar
/// </summary>
public void Jump()
{
Simulation.SendInput.SimulateAction(GIActions.Jump);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.Jump);
}
/// <summary>
@@ -598,7 +590,7 @@ public class Avatar
if (Name == "那维莱特")
{
var dpi = TaskContext.Instance().DpiScale;
Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyDown);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.NormalAttack, KeyType.KeyDown);
while (ms >= 0)
{
if (Ct is { IsCancellationRequested: true })
@@ -611,35 +603,13 @@ public class Avatar
Sleep(50); // 持续操作不应该被cts取消
}
Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyUp);
}
else if (Name == "恰斯卡")
{
var dpi = TaskContext.Instance().DpiScale;
Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyDown);
int cnt = 0;
while (ms >= 0)
{
if (Ct is { IsCancellationRequested: true })
{
return;
}
// 恰在蓄力时快速转动会把视角趋向于水平,所以在回正的时候不做额外Y轴移动
double rate = cnt % 10 < 5 ? 0 : 4.5;//每500ms做一轮上下移动。
cnt++;
Simulation.SendInput.Mouse.MoveMouseBy((int)(500 * dpi), (int)(rate * 100 * dpi));
ms -= 50;
Sleep(50);
}
Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyUp);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.NormalAttack, KeyType.KeyUp);
}
else
{
Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyDown);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.NormalAttack, KeyType.KeyDown);
Sleep(ms); // 持续操作不应该被cts取消
Simulation.SendInput.SimulateAction(GIActions.NormalAttack, KeyType.KeyUp);
AutoFightContext.Instance.Simulator.SimulateAction(GIActions.NormalAttack, KeyType.KeyUp);
}
}
@@ -648,11 +618,11 @@ public class Avatar
key = key.ToLower();
if (key == "left")
{
Simulation.SendInput.Mouse.LeftButtonDown();
AutoFightContext.Instance.Simulator.LeftButtonDown();
}
else if (key == "right")
{
Simulation.SendInput.Mouse.RightButtonDown();
AutoFightContext.Instance.Simulator.RightButtonDown();
}
else if (key == "middle")
{
@@ -665,11 +635,11 @@ public class Avatar
key = key.ToLower();
if (key == "left")
{
Simulation.SendInput.Mouse.LeftButtonUp();
AutoFightContext.Instance.Simulator.LeftButtonUp();
}
else if (key == "right")
{
Simulation.SendInput.Mouse.RightButtonUp();
AutoFightContext.Instance.Simulator.RightButtonUp();
}
else if (key == "middle")
{
@@ -682,11 +652,11 @@ public class Avatar
key = key.ToLower();
if (key == "left")
{
Simulation.SendInput.Mouse.LeftButtonClick();
AutoFightContext.Instance.Simulator.LeftButtonClick();
}
else if (key == "right")
{
Simulation.SendInput.Mouse.RightButtonClick();
AutoFightContext.Instance.Simulator.RightButtonClick();
}
else if (key == "middle")
{
@@ -701,79 +671,19 @@ public class Avatar
public void KeyDown(string key)
{
var vk = KeyBindingsSettingsPageViewModel.MappingKey(User32Helper.ToVk(key));
switch (key)
{
case "VK_LBUTTON":
Simulation.SendInput.Mouse.LeftButtonDown();
break;
case "VK_RBUTTON":
Simulation.SendInput.Mouse.RightButtonDown();
break;
case "VK_MBUTTON":
Simulation.SendInput.Mouse.MiddleButtonDown();
break;
case "VK_XBUTTON1":
Simulation.SendInput.Mouse.XButtonDown(0x0001);
break;
case "VK_XBUTTON2":
Simulation.SendInput.Mouse.XButtonDown(0x0001);
break;
default:
Simulation.SendInput.Keyboard.KeyDown(vk);
break;
}
var vk = User32Helper.ToVk(key);
AutoFightContext.Instance.Simulator.KeyDown(vk);
}
public void KeyUp(string key)
{
var vk = KeyBindingsSettingsPageViewModel.MappingKey(User32Helper.ToVk(key));
switch (key)
{
case "VK_LBUTTON":
Simulation.SendInput.Mouse.LeftButtonUp();
break;
case "VK_RBUTTON":
Simulation.SendInput.Mouse.RightButtonUp();
break;
case "VK_MBUTTON":
Simulation.SendInput.Mouse.MiddleButtonUp();
break;
case "VK_XBUTTON1":
Simulation.SendInput.Mouse.XButtonUp(0x0001);
break;
case "VK_XBUTTON2":
Simulation.SendInput.Mouse.XButtonUp(0x0001);
break;
default:
Simulation.SendInput.Keyboard.KeyUp(vk);
break;
}
var vk = User32Helper.ToVk(key);
AutoFightContext.Instance.Simulator.KeyUp(vk);
}
public void KeyPress(string key)
{
var vk = KeyBindingsSettingsPageViewModel.MappingKey(User32Helper.ToVk(key));
switch (key)
{
case "VK_LBUTTON":
Simulation.SendInput.Mouse.LeftButtonClick();
break;
case "VK_RBUTTON":
Simulation.SendInput.Mouse.RightButtonClick();
break;
case "VK_MBUTTON":
Simulation.SendInput.Mouse.MiddleButtonClick();
break;
case "VK_XBUTTON1":
Simulation.SendInput.Mouse.XButtonClick(0x0001);
break;
case "VK_XBUTTON2":
Simulation.SendInput.Mouse.XButtonClick(0x0001);
break;
default:
Simulation.SendInput.Keyboard.KeyPress(vk);
break;
}
var vk = User32Helper.ToVk(key);
AutoFightContext.Instance.Simulator.KeyPress(vk);
}
}
}
Loaded 100 of 292 files, more files were not shown because too many files have changed in this diff. Show more