// I/O example by Cyron. Slightly edited by frostiikin, but the vast majority of this is all cyron's doing.
// I/O Support, I don't know how to put them in one file so I make multiple vars
local configplayer--I'm actually not sure if configplayer ever needs to be used tbh, I'm mostly winging it off what I saw in derp code

local function valid(mo)
	return mo and mo.valid
end

local BLUESHOES = "client/xmomentum/blueshoes.dat"--you need a place to save that shit
local FLASH = "client/xmomentum/hyperflash.dat"--you need a place to save that shit
--local EGGMUSICTOGGLE = "client/eggmusictoggle.dat"--you need a place to save that shit
//local FILETWO = "client/whatever.dat DUMMY"
//

//
addHook("ThinkFrame", do--Cyron can't fucking code but this is IO stuff
	if valid(consoleplayer)
		and not valid(configplayer)--i really dont know if this is needed..
		and consoleplayer.blueshoes == nil	--my codes ass backwards so this will always read nil at launch, that won't work for all types of codes probably
			configplayer = consoleplayer --i really dont know if this is needed..
			local file = io.openlocal(BLUESHOES)--check for the file
            if file--do you actually have a file to read
                local num = file:read("*n")--tells the fucker to OPEN UP, use *a for strings, *n for numbers
					if num == 1
						COM_BufInsertText(consoleplayer, "blueshoes ".."on")--tells that fucker to put the value here
					else
						COM_BufInsertText(consoleplayer, "blueshoes ".."off")
					end
				file:close()--perish
            else--bitch where the file
                COM_BufInsertText(consoleplayer, "blueshoes on")--this makes a default if theres no file to read
        end
			local file2 = io.openlocal(FLASH)--check for the file
			--print("FUCK")
            if file2--do you actually have a file to read
			--print("FUCK")
                local num = file2:read("*n")--tells the fucker to OPEN UP, use *a for strings, *n for numbers
					if num == 1
						COM_BufInsertText(consoleplayer, "hyperflash ".."on")--tells that fucker to put the value here
					else
						COM_BufInsertText(consoleplayer, "hyperflash ".."off")
					end
				file2:close()--perish
            else--bitch where the file
                COM_BufInsertText(consoleplayer, "hyperflash on")--this makes a default if theres no file to read
        end
	end
end)


//The Command Shit
local function BlueShoes(player, arg)--Conjunction junction, what's your function?
	if player.mo and player.mo.valid
		if arg
			if arg == "on" or arg == "1" or arg == "true" or arg == "yes"--for the dummy these are numbers, but they can be strings, but you'll have to call the read differently
				player.blueshoes =  1
				CONS_Printf(player, "Tails' shoes are now blue!")
				if io and player == consoleplayer--this section calls to save the data
					local file = io.openlocal(BLUESHOES, "w+")--w+ neans to write and overwrite all data in the file.
					file:write(player.blueshoes)--put that value in the file, idfk how to make boolean functions save so i force put "true" or "false" here cuz im shit
					file:close()--perish
				end
			elseif arg == "off" or arg == "false" or arg == "0" or arg == "no"--same thing but different answer
				player.blueshoes =  2
				CONS_Printf(player, "Tails' shoes are now red!")
				if io and player == consoleplayer
					local file = io.openlocal(BLUESHOES, "w+")
					file:write(player.blueshoes)
					file:close()
				end
			end
		else
			CONS_Printf(player, "Changes the colors of Tails' shoes.")
		end
	else
		CONS_Printf(player, "You aren't in a stage, fuckwit.")
	end
end

COM_AddCommand("blueshoes", function(player, arg)--This adds the command
	BlueShoes(player, arg)--Tells command what function to do
end)



//The Command Shit
local function HyperFlash(player, arg)--Conjunction junction, what's your function?
	if player.mo and player.mo.valid
		if arg
			if arg == "on" or arg == "1" or arg == "true" or arg == "yes"--for the dummy these are numbers, but they can be strings, but you'll have to call the read differently
				player.hyperflash =  1
				CONS_Printf(player, "Hyper Screen-Flashing Enabled.")
				if io and player == consoleplayer--this section calls to save the data
					local file = io.openlocal(FLASH, "w+")--w+ neans to write and overwrite all data in the file.
					file:write(player.hyperflash)--put that value in the file, idfk how to make boolean functions save so i force put "true" or "false" here cuz im shit
					file:close()--perish
				end
			elseif arg == "off" or arg == "false" or arg == "0" or arg == "no"--same thing but different answer
				player.hyperflash =  2
				CONS_Printf(player, "Hyper Screen-Flashing Disabled.")
				if io and player == consoleplayer
					local file = io.openlocal(FLASH, "w+")
					file:write(player.hyperflash)
					file:close()
				end
			end
		else
			CONS_Printf(player, "Enables/Disables Hyper Screen-Flashing.")
		end
	else
		CONS_Printf(player, "You aren't in a stage, fuckwit.")
	end
end

COM_AddCommand("hyperflash", function(player, arg)--This adds the command
	HyperFlash(player, arg)--Tells command what function to do
end)




addHook("PlayerThink", function(p)
	if not p.bot
		if p.mo and p.mo.valid and p.mo.health
			if p.mo.skin == "tails" and p.blueshoes == 1
				p.mo.skin = "blueshoestails"
			end
			if p.mo.skin == "blueshoestails" and p.blueshoes == 2
				p.mo.skin = "tails"
			end
		end
	else
		if p.mo.skin == "tails" and players[0].blueshoes == 1
			p.mo.skin = "blueshoestails"
		end
		if p.mo.skin == "blueshoestails" and players[0].blueshoes == 2
			p.mo.skin = "tails"
		end
	end	
end)