require("libs.extra")
require("libs.kvData")
require("libs.utils_interface")
require("libs.game_data")
local JSONs = require("libs.JSON")

local image = {} local keys = {} local setting = {}

local ShowMenu = false
local change_lang = nil

local language_standart = dota.GetLanguage() local language = language_standart

local screen = dota.GetScreenSize()
local HudCreen = LoadHudPosition(screen)
local con = screen.x/HudCreen.x
local rate = con local floor = math.floor
local main = {}  main.scroll_num = 1 main.block = nil local playerCache = {} local const_event = {} --local endgame 

local save_window = {name=nil,img={},init=nil,pos=dota.Vector(500,500,0)} local w_img_size = 20*con local const_20 = 20*con
local cache_key = {} cache_key[513] = 0 local IsMouseDown = false local spectator = false local fix_cam_bug = 0

--//Fonts
local F13 = dota.CreateFont("Arial",13*con,700*con)
local F14 = dota.CreateFont("Arial",14*con,900*con)
local F16 = dota.CreateFont("Arial",16*con,800*con)
local MAX_LINES = 32 local MAX_EXTRA_OPTIONS = 20 
local Enum = GetEnums() local EMPTY_IMAGE = GetTextureId2("doom_bringer_empty1")

local inmenu = {

	CameraDistanceChange = function()
		local distance = camera.GetCameraDistance()
		local safe = 0xffffffee
		local safeMsg = Enum.CAMERA_MAX
		if distance > 0 then
			local proc = floor(1/ ( (Enum.CAMERA_MAX-1000)/ (distance-1000) )*0xff)
			proc = math.min(255, proc*0.75)
			local proc_str = num2hex(math.abs(255 - proc))
			safe = tonumber("0xff"..proc_str..proc_str.."ee") or safe
		end
		if not setting["CamRange"] and main.scroll_num == 1 then
			local min_ = Enum.CAMERA_STANDART 
			local max_ = Enum.CAMERA_MAX
			if not image.cam_distance then
				image.cam_distance = {}
				local xx = main.bg.x+main.bg.w + 10*rate
				if xx > screen.x-50*rate then
					xx = xx - main.bg.w - 45*rate
				end
				local yy = main.bg.y
				local ww = main.bg.h-15*rate

				image.cam_distance.text = DrawText(xx,yy,Enum.WHITE,floor(main.camera_distance),F13,true)
				image.cam_distance.rect = DrawRound(xx+2*rate,yy+15*rate,22*rate,ww,0xffffffee,GetTextureId("NtUI/vgui/scroll_line.png"),true,5*rate)
				image.cam_distance.change= DrawRound(xx,image.cam_distance.rect.y+(main.camera_distance-min_)*image.cam_distance.rect.h/(max_-min_)-15*rate/2,25*rate,15*rate,safe,GetTextureId("NtUI/vgui/scroll_box_horiz.png"),true,5*rate)

				image.cam_distance.change.y = math.min(math.max(image.cam_distance.change.y+15*rate/2,image.cam_distance.rect.y),image.cam_distance.rect.y-15*rate+image.cam_distance.rect.h)

			elseif IsMouseOnButton(image.cam_distance.rect) then

				local mouse = dota.GetMousePosition().y
				local new_distance 
				local shif = image.cam_distance.rect.h/(max_-min_)
				if mouse < image.cam_distance.rect.y+image.cam_distance.change.h then
					new_distance = min_
					image.cam_distance.change.y = image.cam_distance.rect.y
				elseif mouse > image.cam_distance.rect.y+image.cam_distance.rect.h-image.cam_distance.change.h then
					new_distance = max_
					image.cam_distance.change.y = image.cam_distance.rect.y+image.cam_distance.rect.h-image.cam_distance.change.h
				else
					new_distance = min_ + floor(mouse-image.cam_distance.rect.y)/shif
					image.cam_distance.change.y = image.cam_distance.rect.y+floor(mouse-image.cam_distance.rect.y)
				end
				new_distance = floor(new_distance/50)*50

				if distance > safeMsg then
					image.cam_distance.text.text = tostring(distance).." ("..main.cam_range..")"
				else
					image.cam_distance.text.text = tostring(distance)
				end
				if distance ~= new_distance then
					camera.SetCameraDistance(new_distance)
				end
				image.cam_distance.change.color = safe
			elseif main.camera_distance ~= distance then
				main.camera_distance = distance
				WriteLines(dota.GetLuaPath().."scripts/config/CamRange.txt",{math.clamp(main.camera_distance,Enum.CAMERA_STANDART,Enum.CAMERA_MAX)})
			else 
				image.cam_distance.change.y = image.cam_distance.rect.y+(distance-min_)*image.cam_distance.rect.h/(max_-min_)-15*rate/2
				image.cam_distance.change.y = math.min(math.max(image.cam_distance.change.y+15*rate/2,image.cam_distance.rect.y),image.cam_distance.rect.y-15*rate+image.cam_distance.rect.h)
				image.cam_distance.text.text = tostring(distance)
			end
		elseif image.cam_distance then
			image.cam_distance.text = DestroyImg(image.cam_distance.text)
			image.cam_distance.rect = DestroyImg(image.cam_distance.rect)
			image.cam_distance.change = DestroyImg(image.cam_distance.change)
			image.cam_distance = nil
		end
	end,

	ComboMakerCursor = function()
		if image.help_tips.header.text=="ComboMaker" or image.help_tips.header.text=="ComboMaker2" then
			if image.help_tips.extra.show then
				local mouse = dota.GetMousePosition()
				if not image.help_tips.extra.cursor then
					image.help_tips.extra.cursor = DrawRound(mouse.x,mouse.y,25*con,25*con,Enum.WHITE,-1, true,6*con)
				end
				image.help_tips.extra.cursor.textureId = GetTextureId2(image.help_tips.extra.show)
				if image.help_tips.extra.show:sub(1,4)~="item" then					
					image.help_tips.extra.cursor.w =image.help_tips.extra.size_spell
				else
					image.help_tips.extra.cursor.w =image.help_tips.extra.size_item*1.2
				end
				image.help_tips.extra.cursor.x = mouse.x-10*con
				image.help_tips.extra.cursor.y = mouse.y-10*con
			elseif  image.help_tips.extra.cursor then
				image.help_tips.extra.cursor.visible = false
			end
		elseif image.help_tips.extra and image.help_tips.extra.cursor then
			image.help_tips.extra.cursor.visible = false
		end
	end,

	ChatAbuseCustomText = function()
		if image.help_tips.header.text=="ChatAbuz" then
			for z,d in ipairs(image.help_tips) do
				if d[6].text == "ChatAbuzCustom" then
					local textBuff = dota.GetTextFromBuffer():gsub("%%","")
					d[9].w = 10*rate+dota.GetTextSize(F13,textBuff).x
					d[10].text = textBuff
					break
				elseif d[6].text == "ChatAbuzWin" then
					if IsMouseOnButton(d[10]) then
						d[11].color = 0xC0C0C090
					else
						d[11].color = 0x00000090
					end
				end
			end
		end
	end,

	ChangeLang = function()
		if type(change_lang)=="string" then
			main.lang = change_lang
		else
			main.lang = SelectLanguages(setting)
		end
		main.page1 = Page_1(main.lang)
		main.page2 = Page_2(main.lang)
		main.page3 = Page_3(main.lang)
		main.page4_ = Page_4(main.lang)
		main.page_extra = WindowAutoEvade(main.lang)
		main.page_help = Helps(main.lang)
		main.page4 = main.page4_[main.myName] or {}
		LocalizeMenu()

		for i,v in ipairs(main.page1) do
			if v[1] == "Help" then
				if not v.old then
					v.old = v[3]
				end
				v[3] = v.old..Localize(UpdateLog(main.lang),main.lang)	break
			end
		end

		DrawInterface(false)
		DrawInterface(true)
		VisibleInterface(true,main.scroll_num)
		LoadInterfaceSetting()
		Callback("new_lang",main.lang)
		change_lang = nil
	end,

	ComboOutWindowsMove = function()
		if image.help_tips.hold then
			if IsMouseOnButton(image.help_tips.hold2) then
				image.help_tips.hold.color = Enum.COLOR_HEADER
				image.help_tips.hold2.color = Enum.COLOR_HEADER
				if IsLMouseDownOnes() then
					save_window.name = image.help_tips.header.text
					save_window.init = nil
					save_window.img = {}
					local tab = ReadLines(dota.GetLuaPath().."scripts/config/out_windows_cache.txt")
					for i,v in ipairs(tab) do
						local splits = v:split()
						if splits[1] and splits[1] == main.myName then
							table.remove(tab,i)
						end
					end
					tab[#tab+1] = main.myName..":"..image.help_tips.header.text
					WriteLines(dota.GetLuaPath().."scripts/config/out_windows_cache.txt",tab)
					collectgarbage("collect")
				end
			else
				if image.help_tips.hold.color == Enum.COLOR_HEADER then 
					image.help_tips.hold.color = 0xffffff30
					image.help_tips.hold2.color = 0xffffff30
				end
				if image.help_tips.hold.color > 4294967270 then
					image.help_tips.hold.color = 0xffffff30
					image.help_tips.hold2.color = 0xffffff30
				else 
					image.help_tips.hold.color = image.help_tips.hold.color + 5
					image.help_tips.hold2.color = image.help_tips.hold.color + 5
				end
			end
		end
	end,
	
	MainKeyBoxColor = function(ht)
		for i,v in ipairs(ht) do
			if v.key and not v.combo then
				if v.key.text ~= "" and IsMouseOnButton(v.key_bg) then
					v.key_bg.color = Enum.COLOR_KEY_BG_LIGH
				else
					v.key_bg.color = Enum.COLOR_KEY_BG_NORMAL
				end
			end
		end
	end,

	MoveMenuViaMouseScroll = function()
		for i,v in ipairs(image.scroll) do
			if IsMouseOnButton(v) then
				if not ScrollIsEnable(v) then
					MoveScroll(i)
					break
				end
			elseif ScrollIsEnable(v) and i > 2 then
				for a, s in ipairs(image[i]) do
					if IsMouseOnButton(s.key_bg) and s.key.text ~= "" then
						s.key_bg.color = Enum.COLOR_KEY_BG_LIGH
					else
						if s.key and s.key.text ~= "" then
							s.key_bg.color = Enum.COLOR_KEY_BG_NORMAL
						else
							s.key_bg.color = Enum.COLOR_EMPTY
						end
					end
				end
			end
		end
	end,

	MenuHighLight = function()

		if image.help_tips and image.help_tips.extra then
			local ex = image.help_tips.extra
			if ex.name == "AutoEvade" then
				if image.help_tips.extra.manage and IsMouseOnButton(image.help_tips.extra.manage.bg) then
					local moveDodge = image.help_tips.extra.manage
					if moveDodge and moveDodge.txt1 and IsMouseOnButton(moveDodge.txt1) then
						local v = moveDodge.txt1
						return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,rounded=v.rounded})
					end

					if moveDodge and moveDodge.reset_rect and IsMouseOnButton(moveDodge.reset_rect) then
						local v = moveDodge.reset_rect
						return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,rounded=v.rounded})
					end
					for z,v in ipairs(image.help_tips.extra.manage) do
						if v and IsMouseOnButton(v) and not IsEmptyTexture(v.textureId) then
							return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,rounded=v.rounded})
						end
					end
					return DrawHightLight()
				else
					for z,evade in ipairs(main.page_extra) do
						if ex[z] and ex[z].bg and IsMouseOnButton(ex[z].bg) then
							for i,v in ipairs(ex[z]) do
								if IsMouseOnButton(v) then
									return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,v.color==Enum.WHITE and 0xffffff99 or 0xff2525ff,rounded=v.rounded})
								end
							end
						end
					end
				end
			elseif ex[1] then
				if ex.name == "Spell" or ex.name == "Spell#2" then
					for z,ab in ipairs(ex[1]) do
						if IsMouseOnButton(ab) then
							local v = ab
							return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,rounded=v.rounded})
						end
					end
				elseif ex.name == "ComboMaker" or ex.name == "ComboMaker2" then
					if not image.help_tips.extra.cursor then
						for z,ab in ipairs(ex[1]) do
							local v = ab
							if v and IsMouseOnButton(v) and not IsEmptyTexture(v.textureId) then
								return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,rounded=v.rounded})
							end
						end
						for z,ab in ipairs(ex[1].hilite) do
							if IsMouseOnButton(ab) and ab.textureName and ab.textureName~="null" then
								local v = ab
								return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,rounded=v.rounded})
							end
						end
					elseif ex[1].hilite then
						for z,ab in ipairs(ex[1].hilite) do
							if IsMouseOnButton(ab) then
								local v = ab
								return DrawHightLight({v.x,v.y,v.w+1,v.h+1,0,rounded=v.rounded})
							end
						end
					end
				elseif ex.name == "PanelAlly" or ex.name == "PanelEnemy" then
					for z,ab in ipairs(ex[1]) do
						if IsMouseOnButton(ab) then
							local v = ab
							return DrawHightLight({v.x-2,v.y-2,v.w+4,v.h+4,ab.textureId,ab.color-25,rounded=v.rounded})
						end
					end
				end
			end

		end

		if image.help_tips then
			for z = 1, MAX_EXTRA_OPTIONS do
				if image.help_tips[z] then
					if image.help_tips[z].combo or image.help_tips[z].just_list then
						local img_butons = (image.help_tips[z].combo and image.help_tips[z]) or (not image.help_tips[z].combo and image.help_tips[z].just_list)
						for i,v in ipairs(img_butons) do
							if v and IsMouseOnButton(v) and v.visible then								
								DrawHightLight({v.x,v.y,v.w,v.h,0,rounded=v.rounded}) return
							end
						end
					else
						local v = image.help_tips[z].button
						if v and IsMouseOnButton(v) and v.visible then
							DrawHightLight({v.x,v.y,v.w,v.h,0,rounded=v.rounded}) return
						end
					end
				end
			end
			if #image.help_tips>0 and (IsMouseOnButton(image.help_tips.bg) or (image.help_tips.extra and image.help_tips.extra[1] and IsMouseOnButton(image.help_tips.extra[1].bg))) then
				DrawHightLight()
				return
			end
		else 
			if image.scroll and ScrollIsEnable(image.scroll[3]) and image[3] and image[3].extra2 and image[3].extra then

				for aa,bb in ipairs({image[3].extra,image[3].extra2}) do --AutoEvade Killstealer hightlight
					for z,sp in ipairs(bb) do
						local v = bb[z]
						if v and v.textureId > 0 then
							if IsMouseOnButton(v) then
								DrawHightLight({v.x,v.y,v.w,v.h,0,rounded=v.rounded}) return
							end
						end
					end
				end
				
			end
		end 

		if image.scroll then
			for m,l in ipairs(image.scroll) do
				if ScrollIsEnable(l) and image[1] then
					for i, z in ipairs(image[m]) do
						if z.box and IsMouseOnButton(z.box) then
							local v = z.box					
							DrawHightLight({v.x,v.y,v.w,v.h,0,rounded=v.rounded}) return
						end
					end
					if m == 2 and image[m].extra then
						for z = 1, 6 do
							local v =image[m].extra[z] and image[m].extra[z].img
							if v and IsMouseOnButton(v) then
								DrawHightLight({v.x,v.y,v.w,v.h,0,rounded=v.rounded}) return
							end
						end
					end
				end
			end
		end

		DrawHightLight()
	end,

	SetOptionBind = function(code,wheel,cycle)

		if not ShowMenu then return end
		
		if image.help_tips then

			for z = 1, MAX_EXTRA_OPTIONS do
				if image.help_tips[z] and image.help_tips[z].key_bg and IsMouseOnButton(image.help_tips[z].key_bg) then
					local name = image.help_tips[z].option_name.text
					for i, v in ipairs(main.page_help) do
						local is_number = image.help_tips[z].is_number_box 

						if v[1] == name and v[4] and v[4]~="" and (not wheel or is_number) then

							code = (wheel and ProcentGenerate(v[4],wheel,cycle)) or code

							local bindet = string.char(code)
							if bindet and (not is_number or tonumber(bindet)) then
								image.help_tips[z].key.text,keys[name],v[4] = bindet,bindet,bindet
								image.help_tips[z].key_show.text = KeyCode(code)
								if image.help_tips[z].draw_procent and tonumber(v[4]) then
									image.help_tips[z].draw_procent.text = ProcentText(v[4],image.help_tips[z])
								end
								local full_tab = Collect(main.page_help,name,true)
								WriteLines(dota.GetLuaPath().."scripts/config/Extra_Option.txt",full_tab)
								return true
							end
						end
					end
				end
			end
		end

		if image.help_tips and image.help_tips.extra then
			return
		end

		for i = 3,4 do
			if ScrollIsEnable(image.scroll[i])then
				for k, v in ipairs(image[i]) do
					if v.key_bg.color ~= Enum.COLOR_EMPTY and IsMouseOnButton(v.key_bg) and (not wheel or v.is_number_box) then

						code = (wheel and ProcentGenerate(v.key.text,wheel,cycle)) or code

						local bindet = string.char(code)
						local name = v.text.text

						if bindet and (not v.is_number_box or tonumber(bindet)) then
							v.key.text = bindet
							v.key_show.text = KeyCode(code)
							main[tostring("page"..i)][k][4] = bindet
							keys[name] = bindet
							if v.draw_procent then
								v.draw_procent.text = ProcentText(bindet,v)
							end
						end

						local patch = {"UI","Items","Common",main.myName}
						local full_tab = Collect(main[tostring("page"..i)],name)
						WriteLines(dota.GetLuaPath().."scripts/config/"..patch[i]..".txt",full_tab)
						return true
					end
				end
			end
		end

	end

}

function OnInterfaceTick()
	if not main.event_load or not dota.IsInGame() then
		return
	end

	if IsMouseOnButton(main.btn) then
		main.btn.color = Enum.WHITE
		return
	else
		main.btn.color = smoothColorTransition(main.btn.color,0.075)
	end

	DrawOutWindows()

	if change_lang then
		inmenu.ChangeLang()
		return
	end

	if not ShowMenu then
		return
	end

	PreForImage()

	inmenu.CameraDistanceChange()

	local draw_help = false
	local ht = image.help_tips

	inmenu.MenuHighLight()

	if ht and #ht> 0 and ((IsMouseOnButton(ht.bg)
	or (ht.extra and ((ht.extra[1] and IsMouseOnButton(ht.extra[1].bg))
	or (ht.extra[2] and IsMouseOnButton(ht.extra[2].bg))
	or (ht.extra[3] and IsMouseOnButton(ht.extra[3].bg)))))
	or (ht.extra and ht.extra.manage and IsMouseOnButton(ht.extra.manage.bg))
	) then

		inmenu.MainKeyBoxColor(ht)

		inmenu.ComboMakerCursor()

		--inmenu.ChatAbuseCustomText()

		inmenu.ComboOutWindowsMove()

		return true
	end

	for m,l in ipairs(image.scroll) do
		if ScrollIsEnable(l) then
			for i, v in ipairs(image[m]) do
				local info_tables = main[tostring("page"..m)][i] 
				if (IsMouseOnButton(v.box) and (not ht or (ht.header.text and ht.header.text==info_tables[1]))) or (main.reoption and main.reoption==info_tables[1]) then
					if not image.help_tips then
						image.help_tips = {}
						local box_w = 275*con
						local fix_screen_x = 60*con

						if v.box.x-fix_screen_x+box_w > screen.x-60*con then fix_screen_x = v.box.x-fix_screen_x+box_w-screen.x+fix_screen_x+60*con end

						image.help_tips.bg = DrawRound(v.box.x-fix_screen_x,v.box.y+17*con,box_w,56*con,Enum.COLOR_BLACK,-1,true,10*con)
						image.help_tips.header = DrawText(image.help_tips.bg.x+15*con,image.help_tips.bg.y+20*con,Enum.COLOR_HEADER,"",F16,true)
						image.help_tips.line = DrawRect(image.help_tips.header.x, image.help_tips.header.y+dota.GetTextSize(F16,"T").y+2,	box_w - 29*con,2,0x404040ee,0)
						image.help_tips.line2 = DrawRect(image.help_tips.header.x, image.help_tips.header.y+dota.GetTextSize(F16,"T").y+2,	box_w - 29*con,2,0x404040ee,0,false)

						image.help_tips.discr = {}
						image.help_tips.icons = {}
						image.help_tips.icons_bg = {}

						image.help_tips.y_ = dota.GetTextSize(F14,"N").y
						for z = 1,MAX_LINES do
							image.help_tips.discr[z] = DrawText(image.help_tips.header.x,image.help_tips.header.y+22*con,0xccccccff,"",F14,false)
						end

						local linesIcons = DiscriptionMainDrawImages(info_tables,image,con)

						local helper = DiscriptionMainProcessText(linesIcons,F14,con)

						image.help_tips.bg.x = v.box.x-fix_screen_x
						image.help_tips.bg.y = v.box.y + (m ~=2 and 17*con or 20*con)
						image.help_tips.bg.h = 52*con+(image.help_tips.y_)*#helper

						image.help_tips.header.x = image.help_tips.bg.x+15*con
						image.help_tips.header.y = image.help_tips.bg.y+12*con
						image.help_tips.header.text = info_tables[1]

						image.help_tips.line.x = image.help_tips.header.x
						image.help_tips.line.y = image.help_tips.header.y+dota.GetTextSize(F16,"T").y+2
						image.help_tips.line2.x = image.help_tips.header.x

						local icon_count, last_line = DisciptionMainProcessPositions(helper,image,F14,con)

						local count  = 0
						local menegar_down = 0
						local separate_down = 0

						AddOptionInfoLikeSpellForRanges(info_tables[1])

						local opt_manager = OptionManeger()
						for z,d in ipairs(opt_manager) do
							if d[1] == info_tables[1] then
								image.help_tips.hold = DrawRect(image.help_tips.bg.x+image.help_tips.bg.w-25*con, image.help_tips.bg.y+15*con,	12*con,12*con,0xffffff50,0)
								image.help_tips.hold2 = DrawRect(image.help_tips.bg.x+image.help_tips.bg.w-25*con-2, image.help_tips.bg.y+15*con+2,	12*con,12*con,0xffffff50,0)
								local OptionArray = d[2]
								count = count + 1
								image.help_tips.bg.h = image.help_tips.bg.h + 33*con
								image.help_tips.line2.y = image.help_tips.header.y + image.help_tips.y_*last_line+15*con image.help_tips.line2.visible = true
								image.help_tips[count] = {}
								image.help_tips[count].combo = true

								if d.ally_bar then
									OptionArray = OptionArray..GetCurrentHeroesStrImage(main.myHero:GetTeamIndex(),main.myHero:GetPlayerId())
								elseif d.enemy_bar then
									OptionArray = OptionArray..GetCurrentHeroesStrImage(main.myHero:GetEnemyTeam(),nil,#OptionArray>0)
								end

								local help_y = image.help_tips.header.y + image.help_tips.y_*last_line + count*25*rate
								local combo_count = 0
								local comTab = image.help_tips[count]

								local dogCount = 0
								for k in string.gmatch(OptionArray,'%S+') do
									if k:sub(1,1)=="@" then
										dogCount = dogCount +1
									end
								end
								dogCount = math.min(dogCount,9)
								comTab[0] = DrawRect(image.help_tips.bg.x + image.help_tips.bg.w/2 - 5*con - dogCount*((const_20+5*con+1)/2) ,help_y-2,1,1,0xffffff00,0)

								local defolt_off = d[3]

								for k in string.gmatch(OptionArray,'%S+') do
									if k:sub(1,1)=="@" then

										combo_count = combo_count + 1

										comTab[#comTab+1] = DrawOptionManagerImage(d[1], k, comTab[0], comTab[#comTab], help_y,combo_count,const_20,con)

										if AutoEvadeBlockManager(comTab[#comTab].textureName,"scripts/config/AOManager.txt") then											
											IButtonSet(comTab[#comTab],defolt_off)
										elseif defolt_off then
											IButtonSet(comTab[#comTab],false)
										end
									end
								end

								if combo_count > 9 then
									local nextLine = math.ceil(combo_count/9)-1
									image.help_tips.bg.h = image.help_tips.bg.h +28*con*nextLine
									menegar_down = 28*con*nextLine
								end

								break
							end
						end
						
						for z,d in ipairs(main.page_help) do

							if (d[3] == info_tables[1] or (info_tables.is_base_combo and d.bc_extra)) and (not d.hide_on or setting[d.hide_on]) then
								count = count + 1
								if not image.help_tips[count] then
									if d.full_line then separate_down = separate_down + 8*con end 
									local help_y = image.help_tips.header.y + image.help_tips.y_*last_line + count*25*rate + menegar_down + separate_down																		
									local is_visible = not d.bc_extra or d.arrow == true

									image.help_tips[count] = {}
									image.help_tips[count].owner_panel = d[3]
									image.help_tips[count].button =  DrawRect(image.help_tips.header.x,help_y,16*rate,16*rate,Enum.WHITE,CBTexture(true),is_visible)
									image.help_tips[count].discription = DrawText(image.help_tips.header.x+37*rate,help_y,Enum.COLOR_EXTRA,"",F14,is_visible)
									image.help_tips[count].sub_line = DrawLine(image.help_tips.header.x+16*rate/2, help_y, image.help_tips.header.x+16*rate/2, help_y-9*rate, 0x454A53ff,3*rate,d.sub==true)
									image.help_tips[count].full_line = DrawRect(image.help_tips.line.x, help_y-9*rate-0.5, box_w - 29*con,2, 0x404040ee,0,d.full_line==true)

									image.help_tips[count].key_bg = DrawRect(image.help_tips.header.x+18*rate,help_y,16*rate,16*rate,Enum.COLOR_KEY_BG_NORMAL,GetTextureId("NtUI/other/input_box.png"),is_visible)
									image.help_tips[count].key = DrawText(image.help_tips.header.x+23*rate,help_y+1,Enum.WHITE,"",F13,false) --key

									image.help_tips[count].option_name = DrawText(1,2,Enum.WHITE,"",F13,false)
									image.help_tips[count].draw_procent = DrawText(image.help_tips.header.x+25*rate+1,help_y+1,Enum.WHITE,"",F13,false)
									image.help_tips[count].key_show = DrawText(image.help_tips.header.x+25*rate+2,help_y+1,Enum.WHITE,"",F13,false)
									
									image.help_tips[count].draw_procent.center = true
									image.help_tips[count].key_show.center = true

									image.help_tips[count].just_button = d.button
									image.help_tips[count].just_arrow = d.arrow
									image.help_tips[count].linked_off = d.linked_off
									image.help_tips[count].hide_option = d.hide_option
									image.help_tips[count].bonus_line = d.bonus_line

									if d.list then
										image.help_tips[count].just_list = {}
									end

									if count == 1 then
										image.help_tips.line2.y = image.help_tips.header.y + image.help_tips.y_*last_line+15*con
										image.help_tips.line2.visible = true
									end
								end

								image.help_tips[count].discription.color = (d.red and Enum.COLOR_TEXT_DANG_OPTIONS) or Enum.COLOR_EXTRA

								local help_new = DiscriptionHelpDrawImages(d[2],image,con,not d.bc_extra, d[1])    

								-- Если нету бинда сдвиг
								if d[4]=="" then
									image.help_tips[count].discription.x = image.help_tips[count].discription.x - 15*rate
									image.help_tips[count].key_bg.visible = false
								else
									if IsProcentOrNumber(d) then
										image.help_tips[count].is_number_box = true

										image.help_tips[count].discription.x = image.help_tips[count].discription.x + 10*con
										image.help_tips[count].key_bg.w = image.help_tips[count].key_bg.w +10*con
										image.help_tips[count].draw_procent.x = image.help_tips[count].draw_procent.x +6*con

										image.help_tips[count].is_procent = d.procent
										image.help_tips[count].is_big_number = d.big_number
										image.help_tips[count].is_mid_number = d.mid_number
										image.help_tips[count].is_on_off = d.on_off
										image.help_tips[count].is_only_2 = d.only_2
										image.help_tips[count].draw_procent.visible = not d.bc_extra
										image.help_tips[count].draw_procent.text = ProcentText(d[4],image.help_tips[count])
										image.help_tips[count].draw_procent.color = Enum.COLOR_PROCENT
									else
										image.help_tips[count].key_show.visible = not d.bc_extra
									end 
								end

								if keys[d[1]] then
									image.help_tips[count].key.text = keys[d[1]]
									image.help_tips[count].key_show.text = KeyCode(keys[d[1]],true)
								elseif d[4]~="" then
									image.help_tips[count].key.text = d[4]
									image.help_tips[count].key_show.text = KeyCode(image.help_tips[count].key.text,true)
								end

								-- Описание текст
								image.help_tips[count].discription.text = help_new
								if dota.GetTextSize(F14,help_new).x > box_w - (image.help_tips[count].key_bg.visible and 62*con or 50*con) then 
									image.help_tips[count].discription.font = F13
									image.help_tips[count].discription.y = image.help_tips[count].discription.y + 1
								end 

								-- Иконки
								icon_count = DiscriptionHelpProcessText(image,help_new,icon_count,count,image.help_tips[count].discription.font,con)

								image.help_tips[count].discription.text = string.gsub(help_new, "@", "　 ")
								image.help_tips[count].option_name.text = d[1]

								if count == 1 then image.help_tips.bg.h = image.help_tips.bg.h + 5*con end

								if image.help_tips[count].discription.visible then
									image.help_tips.bg.h = image.help_tips.bg.h + 25*con + (d.full_line and 8*rate or 0)
								end

								if image.help_tips[count].just_list then

									local new_list = d.list
									if d.list_ally then
										new_list = new_list..GetCurrentHeroesStrImage(main.myHero:GetTeamIndex(),d.no_self and main.myHero:GetPlayerId() or nil)
									elseif d.list_enemy then
										new_list = new_list..GetCurrentHeroesStrImage(main.myHero:GetEnemyTeam(),nil,#new_list>0)
									end

									local help_y = image.help_tips[count].key.y + 23*rate
									local comTab = image.help_tips[count].just_list
	
									local dogCount = 0
									for k in string.gmatch(new_list,'%S+') do
										if k:sub(1,1)=="@" then
											dogCount = dogCount +1
										end
									end
									dogCount = math.min(dogCount,9)
									comTab[0] = DrawRect(image.help_tips.bg.x + image.help_tips.bg.w/2 - 5*con - dogCount*((const_20+5*con+1)/2) ,help_y-2,1,1,0xffffff00,0)
	
									local combo_count = 0

									for k in string.gmatch(new_list,'%S+') do
										if k:sub(1,1)=="@" then	
											combo_count = combo_count + 1	
											comTab[#comTab+1] = DrawOptionManagerImage(d[1], k, comTab[0], comTab[#comTab], help_y,combo_count,const_20,con)	
											comTab[#comTab].visible = image.help_tips[count].button.visible
											if AutoEvadeBlockManager(comTab[#comTab].textureName,"scripts/config/AOManager.txt") then											
												IButtonSet(comTab[#comTab],false)
											else
												IButtonSet(comTab[#comTab],true)
											end
										end
									end

									menegar_down = menegar_down + 26*rate * math.ceil(combo_count/9)
									if not d.bc_extra then
										image.help_tips.bg.h = image.help_tips.bg.h + 26*rate * math.ceil(combo_count/9) + 1
									end
								end

								if d.arrow then
									ToJustArrow(image.help_tips[count].button)
									image.help_tips[count].button.x = image.help_tips[count].button.x + image.help_tips.bg.w/2 - 30*con
								elseif d.button then 
									ToJustButton(image.help_tips[count].button)
								else
									CBSet(image.help_tips[count].button, not setting[d[1]])
								end
							end
						end

						if info_tables[1]=="AutoEvade" then
							if not image.help_tips.extra then
								image.help_tips.extra = {}
								image.help_tips.extra.name="AutoEvade"

								local temp_spell = GetAllHeroesSpells(main.myHero:GetTeamIndex())
								local panes_bg_size = 250*con

								for x=1,3 do
									local evade = main.page_extra[x]
									local e_tab = {}

									local lock_pos = {}
									if x == 1 then
										lock_pos.x = image.help_tips.bg.x - (panes_bg_size + 1)
										lock_pos.y = image.help_tips.bg.y-20*con
									elseif x == 2 then
										lock_pos.x = image.help_tips.bg.x - (panes_bg_size + 1)*2
										lock_pos.y = image.help_tips.bg.y+math.ceil(#GetAllKVData(3)/8)*26*con+30*con+1
									else
										lock_pos.x = image.help_tips.bg.x - (panes_bg_size + 1)*2
										lock_pos.y = image.help_tips.bg.y -20*con
									end

									image.help_tips.extra[x] = {}
									image.help_tips.extra[x].bg = DrawRound(lock_pos.x,lock_pos.y,250*con,50*con,Enum.COLOR_BLACK,-1,true,10*con)
									image.help_tips.extra[x].txt = DrawText(image.help_tips.extra[x].bg.x+image.help_tips.extra[x].bg.w/2,image.help_tips.extra[x].bg.y+14*con,0xccccccff,evade.show_name,F14,true)
									image.help_tips.extra[x].txt.center = true
									image.help_tips.extra[x].hilite = {}

									local func=GetAllKVData(x)

									for y,u in ipairs(func) do
										e_tab[#e_tab+1] = u.AbilityName
										for o,p in ipairs(temp_spell) do
											if p==u.AbilityName then
												image.help_tips.extra[x].hilite[y] = true
												break
											end
										end
									end

									evade.tab = e_tab
									image.help_tips.extra[x].bg.h = image.help_tips.extra[x].bg.h+math.ceil(#e_tab/8)*26*con

									for g,h in ipairs(e_tab) do

										local off_spell = setting[evade.pref..""..h] == true

										local w_ = 23*con
										local pre = h

										local y_= math.floor(g/8-0.1)
										local new_xx = ((g == 1 or math.fmod(g,8) == 1) and image.help_tips.extra[x].bg.x+24*con) or image.help_tips.extra[x][g-1].x+26*con

										image.help_tips.extra[x][g] = DrawRect(new_xx,image.help_tips.extra[x].txt.y+20*con+26*con*y_,w_,w_,IButtonColor(not off_spell),GetTextureId2(h))
										image.help_tips.extra[x][g].textureName = pre
										--AutoEvade here
										if image.help_tips.extra[x].hilite[g] or h:sub(1,4) == "item" then
											image.help_tips.extra[x].hilite[g] = DrawRect(image.help_tips.extra[x][g].x-1,image.help_tips.extra[x][g].y-1,25*con,25*con,off_spell and Enum.COLOR_RED or Enum.WHITE,0)
											RoundedImage(image.help_tips.extra[x].hilite[g],6*con,Enum.COLOR_ROUNDED,2*con)
										end

									end

								end
								--Рисует пример
								local tip = image.help_tips.extra[1][169]
								if tip then
									DrawSettingDodgeListMenu(image.help_tips.extra,tip,true)
								end

							end
						elseif info_tables[1]=="ComboMaker" or info_tables[1]=="ComboMaker2" then
							if not image.help_tips.extra then
								image.help_tips.extra = {}
								image.help_tips.extra.name=info_tables[1]
								image.help_tips.extra[1] = {}
								local cmaker = image.help_tips.extra[1]
								local increase = 0
								if info_tables[1]=="ComboMaker2" then
									increase = 103*rate
								end
								cmaker.bg = DrawRound(image.help_tips.bg.x+5*con,image.help_tips.line2.y-5*con+increase,box_w,170*con,Enum.COLOR_BLACK,-1,false,10*con)
								cmaker.txt = DrawText(cmaker.bg.x+cmaker.bg.w/2,cmaker.bg.y+10*con,0xccccccff,"",F14,false)
								cmaker.hilite = {}
								cmaker.name={}
								local siz = 25*con
								local inv_count = 0
								image.help_tips.bg.h = image.help_tips.bg.h+100*con+increase/3
								if image.help_tips[1] and image.help_tips[1].button and increase==0 then
									image.help_tips[1].button.visible = false
								end

								if info_tables[1]=="ComboMaker2" and GameMode()==Enum.GAME_MODE_CUSTOM and not setting["ComboMakerOmg4+2"] then
									local full_count = 0 		
									for g = 1, Enum.SLOT_SPELL_MAX do
										local sp = main.myHero:GetAbility(g)
										if sp and not sp:IsHidden() and not HasFlag(sp:GetBehavior(),2) and sp:GetName() ~= "plus_high_five" then
											full_count = full_count +1
										end 
									end				
									full_count = (siz-1*con)
									for g = 1, Enum.SLOT_SPELL_MAX do
										local sp = main.myHero:GetAbility(g)
										if sp and not sp:IsHidden() and not HasFlag(sp:GetBehavior(),2) and sp:GetName() ~= "plus_high_five" then
											inv_count = inv_count +1
											cmaker.name[inv_count] = sp:GetName()
											cmaker[inv_count] = DrawRound(cmaker.bg.x+(siz-1*con)*inv_count-15*con+full_count,cmaker.txt.y+3*con,siz-3*con,siz-3*con,Enum.WHITE,GetTextureId2(sp:GetName()),true,6*con)
										end
									end
								elseif main.myName ~= "invoker" or (main.myHero:GetAbility(1) and main.myHero:GetAbility(1):GetName()~="invoker_quas") then
									for g = 1, Enum.SLOT_SPELL_VISIBLE do
										local sp = main.myHero:GetAbility(g)
										if sp and not sp:IsHidden() and not HasFlag(sp:GetBehavior(),2) then
											cmaker.name[g] = sp:GetName()
											cmaker[g] = DrawRound(cmaker.bg.x+(siz+8*con)*g,cmaker.txt.y+3*con,siz,siz,Enum.WHITE,GetTextureId2(sp:GetName()),true,6*con)
										else
											cmaker[g] = DrawRound(cmaker.bg.x+(siz+8*con)*g,cmaker.txt.y+3*con,siz,siz,Enum.WHITE,EMPTY_IMAGE,true,6*con)
										end
									end
									inv_count = Enum.SLOT_SPELL_VISIBLE
								else
									for g = 1, Enum.SLOT_SPELL_NORMAL do
										local sp = main.myHero:GetAbility(g)
										if sp and sp:GetMaxLevel()==1 and sp:IsBase() then
											inv_count = inv_count +1
											cmaker.name[inv_count] = sp:GetName()
											cmaker[inv_count] = DrawRound(cmaker.bg.x+(siz-1*con)*inv_count-15*con,cmaker.txt.y+3*con,siz-3*con,siz-3*con,Enum.WHITE,GetTextureId2(sp:GetName()),true,6*con)
										end
									end
								end
								--
								local inv = main.myHero:GetInventory()
								local invXX = 20*con
								if main.myName == "invoker" then
									invXX = 10*con
								end
								for ig = 0, Enum.SLOT_ITEM_NORMAL + 1 do
									local sp = inv:GetItemInSlot(ig > Enum.SLOT_ITEM_NORMAL and Enum.SLOT_NEUTRAL or ig)
									local g = ig + 1
									local texture = nil
									if sp and not HasFlag(sp:GetBehavior(),2) then
										cmaker.name[g+inv_count] = sp:GetName()
										texture = GetTextureId2(sp:GetName())
									else
										texture = GetTextureId2("item_emptyitembg")
									end
									cmaker[g+inv_count] = DrawRound(cmaker[1].x+(siz+7*con)*g-(siz+invXX),cmaker[1].y+(siz+5*con),
									(siz+2*con),(siz-4*con),Enum.WHITE,texture,true,6*con)
								end

								for g = 1,10 do
									if g > 8 then
										cmaker.hilite[g] = DrawRound(cmaker.bg.x+(siz+5*con)*(g-4)-(siz+8*con),cmaker[#cmaker].y+(siz*2+15*con),
										siz,siz-3*con,Enum.WHITE,EMPTY_IMAGE,true,6*con)
									else
										cmaker.hilite[g] = DrawRound(cmaker.bg.x+(siz+5*con)*g-18*con,cmaker[#cmaker].y+(siz+10*con),
										siz,siz-3*con,Enum.WHITE,EMPTY_IMAGE,true,6*con)
									end
								end

								local tab = ReadLines(dota.GetLuaPath().."scripts/config/"..info_tables[1]..".txt")
								for g,tt in ipairs(tab) do
									tt = split(tt,":")
									if tt[1] == main.myName then
										for o = 1,10 do
											if tt[o+1] and tt[o+1]~="nil" then
												if tt[o+1]:sub(1,4)~="item" then
													cmaker.hilite[o].textureId = GetTextureId2(tt[o+1])
													cmaker.hilite[o].w =siz-3*con
													cmaker.hilite[o].textureName =tt[o+1]
												else
													cmaker.hilite[o].textureId = GetTextureId2(tt[o+1])
													cmaker.hilite[o].w =siz
													cmaker.hilite[o].textureName =tt[o+1]
												end
											end
										end
									end
								end
								image.help_tips.extra.size_spell = siz-3*con
								image.help_tips.extra.size_item = siz
								image.help_tips.line3 = DrawRect(image.help_tips.header.x, image.help_tips.extra[1].hilite[1].y-10*con,box_w-29*con,2,0x404040ee,0,true)
								image.help_tips.link = DrawRect(image.help_tips.extra[1].hilite[9].x-(siz+5*con),image.help_tips.extra[1].hilite[9].y,siz+13*con,siz-3*con,Enum.WHITE,GetTextureId("NtUI/other/break_linkin.png"))
							end
						elseif info_tables[1]=="Spell" or info_tables[1]=="Spell#2" then
							image.help_tips.extra = {}
							image.help_tips.extra.name=info_tables[1]
							image.help_tips.extra[1] = {}
							image.help_tips.extra[1].bg = DrawRound(image.help_tips.bg.x,image.help_tips.line2.y-5*con,box_w,50*con,Enum.COLOR_BLACK,-1,false,10*con)
							image.help_tips.extra[1].txt = DrawText(image.help_tips.extra[1].bg.x+image.help_tips.extra[1].bg.w/2,image.help_tips.extra[1].bg.y+10*con,0xccccccff,"",F14,false)
							image.help_tips.extra[1].hilite = {}
							image.help_tips[1].button.visible = false

							local SpellN = 1 if info_tables[1]:sub(-1) == "2" then SpellN = 2 end
							local SpellC = 2 if SpellN == 2 then SpellC = 1 end
							local siz = 23*con
							local spcount = 0

							for g = 1, Enum.SLOT_SPELL_MAX do
								local sp = main.myHero and main.myHero:GetAbility(g)
								if sp then
									local spname = PrettyName(sp:GetName())
									local info = GetFastInfo(spname)
									if info and ((info.Damage and not info.KillStealIgnore and not info.OverTimeDmg and not info.OverTimeDmgEx) or info.KSDuration or info.KSRofl) and image[3].extra[SpellC].textureName ~=spname then
										spcount = spcount + 1
										local spxx = image.help_tips.extra[1].bg.x+(siz+8*con)*spcount+60*con
										image.help_tips.extra[1][spcount] = DrawRound(spxx,image.help_tips.extra[1].txt.y,siz,siz,IButtonColor(false),GetTextureId2(spname),true,6*con,ScrollColor(false),2)
										image.help_tips.extra[1][spcount].textureName = spname
										IButtonSet(image.help_tips.extra[1][spcount], image[3].extra[SpellN].textureName == spname)
									end
								end
							end
							if spcount == 0 then
								-- image.help_tips.bg.h = image.help_tips.bg.h - 26*con
								-- image.help_tips.line2.visible = false
							end
						
						elseif info_tables.panel_ally or info_tables.panel_enemy then 
							image.help_tips.extra = {}
							image.help_tips.extra.name = info_tables.panel_ally and "PanelAlly" or "PanelEnemy"
							image.help_tips.extra[1] = {}
							image.help_tips.extra[1].bg = DrawRound(image.help_tips.bg.x,image.help_tips.line2.y-5*con,box_w,50*con,Enum.COLOR_BLACK,-1,false,10*con)
							image.help_tips.extra[1].txt = DrawText(image.help_tips.bg.x+15*con,	image.help_tips.bg.y+image.help_tips.bg.h,0xccccccff,main.use_on,F14,false)
							image.help_tips.extra[1].hilite = {}

							local enemy = info_tables.panel_enemy
							local temp = {}
							local playerId = {}
							local resurs = dota.PlayerResource.GetInstance()

							for t = 0,9 do
								local pl = dota.GetPlayerByPlayerId(t)
								if pl and ((not enemy and pl:IsTeamEnt(main.myHero)) or (enemy and not pl:IsTeamEnt(main.myHero))) then
									playerId[t] = true
									if pl:GetHeroObject() then
										if (not info_tables.remove_self or pl:GetHeroObject():GetIndex()~=main.myHero:GetIndex()) then
											temp[#temp+1] = pl:GetHeroObject():GetName()
										end
									else
										local resursID = resurs:GetHeroId(t)
										if resursID>0 and resursID < 160 then
											temp[#temp+1] = FindHero(resursID)
										end
									end
								end
							end

							for w,e in ipairs(dota.FindEntities(dota.kDotaBaseNPCHero)) do
								if not e:IsIllusion() then
									local pl = e:GetPlayerId()
									if pl>-1 and pl<10 and playerCache[pl] and not playerId[pl] and ((not enemy and e:IsTeamEnt(main.myHero)) or (enemy and not e:IsTeamEnt(main.myHero))) then
										temp[#temp+1] = playerCache[pl]..":"..e:GetName()..":"..pl
									end
								end
							end

							image.help_tips.bg.h = image.help_tips.bg.h + 26*con+3*con
							local aio_tab = ReadLines(dota.GetLuaPath().."scripts/config/AOManager.txt")

							for g,h in ipairs(temp) do
								local color = Enum.WHITE
								local playerHero = h
								if g == 1 then
									image.help_tips.extra[1][g] = DrawRect(image.help_tips.extra[1].bg.x+16*con,image.help_tips.bg.y+image.help_tips.bg.h-30*con,20*con,20*con,color,
									GetTextureId2(playerHero,true))
								else
									image.help_tips.extra[1][g] = DrawRect(image.help_tips.extra[1][g-1].x+23*con,image.help_tips.bg.y+image.help_tips.bg.h-30*con,20*con,20*con,color,
									GetTextureId2(playerHero,true))
								end
								image.help_tips.extra[1][g].textureName = info_tables[1].."@"..h
								if table.find(aio_tab,function(x) return x == info_tables[1].."@"..h end) then
									image.help_tips.extra[1][g].color = 0x707070ff
								end
							end

						elseif info_tables[1]=="Help" then
							local line_num = 4
							image.help_tips.discr[line_num].color = Enum.COLOR_HEADER
							image.help_tips.discr[line_num+1].color = Enum.COLOR_TEXT_ABOUT_BAN
							image.help_tips.discr[line_num+2].color = Enum.COLOR_TEXT_ABOUT_BAN
							image.help_tips.discr[line_num+3].color = Enum.COLOR_TEXT_ABOUT_BAN
							image.help_tips.discr[line_num+4].color = Enum.COLOR_TEXT_ABOUT_BAN
							image.help_tips.discr[line_num+5].color = Enum.COLOR_HEADER
							for z = line_num+6,MAX_LINES do
								image.help_tips.discr[z].color = Enum.COLOR_TEXT_LOW
								if image.help_tips.discr[z].text:find(":") then
									image.help_tips.discr[z].color = Enum.COLOR_HEADER
									image.help_tips.discr[z].text = image.help_tips.discr[z].text:gsub("@"," ")
									image.help_tips.discr[z].x = image.help_tips.discr[z].x+8*con
								end
							end
						end

					end

					draw_help = true
					break
				end
			end
		end
	end

	DestroyOptionWindow(draw_help)

	inmenu.MoveMenuViaMouseScroll()

	main.refresh.color = IButtonColor(IsMouseOnButton(main.refresh))
	main.refresh.visible = not ScrollIsEnable(image.scroll[3])

end

function OnInterfaceUpdate()
	if not ShowMenu then return end
	if image.anim_bg then image.anim_bg:Start() end 
end

function OnInterfaceKey(msg,code)

	if dota.IsShopSearch() or dota.IsConOpen() then return end

	if dota.IsChat() then
		if msg == 513 and IsMouseOnButton(main.btn) then
			dota.ExecuteCommand("cl_chat_active 0")
		else
			return
		end
	end

	if msg == Enum.WHEEL then
		if not setting["CameraCtrMouse"] then 
			if dota.IsKeyDown(Enum.KEY_CTRL) then 
				local current = math.clamp(camera.GetCameraDistance() + (code == -7864312 and -100 or 100),Enum.CAMERA_STANDART,Enum.CAMERA_MAX)
				if current ~= main.camera_distance then
					main.camera_distance = current
					WriteLines(dota.GetLuaPath().."scripts/config/CamRange.txt",{main.camera_distance})
					camera.SetCameraDistance(main.camera_distance)
				end
				return true
			end 
		end		
		if code == 7864320 then		
			if inmenu.SetOptionBind(0,1) then 
				return true
			end	
			if ShowMenu and MoveScroll(math.min(main.scroll_num+1,4)) then
				return true
			end
		elseif code == -7864320 then
			if inmenu.SetOptionBind(0,-1) then 
				return true
			end	
			if ShowMenu and MoveScroll(math.max(main.scroll_num-1,1)) then
				return true
			end
		end
		DrawOutWindows(code == 7864320)
	elseif msg == Enum.L_MOUSE then
		cache_key[Enum.L_MOUSE] = dota.GetTick()+150
		IsMouseDown = true
		if IsMouseOnButton(main.btn) then
			ShowMenu = not ShowMenu
			if ShowMenu then
				DrawInterface(true)
				VisibleInterface(true,main.scroll_num)
				LoadInterfaceSetting()
			else
				DrawInterface(false)
			end
			Callback("show_menu",ShowMenu)			
			return true

		elseif ShowMenu then
			if image.help_tips then
				if image.help_tips.extra then
					local ex = image.help_tips.extra
					if ex.name == "AutoEvade" then
						if image.help_tips.extra.manage then
							local name = image.help_tips.extra.manage.txt.text
							local moveDodge = image.help_tips.extra.manage

							if moveDodge and moveDodge.txt1 and IsMouseOnButton(moveDodge.txt1) then
								CBSwitch(moveDodge.txt1)
								AutoEvadeBlockManager(name,"scripts/config/AEMBlock.txt",true)
								CallbackExtra("AEMBlock",name)
								return true
							end
							-- Тут редачить
							if moveDodge and moveDodge.reset_rect and IsMouseOnButton(moveDodge.reset_rect) then

								local filt = table.filter(image.help_tips.extra.manage,function(x) return x.textureName ~= 'null' end)
								local mapped = table.map(filt,function(x) return x.textureName end)

								AutoEvadeManagerRemove(name,mapped)
								CallbackExtra("AEMBlockRemove",mapped,name)

								local IsMain = ex.manage.is_main_bg
								
								for z,evade in ipairs(filt) do									
									evade.color = IButtonColor(InterfaceChecker(name,evade.textureName,IsMain))
								end
								DrawHightLight()
								return true
							end

							for z,evade in ipairs(image.help_tips.extra.manage) do
								if IsMouseOnButton(evade) then
									local meth = ""
									local IsMain = ex.manage.is_main_bg
									local fn = (InterfaceChecker(name,evade.textureName,IsMain) and "Remove") or "Add"

									if IButtonIsEnable(evade) then
										evade.color = IButtonColor(false)
										meth = AutoEvadeManager(fn,evade.textureName,name)
									else
										evade.color = IButtonColor(true)
										meth = AutoEvadeManager(fn,evade.textureName,name)
									end
									CallbackExtra("AutoEvadeManager",meth..":"..evade.textureName..":"..name)
									return true
								end
							end
						end
						for z,evade in ipairs(main.page_extra) do
							if IsMouseOnButton(ex[z].bg) then
								for i,v in ipairs(ex[z]) do
									if IsMouseOnButton(v) then
										local name = evade.pref..""..evade.tab[i]

										if IButtonIsEnable(v) then
											v.color = IButtonColor(false)
											if ex[z].hilite[i] then	ex[z].hilite[i].color = Enum.COLOR_RED end
											local tab = ReadLines(dota.GetLuaPath()..evade.path) tab[#tab+1] = name
											WriteLines(dota.GetLuaPath()..evade.path,tab)
											setting[name] = true
											Callback(name,true)
										else
											v.color = IButtonColor(true)
											if ex[z].hilite[i] then	ex[z].hilite[i].color = Enum.WHITE end

											local tab = ReadLines(dota.GetLuaPath()..evade.path)

											for i,v in ipairs(tab) do 
												if v == name then 
													table.remove(tab,i) 
													break 
												end 
											end

											WriteLines(dota.GetLuaPath()..evade.path,tab)
											setting[name] = nil
											Callback(name,false)
										end
										return true
									end
								end
							end
						end
					elseif ex.name == "ComboMaker" or ex.name == "ComboMaker2" then
						if not image.help_tips.extra.cursor then
							for z,ab in ipairs(ex[1]) do
								if IsMouseOnButton(ab) then
									image.help_tips.extra.show = ex[1].name[z]
									image.help_tips.extra.last = nil
									break
								end
							end
							for z,ab in ipairs(ex[1].hilite) do
								if IsMouseOnButton(ab) and ab.textureName and ab.textureName~="null" then
									image.help_tips.extra.show = ab.textureName
									image.help_tips.extra.last = z
									break
								end
							end
						elseif ComboMakerManager(ex,nil,ex.name) then
							return true
						end
						ComboMakerManager(ex,true,ex.name)
					elseif ex.name == "Spell" or ex.name == "Spell#2" then
						local spellN = 1 if ex.name:sub(-1) == "2" then spellN = 2 end
						local onicon = nil
						for z,ab in ipairs(ex[1]) do
							if IsMouseOnButton(ab) then
								if not IButtonIsEnable(ab) then
									IButtonSet(ab,true)
									image[3].extra[spellN].textureId = GetTextureId2(ab.textureName)
									image[3].extra[spellN].textureName = ab.textureName
									IButtonSet(image[3].extra[spellN], not setting["ks"..ab.textureName])	
								else
									IButtonSet(ab,false) 
									ab.border = 0
									image[3].extra[spellN].textureId = EMPTY_IMAGE
									image[3].extra[spellN].textureName = "doom_bringer_empty1"		
									IButtonSet(image[3].extra[spellN],true)							
								end
								AutoEvadeBlockManager(ab.textureName,"scripts/config/KSManager.txt",true)
								onicon = z
							end
						end

						if onicon then
							for z,ab in ipairs(ex[1]) do
								if z ~= onicon and ab.color == Enum.WHITE then
									ab.color = Enum.COLOR_OFF
									AutoEvadeBlockManager(ab.textureName,"scripts/config/KSManager.txt",true)
								end
							end
							CallbackExtra("KSManager",1)
							main.killSpell = GetKillStealInfo(main.myHero)
							return
						end
					elseif ex.name == "HeroALL" then
						for z,ab in ipairs(ex[1]) do
							if IsMouseOnButton(ab) then
								if not ex[1].hilite[1] then
									ex[1].hilite[1] = DrawRect(ab.x-1,ab.y-1,22*con,22*con,Enum.COLOR_OFF,-1)
								else
									ex[1].hilite[1].x =ab.x-1
									ex[1].hilite[1].y = ab.y-1
								end
								Callback(ex.name2,ab.textureName)
								return true
							end
						end
					elseif ex.name == "PanelAlly" or ex.name == "PanelEnemy" then
						for z,ab in ipairs(ex[1]) do
							if IsMouseOnButton(ab) then
								if not AutoEvadeBlockManager(ab.textureName,"scripts/config/AOManager.txt",true) then
									ab.color = 0x707070ff
								else
									ab.color = Enum.WHITE
								end
								CallbackExtra("AOManager",ab.textureName)
								return true
							end
						end
					end
				end
				for z = 1, MAX_EXTRA_OPTIONS do
					if image.help_tips[z] then
						if image.help_tips[z].combo then
							for i,v in ipairs(image.help_tips[z]) do
								if IsMouseOnButton(v) then
									IButtonSwitch(v)
									AutoEvadeBlockManager(v.textureName,"scripts/config/AOManager.txt",true)
									CallbackExtra("AOManager",v.textureName)
									return
								end
							end
						else 
							if image.help_tips[z].just_list then 
								for i,v in ipairs(image.help_tips[z].just_list) do
									if IsMouseOnButton(v) then
										IButtonSwitch(v)
										AutoEvadeBlockManager(v.textureName,"scripts/config/AOManager.txt",true)
										CallbackExtra("AOManager",v.textureName)
										return
									end
								end
							end
							if IsMouseOnButton(image.help_tips[z].button) then
								local name = image.help_tips[z].option_name.text
								if image.help_tips[z].just_arrow then
									ToJustArrow(image.help_tips[z].button,z,image.help_tips,con, image.help_tips[z].bonus_line)
								end							
								if image.help_tips[z].just_button then 
									NewButtonCallback(name)
									return true
								end
								setting[name] = not setting[name]
								-- Добавить линк на выключение
								CBSet(image.help_tips[z].button, not setting[name] )
								ExtraButtonLocalize(image.help_tips[z].owner_panel,name)

								DisableLinkedOptions(image.help_tips[z].button,image.help_tips[z].linked_off,name)

								local full_tab = Collect(main.page_help,name,image.help_tips[z].owner_panel)
								WriteLines(dota.GetLuaPath().."scripts/config/Extra_Option.txt",full_tab)
								if image.help_tips[z].hide_option then
									main.reoption = image.help_tips[z].owner_panel
									DestroyOptionWindow()
									OnInterfaceTick()
									main.reoption = nil
								end 
								return true
							end
						end
					end
				end
			end

			if image.scroll then
				local patch = {"UI","Items","Common",main.myName}
				for a,s in ipairs(image.scroll) do
					if ScrollIsEnable(s) then
						for i, v in ipairs(image[a]) do
							if IsMouseOnButton(v.box) then
								
								local name = (a ~= 2 and v.text.text) or main.page2[i][1]

								local tab = main[tostring("page"..a)]
								if tab[i] and tab[i].button then 
									NewButtonCallback(name)
									return true 
								end 

								setting[name] = not setting[name]

								if a ~= 2 then
									CBSet(v.box, not setting[name])
								else 
									IButtonSet(v.box, not setting[name])
								end

								local full_tab = Collect(tab,name)
								WriteLines(dota.GetLuaPath().."scripts/config/"..patch[a]..".txt",full_tab)
								MainButtonLocalize(name,v)
								return true
							end
						end
						if a == 2 then
							for z = 1, 6 do
								if IsMouseOnButton(image[a].extra[z].img) and image[a].extra[z].img.textureName ~= "doom_bringer_empty1" then
									if IButtonIsEnable(image[a].extra[z].img) then
										IButtonSet(image[a].extra[z].img,false)
										local tab = ReadLines(dota.GetLuaPath().."scripts/config/range_display.txt")
										for i,v in ipairs(tab) do if v == image[a].extra[z].img.textureName then table.remove(tab,i) break end end
										WriteLines(dota.GetLuaPath().."scripts/config/range_display.txt",tab)
										keys["range_display"] = keys["range_display"] - 2^z
										Callback("range_display",true,keys["range_display"])
									else
										IButtonSet(image[a].extra[z].img,true)
										--image[a].extra[z].img.border = Enum.WHITE
										local tab = ReadLines(dota.GetLuaPath().."scripts/config/range_display.txt") tab[#tab+1] = image[a].extra[z].img.textureName
										WriteLines(dota.GetLuaPath().."scripts/config/range_display.txt",tab)
										keys["range_display"] = keys["range_display"] + 2^z
										Callback("range_display",true,keys["range_display"])
									end
									return true
								end
							end
						elseif a == 3 then
							for z,sp in ipairs(main.evadeSpell) do--z = 6,9 do -- main.evadeSpell
								local img_e = image[a].extra2[z]
								if z < 5 and img_e and IsMouseOnButton(img_e) then 
									if IButtonIsEnable(img_e) then
										IButtonSet(img_e,false)
										local tab = ReadLines(dota.GetLuaPath().."scripts/config/DODGE_FLAG.txt") tab[#tab+1] = sp.AbilityName
										WriteLines(dota.GetLuaPath().."scripts/config/DODGE_FLAG.txt",tab)
										keys["auto_evade_flag"] = keys["auto_evade_flag"] + 2^z
										Callback("auto_evade_flag",true,keys["auto_evade_flag"])
									else
										IButtonSet(img_e,true)
										local tab = ReadLines(dota.GetLuaPath().."scripts/config/DODGE_FLAG.txt")
										for i,v in ipairs(tab) do
											if v == sp.AbilityName then
												table.remove(tab,i) break
											end
										end
										WriteLines(dota.GetLuaPath().."scripts/config/DODGE_FLAG.txt",tab)
										keys["auto_evade_flag"] = keys["auto_evade_flag"] - 2^z
										Callback("auto_evade_flag",true,keys["auto_evade_flag"])
									end
									return true
								end
							end
							for z,sp in ipairs(main.killSpell) do--z = 6,9 do
								local img_e = image[a].extra[z]
								local ksname = img_e.textureName
								if IsMouseOnButton(img_e) then --"doom_bringer_empty1"
									if IButtonIsEnable(img_e) then
										IButtonSet(img_e,false)
										local tab = ReadLines(dota.GetLuaPath().."scripts/config/KillStealer.txt")
										tab[#tab+1] = ksname
										WriteLines(dota.GetLuaPath().."scripts/config/KillStealer.txt",tab)
										setting["ks"..ksname] = true
										Callback("ks"..ksname,true)
									else
										IButtonSet(img_e,true)
										local tab = ReadLines(dota.GetLuaPath().."scripts/config/KillStealer.txt")
										for i,v in ipairs(tab) do
											if v == ksname then
												table.remove(tab,i)
											end
										end
										WriteLines(dota.GetLuaPath().."scripts/config/KillStealer.txt",tab)
										setting["ks"..ksname] = false
										Callback("ks"..ksname,false)
									end
									return true
								end
							end
						end
					end

				end
			end

			if IsMouseOnButton(main.refresh) and main.refresh.visible then
				OnNewHero(nil,999)
			else
				inmenu.SetOptionBind(0,1,true)
			end

		end
	elseif msg == Enum.L_MOUSE_UP then
		IsMouseDown = false
	elseif msg == Enum.R_MOUSE then
		if ShowMenu and image.help_tips and image.help_tips.extra then
			local tip = image.help_tips.extra
			if tip.name == "ComboMaker" or tip.name == "ComboMaker2" then
				ComboMakerManager(image.help_tips.extra,true,tip.name)
				return true
			elseif tip.name == "AutoEvade" then
				for z,evade in ipairs(main.page_extra) do
					if IsMouseOnButton(tip[z].bg) then
						for i,v in ipairs(tip[z]) do
							if IsMouseOnButton(v) then
								DrawSettingDodgeListMenu(tip,v)
							end
						end
						return true
					end
				end
			end
		end
	elseif msg == Enum.KEY_DOWN then 

		inmenu.SetOptionBind(code,false)

	elseif msg == Enum.WHEEL_DOWN then
		if dota.GetTick() < fix_cam_bug then
			return true
		end
	end
end

function OnInterfaceKey2(msg,code)
	if msg == 513 then	--L_MOUSE_Down
		cache_key[513] = dota.GetTick()+125
		IsMouseDown = true
	elseif msg == 514 then
		IsMouseDown = false
	end
end

--// Draw/Load
function LoadInterfaceSetting()

	local luapath = dota.GetLuaPath()
	local lines = ReadLines(luapath.."scripts/config/UI.txt")


	--// UI (page 1)
	if #lines == 0 then
		setting["Test1234"] = true
		lines = WriteLines(luapath.."scripts/config/UI.txt",Collect(main.page1)) or {}
	end

	for i,line in ipairs(lines) do
		local table1 = line:split()
		setting[table1[1]] = (table1[2] == "true")
	end

	for z,array in ipairs(main.page1) do
		if setting[array[1]] == nil then setting[array[1]] = true end --// new option will disable
		for a,v in ipairs(image[1]) do
			if v.text.text == array[1] then
				if array.button then
					setting[array[1]] = true
					ToJustButton(v.box)
				else
					CBSet(v.box,not setting[array[1]])
				end
				if array[1] == "Help" then
					v.text_show.color = Enum.COLOR_HEADER				
				elseif array[1] == "SkinChanger" and not dota.IsSkinChangerOn() then
					v.text_show.color = Enum.COLOR_KEY_BG_NORMAL		
				elseif array[1] == "MouseSim" and Enum.INCREASE_ORDER_SMOOTH then
					v.text_show.color = Enum.COLOR_HEADER
				end
				break
			end
		end
	end

	--// Items (page 2)
	local safe_item = table.filter(Collect(main.page2),function(v) return v ~= "orchid:false" and v ~= "sheepstick:false" and v ~= "cyclone:false" end)

	lines = ReadLines(dota.GetLuaPath().."scripts/config/Items.txt",safe_item)
	for i,line in ipairs(lines) do
		local table1 = line:split()
		setting[table1[1]] = (table1[2] == "true")
	end

	for i,array in ipairs(main.page2) do

		if setting[array[1]] == nil then
			setting[array[1]] = true
		end

		for a,v in ipairs(image[2]) do
			if v.box.textureName == tostring(array[2]) then
				IButtonSet(v.box,setting[array[1]] ~= true)
				break
			end
		end
	end

	--// Range_display
	keys["range_display"] = 0 setting["range_display"] = true
	lines = ReadLines(luapath.."scripts/config/range_display.txt")

	for i,line in ipairs(lines) do
		for a = 1, 6 do
			if image[2].extra[a] and image[2].extra[a].img.textureName == line then
				IButtonSet(image[2].extra[a].img,true)
				--image[2].extra[a].img.border = Enum.WHITE
				keys["range_display"] = keys["range_display"] + 2^a
				break
			end
		end
	end

	--// AutoEvade
	keys["auto_evade_flag"] = 0 setting["auto_evade_flag"] = true
	lines = ReadLines(luapath.."scripts/config/DODGE_FLAG.txt")
	for i,line in ipairs(lines) do
		for a,x in ipairs(main.evadeSpell) do
			if line == x.AbilityName and a < 5 then
				IButtonSet(image[3].extra2[a],false)
				keys["auto_evade_flag"] = keys["auto_evade_flag"] + 2^a
				break
			end
		end
	end

	--// KillStealer
	lines = ReadLines(luapath.."scripts/config/KillStealer.txt")
	for i,line in ipairs(lines) do
		for a,x in ipairs(main.killSpell) do
			if line == x.name then
				IButtonSet(image[3].extra[a],false)
				setting["ks"..x.name] = true
				break
			end
		end
	end

	--// Extra_Option_DODGE
	main.page_help_cache = {}
	for i,v in ipairs(main.page_extra) do
		for a, x in ipairs(ReadLines(luapath..v.path)) do
			setting[x] = true
			main.page_help_cache[#main.page_help_cache+1] = x
		end
	end

	--// Common (page 3)
	lines = ReadLines(luapath.."scripts/config/Common.txt")
	if #lines == 0 then
		setting["AutHex"] = true
		setting["Hit&Run"] = true
		setting["ManaAbuz"] = true
		setting["TreeChanger"] = true
		lines = WriteLines(luapath.."scripts/config/Common.txt",Collect(main.page3)) or {}
	end

	for i,line in ipairs(lines) do
		local array2 = line:split()
		local name = array2[1]
		setting[name] = (array2[2] == "true")
		if #array2>2 then
			keys[name] = array2[3]
		end
	end

	for i,array in ipairs(main.page3) do
		local name = array[1]
		if setting[name] == nil then setting[name] = true end
		for a,v in ipairs(image[3]) do
			if v.text.text == name then
				CBSet(v.box,setting[name] ~= true)
				local key_bind = array[4]
				if key_bind ~= "" then
					local bind = keys[name]	
					if not bind then bind = key_bind end
					bind = ValidIsNumberBox(array,bind,array[4])
					v.key.text = bind
					v.key_show.text = KeyCode(bind,true)
					keys[name] = bind
					main.page3[i][4] = bind
				else
					v.key_bg.color = Enum.COLOR_EMPTY
					v.text_show.x = v.text_show.x-v.key_bg.w
				end

				if array.red then
					v.text_show.color = Enum.COLOR_TEXT_DANG_OPTIONS
				end
				break
			end
		end
	end

	--// Extra_Option
	lines = ReadLines(luapath.."scripts/config/Extra_Option.txt")
	if #lines == 0 then
		for i, v in ipairs(main.page_help) do
			if ((v[3]=="AutoEvade" or v[3]=="AutoLastHit" or v[3]=="ShowMore" or v[3]=="ForestMH" or v[1]=="SpecItems" or v[1]=="OverlayItems" or v[1]== "TowerRng" or v[1]=="DagerRng" or v[1]=="DagerRngAuto" or v[1]=="HitRunMouse") or v.enable) and not v.disable then
				setting[v[1]] = false
			else
				setting[v[1]] = true
			end
			if #v[4] > 0 then
				keys[v[1]] = v[4]
			end
		end
	else
		for i,line in ipairs(lines) do
			local array = split(line,":")
			if array then
				setting[array[1]] = (array[2] == "true")
				if array[3] and array[3]~="" then
					keys[array[1]] = array[3]
				end
			end
		end

		for i,array in ipairs(main.page_help) do
			if setting[array[1]] == nil then
				if array.enable then
					setting[array[1]] = false
				else
					setting[array[1]] = true
					if array[4] ~= "" then
						keys[array[1]] = keys[array[1]] or array[4]
					end

				end
			end
		end

		for i,array in ipairs(main.page_help) do
			if array[4] ~= "" and keys[array[1]] then
				keys[array[1]] = ValidIsNumberBox(array,keys[array[1]],array[4])
				array[4] = keys[array[1]]
			end
		end

	end

	--// Hero (page 4)
	lines = ReadLines(luapath.."scripts/config/"..main.myName..".txt")
	if #lines == 0 then
		for i,array in ipairs(main.page4) do
			setting[array[1]] = true
		end
		lines = WriteLines(luapath.."scripts/config/"..main.myName..".txt",Collect(main.page4)) or {}
	end

	for i,line in ipairs(lines) do
		local array = line:split()
		setting[array[1]] = (array[2] == "true")
		if array[3] then
			keys[array[1]] = array[3]
		end
	end

	for i,array in ipairs(main.page4) do
		if setting[array[1]] == nil then
			if array.enable then
				setting[array[1]] = false
			else
				setting[array[1]] = true
			end
		end
		for i,v in ipairs(image[4]) do
			if v and v.text.text == array[1] then

				if array.button then
					setting[array[1]] = true
					ToJustButton(v.box)
				else
					CBSet(v.box,setting[array[1]] ~= true)				
				end

				if array[1]:startWith("BaseCombo") or array[1] == "BaseUltSettings" or array[1] == "VokerLeftPanel" or array[1] == "meepooCombo" then
					v.text_show.color = Enum.COLOR_EXTRA
				elseif array.red then
					v.text_show.color = Enum.COLOR_TEXT_DANG_OPTIONS
				end
				if array[4] ~= "" then
					local bind = keys[array[1]]
					if not bind then bind = array[4] end
					bind = ValidIsNumberBox(array,bind,array[4])
					if v.key then
						v.key.text = bind
						v.key_show.text = KeyCode(bind,true)
					end
					keys[array[1]] = bind
					main.page4[i][4] = bind
				else
					v.key_bg.color = Enum.COLOR_EMPTY
					v.text_show.x = v.text_show.x-v.key_bg.w
				end				
				break
			end
		end
	end
	-- lines = nil
end

function DrawInterface(bool)

	if not bool then
		image = nil collectgarbage("collect") image = {}
		DrawStaticUI(false)
		return
	end

	if not image.anim_bg and main.event_update then
		image.anim_bg = SeasonalFall:new(main.bg, 100, con, "summer")
	end

	local y_shift = 35*con
	local text_center = main.bg.x+main.bg.w/2
	local y_ = 0
	local y_change = 24*rate
	local new_draw_x = 1
	------------------------------------------------------------1 page--------------------------------------------------
	image[1] = {} --1 page
	image[1].name = DrawText(text_center,main.btn.y+13*con+8*con+y_shift,Enum.WHITE,main.trans_ui,F13,false) image[1].name.center = true
	for i, v in ipairs(main.page1) do
		y_ = image[1].name.y+24*con+(30*con* math.floor(i/4-0.1))
		image[1][i] = {}
		if i == 1 or math.fmod(i,4) == 1 then
			image[1][i].box = DrawRect(main.bg.x+20*con,y_,16*con,16*con,Enum.WHITE,CBTexture(true),false)
		else
			image[1][i].box = DrawRect(image[1][i-1].box.x+110*con,y_,16*con,16*con,Enum.WHITE,CBTexture(true),false)
		end
		image[1][i].text = DrawText(image[1][i].box.x+20*con,y_+1,Enum.WHITE,v[1],F13,false)
		image[1][i].text_show = DrawText(image[1][i].box.x+20*con,y_+1,Enum.WHITE,v[2],F13,false)
	end
	------------------------------------------------------------2 page--------------------------------------------------
	image[2] = {} --2 page
	image[2].name = DrawText(text_center,main.btn.y+13*rate+8*rate+y_shift,Enum.WHITE,main.trans_items,F13,false)	image[2].name.center = true
	for i, v in ipairs(main.page2) do
		y_ = image[2].name.y+28*rate+(25*rate* math.floor(i/12-0.01))
		image[2][i] = {}
		local full_name = v.special and GetTextureId2(v[2]) or GetTextureId2("item_"..v[2])
		if math.fmod(i,12) == 1 then
			image[2][i].box = DrawRound(main.bg.x+18*rate,y_,30*rate,21*rate,Enum.WHITE,full_name,false,6*con)
		else
			image[2][i].box = DrawRound(image[2][i-1].box.x+36*rate,y_,image[2][i-1].box.w,image[2][i-1].box.h,Enum.WHITE,full_name,false,6*con)
		end
		image[2][i].box.textureName = v[2]
	end

	--range_display
	image[2].name2 = DrawText(text_center,image[2][#main.page2].box.y+26*rate,Enum.WHITE,main.range_display_txt,F13,false) image[2].name2.center = true
	image[2].extra = {}
	local count = 0
	local Spell = nil
	for a = 1, 6 do
		if not image[2].extra[a] then
			image[2].extra[a] = {}
			image[2].extra[a].img = DrawRound(text_center-150*rate+a*38*rate,image[2].name2.y+26*rate,28*rate,28*rate,IButtonColor(false), EMPTY_IMAGE,false,6*con)
			image[2].extra[a].img.textureName = "doom_bringer_empty1"
		end
	end

	for a = 1, 8 do
		Spell = main.myHero and main.myHero:GetAbility(a)
		if Spell and not Spell:IsHidden() and not Spell:IsTalant() and not Spell:IsInnate() then		
			local texture = GetTextureId2(Spell:GetName())
			if a == 6 or (a == 7 and image[2].extra[6].img.textureName == "doom_bringer_empty1" and Spell:IsUlt()) then
				image[2].extra[6].img.textureId = texture
				image[2].extra[6].img.textureName = Spell:GetName()
			else
				count = count + 1
				if count < 6 and image[2].extra[count] then
					image[2].extra[count].img.textureId = texture
					image[2].extra[count].img.textureName = Spell:GetName()
				end
			end
		end
	end
	------------------------------------------------------------3 page--------------------------------------------------
	image[3] = {}
	image[3].name = DrawText(text_center,main.btn.y+13*rate+8*rate+y_shift,Enum.WHITE,main.trans_common,F13,false) image[3].name.center = true
	local fix_pos = #main.page3 - 16

	for i, v in ipairs(main.page3) do
		y_change = 24*rate
		image[3][i] = {}

		if i <= #main.page3-4 then
			y_ = image[3].name.y+y_change+(30*rate* math.floor(i/4-0.1))
			if math.fmod(i,4) == 1 then
				image[3][i].box = DrawRect(main.bg.x+20*rate,y_,16*rate,16*rate,Enum.WHITE,CBTexture(true),false)
			else
				image[3][i].box = DrawRect(image[3][i-1].box.x+105*rate,y_,16*rate,16*rate,Enum.WHITE,CBTexture(true),false)
			end
		else
			y_ = image[3].name.y+y_change+(32*rate*4.6)
			if math.fmod(i-fix_pos,4) == 1 then
				image[3][i].box = DrawRect(main.bg.x+30*rate,y_,16*rate,16*rate,Enum.WHITE,CBTexture(true),false)
			else
				image[3][i].box = DrawRect(image[3][i-1].box.x+100*rate,y_,16*rate,16*rate,Enum.WHITE,CBTexture(true),false)
			end
		end
		
		image[3][i].text = DrawText(image[3][i].box.x+37*rate,y_,Enum.WHITE,v[1],F13,false)
		image[3][i].text_show = DrawText(image[3][i].box.x+37*rate,y_+1,Enum.WHITE,v[2],F13,false)
		image[3][i].key_bg = DrawRect(image[3][i].box.x+18*rate,y_,16*rate,16*rate, Enum.COLOR_KEY_BG_NORMAL, GetTextureId("NtUI/other/input_box.png"),false)
		image[3][i].key = DrawText(image[3][i].box.x+26*rate,y_+1,Enum.WHITE,v[4],F13,false)
		image[3][i].key_show = DrawText(image[3][i].box.x+25*rate+new_draw_x,y_+1,Enum.WHITE,KeyCode(v[4],true),F13,false)
		image[3][i].key_show.center = true

		CreateExtraKeyBind(image[3][i],v)

	end
	y_ = image[3].name.y+55*rate+(30*rate* math.floor(9/4-0.1))

	-----------------------------------------------------------------------------------------------------------------------------
	local ks_size = 23*rate
	image[3].name2 = DrawText(text_center-100*rate,y_+25*rate,Enum.WHITE,main.auto_stealer_txt,F13,false) image[3].name2.center = true
	image[3].extra = {} image[3].extra2 = {}
	image[3].extra[1] = DrawRound(image[3].name2.x+40*rate,image[3].name2.y-4*rate,ks_size,ks_size,Enum.WHITE,EMPTY_IMAGE,false,6*con)
	image[3].extra[1].textureName = "doom_bringer_empty1"
	image[3].extra[2] = DrawRound(image[3].extra[1].x+(ks_size+2*rate),image[3].extra[1].y,ks_size,ks_size,Enum.WHITE,EMPTY_IMAGE,false,6*con)
	image[3].extra[2].textureName = "doom_bringer_empty1"

	-----------------------------------------------------------------------------------------------------------------------------
	image[3].name3 = DrawText(image[3].extra[2].x+40*rate,image[3].name2.y,Enum.WHITE,main.auto_evade_txt,F13,false)
	image[3].extra2[1] = DrawRound(image[3].name3.x+50*rate,image[3].extra[1].y,ks_size,ks_size,Enum.WHITE,EMPTY_IMAGE,false,6*con)
	image[3].extra2[2] = DrawRound(image[3].extra2[1].x+(ks_size+2*rate),image[3].extra2[1].y,ks_size,ks_size,Enum.WHITE,EMPTY_IMAGE,false,6*con)
	image[3].extra2[3] = DrawRound(image[3].extra2[2].x+(ks_size+2*rate),image[3].extra2[1].y,ks_size,ks_size,Enum.WHITE,EMPTY_IMAGE,false,6*con)
	image[3].extra2[4] = DrawRound(image[3].extra2[3].x+(ks_size+2*rate),image[3].extra2[1].y,ks_size,ks_size,Enum.WHITE,EMPTY_IMAGE,false,6*con)

	for i,v in ipairs(main.killSpell) do
		image[3].extra[i].textureId = GetTextureId2(v.name)
		image[3].extra[i].textureName = v.name
		RoundedImage(image[3].extra[i],6*con,Enum.COLOR_ROUNDED_LOW,2)
	end

	for i,v in ipairs(main.evadeSpell) do
		if i < 5 then
			image[3].extra2[i].textureId = GetTextureId2(v.AbilityName)
			RoundedImage(image[3].extra2[i],6*con,Enum.COLOR_ROUNDED_LOW,2)
		end
	end
	------------------------------------------------------------4 page--------------------------------------------------
	image[4] = {}
	image[4].name = DrawText(text_center,main.btn.y+13*rate+8*rate+y_shift,Enum.WHITE,main.trans_hero..""..main.myName:gsub("_"," "):upper(),F13,false)	image[4].name.center = true

	if main.myName == "arc_warden" then
		image[4].name.text = "Hero: "..main.myName:gsub("_"," "):upper()..main.arc_warning
	end

	if main.myName == "rubick" then
		image[4].name.x = image[4].name.x - 150*rate
	end

	for i, v in ipairs(main.page4) do

		if main.myName == "rubick" then
			y_ = image[4].name.y-5*con+26*rate*i
			image[4][i] = {}
			if math.fmod(i,3) == 1 then
				image[4][i].box  = DrawRect(main.bg.x+15*rate,y_,16*rate,16*rate,Enum.WHITE,CBTexture(false),false)
			else
				image[4][i].box = DrawRect(image[4][i-1].box.x,y_,16*rate,16*rate,Enum.WHITE,CBTexture(false),false)
			end
		else 
			y_change = 24*rate
			y_ = image[4].name.y+y_change+(30*rate * math.floor(i/3-0.1))
			image[4][i] = {}
			if math.fmod(i,3) == 1 then
				image[4][i].box  = DrawRect( main.bg.x+40*rate,y_,16*rate,16*rate,Enum.WHITE,CBTexture(false),false)
			else
				image[4][i].box = DrawRect(image[4][i-1].box.x+132*rate,y_,16*rate,16*rate,Enum.WHITE,CBTexture(false),false)
			end
		end

		image[4][i].text = DrawText(image[4][i].box.x+37*rate,y_,Enum.WHITE,v[1],F13,false)
		image[4][i].text_show = DrawText(image[4][i].box.x+37*rate,y_,Enum.WHITE,v[2],F13,false)
		image[4][i].key_bg = DrawRect(image[4][i].box.x+18*rate,y_,16*rate,16*rate,Enum.COLOR_KEY_BG_NORMAL,GetTextureId("NtUI/other/input_box.png"),false) 
		image[4][i].key = DrawText(image[4][i].box.x+26*rate,y_+1,Enum.WHITE,v[4],F13,false)
		image[4][i].key_show = DrawText(image[4][i].box.x+25*rate+new_draw_x,y_+1,Enum.WHITE,KeyCode(v[4],true),F13,false)
		image[4][i].key_show.center = true

		CreateExtraKeyBind(image[4][i],v)
	end

	image.scroll = {}
	for i = 1,4 do
		image.scroll[i]= DrawRound(main.bg.x+main.bg.w/2 + i*22*rate - 62*rate,main.bg.y+main.bg.h+10*rate,15*rate,15*rate,ScrollColor(false),-1,false,24,Enum.COLOR_BLACK,2)
		if i == main.scroll_num then
			ScrollSet(image.scroll[i],true)
		end
	end

end

function DestroyOptionWindow(draw_help)
	if image.help_tips and image.help_tips.discr and not draw_help then
		image.help_tips.bg.visible = false
		image.help_tips.header.visible = false
		image.help_tips.line.visible = false
		image.help_tips.line2.visible = false
		if image.help_tips.hold then
			image.help_tips.hold.visible = false
			image.help_tips.hold2.visible = false
		end
		if image.help_tips.line3 then image.help_tips.line3.visible = false end
		if image.help_tips.link then image.help_tips.link.visible = false end
		for i = 1,MAX_LINES do
			image.help_tips.discr[i].visible = false
		end
		for i,v in ipairs(image.help_tips.icons) do
			v.visible = false
		end
		if #image.help_tips > 0 then
			for i,v in ipairs(image.help_tips) do
				for z,x in ipairs(v) do
					x.visible = false
				end
				if v.just_list then
					for z,x in ipairs(v.just_list) do
						x.visible = false
					end
					v.just_list[0] = DestroyImg(v.just_list[0])
				end
				v.button = DestroyImg(v.button)
				v.discription = DestroyImg(v.discription)
				v.sub_line = DestroyImg(v.sub_line)
				v.full_line = DestroyImg(v.full_line)
				v.key_bg = DestroyImg(v.key_bg)
				v.key = DestroyImg(v.key)
				v.option_name = DestroyImg(v.option_name)
				v.draw_procent = DestroyImg(v.draw_procent)
				v.key_show = DestroyImg(v.key_show)
				v.is_procent = false
				v.is_number_box = false
			end
		end
		if image.help_tips.extra then
			if image.help_tips.extra.name == "HeroALL" then
				Callback(image.help_tips.extra.name2,nil)
			end
			if image.help_tips.extra.cursor then image.help_tips.extra.cursor.visible = false end
			if image.help_tips.extra.manage then image.help_tips.extra.manage = nil collectgarbage("collect") end
			for i,v in ipairs(image.help_tips.extra) do
				if v.bg then
					v.bg.visible = false
					v.txt.visible = false
				end
				v.visible = false
				for z,x in ipairs(v) do
					x.visible = false
					if v.hilite[z] then
						v.hilite[z].visible =false
					end
				end
			end
		end
		image.help_tips = nil
	end
end 

function CreateExtraKeyBind(bind_box,v)

	if v.custom then
		bind_box.text_show.color = Enum.COLOR_HEADER
	end

	if not tonumber(v[4]) or not IsProcentOrNumber(v) then 
		return 
	end

	bind_box.key.visible = false
	bind_box.key_show.visible = false
	bind_box.text_show.x = bind_box.text_show.x + 10*con
	bind_box.key_bg.w = bind_box.key_bg.w+10*con

	bind_box.is_procent = v.procent
	bind_box.is_big_number = v.big_number
	bind_box.is_mid_number = v.mid_number
	bind_box.is_number_box = true
	bind_box.draw_procent = DrawText(bind_box.key.x+6*con,bind_box.key.y,Enum.COLOR_PROCENT,ProcentText(v[4],bind_box),F13,false)
	bind_box.draw_procent.center = true

end

function DrawHightLight(pos)
	if not pos then
		if image.highlight_box then
			image.highlight_box.visible = false
			image.highlight_box = nil
		end
		return
	end
	if pos[1] then
		if not image.highlight_box then
			image.highlight_box = DrawRect(0,0,0,0,Enum.WHITE,pos[5],true)
		elseif image.highlight_box.outline ~= (pos[5]==0) then
			 DrawHightLight()
			 return
		end
		image.highlight_box.x = pos[1]
		image.highlight_box.y = pos[2]
		image.highlight_box.w = pos[3]
		image.highlight_box.h = pos[4]
		image.highlight_box.outline = (pos[5]==0)
		if pos[5] > 0 then
			image.highlight_box.textureId = pos[5]
		end
		image.highlight_box.color = (pos[6] or (pos[5]==-1 and 0x00000050 or Enum.COLOR_OFF ))
		if pos.rounded and pos.rounded>0 then
			image.highlight_box.rounded = pos.rounded
			image.highlight_box.color = Enum.COLOR_ROUNDED
		else 
			image.highlight_box.rounded = 4*con
		end
		image.highlight_box.thick = 2
	end
end

function IsEmptyTexture(textureId)
	return textureId ==EMPTY_IMAGE or textureId ==GetTextureId2("item_emptyitembg")
end

--// Out Panel
function DrawOutWindows(mouse_up)

	if save_window.name and not dota.IsShopOpen() then

		if not save_window.loaded then
			save_window.loaded = ReadLines(dota.GetLuaPath().."scripts/config/out_windows.txt")
			for i,v in ipairs(save_window.loaded) do
				local tab = v:split()
				if tab[1] == "pos" then
					if tab[2] and tab[3] then
						save_window.pos = dota.Vector(tab[2],tab[3],0)
					end
				elseif tab[1] == "size" then
					if tab[2] then
						w_img_size = tonumber(tab[2]) or (18*con)
					end
				end
			end
		end

		if mouse_up~=nil and save_window.init and IsMouseOnButton(save_window.img.bg) and (not save_window.last_tick or save_window.last_tick<dota.GetTick()) then
			if mouse_up then
				w_img_size = math.min(35*con,w_img_size + 2)
			else
				w_img_size = math.max(14*con,w_img_size - 2)
			end
			save_window.init = nil
			save_window.last_tick = dota.GetTick()+100
			save_window.img = {}
			ReWriteLines(dota.GetLuaPath().."scripts/config/out_windows.txt","size",tostring(math.ceil(w_img_size)))
			collectgarbage("collect")
		end

		if save_window.img.hold then
			if IsMouseOnButton(save_window.img.hold2) then
				save_window.img.hold.color =Enum.WHITE
				save_window.img.hold2.color =Enum.WHITE
				if IsLMouseDownOnes() then
					save_window.name = nil
					local tab = ReadLines(dota.GetLuaPath().."scripts/config/out_windows_cache.txt")
					for i,v in ipairs(tab) do
						local splits = v:split()
						if splits[1] and splits[1] == main.myName then
							table.remove(tab,i)
						end
					end
					WriteLines(dota.GetLuaPath().."scripts/config/out_windows_cache.txt",tab)
					return
				end
			else
				save_window.img.hold.color =0xffffff50
				save_window.img.hold2.color =0xffffff50
			end

			if IsMouseOnButton(save_window.img.hold3) then
				save_window.img.hold3.color =Enum.WHITE
				if IsLMouseDownOnes() then
					save_window.edit_mode = not save_window.edit_mode
					save_window.init = nil
					save_window.img = {}
					collectgarbage("collect")
					IsMouseDown = false
				end
			else
				if not save_window.edit_mode then
					save_window.img.hold3.color =0xffffff50
				else
					save_window.img.hold3.color =0x9999ff50
					if not IsMouseOnButton(save_window.img.bg) and save_window.edit_mode and not save_window.pre_pos then
						save_window.edit_mode  = false
						save_window.init = nil
						save_window.img = {}
						collectgarbage("collect")
					end
				end
			end

		end

		if IsMouseDown and save_window.img.bg2 and (save_window.pre_pos or IsMouseOnButton(save_window.img.bg2)) then
			if not save_window.pre_pos then
				save_window.pre_pos = dota.GetMousePosition()
			end
			save_window.pos = dota.Vector(save_window.pos.x+dota.GetMousePosition().x-save_window.pre_pos.x,save_window.pos.y+dota.GetMousePosition().y-save_window.pre_pos.y,0)
			save_window.init = nil
			save_window.pre_pos = dota.GetMousePosition()
			save_window.pre_catche = {}
			save_window.img = {}
			collectgarbage("collect")
		elseif save_window.pre_pos then
			save_window.pre_pos = nil
			save_window.pre_catche = nil
			save_window.init = nil
			save_window.img = {}
			collectgarbage("collect")
			ReWriteLines(dota.GetLuaPath().."scripts/config/out_windows.txt","pos",floor(save_window.pos.x)..":"..floor(save_window.pos.y))
		end

		local function OptimazieDrag(check_name,check_file) 
			if not check_file then 
				check_file = "scripts/config/out_windows_edit.txt"
			end			
			if save_window.pre_catche then 			
				if not save_window.pre_catche[check_name..check_file] then 
					save_window.pre_catche[check_name..check_file] = AutoEvadeBlockManager(check_name,check_file)					
				end 
				return save_window.pre_catche[check_name..check_file]
			else 
				return AutoEvadeBlockManager(check_name,check_file)
			end
		end

		if not save_window.init or save_window.init ~= save_window.name then
			local function TransName(name)
				for z = 1,3 do
					local info = main[tostring("page"..z)]
					for i,v in ipairs(info) do
						if v[1] == name then
							return v[2]
						end
					end
				end

				for i,v in pairs(main.page4) do
					if v[1] == name then
						return v[2]
					end
				end
				return name
			end
			save_window.init = save_window.name
			save_window.hide = false

			local bg_x_size = 0
			for z,d in ipairs(OptionManeger()) do
				if d[1] == save_window.init then
					local OptionArray = d[2]
					for k in string.gmatch(OptionArray,'%S+') do
						if k:sub(1,1)=="@" and (save_window.edit_mode or not OptimazieDrag(d[1]..k)) then
							bg_x_size = bg_x_size +1
						end
					end
					break
				end
			end

			local count = 0
			local kef = w_img_size/const_20
			local img_size = w_img_size
			local pre_size_x = (img_size + 5*con*kef)

			if bg_x_size > 9 or bg_x_size==0 then
				bg_x_size = pre_size_x*9 + 36*con
			else			
				bg_x_size = math.max( pre_size_x*bg_x_size + 36*con, math.max(dota.GetTextSize(F14,TransName(save_window.name)).x+65*con))
			end

			save_window.img.bg = DrawRound(save_window.pos.x,save_window.pos.y+17*con,bg_x_size,34*con+img_size,save_window.edit_mode and 0x404040aa or 0x10101075,-1,true,8*con)
			save_window.img.bg2 = DrawRect(save_window.img.bg.x,save_window.img.bg.y,save_window.img.bg.w,30*con,0x101010ff,0,false)
			save_window.img.header = DrawText(save_window.img.bg.x+15*con,save_window.img.bg.y+8*con,Enum.COLOR_HEADER,save_window.name,F14,false)
			save_window.img.header_visible = DrawText(save_window.img.header.x,save_window.img.header.y,Enum.COLOR_HEADER-138,TransName(save_window.name),F14,true)
			save_window.img.line = DrawRect(save_window.img.bg.x+16*con, save_window.img.header.y+dota.GetTextSize(F14,"T").y+2,	save_window.img.bg.w-29*con,2,0x404040ee,0)

			save_window.img.hold = DrawRect(save_window.img.bg.x+save_window.img.bg.w-25*con, save_window.img.bg.y+8*con,	12*con,12*con,0xffffff50,0)
			save_window.img.hold2 = DrawRect(save_window.img.bg.x+save_window.img.bg.w-25*con-2, save_window.img.bg.y+8*con+2,	12*con,12*con,0xffffff50,0)

			save_window.img.hold3 = DrawRect(save_window.img.bg.x+save_window.img.bg.w-45*con-2, save_window.img.bg.y+6*con+2,	12*con,14*con,0xffffff50,GetTextureId("panorama/images/control_icons/edit_png.vtex_c"))

			save_window.img.tip_text = DrawText(save_window.img.header.x,save_window.img.header.y-25*con,Enum.WHITE,main.window_tip,F13,save_window.edit_mode==true)

			if not save_window.pre_pos then
			for z,d in ipairs(OptionManeger()) do				
				if d[1] == save_window.init then
					local OptionArray = d[2]
					count = count + 1
					save_window.img.bg.h = save_window.img.bg.h +5*con
					save_window.img[count] = {}
					save_window.img[count].combo = true

					if d.ally_bar then
						OptionArray = OptionArray..GetCurrentHeroesStrImage(main.myHero:GetTeamIndex(),main.myHero:GetPlayerId())
					elseif d.enemy_bar then
						OptionArray = OptionArray..GetCurrentHeroesStrImage(main.myHero:GetEnemyTeam())
					end

					local help_y = save_window.img.header.y + count*25*rate
					local combo_count = 0
					local comTab = save_window.img[count]

					local dogCount = 0
					for k in string.gmatch(OptionArray,'%S+') do
						if k:sub(1,1)=="@" and (save_window.edit_mode or not OptimazieDrag(d[1]..k)) then
							dogCount = dogCount +1
						end
					end
					dogCount = math.min(dogCount,9)

					comTab[0] = DrawRect(save_window.img.bg.x + (save_window.img.bg.w)/2 - 2*con - dogCount*((img_size+5*con*kef+1)/2),help_y-2,1,1,0xffffff00,0)
					local last_draw = 0
					local defolt_off = d[3]

					for k in string.gmatch(OptionArray,'%S+') do						
						if k:sub(1,1)=="@" then
							local skip = false
							combo_count = combo_count +1

							if not save_window.edit_mode and OptimazieDrag(d[1]..k) then
								combo_count = combo_count - 1
								skip = true
							end

							comTab[#comTab+1] = DrawOptionManagerImage(d[1], k ,comTab[0],comTab[last_draw],help_y,combo_count,img_size,con,true)

							if not skip then
								last_draw = #comTab
							end

							if OptimazieDrag(comTab[#comTab].textureName,"scripts/config/AOManager.txt") then
								IButtonSet(comTab[#comTab],defolt_off)
							elseif defolt_off then
								IButtonSet(comTab[#comTab],false)
							end

							if save_window.edit_mode then
								IButtonSet(comTab[#comTab],not OptimazieDrag(comTab[#comTab].textureName))
								comTab[#comTab].visible = true
							elseif  OptimazieDrag(comTab[#comTab].textureName) then
								comTab[#comTab].visible = false
							end

						end
					end

					if combo_count > 9 then
						local nextLine = math.ceil(combo_count/9)-1
						save_window.img.bg.h = save_window.img.bg.h + (img_size+math.min(5*con,5*con*kef))*nextLine
					end
					break
				end

			end
			end
		end

		if save_window.name == "ArcInfoPanel" and main.myName == "arc_warden" and main.myHero then
			local ult = GetUlt(main.myHero)
			ult = (ult and ult:GetName() == "arc_warden_tempest_double" and ult)

			local archand = ult and ult:GetPropertyInt("C_DOTA_Ability_ArcWarden_TempestDouble","m_hDoubles")
			if archand and archand ~= -1 then
				if not main.arc_clone or main.arc_clone:GetIndex() < 2 or main.arc_clone:GetHandle()~=archand then
					main.arc_clone = dota.EntityToBaseNPCHero(dota.GlobalInstanceManager:GetClientEntityList():GetClientEntityFromHandle(archand))
				end
			else 
				main.arc_clone = nil
			end
			if main.arc_clone then 
				local midas = FindItem(main.arc_clone,"item_hand_of_midas")
				local tp = GetTp(main.arc_clone)
				local function windowsImage(name)
					for k,l in ipairs(save_window.img[1]) do
						if l.textureName and l.textureName == name then
							return l
						end 
					end
				end
				local arr = {midas,tp}
				for z = 1, 2 do 
					local item = arr[z]
					if item then
						local item_name = item:GetName()
						local func_image = save_window.img[1] and windowsImage(save_window.name.."@"..item_name)
						if func_image then
							if not save_window.img[item_name] then 
								save_window.img[item_name] = DrawText(func_image.x+func_image.w/2,func_image.y+func_image.h/4-1,Enum.WHITE,"",F14,true)
								save_window.img[item_name].center = true
							end
							local cd = (item:GetCooldown() > 0 and item:GetCooldown()) or (item:GetCharges() == 0 and item:GetChargeCooldown())
							if cd and cd > 0 then 
								save_window.img[item_name].text = ""..math.ceil(cd)
							else 
								save_window.img[item_name].text = ""
							end
						end 
					end		
				end	
			end
		end

		if save_window.img.bg then
			if IsMouseOnButton(save_window.img.bg) then

				if save_window.hide then
					save_window.hide = false
					if save_window.img[1] then
						for i,v in ipairs(save_window.img[1]) do
							if v.border~=0 then
								v.color = v.color+100
							end
						end
					end
				end

				if IsLMouseDownOnes() and save_window.img[1] then
					for i,v in ipairs(save_window.img[1]) do
						if IsMouseOnButton(v) then
							if save_window.edit_mode then
								IButtonSwitch(v)
								AutoEvadeBlockManager(v.textureName,"scripts/config/out_windows_edit.txt",true)
								return
							elseif v.visible then
								IButtonSwitch(v)
								AutoEvadeBlockManager(v.textureName,"scripts/config/AOManager.txt",true)
								CallbackExtra("AOManager",v.textureName)
								return
							end
						end
					end
				end
			elseif not save_window.hide then
				save_window.hide = true
				if save_window.img[1] then
					for i,v in ipairs(save_window.img[1]) do
						if v.border~=0 then
							v.color = v.color-100
						end
					end
				end
			end
		end

	elseif save_window.img.bg then
		save_window.img = {}
		save_window.init = nil
		collectgarbage("collect")
	end

end
function LoadOutWindows()
	local lines = ReadLines(dota.GetLuaPath().."scripts/config/out_windows_cache.txt")
	for i,array in ipairs(lines) do
		local v = array:split()
		if v[1] and v[1]==main.myName then
			save_window.name = v[2]
		end
	end
end



--// Controle Menu
function GetPageElements(bool,a)
	image[a].name.visible = bool
	if image[a].name2 then	image[a].name2.visible = bool end
	if image[a].name3 then	image[a].name3.visible = bool end
	for i,v in ipairs(image[a]) do
		image[a][i].box.visible = bool
		if image[a][i].text_show then
			image[a][i].text_show.visible = bool
		end
		if image[a][i].key_bg then
			image[a][i].key_bg.visible = bool
		end
		if image[a][i].key_bg_rect then
			image[a][i].key_bg_rect.visible = bool
		end
		-- if image[a][i].key then
			-- image[a][i].key.visible = false
		-- end
		if image[a][i].key_show then
			image[a][i].key_show.visible = bool
		end
		if image[a][i].draw_procent then
			image[a][i].draw_procent.visible = bool
			image[a][i].key_show.visible = false
		end
	end
	if a == 3 then
		for i,v in ipairs(image[a].extra) do
			v.visible = bool
		end
		for i,v in ipairs(image[a].extra2) do
			v.visible = bool
		end
	elseif a == 2 then --range display
		for i, v in ipairs(image[a].extra) do
			v.img.visible = bool
		end
	end
end
function VisibleInterface(bool,show,hide)
	for a,s in ipairs(image.scroll) do
		s.visible = bool
		if hide and hide == a then
			GetPageElements(false,a)
		end
		if show and show == a then
			GetPageElements(true,a)
		end
		if not show and not hide then
			GetPageElements(bool,a)
		end
	end
	DrawStaticUI(bool)
end
function DrawStaticUI(bol)
	main.bg.visible = bol main.refresh.visible = bol
end
function IsLMouseDownOnes()
	if cache_key[513] > dota.GetTick() then
		cache_key[513] = 0
		return true
	else
		return false
	end
end

--// Menu/Setting Helper
function MoveScroll(i)
	VisibleInterface(true,i,main.scroll_num)
	ScrollSet(image.scroll[main.scroll_num],false)
	ScrollSet(image.scroll[i],true)
	main.scroll_num = i
	Callback("scroll",true,i)
end
function Collect(tab, name, extra_key)
	if name then
		Callback(name,setting[name],keys[name],extra_key)
	end
	local new_tab = {}
	for i,v in ipairs(tab) do
		local str = v[1]..":"..stringvalue(setting[v[1]])
		if v[4] then
			str = str..":"..v[4]
		end
		new_tab[i] = str
	end
	return new_tab
end
function OnNewHero(arg,forceupdate)
	if forceupdate and forceupdate==999 then
		Update()
		return
	end
	local id = arg:GetInt("playerid",0)
	if id and dota.GetLocalPlayer() and id == dota.GetLocalPlayer():GetPlayerId() then
		Update()
	end
end
function Update()
	if main.btn then
		main.myHero = dota.GetLocalHero() or GetLocalHero()
		main.myName = main.myHero:GetName():gsub("npc_dota_hero_","")
		AddComboMaker(main.lang,main.myName,"ComboMaker2")
		AddComboMaker(main.lang,main.myName)
		main.page4 = main.page4_[main.myName] or {}
		if main.myHero and main.myHero:GetName() == "npc_dota_hero_rubick" then main.scroll_num = 1 end
		main.evadeSpell = LoadDodgeDataLocalHeroSpells(main.myHero,nil,true)
		main.killSpell = GetKillStealInfo(main.myHero)
		save_window = {name=nil,img={},init=nil,pos=dota.Vector(500,500,0)}
		if ShowMenu then ShowMenu = false DrawInterface(false) end
		DrawInterface(true)
		LoadInterfaceSetting()
		SendSetting()
		DrawInterface(false)
		LoadOutWindows()
	end
end
function SendSetting()
	local str = {}
	str.settings = {}
	str.keys = {}
	for i = 1,4 do
		local tab = main[tostring("page"..i)]
		if tab then
			for i,v in ipairs(tab) do
				if setting[v[1]] ~= nil then
					str.settings[v[1]] = setting[v[1]]
					if keys[v[1]] and keys[v[1]]~="" then
						str.keys[v[1]] = keys[v[1]]
					end
				end
			end
		end
	end

	for i,v in ipairs(main.page_help) do
		if setting[v[1]] ~= nil then
			str.settings[v[1]] = setting[v[1]]
			if keys[v[1]] and keys[v[1]]~="" then
				str.keys[v[1]] = keys[v[1]]
			end
		end
	end

	for i,v in ipairs(main.page_help_cache) do
		str.settings[v] = setting[v]
	end

	for i,v in ipairs(main.killSpell) do
		str.settings["ks"..v.name] = setting["ks"..v.name]
	end

	str.settings["btn"] = main.btn.x str.keys["btn"] = main.btn.y
	str.settings["bg"] = main.bg.x str.keys["bg"] = main.bg.y
	str.settings["range_display"] = true str.keys["range_display"] = keys["range_display"]
	str.settings["auto_evade_flag"] = true str.keys["auto_evade_flag"] = keys["auto_evade_flag"]
	str.settings["scroll"] = true str.keys["scroll"] = 1
	str.settings["spectator"] = OBS_HERO
	dota.SendLocalEvent("interface",JSONs:encode(str))
end
function Callback(name,array,key,extra_key)
	local str = {}
	str.name = name
	str.option = array
	if key and key~="" then
		str.keys = key
	end
	if extra_key then
		str.extra_key = extra_key
	end
	dota.SendLocalEvent("interface",JSONs:encode(str))
end
function CallbackExtra(name,array,key,extra_key)
	local str = {}
	str.name = name
	str.option = array
	if key and key~="" then
		str.keys = key
	end
	if extra_key then
		str.extra_key = extra_key
	end
	dota.SendLocalEvent("1interfaceExtra",JSONs:encode(str))
end
function NewButtonCallback(name)
	if name == "SkinChanger" then 
		dota.ShowSkinPanel()
	elseif name == "FixCurrentSkins" then 
		dota.ReloadCurrentSkinsForHero()
	elseif name == "ClearAutoEvade" then
		WriteLines(dota.GetLuaPath().."scripts/config/DODGE_FLAG.txt",{})
		WriteLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt",{})
		WriteLines(dota.GetLuaPath().."scripts/config/DODGE_PROJECTS.txt",{})
		WriteLines(dota.GetLuaPath().."scripts/config/DODGE_LINEARS.txt",{})
		WriteLines(dota.GetLuaPath().."scripts/config/DODGE_ANIMS.txt",{})
	elseif name == "AutoEvadeHideIcon" then
		if not image.help_tips or not image.help_tips.extra or image.help_tips.extra.name ~= "AutoEvade" then
			return
		end
		local ex = image.help_tips.extra
		for z,evade in ipairs(main.page_extra) do
			for i,v in ipairs(ex[z]) do
				if ex[z].hilite and not ex[z].hilite[i] then
					v.visible = not v.visible
				end 
			end
		end
	end 
end


--// Localize
function Localize(msg,lang)

	local new_msg = " Update ("..msg

	local replacements = ManualTranslation()
	if lang ~= "russian" and lang ~= "schinese" then
		replacements[lang] = {}
	end
	for z = 1,3 do
		local info = main[tostring("page"..z)]
		for i,v in ipairs(info) do
			replacements[lang][v[1]] = v[2]
		end
	end
	for i,v in pairs(main.page4) do
		replacements[lang][v[1]] = v[2]
	end
	new_msg = string.gsub(new_msg,"%S+", replacements[lang])
	return new_msg
end
function LocalizeMenu()
	F13 = dota.CreateFont("Arial",13*con,700*con)
	F14 = dota.CreateFont("Arial",14*con,900*con)
	F16 = dota.CreateFont("Arial",16*con,800*con)
	if main.lang == "russian" then
		main.trans_ui = "Визуальные"
		main.trans_items = "Предметы"
		main.trans_common = "Общее"
		main.trans_hero = "Герой: "
		main.use_on = "Герои: "
		main.move_dodge = "Уворот движением"
		main.move_dodge_only = "Уворот только движением"
		main.auto_stealer_txt = "КиллСтилер : "
		main.auto_evade_txt = "Уворот : "
		main.range_display_txt = "Радиус способностей"
		main.cam_range = "Опасно"
		main.reset_key = "Сброс"
		main.arc_warning = " есть риск бана! (не играйте чаще 1/10 игр)"
		main.window_tip = "Колесом мыши ↕ можно менять размер"
	elseif main.lang == "schinese" then
		F13 = dota.CreateFont("宋体",13*con,500*con)
		F14 = dota.CreateFont("宋体",14*con,500*con)
		F16 = dota.CreateFont("Arial",16*con,700*con)
		main.trans_ui = "用户界面"
		main.trans_items = "物品"
		main.trans_common = "通用"
		main.trans_hero = "英雄: "
		main.use_on = "使用目标: "
		main.move_dodge = "走位躲避技能"
		main.move_dodge_only = "只用走位躲避技能"
		main.auto_stealer_txt = "自动秒杀 : "
		main.auto_evade_txt = "躲避 : "
		main.range_display_txt = "范围显示"
		main.cam_range = "视距=不安全的"
		main.reset_key = "重置设置"
		main.arc_warning = " 使用这些功能很大概率会被封号! (不要玩超过 1/10 的游戏)"
		main.window_tip = "鼠标滚轮 ↕ 改变图标大小"
	else
		main.trans_ui = "UI"
		main.trans_items = "Items"
		main.trans_common = "Common"
		main.trans_hero = "Hero: "
		main.use_on = "Use on : "
		main.move_dodge = "Dodging by moving"
		main.move_dodge_only = "Dodging by moving. (only)"
		main.auto_stealer_txt = "KillStealer : "
		main.auto_evade_txt = "Evade : "
		main.range_display_txt = "Range Display"
		main.cam_range = "Unsafe"
		main.reset_key = "Reset"
		main.arc_warning = " risk of ban! (dont play more than 1/10 games) "
		main.window_tip = "Mouse wheel ↕ changes the size of the icons"
	end

end

function MainButtonLocalize(name,v)
	if name ~= "Languges" then
		return
	end
	if not setting[name] then
		local enums = GetEnums()
		for i,v in ipairs(enums.languages) do
			if setting["l"..v]==false then
				change_lang = v
				return true
			end
		end
	else
		change_lang =language_standart
		return true
	end
end
function ExtraButtonLocalize(panel_name,extra_name)
	if panel_name and panel_name == "Languges" then
		local enums = GetEnums()
		for i,v in ipairs(enums.languages) do
			if "l"..v ~= extra_name then
				setting["l"..v] = true
				for z,x in ipairs(image.help_tips) do
					if x and x[6] and x[6].text == "l"..v then
						x[1].textureId = CBTexture(false)
					end
				end
			end
		end
		if not setting["Languges"] then
			if setting[extra_name] then
				change_lang = language_standart
			else
				change_lang = extra_name:sub(2)
			end
		end
	end
	return true
end

function LoadLang()

	for i,line in ipairs(ReadLines(dota.GetLuaPath().."scripts/config/UI.txt")	) do
		local name = line:split()
		if name[1] and name[1] == "Languges" and name[2]=="false" then
			for z,line2 in ipairs(ReadLines(dota.GetLuaPath().."scripts/config/Extra_Option.txt")) do
				local name_2 = line2:split()
				if name_2[1] and name_2[2]=="false" and table.find(Enum.languages,function(x) return "l"..x==name_2[1] end) then
					return name_2[1]:sub(2)
				end
			end
		end
	end

end

function DisableLinkedOptions(options,list,name)
	if not list or not CBIsEnable(options) then
		return
	end

	for i,v in ipairs(image.help_tips) do
		local name = v.option_name.text
		if table.find(list,function(x) return x ==name end) and not setting[name] then
			setting[name] = true
			CBSet(v.button, false)
			CallbackExtra(name,setting[name],keys[name])
		end 
	end

end 


--// Trash

function PreForImage()
	if not main.autoevade_images then
		main.autoevade_images = {}
	end
	local num = GetAllKVData(1)
	if #main.autoevade_images<#num then
		local limit = 0
		for i,v in ipairs(num) do
			if not main.autoevade_images[i] then
				main.autoevade_images[i] = true
				GetTextureId2(v.AbilityName)
				limit = limit + 1
				if limit > 3 then
					return
				end
			end
		end
	end
end

function InterfaceChecker(info_name,x_name,isMain)
	local me = dota.GetLocalHero()
	local info = GetFastInfo(info_name)
	local x = GetFastInfo(x_name)

	if not info or not x then return false end
	if info.OnlyMoveDodge then return end

	local Dispellable,infoDispellableLow
	local dis =  FindAbilityKvValue(info.AbilityName, "SpellDispellableType")
	if dis:sub(1,21) == "SPELL_DISPELLABLE_YES" then
		Dispellable =  true
		if dis == "SPELL_DISPELLABLE_YES" then
			infoDispellableLow =  true
		end
	end	 --linear
	local datas= FindAbilityKvValue(info.AbilityName,"AbilityBehavior")
	local targetC = datas:find("DOTA_ABILITY_BEHAVIOR_UNIT_TARGET")

	local linear = (info.LinearHandle~=nil or info.ParticleHandle~=nil or info.ModifierHandle~=nil) and not info.LinearNoDodge
	local targetC_Post = (targetC or info.ProjLocLotus) and not info.TargetButPos and not linear
	-- local targetN = datas:find("DOTA_ABILITY_BEHAVIOR_NO_TARGET")
	local abilityType = FindAbilityKvValue(info.AbilityName,"AbilityType"):find("ABILITY_TYPE_ULTIMATE")
	local abilityDamage = FindAbilityKvValue(info.AbilityName,"AbilityUnitDamageType"):find("DAMAGE_TYPE_MAGICAL")
	local abilityCd = FindAbilityKvValue(info.AbilityName,"AbilityCooldown")
	local frendly = FindAbilityKvValue(info.AbilityName,"AbilityUnitTargetTeam")=="DOTA_UNIT_TARGET_TEAM_FRIENDLY"

	if abilityCd then
		local cd = tonumber(abilityCd) or tonumber(split(abilityCd," ")[1])
		if not cd then 
			local cdkey,cdvalue = FindAbilityDEEPKvValue(info.AbilityName, "AbilityCooldown")
			if cdkey and cdvalue then
				cd = tonumber(cdvalue) or tonumber(split(cdvalue," ")[1])
			end
		end
		abilityCd = cd and cd > 6 
	end

	if (info.ProjectileHandle or info.LinearHandle or info.ParticleHandle or info.ShowModifier or info.ModifierHandle or info.EntityHandle) and not isMain then
		if info.IsHaunt then
			return (x.KillIllusion or x.IsHex or IsBlinkName(x.AbilityName)) and (not x.RemoveAbilities or not CheckAbilities(x.RemoveAbilities,info))
		else
			if x.Dodge and (((( (info.IsDisable and not info.NotStun) or info.IsRoot or info.IsDelayDisable or
			(info.IsSilence and not (x.IsItem and (x.IsInvis or x.IsMagicImmune) ))
			or (info.IsMute and not x.IsPhysImmune) or (info.ManaBurn and not (x.IsUnselected and x.IsInvul)) ) and (
			(x.IsBlockDmg and not info.IsRoot and not info.IsHide and not info.IsCyclone and (not x.IsMischif or info.Damage))

			or (x.IsStatusResist and (not x.DispellableLow or not info.IsPurge))
			or (x.IsBlink or (x.IsJump and (not x.IsItem or (info.LinearHandle or info.ShowModifier or info.IsMute))))  --no force vs atos, but force vs nullifier
			or (x.IsEul and (info.NeedEulsSelf or x.IsDisable)) --eul vs ???
			or (x.IsInvul and ((not info.LinearHandle or info.IsMantaDodge) or not x.IsItem or x.IsLowEul)  and not (x.IsItem and info.IsSilence) and not (x.IsUnselected and info.IsCyclone) )
			or (( (x.IsMagicImmune and not (info.ModifierHandle and info.NeedDodge and info.Damage and not info.CanBeBKBDodge)) or (x.IsHeal and (not x.IsItem or not info.IsSilence))) and not info.IsRoot and (not info.ManaBurn or not x.IsItem)) --bkb vs lion!
			or (x.IsDelayDispell and (not info.IsNuke or info.WeakensEnemy))
			or (x.IsPurge and x.ForSelf and infoDispellableLow and (info.IsSilence or info.IsDisable))
			or (x.IsInvis and not info.TrueSight)
			or (x.Knockback and info.BreakByKnock)
			or (x.IsLotus and ((info.LinearHandle and info.IsDisable) or info.ManaBurn)  and targetC_Post)
			)
			)
			--projectile
			or (info.ProjectileHandle and ((x.ProjectileDodge and not info.NoDodgable and not (x.IsItem and (info.IsNuke or info.IsSlow)))  or
				((info.IsDisable or info.IsMute or info.IsNull or info.EBlade or info.ProjLocLotus) and not info.IsRoot  and (x.IsLotus and targetC_Post) ))
				)
			or (info.IsPhysCombo and (x.IsPhysImmune or x.IsInvul))
			or (info.Function and OwnDodgeFilter(info,x,nil,info.Function) and (not x.IsDisable or not info.ShowModifier) and (not x.IsMagicImmune or not (info.ModifierHandle and info.NeedDodge and info.Damage and not info.CanBeBKBDodge)))
			)
			or (info.IsNuke and ((x.NukeDodge or (x.IsBlockDmg and (not x.OnlyIfDmg or info.Damage) and not (x.IsReturnDmg and info.IsMines))))) --vs nuck pack,ember,naix
			or (info.IsNikeLow and x.NukeLowDodge)
			or (info.IsSlow and x.NukeDodge)
			or (x.IsLinken and targetC_Post and not info.NoLotusDodge and not info.IsDelayDisable and not (info.NeedDodge and info.ModifierHandle and info.Delay))
			or (x.AddAbilities and CheckAbilities(x.AddAbilities,info))
			or (x.IsMagicAbsorb and abilityDamage and not info.IsLowDmgNuke and not info.NoEffectInvis and (not info.IsPurge or not x.DispellableLow))
			)
			and (not info.IsRoot or ((not x.IsDispell or EvadeInTabNum(x.AddAbilities,info,2) or x.IsBlink) and not (info.ProjectileHandle and x.IsInvis and info.NoDodgable)))
			and (not info.IsMute or (not x.IsBlockDmg or x.IsItem))
			and (not x.IsUltBuff and not x.OnlyForUlt)
			and (not x.RemoveAbilities or not CheckAbilities(x.RemoveAbilities,info))
			--and (not targetN or ((not x.IsDisable or x.OnlyWithAghanim) and not x.IsRoot and not x.IsSilence))
			and (not info.MagicImmunityPierce or (info.DodgeBkb or not x.IsMagicImmune))
			and (not info.FunctionOnly or OwnDodgeFilter(info,x,me,info.FunctionOnly)) then
				return true
			end
		end
	elseif info.NeedDodge then

		if not info.InstaCast then

			if x.Dodge and ((((info.IsDisable or info.IsRoot or info.UltimateDodge or
			IsLogicHelper("IsSilence",true,info,x) ) and--no manta vs silence
			((x.IsDisable or x.IsSilence
			or (x.IsStatusResist and not info.NoEffectStatusRes)
			or (x.IsInvul and (not targetC or info.IsDisable or info.IsSilence or x.CantDie) and (not x.InvulTime or not info.DurationAOE) and not (x.IsHide and info.IsRoot)) --invul vs no target or bane_e
			or (x.IsBlockDmg and not info.IsHide and not info.IsRoot and not info.IsSleep and (not x.IsMischif or info.Damage) and (not x.IsItem or info.Damage and not info.IsSilence))
			or (x.IsBlink or (x.IsJump and not info.IsRoot and not info.NoJumpDodge))
			or ((x.IsMagicImmune or x.IsHeal) and not info.IsRoot)
			or (x.IsDelayDispell and Dispellable) or (x.IsPurge and x.ForSelf and infoDispellableLow and (info.IsSilence or info.IsDisable)) --slark,oracle
			or (x.ProjectileDodge and info.ProjectileHandle)
			or (x.IsLotus and targetC and not info.NoLotusDodge)
			or (x.Knockback and info.BreakByKnockAnim)
			or (x.IsInvis and not info.TrueSight and (not info.IsAgro or (not info.Radius and not x.FadeTime)))))
			)
			---------------------------------------------------------------------------------------------------------------
			or (info.IsAgro and (x.IsPhysBuff or x.IsVampiric or x.IsDelayDisable))
			or IsLogicHelper("IsPhysCombo",true,info,x)
			or (info.Function and OwnDodgeFilter(info,x,nil,info.Function))
			or (info.IsNuke and ((x.NukeDodge and (not targetC or (info.Speed or info.Delay or frendly))) or (x.IsBlockDmg and (not x.OnlyIfDmg or info.Damage) and not info.IsHide)))
			) --riki,ursa
			or (x.IsLinken and targetC and not info.NoLotusDodge and not frendly)
			or (x.IsLotus and abilityType and abilityCd and targetC and not info.NoLotusDodge  and not frendly)
			or (x.AddAbilities and CheckAbilities(x.AddAbilities,info))
			or (x.IsMagicAbsorb and abilityDamage and not info.IsLowDmgNuke and not info.NoEffectInvis and (not info.IsPurge or not x.DispellableLow))--ember
			)
			and (not x.IsUltBuff or (abilityType and not info.IsUltBuff)) --phoenix
			and (not x.OnlyForUlt or (abilityType and not info.IsRoot)) --to dodge ulti only
			--and (not (x.IsDisable or x.IsSilence or x.IsDelayDisable or x.WeakensEnemy ) or x.MagicImmunityPierce)
			and (not x.RemoveAbilities or not CheckAbilities(x.RemoveAbilities,info))
			and (not info.FunctionOnly or OwnDodgeFilter(info,x,nil,info.FunctionOnly))
			and (not info.UltimateDodge or UltimateDodge(x,info,me)) then
				return true
			end

		elseif (x.IsMagicImmune or x.IsDelayDispell or x.IsLotus or (x.AddAbilities and CheckAbilities(x.AddAbilities,info))) and
				(not x.RemoveAbilities or not CheckAbilities(x.RemoveAbilities,info))
			then
			return true
		end

	end
	return false
end

--// Event
function OnNewOption(msg)
	if not msg then return end
	AddOptionManager(JSONs:decode(msg))
	-- if main.myHero then main.page4 = main.page4_[main.myHero:GetName():gsub("npc_dota_hero_","")] or {}	end
end

function CustomScript(msg)
	if not msg then return end
	CustomScripts(JSONs:decode(msg))
end

function OnEvent(event)
	local name = event:GetName() 
	if name == "map_shutdown" or name == "game_newmap" or (name == "dota_match_done_client" and ObsByPass()) then 
		OnDisconnect(event)
	elseif name == "dota_player_update_assigned_hero" then 
		OnNewHero(event)
	elseif name == "dota_game_state_change" then 
		OnFullConnect(event)
	elseif name == "dota_ad_ban" then 
		OnBan(event)
	end 	
end

function OnDisconnect(arg)
	if main.event_tick then
		main = {}  main.scroll_num = 1 main.block = nil
		image = {} keys = {} setting = {}
		save_window = {name=nil,img={},init=nil,pos=dota.Vector(500,500,0)}
		OBS_HERO = -1
		collectgarbage("collect")
	end
	if arg then 
		aaa("clear interface | "..arg:GetName())
	end
end

function OnFullConnect(msg)
	local stage = msg and msg:GetInt("new_state",0)
	if not msg or stage == Enum.GAME_STATE_HERO_SELECTION then
		for i,v in ipairs(dota.FindEntities(dota.kDotaPlayer)) do
			local id = v:GetPlayerId()
			if IsGoodPlayerId(i) then
				playerCache[id] = v:GetPlayerName()
			end
		end
	end
end

function OnBan(msg)
	if main.myHero or main.pick or Menu.MenuSelectHero()== "" then
		return
	end

	if dota.PlayerResource.GetInstance():GetHeroId(dota.GetLocalPlayer():GetPlayerId()) > 0 then
		return
	end

	if GameMode() == Enum.GAME_MODE_SD then 
		return
	end

	if not msg and GameMode() == Enum.GAME_MODE_ALL_DRAFT then
		return
	end

	if GameMode() == Enum.GAME_MODE_TURBO then
		if msg then
			dota.ExecuteCommand("dota_select_hero "..Menu.MenuSelectHero())
			main.pick = true
			-- aaa("msg pick",true)
		else
			local state = dota.FindEntitiesWithName("C_DOTATurboHeroPickRules")[1]
			if state and state:GetPropertyInt("C_DOTATurboHeroPickRules","m_Phase") == 1 then
				dota.ExecuteCommand("dota_select_hero "..Menu.MenuSelectHero())
				main.pick = true
				-- aaa("pre pick",true)
			end
		end
	else
		dota.ExecuteCommand("dota_select_hero "..Menu.MenuSelectHero())
		main.pick = true
	end
end

function OnAfkPick()
	if main.myHero or main.afk_stop or #Menu.MenuAfkHeroes() == 0 then
		return
	end

	if dota.PlayerResource.GetInstance():GetHeroId(dota.GetLocalPlayer():GetPlayerId()) > 0 then
		return
	end

	if GameMode() == Enum.GAME_MODE_SD then
		return
	end

	local gold = dota.GetLocalPlayer():GetGold()
	local draft_phase = dota.GameRules.GetInstance():GetPropertyFloat("C_DOTAGamerules","m_nAllDraftPhase")

	if not main.afk_gold or draft_phase ~= main.afk_draft_phase then
		main.afk_draft_phase = draft_phase
		main.afk_gold = gold
	end
	
	if not main.afk_pick then
		if gold < main.afk_gold - 33*2 then
			main.afk_gold = gold 
			main.afk_pick = 1
		end
	elseif gold ~= main.afk_gold then
		gold = main.afk_gold
		if Menu.MenuAfkHeroes()[main.afk_pick] then
			dota.ExecuteCommand("dota_select_hero "..Menu.MenuAfkHeroes()[main.afk_pick])
			main.afk_pick = main.afk_pick + 1 
		else
			main.afk_stop = true
		end
	end

end

--// Helper 
local function SaveStart()
	if not main.save_start then 
		if dota.GetLocalHero() then
			main.save_start = dota.GetTick()+100
			return true
		else 
			main.save_start = dota.GetTick()
		end 
	elseif main.save_start > dota.GetTick() then 
		return true
	end
	return false
end 


--//ComboMaker AuroEvade Ranges
function ComboMakerManager(ex,remov,name)
	local path = dota.GetLuaPath().."scripts/config/"..name..".txt"
	for z,ab in ipairs(ex[1].hilite) do
		if IsMouseOnButton(ab) then
			if not remov then
				if image.help_tips.extra.last and ab.textureName~="null" then
					ex[1].hilite[image.help_tips.extra.last].textureName = ab.textureName
					ex[1].hilite[image.help_tips.extra.last].textureId = GetTextureId2(ab.textureName)
					if ab.textureName:sub(1,4)~="item" then
						ex[1].hilite[image.help_tips.extra.last].w =image.help_tips.extra.size_spell
					else
						ex[1].hilite[image.help_tips.extra.last].w =image.help_tips.extra.size_item
					end
				end
				ab.textureId = GetTextureId2(image.help_tips.extra.show)
				if image.help_tips.extra.show:sub(1,4)~="item" then
					ab.w =image.help_tips.extra.size_spell
					ab.textureName =image.help_tips.extra.show
				else
					ab.w =image.help_tips.extra.size_item
					ab.textureName =image.help_tips.extra.show
				end
				local tab = ReadLines(path)
				local new
				for i,v in ipairs(tab) do
					v = split(v,":")
					if v[1] == main.myName then
						new = main.myName
						for z,ab in ipairs(ex[1].hilite) do
							if ab.textureName == "null" then
								new = new..":nil"
							else
								new = new..":"..ab.textureName
							end
						end
						tab[i] = new
						break
					end
				end
				if not new then
					new = main.myName
					for z,ab in ipairs(ex[1].hilite) do
						if ab.textureName == "null" then
							new = new..":nil"
						else
							new = new..":"..ab.textureName
						end
					end
					tab[#tab+1] = new
				end
				WriteLines(path,tab)
				Callback(name.."Manager",true)
				image.help_tips.extra.cursor.visible = false
				image.help_tips.extra.cursor = nil
				image.help_tips.extra.show = nil
				return true
			else
				local tab = ReadLines(path)
				for i,v in ipairs(tab) do
					v = split(v,":")
					if v[1] == main.myName then
						ab.textureId = EMPTY_IMAGE
						ab.w =image.help_tips.extra.size_spell
						ab.textureName = "null"
						local new = main.myName
						for z,ab in ipairs(ex[1].hilite) do
							if ab.textureName == "null" then
								new = new..":nil"
							else
								new = new..":"..ab.textureName
							end
						end
						tab[i] = new
						WriteLines(path,tab)
						Callback(name.."Manager",true)
						return true
					end
				end
			end
		end

	end
	if remov and image.help_tips.extra.cursor then
		image.help_tips.extra.cursor.visible = false
		image.help_tips.extra.cursor = nil
		image.help_tips.extra.show = nil
	end

end

function AutoEvadeManager(str,name,textureName)
	local tab = ReadLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt")
	for i,v in ipairs(tab) do
		local line = split(v,":")
		if line[1] == str and line[2] == name then

			for z = 3,#line do
				if line[z] == textureName then
					table.remove(line,z)
					tab[i] = Summary(line)
					WriteLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt",tab)
					return line[1]
				end
			end

			tab[i] = tab[i]..":"..textureName
			WriteLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt",tab)
			return line[1]
		end
	end
	tab[#tab+1] = str..":"..name..":"..textureName
	WriteLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt",tab)
	return str
end
function AutoEvadeManagerRemove(textureName,array)
	local tab = ReadLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt")
	for i,v in ipairs(tab) do
		local line = split(v,":")
		for a,name in ipairs(array) do 
			if line[2] == name then

				for z = 3,#line do
					if line[z] == textureName then
						table.remove(line,z)						
						tab[i] = Summary(line)
					end
				end
			end

		end
	end
	WriteLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt",tab)
end

function AutoEvadeBlockManager(name,path,check)
	local tab = ReadLines(dota.GetLuaPath()..path)
	local exist = false
	for i,v in ipairs(tab) do
		if v == name then
			if check then
				table.remove(tab,i)
			end
			exist = true
			break
		end
	end

	if check then
		if not exist then
			tab[#tab+1] = name
		end
		WriteLines(dota.GetLuaPath()..path,tab)
	end
	return exist
end

function Summary(tab)
	local txt = tab[1]
	for i = 2,#tab do
		txt = txt..":"..tab[i]
	end
	return txt
end

function DrawSettingDodgeListMenu(tip,v,draw_from_menu)
	local nameN = v.textureName
	if not tip.manage then
		tip.manage = {}
		tip.manage.rect = DrawRound(v.x,v.y,v.w+1,v.h+1,Enum.COLOR_ROUNDED,0,true,4*con,false,3*con)
		tip.manage.bg = DrawRound(v.x-100*con,v.y+26*con,250*con,76*con,0x000000ee,-1,true,8*con,0xffffff50,2)
		tip.manage.bg2 = DrawRect(tip.manage.bg.x+10*con,tip.manage.bg.y+10*con,tip.manage.bg.w-20*con,tip.manage.bg.h-20*con,0xffffff10,0,true)
		tip.manage.txt = DrawText(tip.manage.bg.x+tip.manage.bg.w/2,tip.manage.bg.y+10*con,0xccccccff,nameN,F14,false)
		tip.manage.first = draw_from_menu
		--чтобы знать название

		local info = GetFastInfo(nameN)
		if info then

			if (info.InstaCast or info.EvadeHelp) then
				local textMsg = "Info : "..((language == "schinese" and info.EvadeHelpCn) or info.EvadeHelp or "if ur closest and lvl>5")
				tip.manage.bg.h = tip.manage.bg.h + 24*con
				tip.manage.bg.y = tip.manage.bg.y-3*con
				tip.manage.txt_help = DrawText(tip.manage.bg2.x+5*con,tip.manage.bg2.y+tip.manage.bg2.h+5*con,0xcffffffff,textMsg,F14,true)
			end

			local function NeedAddOption(info)
				return ((info.LinearHandle and not info.Delay) or (info.ShowModifier and not info.ShowMoreNoDodge) or info.IsNoTargetAOE or info.NeedMove)
				and not info.NoMoveDodge or info.EvadeCustomOption
			end

			if NeedAddOption(info) then
				tip.manage.bg.h = tip.manage.bg.h + 23*con
				tip.manage.bg.y = tip.manage.bg.y-3*con
				local down_cuz_help = tip.manage.txt_help and 22*con or 0
				tip.manage.txt1 = DrawRect(tip.manage.bg2.x+5*con,tip.manage.bg2.y+tip.manage.bg2.h+5*con+down_cuz_help,15*con,15*con,Enum.WHITE,0,true)				
				local active = AutoEvadeBlockManager(nameN,"scripts/config/AEMBlock.txt")
				if info.LinearHandle or info.NeedMove or info.EvadeCustomOption then
					CBSet(tip.manage.txt1, not active)
				else
					CBSet(tip.manage.txt1, active)
				end
				tip.manage.txt2= DrawText(tip.manage.txt1.x+25*con,tip.manage.txt1.y+1,0xcffffffff,info.EvadeCustomOption or main.move_dodge,F14,true)
				if info.OnlyMoveDodge then
					tip.manage.txt2.text = main.move_dodge_only
					tip.manage.bg3 = DrawRect(v.x-100*con,v.y+18*con,250*con,76*con,Enum.WHITE,GetTextureId("NtUI/vgui/dashboard/dash_button_drop_shadow.png"),true)
				end
			end	
			
			tip.manage.bg.h = tip.manage.bg.h + 23*con
			tip.manage.reset_rect = DrawRect(tip.manage.bg2.x+5*con,tip.manage.bg.y+tip.manage.bg.h-26*con,15*con,15*con,Enum.WHITE,CBTexture(false),true)	
			tip.manage.reset_text = DrawText(tip.manage.reset_rect.x+25*con,tip.manage.reset_rect.y+1,0xcffffffff,main.reset_key,F14,true)		
		end

		local IsMain = not ((tip[2].bg and IsMouseOnButton(tip[2].bg)) or (tip[3].bg and IsMouseOnButton(tip[3].bg)))

		tip.manage.is_main_bg = IsMain

		local siz = 25*con

		for g = 1, 7 do
			local sp = main.myHero:GetAbility(g)
			if sp and not sp:IsHidden() and not HasFlag(sp:GetBehavior(),2) then
				tip.manage[g] = DrawRect(tip.manage.bg.x+(siz+8*con)*g-20*con,tip.manage.txt.y+3*con,siz,siz,Enum.WHITE,GetTextureId2(sp:GetName()))
				tip.manage[g].textureName = sp:GetName()
				tip.manage[g].color = IButtonColor(InterfaceChecker(nameN,sp:GetName(),IsMain))
				if FindEvadeManager(sp:GetName(),nameN) then ColorSwitch(tip.manage[g],Enum.COLOR_OFF) end
			else
				tip.manage[g] = DrawRect(tip.manage.bg.x+(siz+8*con)*g-20*con,tip.manage.txt.y+3*con,siz,siz,Enum.WHITE,EMPTY_IMAGE)
			end
		end

		local inv = main.myHero:GetInventory()
		for ig = 0, Enum.SLOT_ITEM_NORMAL + 1 do

			local sp = inv:GetItemInSlot(ig > Enum.SLOT_ITEM_NORMAL and Enum.SLOT_NEUTRAL or ig)
			local g = ig + 1
			
			if sp and not HasFlag(sp:GetBehavior(),2) then
				tip.manage[g+6] = DrawRect(tip.manage[1].x+(siz+8*con)*g-(siz+8*con),tip.manage[1].y+(siz+5*con),(siz+1),(siz-6*con),Enum.WHITE,GetTextureId2(sp:GetName()))
				tip.manage[g+6].textureName = sp:GetName()
				tip.manage[g+6].color = IButtonColor(InterfaceChecker(nameN,sp:GetName(),IsMain))
				if FindEvadeManager(sp:GetName(),nameN) then ColorSwitch(tip.manage[g+6],Enum.COLOR_OFF) end
			else
				tip.manage[g+6] = DrawRect(tip.manage[1].x+(siz+8*con)*g-(siz+8*con),tip.manage[1].y+(siz+5*con),(siz+1),(siz-6*con),Enum.WHITE,GetTextureId2("item_emptyitembg"))
			end
		end
	else
		local redraw = (tip.manage.first~=nil)
		tip.manage = nil
		collectgarbage("collect")
		if redraw then
			DrawSettingDodgeListMenu(tip,v)
		end
	end
end
function FindEvadeManager(textureName,name)
	local tab = ReadLines(dota.GetLuaPath().."scripts/config/AutoEvadeManager1.txt")
	for i,v in ipairs(tab) do
		local line = split(v,":")
		if line[2] == textureName then
			for z = 3,#line do
				if line[z] == name then
					return true
				end
			end
		end
	end
	return false
end

function ShowItemsInSettingList(list)
	local str = ""
	for i,v in ipairs(list) do
		str = str.." @"..(v)
	end
	return str
end

function AddOptionInfoLikeSpellForRanges(option_name)
	if option_name == "Radius" then
		local temp = ""
		for i,v in ipairs(dota.FindEntities(dota.kDotaPlayer)) do
			local hero = v:GetAssignedHero()
			local hero_limit = 10
			if hero and not hero:IsTeamEnt(main.myHero) then
				hero_limit = hero_limit - 1	
				local limit = 9
				for a = 1, 8 do				
					local spell = hero:GetAbility(a)
					if spell and not spell:IsHidden() and not spell:IsTalant() and not spell:IsInnate() then
						limit = limit -1
						temp = temp.." @"..spell:GetName()
					end 
				end
				for a = 1,limit do 
					temp = temp.." @doom_bringer_empty1"
				end
				if hero_limit == 0 then 
					break
				end
			end 
		end
		AddOptionManager({"Radius",temp,true})
	end
end 

do AddOptionsManagerInSettings("AutoEvade",ShowItemsInSettingList(Item_Option)) end
do AddOptionsManagerInSettings("LHMarker",ShowItemsInSettingList(LastHitSpells)) end


function OnLoad()

	main.myHero = dota.GetLocalHero() or GetLocalHero()

	if main.myHero then
	
		if SaveStart() then return end

		if not main.myName then

			main.camera_distance = tonumber(ReadLines(dota.GetLuaPath().."scripts/config/CamRange.txt")[1]) or Enum.CAMERA_STANDART
			main.camera_distance = math.clamp(main.camera_distance,Enum.CAMERA_STANDART,Enum.CAMERA_MAX)
			if main.camera_distance ~= Enum.CAMERA_STANDART then camera.SetCameraDistance(main.camera_distance) fix_cam_bug = dota.GetTick()+500 end

			main.lang = language

			main.myName = main.myHero:GetName():gsub("npc_dota_hero_","")
			AddComboMaker(main.lang,main.myName,"ComboMaker2")
			AddComboMaker(main.lang,main.myName)

			main.page1 = Page_1(main.lang)
			main.page2 = Page_2(main.lang)
			main.page3 = Page_3(main.lang)
			main.page4_ = Page_4(main.lang)
			main.page_extra = WindowAutoEvade(main.lang)
			main.page_help = Helps(main.lang)

			main.evadeSpell = LoadDodgeDataLocalHeroSpells(main.myHero,nil,true)
			main.killSpell = GetKillStealInfo(main.myHero)

			main.page4 = main.page4_[main.myName] or {}

			for i,v in ipairs(main.page1) do
				if v[1] == "Help" then
					if not v.old then
						v.old = v[3]
					end
					v[3] = v.old..Localize(UpdateLog(main.lang),main.lang)	break
				end
			end

			local global = 8
			if floor(screen.x/screen.y*100) <= 133 then
				global = 6.65
			elseif floor(screen.x/screen.y*100) <= 160 then
				global = 7
			end

			local bg_texture = GetTextureId("NtUI/vgui/hud/portraitbackground_motion_swoops.png")

			main.btn = DrawRect(screen.x/2+global*HudCreen.top_panel_size*con+12*con,12*con,22*con,22*con,Enum.WHITE,GetTextureId("NtUI/other/squad_orange_mini.png"),true)		
			main.bg =  DrawRound(main.btn.x - 230*con + main.btn.h/2,main.btn.y + 48*con,460*con,212*con,0x050515ee,bg_texture,false,10*con)			
			main.refresh = DrawRect(main.bg.x+main.bg.w-38*con,main.bg.y+main.bg.h-28*con,20*con,20*con,Enum.COLOR_OFF,GetTextureId("NtUI/other/icon_refresh2.png"),false)

			LocalizeMenu()

			FunctionPreCatch()
			DrawInterface(true)
			LoadInterfaceSetting()
			SendSetting()
			DrawInterface(false)
			LoadOutWindows()

			main.event_key = dota.AddKeyEvent(OnInterfaceKey)
			main.event_tick = dota.AddTickEvent(OnInterfaceTick)			
			main.event_update = dota.OnUpdate(OnInterfaceUpdate)			
			
			main.event_disconnect4 = dota.AddLocalEvent("optionManager", OnNewOption)
			if main.event_key2 then
				main.event_key2 = nil
			end
			--endgame = true
			collectgarbage("collect")
		end
	elseif not main.start_ then
		main.start_ = dota.GetTick()+1500
	else

		if dota.GetGameState() == Enum.GAME_STATE_HERO_SELECTION then --HERO_SELECTION

			if not main.start_tick then
				if GameMode() == Enum.GAME_MODE_TURBO then
					main.start_tick = dota.GetTick()+8000
				else
					main.start_tick = dota.GetTick()+13000
				end
			end

			OnBan()
			OnAfkPick()

			if not main.select and main.start_ < dota.GetTick() then
				main.select = true
				local num = Menu.MenuLineSelect()
				if num~= 0 then
					if dota.GetLocalPlayer():IsTeam(Enum.TEAM_RADIANT) then
						if num == 1 then 		num = 3
						elseif num == 3 then 	num = 1
						elseif num == 4 then	num = 5
						elseif num == 5 then	num = 4
						end
					end
					dota.ExecuteCommand("dota_select_starting_position "..num)
				end
			end

			if not main.select2 and main.start_tick < dota.GetTick() and (GameMode()==Enum.GAME_MODE_TURBO) then
				main.select2 = true
				if (Menu.MenuBannedHero()~="") then
					dota.ExecuteCommand("dota_captain_ban_hero "..Menu.MenuBannedHero())
				end
			end

		end

		if dota.GetGameState() == Enum.GAME_STATE_IN_PROGRESS or dota.GetGameState() == Enum.GAME_STATE_PRE_GAME then
			local pl = dota.GetLocalPlayer()
			if pl and (pl:GetPlayerId() == -1 or pl:GetPlayerId()>=10) then

				if not main.spec then
					local rate_y = screen.y/900
					main.spec = d3d.CreateRect(4*rate_y,105*rate_y+25*rate_y,25*rate_y,25*rate_y,0xFFEC97ff,true,d3d.GetTextureId("panorama/images/plus/achievements/spectator_win_probability_icon_png.vtex_c"))
					if not main.event_key2 then
						main.event_key2 = dota.AddKeyEvent(OnInterfaceKey2)
					end
				elseif IsMouseOnButton(main.spec) then
					main.spec.color = 0xFFEC97ff
					if IsLMouseDownOnes() then
						if not spectator then
							local sel = pl:GetPropertyInt("C_DOTAPlayerController","m_hQueryUnit")
							local selection =  dota.GlobalInstanceManager:GetClientEntityList():GetClientEntityFromHandle(sel)
							if selection and selection:IsDotaNPC() and dota.EntityToBaseNPC(selection):GetUnitType()==1 and not dota.EntityToBaseNPCHero(selection):IsIllusion() then
								spectator = true
								OBS_HERO = sel
								main.spec.color = 0xFFEC9799
							end
						else
							spectator = false
							OBS_HERO = -1
						end
					end
				else
					main.spec.color = 0xFFEC9799
				end
			end
		end

	end

end



function Initialize()
	if not main.event_load then
		language = LoadLang() or language_standart
		--if true then return end
		main.event_load = dota.AddTickEvent(OnLoad)
		main.event_disconnect5 = dota.AddLocalEvent("new_interface_option", CustomScript)
		OnFullConnect()
		const_event.event_full = dota.AddFireEventHook(OnEvent)
		OnLoad()
	end
end

