--[[
	lua/menu/gsg_menuplugins8.lua
	fangli :d | (STEAM_0:0:19962914)
	===DStream===
]]

print("not loading now")

/*concommand.Add("lua_run_m",function(ply,cmd,args,t) RunString(t) end)
concommand.Add("lua_openscript_m",function(ply,cmd,args,t) if !file.Exists(t,"GAME") then Msg("No such file!") return end RunString(file.Read(t,"GAME")) end)

require("cvar3")
require("hac")

local AL = GetConVar("sv_allowcslua")
AL:SetName("sv_blockcslua")
local AL2 = CreateConVar("sv_allowcslua",0,8452)
local shouldLoad = false


local function checkCache()
	local t = hsp.Find("cache/lua/*.lua")
	if #t > 1 and !shouldLoad then
		for k,v in pairs(t) do
			hsp.Delete("cache/lua/"..v)
			shouldLoad = true
		end
	end

	if shouldLoad then
		if #t > 1 then
			local f = t[1]
			print("omg got it")
			print(hsp.Read("cache/lua/"..f))
			shouldLoad = false
		end
	end
	print("Deleted "..tostring(#t).." cache files.")
end

hook.Add("Think","sv_allowcslua",function() 
	--checkCache()
	if IsInGame() and AL:GetBool() != true then 
		AL:SetValue(1) 
		AL2:SetValue(0)
		//timer.Simple(1,function() RunConsoleCommand([[lua_openscript_cl]], [[fa_init_cl.lua]]) end)
	end 
end)


if FLOADED == true then return end
FLOADED = true; TTa = CurTime()


MsgC(Blue,"Loading MenuPlugins!\n")

local Blue 	= Color(0,162,232,255)
local White = Color(255,255,255,255)
local Green = Color(85,218,90,255)
local Sexy 	= Color(255,174,201,255)
local Red 	= Color(255,0,0,255)


local CLError = Color(255,221,102,255)
local SVError = Color(136,221,255,255)

IN_SPEW = false
local function _print( ... )
	IN_SPEW = true
	print( ... )
	IN_SPEW = false
end

function ConsolePrint(str,type,group,level,r,g,b,a)
	if IN_SPEW then return end
	//if type == SPEW_DEBUGGER then _print(r,g,b,a) end
	if Console2Print then
		Console2Print(str,r,g,b,a)
	end
end

require("ffs")

SPEW_MESSAGE = SPEW.SPEW_MESSAGE
SPEW_WARNING = SPEW.SPEW_WARNING
SPEW_ASSERT = SPEW.SPEW_ASSERT
SPEW_ERROR = SPEW.SPEW_ERROR
SPEW_LOG = SPEW.SPEW_LOG
//SPEW_TYPE_COUNT = SPEW.TYPE_COUNT
SPEW_DEBUGGER = SPEW.SPEW_DEBUGGER
SPEW_CONTINUE = SPEW.SPEW_CONTINUE
SPEW_ABORT = SPEW.SPEW_ABORT

SpewT = {
	[SPEW_MESSAGE] = 		"SPEW_MESSAGE",
	[SPEW_WARNING] = 		"SPEW_WARNING",
	[SPEW_ASSERT] = 		"SPEW_ASSERT",
	[SPEW_ERROR] = 			"SPEW_ERROR",
	[SPEW_LOG] = 			"SPEW_LOG",
	//[SPEW_TYPE_COUNT] = 	"SPEW_TYPE_COUNT",
	[SPEW_DEBUGGER] = 		"SPEW_DEBUGGER",
	[SPEW_CONTINUE] = 		"SPEW_CONTINUE",
	[SPEW_ABORT] = 			"SPEW_ABORT",
}

function LuaError(str)
	MsgC(Green,"MENU ERROR: "..str.."\n")
end

FFS.SYNC = {}
FFS.SYNC.Path = "C:\\Users\\xy\\Dropbox\\GMod Menu\\"
function FFS.SYNC.Exists(str)
	str = str or ""
	return FFS.FileDoesExist(FFS.SYNC.Path..str)
end
function FFS.SYNC.Read(str)
	str = str or ""
	return FFS.Read(FFS.SYNC.Path..str)
end
function FFS.SYNC.Write(str)
	str = str or ""
	return FFS.Read(FFS.SYNC.Path..str)
end
function FFS.SYNC.FindFile(str)
	str = str or ""
	local a = FFS.FindFile(FFS.SYNC.Path..str)
	if type(a) != "table" then LuaError("Not found any file at "..str) end
	local str = FFS.SYNC.Path..string.gsub(str,"*.lua","")
	local str = string.gsub(str,"*","")
	local b = {}
	for k,v in ipairs(a) do
		if v != ".." and v != "." and FFS.FileDoesExist(str..v) then
			b[#b+1] = v
		end
	end
	return b
end
function FFS.SYNC.FindFolder(str)
	str = str or ""
	local a = FFS.FindFile(FFS.SYNC.Path..str)
	if type(a) != "table" then LuaError("Not found any file at "..str) end
	local str = FFS.SYNC.Path..string.gsub(str,"*.lua","")
	local str = string.gsub(str,"*","")
	local b = {}
	for k,v in ipairs(a) do
		if v != ".." and v != "." and !FFS.FileDoesExist(str..v) then
			b[#b+1] = v
		end
	end
	return b
end
local NotInclude = include
function include(str)
	if !str then return end
	if string.sub(debug.getinfo(2).source,1,14) != "@menu_plugins\\" then
		return NotInclude(str)
	else
		return LuaRunFile(str)
	end
end
local NotFF = file.Find
function file.Find(str,str2)
	if !str then return end
	if string.sub(debug.getinfo(2).source,1,14) != "@menu_plugins\\" then

		return NotFF(str,str2)
	else
		return FFS.SYNC.FindFile(str), FFS.SYNC.FindFolder(str)
	end
end

local function LuaRun(ply,cmd,args,str)
	local func = CompileString( str, "Console", false)
	if type(func) == "string" or type(func) == nil then LuaError(func or "Unknown Error!!!") return end
	status, err = pcall(func) 
	if status == false then
		LuaError(err)
		return
	end
end
concommand.Add("lua_run_m", LuaRun)

function LuaRunFile(path)
	if !FFS.SYNC.Exists(path, LUA_PATH) then LuaError("File not found: "..path) end
	local str = FFS.SYNC.Read(path)
	if !str or type(str) != "string" then  LuaError("File not found(2): "..path) end
	local func = CompileString( "local FILE_PATH=" .. string.format("%q", FFS.SYNC.Path..path) .. " " .. str, path, false)
	status, err = pcall(func) 
	if status == false then
		LuaError(err or "Syntax error in "..path.."! (Got no error)")
	end
end

for k,v in ipairs( FFS.SYNC.FindFile("menu_plugins\\*.lua", LUA_PATH) ) do

	
	if v == "menu_init.lua" or v:find("-", 1, true) then continue end
	
	MsgC(Blue, 	"[MenuPlugins]: ");
	MsgC(White,	"Loading ");
	MsgC(White,	v.."\n");
	
	LuaRunFile("menu_plugins\\"..v)
end

MsgC(Blue, 	"[MenuPlugins]: ");
MsgC(White,	"Succesfully loaded in just "..tostring(CurTime()-TTa).." seconds!\n");