forked from ThornyFFXI/tCrossBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexturecache.lua
More file actions
113 lines (100 loc) · 3.76 KB
/
texturecache.lua
File metadata and controls
113 lines (100 loc) · 3.76 KB
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
local d3d8 = require('d3d8');
local d3d8_device = d3d8.get_device();
local ffi = require('ffi');
local TextureCache = {};
TextureCache.ItemCache = {};
TextureCache.ImageCache = {};
TextureCache.StatusCache = {};
function TextureCache:Clear()
self.ItemCache = {};
self.ImageCache = {};
self.StatusCache = {};
end
function TextureCache:GetTexture(file)
if (string.sub(file, 1, 5) == 'ITEM:') then
local itemId = tonumber(string.sub(file, 6));
if type(itemId) ~= 'number' then
return;
end
local tx = self.ItemCache[itemId]
if tx then
return tx;
end
local item = AshitaCore:GetResourceManager():GetItemById(itemId);
if (item == nil) then
return;
end
local dx_texture_ptr = ffi.new('IDirect3DTexture8*[1]');
local size = -1;
if (ashita.interface_version == nil) then
size = item.ImageSize;
end
if (ffi.C.D3DXCreateTextureFromFileInMemoryEx(d3d8_device, item.Bitmap, size, 0xFFFFFFFF, 0xFFFFFFFF, 1, 0, ffi.C.D3DFMT_A8R8G8B8, ffi.C.D3DPOOL_MANAGED, ffi.C.D3DX_DEFAULT, ffi.C.D3DX_DEFAULT, 0xFF000000, nil, nil, dx_texture_ptr) == ffi.C.S_OK) then
local texture = d3d8.gc_safe_release(ffi.cast('IDirect3DTexture8*', dx_texture_ptr[0]));
local result, desc = texture:GetLevelDesc(0);
if result == 0 then
tx = {};
tx.Texture = texture;
tx.Width = desc.Width;
tx.Height = desc.Height;
self.ItemCache[itemId] = tx;
return tx;
end
return;
end
end
if (string.sub(file, 1, 7) == 'STATUS:') then
local statusId = tonumber(string.sub(file, 8));
if type(statusId) ~= 'number' then
return;
end
local tx = self.StatusCache[statusId]
if tx then
return tx;
end
local status = AshitaCore:GetResourceManager():GetStatusIconByIndex(statusId);
if (status == nil) then
return;
end
local dx_texture_ptr = ffi.new('IDirect3DTexture8*[1]');
local size = -1;
if (ashita.interface_version == nil) then
size = status.ImageSize;
end
if (ffi.C.D3DXCreateTextureFromFileInMemoryEx(d3d8_device, status.Bitmap, size, 0xFFFFFFFF, 0xFFFFFFFF, 1, 0, ffi.C.D3DFMT_A8R8G8B8, ffi.C.D3DPOOL_MANAGED, ffi.C.D3DX_DEFAULT, ffi.C.D3DX_DEFAULT, 0xFF000000, nil, nil, dx_texture_ptr) == ffi.C.S_OK) then
local texture = d3d8.gc_safe_release(ffi.cast('IDirect3DTexture8*', dx_texture_ptr[0]));
local result, desc = texture:GetLevelDesc(0);
if result == 0 then
tx = {};
tx.Texture = texture;
tx.Width = desc.Width;
tx.Height = desc.Height;
self.StatusCache[statusId] = tx;
return tx;
end
return;
end
end
local tx = self.ImageCache[file];
if tx then
return tx;
end
local path = GetImagePath(file);
if (path ~= nil) then
local dx_texture_ptr = ffi.new('IDirect3DTexture8*[1]');
if (ffi.C.D3DXCreateTextureFromFileA(d3d8_device, path, dx_texture_ptr) == ffi.C.S_OK) then
local texture = d3d8.gc_safe_release(ffi.cast('IDirect3DTexture8*', dx_texture_ptr[0]));
local result, desc = texture:GetLevelDesc(0);
if result == 0 then
tx = {};
tx.Texture = texture;
tx.Width = desc.Width;
tx.Height = desc.Height;
self.ImageCache[file] = tx;
return tx;
end
return;
end
end
end
return TextureCache;