Skip to content

Commit

Permalink
Scry integration (#4486)
Browse files Browse the repository at this point in the history
* feat: Update Reflection usage to go through new Reflection.Client accessor

* feat: Route IPC server stdout/err into HDT log

* feat: Log HearthMirror IPC client-side messages to HDT log

* feat: Instrument HearthMirror IPC server process exits in Influx

* feat: Start and stop the HearthMirror IPC server to match Hearthstone proc

* feat: Hook up debug log to HearthMirror RPC event timings

* feat: Instrument failed and successful memory reading attempts to InfluxDB
  • Loading branch information
joolean authored Sep 25, 2023
1 parent 6fd19b1 commit 12f57c1
Show file tree
Hide file tree
Showing 30 changed files with 153 additions and 72 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ HDT-Localization/
Resources/Generated/
Resources/Tiles/
/lib/HSReplay.dll
/lib/HearthMirror.dll
/lib/HearthMirror.exe
/lib/HearthDb.dll
/lib/BobsBuddy.dll
/lib/Newtonsoft.Json.dll
/lib/System.Reflection.DispatchProxy.dll
/lib/untapped-scry-dotnet.dll

# Rider config files
.idea/
7 changes: 6 additions & 1 deletion Bootstrap/Bootstrap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<HDTDirectory>$(SlnDirectory)/Hearthstone Deck Tracker</HDTDirectory>

<HearthDbUrl>https://libs.hearthsim.net/hdt/HearthDb.dll</HearthDbUrl>
<HearthMirrorUrl>https://libs.hearthsim.net/hdt/HearthMirror.dll</HearthMirrorUrl>
<HearthMirrorUrl>https://libs.hearthsim.net/hdt/HearthMirror.zip</HearthMirrorUrl>
<HSReplayUrl>https://libs.hearthsim.net/hdt/HSReplay.dll</HSReplayUrl>
<BobsBuddyUrl>https://libs.hearthsim.net/hdt/BobsBuddy.dll</BobsBuddyUrl>
</PropertyGroup>
Expand All @@ -42,6 +42,11 @@
</DownloadFile>
</Target>

<Target Name="UnpackHearthMirrorDeps" BeforeTargets="Bootstrap" DependsOnTargets="DownloadDeps">
<Unzip SourceFiles="$(SlnDirectory)/lib/HearthMirror.zip" DestinationFolder="$(SlnDirectory)/lib" />
<Delete Files="$(SlnDirectory)/lib/HearthMirror.zip" />
</Target>

<Target Name="CloneHDTLocalization" Condition="!Exists('$(SlnDirectory)/HDT-Localization')" BeforeTargets="Bootstrap">
<Message Importance="normal" Text="Couldn't find HDT-Localization repo." />
<Exec WorkingDirectory="$(SlnDirectory)" Command="git clone --depth=1 https://github.com/HearthSim/HDT-Localization.git HDT-Localization" />
Expand Down
2 changes: 1 addition & 1 deletion HDTTests/HDTTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<HintPath>..\lib\HearthDb.dll</HintPath>
</Reference>
<Reference Include="HearthMirror">
<HintPath>..\lib\HearthMirror.dll</HintPath>
<HintPath>..\lib\HearthMirror.exe</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions HearthWatcher.Test/HearthWatcher.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="HearthMirror">
<HintPath>..\lib\HearthMirror.dll</HintPath>
</Reference>
<ProjectReference Include="..\HearthWatcher\HearthWatcher.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HearthWatcher\HearthWatcher.csproj" />
<Reference Include="HearthMirror">
<HintPath>..\lib\HearthMirror.exe</HintPath>
</Reference>
</ItemGroup>
</Project>
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
2 changes: 1 addition & 1 deletion HearthWatcher/HearthWatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<HintPath>..\lib\HearthDb.dll</HintPath>
</Reference>
<Reference Include="HearthMirror">
<HintPath>..\lib\HearthMirror.dll</HintPath>
<HintPath>..\lib\HearthMirror.exe</HintPath>
</Reference>
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
9 changes: 7 additions & 2 deletions HearthWatcher/PVPDungeonRunWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ public bool Update()

public bool UpdatePVPDungeonInfo()
{
var pvpDungeonInfo = Reflection.GetPVPDungeonInfo();
DungeonInfo pvpDungeonInfo = null;
using(_ = Reflection.ClientReadTimeout(10000))
{
pvpDungeonInfo = Reflection.Client.GetPVPDungeonInfo();
}

if(pvpDungeonInfo != null)
{
if(pvpDungeonInfo.RunActive)
Expand All @@ -87,7 +92,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
37 changes: 37 additions & 0 deletions Hearthstone Deck Tracker/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,40 @@ public static async void Initialize()
#endif
splashScreenWindow.ShowConditional();
Log.Initialize();
Reflection.LogDebugMessage += msg => Log.Debug("HearthMirror RPC[client]: " + msg);
Reflection.LogMessage += msg => Log.Info("HearthMirror RPC [client]: " + msg);

Reflection.OnMemoryReading += (methodName, successCount, failureCount) =>
{
Influx.OnMemoryReading(methodName, successCount, failureCount);
};

Reflection.OnIpcServerExit += exitCode => {
string mode = "NULL";
if (_game?.CurrentMode != null)
{
mode = _game.CurrentMode.ToString();
}
Influx.OnHearthMirrorExit(exitCode, mode);
};

Reflection.StdErr += (sender, args) => {
if(args.Data != null && args.Data.Trim() != "")
{
Log.Info("HearthMirror RPC [stderr]: " + args.Data);
}
};

Reflection.StdOut += (sender, args) =>
{
if(args.Data != null && args.Data.Trim() != "")
{
Log.Info("HearthMirror RPC [stdout]: " + args.Data);
}
};

Reflection.Exception += e => Log.Warn("HearthMirror Exception: " + e);

ConfigManager.Run();
LocUtil.UpdateCultureInfo();
var newUser = ConfigManager.PreviousVersion == null;
Expand Down Expand Up @@ -268,6 +301,8 @@ private static async void UpdateOverlayAsync()
Remote.Config.Load();
Remote.BattlegroundsBans.Load();
Remote.Mercenaries.Load();

Reflection.StartIpcClient();
}
Overlay.UpdatePosition();

Expand Down Expand Up @@ -340,6 +375,8 @@ private static async void UpdateOverlayAsync()

TrayIcon.MenuItemStartHearthstone.Visible = true;

Reflection.StopIpcClient();

if(Config.Instance.CloseWithHearthstone)
MainWindow.Close();
}
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
6 changes: 3 additions & 3 deletions Hearthstone Deck Tracker/Hearthstone Deck Tracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<NeutralLanguage>en</NeutralLanguage>
<Description>Hearthstone Deck Tracker</Description>
<Copyright>Copyright © HearthSim 2023</Copyright>
<AssemblyVersion>1.21.12</AssemblyVersion>
<FileVersion>1.21.12</FileVersion>
<AssemblyVersion>1.21.13</AssemblyVersion>
<FileVersion>1.21.13</FileVersion>
<UseWPF>true</UseWPF>
<PlatformTarget>x86</PlatformTarget>
<Platforms>x86</Platforms>
Expand Down Expand Up @@ -82,7 +82,7 @@
<HintPath>..\lib\HearthDb.dll</HintPath>
</Reference>
<Reference Include="HearthMirror">
<HintPath>..\lib\HearthMirror.dll</HintPath>
<HintPath>..\lib\HearthMirror.exe</HintPath>
</Reference>
<Reference Include="HSReplay">
<HintPath>..\lib\HSReplay.dll</HintPath>
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
19 changes: 12 additions & 7 deletions Hearthstone Deck Tracker/Hearthstone/CollectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ public static class CollectionHelpers

private static async Task<Collection?> LoadCollection(Key key)
{
var data = await Task.Run(() => new
{
Collection = Reflection.GetFullCollection(),
BattleTag = Reflection.GetBattleTag()
var data = await Task.Run(() => {
using(_ = Reflection.ClientReadTimeout(10000))
{
return new
{
Collection = Reflection.Client.GetFullCollection(),
BattleTag = Reflection.Client.GetBattleTag()
};
}
});
if(data.Collection?.Cards.Any() ?? false)
{
Expand All @@ -31,8 +36,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 +115,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
Loading

0 comments on commit 12f57c1

Please sign in to comment.