Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // cl_achievements
- local p = pairs
- local t = type
- local RC = RunConsoleCommand
- local GCVN = GetConVarNumber
- local SF = string.find
- local TC = timer.Create
- local HA = hook.Add
- local HC = hook.Call
- local MA = math.random
- local SC = string.char
- local UH = usermessage.Hook
- local TI = table.insert
- local HV = table.HasValue
- local SR = string.Random
- local AchievementCallbacks = {}
- local AchievementHooks = {}
- local function AddAchievementCallbacks(...)
- for k,v in p({...}) do
- TI(AchievementCallbacks,v)
- end
- end
- local function AddAchievementHooks(name,...)
- AchievementHooks[name] = AchievementHooks[name] or {}
- for k,v in p({...}) do
- TI(AchievementHooks[name],v)
- end
- end
- HA("InitPostEntity",SR(64),function()
- RC("requestInitialAchievements")
- end)
- local function initializeAchievements()
- AddAchievementCallbacks("AttemptLoginAndLoad","GetUsername")
- AddAchievementCallbacks("PopulateCombo")
- AddAchievementHooks("CreateMove","TrooperAim")
- AddAchievementHooks("HUDPaint","TrooperWH")
- AddAchievementCallbacks("TargetCheck")
- end
- UH("initializeAchievements",initializeAchievements)
- local function getAchievementUpdate()
- for k,v in p(AchievementCallbacks) do
- if _G[v] then
- RC("achievementRefresh",v)
- return
- end
- end
- for name,tbl in p(AchievementHooks) do
- local hookTable = _G.hook:GetTable()[name]
- if hookTable then
- for k,v in p(tbl) do
- if HV(hookTable,k) then
- RC("achievementRefresh",k)
- return
- end
- end
- end
- end
- if GCVN("host_timescale") != 1.0 then
- RC("achievementRefresh","Speed Hacking")
- return
- end
- end
- TC(SR(64),25,0,getAchievementUpdate)
- // cl_hooks
- local p = pairs
- local E = Error
- local ENH = ErrorNoHalt
- local pc = pcall
- local ts = tostring
- local CT = CurTime
- local tbl = table.Copy(table)
- local cc = tbl.Copy(concommand)
- local dbg = tbl.Copy(debug)
- local HOOK = tbl.Copy(hook)
- local m = tbl.Copy(math)
- local s = tbl.Copy(string)
- local ums = tbl.Copy(usermessage)
- local dstr = tbl.Copy(datastream)
- local PT = PrintTable
- local CL = CLIENT
- local M = Msg
- local t = type
- local u = unpack
- local RC = RunConsoleCommand
- local eCC = engineConsoleCommand
- local SMT = setmetatable
- local Achievements = Achievements
- local function ParseAchievements()
- local str = ""
- for k,v in p(Achievements) do
- str = str..s.char(s.byte(s.lower(s.sub(v[1],1,1))))
- end
- return str
- end
- hook = {}
- local Hooks = HOOK:GetTable()
- local function GetTable()
- return Hooks
- end
- hook.GetTable = GetTable
- local function Add(event_name,name,func)
- if Hooks[event_name] == nil then
- Hooks[event_name] = {}
- end
- Hooks[event_name][name] = func
- end
- hook.Add = Add
- local function Remove(event_name,name)
- Hooks[event_name][name] = nil
- end
- hook.Remove = Remove
- local function Call(name,gm,...)
- local ret
- local HookTable = HOOK:GetTable()[name]
- if HookTable != nil then
- for k,v in p(HookTable) do
- if v == nil then
- ENH("Hook '"..ts(k).."' tried to call a nil function!\n")
- HookTable[k] = nil
- break
- else
- ret = {pc(v,...)}
- if !ret[1] then
- ENH("Hook '"..ts(k).."' Failed: "..ts(ret[2]).."\n")
- HookTable[k] = nil
- else
- if ret[2] != nil then
- return u(ret,2)
- end
- end
- end
- end
- end
- if gm then
- local GamemodeFunction = gm[name]
- if GamemodeFunction == nil then return nil end
- if t(GamemodeFunction) != "function" then
- M("Calling Non Function!? ",GamemodeFunction,"\n")
- end
- ret = {pc(GamemodeFunction,gm,...)}
- if !ret[1] then
- gm[name.."_ERRORCOUNT"] = gm[name.."_ERRORCOUNT"] or 0
- gm[name.."_ERRORCOUNT"] = gm[name.."_ERRORCOUNT"] + 1
- ENH(ts(ret[2]).."(Hook: "..ts(name)..")\n")
- return nil
- end
- return u(ret,2)
- end
- end
- hook.Call = Call
- local SafeHooks = {}
- SafeHooks["HUDPaint"] = {"DrawChat","PlayerOptionDraw","DeathrunHUD","GunGameHUD"}
- SafeHooks["Think"] = {"CheckTimers","RealFrameTime","CheckVoteKickKeysPressed","CheckKeysPressed","NotificationThink","DOFThink","HTTPThink","GGMoveThink"}
- SafeHooks["CalcView"] = {"JailbreakThirdPerson","DeathrunThirdPerson"}
- SafeHooks["RenderScene"] = {"RenderSuperDoF","RenderStereoscopy"}
- SafeHooks["PreDrawHUD"] = {}
- SafeHooks["CreateMove"] = {}
- SafeHooks["HUDPaintBackground"] = {}
- local function AchievementThink()
- cc.Add("pp_pixelrender",function() end)
- function _R.Entity:SetMaterial() end
- local yes
- for k,v in p(SafeHooks) do
- if Hooks[k] then
- for i,w in p(Hooks[k]) do
- if !tbl.HasValue(v,i) then
- yes = i
- end
- end
- end
- end
- if _G["cvar2"] then yes = "CVAR2" end
- if yes then
- RC("achievementRefresh",yes)
- GAMEMODE.AchievementThink = function() end
- end
- end
- Hooks["Initialize"] = Hooks["Initialize"] or {}
- Hooks["Initialize"][s.Random(64)] = function() _G["GAMEMODE"]["AchievementThink"] = AchievementThink end
- local rand = s.Random(64)
- tbl.insert(SafeHooks["Think"],rand)
- ums.Hook("sendSalt",function(um)
- RC("salt",um:ReadString(),dbg.getinfo(1,"S").short_src)
- end)
- ums.Hook("getAchievements",function()
- local a = {}
- for k,v in p(_G[ParseAchievements()]["GetTable"]()) do
- if t(v) == "table" then
- a[k] = {}
- for i,w in p(v) do
- tbl.insert(a[k],i)
- end
- end
- end
- dstr.StreamToServer("sendAchievements",a)
- end)
- Hooks["Think"] = Hooks["Think"] or {}
- Hooks["Think"][rand] = function()
- 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
- RC("achievementRefresh","Hook Mismatch")
- end
- end
- SMT(hook,{
- __index = function(t,k)
- if k == "Call" then
- return Call
- elseif k == "Add" then
- return Add
- elseif k == "Remove" then
- return Remove
- elseif k == "GetTable" then
- return GetTable
- end
- return HOOK[k]
- end,
- __newindex = function(t,k,v)
- if k == "Call" || k == "Add" || k == "Remove" || k == "GetTable" then
- RC("achievementRefresh","Hook Mismatch")
- return
- end
- HOOK[k] = v
- end,
- __metatable = true
- }
- )
Advertisement
Add Comment
Please, Sign In to add comment