diff --git a/MainModule/Client/Client.lua b/MainModule/Client/Client.lua index 184fa3824f..bf84d1cd71 100644 --- a/MainModule/Client/Client.lua +++ b/MainModule/Client/Client.lua @@ -22,25 +22,25 @@ local LoadingOrder = { --// Loccalllsssss local _G, game, script, getfenv, setfenv, workspace, - getmetatable, setmetatable, loadstring, coroutine, - rawequal, typeof, print, math, warn, error, pcall, - xpcall, select, rawset, rawget, ipairs, pairs, - next, Rect, Axes, os, tick, Faces, unpack, string, Color3, - newproxy, tostring, tonumber, Instance, TweenInfo, BrickColor, - NumberRange, ColorSequence, NumberSequence, ColorSequenceKeypoint, - NumberSequenceKeypoint, PhysicalProperties, Region3int16, - Vector3int16, elapsedTime, require, table, type, wait, - Enum, UDim, UDim2, Vector2, Vector3, Region3, CFrame, Ray, delay, spawn = +getmetatable, setmetatable, loadstring, coroutine, +rawequal, typeof, print, math, warn, error, pcall, +xpcall, select, rawset, rawget, ipairs, pairs, +next, Rect, Axes, os, tick, Faces, unpack, string, Color3, +newproxy, tostring, tonumber, Instance, TweenInfo, BrickColor, +NumberRange, ColorSequence, NumberSequence, ColorSequenceKeypoint, +NumberSequenceKeypoint, PhysicalProperties, Region3int16, +Vector3int16, elapsedTime, require, table, type, wait, +Enum, UDim, UDim2, Vector2, Vector3, Region3, CFrame, Ray, delay, spawn = _G, game, script, getfenv, setfenv, workspace, - getmetatable, setmetatable, loadstring, coroutine, - rawequal, typeof, print, math, warn, error, pcall, - xpcall, select, rawset, rawget, ipairs, pairs, - next, Rect, Axes, os, tick, Faces, unpack, string, Color3, - newproxy, tostring, tonumber, Instance, TweenInfo, BrickColor, - NumberRange, ColorSequence, NumberSequence, ColorSequenceKeypoint, - NumberSequenceKeypoint, PhysicalProperties, Region3int16, - Vector3int16, elapsedTime, require, table, type, wait, - Enum, UDim, UDim2, Vector2, Vector3, Region3, CFrame, Ray, delay, spawn; +getmetatable, setmetatable, loadstring, coroutine, +rawequal, typeof, print, math, warn, error, pcall, +xpcall, select, rawset, rawget, ipairs, pairs, +next, Rect, Axes, os, tick, Faces, unpack, string, Color3, +newproxy, tostring, tonumber, Instance, TweenInfo, BrickColor, +NumberRange, ColorSequence, NumberSequence, ColorSequenceKeypoint, +NumberSequenceKeypoint, PhysicalProperties, Region3int16, +Vector3int16, elapsedTime, require, table, type, wait, +Enum, UDim, UDim2, Vector2, Vector3, Region3, CFrame, Ray, delay, spawn; local ServicesWeUse = { "Workspace"; @@ -62,7 +62,7 @@ local ServicesWeUse = { --// Logging local clientLog = {}; -local dumplog = function() warn("::Adonis:: Dumping client log...") for i,v in ipairs(clientLog) do warn("::Adonis:: ".. tostring(v)) end end; +local dumplog = function() warn("::Adonis:: Dumping client log...") for i,v in ipairs(clientLog) do warn("::Adonis::", v) end end; local log = function(...) table.insert(clientLog, table.concat({...}, " ")) end; --// Dump log on disconnect @@ -72,8 +72,9 @@ game:GetService("NetworkClient").ChildRemoved:Connect(function(p) end) local unique = {} -local origEnv = getfenv(); setfenv(1,setmetatable({}, {__metatable = unique})) -local origWarn = warn +local origEnv = getfenv(); +setfenv(1,setmetatable({}, {__metatable = unique})) +--local origWarn = warn local startTime = tick() local clientLocked = false local oldInstNew = Instance.new @@ -81,56 +82,93 @@ local oldReq = require local Folder = script.Parent; local locals = {} local client = {} -local Queues = {} local service = {} -local RbxEvents = {} -local Debounces = {} -local LoopQueue = {} -local RealMethods = {} -local RunningLoops = {} -local HookedEvents = {} -local WaitingEvents = {} local ServiceSpecific = {} -local ServiceVariables = {} -local function isModule(module) for ind,modu in next,client.Modules do if rawequal(module, modu) then return true end end end -local function logError(err) warn("ERROR: ".. tostring(err)) if client and client.Remote then client.Remote.Send("LogError",err) end end -local message = function(...) game:GetService("TestService"):Message(...) end -local print = function(...) for i,v in next,{...}do print(':: Adonis :: '..tostring(v)) end end -local warn = function(...) for i,v in next,{...}do warn(tostring(v)) end end -local cPcall = function(func,...) local function cour(...) coroutine.resume(coroutine.create(func),...) end local ran,error=pcall(cour,...) if error then print(error) logError(error) warn('ERROR :: '..error) end end -local Pcall = function(func,...) local ran,error = pcall(func,...) if error then logError(error) end end -local Routine = function(func,...) coroutine.resume(coroutine.create(func),...) end -local Immutable = function(...) local mut = coroutine.wrap(function(...) while true do coroutine.yield(...) end end) mut(...) return mut end + +local function isModule(module) + for ind, modu in next, client.Modules do + if rawequal(module, modu) then + return true + end + end +end +local function logError(...) + warn("ERROR: ", ...) + + if client and client.Remote then + client.Remote.Send("LogError", table.concat({...}, " ")) + end +end +local print = function(...) + print(":: Adonis ::", ...) +end +--[[ +local warn = function(...) + warn(...) +end +]] +local cPcall = function(func, ...) + local ran, err = pcall(coroutine.resume, coroutine.create(func), ...) + + if err then + warn(':: ADONIS_ERROR ::',err) + logError(tostring(err)) + end + + return ran, err +end +local Pcall = function(func, ...) + local ran, err = pcall(func, ...) + + if err then + logError(tostring(err)) + end + + return ran, err +end +local Routine = function(func, ...) + return coroutine.resume(coroutine.create(func), ...) +end +local Immutable = function(...) + local mut = coroutine.wrap(function(...) + while true do + coroutine.yield(...) + end + end) + mut(...) + return mut +end local player = game:GetService("Players").LocalPlayer local Fire, Detected local wrap = coroutine.wrap local Kill; Kill = Immutable(function(info) --if true then print(info or "SOMETHING TRIED TO CRASH CLIENT?") return end wrap(function() pcall(function() - if Detected then - Detected("kick", info) - elseif Fire then - Fire("BadMemes", info) - end - end) end)() + if Detected then + Detected("kick", info) + elseif Fire then + Fire("BadMemes", info) + end + end) end)() wrap(function() pcall(function() - wait(1) - service.Player:Kick(info) - end) end)() + wait(1) + service.Player:Kick(info) + end) end)() wrap(function() pcall(function() - wait(5) - while true do - pcall(spawn,function() - spawn(Kill()) - -- memes - end) - end - end) end)() + wait(5) + while true do + pcall(spawn,function() + spawn(Kill()) + -- memes + end) + end + end) end)() end); -local GetEnv; GetEnv = function(env, repl) +local GetEnv; +GetEnv = function(env, repl) local scriptEnv = setmetatable({},{ __index = function(tab,ind) return (locals[ind] or (env or origEnv)[ind]) @@ -146,28 +184,35 @@ local GetEnv; GetEnv = function(env, repl) end return scriptEnv -end; +end local LoadModule = function(plugin, yield, envVars) - local plug = require(plugin) - if type(plug) == "function" then - if yield then - --Pcall(setfenv(plug,GetEnv(getfenv(plug), envVars))) - local ran,err = service.TrackTask("Plugin: ".. tostring(plugin), setfenv(plug, GetEnv(getfenv(plug), envVars))) - if not ran then - warn("Module encountered an error while loading: "..tostring(plugin)) - warn(tostring(err)) + local plugran, plug = pcall(require, plugin) + + if plugran then + if type(plug) == "function" then + if yield then + --Pcall(setfenv(plug,GetEnv(getfenv(plug), envVars))) + local ran,err = service.TrackTask("Plugin: ".. tostring(plugin), setfenv(plug, GetEnv(getfenv(plug), envVars))) + + if not ran then + warn("Module encountered an error while loading: "..tostring(plugin)) + warn(tostring(err)) + end + else + --service.Threads.RunTask("PLUGIN: "..tostring(plugin),setfenv(plug,GetEnv(getfenv(plug), envVars))) + local ran,err = service.TrackTask("Thread: Plugin: ".. tostring(plugin), setfenv(plug, GetEnv(getfenv(plug), envVars))) + + if not ran then + warn("Module encountered an error while loading: "..tostring(plugin)) + warn(tostring(err)) + end end else - --service.Threads.RunTask("PLUGIN: "..tostring(plugin),setfenv(plug,GetEnv(getfenv(plug), envVars))) - local ran,err = service.TrackTask("Thread: Plugin: ".. tostring(plugin), setfenv(plug, GetEnv(getfenv(plug), envVars))) - if not ran then - warn("Module encountered an error while loading: "..tostring(plugin)) - warn(tostring(err)) - end + client[plugin.Name] = plug end else - client[plugin.Name] = plug + warn("Error while loading client module", plugin, plug) end end; @@ -207,7 +252,6 @@ client = setmetatable({ return func; end end - }); locals = { @@ -233,7 +277,7 @@ service = setfenv(require(Folder.Shared.Service), GetEnv(nil, {client = client}) --player:Kick("Method error") --service.Detected("kick", "Method change detected") elseif eType == "ServerError" then - logError("Client", msg) + logError("Client", tostring(msg)) elseif eType == "ReadError" then --message("===== READ ERROR:::::::") --message(tostring(msg)) @@ -282,18 +326,35 @@ Axes = service.Localize(Axes) --// Wrap log("Wrap") -for i,val in next,service do if type(val) == "userdata" then service[i] = service.Wrap(val, true) end end -pcall(function() return service.Player.Kick end) -script = service.Wrap(script, true) -Folder = service.Wrap(Folder, true) -Enum = service.Wrap(Enum, true) -game = service.Wrap(game, true) + +local service_wrap = service.Wrap +local service_unwrap = service.UnWrap + +for i,val in next,service do if type(val) == "userdata" then service[i] = service_wrap(val, true) end end + +--// Folder Wrap +Folder = service_wrap(Folder, true) + +--// Global Wrapping +Enum = service_wrap(Enum, true) rawequal = service.RawEqual -workspace = service.Wrap(workspace, true) -Instance = {new = function(obj, parent) return service.Wrap(oldInstNew(obj, service.UnWrap(parent)), true) end} -require = function(obj) return service.Wrap(oldReq(service.UnWrap(obj)), true) end +script = service_wrap(script, true) +game = service_wrap(game, true) +workspace = service_wrap(workspace, true) +Instance = { + new = function(obj, parent) + local nobj = oldInstNew(obj) + local par = parent and service_unwrap(parent) + if par then nobj.Parent = par end + return service_wrap(nobj, true) + end +} +require = function(obj) + return service_wrap(oldReq(service_unwrap(obj)), true) +end + client.Service = service -client.Module = service.Wrap(client.Module, true) +client.Module = service_wrap(client.Module, true) --// Setting things up log("Setting things up") @@ -360,214 +421,214 @@ for ind,loc in next,{ CFrame = CFrame; Ray = Ray; service = service; -} do locals[ind] = loc end + } do locals[ind] = loc end --// Init log("Return init function"); -return service.NewProxy({__metatable = "Adonis"; __tostring = function() return "Adonis" end; __call = function(tab,data) - log("Begin init"); - - local remoteName,depsName = string.match(data.Name, "(.*)\\(.*)") - Folder = service.Wrap(data.Folder or folder:Clone() or Folder) - - setfenv(1,setmetatable({}, {__metatable = unique})) - client.Folder = Folder; - client.UIFolder = Folder:WaitForChild("UI"); - client.Shared = Folder:WaitForChild("Shared"); - client.Loader = data.Loader - client.Module = data.Module - client.DepsName = depsName - client.TrueStart = data.Start - client.LoadingTime = data.LoadingTime - client.RemoteName = remoteName - - --// Toss deps into a table so we don't need to directly deal with the Folder instance they're in - log("Get dependencies") - for ind,obj in next,Folder:WaitForChild("Dependencies"):GetChildren() do client.Deps[obj.Name] = obj end - - --// Do this before we start hooking up events - log("Destroy script object") - --folder:Destroy() - script:Destroy() - - --// Intial setup - log("Initial services caching") - for ind, serv in next,ServicesWeUse do local temp = service[serv] end - - --// Client specific service variables/functions - log("Add service specific") - ServiceSpecific.Player = service.Players.LocalPlayer; - ServiceSpecific.PlayerGui = service.Player:FindFirstChild("PlayerGui"); - ServiceSpecific.SafeTweenSize = function(obj,...) pcall(obj.TweenSize,obj,...) end; - ServiceSpecific.SafeTweenPos = function(obj,...) pcall(obj.TweenPosition,obj,...) end; - ServiceSpecific.Filter = function(str,from,to) - return client.Remote.Get("Filter",str,(to and from) or service.Player,to or from) - end; - - ServiceSpecific.LaxFilter = function(str,from) - return service.Filter(str,from or service.Player,from or service.Player) - end; - - ServiceSpecific.BroadcastFilter = function(str,from) - return client.Remote.Get("BroadcastFilter",str,from or service.Player) - end; +return service.NewProxy({ + __call = function(self, data) + log("Begin init"); + + local remoteName,depsName = string.match(data.Name, "(.*)\\(.*)") + Folder = service.Wrap(data.Folder or folder and folder:Clone() or Folder) + + setfenv(1,setmetatable({}, {__metatable = unique})) + client.Folder = Folder; + client.UIFolder = Folder:WaitForChild("UI"); + client.Shared = Folder:WaitForChild("Shared"); + client.Loader = data.Loader + client.Module = data.Module + client.DepsName = depsName + client.TrueStart = data.Start + client.LoadingTime = data.LoadingTime + client.RemoteName = remoteName + + --// Toss deps into a table so we don't need to directly deal with the Folder instance they're in + log("Get dependencies") + for ind,obj in next,Folder:WaitForChild("Dependencies"):GetChildren() do client.Deps[obj.Name] = obj end + + --// Do this before we start hooking up events + log("Destroy script object") + --folder:Destroy() + script:Destroy() + + --// Intial setup + log("Initial services caching") + for ind, serv in next,ServicesWeUse do local temp = service[serv] end + + --// Client specific service variables/functions + log("Add service specific") + ServiceSpecific.Player = service.Players.LocalPlayer; + ServiceSpecific.PlayerGui = service.Player:FindFirstChild("PlayerGui"); + ServiceSpecific.SafeTweenSize = function(obj,...) pcall(obj.TweenSize,obj,...) end; + ServiceSpecific.SafeTweenPos = function(obj,...) pcall(obj.TweenPosition,obj,...) end; + ServiceSpecific.Filter = function(str,from,to) + return client.Remote.Get("Filter",str,(to and from) or service.Player,to or from) + end; - ServiceSpecific.IsMobile = function() - if service.UserInputService.TouchEnabled and not service.UserInputService.MouseEnabled and not service.UserInputService.KeyboardEnabled then - return true - else - return false - end - end; + ServiceSpecific.LaxFilter = function(str,from) + return service.Filter(str,from or service.Player,from or service.Player) + end; - ServiceSpecific.LocalContainer = function() - if not client.Variables.LocalContainer or not client.Variables.LocalContainer.Parent then - client.Variables.LocalContainer = service.New("Folder") - client.Variables.LocalContainer.Name = client.Functions.GetRandom() - client.Variables.LocalContainer.Parent = service.Workspace - end - return client.Variables.LocalContainer - end; + ServiceSpecific.BroadcastFilter = function(str,from) + return client.Remote.Get("BroadcastFilter",str,from or service.Player) + end; - --// Load Core Modules - log("Loading core modules") - for ind,load in next,LoadingOrder do - local modu = Folder.Core:FindFirstChild(load) - if modu then - log("~! Loading Core Module: ".. tostring(load)) - LoadModule(modu, true, {script = script}) - end - end + ServiceSpecific.IsMobile = function() + return service.UserInputService.TouchEnabled and not service.UserInputService.MouseEnabled and not service.UserInputService.KeyboardEnabled + end; - --// Start of module loading and server connection process - local runLast = {} - local runAfterInit = {} - local runAfterLoaded = {} - local runAfterPlugins = {} - - --// Loading Finisher - client.Finish_Loading = function() - log("Client fired finished loading") - if client.Core.Key then - --// Run anything from core modules that needs to be done after the client has finished loading - log("~! Doing run after loaded") - for i,f in next,runAfterLoaded do - Pcall(f, data); + ServiceSpecific.LocalContainer = function() + if not client.Variables.LocalContainer or not client.Variables.LocalContainer.Parent then + client.Variables.LocalContainer = service.New("Folder") + client.Variables.LocalContainer.Name = "__ADONIS_LOCALCONTAINER_" .. client.Functions.GetRandom() + client.Variables.LocalContainer.Parent = service.Workspace end + return client.Variables.LocalContainer + end; - --// Stuff to run after absolutely everything else - log("~! Doing run last") - for i,f in next,runLast do - Pcall(f, data); + --// Load Core Modules + log("Loading core modules") + for ind,load in next,LoadingOrder do + local modu = Folder.Core:FindFirstChild(load) + if modu then + log("~! Loading Core Module: ".. tostring(load)) + LoadModule(modu, true, {script = script}) end - - --// Finished loading - log("Finish loading") - clientLocked = true - client.Finish_Loading = function() end - client.LoadingTime() --origWarn(tostring(tick()-(client.TrueStart or startTime))) - service.Events.FinishedLoading:Fire(os.time()) - - log("~! FINISHED LOADING!") - else - log("Client missing remote key") - client.Kill()("Missing remote key") end - end - --// Initialize Cores - log("~! Init cores"); - for i,name in next,LoadingOrder do - local core = client[name] - log("~! INIT: ".. tostring(name)) - - if core then - if type(core) == "table" or (type(core) == "userdata" and getmetatable(core) == "ReadOnly_Table") then - if core.RunLast then - table.insert(runLast, core.RunLast); - core.RunLast = nil; + --// Start of module loading and server connection process + local runLast = {} + local runAfterInit = {} + local runAfterLoaded = {} + local runAfterPlugins = {} + + --// Loading Finisher + client.Finish_Loading = function() + log("Client fired finished loading") + if client.Core.Key then + --// Run anything from core modules that needs to be done after the client has finished loading + log("~! Doing run after loaded") + for i,f in next,runAfterLoaded do + Pcall(f, data); end - if core.RunAfterInit then - table.insert(runAfterInit, core.RunAfterInit); - core.RunAfterInit = nil; + --// Stuff to run after absolutely everything else + log("~! Doing run last") + for i,f in next,runLast do + Pcall(f, data); end - if core.RunAfterPlugins then - table.insert(runAfterPlugins, core.RunAfterPlugins); - core.RunAfterPlugins = nil; - end - - if core.RunAfterLoaded then - table.insert(runAfterLoaded, core.RunAfterLoaded); - core.RunAfterLoaded = nil; - end + --// Finished loading + log("Finish loading") + clientLocked = true + client.Finish_Loading = function() end + client.LoadingTime() --origWarn(tostring(tick()-(client.TrueStart or startTime))) + service.Events.FinishedLoading:Fire(os.time()) + + log("~! FINISHED LOADING!") + else + log("Client missing remote key") + client.Kill()("Missing remote key") + end + end - if core.Init then - log("Run init for ".. tostring(name)) - Pcall(core.Init, data); - core.Init = nil; + --// Initialize Cores + log("~! Init cores"); + for i,name in next,LoadingOrder do + local core = client[name] + log("~! INIT: ".. tostring(name)) + + if core then + if type(core) == "table" or (type(core) == "userdata" and getmetatable(core) == "ReadOnly_Table") then + if core.RunLast then + table.insert(runLast, core.RunLast); + core.RunLast = nil; + end + + if core.RunAfterInit then + table.insert(runAfterInit, core.RunAfterInit); + core.RunAfterInit = nil; + end + + if core.RunAfterPlugins then + table.insert(runAfterPlugins, core.RunAfterPlugins); + core.RunAfterPlugins = nil; + end + + if core.RunAfterLoaded then + table.insert(runAfterLoaded, core.RunAfterLoaded); + core.RunAfterLoaded = nil; + end + + if core.Init then + log("Run init for ".. tostring(name)) + Pcall(core.Init, data); + core.Init = nil; + end end end end - end - --// Load any afterinit functions from modules (init steps that require other modules to have finished loading) - log("~! Running after init") - for i,f in next,runAfterInit do - Pcall(f, data); - end + --// Load any afterinit functions from modules (init steps that require other modules to have finished loading) + log("~! Running after init") + for i,f in next,runAfterInit do + Pcall(f, data); + end - --// Load Plugins - log("~! Running plugins") - for index,plugin in next,Folder.Plugins:GetChildren() do - LoadModule(plugin, false, {script = plugin}); --noenv - end + --// Load Plugins + log("~! Running plugins") + for index,plugin in next,Folder.Plugins:GetChildren() do + LoadModule(plugin, false, {script = plugin}); --noenv + end - --// We need to do some stuff *after* plugins are loaded (in case we need to be able to account for stuff they may have changed before doing something, such as determining the max length of remote commands) - log("~! Running after plugins") - for i,f in next,runAfterPlugins do - Pcall(f, data); - end + --// We need to do some stuff *after* plugins are loaded (in case we need to be able to account for stuff they may have changed before doing something, such as determining the max length of remote commands) + log("~! Running after plugins") + for i,f in next,runAfterPlugins do + Pcall(f, data); + end - log("Initial loading complete") - - --// Below can be used to determine when all modules and plugins have finished loading; service.Events.AllModulesLoaded:Connect(function() doSomething end) - client.AllModulesLoaded = true; - service.Events.AllModulesLoaded:Fire(os.time()); - - --[[client = service.ReadOnly(client, { - [client.Variables] = true; - [client.Handlers] = true; - G_API = true; - G_Access = true; - G_Access_Key = true; - G_Access_Perms = true; - Allowed_API_Calls = true; - HelpButtonImage = true; - Finish_Loading = true; - RemoteEvent = true; - ScriptCache = true; - Returns = true; - PendingReturns = true; - EncodeCache = true; - DecodeCache = true; - Received = true; - Sent = true; - Service = true; - Holder = true; - GUIs = true; - LastUpdate = true; - RateLimits = true; - - Init = true; - RunAfterInit = true; - RunAfterLoaded = true; - RunAfterPlugins = true; - }, true)--]] - - service.Events.ClientInitialized:Fire(); - - log("~! Return success"); - return "SUCCESS" -end}) + log("Initial loading complete") + + --// Below can be used to determine when all modules and plugins have finished loading; service.Events.AllModulesLoaded:Connect(function() doSomething end) + client.AllModulesLoaded = true; + service.Events.AllModulesLoaded:Fire(os.time()); + + --[[client = service.ReadOnly(client, { + [client.Variables] = true; + [client.Handlers] = true; + G_API = true; + G_Access = true; + G_Access_Key = true; + G_Access_Perms = true; + Allowed_API_Calls = true; + HelpButtonImage = true; + Finish_Loading = true; + RemoteEvent = true; + ScriptCache = true; + Returns = true; + PendingReturns = true; + EncodeCache = true; + DecodeCache = true; + Received = true; + Sent = true; + Service = true; + Holder = true; + GUIs = true; + LastUpdate = true; + RateLimits = true; + + Init = true; + RunAfterInit = true; + RunAfterLoaded = true; + RunAfterPlugins = true; + }, true)--]] + + service.Events.ClientInitialized:Fire(); + + log("~! Return success"); + return "SUCCESS" + end; + __metatable = "Adonis"; + __tostring = function() return "Adonis" end; +}) diff --git a/MainModule/Server/Shared/Service.lua b/MainModule/Server/Shared/Service.lua index df24df15e0..e9277bc4a3 100644 --- a/MainModule/Server/Shared/Service.lua +++ b/MainModule/Server/Shared/Service.lua @@ -481,11 +481,7 @@ return function(errorHandler, eventChecker, fenceSpecific) end end; Wrapped = function(object) - if getmetatable(object) == "Adonis_Proxy" then - return true - else - return false - end + return getmetatable(object) == "Adonis_Proxy" end; UnWrap = function(object) if type(object) == "table" then