-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBattlenet.lua
executable file
·128 lines (106 loc) · 3.78 KB
/
Battlenet.lua
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
118
119
120
121
122
123
124
125
126
127
128
--[[
@Author: NuzzyFutts
@Github: github.com/NuzzyFutts
@File: Battlenet
@input: {string} BNET_CONFIG_FILE_PATH - The path of the Battle.net config file
]]
function main(BNET_CONFIG_FILE_PATH)
local LIST_OF_GAMES = {prometheus="Pro",
destiny2="DST2",
heroes="Hero",
hs_beta="WTCG",
diablo3="D3",
wow="WoW",
s2="S2",
s1="S1",
viper="VIPR"--[[,
agent="PLACEHOLDER_FOR_WARCRAFT_3"]]}
local GAME_NAMES = {prometheus="Overwatch",
destiny2="Destiny 2",
heroes="Heroes of the Storm",
hs_beta="Hearthstone",
diablo3="Diablo 3",
wow="World of Warcraft",
s2="Starcraft 2",
s1="Starcraft",
viper="Call of Duty: Black Ops 4"--[[,
agent="Warcraft 3"]]}
local BANNER_URLS = {prometheus="http://us.blizzard.com/static/_images/lang/en-us/gamecard-games-overwatch.jpg",
destiny2="https://bnetproduct-a.akamaihd.net//ff5/c9fb7c865fa0eb80b1cacef42dd3cb1e-feature-07.png",
heroes="http://us.blizzard.com/static/_images/lang/en-us/gamecard-games-heroes.jpg",
hs_beta="http://us.blizzard.com/static/_images/games/hearthstone/gamecard-games-hearthstone-en.jpg",
diablo3="http://us.blizzard.com/static/_images/lang/en-us/gamecard-games-d3.jpg",
wow="http://us.blizzard.com/static/_images/lang/en-us/gamecard-games-wow.jpg",
s2="http://us.blizzard.com/static/_images/lang/en-us/gamecard-games-sc2.jpg",
s1="http://us.blizzard.com/static/_images/lang/en-us/gamecard-games-sc1.jpg",
viper="https://bnetproduct-a.akamaihd.net//38/c004e9ac19a5b157a01fbe1f07fc92f1-CODBO4-Bnet_Game-Shop_Feature_R1C1-640x360-20180413.png"--[[,
agent="http://us.blizzard.com/static/_images/lang/en-us/gamecard-games-war3.jpg"]]}
local function getInstalledGames()
local familyFile = io.open(BNET_CONFIG_FILE_PATH,"r")
local count = 0
local found = false
local level = 0
local start = nil
local count = 0
local entry = nil
local uid = nil
local games = {}
if familyFile then
for line in familyFile:lines() do
count = count + 1
if found or string.match(line,'^%s*"Games":%s*{') then
entry = string.match(line,'^%s*"([%w%p]+)": {')
if entry ~= nil and level == 1 and entry ~= "battle_net" and entry ~= "prometheus_test" then
table.insert(games, entry)
end
if string.match(line, "{") then
level = level + 1
end
if string.match(line, "}") then
level = level - 1
end
if not found then
found = true
start = count
end
if level == 0 and start ~= count then
break
end
end
end
familyFile:close()
else
--game family file not found file not found
debug("Error: Could not find/open the file 'battle.net.config'")
return nil
end
return games
end
local function finalizeGames(games)
local resultTable = {}
local currTable = {}
if games ~= nil then
for i=1, #games do
if LIST_OF_GAMES[games[i]] ~= nil and GAME_NAMES[games[i]] ~= nil and BANNER_URLS[games[i]] ~= nil then -- Check to see if we know about this game
currTable["appID"]= LIST_OF_GAMES[games[i]]
currTable["appName"] = GAME_NAMES[games[i]]
currTable["installed"] = true
currTable["hidden"] = false
currTable["lastPlayed"] = nil
currTable["appPath"] = "battlenet://"..LIST_OF_GAMES[games[i]]
currTable["bannerURL"] = BANNER_URLS[games[i]]
currTable["bannerName"] = LIST_OF_GAMES[games[i]]..".jpg" --TODO
currTable["launcher"] = "Battle.net"
table.insert(resultTable, currTable)
currTable = {}
else
debug(games[i].." is not known by the Battle.net plugin.")
end
end
end
return resultTable
end
local installedGames = getInstalledGames()
local final = finalizeGames(installedGames)
return final
end