/
Toolbox.cs
117 lines (108 loc) · 4.09 KB
/
Toolbox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using robotManager.Products;
using System.Diagnostics;
using System.Threading;
using WholesomeToolbox;
using wManager.Wow.Helpers;
public class ToolBox
{
public static int ParseInt(string str)
{
if (str != null && int.TryParse(str, out int val))
{
return val;
}
else
{
Logger.LogError($"ERROR: Unable to parse {str}");
return 0;
}
}
public static void Restart()
{
new Thread(() =>
{
Products.ProductStop();
Sleep(2000);
Products.ProductStart();
}).Start();
}
public static WoWVersion GetWoWVersion()
{
string version = WTLua.GetWoWVersion;
if (version == "2.4.3")
return WoWVersion.TBC;
else
return WoWVersion.WOTLK;
}
public static void Sleep(int milliseconds)
{
int latency = Lua.LuaDoString<int>($@"
local result = 0;
local _, _, lagHome, lagWorld = GetNetStats();
if lagHome ~= nil then result = result + lagHome end;
if lagWorld ~= nil then result = result + lagWorld end;
return result;
");
Thread.Sleep(latency + milliseconds);
}
public enum WoWVersion
{
VANILLA,
TBC,
WOTLK
}
public static void PrintLuaTime(string suffix)
{
Lua.LuaDoString($@"DEFAULT_CHAT_FRAME:AddMessage(""{suffix} "" .. date(""%H:%M:%S""));");
}
public static void LUASetup()
{
// Create function to read invisible tooltip lines
Lua.LuaDoString($@"
if (WEquipTooltip == nil) then
CreateFrame(""GAMETOOLTIP"", ""WEquipTooltip"");
local L = L or WEquipTooltip: CreateFontString();
local R = R or WEquipTooltip: CreateFontString();
L: SetFontObject(GameFontNormal);
R: SetFontObject(GameFontNormal);
WEquipTooltip: AddFontStrings(L, R);
WEquipTooltip: SetOwner(WorldFrame, ""ANCHOR_NONE"");
end
if (EnumerateTooltipLines == nil) then
function EnumerateTooltipLines(...)
local result = """"
for i = 1, select(""#"", ...) do
local region = select(i, ...)
if region and region:GetObjectType() == ""FontString"" then
local text = region:GetText() or """"
if text ~= """" then
result = result .. ""|"" .. text
end
end
end
return result
end
end
if (ParseItemInfo == nil) then
function ParseItemInfo(i, j, paramItemLink)
WEquipTooltip:ClearLines();
WEquipTooltip:SetHyperlink(paramItemLink);
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType,
itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(paramItemLink);
local texture, count, locked, quality, readable, lootable, link = GetContainerItemInfo(i, j);
if (count == null) then
count = 1;
end
if (itemSellPrice == null) then
itemSellPrice = 0;
end
if (itemEquipLoc == null) then
itemEquipLoc = '';
end
return table.concat({{ i, j, itemLink, itemName, itemRarity, itemLevel, itemMinLevel, itemType,
itemSubType, itemStackCount, itemEquipLoc, itemSellPrice, count, EnumerateTooltipLines(WEquipTooltip: GetRegions()) }}, ""£"");
end
end
");
}
}