Skip to content

Commit

Permalink
feat: Update Reflection usage to go through new Reflection.Client acc…
Browse files Browse the repository at this point in the history
…essor
  • Loading branch information
joolean committed Aug 31, 2023
1 parent 2ec9352 commit 43d65c8
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion HearthWatcher/DungeonRunWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public async Task<bool> Update()

public bool UpdateDungeonInfo()
{
var dungeonInfo = Reflection.GetDungeonInfo();
var dungeonInfo = Reflection.Client.GetDungeonInfo();
if(dungeonInfo != null)
{
for(var i = 0; i < dungeonInfo.Length; i++)
Expand Down
4 changes: 2 additions & 2 deletions HearthWatcher/PVPDungeonRunWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public bool Update()

public bool UpdatePVPDungeonInfo()
{
var pvpDungeonInfo = Reflection.GetPVPDungeonInfo();
var pvpDungeonInfo = Reflection.Client.GetPVPDungeonInfo();
if(pvpDungeonInfo != null)
{
if(pvpDungeonInfo.RunActive)
Expand All @@ -87,7 +87,7 @@ public bool UpdatePVPDungeonInfo()
}
else if(pvpDungeonInfo.SelectedLoadoutTreasureDbId > 0)
{
var deck = Reflection.GetPVPDungeonSeedDeck();
var deck = Reflection.Client.GetPVPDungeonSeedDeck();
if(deck == null)
return false;
var dbfids = deck.Cards.Select(x => HearthDb.Cards.All.TryGetValue(x.Id, out var card) ? card.DbfId : -1).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private async Task Update()
return;
}

var choices = Reflection.GetCardChoices();
var choices = Reflection.Client.GetCardChoices();
if(choices == null)
{
Message.Error();
Expand Down Expand Up @@ -134,7 +134,7 @@ private async void WatchChoices()
while(_watchChoices)
{
await Task.Delay(100);
var choices = Reflection.GetCardChoices();
var choices = Reflection.Client.GetCardChoices();
if(choices == null)
{
_watchChoices = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task Update(bool checkAccountStatus)
await Tier7Trial.Update();
TrialTimeRemaining = Tier7Trial.TimeRemaining;
TrialUsesRemaining = Tier7Trial.RemainingTrials ?? 0;
Username = Reflection.GetBattleTag()?.Name ?? HSReplayNetOAuth.AccountData.Username;
Username = Reflection.Client.GetBattleTag()?.Name ?? HSReplayNetOAuth.AccountData.Username;
UserState = UserState.Authenticated;
return;
}
Expand All @@ -142,7 +142,7 @@ public async Task Update(bool checkAccountStatus)
UserState = UserState.Loading;
TrialTimeRemaining = null;
int? allTimeFromApi = null;
var acc = Reflection.GetAccountId();
var acc = Reflection.Client.GetAccountId();
if(acc != null)
{
var response = await HSReplayNetOAuth.MakeRequest(c => c.GetAllTimeBGsMMR(acc.Hi, acc.Lo));
Expand Down Expand Up @@ -187,7 +187,7 @@ public void Reset()

public ICommand MyStatsCommand => new Command(() =>
{
var acc = Reflection.GetAccountId();
var acc = Reflection.Client.GetAccountId();
var queryParams = acc != null ? new[] { $"hearthstone_account={acc.Hi}-{acc.Lo}" } : null;
var url = Helper.BuildHsReplayNetUrl("battlegrounds/mine/", "bgs_lobby_my_stats", queryParams);
Helper.TryOpenUrl(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public List<MercenariesTaskViewModel>? Tasks
public bool Update()
{
if(_taskData == null)
_taskData = Reflection.GetMercenariesTasksData();
_taskData = Reflection.Client.GetMercenariesTasksData();

if(_taskData == null)
return false;

var tasks = Reflection.GetMercenariesVisitorTasks();
var tasks = Reflection.Client.GetMercenariesVisitorTasks();
if(tasks == null || tasks.Count == 0)
return false;
Tasks = tasks.Select(task =>
Expand Down
8 changes: 4 additions & 4 deletions Hearthstone Deck Tracker/GameEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private async Task<bool> LogIsComplete()

private async Task UpdatePostGameRanks(GameStats gs)
{
var medalInfo = await Helper.RetryWhileNull(Reflection.GetMedalInfo);
var medalInfo = await Helper.RetryWhileNull(Reflection.Client.GetMedalInfo);
if(medalInfo == null)
{
Log.Warn("Could not get MedalInfo");
Expand All @@ -232,7 +232,7 @@ private async Task UpdatePostGameRanks(GameStats gs)

private async Task UpdatePostGameBattlegroundsRating(GameStats gs)
{
var data = await Helper.RetryWhileNull(Reflection.GetBaconRatingChangeData);
var data = await Helper.RetryWhileNull(Reflection.Client.GetBaconRatingChangeData);
if(data == null)
{
Log.Warn("Could not get battlegrounds rating");
Expand All @@ -243,7 +243,7 @@ private async Task UpdatePostGameBattlegroundsRating(GameStats gs)

private async Task UpdatePostGameMercenariesRating(GameStats gs)
{
var data = await Helper.RetryWhileNull(Reflection.GetMercenariesRatingChangeData);
var data = await Helper.RetryWhileNull(Reflection.Client.GetMercenariesRatingChangeData);
if(data == null)
{
Log.Warn("Could not get mercenaries rating");
Expand Down Expand Up @@ -506,7 +506,7 @@ public void HandleGameStart(DateTime timestamp)
_game.CacheGameType();
_game.CacheSpectator();

_game.MetaData.ServerInfo = Reflection.GetServerInfo();
_game.MetaData.ServerInfo = Reflection.Client.GetServerInfo();
TurnTimer.Instance.Start(_game).Forget();

var selectedDeck = DeckList.Instance.ActiveDeckVersion;
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Hearthstone/BattlegroundsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static HashSet<Race>? AvailableRaces
{
get
{
var races = Reflection.GetAvailableBattlegroundsRaces();
var races = Reflection.Client.GetAvailableBattlegroundsRaces();
if(races == null)
return null;
return new HashSet<Race>(races.Cast<Race>());
Expand Down
10 changes: 5 additions & 5 deletions Hearthstone Deck Tracker/Hearthstone/CollectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static class CollectionHelpers
{
var data = await Task.Run(() => new
{
Collection = Reflection.GetFullCollection(),
BattleTag = Reflection.GetBattleTag()
Collection = Reflection.Client.GetFullCollection(),
BattleTag = Reflection.Client.GetBattleTag()
});
if(data.Collection?.Cards.Any() ?? false)
{
Expand All @@ -31,8 +31,8 @@ public static class CollectionHelpers
{
var data = await Task.Run(() => new
{
Collection = Reflection.GetMercenariesCollection(),
BattleTag = Reflection.GetBattleTag()
Collection = Reflection.Client.GetMercenariesCollection(),
BattleTag = Reflection.Client.GetBattleTag()
});
if(data.Collection?.Any() ?? false)
{
Expand Down Expand Up @@ -110,7 +110,7 @@ private async Task<bool> UpdateCollection(Key? key, bool retry = true)
{
if(!Core.Game.IsRunning)
return _lastUsedKey;
var user = Reflection.GetAccountId();
var user = Reflection.Client.GetAccountId();
if(user == null)
{
if(_lastUsedKey == null && retry)
Expand Down
28 changes: 14 additions & 14 deletions Hearthstone Deck Tracker/Hearthstone/GameV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Format? CurrentFormat
get
{
if(_currentFormat == FormatType.FT_UNKNOWN)
_currentFormat = (FormatType)HearthMirror.Reflection.GetFormat();
_currentFormat = (FormatType)HearthMirror.Reflection.Client.GetFormat();
return HearthDbConverter.GetFormat(_currentFormat);
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public bool IsMulliganDone
}
}

public bool Spectator => _spectator ?? (bool)(_spectator = HearthMirror.Reflection.IsSpectating());
public bool Spectator => _spectator ?? (bool)(_spectator = HearthMirror.Reflection.Client.IsSpectating());

public GameMode CurrentGameMode
{
Expand All @@ -197,23 +197,23 @@ public GameType CurrentGameType
return _currentGameType;
if(_currentMode == Mode.GAMEPLAY)
{
_currentGameType = (GameType)HearthMirror.Reflection.GetGameType();
_currentGameType = (GameType)HearthMirror.Reflection.Client.GetGameType();
return _currentGameType;
}
return GameType.GT_UNKNOWN;
}
}

public MatchInfo MatchInfo => _matchInfo ?? (_matchInfo = HearthMirror.Reflection.GetMatchInfo());
public MatchInfo MatchInfo => _matchInfo ?? (_matchInfo = HearthMirror.Reflection.Client.GetMatchInfo());
private bool _matchInfoCacheInvalid = true;

public BrawlInfo BrawlInfo => _brawlInfo ?? (_brawlInfo = HearthMirror.Reflection.GetBrawlInfo());
public BrawlInfo BrawlInfo => _brawlInfo ?? (_brawlInfo = HearthMirror.Reflection.Client.GetBrawlInfo());

public BattlegroundRatingInfo BattlegroundsRatingInfo => _battlegroundsRatingInfo ?? (_battlegroundsRatingInfo = HearthMirror.Reflection.GetBattlegroundRatingInfo());
public BattlegroundRatingInfo BattlegroundsRatingInfo => _battlegroundsRatingInfo ?? (_battlegroundsRatingInfo = HearthMirror.Reflection.Client.GetBattlegroundRatingInfo());

public MercenariesRatingInfo MercenariesRatingInfo => _mercenariesRatingInfo ?? (_mercenariesRatingInfo = HearthMirror.Reflection.GetMercenariesRatingInfo());
public MercenariesRatingInfo MercenariesRatingInfo => _mercenariesRatingInfo ?? (_mercenariesRatingInfo = HearthMirror.Reflection.Client.GetMercenariesRatingInfo());

public MercenariesMapInfo MercenariesMapInfo => HearthMirror.Reflection.GetMercenariesMapInfo();
public MercenariesMapInfo MercenariesMapInfo => HearthMirror.Reflection.Client.GetMercenariesMapInfo();

private bool IsValidPlayerInfo(MatchInfo.Player playerInfo, bool allowMissing = true)
{
Expand All @@ -228,7 +228,7 @@ internal async void CacheMatchInfo()
if(!_matchInfoCacheInvalid)
return;
MatchInfo matchInfo;
while((matchInfo = HearthMirror.Reflection.GetMatchInfo()) == null || !IsValidPlayerInfo(matchInfo.LocalPlayer) || !IsValidPlayerInfo(matchInfo.OpposingPlayer, IsMercenariesMatch))
while((matchInfo = HearthMirror.Reflection.Client.GetMatchInfo()) == null || !IsValidPlayerInfo(matchInfo.LocalPlayer) || !IsValidPlayerInfo(matchInfo.OpposingPlayer, IsMercenariesMatch))
{
Log.Info($"Waiting for matchInfo... (matchInfo={matchInfo}, localPlayer={matchInfo?.LocalPlayer?.Name}, opposingPlayer={matchInfo?.OpposingPlayer?.Name})");
await Task.Delay(1000);
Expand All @@ -255,17 +255,17 @@ string GetName(MatchInfo.Player player)

internal async void CacheGameType()
{
while((_currentGameType = (GameType)HearthMirror.Reflection.GetGameType()) == GameType.GT_UNKNOWN)
while((_currentGameType = (GameType)HearthMirror.Reflection.Client.GetGameType()) == GameType.GT_UNKNOWN)
await Task.Delay(1000);
}

internal void CacheSpectator() => _spectator = HearthMirror.Reflection.IsSpectating();
internal void CacheSpectator() => _spectator = HearthMirror.Reflection.Client.IsSpectating();

internal void CacheBrawlInfo() => _brawlInfo = HearthMirror.Reflection.GetBrawlInfo();
internal void CacheBrawlInfo() => _brawlInfo = HearthMirror.Reflection.Client.GetBrawlInfo();

internal void CacheBattlegroundRatingInfo() => _battlegroundsRatingInfo = HearthMirror.Reflection.GetBattlegroundRatingInfo();
internal void CacheBattlegroundRatingInfo() => _battlegroundsRatingInfo = HearthMirror.Reflection.Client.GetBattlegroundRatingInfo();

internal void CacheMercenariesRatingInfo() => _mercenariesRatingInfo = HearthMirror.Reflection.GetMercenariesRatingInfo();
internal void CacheMercenariesRatingInfo() => _mercenariesRatingInfo = HearthMirror.Reflection.Client.GetMercenariesRatingInfo();

internal void InvalidateMatchInfoCache() => _matchInfoCacheInvalid = true;

Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Hearthstone/MercenariesCoins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class MercenariesCoins
public static List<MercenariesCoinsEntry> Update()
{
var deltas = new List<MercenariesCoinsEntry>();
var data = Reflection.GetMercenariesInCollection();
var data = Reflection.Client.GetMercenariesInCollection();
if(data == null)
return deltas;
foreach(var merc in data)
Expand Down
6 changes: 3 additions & 3 deletions Hearthstone Deck Tracker/Hearthstone/QueueEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Handle(QueueEventArgs e)
else
{
var selectedId = GetSelectedDeckId(_game.CurrentMode);
_game.CurrentSelectedDeck = selectedId > 0 ? Reflection.GetDecks()?.FirstOrDefault(deck => deck.Id == selectedId) : null;
_game.CurrentSelectedDeck = selectedId > 0 ? Reflection.Client.GetDecks()?.FirstOrDefault(deck => deck.Id == selectedId) : null;
}
if(!Config.Instance.AutoDeckDetection)
return;
Expand Down Expand Up @@ -112,12 +112,12 @@ private void AutoSelectArenaDeck()

private static long GetSelectedDeckId(Mode mode)
{
var selectedDeckId = Reflection.GetSelectedDeckInMenu();
var selectedDeckId = Reflection.Client.GetSelectedDeckInMenu();
if(selectedDeckId > 0)
return selectedDeckId;
if(mode != TAVERN_BRAWL)
return 0;
return Reflection.GetEditedDeck()?.Id ?? 0;
return Reflection.Client.GetEditedDeck()?.Id ?? 0;
}
}
}
20 changes: 10 additions & 10 deletions Hearthstone Deck Tracker/Hearthstone/Watchers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,36 +99,36 @@ public bool InPVPDungeonRunMatch

public class HearthMirrorPackProvider : IPackProvider
{
public List<HearthMirror.Objects.Card> GetCards() => Reflection.GetPackCards();
public int GetPackId() => Reflection.GetLastOpenedBoosterId();
public List<HearthMirror.Objects.Card> GetCards() => Reflection.Client.GetPackCards();
public int GetPackId() => Reflection.Client.GetLastOpenedBoosterId();
}

public class HearthMirrorArenaProvider : IArenaProvider
{
public ArenaInfo? GetArenaInfo() => DeckImporter.FromArena(false);
public HearthMirror.Objects.Card[]? GetDraftChoices() => Reflection.GetArenaDraftChoices()?.ToArray();
public HearthMirror.Objects.Card[]? GetDraftChoices() => Reflection.Client.GetArenaDraftChoices()?.ToArray();
}

public class HearthMirrorFriendlyChallengeProvider : IFriendlyChallengeProvider
{
public bool DialogVisible => Reflection.IsFriendlyChallengeDialogVisible();
public bool DialogVisible => Reflection.Client.IsFriendlyChallengeDialogVisible();
}

public class HearthMirrorRewardTrackProvider : IExperienceProvider
{
public RewardTrackData GetRewardTrackData() => Reflection.GetRewardTrackData();
public RewardTrackData GetRewardTrackData() => Reflection.Client.GetRewardTrackData();
}

public class HearthMirrorQueueProvider : IQueueProvider
{
public FindGameState? FindGameState => Reflection.GetFindGameState();
public FindGameState? FindGameState => Reflection.Client.GetFindGameState();
}

public class HearthMirrorBaconProvider : IBaconProvider
{
public bool? IsShopOpen => Reflection.IsShopOpen();
public bool? IsJournalOpen => Reflection.IsJournalOpen();
public bool? IsPopupShowing => Reflection.IsPopupShowing();
public bool? IsFriendslistOpen => Reflection.IsFriendsListVisible();
public bool? IsShopOpen => Reflection.Client.IsShopOpen();
public bool? IsJournalOpen => Reflection.Client.IsJournalOpen();
public bool? IsPopupShowing => Reflection.Client.IsPopupShowing();
public bool? IsFriendslistOpen => Reflection.Client.IsFriendsListVisible();
}
}
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/HsReplay/PackDataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class PackDataGenerator
Log.Error("Invalid card count: " + cards.Length);
return null;
}
var accId = HearthMirror.Reflection.GetAccountId();
var accId = HearthMirror.Reflection.Client.GetAccountId();
if(accId == null || accId.Hi == 0 || accId.Lo == 0)
{
Log.Error("Could not get account id");
Expand Down
8 changes: 4 additions & 4 deletions Hearthstone Deck Tracker/Importing/DeckImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static List<HearthMirror.Objects.Deck> ConstructedDecksCache

public static ArenaInfo ArenaInfoCache
{
get { return _arenaInfoCache ??= Reflection.GetArenaDeck(); }
get { return _arenaInfoCache ??= Reflection.Client.GetArenaDeck(); }
set { _arenaInfoCache = value; }
}

Expand Down Expand Up @@ -76,7 +76,7 @@ public static List<ImportedDeck> FromConstructed(bool refreshCache = true)
}

private static List<HearthMirror.Objects.Deck> GetConstructedDecks()
=> Reflection.GetDecks()?.Where(IsValidDeck).ToList() ?? new List<HearthMirror.Objects.Deck>();
=> Reflection.Client.GetDecks()?.Where(IsValidDeck).ToList() ?? new List<HearthMirror.Objects.Deck>();

private static bool IsValidDeck(HearthMirror.Objects.Deck deck)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public static List<ImportedDeck> FromBrawl()
}

private static List<HearthMirror.Objects.Deck> GetBrawlDecks()
=> Reflection.GetDecks()?.Where(x => x.Type == BrawlDeckType).ToList() ?? new List<HearthMirror.Objects.Deck>();
=> Reflection.Client.GetDecks()?.Where(x => x.Type == BrawlDeckType).ToList() ?? new List<HearthMirror.Objects.Deck>();

public static List<ImportedDeck> GetImportedDecks(IEnumerable<HearthMirror.Objects.Deck> decks, IList<Deck> localDecks)
{
Expand Down Expand Up @@ -185,7 +185,7 @@ public static List<ImportedDeck> GetImportedDecks(IEnumerable<HearthMirror.Objec
{
try
{
ArenaInfoCache = Reflection.GetArenaDeck();
ArenaInfoCache = Reflection.Client.GetArenaDeck();
if(ArenaInfoCache != null && log)
Log.Info($"Found new {ArenaInfoCache.Wins}-{ArenaInfoCache.Losses} arena deck: hero={ArenaInfoCache.Deck.Hero}, cards={ArenaInfoCache.Deck.Cards.Sum(x => x.Count)}");
else if(log)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private static BattlegroundsLastGames Load()

private async Task<string?> GetPlayerId()
{
var accountId = await Helper.RetryWhileNull(Reflection.GetAccountId, 2, 3000);
var accountId = await Helper.RetryWhileNull(Reflection.Client.GetAccountId, 2, 3000);
return accountId != null ? $"{accountId.Hi}_{accountId.Lo}" : null;
}

Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Utility/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public static async Task<Region> GetCurrentRegion()
{
for(var i = 0; i < 10; i++)
{
var accId = HearthMirror.Reflection.GetAccountId();
var accId = HearthMirror.Reflection.Client.GetAccountId();
if(accId != null)
{
var region = GetRegion(accId.Hi);
Expand Down
2 changes: 1 addition & 1 deletion Hearthstone Deck Tracker/Windows/OverlayWindow.Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private async void HideCardsWhenFriendsListOpen(Point clickPos)
if(_isFriendsListOpen == null)
{
await Task.Delay(500);
_isFriendsListOpen = Reflection.IsFriendsListVisible();
_isFriendsListOpen = Reflection.Client.IsFriendsListVisible();
}
if (_isFriendsListOpen.Value)
{
Expand Down
Loading

0 comments on commit 43d65c8

Please sign in to comment.