Skip to content

Commit

Permalink
Merge pull request #540 from fxeP1/master
Browse files Browse the repository at this point in the history
Admin/Commands/Core/Process.lua | Optimizations
  • Loading branch information
Sceleratis authored Oct 30, 2021
2 parents 9373376 + b004a79 commit c563d10
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 284 deletions.
113 changes: 57 additions & 56 deletions MainModule/Client/Client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ local service = {}
local ServiceSpecific = {}

local function isModule(module)
for ind, modu in next, client.Modules do
for ind, modu in pairs(client.Modules) do
if rawequal(module, modu) then
return true
end
Expand Down Expand Up @@ -185,7 +185,7 @@ GetEnv = function(env, repl)
})

if repl and type(repl)=="table" then
for ind, val in next,repl do
for ind, val in pairs(repl) do
scriptEnv[ind] = val
end
end
Expand Down Expand Up @@ -278,7 +278,7 @@ locals = {

log("Create service metatable");

service = setfenv(require(Folder.Shared.Service), GetEnv(nil, {client = client}))(function(eType, msg, desc, ...)
service = require(Folder.Shared.Service)(function(eType, msg, desc, ...)
local extra = {...}
if eType == "MethodError" and service.Detected then
Kill()("Shananigans denied")
Expand All @@ -301,73 +301,74 @@ end, function(c, parent, tab)
if not isModule(c) and c ~= script and c ~= Folder and parent == nil then
tab.UnHook()
end
end, ServiceSpecific)
end, ServiceSpecific, GetEnv(nil, {client = client}))

--// Localize
log("Localize");
os = service.Localize(os)
math = service.Localize(math)
table = service.Localize(table)
string = service.Localize(string)
coroutine = service.Localize(coroutine)
Instance = service.Localize(Instance)
Vector2 = service.Localize(Vector2)
Vector3 = service.Localize(Vector3)
CFrame = service.Localize(CFrame)
UDim2 = service.Localize(UDim2)
UDim = service.Localize(UDim)
Ray = service.Localize(Ray)
Rect = service.Localize(Rect)
Faces = service.Localize(Faces)
Color3 = service.Localize(Color3)
NumberRange = service.Localize(NumberRange)
NumberSequence = service.Localize(NumberSequence)
NumberSequenceKeypoint = service.Localize(NumberSequenceKeypoint)
ColorSequenceKeypoint = service.Localize(ColorSequenceKeypoint)
PhysicalProperties = service.Localize(PhysicalProperties)
ColorSequence = service.Localize(ColorSequence)
Region3int16 = service.Localize(Region3int16)
Vector3int16 = service.Localize(Vector3int16)
BrickColor = service.Localize(BrickColor)
TweenInfo = service.Localize(TweenInfo)
Axes = service.Localize(Axes)
task = service.Localize(task)
local Localize = service.Localize
os = Localize(os)
math = Localize(math)
table = Localize(table)
string = Localize(string)
coroutine = Localize(coroutine)
Instance = Localize(Instance)
Vector2 = Localize(Vector2)
Vector3 = Localize(Vector3)
CFrame = Localize(CFrame)
UDim2 = Localize(UDim2)
UDim = Localize(UDim)
Ray = Localize(Ray)
Rect = Localize(Rect)
Faces = Localize(Faces)
Color3 = Localize(Color3)
NumberRange = Localize(NumberRange)
NumberSequence = Localize(NumberSequence)
NumberSequenceKeypoint = Localize(NumberSequenceKeypoint)
ColorSequenceKeypoint = Localize(ColorSequenceKeypoint)
PhysicalProperties = Localize(PhysicalProperties)
ColorSequence = Localize(ColorSequence)
Region3int16 = Localize(Region3int16)
Vector3int16 = Localize(Vector3int16)
BrickColor = Localize(BrickColor)
TweenInfo = Localize(TweenInfo)
Axes = Localize(Axes)
task = Localize(task)

--// Wrap
log("Wrap")

local service_wrap = service.Wrap
local service_unwrap = service.UnWrap
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
for i,val in pairs(service) do if type(val) == "userdata" then service[i] = service_Wrap(val, true) end end

--// Folder Wrap
Folder = service_wrap(Folder, true)
Folder = service_Wrap(Folder, true)

--// Global Wrapping
Enum = service_wrap(Enum, true)
Enum = service_Wrap(Enum, true)
rawequal = service.RawEqual
script = service_wrap(script, true)
game = service_wrap(game, true)
workspace = service_wrap(workspace, true)
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)
local par = parent and service_UnWrap(parent)
if par then nobj.Parent = par end
return service_wrap(nobj, true)
return service_Wrap(nobj, true)
end
}
require = function(obj)
return service_wrap(oldReq(service_unwrap(obj)), true)
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")
for ind,loc in next,{
for ind,loc in pairs({
_G = _G;
game = game;
spawn = spawn;
Expand Down Expand Up @@ -432,7 +433,7 @@ for ind,loc in next,{
task = task;
tick = tick;
service = service;
} do locals[ind] = loc end
}) do locals[ind] = loc end

--// Init
log("Return init function");
Expand All @@ -445,8 +446,8 @@ return service.NewProxy({

setfenv(1,setmetatable({}, {__metatable = unique}))
client.Folder = Folder;
client.UIFolder = Folder:WaitForChild("UI");
client.Shared = Folder:WaitForChild("Shared");
client.UIFolder = Folder:WaitForChild("UI",9e9);
client.Shared = Folder:WaitForChild("Shared",9e9);
client.Loader = data.Loader
client.Module = data.Module
client.DepsName = depsName
Expand All @@ -456,7 +457,7 @@ return service.NewProxy({

--// 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
for ind,obj in ipairs(Folder:WaitForChild("Dependencies",9e9):GetChildren()) do client.Deps[obj.Name] = obj end

--// Do this before we start hooking up events
log("Destroy script object")
Expand All @@ -465,7 +466,7 @@ return service.NewProxy({

--// Intial setup
log("Initial services caching")
for ind, serv in next,ServicesWeUse do local temp = service[serv] end
for ind, serv in ipairs(ServicesWeUse) do local temp = service[serv] end

--// Client specific service variables/functions
log("Add service specific")
Expand Down Expand Up @@ -521,7 +522,7 @@ return service.NewProxy({

--// Load Core Modules
log("Loading core modules")
for ind,load in next,LoadingOrder do
for ind,load in ipairs(LoadingOrder) do
local modu = Folder.Core:FindFirstChild(load)
if modu then
log("~! Loading Core Module: ".. tostring(load))
Expand All @@ -541,13 +542,13 @@ return service.NewProxy({
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
for i,f in pairs(runAfterLoaded) do
Pcall(f, data);
end

--// Stuff to run after absolutely everything else
log("~! Doing run last")
for i,f in next,runLast do
for i,f in pairs(runLast) do
Pcall(f, data);
end

Expand All @@ -567,7 +568,7 @@ return service.NewProxy({

--// Initialize Cores
log("~! Init cores");
for i,name in next,LoadingOrder do
for i,name in ipairs(LoadingOrder) do
local core = client[name]
log("~! INIT: ".. tostring(name))

Expand Down Expand Up @@ -604,19 +605,19 @@ return service.NewProxy({

--// 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
for i,f in pairs(runAfterInit) do
Pcall(f, data);
end

--// Load Plugins
log("~! Running plugins")
for index,plugin in next,Folder.Plugins:GetChildren() do
for index,plugin in ipairs(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
for i,f in pairs(runAfterPlugins) do
Pcall(f, data);
end

Expand Down
51 changes: 32 additions & 19 deletions MainModule/Server/Commands/Moderators.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ return function(Vargs, env)

local nilPlayers = 0
for i,v in pairs(service.NetworkServer:GetChildren()) do
if v and v:GetPlayer() and not service.Players:FindFirstChild(v:GetPlayer().Name) then
if v:IsA("NetworkReplicator") and v:GetPlayer() and not service.Players:FindFirstChild(v:GetPlayer().Name) then
nilPlayers = nilPlayers + 1
end
end
Expand Down Expand Up @@ -2871,29 +2871,40 @@ return function(Vargs, env)
Function = function(plr,args)
for i,v in pairs(service.GetPlayers(plr,args[1])) do
Routine(function()
if v and v.Character and v.Character:FindFirstChild("Humanoid") then
v.Character.Archivable = true
local cl = v.Character:Clone()
local Character = v.Character
local Humanoid = Character and Character:FindFirstChildOfClass("Humanoid")

if Humanoid then
Character.Archivable = true

local cl = Character:Clone()
table.insert(Variables.Objects,cl)

local Animate
local anim = cl:FindFirstChild("Animate")
if anim then
local Animate = v.Character.Humanoid.RigType == Enum.HumanoidRigType.R15 and Deps.Assets.R15Animate:Clone() or Deps.Assets.R6Animate:Clone()
Animate = Humanoid.RigType == Enum.HumanoidRigType.R15 and Deps.Assets.R15Animate:Clone() or Deps.Assets.R6Animate:Clone()
Animate:ClearAllChildren()
for _,v in ipairs(anim:GetChildren()) do
for _, v in ipairs(anim:GetChildren()) do
v.Parent = Animate
end
anim:Destroy()

Animate.Parent = cl
end

if Character.PrimaryPart then
cl:SetPrimaryPartCFrame(Character.PrimaryPart.CFrame)
end
if Animate then
Animate.Disabled = false
anim:Destroy()
end
cl:FindFirstChild("Humanoid").Died:Connect(function()
cl:Destroy()
end)

cl.Archivable = false
cl.Parent = workspace
cl:MoveTo(v.Character:GetModelCFrame().p)
cl:MakeJoints()
cl:WaitForChild("Humanoid")
v.Character.Archivable = false
repeat wait(0.5) until not cl:FindFirstChild("Humanoid") or cl.Humanoid.Health <= 0
wait(5)
if cl then cl:Destroy() end
end
end)
end
Expand Down Expand Up @@ -5887,24 +5898,25 @@ return function(Vargs, env)

local function makeBot(player)
local char = player.Character
local torso = player.Character:FindFirstChild("HumanoidRootPart")
local torso = char:FindFirstChild("HumanoidRootPart") or char.PrimaryPart
local pos = torso.CFrame
local clone

local clone
char.Archivable = true
clone = char:Clone()
char.Archivable = false

for i = 1, num do
local new = clone:Clone()
local hum = new:FindFirstChildOfClass("Humanoid")

local brain = Deps.Assets.BotBrain:Clone()
local event = brain.Event

local oldAnim = new:FindFirstChild("Animate")
local isR15 = (hum.RigType == "R15")
local anim = (isR15 and Deps.Assets.R15Animate:Clone()) or Deps.Assets.R6Animate:Clone()

new.Parent = workspace
new.Name = player.Name
new.HumanoidRootPart.CFrame = pos*CFrame.Angles(0,math.rad((360/num)*i),0)*CFrame.new((num*0.2)+5,0,0)

Expand All @@ -5917,10 +5929,11 @@ return function(Vargs, env)
end

anim.Parent = new
anim.Disabled = false

brain.Parent = new

anim.Disabled = false
brain.Disabled = false
new.Parent = workspace

wait()

Expand Down
Loading

0 comments on commit c563d10

Please sign in to comment.