--[[
	Perfect Ward, originally by Husky
	New API and new Summoners Rift by MLStudio
	Maintained by SebastianBar
	========================================================================

	Changelog in BoL forum!
]]--    

local version = 1.0
local update = true -- Disable this if you don't want Auto updates
local drawWardSpots = false
local wardSlot = nil
local putSafeWard = nil

local wardSpots = {
	{x=3261.93, y=60, z=7773.65}, -- BLUE GOLEM
	{x=7831.46, y=60, z=3501.13}, -- BLUE LIZARD
	{x=10586.62, y=60, z=3067.93}, -- BLUE TRI BUSH
	{x=6483.73, y=60, z=4606.57}, -- BLUE PASS BUSH
	{x=7610.46, y=60, z=5000}, -- BLUE RIVER ENTRANCE
	{x=4717.09, y=50.83, z=7142.35}, -- BLUE ROUND BUSH
	{x=4882.86, y=27.83, z=8393.77}, -- BLUE RIVER ROUND BUSH
	{x=6951.01, y=52.26, z=3040.55}, -- BLUE SPLIT PUSH BUSH
	{x=5583.74, y=51.43, z=3573.83}, --BlUE RIVER CENTER CLOSE

	{x=11600.35, y=51.73, z=7090.37}, -- RED GOLEM
	{x=11573.9, y=51.71, z=6457.76}, -- RED GOLEM 2
	{x=12629.72, y=48.62, z=4908.16}, -- RED TRIBRUSH 2
	{x=7018.75, y=54.76, z=11362.12}, -- RED LIZARD
	{x=4232.69, y=47.56, z=11869.25}, -- RED TRI BUSH
	{x=8198.22, y=49.38, z=10267.89}, -- RED PASS BUSH
	{x=7202.43, y=53.18, z=9881.83}, -- RED RIVER ENTRANCE
	{x=10074.63, y=51.74, z=7761.62}, -- RED ROUND BUSH
	{x=9795.85, y=-12.21, z=6355.15}, -- RED RIVER ROUND BUSH
	{x=7836.85, y=56.48, z=11906.34}, -- RED SPLIT PUSH BUSH

	{x=10546.35, y=-60, z=5019.06}, -- DRAGON
	{x=9344.95, y=-64.07, z=5703.43}, -- DRAGON BUSH
	{x=4334.98, y=-60.42, z=9714.54}, -- BARON
	{x=5363.31, y=-62.70, z=9157.05}, -- BARON BUSH

	--{x=12731.25, y=50.32, z=9132.66}, -- RED BOT T2
	--{x=8036.52, y=45.19, z=12882.94}, -- RED TOP T2
	{x=9757.9, y=50.73, z=8768.25}, -- RED MID T1

	{x=4749.79, y=53.59, z=5890.76}, -- BLUE MID T1
	{x=5983.58, y=52.99, z=1547.98}, -- BLUE BOT T2
	{x=1213.70, y=58.77, z=5324.73}, -- BLUE TOP T2

	{x=6523.58, y=60, z=6743.31}, -- BLUE MIDLANE
	{x=8223.67, y=60, z=8110.15}, -- RED MIDLANE
	{x=9736.8, y=51.98, z=6916.26}, -- RED MID PATH
	{x=2222.31, y=53.2, z=9964.1}, -- BLUE TRI TOP
	{x=8523.9, y=51.24, z=4707.76}, -- DRAGON PASS BUSH
	{x=6323.9, y=53.62, z=10157.76} -- NASHOR PASS BUSH
}

local situationalWards={
	{x=13512.60, y=51.37, z=2868},
	{x=1764.57, y=52.84, z=12892.7},
	{x=4222.72, y=53.61, z=7038.58},
	{x=4379.51, y=42.73, z=8093.74},
	{x=4978.19, y=54.34, z=3042.69},
	{x=5943.51, y=53.18, z=9792.40},
	{x=5597.66, y=39.73, z=12491.04},
	{x=5732.81, y=53.39, z=10289.76},
	{x=5973.48, y=54.34, z=11115.68},
	{x=9068.02, y=53.22, z=11186.68},
	{x=10070.2, y=-60.33, z=4132.45},
	{x=12073.18, y=52.32, z=4795.50},
	{x=12210.03, y=51.38, z=1411.44},
	{x=1245.83, y=52.84, z=12040.08},
	{x=2697.76, y=52.84, z=13567.86}
	
	
}

local safeWardSpots = {
-- DISABLED, IS NOT WORKING
--	{    -- DRAGON -> TRI BUSH
--		magneticSpot = {x=10072, y=-71.24, z=3908},
--		clickPosition = {x=10297.93, y=49.03, z=3358.59},
--		wardPosition =  {x=10273.9, y=49.03, z=3257.76},
--		movePosition  = {x=10072,    y=-71.24, z=3908}
--	},
	{    -- RED MID -> SOLO BUSH
		magneticSpot = {x=9223, y=52.95, z=7525.34},
		clickPosition = {x=9603.52, y=54.71, z=7872.23},
		wardPosition = {x=9873.90, y=51.52, z=7957.76},
		movePosition = {x=9223, y=52.95, z=7525.34}
	},
	{    -- RED MID FROM TOWER -> SOLO BUSH
		magneticSpot =  {x=9127.66, y=53.76, z=8337.72},
		clickPosition = {x=9624.05, y=72.46, z=8122.68},
		wardPosition =  {x=9873.90, y=51.52, z=7957.76},
		movePosition  = {x=9127.66, y=53.76, z=8337.72}
	},
	{    -- BLUE MID -> SOLO BUSH
		magneticSpot =  {x=5667.73, y=51.65, z=7360.45},
		clickPosition = {x=5148.87, y=50.41, z=7205.80},
		wardPosition =  {x=4923.90, y=50.64, z=7107.76},
		movePosition  = {x=5667.73, y=51.65, z=7360.45}
	},
	{    -- BLUE MID FROM TOWER -> SOLO BUSH
		magneticSpot =  {x=5621.65, y=52.81, z=6452.61},
		clickPosition = {x=5255.46, y=50.44, z=6866.24},
		wardPosition =  {x=4923.90, y=50.64, z=7107.76},
		movePosition  = {x=5621.65, y=52.81, z=6452.61}
	},
	{    -- NASHOR -> TRI BUSH
		magneticSpot =  {x=4724, y=-71.24, z=10856},
		clickPosition = {x=4627.26, y=-71.24, z=11311.69},
		wardPosition =  {x=4473.9, y=51.4, z=11457.76},
		movePosition  = {x=4724, y=-71.24, z=10856}
	},
	{    -- BLUE TOP -> SOLO BUSH
		magneticSpot  = {x=2824, y=54.33, z=10356},
		clickPosition = {x=3078.62, y=54.33, z=10868.39},
		wardPosition  = {x=3078.62, y=-67.95, z=10868.39},
		movePosition  = {x=2824, y=54.33, z=10356}
	},
	{ -- BLUE MID -> ROUND BUSH
		magneticSpot  = {x=5474, y=51.67, z=7906},
		clickPosition = {x=5132.65, y=51.67, z=8373.2},
		wardPosition  = {x=5123.9, y=-21.23, z=8457.76},
		movePosition  = {x=5474, y=51.67, z=7906}
	},
	{ -- BLUE MID -> RIVER LANE BUSH
		magneticSpot  = {x=5874, y=51.65, z=7656},
		clickPosition = {x=6202.24, y=51.65, z=8132.12},
		wardPosition  = {x=6202.24, y=-67.39, z=8132.12},
		movePosition  = {x=5874, y=51.65, z=7656}
	},
	{ -- BLUE LIZARD -> DRAGON PASS BUSH
		magneticSpot  = {x=8022, y=53.72, z=4258},
		clickPosition = {x=8400.68, y=53.72, z=4657.41},
		wardPosition  = {x=8523.9, y=51.24, z=4707.76},
		movePosition  = {x=8022, y=53.72, z=4258}
	},
	{ -- RED MID -> ROUND BUSH
		magneticSpot  = {x=9372, y=52.63, z=7008},
		clickPosition = {x=9703.5, y=52.63, z=6589.9},
		wardPosition  = {x=9823.9, y=23.47, z=6507.76},
		movePosition  = {x=9372, y=52.63, z=7008}
	},
	{ -- RED MID -> RIVER ROUND BUSH // Inconsistent Placement
		magneticSpot  = {x=9072, y=53.04, z=7158},
		clickPosition = {x=8705.95, y=53.04, z=6819.1},
		wardPosition  = {x=8718.88, y=95.75, z=6764.86},
		movePosition  = {x=9072, y=53.04, z=7158}
	},
	--	{ -- RED MID -> RIVER LANE BUSH
	--		magneticSpot  = {x=8530.27, y=46.98, z=6637.38},
	--		clickPosition = {x=8539.27, y=46.98, z=6637.38},
	--		wardPosition  = {x=8396.10, y=46.98, z=6464.81},
	--		movePosition  = {x=8779.17, y=46.98, z=6804.70}
	--	},
	{ -- RED BOTTOM -> SOLO BUSH
		magneticSpot  = {x=12422, y=51.73, z=4508},
		clickPosition = {x=12353.94, y=51.73, z=4031.58},
		wardPosition  = {x=12023.9, y=-66.25, z=3757.76},
		movePosition  = {x=12422, y=51.73, z=4508}
	},
	{ -- RED LIZARD -> NASHOR PASS BUSH -- FIXED FOR MORE VISIBLE AREA
		magneticSpot  = {x=6824, y=56, z=10656},
		clickPosition = {x=6484.47, y=53.5, z=10309.94},
		wardPosition  = {x=6323.9, y=53.62, z=10157.76},
		movePosition  = {x=6824, y=56, z=10656}
	},
	{ -- BLUE GOLEM -> BLUE LIZARD
		magneticSpot  = {x=8272,    y=51.13, z=2908},
		clickPosition = {x=8163.7056, y=51.13, z=3436.0476},
		wardPosition  = {x=8163.71, y=51.6628, z=3436.05},
		movePosition  = {x=8272,    y=51.13, z=2908}
	},
	{ -- RED GOLEM -> RED LIZARD
		magneticSpot  = {x=6574, y=56.48, z=12006},
		clickPosition = {x=6678.08, y=56.48, z=11477.83},
		wardPosition  = {x=6678.08, y=53.85, z=11477.83},
		movePosition  = {x=6574, y=56.48, z=12006}
	},
	{ -- BLUE TOP SIDE BRUSH
		magneticSpot  = {x=1774, y=52.84, z=10756},
		clickPosition = {x=2302.36, y=52.84, z=10874.22},
		wardPosition  = {x=2773.9, y=-71.24, z=11307.76},
		movePosition  = {x=1774, y=52.84, z=10756}
	},
	{ -- MID LANE DEATH BRUSH
		magneticSpot  = {x=5874, y=-70.12, z=8306},
		clickPosition = {x=5332.9, y=-70.12, z=8275.21},
		wardPosition  = {x=5123.9, y=-21.23, z=8457.76},
		movePosition  = {x=5874, y=-70.12, z=8306}
	},
	{ -- MID LANE DEATH BRUSH RIGHT SIDE
		magneticSpot  = {x=9022, y=-71.24, z=6558},
		clickPosition = {x=9540.43, y=-71.24, z=6657.68},
		wardPosition  = {x=9773.9, y=9.56, z=6457.76},
		movePosition  = {x=9022, y=-71.24, z=6558}
	},
	{ -- BLUE INNER TURRET JUNGLE
		magneticSpot  = {x=6874, y=50.52, z=1708},
		clickPosition = {x=6849.11, y=50.52, z=2252.01},
		wardPosition  = {x=6723.9, y=52.17, z=2507.76},
		movePosition  = {x=6874, y=50.52, z=1708}
	},
	{ -- RED INNER TURRET JUNGLE
		magneticSpot  = {x=8122, y=52.84, z=13206},
		clickPosition = {x=8128.53, y=52.84, z=12658.41},
		wardPosition  = {x=8323.9, y=56.48, z=12457.76},
		movePosition  = {x=8122, y=52.84, z=13206}
	}
}

local wardItems = {
	{ id = 2043, spellName = "VisionWard", screenName = "Vision Ward"},
	{ id = 2044, spellName = "SightWard", screenName = "Sight Ward"},
	{ id = 3340, spellName = "RelicSmallLantern", screenName = "?"},
	{ id = 3350, spellName = "YellowTrinketUpgrade", screenName = "?"},
	{ id = 3361, spellName = "GreaterStealthTotem", screenName = "?"},
	{ id = 3362, spellName = "GreaterVisionTotem", screenName = "?"},
	{ id = 3154, spellName = "WriggleLantern", screenName = "?"},
	{ id = 3160, spellName = "FeralFlare", screenName = "?"},
	{ id = 2045, spellName = "ItemGhostWard", screenName = "?"},
	{ id = 2049, spellName = "ItemGhostWard", screenName = "?"},
	{ id = 2050, spellName = "ItemMiniWard", screenName = "?"}
}

function OnLoad()
	print("<font color=\"#FF0000\">SebastianBar's</font> <font color=\"#FFFFFF\">Perfect Ward v"..version.."</font>")
	updateScript()
	PerfectWard = scriptConfig("SebastianBar's Perfect Ward", "PerfectWard")
	PerfectWard:addParam("enable", "Enable Perfect Ward", SCRIPT_PARAM_ONOFF, true)
	PerfectWard:addParam("situational", "Enable Situational Spots", SCRIPT_PARAM_ONOFF, true)
	PerfectWard:addParam("lagfree", "Enable Lagfree Circles", SCRIPT_PARAM_ONOFF, true)
	PerfectWard:addParam("printAvailable", "Message if Ward is available", SCRIPT_PARAM_ONOFF, true)
	PerfectWard:addParam("castWard", "Ward Casting", SCRIPT_PARAM_ONKEYDOWN, false, string.byte("T"))
	PerfectWard:addParam("debug", "Debug mode", SCRIPT_PARAM_ONOFF, false)
end

function OnTick()
	if putSafeWard ~= nil then
		if GetDistance(safeWardSpots[putSafeWard].clickPosition, myHero) <= 600 then
			CastSpell(wardSlot, safeWardSpots[putSafeWard].clickPosition.x, safeWardSpots[putSafeWard].clickPosition.z)
			putSafeWard = nil
		end
	end
	if PerfectWard.castWard and checkWardsAvailable()~=nil then
		drawWardSpots = true
	end
end

function checkWardsAvailable()
	for i,wardItem in pairs(wardItems) do
		if myHero:getInventorySlot(ITEM_1) == wardItem.id and myHero:CanUseSpell(ITEM_1) == READY then return ITEM_1
		elseif myHero:getInventorySlot(ITEM_2) == wardItem.id and myHero:CanUseSpell(ITEM_2) == READY then return ITEM_2
		elseif myHero:getInventorySlot(ITEM_3) == wardItem.id and myHero:CanUseSpell(ITEM_3) == READY then return ITEM_3
		elseif myHero:getInventorySlot(ITEM_4) == wardItem.id and myHero:CanUseSpell(ITEM_4) == READY then return ITEM_4
		elseif myHero:getInventorySlot(ITEM_5) == wardItem.id and myHero:CanUseSpell(ITEM_5) == READY then return ITEM_5
		elseif myHero:getInventorySlot(ITEM_6) == wardItem.id and myHero:CanUseSpell(ITEM_6) == READY then return ITEM_6
		elseif myHero:getInventorySlot(ITEM_7) == wardItem.id and myHero:CanUseSpell(ITEM_7) == READY then return ITEM_7
		end
    end
	return nil
end

function OnWndMsg(msg,key)
	if not PerfectWard.enable then return end
	if msg == KEY_DOWN then
		wardSlot = nil
		if key == 49 then
			wardSlot = ITEM_1
		elseif key == 50 then
			wardSlot = ITEM_2
		elseif key == 51 then
			wardSlot = ITEM_3
		elseif key == 52 then
			wardSlot = ITEM_7
		elseif key == 53 then
			wardSlot = ITEM_4
		elseif key == 54 then
			wardSlot = ITEM_5
		elseif key == 55 then
			wardSlot = ITEM_6
		elseif key == PerfectWard._param[5].key then
			wardSlot = checkWardsAvailable()
		else
			wardSlot = nil
			drawWardSpots = false
		end
		if wardSlot ~= nil then
			local item = myHero:getInventorySlot(wardSlot)
			for i,wardItem in pairs(wardItems) do
				if item == wardItem.id and myHero:CanUseSpell(wardSlot) == READY then
					drawWardSpots = true
					return
				end
			end
		end
	elseif msg == WM_LBUTTONUP and drawWardSpots then
		drawWardSpots = false
	elseif msg == WM_LBUTTONDOWN and drawWardSpots then
		drawWardSpots = false
		for i,wardSpot in pairs(wardSpots) do
			if GetDistance(wardSpot, mousePos) <= 250 then
				CastSpell(wardSlot, wardSpot.x, wardSpot.z)
				return
			end
		end
		if PerfectWard.situational then
			for i,wardSpot in pairs(situationalWards) do
				if GetDistance(wardSpot, mousePos) <= 250 then
					CastSpell(wardSlot, wardSpot.x, wardSpot.z)
					return
				end
			end
		end
		for i,wardSpot in pairs(safeWardSpots) do
			if GetDistance(wardSpot.magneticSpot, mousePos) <= 100 then
				CastSpell(wardSlot, wardSpot.clickPosition.x, wardSpot.clickPosition.z)
				myHero:MoveTo(wardSpot.movePosition.x, wardSpot.movePosition.z)
				putSafeWard = i
				return
			end
		end
	elseif msg == WM_RBUTTONDOWN and drawWardSpots then
		drawWardSpots = false
	elseif msg == WM_RBUTTONDOWN then
		putSafeWard = nil
	end
end

function get2DFrom3D(x, y, z)
	local pos = WorldToScreen(D3DXVECTOR3(x, y, z))
	return pos.x, pos.y, OnScreen(pos.x, pos.y)
end

function round(num)
	if num >= 0 then return math.floor(num+.5) else return math.ceil(num-.5) end
end

function DrawCircleNextLvl(x, y, z, radius, width, color, chordlength)
	radius = radius or 300
	quality = math.max(8, round(180 / math.deg((math.asin((chordlength / (2 * radius)))))))
	quality = math.pi / quality
	radius = radius * .92
	local points = {}
	for theta = 0, 2 * math.pi + quality, quality do
		local c = WorldToScreen(D3DXVECTOR3(x + radius * math.cos(theta), y, z - radius * math.sin(theta)))
		points[#points + 1] = D3DXVECTOR2(c.x, c.y)
	end
	DrawLines2(points, width or 1, color or 4294967295)
end

function DrawCircle2(x, y, z, radius, color)
	local vPos1 = Vector(x, y, z)
	local vPos2 = Vector(cameraPos.x, cameraPos.y, cameraPos.z)
	local tPos = vPos1 - (vPos1 - vPos2):normalized() * radius
	local sPos = WorldToScreen(D3DXVECTOR3(tPos.x, tPos.y, tPos.z))
	if OnScreen({x = sPos.x, y = sPos.y }, {x = sPos.x, y = sPos.y }) then
		DrawCircleNextLvl(x, y, z, radius, 1, color, 300) 
	end
end

function OnDraw()
	if not PerfectWard.enable then return end
	local wardAvailable = checkWardsAvailable()
	if PerfectWard.printAvailable and wardAvailable~=nil then
		DrawText("WARD AVAILABLE TO CAST!", 21, 5, 100, 0xFFFFFFFF)
		DrawText("Next casting: "..myHero:getItem(wardAvailable).name, 21, 5, 120, 0xFFFFFFFF)
	end
	if drawWardSpots then
		for i, wardSpot in pairs(wardSpots) do
			local wardColor = (GetDistance(wardSpot, mousePos) <= 250) and ARGB(255,0,255,0) or ARGB(255,255,255,255)
			local x, y, onScreen = get2DFrom3D(wardSpot.x, wardSpot.y, wardSpot.z)
			if onScreen then
				if PerfectWard.lagfree then
					DrawCircle2(wardSpot.x, wardSpot.y, wardSpot.z, 30, wardColor)
					DrawCircle2(wardSpot.x, wardSpot.y, wardSpot.z, 250, wardColor)
				else
					DrawCircle(wardSpot.x, wardSpot.y, wardSpot.z, 30, wardColor)
					DrawCircle(wardSpot.x, wardSpot.y, wardSpot.z, 250, wardColor)
				end
			end
		end
		if PerfectWard.situational then
			for i, wardSpot in pairs(situationalWards) do
				local wardColor = (GetDistance(wardSpot, mousePos) <= 250) and ARGB(255,0,255,0) or ARGB(255,255,255,255)
				local x, y, onScreen = get2DFrom3D(wardSpot.x, wardSpot.y, wardSpot.z)
				if onScreen then
					if PerfectWard.lagfree then
						DrawCircle2(wardSpot.x, wardSpot.y, wardSpot.z, 30, wardColor)
						DrawCircle2(wardSpot.x, wardSpot.y, wardSpot.z, 250, wardColor)
					else
						DrawCircle(wardSpot.x, wardSpot.y, wardSpot.z, 30, wardColor)
						DrawCircle(wardSpot.x, wardSpot.y, wardSpot.z, 250, wardColor)
					end
				end
			end
		end
		for i,wardSpot in pairs(safeWardSpots) do
			local wardColor  = (GetDistance(wardSpot.magneticSpot, mousePos) <= 100) and ARGB(255,0,255,0) or ARGB(255,255,255,255)
			local arrowColor = (GetDistance(wardSpot.magneticSpot, mousePos) <= 100) and ARGB(255,0,255,0) or ARGB(255,255,255,255)
			local x, y, onScreen = get2DFrom3D(wardSpot.magneticSpot.x, wardSpot.magneticSpot.y, wardSpot.magneticSpot.z)
			if onScreen then
				if PerfectWard.lagfree then
					DrawCircle2(wardSpot.wardPosition.x, wardSpot.wardPosition.y, wardSpot.wardPosition.z, 30, wardColor)
					DrawCircle2(wardSpot.magneticSpot.x, wardSpot.magneticSpot.y, wardSpot.magneticSpot.z, 100, wardColor)
				else
					DrawCircle(wardSpot.wardPosition.x, wardSpot.wardPosition.y, wardSpot.wardPosition.z, 30, wardColor)
					DrawCircle(wardSpot.magneticSpot.x, wardSpot.magneticSpot.y, wardSpot.magneticSpot.z, 100, wardColor)
				end
				local magneticWardSpotVector = Vector(wardSpot.magneticSpot.x, wardSpot.magneticSpot.y, wardSpot.magneticSpot.z)
				local wardPositionVector = Vector(wardSpot.wardPosition.x, wardSpot.wardPosition.y, wardSpot.wardPosition.z)
				local directionVector = (wardPositionVector-magneticWardSpotVector):normalized()
				local line1Start = magneticWardSpotVector + directionVector:perpendicular() * 100
				local line1End = wardPositionVector + directionVector:perpendicular() * 30
				local line2Start = magneticWardSpotVector + directionVector:perpendicular2() * 100
				local line2End = wardPositionVector + directionVector:perpendicular2() * 30
				local p1 = WorldToScreen(D3DXVECTOR3(line1Start.x,line1Start.y,line1Start.z))
				local p2 = WorldToScreen(D3DXVECTOR3(line1End.x,line1End.y,line1End.z))
				local p3 = WorldToScreen(D3DXVECTOR3(line2Start.x,line2Start.y,line2Start.z))
				local p4 = WorldToScreen(D3DXVECTOR3(line2End.x,line2End.y,line2End.z))
				DrawLine(p1.x, p1.y, p2.x, p2.y, 1, arrowColor)
				DrawLine(p3.x, p3.y, p4.x, p4.y, 1, arrowColor)
			end
		end
	end
	if PerfectWard.debug then
		DrawText("Cursor Pos: X = ".. string.format("%.2f", mousePos.x) .." Y = ".. string.format("%.2f", mousePos.y) .." Z = ".. string.format("%.2f", mousePos.z), 21, 5, 140, 0xFFFFFFFF)
		local target = GetTarget()
		for i,wardItem in pairs(wardItems) do
			if target ~= nil and target.name == wardItem.spellName then
				DrawText("Target Pos: X = ".. string.format("%.2f", target.x) .." Y = ".. string.format("%.2f", target.y) .." Z = ".. string.format("%.2f", target.z), 21, 5, 160, 0xFFFFFFFF)
			end
		end
	end
end

function updateScript()
	if update then
		local serverVersion = tonumber(GetWebResult("raw.github.com", "/SebastianBar/BoL/master/PerfectWard.version"))
		if serverVersion and serverVersion > version then
			print("<font color=\"#FF0000\">SebastianBar's</font> <font color=\"#FFFFFF\">Perfect Ward: Updating to v"..serverVersion..". Don't press F9!</font>")
			DownloadFile("http://raw.github.com/SebastianBar/BoL/master/PerfectWard.lua".."?rand"..math.random(1,9999), SCRIPT_PATH.."PerfectWard.lua",function()
			print("<font color=\"#FF0000\">SebastianBar's</font> <font color=\"#FFFFFF\">Perfect Ward Changelog v"..serverVersion..": "..GetWebResult("raw.github.com", "/SebastianBar/BoL/master/PerfectWard.changelog").."</font>")
			print("<font color=\"#FF0000\">SebastianBar's</font> <font color=\"#FFFFFF\">Perfect Ward: Updated to v"..serverVersion..". Press F9 twice to reload</font>")
			end)
		else
			print("<font color=\"#FF0000\">SebastianBar's</font> <font color=\"#FFFFFF\">Perfect Ward: You have the lastest version!</font>")
		end
	end
end

assert(load(Base64Decode("G0x1YVIAAQQEBAgAGZMNChoKAAAAAAAAAAAAAQIKAAAABgBAAEFAAAAdQAABBkBAAGUAAAAKQACBBkBAAGVAAAAKQICBHwCAAAQAAAAEBgAAAGNsYXNzAAQNAAAAU2NyaXB0U3RhdHVzAAQHAAAAX19pbml0AAQLAAAAU2VuZFVwZGF0ZQACAAAAAgAAAAgAAAACAAotAAAAhkBAAMaAQAAGwUAABwFBAkFBAQAdgQABRsFAAEcBwQKBgQEAXYEAAYbBQACHAUEDwcEBAJ2BAAHGwUAAxwHBAwECAgDdgQABBsJAAAcCQQRBQgIAHYIAARYBAgLdAAABnYAAAAqAAIAKQACFhgBDAMHAAgCdgAABCoCAhQqAw4aGAEQAx8BCAMfAwwHdAIAAnYAAAAqAgIeMQEQAAYEEAJ1AgAGGwEQA5QAAAJ1AAAEfAIAAFAAAAAQFAAAAaHdpZAAEDQAAAEJhc2U2NEVuY29kZQAECQAAAHRvc3RyaW5nAAQDAAAAb3MABAcAAABnZXRlbnYABBUAAABQUk9DRVNTT1JfSURFTlRJRklFUgAECQAAAFVTRVJOQU1FAAQNAAAAQ09NUFVURVJOQU1FAAQQAAAAUFJPQ0VTU09SX0xFVkVMAAQTAAAAUFJPQ0VTU09SX1JFVklTSU9OAAQEAAAAS2V5AAQHAAAAc29ja2V0AAQIAAAAcmVxdWlyZQAECgAAAGdhbWVTdGF0ZQAAB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