Advertisement
S1L1R

addon.lua

May 27th, 2020 (edited)
4,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.36 KB | None | 0 0
  1. -- LOAD LIBS
  2. local http = loadstring("local a=require(\"ffi\")a.cdef(\"typedef uint32_t request_handle_t; typedef uint64_t steam_api_call_t; typedef struct { void* __pad[11]; void* steam_http; }steam_ctx_t; typedef uint32_t(__thiscall* create_http_request_t)(void*, uint32_t, const char*); typedef bool(__thiscall* send_http_request_t)(void* _this, request_handle_t handle, steam_api_call_t call_handle); typedef bool(__thiscall* get_http_response_header_size_t)( void* _this, request_handle_t hRequest, const char *pchHeaderName, uint32_t *unResponseHeaderSize ); typedef bool(__thiscall* get_http_response_header_value_t)(void* _this, request_handle_t hRequest, const char *pchHeaderName, char *pHeaderValueBuffer, uint32_t unBufferSize); typedef bool(__thiscall* get_http_response_body_size_t)(void* _this, request_handle_t hRequest, uint32_t *unBodySize ); typedef bool(__thiscall* get_http_response_body_data_t)(void* _this, request_handle_t hRequest, char *pBodyDataBuf, uint32_t unBufferSize ); typedef bool(__thiscall* set_http_request_param_t)(void* _this, request_handle_t hRequest, const char* pchParamName, const char* pchParamValue); typedef bool(__thiscall* release_http_request_t)(void* _this, request_handle_t hRequest);\")local b=client.find_signature(\"client_panorama.dll\",\"\\xFF\\x15\\xCC\\xCC\\xCC\\xCC\\xB9\\xCC\\xCC\\xCC\\xCC\\xE8\\xCC\\xCC\\xCC\\xCC\\x6A\")or error(\"steam_ctx\")local c=a.cast(\"steam_ctx_t**\",a.cast(\"char*\",b)+7)[0]or error(\"steam_ctx not found\")local d=a.cast(\"void*\",c.steam_http)or error(\"steam_http error\")local e=a.cast(\"void***\",d)or error(\"steam_http_ptr error\")local f=e[0]or error(\"steam_http_ptr was null\")local g=a.cast('create_http_request_t',f[0])local h=a.cast('send_http_request_t',f[5])local i=a.cast('get_http_response_header_size_t',f[9])local j=a.cast('get_http_response_header_value_t',f[10])local k=a.cast('get_http_response_body_size_t',f[11])local l=a.cast('get_http_response_body_data_t',f[12])local m=a.cast('set_http_request_param_t',f[4])local n=a.cast('release_http_request_t',f[14])local o={}local p={__index=o}function o.new(q,r,s)local t={handle=q,url=r,callback=s,ticks=0}local u=setmetatable(t,p)return u end;local v={}local w={__index=v}function v.new(x,y,z)local t={state=x,body=y,header={content_type=z.content_type}}local A=setmetatable(t,w)return A end;function v:success()return self.state==0 end;local B={state={ok=0,no_response=1,timed_out=2,unknown=3}}local C={__index=B}function B.new(D)local D=D or{}local t={requests={},task_interval=D.task_interval or 0.5,enable_debug=false,timeout=D.timeout or 10}local E=setmetatable(t,C)E:_process_tasks()return E end;function B:get(r,s)local q=g(d,1,r)if h(d,q,0)==false then return end;local u=o.new(q,r,s)self:_debug(\"[HTTP] New GET request to: %s\",r)table.insert(self.requests,u)end;function B:post(r,F,s)local q=g(d,3,r)for G,H in pairs(F)do m(d,q,G,H)end;if h(d,q,0)==false then return end;local u=o.new(q,r,s)self:_debug(\"[HTTP] New POST request to: %s\",r)table.insert(self.requests,u)end;function B:_process_tasks()for I,u in ipairs(self.requests)do local J=a.new(\"uint32_t[1]\")self:_debug(\"--------------------\")self:_debug(\"[HTTP] Processing request #%s\",I)if k(d,u.handle,J)==true then local K=J[0]if K>0 then local y=a.new(\"char[?]\",K)if l(d,u.handle,y,K)==true then self:_debug(\"[HTTP] Request #%s finished. Invoking callback.\",I)table.remove(self.requests,I)n(d,u.handle)u.callback(v.new(B.state.ok,a.string(y,K),{content_type=B._get_header(u,\"Content-Type\")}))end else table.remove(self.requests,I)n(d,u.handle)u.callback(v.new(B.state.no_response,nil,{}))end end;local L=u.ticks+1;if L>=self.timeout then table.remove(self.requests,I)n(d,u.handle)u.callback(v.new(B.state.timed_out,nil,{}))else u.ticks=L end end;client.delay_call(self.task_interval,B._bind(self,'_process_tasks'))end;function B:_debug(...)if self.enable_debug==true then client.log(string.format(...))end end;function B._get_header(u,M)local N=a.new(\"uint32_t[1]\")if i(d,u.handle,M,N)then local O=N[0]local P=a.new(\"char[?]\",O)if j(d,u.handle,M,P,O)then return a.string(P,O)end end;return nil end;function B._bind(Q,G)return function(...)return Q[G](Q,...)end end;return B")().new()
  3. local json = (function()local a={_version="0.1.2"}local b;local c={["\\"]="\\\\",["\""]="\\\"",["\b"]="\\b",["\f"]="\\f",["\n"]="\\n",["\r"]="\\r",["\t"]="\\t"}local d={["\\/"]="/"}for e,f in pairs(c)do d[f]=e end;local function g(h)return c[h]or string.format("\\u%04x",h:byte())end;local function i(j)return"null"end;local function k(j,l)local m={}l=l or{}if l[j]then error("circular reference")end;l[j]=true;if rawget(j,1)~=nil or next(j)==nil then local n=0;for e in pairs(j)do if type(e)~="number"then error("invalid table: mixed or invalid key types")end;n=n+1 end;if n~=#j then error("invalid table: sparse array")end;for o,f in ipairs(j)do table.insert(m,b(f,l))end;l[j]=nil;return"["..table.concat(m,",").."]"else for e,f in pairs(j)do if type(e)~="string"then error("invalid table: mixed or invalid key types")end;table.insert(m,b(e,l)..":"..b(f,l))end;l[j]=nil;return"{"..table.concat(m,",").."}"end end;local function p(j)return'"'..j:gsub('[%z\1-\31\\"]',g)..'"'end;local function q(j)if j~=j or j<=-math.huge or j>=math.huge then error("unexpected number value '"..tostring(j).."'")end;return string.format("%.14g",j)end;local r={["nil"]=i,["table"]=k,["string"]=p,["number"]=q,["boolean"]=tostring}b=function(j,l)local s=type(j)local t=r[s]if t then return t(j,l)end;error("unexpected type '"..s.."'")end;function a.encode(j)return b(j)end;local u;local function v(...)local m={}for o=1,select("#",...)do m[select(o,...)]=true end;return m end;local w=v(" ","\t","\r","\n")local x=v(" ","\t","\r","\n","]","}",",")local y=v("\\","/",'"',"b","f","n","r","t","u")local z=v("true","false","null")local A={["true"]=true,["false"]=false,["null"]=nil}local function B(C,D,E,F)for o=D,#C do if E[C:sub(o,o)]~=F then return o end end;return#C+1 end;local function G(C,D,H)local I=1;local J=1;for o=1,D-1 do J=J+1;if C:sub(o,o)=="\n"then I=I+1;J=1 end end;error(string.format("%s at line %d col %d",H,I,J))end;local function K(n)local t=math.floor;if n<=0x7f then return string.char(n)elseif n<=0x7ff then return string.char(t(n/64)+192,n%64+128)elseif n<=0xffff then return string.char(t(n/4096)+224,t(n%4096/64)+128,n%64+128)elseif n<=0x10ffff then return string.char(t(n/262144)+240,t(n%262144/4096)+128,t(n%4096/64)+128,n%64+128)end;error(string.format("invalid unicode codepoint '%x'",n))end;local function L(M)local N=tonumber(M:sub(3,6),16)local O=tonumber(M:sub(9,12),16)if O then return K((N-0xd800)*0x400+O-0xdc00+0x10000)else return K(N)end end;local function P(C,o)local Q=false;local R=false;local S=false;local T;for U=o+1,#C do local V=C:byte(U)if V<32 then G(C,U,"control character in string")end;if T==92 then if V==117 then local W=C:sub(U+1,U+5)if not W:find("%x%x%x%x")then G(C,U,"invalid unicode escape in string")end;if W:find("^[dD][89aAbB]")then R=true else Q=true end else local h=string.char(V)if not y[h]then G(C,U,"invalid escape char '"..h.."' in string")end;S=true end;T=nil elseif V==34 then local M=C:sub(o+1,U-1)if R then M=M:gsub("\\u[dD][89aAbB]..\\u....",L)end;if Q then M=M:gsub("\\u....",L)end;if S then M=M:gsub("\\.",d)end;return M,U+1 else T=V end end;G(C,o,"expected closing quote for string")end;local function X(C,o)local V=B(C,o,x)local M=C:sub(o,V-1)local n=tonumber(M)if not n then G(C,o,"invalid number '"..M.."'")end;return n,V end;local function Y(C,o)local V=B(C,o,x)local Z=C:sub(o,V-1)if not z[Z]then G(C,o,"invalid literal '"..Z.."'")end;return A[Z],V end;local function _(C,o)local m={}local n=1;o=o+1;while 1 do local V;o=B(C,o,w,true)if C:sub(o,o)=="]"then o=o+1;break end;V,o=u(C,o)m[n]=V;n=n+1;o=B(C,o,w,true)local a0=C:sub(o,o)o=o+1;if a0=="]"then break end;if a0~=","then G(C,o,"expected ']' or ','")end end;return m,o end;local function a1(C,o)local m={}o=o+1;while 1 do local a2,j;o=B(C,o,w,true)if C:sub(o,o)=="}"then o=o+1;break end;if C:sub(o,o)~='"'then G(C,o,"expected string for key")end;a2,o=u(C,o)o=B(C,o,w,true)if C:sub(o,o)~=":"then G(C,o,"expected ':' after key")end;o=B(C,o+1,w,true)j,o=u(C,o)m[a2]=j;o=B(C,o,w,true)local a0=C:sub(o,o)o=o+1;if a0=="}"then break end;if a0~=","then G(C,o,"expected '}' or ','")end end;return m,o end;local a3={['"']=P,["0"]=X,["1"]=X,["2"]=X,["3"]=X,["4"]=X,["5"]=X,["6"]=X,["7"]=X,["8"]=X,["9"]=X,["-"]=X,["t"]=Y,["f"]=Y,["n"]=Y,["["]=_,["{"]=a1}u=function(C,D)local a0=C:sub(D,D)local t=a3[a0]if t then return t(C,D)end;G(C,D,"unexpected character '"..a0 .."'")end;function a.decode(C)if type(C)~="string"then error("expected argument of type string, got "..type(C))end;local m,D=u(C,B(C,1,w,true))D=B(C,D,w,true)if D<=#C then G(C,D,"trailing garbage")end;return m end;return a end)()
  4. -- END
  5.  
  6. -- Creating a database files
  7. local db = database.read('addon') or {}
  8. local userinfo_db = database.read('usrinfo') or {}
  9.  
  10. -- Location and version of the file
  11. local ui_location = { 'config', 'presets' }
  12.  
  13. -- Colored console logs
  14. local log_color = { r = 240, g = 240, b = 240 }
  15. local colored_text = { r = 65, g = 173, b = 224 }
  16. local client_log = function(text)
  17.     client.color_log(log_color.r, log_color.g, log_color.b, "- Downloading\0")
  18.     client.color_log(colored_text.r, colored_text.g, colored_text.b, " ", text)
  19. end
  20.  
  21. local success_log = function(text)
  22.     client.color_log(log_color.r, log_color.g, log_color.b, "- Loaded\0")
  23.     client.color_log(colored_text.r, colored_text.g, colored_text.b, " ", text)
  24. end
  25.  
  26. userinfo_db.active = true
  27.  
  28. -- Different script versions
  29. local get_lua_scripts = {
  30.     ["usr"] = 'https://pastebin.com/raw/bhKaQHTD',
  31.     ["NaN"] = '',
  32. }
  33.  
  34. -- loader
  35. local loader = function()
  36.  
  37.     local init = function(list)
  38.         local l_luas_list = ui.new_multiselect(ui_location[1], ui_location[2], "\n lua_scripts", list.title) or error('Reload active scripts')
  39.         if db.data_luas ~= nil then
  40.             ui.set(l_luas_list, db.data_luas)
  41.         end
  42.    
  43.         local loaded_luas = { }
  44.    
  45.         local contains = function(tab, val) for i = 1, #tab do if tab[i] == val then return true; end end; return false end
  46.         local load_luas = function()
  47.             if l_luas_list == nil then return end
  48.             local element = ui.get(l_luas_list)
  49.             client.color_log(0, 0, 0, ' ')
  50.             for i, link in pairs(list.links) do
  51.                 if contains(element, list.title[i]) and (loaded_luas[i] == false or loaded_luas[i] == nil) then
  52.                     http:get(link, function(response)
  53.                         loadstring(response.body)()
  54.                         loaded_luas[i] = true
  55.                         success_log(list.title[i] .. '\0')
  56.                         client.color_log(240, 240, 240, ' ')
  57.                     end)
  58.                 end
  59.             end
  60.         end
  61.         load_luas()
  62.         ui.set_callback(l_luas_list, load_luas)
  63.    
  64.         client.set_event_callback("paint_ui", function()
  65.             db.data_luas = ui.get(l_luas_list)
  66.             database.write('addon', db)
  67.         end)
  68.     end
  69.  
  70.     -- Load script from server
  71.     http:get(get_lua_scripts["usr"], function(response)
  72.         local scripts = json.decode(response.body)
  73.  
  74.         local list = { title = {}, links = {} }
  75.         for i, script in pairs(scripts.luas) do
  76.             list.title[i] = script.name
  77.             list.links[i] = script.link
  78.         end
  79.         client.color_log(240, 240, 240, '')
  80.         init(list)
  81.     end)
  82. end
  83.  
  84. if userinfo_db.active then loader() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement