Add support for registering .COL libraries
This commit is contained in:
parent
834c296278
commit
93d125ff2d
|
@ -4,6 +4,7 @@ objectsToPlace = {}
|
||||||
objectRegister = {}
|
objectRegister = {}
|
||||||
modelRegister = {}
|
modelRegister = {}
|
||||||
textureRegister = {}
|
textureRegister = {}
|
||||||
|
collisionRegister = {}
|
||||||
blacklistObjects = {}
|
blacklistObjects = {}
|
||||||
-- Blacklist for SanVice:
|
-- Blacklist for SanVice:
|
||||||
-- blacklistObjects[7479] = true
|
-- blacklistObjects[7479] = true
|
||||||
|
@ -24,6 +25,18 @@ logpath = "log.txt"
|
||||||
if fileExists(logpath) then fileDelete(logpath) end
|
if fileExists(logpath) then fileDelete(logpath) end
|
||||||
logfile = fileCreate(logpath)
|
logfile = fileCreate(logpath)
|
||||||
|
|
||||||
|
function registerCollisionArchive(path)
|
||||||
|
cols = engineGetCOLsFromLibrary(path)
|
||||||
|
for colName,colData in pairs(cols) do
|
||||||
|
colNameStd = string.lower(colName)
|
||||||
|
if collisionRegister[colNameStd] == nil then
|
||||||
|
collisionRegister[colNameStd] = engineLoadCOL(colData)
|
||||||
|
else
|
||||||
|
outputChatBox("Warning: Duplicate collision: " ..colName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function displayStatus(text)
|
function displayStatus(text)
|
||||||
if debugToggle == false then return end
|
if debugToggle == false then return end
|
||||||
x,y = guiGetScreenSize()
|
x,y = guiGetScreenSize()
|
||||||
|
@ -41,26 +54,37 @@ function registerObject(...) -- id,model,texture,drawDistance
|
||||||
end
|
end
|
||||||
|
|
||||||
function registerObjectNow(id,model,texture,drawDistance)
|
function registerObjectNow(id,model,texture,drawDistance)
|
||||||
|
modelStd = string.lower(model)
|
||||||
|
textureStd = string.lower(texture)
|
||||||
|
|
||||||
if blacklistObjects[id] then
|
if blacklistObjects[id] then
|
||||||
debugWrite("Skipping object " ..tostring(id).. " (" ..texture.. " + " ..model.. ") - Blacklisted.\n")
|
debugWrite("Skipping object " ..tostring(id).. " (" ..texture.. " + " ..model.. ") - Blacklisted.\n")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if textureRegister[texture] == nil then
|
|
||||||
|
if textureRegister[textureStd] == nil then
|
||||||
debugWrite("Loading texture: " ..texture.. "\n")
|
debugWrite("Loading texture: " ..texture.. "\n")
|
||||||
textureRegister[texture] = engineLoadTXD(texture)
|
textureRegister[textureStd] = engineLoadTXD("img/" ..texture.. ".txd")
|
||||||
end
|
end
|
||||||
|
|
||||||
if modelRegister[model] == nil then
|
if modelRegister[modelStd] == nil then
|
||||||
debugWrite("Loading model: " ..model.. "\n")
|
debugWrite("Loading model: " ..model.. "\n")
|
||||||
modelRegister[model] = engineLoadDFF(model)
|
modelRegister[modelStd] = engineLoadDFF("img/" ..model.. ".dff")
|
||||||
end
|
end
|
||||||
|
|
||||||
realID = engineRequestModel("object",10768)
|
realID = engineRequestModel("object",10768)
|
||||||
debugWrite("Making object " ..tostring(id).. ": " ..texture.. " + " ..model.. " = " ..tostring(realID).. "\n")
|
debugWrite("Making object " ..tostring(id).. ": " ..texture.. " + " ..model.. " = " ..tostring(realID).. "\n")
|
||||||
engineImportTXD(textureRegister[texture],realID)
|
colAvailable = false
|
||||||
engineReplaceModel(modelRegister[model],realID)
|
if collisionRegister[modelStd] ~= nil then
|
||||||
|
engineReplaceCOL(collisionRegister[modelStd],realID)
|
||||||
|
colAvailable = true
|
||||||
|
end
|
||||||
|
engineImportTXD(textureRegister[textureStd],realID)
|
||||||
|
engineReplaceModel(modelRegister[modelStd],realID)
|
||||||
engineSetModelLODDistance(realID,drawDistance)
|
engineSetModelLODDistance(realID,drawDistance)
|
||||||
objectRegister[id] = realID
|
objectRegister[id] = {}
|
||||||
|
objectRegister[id]["realID"] = realID
|
||||||
|
objectRegister[id]["colAvailable"] = colAvailable
|
||||||
|
|
||||||
if tempObj then
|
if tempObj then
|
||||||
destroyElement(tempObj)
|
destroyElement(tempObj)
|
||||||
|
@ -82,9 +106,11 @@ end
|
||||||
function placeObjectNow(id,interior,x,y,z,rx,ry,rz,rw,lod)
|
function placeObjectNow(id,interior,x,y,z,rx,ry,rz,rw,lod)
|
||||||
if objectRegister[id] == nil then return end
|
if objectRegister[id] == nil then return end
|
||||||
erx,ery,erz = fromQuaternion(rx,ry,rz,rw)
|
erx,ery,erz = fromQuaternion(rx,ry,rz,rw)
|
||||||
obj = createObject(objectRegister[id],x,y + 6000,z,erx,ery,erz)
|
obj = createObject(objectRegister[id]["realID"],x,y + 6000,z,erx,ery,erz)
|
||||||
setElementInterior(obj,interior)
|
setElementInterior(obj,interior)
|
||||||
setElementCollisionsEnabled(obj,false)
|
if not objectRegister[id]["colAvailable"] then
|
||||||
|
setElementCollisionsEnabled(obj,false)
|
||||||
|
end
|
||||||
displayStatus("Placed model: " ..tostring(id).. ", " ..tostring(#objectsToPlace).. " remaining...")
|
displayStatus("Placed model: " ..tostring(id).. ", " ..tostring(#objectsToPlace).. " remaining...")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -124,8 +150,8 @@ addEventHandler("onClientRender",root,handleLoading)
|
||||||
|
|
||||||
addEventHandler("onClientResourceStop",root,function(res)
|
addEventHandler("onClientResourceStop",root,function(res)
|
||||||
if res == resource then
|
if res == resource then
|
||||||
for _,value in pairs(objectRegister) do
|
for key,_ in pairs(objectRegister) do
|
||||||
engineFreeModel(value)
|
engineFreeModel(objectRegister[key]["realID"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
|
@ -0,0 +1,34 @@
|
||||||
|
-- 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
|
|
@ -185,6 +185,7 @@ def main():
|
||||||
fileMeta.write("<meta>\n")
|
fileMeta.write("<meta>\n")
|
||||||
fileMeta.write('<info author="unknown" version="1.0.0" name="' +pathOut.rsplit(os.path.sep,1)[-1]+ '"/>\n')
|
fileMeta.write('<info author="unknown" version="1.0.0" name="' +pathOut.rsplit(os.path.sep,1)[-1]+ '"/>\n')
|
||||||
fileMeta.write('<download_priority_group>-1</download_priority_group>\n')
|
fileMeta.write('<download_priority_group>-1</download_priority_group>\n')
|
||||||
|
fileMeta.write('<script src="col.lua" type="client"/>\n')
|
||||||
fileMeta.write('<script src="quaternion.lua" type="client"/>\n')
|
fileMeta.write('<script src="quaternion.lua" type="client"/>\n')
|
||||||
fileMeta.write('<script src="client.lua" type="client"/>\n')
|
fileMeta.write('<script src="client.lua" type="client"/>\n')
|
||||||
for ide in data["ide"]:
|
for ide in data["ide"]:
|
||||||
|
@ -221,7 +222,7 @@ def main():
|
||||||
if section == "objs":
|
if section == "objs":
|
||||||
for element in data["ide"][ide][section]:
|
for element in data["ide"][ide][section]:
|
||||||
if not element["id"] in objectIDs: continue
|
if not element["id"] in objectIDs: continue
|
||||||
fileIde.write('registerObject(' +element["id"]+ ',"img/' +element["modelName"]+ '.dff","img/' +element["textureName"]+ '.txd",' +element["drawDistances"][0]+ ')\n')
|
fileIde.write('registerObject(' +element["id"]+ ',"' +element["modelName"]+ '","' +element["textureName"]+ '",' +element["drawDistances"][0]+ ')\n')
|
||||||
|
|
||||||
if not element["modelName"] in modelNames:
|
if not element["modelName"] in modelNames:
|
||||||
fileMeta.write('<file src="img/' +element["modelName"]+ '.dff"/>\n')
|
fileMeta.write('<file src="img/' +element["modelName"]+ '.dff"/>\n')
|
||||||
|
|
Loading…
Reference in New Issue