Skip to content

Commit

Permalink
Benchmark: Added a way to mass load all available profiles -- current…
Browse files Browse the repository at this point in the history
…ly 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.
  • Loading branch information
Xian55 committed Sep 8, 2024
1 parent f61cc88 commit f5395a6
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 62 deletions.
32 changes: 32 additions & 0 deletions .bat/json_find_most_requirement_count.ps1
Original file line number Diff line number Diff line change
@@ -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."
}
2 changes: 2 additions & 0 deletions .bat/link_json_to_benchmark_release.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mklink /J "..\Benchmarks\bin\Release\Json" "..\Json"
PAUSE
1 change: 1 addition & 0 deletions Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
<ProjectReference Include="..\HeadlessServer\HeadlessServer.csproj" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions Benchmarks/ClassProfile/LoadAllProfiles.cs
Original file line number Diff line number Diff line change
@@ -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<string> 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;
//}
}
}
11 changes: 8 additions & 3 deletions Core/DataFrame/FrameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static bool IsValid(Rectangle rect, Version addonVersion)
{
try
{
var config = JsonConvert.DeserializeObject<DataFrameConfig>(File.ReadAllText(FrameConfigMeta.DefaultFilename));
var config = Load();

bool sameVersion = config.Version == FrameConfigMeta.Version;
bool sameAddonVersion = config.AddonVersion == addonVersion;
Expand All @@ -38,11 +38,16 @@ public static bool IsValid(Rectangle rect, Version addonVersion)
}
}

public static DataFrameConfig Load()
{
return JsonConvert.DeserializeObject<DataFrameConfig>(File.ReadAllText(FrameConfigMeta.DefaultFilename));
}

public static DataFrame[] LoadFrames()
{
if (Exists())
{
var config = JsonConvert.DeserializeObject<DataFrameConfig>(File.ReadAllText(FrameConfigMeta.DefaultFilename));
var config = Load();
if (config.Version == FrameConfigMeta.Version)
return config.Frames;
}
Expand All @@ -52,7 +57,7 @@ public static DataFrame[] LoadFrames()

public static DataFrameMeta LoadMeta()
{
var config = JsonConvert.DeserializeObject<DataFrameConfig>(File.ReadAllText(FrameConfigMeta.DefaultFilename));
var config = Load();
if (config.Version == FrameConfigMeta.Version)
return config.Meta;

Expand Down
16 changes: 14 additions & 2 deletions Core/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 9 additions & 1 deletion HeadlessServer/HeadlessServer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using CommandLine;

using Core;

using Microsoft.Extensions.Logging;

namespace HeadlessServer;
Expand All @@ -23,7 +25,8 @@ public HeadlessServer(ILogger<HeadlessServer> logger,
SpellBookReader spellBookReader,
BagReader bagReader,
ExecGameCommand exec,
AddonConfigurator addonConfigurator, Wait wait)
AddonConfigurator addonConfigurator,
Wait wait)
{
this.logger = logger;
this.botController = botController;
Expand All @@ -45,6 +48,11 @@ public void Run(ParserResult<RunOptions> options)
botController.ToggleBotStatus();
}

public void RunLoadOnly(ParserResult<RunOptions> options)
{
botController.LoadClassProfile(options.Value.ClassConfig!);
}

private void InitState()
{
addonReader.FullReset();
Expand Down
105 changes: 54 additions & 51 deletions HeadlessServer/HeadlessServer.csproj
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
<None Remove="headless_appsettings.Development.json" />
<None Remove="headless_appsettings.json" />
</ItemGroup>
<ItemGroup>
<None Remove="headless_appsettings.Development.json" />
<None Remove="headless_appsettings.json" />
</ItemGroup>

<ItemGroup>
<Content Include="headless_appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="headless_appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="headless_appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="headless_appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Serilog.Expressions" />
<PackageReference Include="Serilog.Extensions.Logging" />
<PackageReference Include="Serilog.Settings.Configuration" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.Debug" />
<PackageReference Include="Serilog.Sinks.File" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Hosting" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Serilog.Expressions" />
<PackageReference Include="Serilog.Extensions.Logging" />
<PackageReference Include="Serilog.Settings.Configuration" />
<PackageReference Include="Serilog.Sinks.Console" />
<PackageReference Include="Serilog.Sinks.Debug" />
<PackageReference Include="Serilog.Sinks.File" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="addon_config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data_config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="addon_config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data_config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="frame_config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
18 changes: 13 additions & 5 deletions HeadlessServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -108,9 +108,17 @@ private static void Main(string[] args)
logger.LogError(e, e.Message);
};

provider
.GetRequiredService<HeadlessServer>()
.Run(options);
HeadlessServer headlessServer = provider.GetRequiredService<HeadlessServer>();

if (options.Value.LoadOnly)
{
headlessServer.RunLoadOnly(options);
Environment.Exit(0);
}
else
{
headlessServer.Run(options);
}

Exit:
Console.ReadKey();
Expand Down
6 changes: 6 additions & 0 deletions HeadlessServer/RunOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ In order to run `HeadlessServer` please look at the `HeadlessServer\run.bat`.
| `-t`<br>`-otargeting` | While overlay enabled, show Targeting points | `false` | - |
| `-s`<br>`-oskinning` | While overlay enabled, show Skinning points | `false` | - |
| `-v`<br>`-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
Expand Down

0 comments on commit f5395a6

Please sign in to comment.