Skip to content

Commit

Permalink
v1.1.8
Browse files Browse the repository at this point in the history
v1.1.8
  • Loading branch information
IBM5100o committed Dec 10, 2024
1 parent 6556e9a commit c42f126
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 47 deletions.
74 changes: 30 additions & 44 deletions HDT_BGrank/BGrank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ public class BGrank

private bool isReset = true;
private bool namesReady = false;
private bool playerReady = false;
private bool leaderBoardReady = false;

private Mirror mirror = null;
private List<string> oppNames = null;
private Dictionary<string, string> leaderBoard = null;
private readonly HttpClient client;
Expand All @@ -37,15 +35,13 @@ private void Reset()
{
done = false;
namesReady = false;
playerReady = false;
failToGetData = false;
leaderBoardReady = false;
ClearMemory();
}

public void ClearMemory()
{
mirror = null;
oppDict = null;
oppNames = null;
leaderBoard = null;
Expand All @@ -59,7 +55,7 @@ public void OnGameStart()
public void OnTurnStart(ActivePlayer player)
{
GetLeaderBoard();
playerReady = true;
GetOppNames();
}

public void OnUpdate()
Expand All @@ -74,14 +70,9 @@ public void OnUpdate()
}
else if (!done && Core.Game.IsBattlegroundsMatch)
{
if (isReset)
{
mirror = new Mirror { ImageName = "Hearthstone" };
isReset = false;
}
isReset = false;
if (failToGetData) { done = true; }
else if (!namesReady) { GetOppNames(); }
else if (leaderBoardReady)
else if (namesReady && leaderBoardReady)
{
Dictionary<string, int> unsortDict = new Dictionary<string, int>();
oppDict = new Dictionary<string, string>();
Expand Down Expand Up @@ -151,10 +142,7 @@ private async Task GetLeaderBoard()
for (int i = 0; i < lines.Length-1; i++)
{
string line = lines[i];
if (i > 0)
{
line = line.Substring(6);
}
if (i > 0) { line = line.Substring(6); }
string[] tmp = line.Split(' ');
if (tmp.Length == 2)
{
Expand Down Expand Up @@ -237,46 +225,40 @@ private string GetRegionStr()

private void GetOppNames()
{
if (!playerReady) { return; }
if (!Core.Game.IsBattlegroundsMatch || namesReady) { return; }

// The code below is from: https://github.com/Zero-to-Heroes/unity-spy-.net4.5
try
{
string myName = Reflection.Client?.GetMatchInfo()?.LocalPlayer?.Name;
if (string.IsNullOrEmpty(myName)) { return; }
Mirror mirror = new Mirror { ImageName = "Hearthstone" };
var leaderboardMgr = mirror.Root?["PlayerLeaderboardManager"]?["s_instance"];
dynamic[] playerTiles = GetPlayerTiles(leaderboardMgr);
var numberOfPlayerTiles = playerTiles?.Length ?? 0;
if (numberOfPlayerTiles == 0) { return; }
bool allPass = true;
List<string> tmpNames = new List<string>();

for (int i = 0; i < numberOfPlayerTiles; i++)
{
var playerTile = playerTiles[i];
// Info not available until the player mouses over the tile in the leaderboard, and there is no other way to get it
string playerName = playerTile["m_overlay"]?["m_heroActor"]?["m_playerNameText"]?["m_Text"];
if (string.IsNullOrEmpty(playerName))
{
allPass = false;
break;
}
if (string.IsNullOrEmpty(playerName)) { return; }
if (playerName != myName && !tmpNames.Contains(playerName)) { tmpNames.Add(playerName); }
}
if (allPass)

// For those who use the BattleTag MOD
for (int i = 0; i < tmpNames.Count; i++)
{
// For those who use the BattleTag MOD
for (int i = 0; i < tmpNames.Count; i++)
int index = tmpNames[i].IndexOf('#');
if (index > 0)
{
int index = tmpNames[i].IndexOf('#');
if (index > 0)
{
tmpNames[i] = tmpNames[i].Substring(0, index);
}
tmpNames[i] = tmpNames[i].Substring(0, index);
}
oppNames = new List<string>(tmpNames);
namesReady = true;
}
oppNames = new List<string>(tmpNames);
namesReady = true;
}
catch (Exception ex)
{
Expand All @@ -287,22 +269,26 @@ private void GetOppNames()
// The code below is from: https://github.com/Zero-to-Heroes/unity-spy-.net4.5
private static dynamic[] GetPlayerTiles(dynamic leaderboardMgr)
{
var result = new List<dynamic>();
var teams = leaderboardMgr["m_teams"]?["_items"];
foreach (var team in teams)
try
{
return leaderboardMgr?["m_playerTiles"]?["_items"];
}
catch (Exception)
{
if (team == null)
var result = new List<dynamic>();
var teams = leaderboardMgr["m_teams"]?["_items"];
foreach (var team in teams)
{
continue;
}
if (team == null) { continue; }

var tiles = team["m_playerLeaderboardCards"]?["_items"];
foreach (var tile in tiles)
{
result.Add(tile);
var tiles = team["m_playerLeaderboardCards"]?["_items"];
foreach (var tile in tiles)
{
result.Add(tile);
}
}
return result.ToArray();
}
return result.ToArray();
}
}
}
2 changes: 1 addition & 1 deletion HDT_BGrank/BGrankPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void CreateMenuItem()

public Version Version
{
get { return new Version(1, 1, 7); }
get { return new Version(1, 1, 8); }
}

}
Expand Down
4 changes: 2 additions & 2 deletions HDT_BGrank/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.7")]
[assembly: AssemblyFileVersion("1.1.7")]
[assembly: AssemblyVersion("1.1.8")]
[assembly: AssemblyFileVersion("1.1.8")]

0 comments on commit c42f126

Please sign in to comment.