@tilua-types/sunc 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.tilua CHANGED
@@ -1,399 +1,401 @@
1
- -- The script-executor environment, as tilua types.
2
- --
3
- -- Names from sUNC (senS' Unified Naming Convention, https://docs.sunc.io) and
4
- -- the UNC standard it grew out of
5
- -- (https://github.com/unified-naming-convention/NamingStandard). These are the
6
- -- functions an executor injects into a script's environment: they are not part
7
- -- of Luau and not part of Roblox, so nothing here exists in a normal game.
8
- --
9
- -- Depends on `@tilua-types/roblox`, which is loaded along with it: almost every one
10
- -- of these takes or returns an engine type (`Instance`, `BasePart`,
11
- -- `RBXScriptSignal`), and `debug` here *adds* to the `debug` those libraries
12
- -- declare rather than replacing it.
13
- --
14
- -- No executor implements all of this, and several names mean slightly
15
- -- different things between them. Where sUNC and UNC disagree, sUNC's shape is
16
- -- the one written down; where only UNC has a name (`crypt`, the `rconsole`
17
- -- family, mouse input), it is kept, since executors still expose it.
18
-
19
- -- ============================================================
20
- -- Environment
21
- -- ============================================================
22
-
23
- -- The executor's own global table — shared by every script it runs.
24
- declare function getgenv(): { [string]: unknown }
25
-
26
- -- The game's global environment: the `_G` LocalScripts and ModuleScripts see.
27
- declare function getrenv(): { [string]: unknown }
28
-
29
- -- The Luau registry.
30
- declare function getreg(): { [unknown]: unknown }
31
-
32
- -- Everything the garbage collector is holding. Tables are left out unless
33
- -- `includeTables` is true.
34
- declare function getgc(includeTables?: boolean): (((...unknown) => ...unknown) | { [unknown]: unknown })[]
35
-
36
- -- `filtergc` is `getgc` with the search done for you. The filter says what to
37
- -- look for, and `returnOne` asks for the first match instead of every match —
38
- -- which is what makes the return type two different things.
39
- type FunctionFilter = {
40
- Name?: string,
41
- IgnoreExecutor?: boolean,
42
- Hash?: string,
43
- Constants?: unknown[],
44
- Upvalues?: unknown[],
45
- Proto?: number,
46
- }
47
-
48
- type TableFilter = {
49
- Keys?: unknown[],
50
- Values?: unknown[],
51
- KeyValuePairs?: { [unknown]: unknown },
52
- Metatable?: { [unknown]: unknown },
53
- }
54
-
55
- declare function filtergc(kind: "function", filter: FunctionFilter, returnOne: true): ((...unknown) => ...unknown) | nil
56
- declare function filtergc(kind: "function", filter: FunctionFilter, returnOne?: false): ((...unknown) => ...unknown)[]
57
- declare function filtergc(kind: "table", filter: TableFilter, returnOne: true): { [unknown]: unknown } | nil
58
- declare function filtergc(kind: "table", filter: TableFilter, returnOne?: false): { [unknown]: unknown }[]
59
-
60
- -- ============================================================
61
- -- Closures
62
- -- ============================================================
63
-
64
- -- Replace what `func` does with `hook`, and give back a callable copy of the
65
- -- original. The hook keeps the original's type, so a hooked function is still
66
- -- called the way it was.
67
- declare function hookfunction<T>(func: T, hook: (...unknown) => ...unknown): T
68
-
69
- -- Replace one metamethod of `object`'s metatable, returning the original.
70
- declare function hookmetamethod<T>(object: T, method: string, hook: (...unknown) => ...unknown): (...unknown) => ...unknown
71
-
72
- -- Undo every hook on a function, back to the one it started as. Errors if the
73
- -- function was never hooked.
74
- declare function restorefunction(func: (...unknown) => ...unknown): ()
75
-
76
- -- A copy of `func` that is a distinct function with the same behaviour.
77
- declare function clonefunction<T>(func: T): T
78
-
79
- -- Wrap a Luau function so it looks and behaves like a C closure.
80
- declare function newcclosure<T>(func: T): T
81
-
82
- -- Was the caller of the current function the executor, rather than the game?
83
- declare function checkcaller(): boolean
84
-
85
- declare function iscclosure(func: (...unknown) => ...unknown): boolean
86
- declare function islclosure(func: (...unknown) => ...unknown): boolean
87
- declare function isexecutorclosure(func: (...unknown) => ...unknown): boolean
88
-
89
- -- A hash of a function's bytecode: two functions that do the same thing have
90
- -- the same hash, which is how a hook finds its target across updates.
91
- declare function getfunctionhash(func: (...unknown) => ...unknown): string
92
-
93
- -- ============================================================
94
- -- Metatables
95
- -- ============================================================
96
-
97
- declare function getrawmetatable<T>(object: T): { [unknown]: unknown } | nil
98
- declare function setrawmetatable<T>(object: T, metatable: { [unknown]: unknown } | nil): T
99
- declare function isreadonly(object: unknown): boolean
100
- declare function setreadonly(object: unknown, readonly: boolean): ()
101
-
102
- -- Inside a `__namecall` hook: which method was called.
103
- declare function getnamecallmethod(): string
104
-
105
- -- ============================================================
106
- -- Scripts and threads
107
- -- ============================================================
108
-
109
- declare function getcallingscript(): BaseScript | nil
110
- declare function getscripts(): (LocalScript | ModuleScript)[]
111
- declare function getrunningscripts(): (LocalScript | ModuleScript)[]
112
- declare function getloadedmodules(excludeCore?: boolean): ModuleScript[]
113
- declare function getscriptfromthread(thread: thread): BaseScript | nil
114
-
115
- -- A script's globals, the way the script itself sees them.
116
- declare function getsenv(script: LocalScript | ModuleScript): { [string]: unknown }
117
-
118
- declare function getscriptbytecode(script: LocalScript | ModuleScript): string
119
- declare function getscriptclosure(script: LocalScript | ModuleScript): (...unknown) => ...unknown
120
- declare function getscripthash(script: LocalScript | ModuleScript): string
121
-
122
- -- The current thread's permission level, and a way to change it.
123
- declare function getthreadidentity(): number
124
- declare function setthreadidentity(identity: number): ()
125
-
126
- -- ============================================================
127
- -- Instances
128
- -- ============================================================
129
-
130
- -- A reference to the same instance that the game's own code cannot recognise
131
- -- as yours — what keeps a detection hook from seeing the instance you hold.
132
- declare function cloneref<T>(object: T): T
133
-
134
- -- Two references, one instance?
135
- declare function compareinstances(a: Instance, b: Instance): boolean
136
-
137
- -- Every instance in the data model, and those parented to nil.
138
- declare function getinstances(): Instance[]
139
- declare function getnilinstances(): Instance[]
140
-
141
- -- A hidden container for the executor's own UI, which the game cannot see.
142
- declare function gethui(): Folder
143
-
144
- -- Properties the engine hides from scripts: `Instance.Archivable`-style flags,
145
- -- and anything marked not scriptable.
146
- declare function gethiddenproperty(object: Instance, property: string): (unknown, boolean)
147
- declare function sethiddenproperty(object: Instance, property: string, value: unknown): boolean
148
- declare function isscriptable(object: Instance, property: string): boolean
149
- declare function setscriptable(object: Instance, property: string, scriptable: boolean): boolean
150
-
151
- -- The function assigned to a callback property (`OnServerInvoke`, ...).
152
- declare function getcallbackvalue(object: Instance, property: string): ((...unknown) => ...unknown) | nil
153
-
154
- declare function setrbxclipboard(data: string): boolean
155
-
156
- declare cache: {
157
- -- Forget an instance, so the next reference to it is a new one.
158
- invalidate: (object: Instance) => (),
159
- -- Point every future reference to `object` at `newObject` instead.
160
- replace: (object: Instance, newObject: Instance) => (),
161
- iscached: (object: Instance) => boolean,
162
- }
163
-
164
- -- ============================================================
165
- -- Signals and events
166
- -- ============================================================
167
-
168
- -- One connection of a signal. `Function` and `Thread` are nil for connections
169
- -- the engine made itself.
170
- type Connection = {
171
- Function: ((...unknown) => ...unknown) | nil,
172
- Thread: thread | nil,
173
- Enabled: boolean,
174
- ForeignState: boolean,
175
- LuaConnection: boolean,
176
- Fire: (self: Connection, ...unknown) => (),
177
- Defer: (self: Connection, ...unknown) => (),
178
- Disconnect: (self: Connection) => (),
179
- Disable: (self: Connection) => (),
180
- Enable: (self: Connection) => (),
181
- }
182
-
183
- -- Any signal at all. Written as the shape every signal has rather than as
184
- -- `RBXScriptSignal<T...>`, because a signal's type carries the argument pack
185
- -- of its own event and these functions do not care which event it is.
186
- type AnySignal = { Connect: (self: unknown, callback: (...unknown) => ()) => RBXScriptConnection }
187
-
188
- declare function getconnections(signal: AnySignal): Connection[]
189
-
190
- -- Run every Luau connection of a signal now.
191
- declare function firesignal(signal: AnySignal, ...: unknown): ()
192
-
193
- -- Send a signal to the server, for the signals that replicate.
194
- declare function replicatesignal(signal: AnySignal, ...: unknown): ()
195
-
196
- declare function fireclickdetector(object: ClickDetector, distance?: number, event?: string): ()
197
- declare function fireproximityprompt(prompt: ProximityPrompt): ()
198
-
199
- -- `toggle` is true (or 0) to begin the touch and false (or 1) to end it.
200
- declare function firetouchinterest(part: BasePart, other: BasePart, toggle: boolean | number): ()
201
-
202
- -- ============================================================
203
- -- Filesystem
204
- -- ============================================================
205
- --
206
- -- Paths are relative to the executor's own workspace folder.
207
-
208
- declare function readfile(path: string): string
209
- declare function writefile(path: string, data: string): ()
210
- declare function appendfile(path: string, data: string): ()
211
- declare function delfile(path: string): ()
212
- declare function isfile(path: string): boolean
213
- declare function listfiles(path: string): string[]
214
- declare function makefolder(path: string): ()
215
- declare function delfolder(path: string): ()
216
- declare function isfolder(path: string): boolean
217
- declare function dofile(path: string): ()
218
-
219
- -- A `rbxasset://` id for a file on disk, usable wherever the engine takes a
220
- -- content id (images, sounds, meshes).
221
- declare function getcustomasset(path: string, noCache?: boolean): string
222
-
223
- -- ============================================================
224
- -- HTTP and encoding
225
- -- ============================================================
226
-
227
- type HttpRequest = {
228
- Url: string,
229
- Method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | "HEAD" | "OPTIONS",
230
- Body?: string,
231
- Headers?: { [string]: string },
232
- Cookies?: { [string]: string },
233
- }
234
-
235
- type HttpResponse = {
236
- Body: string,
237
- StatusCode: number,
238
- StatusMessage: string,
239
- Success: boolean,
240
- Headers: { [string]: string },
241
- }
242
-
243
- -- Yields until the response arrives.
244
- declare function request(options: HttpRequest): HttpResponse
245
-
246
- declare function base64encode(data: string): string
247
- declare function base64decode(data: string): string
248
- declare function lz4compress(data: string): string
249
- declare function lz4decompress(data: string, size: number): string
250
-
251
- -- UNC put the encoding and cipher helpers in one table; executors still do.
252
- declare crypt: {
253
- base64encode: (data: string) => string,
254
- base64decode: (data: string) => string,
255
- encrypt: (data: string, key: string, iv?: string, mode?: string) => (string, string),
256
- decrypt: (data: string, key: string, iv: string, mode: string) => string,
257
- hash: (data: string, algorithm: string) => string,
258
- generatebytes: (size: number) => string,
259
- generatekey: () => string,
260
- }
261
-
262
- type WebSocketConnection = {
263
- Send: (self: WebSocketConnection, message: string) => (),
264
- Close: (self: WebSocketConnection) => (),
265
- OnMessage: RBXScriptSignal<string>,
266
- OnClose: RBXScriptSignal<()>,
267
- }
268
-
269
- declare WebSocket: {
270
- connect: (url: string) => WebSocketConnection,
271
- }
272
-
273
- -- ============================================================
274
- -- Drawing
275
- -- ============================================================
276
- --
277
- -- Shapes drawn above the game window. `Drawing.new` gives back the type its
278
- -- argument names, so `Drawing.new("Circle").Radius` is a number and
279
- -- `Drawing.new("Line").Radius` is an error.
280
-
281
- type BaseDrawing = {
282
- Visible: boolean,
283
- ZIndex: number,
284
- Transparency: number,
285
- Color: Color3,
286
- Destroy: (self: BaseDrawing) => (),
287
- }
288
-
289
- type DrawingLine = BaseDrawing & { From: Vector2, To: Vector2, Thickness: number }
290
- type DrawingText = BaseDrawing & {
291
- Text: string,
292
- TextBounds: Vector2,
293
- Font: number,
294
- Size: number,
295
- Position: Vector2,
296
- Center: boolean,
297
- Outline: boolean,
298
- OutlineColor: Color3,
299
- }
300
- type DrawingImage = BaseDrawing & { Data: string, Size: Vector2, Position: Vector2, Rounding: number }
301
- type DrawingCircle = BaseDrawing & {
302
- NumSides: number, Radius: number, Position: Vector2, Thickness: number, Filled: boolean,
303
- }
304
- type DrawingSquare = BaseDrawing & {
305
- Size: Vector2, Position: Vector2, Thickness: number, Filled: boolean,
306
- }
307
- type DrawingQuad = BaseDrawing & {
308
- PointA: Vector2, PointB: Vector2, PointC: Vector2, PointD: Vector2, Thickness: number, Filled: boolean,
309
- }
310
- type DrawingTriangle = BaseDrawing & {
311
- PointA: Vector2, PointB: Vector2, PointC: Vector2, Thickness: number, Filled: boolean,
312
- }
313
-
314
- type Drawing = DrawingLine | DrawingText | DrawingImage | DrawingCircle
315
- | DrawingSquare | DrawingQuad | DrawingTriangle
316
-
317
- declare Drawing: {
318
- new: ((kind: "Line") => DrawingLine)
319
- & ((kind: "Text") => DrawingText)
320
- & ((kind: "Image") => DrawingImage)
321
- & ((kind: "Circle") => DrawingCircle)
322
- & ((kind: "Square") => DrawingSquare)
323
- & ((kind: "Quad") => DrawingQuad)
324
- & ((kind: "Triangle") => DrawingTriangle),
325
- Fonts: { UI: number, System: number, Plex: number, Monospace: number },
326
- }
327
-
328
- -- Destroy every drawing at once; references to them stop working.
329
- declare function cleardrawcache(): ()
330
-
331
- declare function getrenderproperty(drawing: Drawing, property: string): unknown
332
- declare function setrenderproperty(drawing: Drawing, property: string, value: unknown): ()
333
- declare function isrenderobj(object: unknown): boolean
334
-
335
- -- ============================================================
336
- -- Console
337
- -- ============================================================
338
-
339
- declare function rconsolecreate(): ()
340
- declare function rconsoledestroy(): ()
341
- declare function rconsoleclear(): ()
342
- declare function rconsoleprint(text: string): ()
343
- declare function rconsolesettitle(title: string): ()
344
- declare function rconsoleinput(): string
345
-
346
- -- ============================================================
347
- -- Input
348
- -- ============================================================
349
- --
350
- -- Real mouse and keyboard events, delivered to the window. They do nothing
351
- -- while the Roblox window is not the active one — `isrbxactive` says whether
352
- -- it is.
353
-
354
- declare function isrbxactive(): boolean
355
- declare function mouse1click(): ()
356
- declare function mouse1press(): ()
357
- declare function mouse1release(): ()
358
- declare function mouse2click(): ()
359
- declare function mouse2press(): ()
360
- declare function mouse2release(): ()
361
- declare function mousemoveabs(x: number, y: number): ()
362
- declare function mousemoverel(x: number, y: number): ()
363
- declare function mousescroll(pixels: number): ()
364
-
365
- -- ============================================================
366
- -- Debug
367
- -- ============================================================
368
- --
369
- -- These add to the `debug` of `@tilua-types/lua` and `@tilua-types/roblox`: the executor
370
- -- reaches into a function's own bytecode. Each takes a function, or a stack
371
- -- level counted from the caller.
372
-
373
- declare debug: {
374
- getconstant: (func: ((...unknown) => ...unknown) | number, index: number) => unknown,
375
- getconstants: (func: ((...unknown) => ...unknown) | number) => unknown[],
376
- setconstant: (func: ((...unknown) => ...unknown) | number, index: number, value: unknown) => (),
377
- getupvalue: (func: ((...unknown) => ...unknown) | number, index: number) => unknown,
378
- getupvalues: (func: ((...unknown) => ...unknown) | number) => unknown[],
379
- setupvalue: (func: ((...unknown) => ...unknown) | number, index: number, value: unknown) => (),
380
- getproto: (func: ((...unknown) => ...unknown) | number, index: number, active?: boolean)
381
- => ((...unknown) => ...unknown) | ((...unknown) => ...unknown)[],
382
- getprotos: (func: ((...unknown) => ...unknown) | number) => ((...unknown) => ...unknown)[],
383
- getstack: (level: number, index?: number) => unknown,
384
- setstack: (level: number, index: number, value: unknown) => (),
385
- }
386
-
387
- -- ============================================================
388
- -- Miscellaneous
389
- -- ============================================================
390
-
391
- -- The executor's name and version.
392
- declare function identifyexecutor(): (string, string)
393
-
394
- declare function setclipboard(text: string): ()
395
- declare function setfpscap(fps: number): ()
396
- declare function messagebox(text: string, caption: string, flags: number): number
397
-
398
- -- Source to run after the next teleport, in the new place.
399
- declare function queue_on_teleport(code: string): ()
1
+ -- The script-executor environment, as tilua types.
2
+ --
3
+ -- Names from sUNC (senS' Unified Naming Convention, https://docs.sunc.io) and
4
+ -- the UNC standard it grew out of
5
+ -- (https://github.com/unified-naming-convention/NamingStandard). These are the
6
+ -- functions an executor injects into a script's environment: they are not part
7
+ -- of Luau and not part of Roblox, so nothing here exists in a normal game.
8
+ --
9
+ -- Depends on `@tilua-types/roblox`, which is loaded along with it: almost every one
10
+ -- of these takes or returns an engine type (`Instance`, `BasePart`,
11
+ -- `RBXScriptSignal`), and `debug` here *adds* to the `debug` those libraries
12
+ -- declare rather than replacing it.
13
+ --
14
+ -- No executor implements all of this, and several names mean slightly
15
+ -- different things between them. Where sUNC and UNC disagree, sUNC's shape is
16
+ -- the one written down; where only UNC has a name (`crypt`, the `rconsole`
17
+ -- family, mouse input), it is kept, since executors still expose it.
18
+
19
+ -- ============================================================
20
+ -- Environment
21
+ -- ============================================================
22
+
23
+ -- The executor's own global table — shared by every script it runs.
24
+ declare function getgenv(): { [string]: unknown }
25
+
26
+ -- The game's global environment: the `_G` LocalScripts and ModuleScripts see.
27
+ declare function getrenv(): { [string]: unknown }
28
+
29
+ -- The Luau registry.
30
+ declare function getreg(): { [unknown]: unknown }
31
+
32
+ -- Everything the garbage collector is holding. Tables are left out unless
33
+ -- `includeTables` is true.
34
+ declare function getgc(includeTables?: boolean): (((...args: unknown[]) => unknown) | { [unknown]: unknown })[]
35
+
36
+ -- `filtergc` is `getgc` with the search done for you. The filter says what to
37
+ -- look for, and `returnOne` asks for the first match instead of every match —
38
+ -- which is what makes the return type two different things.
39
+ type FunctionFilter = {
40
+ Name?: string,
41
+ IgnoreExecutor?: boolean,
42
+ Hash?: string,
43
+ Constants?: unknown[],
44
+ Upvalues?: unknown[],
45
+ Proto?: number,
46
+ }
47
+
48
+ type TableFilter = {
49
+ Keys?: unknown[],
50
+ Values?: unknown[],
51
+ KeyValuePairs?: { [unknown]: unknown },
52
+ Metatable?: { [unknown]: unknown },
53
+ }
54
+
55
+ declare function filtergc(kind: "function", filter: FunctionFilter, returnOne: true): ((...args: unknown[]) => unknown) | nil
56
+ declare function filtergc(kind: "function", filter: FunctionFilter, returnOne?: false): ((...args: unknown[]) => unknown)[]
57
+ declare function filtergc(kind: "table", filter: TableFilter, returnOne: true): { [unknown]: unknown } | nil
58
+ declare function filtergc(kind: "table", filter: TableFilter, returnOne?: false): { [unknown]: unknown }[]
59
+
60
+ -- ============================================================
61
+ -- Closures
62
+ -- ============================================================
63
+
64
+ -- Replace what `func` does with `hook`, and give back a callable copy of the
65
+ -- original. The hook keeps the original's type, so a hooked function is still
66
+ -- called the way it was.
67
+ declare function hookfunction<T>(func: T, hook: (...args: unknown[]) => unknown): T
68
+
69
+ -- Replace one metamethod of `object`'s metatable, returning the original.
70
+ declare function hookmetamethod<T>(object: T, method: string, hook: (...args: unknown[]) => unknown): (...args: unknown[]) => unknown
71
+
72
+ -- Undo every hook on a function, back to the one it started as. Errors if the
73
+ -- function was never hooked.
74
+ declare function restorefunction(func: (...args: unknown[]) => unknown): nil
75
+
76
+ -- A copy of `func` that is a distinct function with the same behaviour.
77
+ declare function clonefunction<T>(func: T): T
78
+
79
+ -- Wrap a Luau function so it looks and behaves like a C closure.
80
+ declare function newcclosure<T>(func: T): T
81
+
82
+ -- Was the caller of the current function the executor, rather than the game?
83
+ declare function checkcaller(): boolean
84
+
85
+ declare function iscclosure(func: (...args: unknown[]) => unknown): boolean
86
+ declare function islclosure(func: (...args: unknown[]) => unknown): boolean
87
+ declare function isexecutorclosure(func: (...args: unknown[]) => unknown): boolean
88
+
89
+ -- A hash of a function's bytecode: two functions that do the same thing have
90
+ -- the same hash, which is how a hook finds its target across updates.
91
+ declare function getfunctionhash(func: (...args: unknown[]) => unknown): string
92
+
93
+ -- ============================================================
94
+ -- Metatables
95
+ -- ============================================================
96
+
97
+ declare function getrawmetatable<T>(object: T): { [unknown]: unknown } | nil
98
+ declare function setrawmetatable<T>(object: T, metatable: { [unknown]: unknown } | nil): T
99
+ declare function isreadonly(object: unknown): boolean
100
+ declare function setreadonly(object: unknown, readonly: boolean): nil
101
+
102
+ -- Inside a `__namecall` hook: which method was called.
103
+ declare function getnamecallmethod(): string
104
+
105
+ -- ============================================================
106
+ -- Scripts and threads
107
+ -- ============================================================
108
+
109
+ declare function getcallingscript(): BaseScript | nil
110
+ declare function getscripts(): (LocalScript | ModuleScript)[]
111
+ declare function getrunningscripts(): (LocalScript | ModuleScript)[]
112
+ declare function getloadedmodules(excludeCore?: boolean): ModuleScript[]
113
+ declare function getscriptfromthread(thread: thread): BaseScript | nil
114
+
115
+ -- A script's globals, the way the script itself sees them.
116
+ declare function getsenv(script: LocalScript | ModuleScript): { [string]: unknown }
117
+
118
+ declare function getscriptbytecode(script: LocalScript | ModuleScript): string
119
+ declare function getscriptclosure(script: LocalScript | ModuleScript): (...args: unknown[]) => unknown
120
+ declare function getscripthash(script: LocalScript | ModuleScript): string
121
+
122
+ -- The current thread's permission level, and a way to change it.
123
+ declare function getthreadidentity(): number
124
+ declare function setthreadidentity(identity: number): nil
125
+
126
+ -- ============================================================
127
+ -- Instances
128
+ -- ============================================================
129
+
130
+ -- A reference to the same instance that the game's own code cannot recognise
131
+ -- as yours — what keeps a detection hook from seeing the instance you hold.
132
+ declare function cloneref<T>(object: T): T
133
+
134
+ -- Two references, one instance?
135
+ declare function compareinstances(a: Instance, b: Instance): boolean
136
+
137
+ -- Every instance in the data model, and those parented to nil.
138
+ declare function getinstances(): Instance[]
139
+ declare function getnilinstances(): Instance[]
140
+
141
+ -- A hidden container for the executor's own UI, which the game cannot see.
142
+ declare function gethui(): Folder
143
+
144
+ -- Properties the engine hides from scripts: `Instance.Archivable`-style flags,
145
+ -- and anything marked not scriptable.
146
+ declare function gethiddenproperty(object: Instance, property: string): [unknown, boolean]
147
+ declare function sethiddenproperty(object: Instance, property: string, value: unknown): boolean
148
+ declare function isscriptable(object: Instance, property: string): boolean
149
+ declare function setscriptable(object: Instance, property: string, scriptable: boolean): boolean
150
+
151
+ -- The function assigned to a callback property (`OnServerInvoke`, ...).
152
+ declare function getcallbackvalue(object: Instance, property: string): ((...args: unknown[]) => unknown) | nil
153
+
154
+ declare function setrbxclipboard(data: string): boolean
155
+
156
+ declare cache: {
157
+ -- Forget an instance, so the next reference to it is a new one.
158
+ invalidate: (object: Instance) => nil,
159
+ -- Point every future reference to `object` at `newObject` instead.
160
+ replace: (object: Instance, newObject: Instance) => nil,
161
+ iscached: (object: Instance) => boolean,
162
+ }
163
+
164
+ -- ============================================================
165
+ -- Signals and events
166
+ -- ============================================================
167
+
168
+ -- One connection of a signal. `Function` and `Thread` are nil for connections
169
+ -- the engine made itself.
170
+ type Connection = {
171
+ Function: ((...args: unknown[]) => unknown) | nil,
172
+ Thread: thread | nil,
173
+ Enabled: boolean,
174
+ ForeignState: boolean,
175
+ LuaConnection: boolean,
176
+ Fire: (self: Connection, ...args: unknown[]) => nil,
177
+ Defer: (self: Connection, ...args: unknown[]) => nil,
178
+ Disconnect: (self: Connection) => nil,
179
+ Disable: (self: Connection) => nil,
180
+ Enable: (self: Connection) => nil,
181
+ }
182
+
183
+ -- Any signal at all. Written as the shape every signal has rather than as
184
+ -- `RBXScriptSignal<T>`, because a signal's type carries the arguments of its
185
+ -- own event, as a tuple, and these functions do not care which event it is.
186
+ type AnySignal = { Connect: (self: unknown, callback: (...args: unknown[]) => nil) => RBXScriptConnection }
187
+
188
+ declare function getconnections(signal: AnySignal): Connection[]
189
+
190
+ -- Run every Luau connection of a signal now.
191
+ declare function firesignal(signal: AnySignal, ...args: unknown[]): nil
192
+
193
+ -- Send a signal to the server, for the signals that replicate.
194
+ declare function replicatesignal(signal: AnySignal, ...args: unknown[]): nil
195
+
196
+ declare function fireclickdetector(object: ClickDetector, distance?: number, event?: string): nil
197
+ declare function fireproximityprompt(prompt: ProximityPrompt): nil
198
+
199
+ -- `toggle` is true (or 0) to begin the touch and false (or 1) to end it.
200
+ declare function firetouchinterest(part: BasePart, other: BasePart, toggle: boolean | number): nil
201
+
202
+ -- ============================================================
203
+ -- Filesystem
204
+ -- ============================================================
205
+ --
206
+ -- Paths are relative to the executor's own workspace folder.
207
+
208
+ declare function readfile(path: string): string
209
+ declare function writefile(path: string, data: string): nil
210
+ declare function appendfile(path: string, data: string): nil
211
+ declare function delfile(path: string): nil
212
+ declare function isfile(path: string): boolean
213
+ declare function listfiles(path: string): string[]
214
+ declare function makefolder(path: string): nil
215
+ declare function delfolder(path: string): nil
216
+ declare function isfolder(path: string): boolean
217
+ declare function dofile(path: string): nil
218
+ -- Compiles a file without running it, as `loadstring` does a string.
219
+ declare function loadfile(path: string, chunkname?: string): [((...args: unknown[]) => unknown) | nil, string | nil]
220
+
221
+ -- A `rbxasset://` id for a file on disk, usable wherever the engine takes a
222
+ -- content id (images, sounds, meshes).
223
+ declare function getcustomasset(path: string, noCache?: boolean): string
224
+
225
+ -- ============================================================
226
+ -- HTTP and encoding
227
+ -- ============================================================
228
+
229
+ type HttpRequest = {
230
+ Url: string,
231
+ Method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE" | "HEAD" | "OPTIONS",
232
+ Body?: string,
233
+ Headers?: { [string]: string },
234
+ Cookies?: { [string]: string },
235
+ }
236
+
237
+ type HttpResponse = {
238
+ Body: string,
239
+ StatusCode: number,
240
+ StatusMessage: string,
241
+ Success: boolean,
242
+ Headers: { [string]: string },
243
+ }
244
+
245
+ -- Yields until the response arrives.
246
+ declare function request(options: HttpRequest): HttpResponse
247
+
248
+ declare function base64encode(data: string): string
249
+ declare function base64decode(data: string): string
250
+ declare function lz4compress(data: string): string
251
+ declare function lz4decompress(data: string, size: number): string
252
+
253
+ -- UNC put the encoding and cipher helpers in one table; executors still do.
254
+ declare crypt: {
255
+ base64encode: (data: string) => string,
256
+ base64decode: (data: string) => string,
257
+ encrypt: (data: string, key: string, iv?: string, mode?: string) => [string, string],
258
+ decrypt: (data: string, key: string, iv: string, mode: string) => string,
259
+ hash: (data: string, algorithm: string) => string,
260
+ generatebytes: (size: number) => string,
261
+ generatekey: () => string,
262
+ }
263
+
264
+ type WebSocketConnection = {
265
+ Send: (self: WebSocketConnection, message: string) => nil,
266
+ Close: (self: WebSocketConnection) => nil,
267
+ OnMessage: RBXScriptSignal<[string]>,
268
+ OnClose: RBXScriptSignal<[]>,
269
+ }
270
+
271
+ declare WebSocket: {
272
+ connect: (url: string) => WebSocketConnection,
273
+ }
274
+
275
+ -- ============================================================
276
+ -- Drawing
277
+ -- ============================================================
278
+ --
279
+ -- Shapes drawn above the game window. `Drawing.new` gives back the type its
280
+ -- argument names, so `Drawing.new("Circle").Radius` is a number and
281
+ -- `Drawing.new("Line").Radius` is an error.
282
+
283
+ type BaseDrawing = {
284
+ Visible: boolean,
285
+ ZIndex: number,
286
+ Transparency: number,
287
+ Color: Color3,
288
+ Destroy: (self: BaseDrawing) => nil,
289
+ }
290
+
291
+ type DrawingLine = BaseDrawing & { From: Vector2, To: Vector2, Thickness: number }
292
+ type DrawingText = BaseDrawing & {
293
+ Text: string,
294
+ TextBounds: Vector2,
295
+ Font: number,
296
+ Size: number,
297
+ Position: Vector2,
298
+ Center: boolean,
299
+ Outline: boolean,
300
+ OutlineColor: Color3,
301
+ }
302
+ type DrawingImage = BaseDrawing & { Data: string, Size: Vector2, Position: Vector2, Rounding: number }
303
+ type DrawingCircle = BaseDrawing & {
304
+ NumSides: number, Radius: number, Position: Vector2, Thickness: number, Filled: boolean,
305
+ }
306
+ type DrawingSquare = BaseDrawing & {
307
+ Size: Vector2, Position: Vector2, Thickness: number, Filled: boolean,
308
+ }
309
+ type DrawingQuad = BaseDrawing & {
310
+ PointA: Vector2, PointB: Vector2, PointC: Vector2, PointD: Vector2, Thickness: number, Filled: boolean,
311
+ }
312
+ type DrawingTriangle = BaseDrawing & {
313
+ PointA: Vector2, PointB: Vector2, PointC: Vector2, Thickness: number, Filled: boolean,
314
+ }
315
+
316
+ type Drawing = DrawingLine | DrawingText | DrawingImage | DrawingCircle
317
+ | DrawingSquare | DrawingQuad | DrawingTriangle
318
+
319
+ declare Drawing: {
320
+ new: ((kind: "Line") => DrawingLine)
321
+ & ((kind: "Text") => DrawingText)
322
+ & ((kind: "Image") => DrawingImage)
323
+ & ((kind: "Circle") => DrawingCircle)
324
+ & ((kind: "Square") => DrawingSquare)
325
+ & ((kind: "Quad") => DrawingQuad)
326
+ & ((kind: "Triangle") => DrawingTriangle),
327
+ Fonts: { UI: number, System: number, Plex: number, Monospace: number },
328
+ }
329
+
330
+ -- Destroy every drawing at once; references to them stop working.
331
+ declare function cleardrawcache(): nil
332
+
333
+ declare function getrenderproperty(drawing: Drawing, property: string): unknown
334
+ declare function setrenderproperty(drawing: Drawing, property: string, value: unknown): nil
335
+ declare function isrenderobj(object: unknown): boolean
336
+
337
+ -- ============================================================
338
+ -- Console
339
+ -- ============================================================
340
+
341
+ declare function rconsolecreate(): nil
342
+ declare function rconsoledestroy(): nil
343
+ declare function rconsoleclear(): nil
344
+ declare function rconsoleprint(text: string): nil
345
+ declare function rconsolesettitle(title: string): nil
346
+ declare function rconsoleinput(): string
347
+
348
+ -- ============================================================
349
+ -- Input
350
+ -- ============================================================
351
+ --
352
+ -- Real mouse and keyboard events, delivered to the window. They do nothing
353
+ -- while the Roblox window is not the active one — `isrbxactive` says whether
354
+ -- it is.
355
+
356
+ declare function isrbxactive(): boolean
357
+ declare function mouse1click(): nil
358
+ declare function mouse1press(): nil
359
+ declare function mouse1release(): nil
360
+ declare function mouse2click(): nil
361
+ declare function mouse2press(): nil
362
+ declare function mouse2release(): nil
363
+ declare function mousemoveabs(x: number, y: number): nil
364
+ declare function mousemoverel(x: number, y: number): nil
365
+ declare function mousescroll(pixels: number): nil
366
+
367
+ -- ============================================================
368
+ -- Debug
369
+ -- ============================================================
370
+ --
371
+ -- These add to the `debug` of `@tilua-types/lua` and `@tilua-types/roblox`: the executor
372
+ -- reaches into a function's own bytecode. Each takes a function, or a stack
373
+ -- level counted from the caller.
374
+
375
+ declare debug: {
376
+ getconstant: (func: ((...args: unknown[]) => unknown) | number, index: number) => unknown,
377
+ getconstants: (func: ((...args: unknown[]) => unknown) | number) => unknown[],
378
+ setconstant: (func: ((...args: unknown[]) => unknown) | number, index: number, value: unknown) => nil,
379
+ getupvalue: (func: ((...args: unknown[]) => unknown) | number, index: number) => unknown,
380
+ getupvalues: (func: ((...args: unknown[]) => unknown) | number) => unknown[],
381
+ setupvalue: (func: ((...args: unknown[]) => unknown) | number, index: number, value: unknown) => nil,
382
+ getproto: (func: ((...args: unknown[]) => unknown) | number, index: number, active?: boolean)
383
+ => ((...args: unknown[]) => unknown) | ((...args: unknown[]) => unknown)[],
384
+ getprotos: (func: ((...args: unknown[]) => unknown) | number) => ((...args: unknown[]) => unknown)[],
385
+ getstack: (level: number, index?: number) => unknown,
386
+ setstack: (level: number, index: number, value: unknown) => nil,
387
+ }
388
+
389
+ -- ============================================================
390
+ -- Miscellaneous
391
+ -- ============================================================
392
+
393
+ -- The executor's name and version.
394
+ declare function identifyexecutor(): [string, string]
395
+
396
+ declare function setclipboard(text: string): nil
397
+ declare function setfpscap(fps: number): nil
398
+ declare function messagebox(text: string, caption: string, flags: number): number
399
+
400
+ -- Source to run after the next teleport, in the new place.
401
+ declare function queue_on_teleport(code: string): nil
package/lowering.mjs ADDED
@@ -0,0 +1,36 @@
1
+ // @ts-check
2
+ /**
3
+ * What tilua lowers for an executor: the functions whose Luau answer is
4
+ * several values. tilua has one value where Luau has several — an array — so
5
+ * each of these is called through runtime/sunc.luau, which gathers them. A
6
+ * global read as a value gets the same function, so the two never disagree.
7
+ */
8
+ import { readFileSync } from "node:fs"
9
+ import { dirname, join } from "node:path"
10
+ import { fileURLToPath } from "node:url"
11
+
12
+ /** @typedef {import("@tilua/parser").LoweringPlugin} LoweringPlugin */
13
+
14
+ const here = dirname(fileURLToPath(import.meta.url))
15
+ const sunc = readFileSync(join(here, "runtime", "sunc.luau"), "utf8")
16
+
17
+ /** The globals the runtime answers for. */
18
+ const GATHERED = new Set(["gethiddenproperty", "loadfile", "identifyexecutor", "crypt.encrypt"])
19
+
20
+ /** @type {(runtime: string, name: string) => string} */
21
+ const member = (runtime, name) => `${runtime}.${name.replace(".", "_")}`
22
+
23
+ /** @type {LoweringPlugin} */
24
+ const plugin = {
25
+ runtime: { sunc },
26
+
27
+ globalCall({ name, use }) {
28
+ return GATHERED.has(name) ? { callee: member(use("sunc"), name) } : undefined
29
+ },
30
+
31
+ globalValue({ name, use }) {
32
+ return GATHERED.has(name) ? member(use("sunc"), name) : undefined
33
+ },
34
+ }
35
+
36
+ export default plugin
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@tilua-types/sunc",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "The script-executor environment as tilua types: sUNC and UNC names (getgenv, writefile, hookfunction, Drawing, ...)",
5
5
  "license": "ISC",
6
6
  "files": [
7
7
  "index.d.tilua",
8
+ "lowering.mjs",
9
+ "runtime",
8
10
  "README.md"
9
11
  ],
10
12
  "tilua": {
11
- "types": "index.d.tilua"
13
+ "types": "index.d.tilua",
14
+ "lowering": "lowering.mjs"
12
15
  },
13
16
  "dependencies": {
14
- "@tilua-types/roblox": "^2.1.0"
17
+ "@tilua-types/roblox": "^3.0.0"
15
18
  },
16
19
  "keywords": [
17
20
  "tilua",
@@ -0,0 +1,22 @@
1
+ local __NAME__ = {}
2
+
3
+ -- The executor functions whose Luau answer is several values, as tilua has
4
+ -- them: one array. The compiler calls these instead of the globals they stand
5
+ -- for, and reading one of those globals as a value gives the function here.
6
+
7
+ __NAME__.gethiddenproperty = function(object, property)
8
+ return { gethiddenproperty(object, property) }
9
+ end
10
+
11
+ __NAME__.loadfile = function(path, chunkname)
12
+ local f, message = loadfile(path, chunkname)
13
+ return { f, message }
14
+ end
15
+
16
+ __NAME__.identifyexecutor = function()
17
+ return { identifyexecutor() }
18
+ end
19
+
20
+ __NAME__.crypt_encrypt = function(...)
21
+ return { crypt.encrypt(...) }
22
+ end