-- New ways hook by MikuAuahDark

Hooks={}
function AddHook(hook,func,prio)	-- it's NOT "addhook"
	if Hooks[hook]~=nil then
		for n,v in pairs(Hooks[hook]) do
			if v==func then
				print("\169255000000WARNING: Hooks already exist(Hook "..hook.." to "..tostring(func)..")")
				return n
			end
		end
		table.insert(Hooks[hook],func)
		for n,v in pairs(Hooks[hook]) do
			if v==func then
				print("\169000255000INFO: Hook successfully added(Hook "..hook.." to "..tostring(func)..")")
				return n
			end
		end
	else
		Hooks[hook]={func}
		addhook(hook,"temporary_"..hook,-32767)
		_G["temporary_"..hook]=function(...)
			for n,v in pairs(Hooks[hook]) do
				local temp
				if type(v)=="function" then
					temp=v(...) or 0
					if temp>=1 then
						return temp
					end
				else
					local f=loadstring("return "..v)()
					temp=f(...) or 0
					if temp>=1 then
						return temp
					end
				end
			end
		end
		print("\169000255000INFO: Hook successfully added(Hook "..hook.." to "..tostring(func)..")")
		return 1
	end
	return 0,"ERROR: Unknown Error"
end

function FreeHook(hook,id)	-- it's NOT "freehook"
	local temp=#(Hooks[hook] or {})
	if temp>1 then
		for n,v in pairs(Hooks[hook]) do
			if n==id then
				print("\169000255000INFO: Hook successfully removed(Hook "..hook.." at "..tostring(Hooks[hook][n])..")")
				Hooks[hook][n]=nil
				return true
			end
		end
		return false
	elseif temp==1 and Hooks[hook][id]~=nil then
		print("\169000255000INFO: Hook successfully removed(Hook "..hook.." at "..tostring(Hooks[hook][id])..")")
		Hooks[hook]=nil
		freehook(hook,"temporary_"..hook)
		return true
	end
	print("\169255000000WARNING: Hook cannot removed, hook with specificed ID cannot be found")
	return false
end