Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setfenv(1, _G)
- local function to_markup(str)
- local current_tag
- local current_string
- local markup = {}
- local found_tag = false
- for char in tostring(str):gmatch("(.)") do
- if char == "<" then
- current_tag = {}
- if current_string then
- table.insert(markup, {type = "text", text = table.concat(current_string, "")})
- current_string = nil
- end
- end
- if current_tag then
- table.insert(current_tag, char)
- if char == ">" then
- local tag, args = table.concat(current_tag):match("<(%l-)=(.+)>")
- if tag and args then
- args = args:Split(",")
- table.insert(markup, {type = "tag", tag = tag, args = args})
- end
- current_tag = nil
- found_tag = true
- end
- else
- current_string = current_string or {}
- table.insert(current_string, char)
- end
- end
- if current_string then
- table.insert(markup, {type = "text", text = table.concat(current_string, "")})
- current_string = nil
- end
- if found_tag then
- return markup
- end
- end
- local function GetMaterialFromURL(url, size)
- local mat = CreateMaterial("fishing_hud_rc_" .. util.CRC(url) .. "_" .. FrameNumber(), "UnlitGeneric", {})
- pac.urltex.GetMaterialFromURL(url, function(_mat)
- mat:SetTexture("$basetexture", _mat:GetTexture("$basetexture"))
- end, nil, "UnlitGeneric", size, false)
- mat:SetFloat("$alpha", 0.999)
- return mat
- end
- old_drawtext = old_drawtext or surface.DrawText local old_drawtext = old_drawtext
- old_settextpos = old_settextpos or surface.SetTextPos local old_settextpos = old_settextpos
- old_settextcolor = old_settextcolor or surface.SetTextColor local old_settextcolor = old_settextcolor
- local X, Y = 0, 0
- local R, G, B, A = 0, 0 ,0 ,0
- function surface.SetTextColor(r, g, b, a)
- if type(r) == "table" then
- g = r.g
- b = r.b
- a = r.a
- r = r.r
- end
- R = r
- G = g
- B = b
- A = a
- return old_settextcolor(r, g, b ,a)
- end
- function surface.SetTextPos(x, y)
- X = x
- Y = y
- return old_settextpos(x, y)
- end
- local old_x, old_y, old_r, old_g, old_b, old_a
- local cache = {}
- function surface.DrawText(str)
- local markup = cache[str]
- if not markup then
- markup = to_markup(str) or true
- cache[str] = markup
- end
- if markup and markup ~= true then
- -- umm
- markup.env = markup.env or {}
- local w = 0
- old_x = X
- old_y = Y
- old_r = R
- old_g = G
- old_b = B
- old_a = A
- for key, data in pairs(markup) do
- if data.type == "text" then
- old_settextpos(X + w, Y)
- old_drawtext(data.text)
- w = w + surface.GetTextSize(data.text)
- elseif data.type == "tag" then
- if data.tag == "color" then
- old_settextcolor(
- tonumber(data.args[1]) or R,
- tonumber(data.args[2]) or G,
- tonumber(data.args[3]) or B,
- tonumber(data.args[4]) or A
- )
- elseif data.tag == "texture" then
- if not data.mat then
- if data.args[1]:find("http") then
- data.mat = GetMaterialFromURL(data.args[1], 128)
- else
- local mat = Material(data.args[1])
- local shader = mat:GetShader()
- if shader == "VertexLitGeneric" or shader == "Cable" then
- local tex_path = mat:GetString("$basetexture")
- if tex_path then
- local params = {}
- params["$basetexture"] = tex_path
- params["$vertexcolor"] = 1
- params["$vertexalpha"] = 1
- mat = CreateMaterial("markup_fixmat_" .. tex_path .. os.clock(), "UnlitGeneric", params)
- end
- end
- data.mat = mat
- end
- else
- local _, h = surface.GetTextSize(str)
- local mult = tonumber(data.args[2])
- if mult then
- h = h * mult
- end
- surface.SetDrawColor(255, 255, 255, 255)
- surface.SetMaterial(data.mat)
- surface.DrawTexturedRect(X + w + 4, Y, h, h)
- w = w + h + 8
- end
- end
- end
- end
- if old_x then
- old_settextpos(old_x, old_y)
- end
- if old_r then
- old_settextcolor(old_r, old_g, old_b, old_a)
- end
- return
- end
- return old_drawtext(str)
- end
- chat.AddText("LOLOLOL<texture=http://images.wikia.com/uncyclopedia/images/8/80/Smiley.png><color=2,55,52>LOLOLOLOL")
Advertisement
Add Comment
Please, Sign In to add comment