Skip to content

Commit

Permalink
Various fixes, update website (#255)
Browse files Browse the repository at this point in the history
* Fix Master It ratios to match UI changes

* Get center-ish of long checkmark arm. Cut out circle+checkmark from number scan area

* configurable snap-it overlay size

* Fix startup cancel if WFInfo already running

* use Item ID when finding current listings (names may differ due to "blueprint")

* clipboardtemplate ;

* Update website
  • Loading branch information
D1firehail authored Oct 29, 2022
1 parent 084a67e commit 8c0a660
Show file tree
Hide file tree
Showing 16 changed files with 314 additions and 52 deletions.
15 changes: 15 additions & 0 deletions WFInfo/CustomEntrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.Threading.Tasks;
using System.Management;
using Microsoft.Win32;
using System.Windows;
using System.Linq;

namespace WFInfo
{
Expand Down Expand Up @@ -89,6 +91,19 @@ public static void Main()
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

Directory.CreateDirectory(appPath);

string thisprocessname = Process.GetCurrentProcess().ProcessName;
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
{
using (StreamWriter sw = File.AppendText(appPath + @"\debug.log"))
{
sw.WriteLineAsync("[" + DateTime.UtcNow + "] Duplicate process found - start canceled. Version: " + version);
}
MessageBox.Show("Another instance of WFInfo is already running, close it and try again", "WFInfo V" + version);
return;
}

Directory.CreateDirectory(app_data_tesseract_catalog);
Directory.CreateDirectory(app_data_tesseract_catalog + @"\x86");
Directory.CreateDirectory(app_data_tesseract_catalog + @"\x64");
Expand Down
3 changes: 2 additions & 1 deletion WFInfo/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,12 +1500,13 @@ public async Task<JToken> GetCurrentListing(string primeName)
var body = await response.Content.ReadAsStringAsync();
var payload = JsonConvert.DeserializeObject<JObject>(body);
var sellOrders = (JArray)payload?["payload"]?["sell_orders"];
string itemID = PrimeItemToItemID(primeName);

if (sellOrders != null)
{
foreach (var listing in sellOrders)
{
if (primeName == (string)listing?["item"]?["en"]?["item_name"])
if (itemID == (string)listing?["item"]?["id"])
{
request.Dispose();
return listing;
Expand Down
9 changes: 0 additions & 9 deletions WFInfo/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ public partial class MainWindow : Window

public MainWindow()
{

string thisprocessname = Process.GetCurrentProcess().ProcessName;
if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
{
Main.AddLog("Duplicate process found");
Close();
}


INSTANCE = this;
main = new Main();
listener = new LowLevelListener(); //publisher
Expand Down
49 changes: 38 additions & 11 deletions WFInfo/Ocr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -846,15 +846,15 @@ internal static void ProcessSnapIt(Bitmap snapItImage, Bitmap fullShot, Point sn
}

int width = (int)(part.Bounding.Width * screenScaling);
if (width < 120)
if (width < _settings.MinOverlayWidth)
{
if (width < 50)
continue;
width = 120;
//if (width < 50)
// continue;
width = _settings.MinOverlayWidth;
}
else if (width > 160)
else if (width > _settings.MaxOverlayWidth)
{
width = 160;
width = _settings.MaxOverlayWidth;
}


Expand Down Expand Up @@ -1393,6 +1393,7 @@ private static void GetItemCounts(Bitmap filteredImage, Bitmap filteredImageClea
//find "center of mass" for just the circle+checkmark icon
int xCenterNew = x;
int yCenterNew = y;
int rightmost = 0; //rightmost edge of circle+checkmark icon
sumBlack = 1;
//use "flood search" approach from the pixel found above to find the whole checkmark+circle icon
Stack<Point> searchSpace = new Stack<Point>();
Expand All @@ -1418,6 +1419,8 @@ private static void GetItemCounts(Bitmap filteredImage, Bitmap filteredImageClea
xCenterNew += p.X + xOff;
yCenterNew += p.Y + yOff;
sumBlack++;
if (p.X + xOff > rightmost)
rightmost = p.X + xOff;
}
}
}
Expand All @@ -1430,6 +1433,28 @@ private static void GetItemCounts(Bitmap filteredImage, Bitmap filteredImageClea
xCenterNew = xCenterNew / sumBlack;
yCenterNew = yCenterNew / sumBlack;

//Search slight bit up and down to get well within the long line of the checkmark
int lowest = yCenterNew + 1000;
int highest = yCenterNew - 1000;
for (int yOff = -5; yOff < 5; yOff++)
{
int checkY = yCenterNew + yOff;
if (checkY > 0 && checkY < imgHeight)
{
index = 4 * (xCenterNew + (checkY) * imgWidth);
if (LockedBitmapBytes[index] == 0 && LockedBitmapBytes[index + 1] == 0 && LockedBitmapBytes[index + 2] == 0 && LockedBitmapBytes[index + 3] == 255)
{
if (checkY > highest)
highest = checkY;

if (checkY < lowest)
lowest = checkY;
}
}
}
yCenterNew = (highest + lowest) / 2;


//mark second-pass center
filteredImage.SetPixel(Left + xCenterNew, Top + yCenterNew, Color.Magenta);

Expand Down Expand Up @@ -1507,6 +1532,7 @@ private static void GetItemCounts(Bitmap filteredImage, Bitmap filteredImageClea
unfilteredImage.UnlockBits(lockedBitmapData);

//recalculate centers to be relative to whole image
rightmost = rightmost + Left + 1;
xCenter = xCenter + Left;
yCenter = yCenter + Top;
xCenterNew = xCenterNew + Left;
Expand Down Expand Up @@ -1555,6 +1581,8 @@ private static void GetItemCounts(Bitmap filteredImage, Bitmap filteredImageClea
index = 4 * (Left + (Top + Height) * imgWidth);
}
Height-= 2;

Left = rightmost; // cut out checkmark+circle icon
index = 4 * (Left + (Top + Height) * imgWidth);

//search for width
Expand Down Expand Up @@ -1814,23 +1842,23 @@ private static List<InventoryItem> FindOwnedItems(Bitmap ProfileImage, string ti
hitRatio = hits / (double)(rightEdge - leftEdge );
hitRatios.Add(hitRatio);

if (hitRatio > 0.5 && rightMostHit+1 < rightEdge && rightEdge - leftEdge > 100) //make sure the innermost right edge is used (avoid bright part of frame overlapping with edge)
if (hitRatio > 0.2 && rightMostHit+1 < rightEdge && rightEdge - leftEdge > 100) //make sure the innermost right edge is used (avoid bright part of frame overlapping with edge)
{
g.DrawLine(red, rightEdge, bottomEdge, rightMostHit, bottomEdge);
rightEdge = rightMostHit;
bottomEdge = y;
hitRatios.Clear();
hitRatios.Add(1);
}
if (hitRatio > 0.5 && leftMostHit > leftEdge && rightEdge - leftEdge > 100) //make sure the innermost left edge is used (avoid bright part of frame overlapping with edge)
if (hitRatio > 0.2 && leftMostHit > leftEdge && rightEdge - leftEdge > 100) //make sure the innermost left edge is used (avoid bright part of frame overlapping with edge)
{
g.DrawLine(red, leftEdge, bottomEdge, leftMostHit, bottomEdge);
leftEdge = leftMostHit;
bottomEdge = y;
hitRatios.Clear();
hitRatios.Add(1);
}
} while (bottomEdge+2 < ProfileImageClean.Height && hitRatios.Last() > 0.5);
} while (bottomEdge+2 < ProfileImageClean.Height && hitRatios.Last() > 0.2);
hitRatios.RemoveAt(hitRatios.Count - 1);
//find if/where it transitions from text (some misses) to no text (basically no misses) then back to text (some misses). This is proof it's an owned item and marks the bottom edge of the text
int ratioChanges = 0;
Expand All @@ -1853,7 +1881,7 @@ private static List<InventoryItem> FindOwnedItems(Bitmap ProfileImage, string ti
int width = rightEdge - leftEdge;
int height = bottomEdge - topEdge;

if (ratioChanges != 4 || width < 4 * height || width > 6 * height)
if (ratioChanges != 4 || width < 2.4 * height || width > 4 * height)
{
g.DrawRectangle(pink, leftEdge, topEdge, width, height);
x = Math.Max(rightEdge, x);
Expand Down Expand Up @@ -1918,7 +1946,6 @@ private static List<InventoryItem> FindOwnedItems(Bitmap ProfileImage, string ti
g.FillRectangle(Brushes.LightGray, cloneRect.X, cloneRect.Y + cloneRect.Height, cloneRect.Width, cloneRect.Height);
g.DrawString(rawText, font, Brushes.DarkBlue, new Point(cloneRect.X, cloneRect.Y + cloneRect.Height));


}
}
_tesseractService.FirstEngine.SetVariable("tessedit_char_whitelist", "");
Expand Down
4 changes: 3 additions & 1 deletion WFInfo/Settings/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Point MainWindowLocation
public bool Clipboard { get; set; } = false;
public long AutoDelay { get; set; } = 250L;
public int ImageRetentionTime { get; set; } = 12;
public string ClipboardTemplate { get; set; } = "-- PC 48 hours avg price by WFM (c) WFInfo"
public string ClipboardTemplate { get; set; } = "-- PC 48 hours avg price by WFM (c) WFInfo";
public bool SnapitExport { get; set; } = false;
public int Delay { get; set; } = 10000;
public bool HighlightRewards { get; set; } = true;
Expand All @@ -79,6 +79,8 @@ public Point MainWindowLocation
public double SnapRowTextDensity { get; set; } = 0.015;
public double SnapRowEmptyDensity { get; set; } = 0.01;
public double SnapColEmptyDensity { get; set; } = 0.005;
public int MinOverlayWidth { get; set; } = 120;
public int MaxOverlayWidth { get; set; } = 160;
public string Ignored { get; set; } = null;
[OnError]
internal void OnError(StreamingContext context, ErrorContext errorContext)
Expand Down
2 changes: 2 additions & 0 deletions WFInfo/Settings/IReadOnlyApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public interface IReadOnlyApplicationSettings
double SnapRowTextDensity { get; }
double SnapRowEmptyDensity { get; }
double SnapColEmptyDensity { get; }
int MinOverlayWidth { get; }
int MaxOverlayWidth { get; }
string Ignored { get; }
}
}
20 changes: 20 additions & 0 deletions WFInfo/Settings/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ public double SnapColEmptyDensity
}
}

public int MinOverlayWidth
{
get => _settings.MinOverlayWidth;
set
{
_settings.MinOverlayWidth = value;
RaisePropertyChanged();
}
}

public int MaxOverlayWidth
{
get => _settings.MaxOverlayWidth;
set
{
_settings.MaxOverlayWidth = value;
RaisePropertyChanged();
}
}

public string Ignored{
get => _settings.Ignored;
set {
Expand Down
19 changes: 19 additions & 0 deletions WFInfo/Settings/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@
</DockPanel>
</DockPanel>
</Border>
<Border DockPanel.Dock="Top"
Padding="15 5 25 5">
<UniformGrid>
<Label Content="Min Width (snap)"/>
<TextBox x:Name="MinOverlayWidth_number_box"
ToolTip="The minimum width in pixels snap-it overlays will be displayed on screen"
Text="{Binding SettingsViewModel.MinOverlayWidth, Mode=TwoWay}"
components:NumericOnlyEntry.RegexFilter="^[0-9\.,]+$"
VerticalAlignment="Top" />

<Label Content="Max Width (snap)"/>
<TextBox x:Name="MaxOverlayWidth_number_box"
ToolTip="The maximum width in pixels snap-it overlays will be displayed on screen"
Text="{Binding SettingsViewModel.MaxOverlayWidth, Mode=TwoWay}"
components:NumericOnlyEntry.RegexFilter="^[0-9\.,]+$"
VerticalAlignment="Top" />

</UniformGrid>
</Border>
<Border DockPanel.Dock="Top"
Padding="15 5 25 5">
<UniformGrid>
Expand Down
Binary file added docs/images/Settings/ActivationHotkeys.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Settings/DisplayMode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Settings/Miscellaneous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Settings/OverlayOptions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Settings/SnapItEfficiency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Settings/SnapSettings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/Settings/Unmarked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8c0a660

Please sign in to comment.