SA2MTA/baseResource/col.lua

34 lines
925 B
Lua

-- Author: thisdp
-- Source: https://wiki.multitheftauto.com/wiki/EngineGetCOLsFromLibrary
local matchedCOLVer = {
COLL = "COLL",
COL2 = "COL2",
COL3 = "COL3",
}
function engineGetCOLsFromLibrary(file)
assert(type(file) == "string","Bad argument @'engineGetCOLsFromLibrary' expected a string at argument 1, got "..type(file))
if fileExists(file) then --COL Library
local f = fileOpen(file)
local str = fileRead(f,fileGetSize(f))
fileClose(f)
return engineGetCOLsFromLibrary(str)
else
local cols = {}
while true do
local colVer = file:sub(1,4)
if matchedCOLVer[colVer] then
local a,b,c,d = file:byte(5,8)
local colSize = a+b*0x100+c*0x10000+d*0x1000000
local col = file:sub(1,colSize+8)
local colName = col:sub(9,29)
local zeroPoint = colName:find("\0")
cols[colName:sub(1,zeroPoint-1)] = col
file = file:sub(colSize+9)
else
break
end
end
return cols
end
end