SneakySquid icon

catjpeg.lua

SneakySquid | PRO | 07/17/24 12:40:27 PM UTC (Edited) | 0 ⭐ | 1805 👁️ | Never ⏰ | []
Lua |

1.56 KB

|

None

|

0 👍

/

0 👎

local catjpeg = Material("catjpeg.jpg", "noclamp")
catjpeg = catjpeg:GetTexture("$basetexture")
 
local function GetStaticProps()
    local static_props = {}
 
    local map = string.format("maps/%s.bsp", game.GetMap())
    local fl = file.Open(map, "rb", "GAME")
 
    fl:Seek(568)
 
    local lump_data = {
        data = {},
        fileofs = fl:ReadLong(),
        filelen = fl:ReadLong(),
        version = fl:ReadLong(),
        fourCC = fl:Read(4),
    }
 
    fl:Seek(lump_data.fileofs)
 
    for i = 1, fl:ReadLong() do
        lump_data.data[i] = {
            id = fl:Read(4),
            flags = fl:ReadShort(),
            version = fl:ReadShort(),
            fileofs = fl:ReadLong(),
            filelen = fl:ReadLong(),
        }
    end
 
    for _, lump in ipairs(lump_data.data) do
        fl:Seek(lump.fileofs)
 
        for i = 1, fl:ReadLong() do
            local mdl = fl:Read(128)
            mdl = string.match(mdl, "^[%Z]+")
 
            if (mdl) then
                table.insert(static_props, mdl)
            end
        end
    end
 
    fl:Close()
 
    return static_props
end
 
do
    local brushes = Entity(0):GetBrushSurfaces()
 
    for i, surfaceinfo in ipairs(brushes) do
        if (surfaceinfo:IsWater() or surfaceinfo:IsSky()) then continue end
 
        local mat = surfaceinfo:GetMaterial()
        mat:SetTexture("$basetexture", catjpeg)
        mat:SetTexture("$basetexture2", catjpeg)
    end
end
 
do
    local props = GetStaticProps()
    local ent = ClientsideModel("error")
 
    for i, mdl in ipairs(props) do
        ent:SetModel(mdl)
 
        for _, mat in ipairs(ent:GetMaterials()) do
            mat = Material(mat)
            mat:SetTexture("$basetexture", catjpeg)
            mat:SetTexture("$basetexture2", catjpeg)
        end
    end
 
    ent:Remove()
end

Comments