From f5395a623bc4c020c4f83f06cadfe2a131106657 Mon Sep 17 00:00:00 2001
From: Xian55 <367101+Xian55@users.noreply.github.com>
Date: Sun, 8 Sep 2024 14:28:21 +0200
Subject: [PATCH] Benchmark: Added a way to mass load all available profiles --
currently not working.
HeadlessServer: Added --loadonly flag to only attempt to load the class profile then exit.
Core: FrameConfig: Added a way to just Load the config.
Core: DependencyInjection: When loading the FrameConfig be more verbose about the error messages.
---
.bat/json_find_most_requirement_count.ps1 | 32 +++++++
.bat/link_json_to_benchmark_release.bat | 2 +
Benchmarks/Benchmarks.csproj | 1 +
Benchmarks/ClassProfile/LoadAllProfiles.cs | 43 +++++++++
Core/DataFrame/FrameConfig.cs | 11 ++-
Core/DependencyInjection.cs | 16 +++-
HeadlessServer/HeadlessServer.cs | 10 +-
HeadlessServer/HeadlessServer.csproj | 105 +++++++++++----------
HeadlessServer/Program.cs | 18 +++-
HeadlessServer/RunOptions.cs | 6 ++
README.md | 1 +
11 files changed, 183 insertions(+), 62 deletions(-)
create mode 100644 .bat/json_find_most_requirement_count.ps1
create mode 100644 .bat/link_json_to_benchmark_release.bat
create mode 100644 Benchmarks/ClassProfile/LoadAllProfiles.cs
diff --git a/.bat/json_find_most_requirement_count.ps1 b/.bat/json_find_most_requirement_count.ps1
new file mode 100644
index 00000000..9849f6cb
--- /dev/null
+++ b/.bat/json_find_most_requirement_count.ps1
@@ -0,0 +1,32 @@
+# Define the folder path
+$folderPath = "..\JSON\class"
+
+# Initialize a variable to store the result
+$maxCount = 0
+$maxFile = ""
+
+# Get all files in the folder
+$files = Get-ChildItem -Path $folderPath -File
+
+# Iterate through each file
+foreach ($file in $files) {
+ # Read the file content
+ $content = Get-Content -Path $file.FullName
+
+ # Count occurrences of the word "Requirement"
+ $count = [regex]::Matches($content, "Requirement", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase).Count
+
+ # Check if this file has more occurrences than the current maximum
+ if ($count -gt $maxCount) {
+ $maxCount = $count
+ $maxFile = $file.FullName
+ }
+}
+
+# Output the result
+if ($maxFile -ne "") {
+ Write-Output "File with the most occurrences of 'Requirement': $maxFile"
+ Write-Output "Occurrences count: $maxCount"
+} else {
+ Write-Output "No files found in the specified folder."
+}
\ No newline at end of file
diff --git a/.bat/link_json_to_benchmark_release.bat b/.bat/link_json_to_benchmark_release.bat
new file mode 100644
index 00000000..e2388008
--- /dev/null
+++ b/.bat/link_json_to_benchmark_release.bat
@@ -0,0 +1,2 @@
+mklink /J "..\Benchmarks\bin\Release\Json" "..\Json"
+PAUSE
\ No newline at end of file
diff --git a/Benchmarks/Benchmarks.csproj b/Benchmarks/Benchmarks.csproj
index b36f521a..1b7b7028 100644
--- a/Benchmarks/Benchmarks.csproj
+++ b/Benchmarks/Benchmarks.csproj
@@ -13,6 +13,7 @@
+
diff --git a/Benchmarks/ClassProfile/LoadAllProfiles.cs b/Benchmarks/ClassProfile/LoadAllProfiles.cs
new file mode 100644
index 00000000..9bd6f825
--- /dev/null
+++ b/Benchmarks/ClassProfile/LoadAllProfiles.cs
@@ -0,0 +1,43 @@
+using BenchmarkDotNet.Attributes;
+
+using HeadlessServer;
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using WinAPI;
+
+namespace Benchmarks.ClassProfile;
+
+public class LoadAllProfiles
+{
+ [Benchmark]
+ [ArgumentsSource(nameof(GetProfileNames))]
+ public void LoadProfile(string profileName)
+ {
+ // TODO: fix loading error frame_config.json not exists
+ HeadlessServer.Program.Main([$"{profileName}", "-m Local", "--loadonly"]);
+ }
+
+ public static IEnumerable GetProfileNames()
+ {
+ var dataConfig = DataConfig.Load();
+
+ Directory.SetCurrentDirectory("..\\..\\..\\..\\HeadlessServer");
+
+ var root = Path.Join(dataConfig.Class, Path.DirectorySeparatorChar.ToString());
+ var files = Directory.EnumerateFiles(root, "*.json*", SearchOption.AllDirectories)
+ .Select(path => path.Replace(root, string.Empty))
+ .OrderBy(x => x, new NaturalStringComparer());
+
+ yield return files.First();
+
+ //foreach (var fileName in files)
+ //{
+ // yield return fileName;
+ //}
+ }
+}
diff --git a/Core/DataFrame/FrameConfig.cs b/Core/DataFrame/FrameConfig.cs
index 735954c7..7ab3e002 100644
--- a/Core/DataFrame/FrameConfig.cs
+++ b/Core/DataFrame/FrameConfig.cs
@@ -25,7 +25,7 @@ public static bool IsValid(Rectangle rect, Version addonVersion)
{
try
{
- var config = JsonConvert.DeserializeObject(File.ReadAllText(FrameConfigMeta.DefaultFilename));
+ var config = Load();
bool sameVersion = config.Version == FrameConfigMeta.Version;
bool sameAddonVersion = config.AddonVersion == addonVersion;
@@ -38,11 +38,16 @@ public static bool IsValid(Rectangle rect, Version addonVersion)
}
}
+ public static DataFrameConfig Load()
+ {
+ return JsonConvert.DeserializeObject(File.ReadAllText(FrameConfigMeta.DefaultFilename));
+ }
+
public static DataFrame[] LoadFrames()
{
if (Exists())
{
- var config = JsonConvert.DeserializeObject(File.ReadAllText(FrameConfigMeta.DefaultFilename));
+ var config = Load();
if (config.Version == FrameConfigMeta.Version)
return config.Frames;
}
@@ -52,7 +57,7 @@ public static DataFrame[] LoadFrames()
public static DataFrameMeta LoadMeta()
{
- var config = JsonConvert.DeserializeObject(File.ReadAllText(FrameConfigMeta.DefaultFilename));
+ var config = Load();
if (config.Version == FrameConfigMeta.Version)
return config.Meta;
diff --git a/Core/DependencyInjection.cs b/Core/DependencyInjection.cs
index 0c69ef95..f1017ecb 100644
--- a/Core/DependencyInjection.cs
+++ b/Core/DependencyInjection.cs
@@ -254,15 +254,27 @@ public static bool AddWoWProcess(
}
NativeMethods.GetWindowRect(process.MainWindowHandle, out Rectangle rect);
- if (FrameConfig.Exists() && !FrameConfig.IsValid(rect, installVersion))
+ if (!FrameConfig.Exists())
+ {
+ log.LogError($"{nameof(FrameConfig)} doesn't exists!");
+
+ return false;
+ }
+
+ if (!FrameConfig.IsValid(rect, installVersion))
{
// At this point the webpage never loads so fallback to configuration page
FrameConfig.Delete();
- log.LogError($"{nameof(FrameConfig)} doesn't exists or window rect is different then config!");
+
+ log.LogError($"{nameof(FrameConfig)} window rect is different then config!");
+ log.LogError($"{nameof(FrameConfig)} {rect}");
+ log.LogError($"{nameof(FrameConfig)} {installVersion}");
+ log.LogError($"{nameof(FrameConfig)} {FrameConfig.Load()}");
return false;
}
+
return true;
}
diff --git a/HeadlessServer/HeadlessServer.cs b/HeadlessServer/HeadlessServer.cs
index c7f22696..cbd2d8d6 100644
--- a/HeadlessServer/HeadlessServer.cs
+++ b/HeadlessServer/HeadlessServer.cs
@@ -1,5 +1,7 @@
using CommandLine;
+
using Core;
+
using Microsoft.Extensions.Logging;
namespace HeadlessServer;
@@ -23,7 +25,8 @@ public HeadlessServer(ILogger logger,
SpellBookReader spellBookReader,
BagReader bagReader,
ExecGameCommand exec,
- AddonConfigurator addonConfigurator, Wait wait)
+ AddonConfigurator addonConfigurator,
+ Wait wait)
{
this.logger = logger;
this.botController = botController;
@@ -45,6 +48,11 @@ public void Run(ParserResult options)
botController.ToggleBotStatus();
}
+ public void RunLoadOnly(ParserResult options)
+ {
+ botController.LoadClassProfile(options.Value.ClassConfig!);
+ }
+
private void InitState()
{
addonReader.FullReset();
diff --git a/HeadlessServer/HeadlessServer.csproj b/HeadlessServer/HeadlessServer.csproj
index 7d535c32..83e76d4c 100644
--- a/HeadlessServer/HeadlessServer.csproj
+++ b/HeadlessServer/HeadlessServer.csproj
@@ -1,59 +1,62 @@
-
- Exe
- enable
- enable
- app.manifest
- AnyCPU;x64;x86
-
+
+ Exe
+ enable
+ enable
+ app.manifest
+ AnyCPU;x64;x86
+
-
-
-
-
+
+
+
+
-
-
- PreserveNewest
- true
- PreserveNewest
-
-
- PreserveNewest
- true
- PreserveNewest
-
-
+
+
+ PreserveNewest
+ true
+ PreserveNewest
+
+
+ PreserveNewest
+ true
+ PreserveNewest
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
- Always
-
-
- Always
-
-
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
diff --git a/HeadlessServer/Program.cs b/HeadlessServer/Program.cs
index 30e81ba1..2be72af2 100644
--- a/HeadlessServer/Program.cs
+++ b/HeadlessServer/Program.cs
@@ -13,9 +13,9 @@
namespace HeadlessServer;
-internal sealed class Program
+public sealed class Program
{
- private static void Main(string[] args)
+ public static void Main(string[] args)
{
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
@@ -108,9 +108,17 @@ private static void Main(string[] args)
logger.LogError(e, e.Message);
};
- provider
- .GetRequiredService()
- .Run(options);
+ HeadlessServer headlessServer = provider.GetRequiredService();
+
+ if (options.Value.LoadOnly)
+ {
+ headlessServer.RunLoadOnly(options);
+ Environment.Exit(0);
+ }
+ else
+ {
+ headlessServer.Run(options);
+ }
Exit:
Console.ReadKey();
diff --git a/HeadlessServer/RunOptions.cs b/HeadlessServer/RunOptions.cs
index d5ab4b66..28f5275e 100644
--- a/HeadlessServer/RunOptions.cs
+++ b/HeadlessServer/RunOptions.cs
@@ -93,4 +93,10 @@ public sealed class RunOptions
Default = false,
HelpText = $"Disable PathVisualization in RemoteV1")]
public bool PathVisualizer { get; set; }
+
+ [Option("loadonly",
+ Required = false,
+ Default = false,
+ HelpText = $"Loads the class profile then exists")]
+ public bool LoadOnly { get; set; }
}
diff --git a/README.md b/README.md
index e1af0107..548ec956 100644
--- a/README.md
+++ b/README.md
@@ -306,6 +306,7 @@ In order to run `HeadlessServer` please look at the `HeadlessServer\run.bat`.
| `-t`
`-otargeting` | While overlay enabled, show Targeting points | `false` | - |
| `-s`
`-oskinning` | While overlay enabled, show Skinning points | `false` | - |
| `-v`
`-otargetvsadd` | While overlay enabled, show Target vs Add points | `false` | - |
+| `--loadonly` | Loads the given class profile then exists | `false` | - |
e.g. run from Powershell without any optional parameter
```ps