1filename = nil
2loaded = false
3loadedPaths = nil
4
5function setFileName(name)
6 filename = name
7end
8
9function isLoaded()
10 return loaded
11end
12
13function load()
14 local version = g_game.getClientVersion()
15 local things = g_settings.getNode('things')
16 g_game.enableFeature(GameBlueNpcNameColor)
17 g_game.enableFeature(GameSpritesAlphaChannel)
18 g_game.enableFeature(GameChangeMapAwareRange)
19 g_game.enableFeature(GameSpritesU32)
20
21 local datPath, sprPath
22 if things["data"] ~= nil and things["sprites"] ~= nil then
23 datPath = '/things/' .. things["data"]
24 if G.hdSprites and things["sprites_hd"] then
25 sprPath = '/things/' .. things["sprites_hd"]
26 else
27 sprPath = '/things/' .. things["sprites"]
28 end
29 else
30 if filename then
31 datPath = resolvepath('/things/' .. filename)
32 sprPath = resolvepath('/things/' .. filename)
33 if G.hdSprites then
34 local hdsprPath = resolvepath('/things/' .. filename .. '_hd')
35 if g_resources.fileExists(hdsprPath) then
36 sprPath = hdsprPath
37 end
38 end
39 else
40 datPath = resolvepath('/things/' .. version .. '/Tibia')
41 sprPath = resolvepath('/things/' .. version .. '/Tibia')
42 if G.hdSprites then
43 local hdsprPath = resolvepath('/things/' .. version .. '/Tibia_hd')
44 if g_resources.fileExists(hdsprPath) then
45 sprPath = hdsprPath
46 end
47 end
48 end
49 if g_sounds then
50 g_sounds.loadClientFiles(resolvepath(string.format('/sounds/%d/', version)))
51 end
52 return
53 end
54
55 local paths = datPath .. '|' .. sprPath
56 if loaded and loadedPaths == paths then
57 return
58 end
59
60 local errorMessage = ''
61 if not g_things.loadDat(datPath) then
62 if not g_game.getFeature(GameSpritesU32) then
63 g_game.enableFeature(GameSpritesU32)
64 if not g_things.loadDat(datPath) then
65 errorMessage = errorMessage .. tr("Unable to load dat file, please place a valid dat in '%s'", datPath) .. '\n'
66 end
67 else
68 errorMessage = errorMessage .. tr("Unable to load dat file, please place a valid dat in '%s'", datPath) .. '\n'
69 end
70 end
71 if not g_sprites.loadSpr(sprPath, G.hdSprites or false) then
72 errorMessage = errorMessage .. tr("Unable to load spr file, please place a valid spr in '%s'", sprPath)
73 end
74
75 loaded = (errorMessage:len() == 0)
76 loadedPaths = loaded and paths or nil
77
78 if errorMessage:len() > 0 then
79 local messageBox = displayErrorBox(tr('Error'), errorMessage)
80 addEvent(function() messageBox:raise() messageBox:focus() end)
81
82 g_game.setClientVersion(0)
83 g_game.setProtocolVersion(0)
84 end
85end
86