-
Notifications
You must be signed in to change notification settings - Fork 0
/
sekai.lua
310 lines (298 loc) · 7.97 KB
/
sekai.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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
local Environment = (getfenv or function() return _G end)(0) --(getfenv or getenv or os.getenv or os.getfenv)(0)
local Variables = {}
local Addresses = {}
local CurrentLine = 1
function SplitString(inputstr, sep)
if string.split then
return string.split(inputstr, sep)
else
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
end
function SplitIntoCharacters(input)
local Table = {}
for i = 1, #input do
table.insert(Table, string.sub(input, i, i))
end
return Table
end
function HashToAddress(___)
return (function()
local Hash = SHA1(___):sub(1, 8)
if tostring(Hash:sub(1, 1)) == "0" then
Hash = "f"..Hash:sub(2)
end
return Hash:upper()
end)()
end
for __, _ in pairs(builtins) do
if Environment[__] then
local Hash = HashToAddress(__)
Addresses[Hash] = {
__ = __,
___ = Environment[__]
}
end
end
function ReverseTable(Table)
local ReversedTable = {}
for i = 0, #Table - 1 do
table.insert(ReversedTable, Table[(#Table) - i])
end
return ReversedTable
end
function RetrieveInstruction(_Address)
local Address = tostring(_Address:upper())
if Addresses[Address] then
-- INSTRUCTION
return Addresses[Address]["___"]
else
if Address:sub(1, 1) == "0" then
-- NUMBER?!??!!?
return tonumber(Address)
elseif Address:sub(1, 1) == "Z" then
local VariableName = Address:sub(2, 7)
for ___, ____ in pairs({
-- GENERAL PURPOSE
["0"] = function()
-- RETRIEVE VARIABLE
return Variables[VariableName]
end,
["1"] = function(Argument)
-- SET VARIABLE
if tonumber(Argument) then
Argument = tonumber(Argument)
end
Variables[VariableName] = Argument
end,
-- NUMBERS AND STUFFS
["2"] = function(Number)
-- ADD
if tonumber(Number) ~= Number then
return print('Number to operate on must be an int')
end
return Variables[VariableName] + Number
end,
["3"] = function(Number)
-- SUB
if tonumber(Number) ~= Number then
return print('Number to operate on must be an int')
end
return Variables[VariableName] - Number
end,
["4"] = function(Number)
-- MUL
if tonumber(Number) ~= Number then
return print('Number to operate on must be an int')
end
return Variables[VariableName] * Number
end,
["5"] = function(Number)
-- DIV
if tonumber(Number) ~= Number then
return print('Number to operate on must be an int')
end
return Variables[VariableName] / Number
end,
["6"] = function()
-- NEG
return -Variables[VariableName]
end,
["7"] = function()
-- OPP
return not Variables[VariableName]
end,
-- STRING FUNCTIONS
["A"] = function(...)
-- SET NEXT CHAR
if type(({...})[1]) == "string" then
for _, CharacterNumber in pairs({...}) do
Variables[VariableName] = Variables[VariableName] .. CharacterNumber
end
else
for _, CharacterNumber in pairs({...}) do--ReverseTable({...})) do
if Variables[VariableName] then
if tostring(Variables[VariableName]) ~= Variables[VariableName] then
print('Can\'t edit a non-string variable!')
break
end
else
Variables[VariableName] = ""
end
--[[if tonumber(CharacterNumber) ~= CharacterNumber then
print('Can\'t edit a string variable with '..type(CharacterNumber)..'! Please use a number.')
break
end]]
Variables[VariableName] = Variables[VariableName] .. string.char(CharacterNumber)
end
end
end,
-- IF STATEMENTS
["B"] = function(...)
return Variables[VariableName] == ({...})[1]
end,
["C"] = function(...)
return Variables[VariableName] > ({...})[1]
end,
["D"] = function(...)
return Variables[VariableName] < ({...})[1]
end,
["E"] = function(...)
return Variables[VariableName] >= ({...})[1]
end,
["F"] = function(...)
return Variables[VariableName] <= ({...})[1]
end,
}) do
if ___ == Address:sub(8) then
return ____
end
end
else
return _Address
end
end
end
function EnforceRules(Instruction, DoesntFollowRules)
local FollowsRules = true
if #Instruction ~= 8 then
FollowsRules = false
end
if Instruction ~= string.upper(Instruction) then
FollowsRules = false
end
if not FollowsRules then
DoesntFollowRules()
end
end
function HandleArguments(Instruction, DoesntFollowRules)
local HandleArgument = function(Argument, Arguments)
EnforceRules(Argument, function()
return DoesntFollowRules()
end)
local InstructionFunction = RetrieveInstruction(Argument)
if type(InstructionFunction) == "function" then
InstructionFunction = InstructionFunction(table.unpack(Arguments or {}))
end
return InstructionFunction
end
local Arguments = {}
if #Instruction > 1 then
-- Run arguments backwards.
local ReversedArguments = {}
for _, _Instruction in pairs(ReverseTable(Instruction)) do
local PiledArguments = {}
for e = 0, #ReversedArguments - 1 do
local _Argument = ReversedArguments[(#ReversedArguments) - e]
table.insert(PiledArguments, _Argument)
--print(_Argument)
end
table.insert(ReversedArguments, HandleArgument(_Instruction, PiledArguments))
end
Arguments = ReverseTable(ReversedArguments)
else
-- We can just handle the first argument, by itself.
table.insert(Arguments, HandleArgument(Instruction[1]))
end
return Arguments
end
function Interpret(UnparsedScript)
CurrentLine = 1
local Script = SplitString(UnparsedScript, '\n')
local OK = true
while CurrentLine <= #Script and OK do
if Script[CurrentLine]:sub(1, 1) == "#" then
-- It's a comment. Let's ignore it.
else
local Instruction = SplitString(Script[CurrentLine], ' ')
local InstructionFunction = RetrieveInstruction(Instruction[1])
EnforceRules(Instruction[1], function()
print('Syntax error')
OK = false
return
end)
if InstructionFunction then
if type(InstructionFunction) == "function" then
table.remove(Instruction, 1)
local Arguments = HandleArguments(Instruction, function()
print('Syntax error')
OK = false
return
end)
InstructionFunction(table.unpack(Arguments))
else
print('Not function, skipping~')
end
end
end
CurrentLine = CurrentLine + 1
end
end
for __, ___ in pairs({
-- # GENERAL PURPOSE
['getindex'] = function(From, ...)
local Initial = From
for _, Index in pairs({...}) do
if Initial[Index] then
Initial = Initial[Index]
end
end
return Initial
end,
['setindex'] = function(ToSet, Index, Value)
ToSet[Index] = Value
end,
['call'] = function(ToCall, ...)
return ToCall(...)
end,
['createtable'] = function(...)
local InitialTable = {}
for _, Argument in pairs({...}) do
table.insert(InitialTable)
end
return InitialTable
end,
['tick'] = function()
return game:GetService('RunService').Heartbeat:Wait()
end,
-- # JUMPS
['jump'] = function(Jump, Condition)
if type(Jump) == "table" then
if Jump.JumpSpot then
if Condition ~= nil then
if Condition then
CurrentLine = Jump.JumpSpot
end
else
CurrentLine = Jump.JumpSpot
end
end
end
end,
['createjumpspot'] = function(Line)
return {
JumpSpot = (Line or CurrentLine)
}
end
}) do
local Hash = HashToAddress(__)
Addresses[Hash] = {
__ = __,
___ = ___
}
end
return {
init = Interpret,
hookprint = function()
local event = Instance.new('BindableEvent')
Environment["print"] = function()
event:Fire()
end
return event.Event
end,
instructions = Addresses
}