Advertisement
SneakySquid

catjpeg.lua

May 4th, 2020
1,529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local catjpeg = Material("catjpeg.jpg", "noclamp")
  2. catjpeg = catjpeg:GetTexture("$basetexture")
  3.  
  4. local function GetStaticProps()
  5.     local static_props = {}
  6.  
  7.     local map = string.format("maps/%s.bsp", game.GetMap())
  8.     local fl = file.Open(map, "rb", "GAME")
  9.  
  10.     fl:Seek(568)
  11.  
  12.     local lump_data = {
  13.         data = {},
  14.         fileofs = fl:ReadLong(),
  15.         filelen = fl:ReadLong(),
  16.         version = fl:ReadLong(),
  17.         fourCC = fl:Read(4),
  18.     }
  19.  
  20.     fl:Seek(lump_data.fileofs)
  21.  
  22.     for i = 1, fl:ReadLong() do
  23.         lump_data.data[i] = {
  24.             id = fl:Read(4),
  25.             flags = fl:ReadShort(),
  26.             version = fl:ReadShort(),
  27.             fileofs = fl:ReadLong(),
  28.             filelen = fl:ReadLong(),
  29.         }
  30.     end
  31.  
  32.     for _, lump in ipairs(lump_data.data) do
  33.         fl:Seek(lump.fileofs)
  34.  
  35.         for i = 1, fl:ReadLong() do
  36.             local mdl = fl:Read(128)
  37.             mdl = string.match(mdl, "^[%Z]+")
  38.  
  39.             if (mdl) then
  40.                 table.insert(static_props, mdl)
  41.             end
  42.         end
  43.     end
  44.  
  45.     fl:Close()
  46.  
  47.     return static_props
  48. end
  49.  
  50. do
  51.     local brushes = Entity(0):GetBrushSurfaces()
  52.  
  53.     for i, surfaceinfo in ipairs(brushes) do
  54.         if (surfaceinfo:IsWater() or surfaceinfo:IsSky()) then continue end
  55.  
  56.         local mat = surfaceinfo:GetMaterial()
  57.         mat:SetTexture("$basetexture", catjpeg)
  58.         mat:SetTexture("$basetexture2", catjpeg)
  59.     end
  60. end
  61.  
  62. do
  63.     local props = GetStaticProps()
  64.     local ent = ClientsideModel("error")
  65.  
  66.     for i, mdl in ipairs(props) do
  67.         ent:SetModel(mdl)
  68.  
  69.         for _, mat in ipairs(ent:GetMaterials()) do
  70.             mat = Material(mat)
  71.             mat:SetTexture("$basetexture", catjpeg)
  72.             mat:SetTexture("$basetexture2", catjpeg)
  73.         end
  74.     end
  75.  
  76.     ent:Remove()
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement