Which is fastest way to get skill stack count?
AFAIK there is no direct way to read it from any THUD provided object like for example charges (or cooldowns).
I have used BuffRuleCalculator to read stack count for me.
For curiosity's sake I tested reading it "directly" from UI and it works.
Doing this requires you to register beforehand "stackcount" UI element you want to watch and to convert its contents to text when you "read" it.
I haven't done any performance analysis which method is faster as I'm afraid that it is hard to do.
If BuffRuleCalculator reads the stack count directly from memory it might be faster than using OCR to read text from UI element?
Assuming that IUiElement.ReadText() uses OCR as its parameters implies.
It seems that stack count is not straightforward to read from memory, otherwise we would have as an attribute in IPlayerSkill or IBuff like important attributes.
Code:
private bool firstTime = true;
private static string[] uiElementNames = new string[]
{
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_1",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_1.stackcount",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_2",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_2.stackcount",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_3",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_3.stackcount",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_4",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_skill_hotbar_4.stackcount",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_activeSkillLeft",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_activeSkillLeft.stackcount",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_activeSkillRight",
"Root.NormalLayer.game_dialog_backgroundScreenPC.game_activeSkillRight.stackcount",
};
private string checkForSomething()
{
if (firstTime)
{
firstTime = false;
var skill = 0;
for (var i = 0; i < uiElementNames.Length; i += 2) // Even elements are skill button IUiElement.
{
skill += 1;
var name = uiElementNames[i];
var uiElement = Hud.Render.GetUiElement(name);
if (uiElement != null)
{
Hud.Debug(string.Format("IUiElement {0} {1},{2}", name, uiElement.Rectangle.X, uiElement.Rectangle.Y));
var nameText = uiElementNames[i + 1];
Hud.Render.RegisterUiElement(nameText, uiElement, null);
Hud.Debug(string.Format("RegisterUiElement {0}", nameText));
}
if (skill == 4)
{
break;
}
skill += 1;
}
}
var builder = new StringBuilder("Stacks ");
for (var i = 1; i < uiElementNames.Length; i += 2) // Odd elements are skill button stack IUiElement.
{
var uiElement = Hud.Render.GetUiElement(uiElementNames[i]);
if (uiElement != null)
{
var text = uiElement.ReadText(Encoding.ASCII, removeColors: true);
if (text?.Length > 0)
{
builder.Append((i / 2) + 1).Append('=').Append(text).Append(' ');
}
}
}
return builder.ToString();
}