Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Only mostly shitty MSC ASTC exporter.
- -- Repackages the texture data into Unity
- -- CABs so's AssetStudio can parse it.
- -- Processes all files and subfolders it can find.
- -- *.png / *.jpg / *.tga will end up with *.cab next to them.
- require "lfs"
- local function processImg(infile, entry)
- local input = io.open("c281abfcf2c9ab349a5adca88b286ec0", "rb")
- local output = io.open(infile:sub(1, #infile - 3) .. "cab", "wb")
- output:write(input:read(4096))
- if #entry > 12 then entry = entry:sub(1, 12) end
- if #entry < 12 then entry = entry .. string.rep(" ", 12 - #entry) end
- output:write("\12\00\00\00" .. entry)
- input:read(16)
- output:write(input:read(8))
- local input2 = io.open(infile, "rb")
- local size = lfs.attributes(infile).size - 16
- input2:read(4)
- local texType = 44 + input2:read(1):byte()
- input2:read(2)
- local wB = input2:read(2)
- local width = wB:byte(1) + wB:byte(2) * 256
- input2:read(1)
- local hB = input2:read(2)
- local height = hB:byte(1) + hB:byte(2) * 256
- input2:read(4)
- output:write(wB .. "\0\0" .. hB .. "\0\0")
- input:read(8)
- --[[
- 0x30 48 ASTC_4x4 ASTC (4x4 pixel block in 128 bits) compressed RGB(A) texture format.
- 0x31 49 ASTC_5x5 ASTC (5x5 pixel block in 128 bits) compressed RGB(A) texture format.
- 0x32 50 ASTC_6x6 ASTC (6x6 pixel block in 128 bits) compressed RGB(A) texture format.
- ASTC_8x8 ASTC (8x8 pixel block in 128 bits) compressed RGB(A) texture format.
- ASTC_10x10 ASTC (10x10 pixel block in 128 bits) compressed RGB(A) texture format.
- ASTC_12x12 ASTC (12x12 pixel block in 128 bits) compressed RGB(A) texture format.
- ]]--
- output:write(input:read(4) .. string.char(texType))
- input:read(1)
- output:write(input:read(59))
- input:read(size)
- output:write(input2:read(size))
- output:write(input:read(4198508) or "something fucked up here")
- input:close()
- input2:close()
- output:close()
- end
- local function scanDir(dir)
- for entry in lfs.dir(dir) do if entry ~= "." and entry ~= ".." then
- local attrib = lfs.attributes(dir .. "/" .. entry)
- local ext = entry:sub(-3):lower()
- if not attrib then print("Failed to access attribute data for " .. dir .. "/" .. entry) end
- if attrib.mode == "directory" then
- scanDir(dir .. "/" .. entry)
- elseif ext == "png" or ext == "jpg" or ext == "tga" or ext == "bmp" then
- processImg(dir .. "/" .. entry, entry:sub(1, #entry - 4))
- end
- end end
- end
- return scanDir(lfs.currentdir())
Add Comment
Please, Sign In to add comment