--[[ | This file was obtained through the combined efforts | of Madbluntz & Plymouth Antiquarian Society. | | Credits: lifestorm, Gregory Wayne Rossel JR., | Maloy, DrPepper10 @ RIP, Atle! | | Visit for more: https://plymouth.thetwilightzone.ru/ --]] local urltex = {} urltex.TextureSize = 1024 urltex.ActivePanel = urltex.ActivePanel or NULL urltex.Queue = urltex.Queue or {} urltex.Cache = urltex.Cache or {} concommand.Add("pac_urltex_clear_cache", function() urltex.Cache = {} urltex.Queue = {} end) if urltex.ActivePanel:IsValid() then urltex.ActivePanel:Remove() end local enable = CreateClientConVar("pac_enable_urltex", "1", true) local EMPTY_FUNC = function() end local function findFlag(url, flagID) local startPos, endPos = url:find(flagID) if not startPos then return url, false end if url:sub(endPos + 1, endPos + 1) == ' ' or url:sub(startPos - 1, startPos - 1) == ' ' then url = url:gsub(' ?' .. flagID .. ' ?', '') return url, true end return url, false end function urltex.GetMaterialFromURL(url, callback, skip_cache, shader, size, size_hack, additionalData) if size_hack == nil then size_hack = true end additionalData = additionalData or {} shader = shader or "VertexLitGeneric" if not enable:GetBool() then return end local noclampS, noclamp, noclampT url, noclampS = findFlag(url, 'noclamps') url, noclampT = findFlag(url, 'noclampt') url, noclamp = findFlag(url, 'noclamp') local urlAddress = url local urlIndex = url if noclamp then urlIndex = urlIndex .. ' noclamp' elseif noclampS then urlIndex = urlIndex .. ' noclampS' elseif noclampT then urlIndex = urlIndex .. ' noclampT' end noclamp = noclamp or noclampS and noclampT local renderTargetNeeded = noclampS or noclamp or noclampT if isfunction(callback) and not skip_cache and urltex.Cache[urlIndex] then local tex = urltex.Cache[urlIndex] local mat = CreateMaterial("pac3_urltex_" .. pac.Hash(), shader, additionalData) mat:SetTexture("$basetexture", tex) callback(mat, tex) return end callback = callback or EMPTY_FUNC if urltex.Queue[urlIndex] then table.insert(urltex.Queue[urlIndex].callbacks, callback) else urltex.Queue[urlIndex] = { url = urlAddress, urlIndex = urlIndex, callbacks = {callback}, tries = 0, size = size, size_hack = size_hack, shader = shader, noclampS = noclampS, noclampT = noclampT, noclamp = noclamp, rt = renderTargetNeeded, additionalData = additionalData } end end function urltex.Think() if not pac.IsEnabled() then return end if table.Count(urltex.Queue) > 0 then for url, data in pairs(urltex.Queue) do -- when the panel is gone start a new one if not urltex.ActivePanel:IsValid() then urltex.StartDownload(data.url, data) end end urltex.Busy = true else urltex.Busy = false end end timer.Create("urltex_queue", 0.1, 0, urltex.Think) function urltex.StartDownload(url, data) if urltex.ActivePanel:IsValid() then urltex.ActivePanel:Remove() end url = pac.FixUrl(url) local size = tonumber(data.size or urltex.TextureSize) local id = "urltex_download_" .. url local pnl local frames_passed = 0 local function createDownloadPanel() pnl = vgui.Create("DHTML") -- Tested in PPM/2, this code works perfectly pnl:SetVisible(false) pnl:SetSize(size, size) pnl:SetHTML([[