Skip to content

Commit

Permalink
fixed after HDT update
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Oct 21, 2017
1 parent 787f35e commit 74c6169
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Autosquelch/Autosquelch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="HearthstoneDeckTracker">
<HintPath>..\..\..\..\AppData\Local\HearthstoneDeckTracker\app-1.5.1\HearthstoneDeckTracker.exe</HintPath>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -54,6 +57,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AutosquelchPlugin.cs" />
<Compile Include="HueAndBrightness.cs" />
<Compile Include="MouseHelpers.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions Autosquelch/AutosquelchPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public void OnLoad()
{
Squelched = false;
PluginRunning = true;
var d = Config.Instance.DeckExportDelay;

GameEvents.OnGameStart.Add(() =>
{
Expand Down Expand Up @@ -155,8 +154,8 @@ public async Task Squelch()

await MouseHelpers.ClickOnPoint(hearthstoneWindow, opponentHeroPosition, false);

await Task.Delay(TimeSpan.FromMilliseconds(Config.Instance.DeckExportDelay * 4));
var capture = await ScreenCapture.CaptureHearthstoneAsync(squelchBubblePosition, lockWidth, lockHeight, hearthstoneWindow);
await Task.Delay(TimeSpan.FromSeconds(0.3));
var capture = await ScreenCapture.CaptureHearthstoneAsync(squelchBubblePosition, lockWidth, lockHeight, hearthstoneWindow);
squelchBubbleVisible = HueAndBrightness.GetAverage(capture).Brightness > minBrightness;
if (!squelchBubbleVisible)
await Task.Delay(TimeSpan.FromSeconds(0.5));
Expand Down
44 changes: 44 additions & 0 deletions Autosquelch/HueAndBrightness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#region

using System.Drawing;

#endregion

namespace Hearthstone_Deck_Tracker.Exporting
{
public class HueAndBrightness
{
public HueAndBrightness(double hue, double brightness)
{
Hue = hue;
Brightness = brightness;
}

public double Hue { get; }
public double Brightness { get; }

public static HueAndBrightness GetAverage(Bitmap bmp, double saturationThreshold = 0.05)
{
var totalHue = 0.0f;
var totalBrightness = 0.0f;
var validPixels = 0;
for(var i = 0; i < bmp.Width; i++)
{
for(var j = 0; j < bmp.Height; j++)
{
var pixel = bmp.GetPixel(i, j);

//ignore sparkle
if(pixel.GetSaturation() > saturationThreshold)
{
totalHue += pixel.GetHue();
totalBrightness += pixel.GetBrightness();
validPixels++;
}
}
}

return new HueAndBrightness(totalHue / validPixels, totalBrightness / validPixels);
}
}
}
3 changes: 0 additions & 3 deletions Autosquelch/MouseHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ public static async Task ClickOnPoint(IntPtr wndHandle, Point clientPoint, bool
else
mouse_event((uint)RightDown, 0, 0, 0, UIntPtr.Zero);

await Task.Delay(Config.Instance.DeckExportDelay);

//mouse up
if (leftMouseButton)
mouse_event((uint)LeftUp, 0, 0, 0, UIntPtr.Zero);
else
mouse_event((uint)RightUp, 0, 0, 0, UIntPtr.Zero);

await Task.Delay(Config.Instance.DeckExportDelay);
}
}
}

0 comments on commit 74c6169

Please sign in to comment.