Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.96 KB | None | 0 0
  1.  
  2.  
  3. --[[
  4.  
  5. === HeX's Server Plugins ===
  6.  
  7. HSP_Shared.lua
  8.  
  9. Shared resources
  10.  
  11. ]]
  12.  
  13.  
  14.  
  15.  
  16.  
  17. HSP.RED2 = Color(255,0,0) --More red
  18.  
  19. HSP.RED = Color(255,0,11) --Red
  20.  
  21. HSP.KIRED = Color(255,80,0) --Killicon Red
  22.  
  23.  
  24.  
  25. HSP.GREEN2 = Color(0,255,0) --Green
  26.  
  27. HSP.GREEN = Color(66,255,96) --HSP green
  28.  
  29. HSP.SGREEN = Color(180,250,160) --Source green
  30.  
  31.  
  32.  
  33. HSP.BLUE2 = Color(0,0,255) --Blue
  34.  
  35. HSP.SBLUE = Color(0,255,255) --Blue
  36.  
  37. HSP.BLUE = Color(51,153,255) --HeX Blue
  38.  
  39. HSP.LPBLUE = Color(80,170,255) --Laser pistol blue
  40.  
  41. HSP.PBLUE = Color(155,205,248) --printall blue
  42.  
  43.  
  44.  
  45. HSP.SYELLOW = Color(255,255,0) --LuaError Yellow
  46.  
  47. HSP.YELLOW2 = Color(255,220,0,200) --HEV yellow
  48.  
  49. HSP.YELLOW = Color(255,200,0) --Yellow
  50.  
  51.  
  52.  
  53. HSP.ORANGE = Color(255,153,0) --Respected orange
  54.  
  55. HSP.PINK = Color(255,0,153) --Faggot pink
  56.  
  57.  
  58.  
  59. HSP.PURPLE = Color(149,102,255) --ASK2 purple
  60.  
  61. HSP.KIPURPLE = Color(192,0,192) --Killicon Purple
  62.  
  63. HSP.SVOTE = Color(255,64,96) --Solidvote Purple
  64.  
  65.  
  66.  
  67. HSP.GREY = Color(175,175,175) --Blackops grey
  68.  
  69. HSP.SGREY = Color(192,192,192) --Source grey
  70.  
  71.  
  72.  
  73. HSP.WHITE = Color(255,255,255) --White
  74.  
  75. HSP.WHITE2 = Color(254,254,254) --White2
  76.  
  77.  
  78.  
  79.  
  80.  
  81. function COLCON(...)
  82.  
  83. local color = HSP.WHITE
  84.  
  85. for k, v in pairs( {...} ) do
  86.  
  87. local typ = type(v)
  88.  
  89.  
  90.  
  91. if (typ == "table" && v["b"] && v["g"] && v["r"] ) then
  92.  
  93. color = v
  94.  
  95.  
  96.  
  97. elseif (typ == "Player" and IsValid(v) ) then
  98.  
  99. MsgC( team.GetColor( v:Team() ), v:GetName() )
  100.  
  101.  
  102.  
  103. elseif ( (typ == "Entity" or typ == "Weapon" or typ == "Vehicle" or typ == "NPC" ) and IsValid(v) ) then
  104.  
  105. MsgC( HSP.BLUE, v:GetClass() )
  106.  
  107.  
  108.  
  109. else
  110.  
  111. MsgC(color, tostring(v) )
  112.  
  113. end
  114.  
  115. end
  116.  
  117. MsgC(color, "\n")
  118.  
  119. end
  120.  
  121.  
  122.  
  123. local function DumpColors()
  124.  
  125. for k,v in pairs(HSP) do
  126.  
  127. if type(v) == "table" and v["r"] then --Color
  128.  
  129. COLCON(HSP.SGREY, k.."\t- ", v, "Test buttocks, HSP colors, -=[UH]=- United Hosts")
  130.  
  131. end
  132.  
  133. end
  134.  
  135. end
  136.  
  137. concommand.Add("hsp_colors"..(SERVER and "" or "_cl"), function(p) if p:IsAdmin() then DumpColors() end end)
  138.  
  139.  
  140.  
  141.  
  142.  
  143. //Garry!
  144.  
  145. if not hook.Hooks then
  146.  
  147. hook.Hooks = hook.GetTable()
  148.  
  149. end
  150.  
  151.  
  152.  
  153.  
  154.  
  155. HSP.Contact = "tell HeX (http://steamcommunity.com/id/MFSiNC)"
  156.  
  157. THIS_MAP = game.GetMap():lower()
  158.  
  159. ModDIR = util.RelativePathToFull("."):sub(1,-2):gsub("\\", "/"):Trim("/")
  160.  
  161. _R = debug.getregistry()
  162.  
  163.  
  164.  
  165. local pEntity = FindMetaTable("Entity")
  166.  
  167.  
  168.  
  169. function pEntity:print(str,msg) --Has to be on entity
  170.  
  171. if not IsValid(self) or not self:IsPlayer() then
  172.  
  173. return print(str)
  174.  
  175. end
  176.  
  177.  
  178.  
  179. if not msg then
  180.  
  181. str = str.."\n"
  182.  
  183. end
  184.  
  185. self:PrintMessage(HUD_PRINTCONSOLE, str)
  186.  
  187. end
  188.  
  189.  
  190.  
  191. function pEntity:Msg(str)
  192.  
  193. if not IsValid(self) or not self:IsPlayer() then
  194.  
  195. return Msg(str)
  196.  
  197. end
  198.  
  199.  
  200.  
  201. self:PrintMessage(HUD_PRINTCONSOLE, str)
  202.  
  203. end
  204.  
  205.  
  206.  
  207.  
  208.  
  209. function ValidString(v)
  210.  
  211. return (v and type(v) == "string" and v != "")
  212.  
  213. end
  214.  
  215. HSP.ValidString = ValidString
  216.  
  217. string.IsValid = ValidString --The new way!
  218.  
  219.  
  220.  
  221. function string.Check(str,check)
  222.  
  223. return str:sub(1,#check) == check
  224.  
  225. end
  226.  
  227.  
  228.  
  229. function string.EndCheck(str,check)
  230.  
  231. return str:sub(-1,-#check) == check
  232.  
  233. end
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241. function player.Get(what)
  242.  
  243. what = tostring(what):lower()
  244.  
  245. local match = {}
  246.  
  247.  
  248.  
  249. for k,v in pairs( player.GetAll() ) do
  250.  
  251. local name = v:Name():lower()
  252.  
  253. if (name == what or tonumber(what) == v:EntIndex() or name:find(what)) then
  254.  
  255. table.insert(match,v)
  256.  
  257. end
  258.  
  259. end
  260.  
  261.  
  262.  
  263. return match
  264.  
  265. end
  266.  
  267.  
  268.  
  269. function player.Name(str)
  270.  
  271. return player.Get(str)[1] or NULL
  272.  
  273. end
  274.  
  275.  
  276.  
  277. function epairs(egc)
  278.  
  279. return pairs( ents.FindByClass(egc) )
  280.  
  281. end
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291. function HSP.Time()
  292.  
  293. return os.date("%I:%M:%S%p")
  294.  
  295. end
  296.  
  297. function HSP.Date()
  298.  
  299. return os.date("%d-%m-%y %I:%M:%S%p")
  300.  
  301. end
  302.  
  303. function HSP.DateOnly()
  304.  
  305. return os.date("%d-%m-%y")
  306.  
  307. end
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317. HSP.file = {}
  318.  
  319.  
  320.  
  321. function HSP.file.MakeTreeForFile(path) --Make dir tree, WHY GARRY
  322.  
  323. local Tab = path:Split("/")
  324.  
  325. local Here = ""
  326.  
  327.  
  328.  
  329. for k,v in ipairs(Tab) do
  330.  
  331. if k != #Tab then --Last entry in path table
  332.  
  333. Here = Here..v.."/"
  334.  
  335. end
  336.  
  337. end
  338.  
  339.  
  340.  
  341. if not file.IsDir(Here, "DATA") then
  342.  
  343. file.CreateDir(Here, "DATA")
  344.  
  345. end
  346.  
  347. end
  348.  
  349.  
  350.  
  351.  
  352.  
  353. function HSP.file.Write(path,cont)
  354.  
  355. HSP.file.MakeTreeForFile(path)
  356.  
  357.  
  358.  
  359. --Write
  360.  
  361. local Out = file.Open(path, "w", "DATA")
  362.  
  363. if not Out then return end
  364.  
  365. Out:Write(cont)
  366.  
  367. Out:Close()
  368.  
  369. end
  370.  
  371.  
  372.  
  373. function HSP.file.Append(path,cont)
  374.  
  375. HSP.file.MakeTreeForFile(path)
  376.  
  377.  
  378.  
  379. --Write-append
  380.  
  381. local Out = file.Open(path, "a", "DATA")
  382.  
  383. if not Out then return end
  384.  
  385. Out:Write(cont)
  386.  
  387. Out:Close()
  388.  
  389. end
  390.  
  391.  
  392.  
  393. function HSP.file.Find(what,loc)
  394.  
  395. local Files,Dirs = file.Find(what,loc)
  396.  
  397.  
  398.  
  399. --Merge the 2 tables like GM12
  400.  
  401. if Dirs then
  402.  
  403. for k,v in pairs(Dirs) do
  404.  
  405. table.insert(Files,v)
  406.  
  407. end
  408.  
  409. end
  410.  
  411.  
  412.  
  413. return Files
  414.  
  415. end
  416.  
  417.  
  418.  
  419. function HSP.file.Read(what,loc)
  420.  
  421. if not loc or loc == false then loc = "DATA" end
  422.  
  423. if loc == true then loc = "GAME" end
  424.  
  425.  
  426.  
  427. local Out = file.Open(what, "r", loc)
  428.  
  429. if not Out then return end
  430.  
  431. local str = Out:Read( Out:Size() )
  432.  
  433. Out:Close()
  434.  
  435.  
  436.  
  437. if not str then return "" end
  438.  
  439. return str
  440.  
  441. end
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455. function HSP.MyCall(lev)
  456.  
  457. local DGI = debug.getinfo(lev or 3)
  458.  
  459. if not DGI then return "Gone", 0 end
  460.  
  461.  
  462.  
  463. local Path = (DGI.short_src or "Gone"):gsub("\\","/")
  464.  
  465. local Line = (DGI.linedefined or 0)
  466.  
  467.  
  468.  
  469. return Path,Line
  470.  
  471. end
  472.  
  473. function HSP.FSource(func)
  474.  
  475. local typ = type(func)
  476.  
  477. if typ != "function" then
  478.  
  479. error("! HSP.FSource, func is a: "..typ)
  480.  
  481. end
  482.  
  483.  
  484.  
  485. return debug.getinfo(func).short_src or "GONE"
  486.  
  487. end
  488.  
  489.  
  490.  
  491.  
  492.  
  493.  
  494.  
  495. HSP.Detour = { Saved = {} }
  496.  
  497.  
  498.  
  499. function HSP.Detour.Meta(lib,func,new)
  500.  
  501. if not (lib and func and new) then
  502.  
  503. error("Missing args from HSP.Detour.Meta(lib,func,new)")
  504.  
  505. end
  506.  
  507.  
  508.  
  509. local _R = debug.getregistry()
  510.  
  511.  
  512.  
  513. if not _R[lib][func] then
  514.  
  515. error("Missing table, '_R."..lib.."."..func.."' doesn't exist")
  516.  
  517. end
  518.  
  519.  
  520.  
  521. if _R[lib][func.."Old"] then
  522.  
  523. _R[lib][func] = _R[lib][func.."Old"]
  524.  
  525. _R[lib][func.."Old"] = nil
  526.  
  527. HSP.Detour.Saved[lib.."."..func] = nil
  528.  
  529.  
  530.  
  531. ErrorNoHalt( Format("Detour of '%s.%s' from: %s was RELOADED\n", lib, func, HSP.FSource(new)) )
  532.  
  533. end
  534.  
  535.  
  536.  
  537. HSP.Detour.Saved[lib.."."..func] = {old = _R[lib][func], new = new}
  538.  
  539. _R[lib][func.."Old"] = _R[lib][func]
  540.  
  541. _R[lib][func] = new
  542.  
  543. end
  544.  
  545. --[[
  546.  
  547. HSP.Detour.Meta("Player", "PrintMessage", function(new) end)
  548.  
  549.  
  550.  
  551. HSP.Detour.Meta("bf_read", "ReadString", function(new) end)
  552.  
  553. ]]
  554.  
  555.  
  556.  
  557.  
  558.  
  559. function HSP.Detour.Global(lib,func,new)
  560.  
  561. if not (lib and func and new) then
  562.  
  563. error("Missing args from HSP.Detour.Global(lib,func,new)")
  564.  
  565. end
  566.  
  567.  
  568.  
  569. local where = lib
  570.  
  571. if where == "_G" then
  572.  
  573. where = _G
  574.  
  575. else
  576.  
  577. where = _G[where]
  578.  
  579. end
  580.  
  581.  
  582.  
  583. if not where then --Table doesn't exists in _G
  584.  
  585. error("Missing table, '_G."..lib.."."..func.."' doesn't exist")
  586.  
  587. end
  588.  
  589.  
  590.  
  591. if where[func.."Old"] then
  592.  
  593. where[func] = where[func.."Old"]
  594.  
  595. where[func.."Old"] = nil
  596.  
  597. HSP.Detour.Saved[lib.."."..func] = nil
  598.  
  599.  
  600.  
  601. ErrorNoHalt( Format("Detour of '%s.%s' from: %s was RELOADED\n", lib, func, HSP.FSource(new)) )
  602.  
  603. end
  604.  
  605.  
  606.  
  607. HSP.Detour.Saved[lib.."."..func] = {old = where[func], new = new}
  608.  
  609. where[func.."Old"] = where[func]
  610.  
  611. where[func] = new
  612.  
  613. end
  614.  
  615.  
  616.  
  617. --[[
  618.  
  619. HSP.Detour.Global("os", "date", function(new) end)
  620.  
  621.  
  622.  
  623. HSP.Detour.Global("_G", "PrintMessage", function(new) end)
  624.  
  625. ]]
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633. if SERVER then
  634.  
  635. function HSP.Detour.Dump(ply,cmd,args)
  636.  
  637. if not ply:IsSuperAdmin() then return end
  638.  
  639.  
  640.  
  641. for k,v in pairs( HSP.Detour.Saved ) do
  642.  
  643. print("! func,old,new: ", k, HSP.FSource(v.old), HSP.FSource(v.new) )
  644.  
  645. end
  646.  
  647. end
  648.  
  649. concommand.Add("hsp_detour_dump", HSP.Detour.Dump)
  650.  
  651. end
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699. ----------------------------------------
  700. -- 2014-07-12 20:32:45 --
  701. ------------------------------------------
  702. --[[
  703.  
  704. === HeX's Server Plugins ===
  705.  
  706. HSP_Shared.lua
  707.  
  708. Shared resources
  709.  
  710. ]]
  711.  
  712.  
  713.  
  714.  
  715.  
  716. HSP.RED2 = Color(255,0,0) --More red
  717.  
  718. HSP.RED = Color(255,0,11) --Red
  719.  
  720. HSP.KIRED = Color(255,80,0) --Killicon Red
  721.  
  722.  
  723.  
  724. HSP.GREEN2 = Color(0,255,0) --Green
  725.  
  726. HSP.GREEN = Color(66,255,96) --HSP green
  727.  
  728. HSP.SGREEN = Color(180,250,160) --Source green
  729.  
  730.  
  731.  
  732. HSP.BLUE2 = Color(0,0,255) --Blue
  733.  
  734. HSP.SBLUE = Color(0,255,255) --Blue
  735.  
  736. HSP.BLUE = Color(51,153,255) --HeX Blue
  737.  
  738. HSP.LPBLUE = Color(80,170,255) --Laser pistol blue
  739.  
  740. HSP.PBLUE = Color(155,205,248) --printall blue
  741.  
  742.  
  743.  
  744. HSP.SYELLOW = Color(255,255,0) --LuaError Yellow
  745.  
  746. HSP.YELLOW2 = Color(255,220,0,200) --HEV yellow
  747.  
  748. HSP.YELLOW = Color(255,200,0) --Yellow
  749.  
  750.  
  751.  
  752. HSP.ORANGE = Color(255,153,0) --Respected orange
  753.  
  754. HSP.PINK = Color(255,0,153) --Faggot pink
  755.  
  756.  
  757.  
  758. HSP.PURPLE = Color(149,102,255) --ASK2 purple
  759.  
  760. HSP.KIPURPLE = Color(192,0,192) --Killicon Purple
  761.  
  762. HSP.SVOTE = Color(255,64,96) --Solidvote Purple
  763.  
  764.  
  765.  
  766. HSP.GREY = Color(175,175,175) --Blackops grey
  767.  
  768. HSP.SGREY = Color(192,192,192) --Source grey
  769.  
  770.  
  771.  
  772. HSP.WHITE = Color(255,255,255) --White
  773.  
  774. HSP.WHITE2 = Color(254,254,254) --White2
  775.  
  776.  
  777.  
  778.  
  779.  
  780. function COLCON(...)
  781.  
  782. local color = HSP.WHITE
  783.  
  784. for k, v in pairs( {...} ) do
  785.  
  786. local typ = type(v)
  787.  
  788.  
  789.  
  790. if (typ == "table" && v["b"] && v["g"] && v["r"] ) then
  791.  
  792. color = v
  793.  
  794.  
  795.  
  796. elseif (typ == "Player" and IsValid(v) ) then
  797.  
  798. MsgC( team.GetColor( v:Team() ), v:GetName() )
  799.  
  800.  
  801.  
  802. elseif ( (typ == "Entity" or typ == "Weapon" or typ == "Vehicle" or typ == "NPC" ) and IsValid(v) ) then
  803.  
  804. MsgC( HSP.BLUE, v:GetClass() )
  805.  
  806.  
  807.  
  808. else
  809.  
  810. MsgC(color, tostring(v) )
  811.  
  812. end
  813.  
  814. end
  815.  
  816. MsgC(color, "\n")
  817.  
  818. end
  819.  
  820.  
  821.  
  822. local function DumpColors()
  823.  
  824. for k,v in pairs(HSP) do
  825.  
  826. if type(v) == "table" and v["r"] then --Color
  827.  
  828. COLCON(HSP.SGREY, k.."\t- ", v, "Test buttocks, HSP colors, -=[UH]=- United Hosts")
  829.  
  830. end
  831.  
  832. end
  833.  
  834. end
  835.  
  836. concommand.Add("hsp_colors"..(SERVER and "" or "_cl"), function(p) if p:IsAdmin() then DumpColors() end end)
  837.  
  838.  
  839.  
  840.  
  841.  
  842. //Garry!
  843.  
  844. if not hook.Hooks then
  845.  
  846. hook.Hooks = hook.GetTable()
  847.  
  848. end
  849.  
  850.  
  851.  
  852.  
  853.  
  854. HSP.Contact = "tell HeX (http://steamcommunity.com/id/MFSiNC)"
  855.  
  856. THIS_MAP = game.GetMap():lower()
  857.  
  858. ModDIR = util.RelativePathToFull("."):sub(1,-2):gsub("\\", "/"):Trim("/")
  859.  
  860. _R = debug.getregistry()
  861.  
  862.  
  863.  
  864. local pEntity = FindMetaTable("Entity")
  865.  
  866.  
  867.  
  868. function pEntity:print(str,msg) --Has to be on entity
  869.  
  870. if not IsValid(self) or not self:IsPlayer() then
  871.  
  872. return print(str)
  873.  
  874. end
  875.  
  876.  
  877.  
  878. if not msg then
  879.  
  880. str = str.."\n"
  881.  
  882. end
  883.  
  884. self:PrintMessage(HUD_PRINTCONSOLE, str)
  885.  
  886. end
  887.  
  888.  
  889.  
  890. function pEntity:Msg(str)
  891.  
  892. if not IsValid(self) or not self:IsPlayer() then
  893.  
  894. return Msg(str)
  895.  
  896. end
  897.  
  898.  
  899.  
  900. self:PrintMessage(HUD_PRINTCONSOLE, str)
  901.  
  902. end
  903.  
  904.  
  905.  
  906.  
  907.  
  908. function ValidString(v)
  909.  
  910. return (v and type(v) == "string" and v != "")
  911.  
  912. end
  913.  
  914. HSP.ValidString = ValidString
  915.  
  916. string.IsValid = ValidString --The new way!
  917.  
  918.  
  919.  
  920. function string.Check(str,check)
  921.  
  922. return str:sub(1,#check) == check
  923.  
  924. end
  925.  
  926.  
  927.  
  928. function string.EndCheck(str,check)
  929.  
  930. return str:sub(-1,-#check) == check
  931.  
  932. end
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940. function player.Get(what)
  941.  
  942. what = tostring(what):lower()
  943.  
  944. local match = {}
  945.  
  946.  
  947.  
  948. for k,v in pairs( player.GetAll() ) do
  949.  
  950. local name = v:Name():lower()
  951.  
  952. if (name == what or tonumber(what) == v:EntIndex() or name:find(what)) then
  953.  
  954. table.insert(match,v)
  955.  
  956. end
  957.  
  958. end
  959.  
  960.  
  961.  
  962. return match
  963.  
  964. end
  965.  
  966.  
  967.  
  968. function player.Name(str)
  969.  
  970. return player.Get(str)[1] or NULL
  971.  
  972. end
  973.  
  974.  
  975.  
  976. function epairs(egc)
  977.  
  978. return pairs( ents.FindByClass(egc) )
  979.  
  980. end
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990. function HSP.Time()
  991.  
  992. return os.date("%I:%M:%S%p")
  993.  
  994. end
  995.  
  996. function HSP.Date()
  997.  
  998. return os.date("%d-%m-%y %I:%M:%S%p")
  999.  
  1000. end
  1001.  
  1002. function HSP.DateOnly()
  1003.  
  1004. return os.date("%d-%m-%y")
  1005.  
  1006. end
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016. HSP.file = {}
  1017.  
  1018.  
  1019.  
  1020. function HSP.file.MakeTreeForFile(path) --Make dir tree, WHY GARRY
  1021.  
  1022. local Tab = path:Split("/")
  1023.  
  1024. local Here = ""
  1025.  
  1026.  
  1027.  
  1028. for k,v in ipairs(Tab) do
  1029.  
  1030. if k != #Tab then --Last entry in path table
  1031.  
  1032. Here = Here..v.."/"
  1033.  
  1034. end
  1035.  
  1036. end
  1037.  
  1038.  
  1039.  
  1040. if not file.IsDir(Here, "DATA") then
  1041.  
  1042. file.CreateDir(Here, "DATA")
  1043.  
  1044. end
  1045.  
  1046. end
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052. function HSP.file.Write(path,cont)
  1053.  
  1054. HSP.file.MakeTreeForFile(path)
  1055.  
  1056.  
  1057.  
  1058. --Write
  1059.  
  1060. local Out = file.Open(path, "w", "DATA")
  1061.  
  1062. if not Out then return end
  1063.  
  1064. Out:Write(cont)
  1065.  
  1066. Out:Close()
  1067.  
  1068. end
  1069.  
  1070.  
  1071.  
  1072. function HSP.file.Append(path,cont)
  1073.  
  1074. HSP.file.MakeTreeForFile(path)
  1075.  
  1076.  
  1077.  
  1078. --Write-append
  1079.  
  1080. local Out = file.Open(path, "a", "DATA")
  1081.  
  1082. if not Out then return end
  1083.  
  1084. Out:Write(cont)
  1085.  
  1086. Out:Close()
  1087.  
  1088. end
  1089.  
  1090.  
  1091.  
  1092. function HSP.file.Find(what,loc)
  1093.  
  1094. local Files,Dirs = file.Find(what,loc)
  1095.  
  1096.  
  1097.  
  1098. --Merge the 2 tables like GM12
  1099.  
  1100. if Dirs then
  1101.  
  1102. for k,v in pairs(Dirs) do
  1103.  
  1104. table.insert(Files,v)
  1105.  
  1106. end
  1107.  
  1108. end
  1109.  
  1110.  
  1111.  
  1112. return Files
  1113.  
  1114. end
  1115.  
  1116.  
  1117.  
  1118. function HSP.file.Read(what,loc)
  1119.  
  1120. if not loc or loc == false then loc = "DATA" end
  1121.  
  1122. if loc == true then loc = "GAME" end
  1123.  
  1124.  
  1125.  
  1126. local Out = file.Open(what, "r", loc)
  1127.  
  1128. if not Out then return end
  1129.  
  1130. local str = Out:Read( Out:Size() )
  1131.  
  1132. Out:Close()
  1133.  
  1134.  
  1135.  
  1136. if not str then return "" end
  1137.  
  1138. return str
  1139.  
  1140. end
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154. function HSP.MyCall(lev)
  1155.  
  1156. local DGI = debug.getinfo(lev or 3)
  1157.  
  1158. if not DGI then return "Gone", 0 end
  1159.  
  1160.  
  1161.  
  1162. local Path = (DGI.short_src or "Gone"):gsub("\\","/")
  1163.  
  1164. local Line = (DGI.linedefined or 0)
  1165.  
  1166.  
  1167.  
  1168. return Path,Line
  1169.  
  1170. end
  1171.  
  1172. function HSP.FSource(func)
  1173.  
  1174. local typ = type(func)
  1175.  
  1176. if typ != "function" then
  1177.  
  1178. error("! HSP.FSource, func is a: "..typ)
  1179.  
  1180. end
  1181.  
  1182.  
  1183.  
  1184. return debug.getinfo(func).short_src or "GONE"
  1185.  
  1186. end
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194. HSP.Detour = { Saved = {} }
  1195.  
  1196.  
  1197.  
  1198. function HSP.Detour.Meta(lib,func,new)
  1199.  
  1200. if not (lib and func and new) then
  1201.  
  1202. error("Missing args from HSP.Detour.Meta(lib,func,new)")
  1203.  
  1204. end
  1205.  
  1206.  
  1207.  
  1208. local _R = debug.getregistry()
  1209.  
  1210.  
  1211.  
  1212. if not _R[lib][func] then
  1213.  
  1214. error("Missing table, '_R."..lib.."."..func.."' doesn't exist")
  1215.  
  1216. end
  1217.  
  1218.  
  1219.  
  1220. if _R[lib][func.."Old"] then
  1221.  
  1222. _R[lib][func] = _R[lib][func.."Old"]
  1223.  
  1224. _R[lib][func.."Old"] = nil
  1225.  
  1226. HSP.Detour.Saved[lib.."."..func] = nil
  1227.  
  1228.  
  1229.  
  1230. ErrorNoHalt( Format("Detour of '%s.%s' from: %s was RELOADED\n", lib, func, HSP.FSource(new)) )
  1231.  
  1232. end
  1233.  
  1234.  
  1235.  
  1236. HSP.Detour.Saved[lib.."."..func] = {old = _R[lib][func], new = new}
  1237.  
  1238. _R[lib][func.."Old"] = _R[lib][func]
  1239.  
  1240. _R[lib][func] = new
  1241.  
  1242. end
  1243.  
  1244. --[[
  1245.  
  1246. HSP.Detour.Meta("Player", "PrintMessage", function(new) end)
  1247.  
  1248.  
  1249.  
  1250. HSP.Detour.Meta("bf_read", "ReadString", function(new) end)
  1251.  
  1252. ]]
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258. function HSP.Detour.Global(lib,func,new)
  1259.  
  1260. if not (lib and func and new) then
  1261.  
  1262. error("Missing args from HSP.Detour.Global(lib,func,new)")
  1263.  
  1264. end
  1265.  
  1266.  
  1267.  
  1268. local where = lib
  1269.  
  1270. if where == "_G" then
  1271.  
  1272. where = _G
  1273.  
  1274. else
  1275.  
  1276. where = _G[where]
  1277.  
  1278. end
  1279.  
  1280.  
  1281.  
  1282. if not where then --Table doesn't exists in _G
  1283.  
  1284. error("Missing table, '_G."..lib.."."..func.."' doesn't exist")
  1285.  
  1286. end
  1287.  
  1288.  
  1289.  
  1290. if where[func.."Old"] then
  1291.  
  1292. where[func] = where[func.."Old"]
  1293.  
  1294. where[func.."Old"] = nil
  1295.  
  1296. HSP.Detour.Saved[lib.."."..func] = nil
  1297.  
  1298.  
  1299.  
  1300. ErrorNoHalt( Format("Detour of '%s.%s' from: %s was RELOADED\n", lib, func, HSP.FSource(new)) )
  1301.  
  1302. end
  1303.  
  1304.  
  1305.  
  1306. HSP.Detour.Saved[lib.."."..func] = {old = where[func], new = new}
  1307.  
  1308. where[func.."Old"] = where[func]
  1309.  
  1310. where[func] = new
  1311.  
  1312. end
  1313.  
  1314.  
  1315.  
  1316. --[[
  1317.  
  1318. HSP.Detour.Global("os", "date", function(new) end)
  1319.  
  1320.  
  1321.  
  1322. HSP.Detour.Global("_G", "PrintMessage", function(new) end)
  1323.  
  1324. ]]
  1325.  
  1326.  
  1327.  
  1328.  
  1329.  
  1330.  
  1331.  
  1332. if SERVER then
  1333.  
  1334. function HSP.Detour.Dump(ply,cmd,args)
  1335.  
  1336. if not ply:IsSuperAdmin() then return end
  1337.  
  1338.  
  1339.  
  1340. for k,v in pairs( HSP.Detour.Saved ) do
  1341.  
  1342. print("! func,old,new: ", k, HSP.FSource(v.old), HSP.FSource(v.new) )
  1343.  
  1344. end
  1345.  
  1346. end
  1347.  
  1348. concommand.Add("hsp_detour_dump", HSP.Detour.Dump)
  1349.  
  1350. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement