Skip to content

Commit

Permalink
Fixes for HS update
Browse files Browse the repository at this point in the history
  • Loading branch information
rembound committed Sep 16, 2016
1 parent fb14acf commit bd90296
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 40 deletions.
4 changes: 2 additions & 2 deletions ArenaWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<Run Text="with support from the community at GitHub." />
<Run Text="Thanks go out to Grinning Goat for providing " /><Hyperlink NavigateUri="{Binding StringTierList}" RequestNavigate="Hyperlink_RequestNavigate" Style="{StaticResource HyperlinkAboutStyle}">Hearthstone Arena Tier List</Hyperlink><Run Text="!" />
<LineBreak /><LineBreak />
<Run Text="Thanks for your support! Any " /><Hyperlink NavigateUri="{Binding StringDonate}" RequestNavigate="Hyperlink_RequestNavigate" Style="{StaticResource HyperlinkAboutStyle}">donation</Hyperlink><Run Text=" is greatly appreciated." />
<Hyperlink NavigateUri="{Binding StringDonate}" RequestNavigate="Hyperlink_RequestNavigate" Style="{StaticResource HyperlinkAboutStyle}">Donate</Hyperlink><Run Text=" to help support development. Thank you!" />
</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Name="AboutDonate" Content="donate" Width="60" Margin="0,0,0,0" Height="30" Style="{DynamicResource AccentedSquareButtonStyle}" Click="AboutDonate_Click"/>
Expand Down Expand Up @@ -90,7 +90,7 @@
<Run Text="The tier list and card data was updated to the latest version." />
<Run Text="More info about the tier list can be found at: " /><Hyperlink NavigateUri="{Binding StringTierList}" RequestNavigate="Hyperlink_RequestNavigate" Style="{StaticResource HyperlinkAboutStyle}">Hearthstone Arena Tier List</Hyperlink>
<LineBreak /><LineBreak />
<Run Text="Thanks for your support! Any " /><Hyperlink NavigateUri="{Binding StringDonate}" RequestNavigate="Hyperlink_RequestNavigate" Style="{StaticResource HyperlinkAboutStyle}">donation</Hyperlink><Run Text=" is greatly appreciated." />
<Hyperlink NavigateUri="{Binding StringDonate}" RequestNavigate="Hyperlink_RequestNavigate" Style="{StaticResource HyperlinkAboutStyle}">Donate</Hyperlink><Run Text=" to help support development. Thank you!" />
</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Name="DataUpdateDonate" Content="donate" Width="60" Margin="0,0,0,0" Height="30" Style="{DynamicResource AccentedSquareButtonStyle}" Click="AboutDonate_Click"/>
Expand Down
190 changes: 152 additions & 38 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public enum PluginState { Idle, SearchHeroes, SearchBigHero, DetectedHeroes, Sea

// HearthMirror
private bool usehearthmirror = true;
List<Card> previouscards = new List<Card>();
int samecardconfirmations;

// Updates
private DateTime lastpluginupdatecheck = DateTime.MinValue;
Expand Down Expand Up @@ -247,7 +249,7 @@ public string Author

public Version Version
{
get { return new Version("0.8.1"); }
get { return new Version("0.8.2"); }
}

public MenuItem MenuItem
Expand Down Expand Up @@ -859,6 +861,9 @@ private void NewArena()
loglastheroname = "";
loglastcardid = "";

previouscards.Clear();
samecardconfirmations = 0;

ClearDetected();

arenawindow.Hero0.HeroImage.Source = null;
Expand Down Expand Up @@ -1343,11 +1348,12 @@ private async Task Detect()
Debug.AppendLog("Arenacheck2 true\n");
}
}
Debug.AppendLog("Arenacheck1: " + detection.GetHashDistance(Detection.arenahash, arenascreenhash) + "\n");
//Debug.AppendLog("Arenacheck1: " + detection.GetHashDistance(Detection.arenahash, arenascreenhash) + "\n");
Debug.AppendLog("Arenacheck2: " + detection.GetHashDistance(Detection.arenahash2, arenascreenhash) + "\n");


if (detection.GetHashDistance(Detection.arenahash, arenascreenhash) < 10 || arenacheck2)

//if (detection.GetHashDistance(Detection.arenahash, arenascreenhash) < 10 || arenacheck2)
if (Hearthstone_Deck_Tracker.API.Core.Game.CurrentMode == Hearthstone_Deck_Tracker.Enums.Hearthstone.Mode.DRAFT)
{
// In arena
// If previously not in arena, wait for stable arena screen
Expand Down Expand Up @@ -1461,7 +1467,47 @@ private async Task Detect()

private void SearchHeroes(List<int> heroindices)
{
if (detection.ConfirmDetected(detectedheroes, heroindices, HeroConfirmations) == 3)
if (usehearthmirror)
{

HearthMirror.Objects.ArenaInfo arenainfo = Reflection.GetArenaDeck();
Log.Info("SH Cards");
if (arenainfo.Deck.Cards.Count == 0)
{
Log.Info("GetArenaDraftChoices");
List<HearthMirror.Objects.Card> choices = Reflection.GetArenaDraftChoices();
if (choices.Count == 3)
{
List<string> heronames = new List<string>();
for (int i = 0; i < 3; i++)
{
Log.Info("Hero Choice: " + choices[i].Id);
string heroname = Database.GetHeroNameFromId(choices[i].Id, false);
if (heroname != null)
{
heronames.Add(heroname);
}
}

if (heronames.Count == 3)
{
arenadata.detectedheroes.Clear();
arenadata.detectedheroes.Add(heronames[0]);
arenadata.detectedheroes.Add(heronames[1]);
arenadata.detectedheroes.Add(heronames[2]);
SaveArenaData();

plugins.HeroesDetected(arenadata, heronames[0], heronames[1], heronames[2]);

// Show the heroes
UpdateDetectedHeroes();

SetState(PluginState.SearchBigHero);
}
}
}
}
else if (detection.ConfirmDetected(detectedheroes, heroindices, HeroConfirmations) == 3)
{
// All heroes detected
HeroHashData hero0 = herohashlist[detectedheroes[0].index];
Expand All @@ -1485,29 +1531,12 @@ private void SearchHeroes(List<int> heroindices)

private void SearchBigHero(List<int> heroindices)
{
Tuple<List<int>, List<Tuple<ulong, List<Tuple<int, int>>>>> detectedbigheroes = detection.DetectBigHero(herohashlist);
List<int> bigheroindices = detectedbigheroes.Item1;

// Show debug info
for (int i = 0; i < detectedbigheroes.Item2.Count; i++)
{
ulong bigherohash = detectedbigheroes.Item2[i].Item1;
List<Tuple<int, int>> detectedindices = detectedbigheroes.Item2[i].Item2;

Debug.AppendLog("\nBig Hero Hash: " + string.Format("0x{0:X}", bigherohash));
foreach (Tuple<int, int> bigheroindex in detectedindices)
{
Debug.AppendLog(", " + herohashlist[bigheroindex.Item1].name + " (" + bigheroindex.Item2 + ")");
}
Debug.AppendLog("\n");
}

if (detection.ConfirmDetected(detectedbighero, bigheroindices, BigHeroConfirmations) == 1)
if (usehearthmirror)
{
// Big hero detected

// Update gui
string bigheroname = herohashlist[detectedbighero[0].index].name;
string bigheroname = loglastheroname;
int bigheroindex = -1;
for (int i = 0; i < arenadata.detectedheroes.Count; i++)
{
Expand All @@ -1517,12 +1546,56 @@ private void SearchBigHero(List<int> heroindices)
break;
}
}
ChangeHeroSize(bigheroindex, 56, 56, 4);

SetState(PluginState.DetectedHeroes);
if (bigheroindex != -1)
{
ResetHeroSize();
ChangeHeroSize(bigheroindex, 56, 56, 4);

// Call it immediately
WaitHeroPick(heroindices);
//SetState(PluginState.DetectedHeroes);
}
}
else
{
Tuple<List<int>, List<Tuple<ulong, List<Tuple<int, int>>>>> detectedbigheroes = detection.DetectBigHero(herohashlist);
List<int> bigheroindices = detectedbigheroes.Item1;

// Show debug info
for (int i = 0; i < detectedbigheroes.Item2.Count; i++)
{
ulong bigherohash = detectedbigheroes.Item2[i].Item1;
List<Tuple<int, int>> detectedindices = detectedbigheroes.Item2[i].Item2;

Debug.AppendLog("\nBig Hero Hash: " + string.Format("0x{0:X}", bigherohash));
foreach (Tuple<int, int> bigheroindex in detectedindices)
{
Debug.AppendLog(", " + herohashlist[bigheroindex.Item1].name + " (" + bigheroindex.Item2 + ")");
}
Debug.AppendLog("\n");
}

if (detection.ConfirmDetected(detectedbighero, bigheroindices, BigHeroConfirmations) == 1)
{
// Big hero detected

// Update gui
string bigheroname = herohashlist[detectedbighero[0].index].name;
int bigheroindex = -1;
for (int i = 0; i < arenadata.detectedheroes.Count; i++)
{
if (arenadata.detectedheroes[i] == bigheroname)
{
bigheroindex = i;
break;
}
}
ChangeHeroSize(bigheroindex, 56, 56, 4);

SetState(PluginState.DetectedHeroes);

// Call it immediately
WaitHeroPick(heroindices);
}
}
}

Expand Down Expand Up @@ -1570,17 +1643,20 @@ private void ChangeHeroSize(int index, int width, int height, int margin)

private void WaitHeroPick(List<int> heroindices)
{
Debug.AppendLog("\nChoosing: " + herohashlist[detectedbighero[0].index].name + "\n");

// All heroes detected, wait for pick
if (detection.GetUndetectedCount(heroindices) == 0)
if (!usehearthmirror)
{
// Cancelled the choice
ClearDetected();
SetState(PluginState.SearchBigHero);
Debug.AppendLog("\nChoosing: " + herohashlist[detectedbighero[0].index].name + "\n");

// All heroes detected, wait for pick
if (detection.GetUndetectedCount(heroindices) == 0)
{
// Cancelled the choice
ClearDetected();
SetState(PluginState.SearchBigHero);

// Restore gui
ResetHeroSize();
// Restore gui
ResetHeroSize();
}
}
}

Expand Down Expand Up @@ -1617,7 +1693,45 @@ private async Task SearchCards(List<int> cardindices)
cards[i] = GetCard(choices[i].Id);
Log.Info("Choice: " + choices[i].Id);
}
valid = true;

// Check for same cards
bool samecardsdetected = false;
if (previouscards.Count == 3)
{
int samecards = 0;
for (int i = 0; i < 3; i++)
{
if (previouscards[i].Id == cards[i].Id)
{
samecards++;
}
}

if (samecards == 3)
{
// All the same cards, can be valid but unlikely
samecardsdetected = true;
}
}

// Save card choices
previouscards.Clear();
for (int i = 0; i < 3; i++)
{
previouscards.Add(cards[i]);
}

// Wait for confirmations when same cards detected
if (samecardsdetected && samecardconfirmations < 3)
{
Log.Info("Same cards detected: confirmation " + samecardconfirmations);
samecardconfirmations++;
}
else
{
samecardconfirmations = 0;
valid = true;
}
}
}
else if (detection.ConfirmDetected(detectedcards, cardindices, CardConfirmations) == 3)
Expand Down

0 comments on commit bd90296

Please sign in to comment.