Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- materials = materials or {} local self = materials
- materials.Replaced = {}
- function materials.ReplaceTexture(path, to)
- check(path, "string")
- check(to, "string", "ITexture", "Material")
- path = path:lower()
- local mat = Material(path)
- if not mat:IsError() then
- local typ = type(to)
- local tex
- if typ == "string" then
- tex = Material(to):GetMaterialTexture("$basetexture")
- elseif typ == "ITexture" then
- tex = to
- elseif typ == "Material" then
- tex = to:GetMaterialTexture("$basetexture")
- else return false end
- self.Replaced[path] = self.Replaced[path] or {}
- self.Replaced[path].OldTexture = self.Replaced[path].OldTexture or mat:GetMaterialTexture("$basetexture")
- self.Replaced[path].NewTexture = tex
- mat:SetMaterialTexture("$basetexture",tex)
- return true
- end
- return false
- end
- function materials.SetColor(path, color)
- check(path, "string")
- check(color, "Vector")
- path = path:lower()
- local mat = Material(path)
- if not mat:IsError() then
- self.Replaced[path] = self.Replaced[path] or {}
- self.Replaced[path].OldColor = self.Replaced[path].OldColor or mat:GetMaterialVector("$color")
- self.Replaced[path].NewColor = color
- mat:SetMaterialVector("$color", color)
- return true
- end
- return false
- end
- function materials.RestoreAll()
- for name, tbl in pairs(self.Replaced) do
- if
- !pcall(function()
- if tbl.OldTexture then
- materials.ReplaceTexture(name, tbl.OldTexture)
- end
- if tbl.OldColor then
- materials.SetColor(name, tbl.OldColor)
- end
- end)
- then
- print("Failed to restore: " .. tostring(name))
- end
- end
- end
- hook.Add('ShutDown','MatRestorer',materials.RestoreAll)
Advertisement
Add Comment
Please, Sign In to add comment