Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Now=SysTime
- local debug=debug
- local table=table
- local backthen=Now()
- local counter=0
- local c={}
- local function infinitetrack()
- if counter>10 then
- debug.sethook()
- counter=0
- ErrorNoHalt"Infinite loop detected: "
- debug.Trace()
- local calls={}
- local prev
- for k,v in pairs(c) do
- local line = tostring(v.func).."\t line: \t"..tostring(v.currentline)
- if prev==line then
- prev=line
- line="^"
- else
- prev=line
- end
- calls[k]=k..': \t'..line
- end
- ErrorNoHalt("\nLast 11 calls:\n"..table.concat(calls,'\n')..'\n')
- c={}
- error("Time limit exceeded",2)
- end
- counter=counter+1
- local info = debug.getinfo(2)
- if info then table.insert(c,info) end
- end
- local f=function()
- if Now()-backthen>7 then -- enjoy your 7 seconds freeze
- counter=0
- debug.sethook(infinitetrack,"",1)
- end
- end
- local function load()
- hook.Add("Think","infinite_loop_protection",function()
- backthen=Now()
- debug.sethook(f,"",2^25)
- end)
- end
- concommand.Add("allow_infinite_loop",function(pl)
- if SERVER and IsValid(pl) then return end
- hook.Remove("Think","infinite_loop_protection")
- debug.sethook()
- end)
- concommand.Add("enable_infinite_loop_protection",function(pl)
- if SERVER and IsValid(pl) then return end
- load()
- end)
- if GetConVarNumber("developer") == 666 then
- print("Ah loading this crap anyway")
- load()
- end
Advertisement
Add Comment
Please, Sign In to add comment