This repository has been archived by the owner on Jul 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
ConfigManager.lua
279 lines (258 loc) · 6.33 KB
/
ConfigManager.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
local required = {
"isfolder",
"makefolder",
"isfile",
"writefile",
"readfile",
"delfile",
"listfiles"
}
local missing = {}
for _,v in next, required do
if not getgenv()[v] then
table.insert(missing, v)
end
end
if #missing > 0 then
local a = Instance.new("Message", workspace)
a.Text = "-- Config Manager --\nYour exploit does not have the following functions:\n"..table.concat(missing, "\n").."\n\n(this means you need a better exploit)"
task.wait(10)
a:Destroy()
return
end
local http = game:GetService("HttpService")
local months = {[1] = "January", [2] = "February", [3] = "March", [4] = "April", [5] = "May", [6] = "June", [7] = "July", [8] = "August", [9] = "September", [10] = "October", [11] = "November", [12] = "December"}
function Encode(a)
return http:JSONEncode(a)
end
function Decode(a)
return http:JSONDecode(a)
end
function GetDate()
local a = os.date("*t")
local month = months[a.month]
local day = a.day
local year = a.year
local hour = (a.hour < 10 and "0"..a.hour) or a.hour
local minute = (a.min < 10 and "0"..a.min) or a.min
local second = (a.sec < 10 and "0"..a.sec) or a.sec
return string.format("%s %s, %s | %s:%s:%s", month, day, year, hour, minute, second)
end
function ToTable(a) -- converts data types to tables
local t = typeof(a)
local b = {}
if t == "Color3" then
b.Values = {
[1] = a.R,
[2] = a.G,
[3] = a.B
}
elseif t == "Vector2" then
b.Values = {
[1] = a.X,
[2] = a.Y
}
elseif t == "Vector3" then
b.Values = {
[1] = a.X,
[2] = a.Y,
[3] = a.Z
}
elseif t == "CFrame" then
local pos, xv, yv, zv = a.Position, a.XVector, a.YVector, a.ZVector
b.Values = {
[1] = pos.X,
[2] = pos.Y,
[3] = pos.Z,
[4] = xv.X,
[5] = yv.X,
[6] = zv.X,
[7] = xv.Y,
[8] = yv.Y,
[9] = zv.Y,
[10] = xv.Z,
[11] = yv.Z,
[12] = zv.Z
}
elseif t == "UDim" then
b.Values = {
[1] = a.Scale,
[2] = a.Offset
}
elseif t == "UDim2" then
b.Values = {
[1] = a.X.Scale,
[2] = a.X.Offset,
[3] = a.Y.Scale,
[4] = a.Y.Offset
}
elseif t == "BrickColor" then
b.Values = {
[1] = a.Name
}
end
b.__ValueTable = t
return b
end
local new = {
Color3 = Color3.new,
Vector2 = Vector2.new,
Vector3 = Vector3.new,
CFrame = CFrame.new,
UDim = UDim.new,
UDim2 = UDim2.new,
BrickColor = BrickColor.new
}
function ToValue(a) -- converts tables to data types
return new[a.__ValueTable](unpack(a.Values))
end
function CloneTable(a) -- clones a table so it doesnt fuck up the original table during conversion
local t = {}
for i,v in next, a do
if typeof(v) == "table" then
v = CloneTable(v)
end
t[i] = v
end
return t
end
function ConvertData(a) -- recursively converts data types to tables (encoding)
for i,v in next, a do
if typeof(v) == "table" then
a[i] = ConvertData(v)
elseif new[typeof(v)] ~= nil then
a[i] = ToTable(v)
end
end
return a
end
function ConvertTables(a) -- recursively converts tables to data types (decoding)
for i,v in next, a do
if typeof(v) == "table" then
if v.__ValueTable ~= nil then
a[i] = ToValue(v)
else
a[i] = ConvertTables(v)
end
end
end
return a
end
local Initialized = false
local Folder = ""
function Exists(a)
return isfile(Folder..a..".json")
end
function Read(a)
return ConvertTables(Decode(readfile(Folder..a..".json")))
end
function Write(a, data)
writefile(Folder..a..".json", Encode(ConvertData(CloneTable(data))))
end
function Init(a, d, c)
assert(not Initialized, "Config Manager has already been initialized")
assert(typeof(a) == "string", "bad argument #1 to 'Init' (string expected, got "..typeof(a)..")")
assert(a:gsub(" ","") ~= "", "bad argument #1 to 'Init' (string is empty)")
assert(typeof(d) == "table", "bad argument #2 to 'Init' (table expected, got "..typeof(d)..")")
if not isfolder(a) then
makefolder(a)
Folder = a.."\\"
end
Folder = a.."\\"
if not Exists("Default") then
Write("Default", {Saved = GetDate(), Data = d})
end
local file = Read("Default")
Initialized = true
if typeof(c) == "function" then
c(file)
end
return file
end
function Load(a, c)
assert(Initialized, "Config Manager has not been initialized")
if Exists(a) then
local file = Read(a)
if typeof(c) == "function" then
c(file)
end
return file
end
end
function Save(a, t)
assert(Initialized, "Config Manager has not been initialized")
Write(a, {Saved = GetDate(), Data = t})
end
function Get()
assert(Initialized, "Config Manager has not been initialized")
local flen = Folder:len()
local t = {}
for _,v in next, listfiles(Folder) do
table.insert(t, v:sub(flen + 1, -6))
end
table.sort(t, function(a, b)
return a < b
end)
return t
end
function SetDefault(a)
assert(Initialized, "Config Manager has not been initialized")
if Exists(a) then
Write("Default", Read(a))
end
end
function Delete(a)
assert(Initialized, "Config Manager has not been initialized")
if Exists(a) then
delfile(Folder..a..".json")
end
end
function Valid(a)
return Exists(a)
end
return {
Init = Init,
Load = Load,
Save = Save,
Get = Get,
SetDefault = SetDefault,
Delete = Delete,
Valid = Valid,
Encode = function(data)
return Encode(ConvertData({Saved = GetDate(), Data = CloneTable(data)}))
end,
Decode = function(data)
return ConvertTables(Decode(data))
end
}
--[[
Init
<table> Init(<string> Name, <table> Default, <function?> Callback)
Initializes Config Manager. Loads and returns the default config.
If a Callback is specified, it calls that function with the default config as a parameter.
Load
<table> Load(<string> Config, <function?> Callback)
Loads and returns the specified Config.
If a Callback is specified, it calls that function with the specified Config as a parameter.
Save
<void> Save(<string> Config, <table> Data)
Creates a new config with Data.
Get
<table> Get(<void>)
Returns an array of all of your configs.
Set Default
<void> SetDefault(<string> Config)
Sets the specified Config to the default config.
Delete
<void> Delete(<string> Config)
Deletes the specified Config.
Valid
<bool> Valid(<string> Config)
Returns true if the specified Config exists.
Encode
<string> Encode(<table> Data)
Encodes Data and returns it. This is a copy of the function that is used to write configs.
Decode
<table> Decode(<string> Data)
Decodes Data and returns it. This is a copy of the function that is used to read configs.
]]