Skip to content

Commit

Permalink
Merge pull request #550 from Xian55/fix/549
Browse files Browse the repository at this point in the history
Fix Screen was not captured during configuration mode
  • Loading branch information
Xian55 authored Nov 12, 2023
2 parents ee1aff9 + 1789e5b commit 26c70ff
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 90 deletions.
23 changes: 14 additions & 9 deletions Core/Configurator/FrameConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public void Dispose()

private void ManualConfigThread()
{
screen.Enabled = true;

while (!cts.Token.IsCancellationRequested)
{
DoConfig(false);
Expand All @@ -91,6 +93,8 @@ private void ManualConfigThread()
wait.Update();
}
screenshotThread = null;

screen.Enabled = false;
}

private bool DoConfig(bool auto)
Expand Down Expand Up @@ -173,10 +177,7 @@ private bool DoConfig(bool auto)
DataFrameMeta = temp;
stage++;

if (auto)
{
logger.LogInformation($"{nameof(DataFrameMeta)}: {DataFrameMeta}");
}
logger.LogInformation($"{DataFrameMeta}");
}
break;
case Stage.ValidateMetaSize:
Expand Down Expand Up @@ -211,14 +212,14 @@ void cropSize(IImageProcessingContext x)
ImageBase64 = cropped.ToBase64String(JpegFormat.Instance);
}

DataFrames = FrameConfig.TryCreateFrames(DataFrameMeta, cropped);
if (DataFrames.Length == DataFrameMeta.frames)
DataFrames = FrameConfig.CreateFrames(DataFrameMeta, cropped);
if (DataFrames.Length == DataFrameMeta.Count)
{
stage++;
}
else
{
logger.LogWarning($"DataFrameMeta and FrameConfig dosen't match Frames: ({DataFrames.Length}) != Meta: ({DataFrameMeta.frames})");
logger.LogWarning($"DataFrameMeta and FrameConfig dosen't match Frames: ({DataFrames.Length}) != Meta: ({DataFrameMeta.Count})");
stage = Stage.Reset;

if (auto)
Expand Down Expand Up @@ -335,8 +336,8 @@ public bool FinishConfig()
Version? version = addonConfigurator.GetInstallVersion();
if (version == null ||
DataFrames.Length == 0 ||
DataFrameMeta.frames == 0 ||
DataFrames.Length != DataFrameMeta.frames ||
DataFrameMeta.Count == 0 ||
DataFrames.Length != DataFrameMeta.Count ||
!TryResolveRaceAndClass(out _, out _, out _))
{
logger.LogInformation("Frame configuration was incomplete! Please try again, after resolving the previusly mentioned issues...");
Expand All @@ -354,11 +355,15 @@ public bool FinishConfig()

public bool StartAutoConfig()
{
screen.Enabled = true;

while (DoConfig(true))
{
wait.Update();
}

screen.Enabled = false;

return FinishConfig();
}

Expand Down
19 changes: 10 additions & 9 deletions Core/DataFrame/DataFrameConfig.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System;

using SixLabors.ImageSharp;

namespace Core;

public readonly struct DataFrameConfig
public readonly record struct DataFrameConfig
{
public int Version { get; }
public Version addonVersion { get; }
public Rectangle rect { get; }
public DataFrameMeta meta { get; }
public DataFrame[] frames { get; }
public Version AddonVersion { get; }
public Rectangle Rect { get; }
public DataFrameMeta Meta { get; }
public DataFrame[] Frames { get; }

public DataFrameConfig(int version, Version addonVersion, Rectangle rect, DataFrameMeta meta, DataFrame[] frames)
{
Version = version;
this.addonVersion = addonVersion;
this.rect = rect;
this.meta = meta;
this.frames = frames;
this.AddonVersion = addonVersion;
this.Rect = rect;
this.Meta = meta;
this.Frames = frames;
}
}
80 changes: 23 additions & 57 deletions Core/DataFrame/DataFrameMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,81 +4,47 @@

namespace Core;

public readonly struct DataFrameMeta : IEquatable<DataFrameMeta>
public readonly record struct DataFrameMeta
{
[JsonIgnore]
public static DataFrameMeta Empty { get; } = new(-1, 0, 0, 0, 0);
private static readonly DataFrameMeta empty = new(-1, 0, 0, 0, 0);
[JsonIgnore]
public static ref readonly DataFrameMeta Empty => ref empty;

[JsonConstructor]
public DataFrameMeta(int hash, int spacing, int size, int rows, int frames)
public DataFrameMeta(int hash, int spacing, int sizes, int rows, int count)
{
this.hash = hash;
this.spacing = spacing;
this.size = size;
this.rows = rows;
this.frames = frames;
this.Hash = hash;
this.Spacing = spacing;
this.Sizes = sizes;
this.Rows = rows;
this.Count = count;
}

public int hash { get; }
public int Hash { get; }

public int spacing { get; }
public int Spacing { get; }

public int size { get; }
public int Sizes { get; }

public int rows { get; }
public int Rows { get; }

public int frames { get; }
public int Count { get; }

public Size EstimatedSize(Rectangle screenRect)
{
const int error = 2;

int squareSize = size + error + (spacing != 0 ? spacing + error : 0);
if (squareSize <= 0)
return Size.Empty;

SizeF estimatedSize = new((float)Math.Ceiling(frames / (float)rows) * squareSize, rows * squareSize);

if (estimatedSize.Width > screenRect.Width ||
estimatedSize.Height > screenRect.Height)
{
int cellSize = Sizes + error + (Spacing != 0 ? Spacing + error : 0);
if (cellSize <= 0)
return Size.Empty;
}

return (Size)estimatedSize;
}

public override int GetHashCode()
{
return hash;
}

public static bool operator ==(DataFrameMeta left, DataFrameMeta right)
{
return left.Equals(right);
}
SizeF estimated =
new((float)Math.Ceiling(Count / (float)Rows) * cellSize, Rows * cellSize);

public static bool operator !=(DataFrameMeta left, DataFrameMeta right)
{
return !(left == right);
}

public bool Equals(DataFrameMeta other)
{
return other.hash == hash &&
other.spacing == spacing &&
other.size == size &&
other.rows == rows &&
other.frames == frames;
}

public override bool Equals(object? obj)
{
return obj is DataFrameMeta && Equals((DataFrameMeta)obj);
}

public override string ToString()
{
return $"hash: {hash} | spacing: {spacing} | size: {size} | rows: {rows} | frames: {frames}";
return estimated.Width > screenRect.Width ||
estimated.Height > screenRect.Height
? Size.Empty
: (Size)estimated;
}
}
18 changes: 9 additions & 9 deletions Core/DataFrame/FrameConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Core;

public static class FrameConfigMeta
{
public const int Version = 3;
public const int Version = 4;
public const string DefaultFilename = "frame_config.json";
}

Expand All @@ -28,9 +28,9 @@ public static bool IsValid(Rectangle rect, Version addonVersion)
var config = JsonConvert.DeserializeObject<DataFrameConfig>(File.ReadAllText(FrameConfigMeta.DefaultFilename));

bool sameVersion = config.Version == FrameConfigMeta.Version;
bool sameAddonVersion = config.addonVersion == addonVersion;
bool sameRect = config.rect.Width == rect.Width && config.rect.Height == rect.Height;
return sameAddonVersion && sameVersion && sameRect && config.frames.Length > 1;
bool sameAddonVersion = config.AddonVersion == addonVersion;
bool sameRect = config.Rect.Width == rect.Width && config.Rect.Height == rect.Height;
return sameAddonVersion && sameVersion && sameRect && config.Frames.Length > 1;
}
catch
{
Expand All @@ -44,7 +44,7 @@ public static DataFrame[] LoadFrames()
{
var config = JsonConvert.DeserializeObject<DataFrameConfig>(File.ReadAllText(FrameConfigMeta.DefaultFilename));
if (config.Version == FrameConfigMeta.Version)
return config.frames;
return config.Frames;
}

return Array.Empty<DataFrame>();
Expand All @@ -54,7 +54,7 @@ public static DataFrameMeta LoadMeta()
{
var config = JsonConvert.DeserializeObject<DataFrameConfig>(File.ReadAllText(FrameConfigMeta.DefaultFilename));
if (config.Version == FrameConfigMeta.Version)
return config.meta;
return config.Meta;

return DataFrameMeta.Empty;
}
Expand Down Expand Up @@ -90,12 +90,12 @@ public static DataFrameMeta GetMeta(Bgra32 color)
return new DataFrameMeta(hash, spacing, size, rows, count);
}

public static DataFrame[] TryCreateFrames(DataFrameMeta meta, Image<Bgra32> bmp)
public static DataFrame[] CreateFrames(DataFrameMeta meta, Image<Bgra32> bmp)
{
DataFrame[] frames = new DataFrame[meta.frames];
DataFrame[] frames = new DataFrame[meta.Count];
frames[0] = new(0, 0, 0);

for (int i = 1; i < meta.frames; i++)
for (int i = 1; i < meta.Count; i++)
{
if (TryGetNextPoint(bmp, i, frames[i].X, out int x, out int y))
{
Expand Down
3 changes: 2 additions & 1 deletion Core/WoWScreen/WowScreenDXGI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ public void Update()
ID3D11Texture2D texture
= idxgiResource.QueryInterface<ID3D11Texture2D>();

UpdateAddonImage(texture);
if (frames.Length > 2)
UpdateAddonImage(texture);

if (Enabled)
UpdateScreenImage(texture);
Expand Down
10 changes: 5 additions & 5 deletions Frontend/Pages/FrameConfiguration.razor
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<h5 class="row col-md-12">Your screen:</h5>

<div class="row col-md-12">
@if (@frameConfigurator.DataFrames.Length != frameConfigurator.DataFrameMeta.frames)
@if (@frameConfigurator.DataFrames.Length != frameConfigurator.DataFrameMeta.Count)
{
<img style="border:1px solid red; margin: 5px" src="@frameConfigurator.ImageBase64" alt="Red dot" />
}
Expand All @@ -116,24 +116,24 @@
<ul class="list-group">
<li class="list-group-item">
Step 1: Please ensure the addon <span class="px-2"><b>@addonConfig.Title</b></span> found in the addon folders is running. You should see the multi-coloured pixels at the top left of the screen.
@if (frameConfigurator.DataFrames.Length != frameConfigurator.DataFrameMeta.frames)
@if (frameConfigurator.DataFrames.Length != frameConfigurator.DataFrameMeta.Count)
{
<br>
<img src="_content/Frontend/img/addon-normal.png" />
}
</li>
<li class="list-group-item">
Step 2: Now we are going to put the addon into configuration mode, this will change the addon colours displayed. In the wow chat window: type <span class="ml-1"><b>&#47;@addonConfig.Command</b></span>
@if (frameConfigurator.DataFrames.Length != frameConfigurator.DataFrameMeta.frames)
@if (frameConfigurator.DataFrames.Length != frameConfigurator.DataFrameMeta.Count)
{
<br>
<img src="_content/Frontend/img/addon-config.png" />
}
</li>
<li class="list-group-item">
Step 3: Should see @frameConfigurator.DataFrameMeta.frames frames - Now i see @frameConfigurator.DataFrames.Length data frames.
Step 3: Should see @frameConfigurator.DataFrameMeta.Count frames - Now i see @frameConfigurator.DataFrames.Length data frames.
</li>
@if (frameConfigurator.DataFrameMeta.frames != 0 && frameConfigurator.DataFrames.Length == frameConfigurator.DataFrameMeta.frames)
@if (frameConfigurator.DataFrameMeta.Count != 0 && frameConfigurator.DataFrames.Length == frameConfigurator.DataFrameMeta.Count)
{
<li class="list-group-item">
<span>Step 4: Now return to normal mode, In the wow chat window: type <span class="ml-1"><b>&#47;@addonConfig.Command</b></span></span>
Expand Down

0 comments on commit 26c70ff

Please sign in to comment.