Skip to content

Commit

Permalink
Fix info leak when guessed cards are drawn/discarded
Browse files Browse the repository at this point in the history
  • Loading branch information
azeier committed Jun 8, 2019
1 parent ae3fb9f commit 4ba6b39
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Hearthstone Deck Tracker/Hearthstone/Entities/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public void SetOriginalCardId(int dbfId)
public bool CreatedInDeck => OriginalZone == Zone.DECK;
public bool CreatedInHand => OriginalZone == Zone.HAND;
public bool? OriginalEntityWasCreated { get; internal set; }
public GuessedCardState GuessedCardState { get; set; } = GuessedCardState.None;

public override string ToString()
{
Expand Down Expand Up @@ -221,6 +222,8 @@ public override string ToString()
sb.Append(", OriginalController=" + OriginalController);
if(!string.IsNullOrEmpty(OriginalCardId))
sb.Append(", OriginalCardId=" + OriginalCardId);
if(GuessedCardState != GuessedCardState.None)
sb.Append(", guessedCardState=" + GuessedCardState);
return sb.ToString();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Hearthstone_Deck_Tracker.Hearthstone.Entities
{
public enum GuessedCardState
{
None,
Guessed,
Revealed
}
}
12 changes: 8 additions & 4 deletions Hearthstone Deck Tracker/Hearthstone/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,15 @@ internal List<Card> GetPlayerCardList(bool removeNotInDeck, bool highlightCardsI
}

public List<Card> OpponentCardList
=> RevealedEntities.Where(x => !(x.Info.Hidden && (x.IsInDeck || x.IsInHand)) && (x.IsPlayableCard || !x.HasTag(GameTag.CARDTYPE))
&& (x.GetTag(GameTag.CREATOR) == 1 || ((!x.Info.Created || (Config.Instance.OpponentIncludeCreated && (x.Info.CreatedInDeck || x.Info.CreatedInHand)))
&& x.Info.OriginalController == Id) || x.IsInHand || x.IsInDeck) && !(x.Info.Created && x.IsInSetAside))
=> RevealedEntities.Where(x => !(x.Info.GuessedCardState == GuessedCardState.None && x.Info.Hidden && (x.IsInDeck || x.IsInHand))
&& (x.IsPlayableCard || !x.HasTag(GameTag.CARDTYPE))
&& (x.GetTag(GameTag.CREATOR) == 1
|| ((!x.Info.Created || (Config.Instance.OpponentIncludeCreated && (x.Info.CreatedInDeck || x.Info.CreatedInHand)))
&& x.Info.OriginalController == Id)
|| x.IsInHand || x.IsInDeck)
&& !(x.Info.Created && x.IsInSetAside && x.Info.GuessedCardState != GuessedCardState.Guessed))
.GroupBy(e => new { CardId = e.Info.WasTransformed ? e.Info.OriginalCardId : e.CardId,
Hidden = (e.IsInHand || e.IsInDeck) && e.IsControlledBy(Id),
Hidden = (e.IsInHand || e.IsInDeck || (e.IsInSetAside && e.Info.GuessedCardState == GuessedCardState.Guessed)) && e.IsControlledBy(Id),
Created = e.Info.Created || (e.Info.Stolen && e.Info.OriginalController != Id),
Discarded = e.Info.Discarded && Config.Instance.HighlightDiscarded})
.Select(g =>
Expand Down
29 changes: 21 additions & 8 deletions Hearthstone Deck Tracker/LogReader/Handlers/PowerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void Handle(string logLine, IHsGameState gameState, IGame game)
var id = int.Parse(match.Groups["id"].Value);
var cardId = match.Groups["cardId"].Value;
var zone = GameTagHelper.ParseEnum<Zone>(match.Groups["zone"].Value);
var guessedCardId = false;
if(!game.Entities.ContainsKey(id))
{
if(string.IsNullOrEmpty(cardId) && zone != Zone.SETASIDE)
Expand All @@ -137,10 +138,14 @@ public void Handle(string logLine, IHsGameState gameState, IGame game)
{
Log.Info($"Found known cardId for entity {id}: {cardId}");
gameState.KnownCardIds[blockId.Value].Remove(cardId);
guessedCardId = true;
}
}
}
game.Entities.Add(id, new Entity(id) {CardId = cardId});
var entity = new Entity(id) { CardId = cardId };
if(guessedCardId)
entity.Info.GuessedCardState = GuessedCardState.Guessed;
game.Entities.Add(id, entity);
}
gameState.SetCurrentEntity(id);
if(gameState.DeterminedPlayers)
Expand Down Expand Up @@ -169,7 +174,11 @@ public void Handle(string logLine, IHsGameState gameState, IGame game)
game.Entities.Add(entityId, new Entity(entityId));
var entity = game.Entities[entityId];
if(type != "CHANGE_ENTITY" || string.IsNullOrEmpty(entity.CardId))
{
entity.CardId = cardId;
if(entity.Info.GuessedCardState != GuessedCardState.None)
entity.Info.GuessedCardState = GuessedCardState.Revealed;
}
if(type == "CHANGE_ENTITY")
{
if(!entity.Info.OriginalEntityWasCreated.HasValue)
Expand Down Expand Up @@ -201,16 +210,20 @@ public void Handle(string logLine, IHsGameState gameState, IGame game)
}
else if(logLine.Contains("HIDE_ENTITY"))
{
if(gameState.CurrentBlock?.CardId == Collectible.Neutral.KingTogwaggle
|| gameState.CurrentBlock?.CardId == NonCollectible.Neutral.KingTogwaggle_KingsRansomToken)
var match = HideEntityRegex.Match(logLine);
if(match.Success)
{
var match = HideEntityRegex.Match(logLine);
if(match.Success)
var id = int.Parse(match.Groups["id"].Value);
if(game.Entities.TryGetValue(id, out var entity))
{
var id = int.Parse(match.Groups["id"].Value);
if(game.Entities.TryGetValue(id, out var entity))
if(entity.Info.GuessedCardState == GuessedCardState.Revealed)
entity.Info.GuessedCardState = GuessedCardState.Guessed;
if(gameState.CurrentBlock?.CardId == Collectible.Neutral.KingTogwaggle
|| gameState.CurrentBlock?.CardId == NonCollectible.Neutral.KingTogwaggle_KingsRansomToken)
{
entity.Info.Hidden = true;
}
}
}
}
}
if(logLine.Contains("End Spectator") && !game.IsInMenu)
Expand Down

0 comments on commit 4ba6b39

Please sign in to comment.