local function wait_png(matstr) local html = vgui.Create("DHTML") html:AddFunction("console", "memeify", function() html.done = true end) local mat = Material(matstr) local rw, rh = mat:GetInt "$realwidth", mat:GetInt "$realheight" local f = file.Open("materials/"..matstr, "rb", "GAME") local cont = f:Read(f:Size()) f:Close() f = file.Open(matstr:gsub("/","_"), "wb", "DATA") f:Write(cont) f:Close() html:SetPos(ScrW() - 1, ScrH() - 1) local mapw, maph = 1, 1 while (mapw < rw) do mapw = mapw * 2 end while (maph < rh) do maph = maph * 2 end html:SetSize(mapw, maph) html:SetHTML([[ ]]) html:SetVisible(true) local co = love.__love_co local transplant = CreateMaterial("LoveEMU_"..rand.."transplant_png_"..png_count..matstr, "UnlitGeneric", { ["$translucent"] = 1, ["$nolod"] = 1, ["$ignorez"] = 1, ["$vertexalpha"] = 0, }) png_count = png_count + 1 love.__love_incallback = true local resume = function() love.__love_incallback = false love.__love_resume(co, transplant, rw, rh, mat) end hook.Add("Think", "LoveEMU_TransplantPNG", function() if (IsValid(html) and html.done and html:GetHTMLMaterial()) then local tex = html:GetHTMLMaterial():GetTexture "$basetexture" transplant:SetTexture("$basetexture", tex) tex:Download() html:Remove() -- lol fuck memory we can't destroy or reuse it local rt = GetRenderTargetEx("LoveEMU_"..rand.."transplant_rt_"..png_count..matstr, mapw, maph, RT_SIZE_NO_CHANGE, MATERIAL_RT_DEPTH_NONE, 1, CREATERENDERTARGETFLAGS_UNFILTERABLE_OK, IMAGE_FORMAT_RGBA8888) render.PushRenderTarget(rt) render.OverrideAlphaWriteEnable(true, true) cam.Start2D() render.Clear(0, 0, 0, 0, false, false) surface.SetMaterial(transplant) surface.SetDrawColor(255,255,255,255) surface.DrawTexturedRectUV(0, 0, rw, rh, 0, 0, rw / mapw, rh / maph) render.OverrideAlphaWriteEnable(true, false) file.Write("loveemu_pot_"..matstr:gsub("/","_"), render.Capture { format = "png", alpha = true, x = 0, y = 0, w = mapw, h = maph }) cam.End2D() mat = Material("data/loveemu_pot_"..matstr:gsub("/","_"), "noclamp") render.PopRenderTarget(rt) resume() end end) return love.__love_yield() end