-- paradox note: https://pastebin.com/NBAiQpJU
-- paradox note 2: All the shit-cheat posts are private. Sucks since I'm missing some of them.

local data = {
	{
		filename = "shitcheat_7.4_to_7.5_changelog.txt",
		url = "https://pastebin.com/raw/NiRzmgMb",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_7.5.lua",
		url = "https://pastebin.com/raw/3EtBW4rT",
		version = "7.5",
		changelog = "shitcheat_7.4_to_7.5_changelog.txt",
		executable = true,
	},
	{
		name = "Niggermenu",
		filename = "gmod_leak_dump_part_15__niggermenu.lua",
		url = "https://pastebin.com/raw/4ufXyHSQ",
		version = "0.0.2",
		executable = true,
	},
	{
		filename = "shitcheat_7.3_to_7.4_changelog.txt",
		url = "https://pastebin.com/raw/VghWy6G8",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_7.4.lua",
		url = "https://pastebin.com/raw/0UGZnZzW",
		version = "7.4",
		changelog = "shitcheat_7.3_to_7.4_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_7.2a_to_7.3_changelog.txt",
		url = "https://pastebin.com/raw/ES0aGcsc",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_7.3.lua",
		url = "https://pastebin.com/raw/LVZr07zk",
		version = "7.3",
		changelog = "shitcheat_7.2a_to_7.3_changelog.txt",
		executable = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_8.0_(april_fools).lua",
		url = "https://pastebin.com/raw/RfGP2EXP",
		version = "8.0 (April Fools)",
		executable = true,
		hidden = true,
	},
	{
		filename = "shitcheat_7.2_to_7.2a_changelog.txt",
		url = "https://pastebin.com/raw/c1jjt7qL",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_7.2a.lua",
		url = "https://pastebin.com/raw/KnaUyAqx",
		version = "7.2a",
		changelog = "shitcheat_7.2_to_7.2a_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_7.1a_to_7.2_changelog.txt",
		url = "https://pastebin.com/raw/1hsrHvWh",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_7.1a.lua",
		url = "https://pastebin.com/raw/89i8udPT",
		version = "7.1a",
		executable = true,
	},
	{
		name = "Shitcheat Archive",
		filename = "shitcheat_grand_archive.lua",
		url = "https://pastebin.com/raw/4ByaB7ct",
		executable = true,
		hidden = true,
	},
	{
		filename = "shitcheat_7.0_to_7.1_changelog.txt",
		url = "https://pastebin.com/raw/JgP7eh5d",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_7.1.lua",
		url = "https://pastebin.com/raw/t7RgbC2L",
		version = "7.1",
		changelog = "shitcheat_7.0_to_7.1_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_6.7a_to_7.0_changelog.txt",
		url = "https://pastebin.com/raw/db5x66r1",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_7.0.lua",
		url = "https://pastebin.com/raw/ZTAcfvGS",
		version = "7.0",
		changelog = "shitcheat_6.7a_to_7.0_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_6.7a_hotfix.txt",
		url = "https://pastebin.com/raw/jkE1XENk",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.7a_hotfix.lua",
		url = "https://pastebin.com/raw/n0An9tmD",
		version = "6.7a hotfix 1",
		changelog = "shitcheat_6.7a_hotfix.txt",
		executable = true,
	},
	{
		filename = "shitcheat_6.6_to_6.7_changelog.txt",
		url = "https://pastebin.com/raw/18M51Jjc",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.7.lua",
		url = "https://pastebin.com/raw/XyBFV3Jn",
		version = "6.7",
		changelog = "shitcheat_6.6_to_6.7_changelog.txt",
		executable = true,
	},
	{
		name = "SethHack",
		filename = "gmod_leak_dump_part_14__sethhack_2014.lua",
		url = "https://pastebin.com/raw/hBmrBx6e",
		version = "4.3",
		executable = true,
	},
	{
		name = "AutoAim",
		filename = "gmod_leak_dump_part_13__rabidtoaster's_aimbot.lua",
		url = "https://pastebin.com/raw/tR68Q4eY",
		executable = true,
	},
	{
		name = "Smeg Hack",
		filename = "gmod_leak_dump_part_12__smeghack.lua",
		url = "https://pastebin.com/raw/RhUeU1b8",
		executable = true,
	},
	{
		name = "GearVision",
		filename = "gmod_leak_dump_part_11__gearmenu.lua",
		url = "https://pastebin.com/raw/huX9ED6B",
		version = "2.4",
		executable = true,
	},
	{
		name = "AHack",
		filename = "gmod_leak_dump_part_10__ahack_2012.lua",
		url = "https://pastebin.com/raw/hfuRzRif",
		version = "1.5.0",
		executable = true,
	},
	{
		name = "MEMEWare",
		filename = "gmod_leak_dump_part_9__memeware.lua",
		url = "https://pastebin.com/raw/sNTDn4Ly",
		executable = true,
	},
	{
		name = "BridgeHack",
		filename = "gmod_leak_dump_part_8__trinity_hack.lua",
		url = "https://pastebin.com/raw/PHHusJJ7",
		version = "1.3",
		executable = true,
	},
	{
		name = "Titanium Smasher",
		filename = "gmod_leak_dump_part_7__titanium_smasher.lua",
		url = "https://pastebin.com/raw/qMDRirYd",
		executable = true,
	},
	{
		name = "snixzz3",
		filename = "gmod_leak_dump_part_6__snixzz3_cancer.lua",
		url = "https://pastebin.com/raw/CPiw7VNP",
		version = "1.3.6b",
		executable = true,
		hidden = true, -- causes game crash if not patched lol
	},
	{
		name = "SkidScorcher",
		filename = "gmod_leak_dump_part_5__skidscorcher_pub.lua",
		url = "https://pastebin.com/raw/MLrsetxv",
		version = "2.0 public",
		executable = true,
	},
	{
		name = "PWare",
		filename = "gmod_leak_dump_part_4__pware.lua",
		url = "https://pastebin.com/raw/mP2ACSEh",
		executable = true,
	},
	{
		name = "Electfried", -- not misspelled
		filename = "gmod_leak_dump_part_3__electrified.lua",
		url = "https://pastebin.com/raw/EG33z4zm",
		version = "1",
		executable = true,
	},
	{
		name = "LucidCheats",
		filename = "gmod_leak_dump_part_2__lucid_hvh_shit.lua",
		url = "https://pastebin.com/raw/va6TEHQt",
		version = "1.6.6.8",
		executable = true,
	},
	{
		name = "DingusWork",
		filename = "gmod_leak_dump_part_1__dingushack.lua",
		url = "https://pastebin.com/raw/VYdqrCHs",
		executable = true,
	},
	{
		filename = "shitcheat_6.5_to_6.6_changelog.txt",
		url = "https://pastebin.com/raw/T2jHafGc",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.6.lua",
		url = "https://pastebin.com/raw/CGdvgrjY",
		version = "6.6",
		changelog = "shitcheat_6.5_to_6.6_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_6.4_to_6.5_changelog.txt",
		url = "https://pastebin.com/raw/ahC7RdNP",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.5.lua",
		url = "https://pastebin.com/raw/R2rXGCuQ",
		version = "6.5",
		changelog = "shitcheat_6.4_to_6.5_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_6.3_to_6.4_changelog.txt",
		url = "https://pastebin.com/raw/id6j4r4y",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.4.lua",
		url = "https://pastebin.com/raw/6j8hdkPK",
		version = "6.4",
		changelog = "shitcheat_6.3_to_6.4_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_6.2_to_6.3_changelog.txt",
		url = "https://pastebin.com/raw/fiichXTQ",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.3.lua",
		url = "https://pastebin.com/raw/v5XKBJdR",
		version = "6.3",
		changelog = "shitcheat_6.2_to_6.3_changelog.txt",
		executable = true,
	},
	{
		name = "Shitcheat auto-updater",
		filename = "shitcheat_auto-updater_1.1.lua",
		url = "https://pastebin.com/raw/2u6twCsQ",
		version = "1.1",
		executable = true,
		hidden = true,
	},
	{
		filename = "shitcheat_6.1_to_6.2_changelog.txt",
		url = "https://pastebin.com/raw/Lx2MCS86",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.2.lua",
		url = "https://pastebin.com/raw/WY79nG4T",
		version = "6.2",
		changelog = "shitcheat_6.1_to_6.2_changelog.txt",
		executable = true,
	},
	{
		name = "Shitcheat auto-updater",
		filename = "shitcheat_auto-updater_1.0.lua",
		url = "https://pastebin.com/raw/jrdSYPHY",
		version = "1.0",
		executable = true,
		hidden = true,
	},
	{
		filename = "shitcheat_6.0_to_6.1_changelog.txt",
		url = "https://pastebin.com/raw/Hg46Umk3",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.1.lua",
		url = "https://pastebin.com/raw/R2NWbyzx",
		version = "6.1",
		changelog = "shitcheat_6.0_to_6.1_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.8_to_6.0_changelog.txt",
		url = "https://pastebin.com/raw/Gx1UXJ7T",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_6.0.lua",
		url = "https://pastebin.com/raw/gVvF7yZs",
		version = "6.0",
		changelog = "shitcheat_5.8_to_6.0_changelog.txt",
		executable = true,
	},
	{
		name = "How to play HL2RP",
		filename = "how_to_play__hl2rp.txt",
		url = "https://pastebin.com/raw/BHUPQEJa",
		hidden = true,
	},
	{
		filename = "shitcheat_5.7_to_5.8_changelog.txt",
		url = "https://pastebin.com/raw/9N20MZ30",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.8.lua",
		url = "https://pastebin.com/raw/efj1TZRh",
		version = "5.8",
		changelog = "shitcheat_5.7_to_5.8_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.6c_to_5.7_changelog.txt",
		url = "https://pastebin.com/raw/Kq3wRj3F",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.7.lua",
		url = "https://pastebin.com/raw/RiFCkfsA",
		version = "5.7",
		changelog = "shitcheat_5.6c_to_5.7_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.6b_to_5.6c_changelog.txt",
		url = "https://pastebin.com/raw/BzJr6xBb",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.6c.lua",
		url = "https://pastebin.com/raw/T6WiHpPr",
		version = "5.6c",
		changelog = "shitcheat_5.6b_to_5.6c_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.6a_to_5.6b_changelog.txt",
		url = "https://pastebin.com/raw/5RLsbStG",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.6b.lua",
		url = "https://pastebin.com/raw/bJPa058J",
		version = "5.6b",
		changelog = "shitcheat_5.6a_to_5.6b_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.6_to_5.6a_changelog.txt",
		url = "https://pastebin.com/raw/PexxzHDY",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.6a.lua",
		url = "https://pastebin.com/raw/5FcPKdrh",
		version = "5.6a",
		changelog = "shitcheat_5.6_to_5.6a_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.5_to_5.6_changelog.txt",
		url = "https://pastebin.com/raw/rcGvvLz1",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.6.lua",
		url = "https://pastebin.com/raw/dJZgWsrY",
		version = "5.6",
		changelog = "shitcheat_5.5_to_5.6_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.4_to_5.5_changelog.txt",
		url = "https://pastebin.com/raw/zmt0eWab",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.5.lua",
		url = "https://pastebin.com/raw/UZMAdPiw",
		version = "5.5",
		changelog = "shitcheat_5.4_to_5.5_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.3_to_5.4_changelog.txt",
		url = "https://pastebin.com/raw/JC2MEGFW",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.4.lua",
		url = "https://pastebin.com/raw/YC2aWVTy",
		version = "5.4",
		changelog = "shitcheat_5.3_to_5.4_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.2_to_5.3_changelog.txt",
		url = "https://pastebin.com/raw/QWQ3zVep",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.3.lua",
		url = "https://pastebin.com/raw/YSza88Qb",
		version = "5.3",
		changelog = "shitcheat_5.2_to_5.3_changelog.txt",
		executable = true,
	},
	{
		name = "d_entities.txt",
		filename = "d_entities.txt.txt",
		url = "https://pastebin.com/raw/H69D1AZd",
		hidden = true,
	},
	{
		filename = "shitcheat_5.1a_to_5.2_changelog.txt",
		url = "https://pastebin.com/raw/s3sSFvDn",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.2.lua",
		url = "https://pastebin.com/raw/Z5kybp1m",
		version = "5.2",
		changelog = "shitcheat_5.1a_to_5.2_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.1_to_5.1a_changelog.txt",
		url = "https://pastebin.com/raw/eq6SWWd9",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.1a.lua",
		url = "https://pastebin.com/raw/bXR0PNLH",
		version = "5.1a",
		changelog = "shitcheat_5.1_to_5.1a_changelog.txt",
		executable = true,
	},
	{
		filename = "shitcheat_5.0_to_5.1_changelog.txt",
		url = "https://pastebin.com/raw/vfHYsy5K",
		hidden = true,
	},
	{
		name = "Shitcheat",
		filename = "shitcheat_5.1.lua",
		url = "https://pastebin.com/raw/0yRr1tAv",
		version = "5.1",
		changelog = "shitcheat_5.0_to_5.1_changelog.txt",
		executable = true,
	},
}
local index = {}
for k, v in ipairs(data) do
	index[v.filename] = k
end

local show_hidden = false

local window = vgui.Create("DFrame")
window:SetTitle("Script loader")
window:SetSize(ScrW()*0.35, ScrH()*0.35)
window:Center()
window:MakePopup()
window:SetSizable(true)

local divider = vgui.Create("DHorizontalDivider", window)
divider:Dock(FILL)
divider:SetDividerWidth(4)
divider:SetLeftWidth(window:GetWide()*0.5-6)

local left = vgui.Create("DListView", window)
divider:SetLeft(left)
left:AddColumn("Script")
function left:update_list()
	self:Clear()
	for k, v in ipairs(data) do
		if v.hidden and not show_hidden then
			continue
		end
		if v.name and v.version then
			v.pretty_name = v.name.." "..v.version
		else
			v.pretty_name = v.name or v.filename or "Untitled "..k
		end
		self:AddLine(v.pretty_name, v.hidden and "Hidden" or "", v.filename)
	end
end
left:update_list()

local right = vgui.Create("DPanel", window)
divider:SetRight(right)
right:SetPaintBackground(false)

local header = vgui.Create("DLabel", right)
header:Dock(TOP)
header:DockMargin(0, 0, 0, 4)
header:SetFont("DermaLarge")
header:SetText("None selected")

local extra = vgui.Create("DLabel", right)
extra:Dock(FILL)
extra:SetContentAlignment(7)
extra:SetText("Click an entry on the left to begin.")

local cluster = vgui.Create("DPanel", right)
cluster:Dock(BOTTOM)
cluster:SetPaintBackground(false)

local load = vgui.Create("DButton", cluster)
load:Dock(FILL)
load:SetText("Execute")
load:SetEnabled(false)

local hidden_cb = vgui.Create("DCheckBoxLabel", cluster)
hidden_cb:Dock(RIGHT)
hidden_cb:DockMargin(4, 0, 0, 0)
hidden_cb:SetText("Show hidden")
hidden_cb:SetChecked(show_hidden)
function hidden_cb:OnChange(bool)
	show_hidden = bool
	left:update_list()
end

local changelog = vgui.Create("DButton", cluster)
changelog:Dock(RIGHT)
changelog:DockMargin(4, 0, 0, 0)
changelog:SetText("View changelog")
changelog:SetWide(window:GetWide()*0.125)
changelog:SetEnabled(false)

local entry
local labels = {
	name = "Name: ",
	filename = "Filename: ",
	url = "URL: ",
	version = "Version: ",
	hidden = "Hidden: "
}
function left:OnRowSelected(_, row)
	entry = data[index[row:GetValue(3)]]
	header:SetText(entry.pretty_name)
	local str = ""
	for k, v in pairs(entry) do
		if v and labels[k] then
			str = str..labels[k]..tostring(v).."\n"
		end
	end
	load:SetEnabled(true)
	load:SetText(entry.executable and "Execute" or "View")
	changelog:SetEnabled(entry.changelog and index[entry.changelog])
	extra:SetText(str)
end

local function fetch(url, callback)
	http.Fetch(url, function(body, size, headers, code)
		if code == 200 or code == 204 then
			callback(true, body, size)
		else
			callback(false, code)
		end
	end, function(err)
		callback(false, err)
	end)
end
local function popup(msg)
	local window = vgui.Create("DFrame")
	window:SetSize(ScrW()*0.25, ScrH()*0.25)
	window:Center()
	window:MakePopup()
	window:SetSizable(true)
	
	local text = vgui.Create("DLabel", window)
	text:Dock(FILL)
	text:SetContentAlignment(7)
	text:SetText(msg)
end

function load:DoClick()
	local entry = entry
	fetch(entry.url, function(succ, resp)
		if succ then
			if entry.executable then
				local succ, err = pcall(function()
					CompileString(resp, entry.filename or entry.pretty_name)()
				end)
				if not succ then
					popup(string.format("Encountered a script error while running %s:\n%s", entry.pretty_name, err))
				end
			else
				popup(resp)
			end
		else
			popup(string.format("An error occured while trying to fetch %s.", entry.url))
		end
	end)
end
function changelog:DoClick()
	local entry = data[index[entry.changelog]]
	fetch(entry.url, function(succ, resp)
		if succ then
			popup(resp)
		else
			popup(string.format("An error occured while trying to fetch %s.", entry.url))
		end
	end)
end