Skip to content

Lua API Overview

Euphoriahh edited this page Oct 31, 2023 · 2 revisions

Intro

  • Most of this is found within other popular software of the same kind as ours. Most of the functions existed in the previous iteration of Synapse.
  • Some functions may be defined under several names (for example, checkcaller is also defined as is_protosmasher_caller) for compatibility with scripts written for other software. Those other definitions are not included in this document for the sake of organization.

Environment Helper Functions

<table> getgenv(<void>)

Returns the environment that will be applied to each script ran by Synapse.

<table> getrenv(<void>)  

Returns the global Roblox environment for the LocalScript state.

<table> getreg(<void>)  

Returns the Lua registry.

<table> getgc(<void>)  

Returns a copy of the Lua GC list.

<table> getinstances(<void>)  

Returns a list of all instances within the game.

<table> getnilinstances(<void>)  

Returns a list of all instances parented to nil within the game.

<table> getscripts(<void>)  

Returns a list of all scripts within the game.

<table> getloadedmodules(<void>)  

Returns all ModuleScripts loaded in the game.

<table> getconnections(<Signal> obj)  

Gets a list of connections to the specified signal. You can then use :Disable and :Enable on the connections to disable/enable them.

Keyboard/Mouse Functions

<bool> isrbxactive(<void>)  

Returns if the Roblox window is in focus. This must return true for any other mouse/keyboard function to work.

<void> keypress(<int> keycode)  

Simulates a key press for the specified keycode. For more information: https://docs.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes

<void> keyrelease(<int> key)  

Releases key on the keyboard. You can access the int key values on MSDN.

<void> mouse1click(<void>)  

Simulates a full left mouse button press.

<void> mouse1press(<void>)  

Simulates a left mouse button press without releasing it.

<void> mouse1release(<void>)  

Simulates a left mouse button release.

<void> mouse2click(<void>)  

Simulates a full right mouse button press.

<void> mouse2press(<void>)  

Clicks down on the right mouse button.

<void> mouse2release(<void>)  

Simulates a right mouse button release.

<void> mousescroll(<signed int> px)  

Scrolls the mouse wheel virtually by px pixels.

<void> mousemoverel(<int> x, <int> y)  

Moves the mouse cursor relatively to the current mouse position by coordinates x and y.

Hooking Functions

<function> hookfunction(<function> old, <function> hook)  

Hooks function 'old', replacing it with the function 'hook'. The old function is returned, you must use it to call the function further.

<function> newcclosure(<function> f)  

Pushes a new CClosure that invokes function f upon call. Used for metatable hooks.

File Functions

<string> readfile(<string> path)  

Reads the contents of the file located at path and returns it. If the file does not exist, it errors.

<void> writefile(<string> filepath, <string> contents)  

Writes contents to the supplied filepath.

<void> appendfile(<string> path, <string> content)  

Appends content to the file contents at path. If the file does not exist, it errors.

<function> loadfile(<string> path)  

Loads in the contents of a file as a chunk and returns it if compilation is successful. Otherwise, if an error has occured during compilation, nil followed by the error message will be returned.

Script Environment Functions

<table> getsenv(<LocalScript, ModuleScript> Script)  

Returns the environment of Script. Returns nil if the script is not running.

<LocalScript, ModuleScript, nil> getcallingscript(<void>)  

Gets the script that is calling this function.

Table Modification Functions

<table, nil> getrawmetatable(<T> value)  

Retrieve the metatable of value irregardless of value's metatable's __metatable field. Returns nil if it doesn't exist.

<void> setreadonly(<table> table, <bool> ro)  

Sets table's read-only value to ro

<bool> isreadonly(<table> table)  

Returns table's read-only condition.

Reflection Functions

<function> loadstring(<string> chunk, [<string> chunkname])  

Loads chunk as a Lua function and returns it if compilation is succesful. Otherwise, if an error has occured during compilation, nil followed by the error message will be returned.

<bool> checkcaller(<void>)  

Returns true if the current thread was made by Synapse. Useful for metatable hooks.

<bool> islclosure(<function> f)  

Returns true if f is an LClosure

<string> dumpstring(<string> Script)  

Returns the Roblox formatted bytecode for source string Script.

<string> decompile(<LocalScript, ModuleScript, function> Script, bool Bytecode = false)  

Decompiles Script and returns the decompiled script. If the decompilation fails, then the return value will be an error message.

Misc Functions

<void> setclipboard(<string> value)  

Sets value to the clipboard.

<void> setnonreplicatedproperty(<Instance> obj, <string> prop, <T> value)  

Sets the prop property of obj, not replicating to the server. Useful for anticheat bypasses.

<table> getspecialinfo(<Instance> obj)  

Gets a list of special properties for MeshParts, UnionOperations, and Terrain instances.

<void> saveinstance(<table> t = { noscripts = false, mode = "optimized" })  

Saves the Roblox game into your workspace folder. You can use table t to customize options for this.

debug Library

<table> debug.getlocals(<int> lvl)  

Returns a table containing the upvalues at level lvl.

<T> debug.getlocal(<int> lvl, <string> localname)  

Returns the local with name localname in level lvl.

<void> debug.setlocal(<int> lvl, <string> localname, <T> value)  

Set local localname to value value at level lvl.

<table> debug.getconstants(<function, int> fi)  

Retrieve the constants in function fi or at level fi.

<T> debug.getconstant(<function, int> fi, <int> idx)  

Returns the constant at index idx in function fi or level fi.

<void> debug.setconstant(<function, int> fi, <string> consname, <int, bool, nil, string> value)  

Set constant consname to tuple value at level or function fi.

<table> debug.getupvalues(<function, int> fi)  

Retrieve the upvalues in function fi or at level fi.

<T> debug.getupvalue(<function, int> fi, <string> upval)  

Returns the upvalue with name upval in function or level fi.

<void> debug.setupvalue(<function, int> fi, <string> upvname, <T> value)  

Set upvalue upvname to value value at level or function fi.

<table> debug.setmetatable(<T> o, <table> mt)  

Set the metatable of o to mt.

<table> debug.getregistry(<void>)  

Returns the Lua registry.

debug.getinfo(<function, int> fi, <string> w = "flnSu")  

Returns a table of info pertaining to the Lua function fi.

bit Library

<int> bit.bdiv(<uint> dividend, <uint> divisor)  

Divides dividend by divisor, remainder is not returned.

<int> bit.badd(<uint> a, <uint> b)  

Adds a with b, allows overflows (unlike normal Lua).

<int> bit.bsub(<uint> a, <uint> b)  

Subtracts a with b, allows overflows (unlike normal Lua).

<int> bit.rshift(<uint> val, <uint> by)  

Does a right shift on val using by.

<int> bit.band(<uint> val, <uint> by)  

Does a logical AND (&) on val using by.

<int> bit.bor(<uint> val, <uint> by)  

Does a logical OR (|) on val using by.

<int> bit.bxor(<uint> val, <uint> by)  

Does a logical XOR (⊕) on val using by.

<int> bit.bnot(<uint> val)  

Does a logical NOT on val.

<int> bit.bmul(<uint> val, <uint> by)  

Multiplies val using by, allows overflows (unlike normal Lua)

<int> bit.bswap(<uint> val)  

Does a bitwise swap on val.

<int> bit.tobit(<uint> val)  

Converts val into proper form for bitwise operations.

<int> bit.ror(<uint> val, <uint> by)  

Rotates right val using by.

<int> bit.lshift(<uint> val, <uint> by)  

Does a left shift on val using by.

<string> bit.tohex(<uint> val)  

Converts val to a hex string.

syn Library

<string> syn.crypt.encrypt(<string> data, <string> key)  

Encrypt's data with key.

<string> syn.crypt.decrypt(<string> data, <string> key)  

Decrypt's data with key.

<string> syn.crypt.base64.encode(<string> data)  

Encodes data with base64.

<string> syn.crypt.base64.decode(<string> data)  

Decodes data with base64.

<string> syn.crypt.hash(<string> data)  

Hashes data.

<void> syn.cache_replace(<Instance> obj, <Instance> t_obj)  

Replace obj in the instance cache with t_obj.

<void> syn.cache_invalidate(<Instance> obj)  

Invalidate obj's cache entry, forcing a recache upon the next lookup.

<void> syn.set_thread_identity(<int> n)  

Sets the current thread identity after a Task Scheduler cycle is performed. (Note: call wait() after invoking this function for the expected results)

<int> syn.get_thread_identity(<void>)  

Returns the current thread identity.

<bool> syn.is_cached(<Instance> obj)  

Returns true if obj is currently cached within the registry.

<void> syn.write_clipboard(<string> content)  

Writes content to the current Windows clipboard.

<WebSocket> syn.open_web_socket(<string> name)  

Open's the Synapse WebSocket with channel name. This function will not exist if the user did not enable WebSocket support in theme.json.

Notes

  • _G and shared are replaced by Synapse with its own copy for security reasons. Use getrenv()._G/getrenv().shared if you want to access the original.
  • Always use newcclosure for metatable hooks - this is required to prevent detection methods and internal checks.