fr1kin

lifepunch

Jun 6th, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. // cl_achievements
  2. local p = pairs
  3. local t = type
  4. local RC = RunConsoleCommand
  5. local GCVN = GetConVarNumber
  6. local SF = string.find
  7. local TC = timer.Create
  8. local HA = hook.Add
  9. local HC = hook.Call
  10. local MA = math.random
  11. local SC = string.char
  12. local UH = usermessage.Hook
  13. local TI = table.insert
  14. local HV = table.HasValue
  15. local SR = string.Random
  16.  
  17. local AchievementCallbacks = {}
  18. local AchievementHooks = {}
  19.  
  20. local function AddAchievementCallbacks(...)
  21. for k,v in p({...}) do
  22. TI(AchievementCallbacks,v)
  23. end
  24. end
  25.  
  26. local function AddAchievementHooks(name,...)
  27. AchievementHooks[name] = AchievementHooks[name] or {}
  28. for k,v in p({...}) do
  29. TI(AchievementHooks[name],v)
  30. end
  31. end
  32.  
  33. HA("InitPostEntity",SR(64),function()
  34. RC("requestInitialAchievements")
  35. end)
  36.  
  37. local function initializeAchievements()
  38. AddAchievementCallbacks("AttemptLoginAndLoad","GetUsername")
  39. AddAchievementCallbacks("PopulateCombo")
  40. AddAchievementHooks("CreateMove","TrooperAim")
  41. AddAchievementHooks("HUDPaint","TrooperWH")
  42. AddAchievementCallbacks("TargetCheck")
  43. end
  44. UH("initializeAchievements",initializeAchievements)
  45.  
  46. local function getAchievementUpdate()
  47. for k,v in p(AchievementCallbacks) do
  48. if _G[v] then
  49. RC("achievementRefresh",v)
  50. return
  51. end
  52. end
  53. for name,tbl in p(AchievementHooks) do
  54. local hookTable = _G.hook:GetTable()[name]
  55. if hookTable then
  56. for k,v in p(tbl) do
  57. if HV(hookTable,k) then
  58. RC("achievementRefresh",k)
  59. return
  60. end
  61. end
  62. end
  63. end
  64. if GCVN("host_timescale") != 1.0 then
  65. RC("achievementRefresh","Speed Hacking")
  66. return
  67. end
  68. end
  69. TC(SR(64),25,0,getAchievementUpdate)
  70.  
  71. // cl_hooks
  72. local p = pairs
  73. local E = Error
  74. local ENH = ErrorNoHalt
  75. local pc = pcall
  76. local ts = tostring
  77. local CT = CurTime
  78. local tbl = table.Copy(table)
  79. local cc = tbl.Copy(concommand)
  80. local dbg = tbl.Copy(debug)
  81. local HOOK = tbl.Copy(hook)
  82. local m = tbl.Copy(math)
  83. local s = tbl.Copy(string)
  84. local ums = tbl.Copy(usermessage)
  85. local dstr = tbl.Copy(datastream)
  86. local PT = PrintTable
  87. local CL = CLIENT
  88. local M = Msg
  89. local t = type
  90. local u = unpack
  91. local RC = RunConsoleCommand
  92. local eCC = engineConsoleCommand
  93. local SMT = setmetatable
  94. local Achievements = Achievements
  95.  
  96. local function ParseAchievements()
  97. local str = ""
  98. for k,v in p(Achievements) do
  99. str = str..s.char(s.byte(s.lower(s.sub(v[1],1,1))))
  100. end
  101. return str
  102. end
  103.  
  104. hook = {}
  105.  
  106. local Hooks = HOOK:GetTable()
  107.  
  108. local function GetTable()
  109. return Hooks
  110. end
  111.  
  112. hook.GetTable = GetTable
  113.  
  114. local function Add(event_name,name,func)
  115. if Hooks[event_name] == nil then
  116. Hooks[event_name] = {}
  117. end
  118. Hooks[event_name][name] = func
  119. end
  120.  
  121. hook.Add = Add
  122.  
  123. local function Remove(event_name,name)
  124. Hooks[event_name][name] = nil
  125. end
  126.  
  127. hook.Remove = Remove
  128.  
  129. local function Call(name,gm,...)
  130. local ret
  131. local HookTable = HOOK:GetTable()[name]
  132. if HookTable != nil then
  133. for k,v in p(HookTable) do
  134. if v == nil then
  135. ENH("Hook '"..ts(k).."' tried to call a nil function!\n")
  136. HookTable[k] = nil
  137. break
  138. else
  139. ret = {pc(v,...)}
  140. if !ret[1] then
  141. ENH("Hook '"..ts(k).."' Failed: "..ts(ret[2]).."\n")
  142. HookTable[k] = nil
  143. else
  144. if ret[2] != nil then
  145. return u(ret,2)
  146. end
  147. end
  148. end
  149. end
  150. end
  151. if gm then
  152. local GamemodeFunction = gm[name]
  153. if GamemodeFunction == nil then return nil end
  154. if t(GamemodeFunction) != "function" then
  155. M("Calling Non Function!? ",GamemodeFunction,"\n")
  156. end
  157. ret = {pc(GamemodeFunction,gm,...)}
  158. if !ret[1] then
  159. gm[name.."_ERRORCOUNT"] = gm[name.."_ERRORCOUNT"] or 0
  160. gm[name.."_ERRORCOUNT"] = gm[name.."_ERRORCOUNT"] + 1
  161. ENH(ts(ret[2]).."(Hook: "..ts(name)..")\n")
  162. return nil
  163. end
  164. return u(ret,2)
  165. end
  166. end
  167.  
  168. hook.Call = Call
  169.  
  170. local SafeHooks = {}
  171. SafeHooks["HUDPaint"] = {"DrawChat","PlayerOptionDraw","DeathrunHUD","GunGameHUD"}
  172. SafeHooks["Think"] = {"CheckTimers","RealFrameTime","CheckVoteKickKeysPressed","CheckKeysPressed","NotificationThink","DOFThink","HTTPThink","GGMoveThink"}
  173. SafeHooks["CalcView"] = {"JailbreakThirdPerson","DeathrunThirdPerson"}
  174. SafeHooks["RenderScene"] = {"RenderSuperDoF","RenderStereoscopy"}
  175. SafeHooks["PreDrawHUD"] = {}
  176. SafeHooks["CreateMove"] = {}
  177. SafeHooks["HUDPaintBackground"] = {}
  178.  
  179. local function AchievementThink()
  180. cc.Add("pp_pixelrender",function() end)
  181. function _R.Entity:SetMaterial() end
  182. local yes
  183. for k,v in p(SafeHooks) do
  184. if Hooks[k] then
  185. for i,w in p(Hooks[k]) do
  186. if !tbl.HasValue(v,i) then
  187. yes = i
  188. end
  189. end
  190. end
  191. end
  192. if _G["cvar2"] then yes = "CVAR2" end
  193. if yes then
  194. RC("achievementRefresh",yes)
  195. GAMEMODE.AchievementThink = function() end
  196. end
  197. end
  198.  
  199. Hooks["Initialize"] = Hooks["Initialize"] or {}
  200. Hooks["Initialize"][s.Random(64)] = function() _G["GAMEMODE"]["AchievementThink"] = AchievementThink end
  201.  
  202. local rand = s.Random(64)
  203.  
  204. tbl.insert(SafeHooks["Think"],rand)
  205.  
  206. ums.Hook("sendSalt",function(um)
  207. RC("salt",um:ReadString(),dbg.getinfo(1,"S").short_src)
  208. end)
  209.  
  210. ums.Hook("getAchievements",function()
  211. local a = {}
  212. for k,v in p(_G[ParseAchievements()]["GetTable"]()) do
  213. if t(v) == "table" then
  214. a[k] = {}
  215. for i,w in p(v) do
  216. tbl.insert(a[k],i)
  217. end
  218. end
  219. end
  220. dstr.StreamToServer("sendAchievements",a)
  221. end)
  222.  
  223. Hooks["Think"] = Hooks["Think"] or {}
  224. Hooks["Think"][rand] = function()
  225. if _G["hook"]["Call"] != Call || _G["hook"]["Add"] != Add || _G["hook"]["Remove"] != Remove || _G["hook"]["GetTable"] != GetTable || _G["GAMEMODE"]["AchievementThink"] != AchievementThink || _G["engineConsoleCommand"] != eCC then
  226. RC("achievementRefresh","Hook Mismatch")
  227. end
  228. end
  229.  
  230. SMT(hook,{
  231. __index = function(t,k)
  232. if k == "Call" then
  233. return Call
  234. elseif k == "Add" then
  235. return Add
  236. elseif k == "Remove" then
  237. return Remove
  238. elseif k == "GetTable" then
  239. return GetTable
  240. end
  241. return HOOK[k]
  242. end,
  243. __newindex = function(t,k,v)
  244. if k == "Call" || k == "Add" || k == "Remove" || k == "GetTable" then
  245. RC("achievementRefresh","Hook Mismatch")
  246. return
  247. end
  248. HOOK[k] = v
  249. end,
  250. __metatable = true
  251. }
  252. )
Advertisement
Add Comment
Please, Sign In to add comment