-
Notifications
You must be signed in to change notification settings - Fork 132
/
DumpImages.lua
97 lines (76 loc) · 2.26 KB
/
DumpImages.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
import 'WzComparerR2.PluginBase'
import 'WzComparerR2.WzLib'
import 'System.IO'
import 'System.Xml'
------------------------------------------------------------
local function enumAllWzNodes(node)
return coroutine.wrap(function()
coroutine.yield(node)
for _,v in each(node.Nodes) do
for child in enumAllWzNodes(v) do
coroutine.yield(child)
end
end
end)
end
local function isPng(value)
if value and type(value) == "userdata" and value:GetType().Name == 'Wz_Png' then
return true
else
return false
end
end
local p = Path.GetInvalidFileNameChars()
local ivStr = ""
for i, v in each(p) do
if v >= 32 then
ivStr = ivStr .. string.char(v)
end
end
local ivPattern = "["..ivStr.."]"
------------------------------------------------------------
-- all variables
local topWzPath = 'Character'
local topNode = PluginManager.FindWz(topWzPath)
local outputDir = "D:\\wzDump"
------------------------------------------------------------
-- main function
if not topNode then
env:WriteLine('"{0}" not loaded.', topWzPath)
return
end
-- enum all wz_images
for n in enumAllWzNodes(topNode) do
local img = Wz_NodeExtension.GetNodeWzImage(n)
if img then
--extract wz image
env:WriteLine('(extract)'..(img.Name))
if img:TryExtract() then
local dir = outputDir.."\\"..(n.FullPathToFile)
local dirCreated = false
--find all png
for n2 in enumAllWzNodes(img.Node) do
local png = n2.Value
if isPng(png) and (png.Width>1 or png.Height>1) then
local fn = n2.FullPath:sub(img.Name:len()+2):gsub("\\", "."):gsub(ivPattern, "")
fn = Path.Combine(dir, fn .. ".png")
--ensure dir exists
if not dirCreated then
if not Directory.Exists(dir) then
Directory.CreateDirectory(dir)
end
dirCreated = true
end
--save as png
local bmp = png:ExtractPng()
bmp:Save(fn)
bmp:Dispose()
end
end
img:Unextract()
else --error
env:WriteLine((img.Name)..' extract failed.')
end --end extract
end -- end type validate
end -- end foreach
env:WriteLine('--------Done.---------')