Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- NotAshley's loadstring fix.
- Credit to einsteinK, as well as the creators of LuLu for the parser. This parser now supports local variables.
- Credit to Reinitialized and NecroBumpist for the VM and RBX.lua sandboxing scripts.
- ]]
- local luaZ = {}
- ------------------------------------------------------------------------
- -- * reader() should return a string, or nil if nothing else to parse.
- -- Additional data can be set only during stream initialization
- -- * Readers are handled in lauxlib.c, see luaL_load(file|buffer|string)
- -- * LUAL_BUFFERSIZE=BUFSIZ=512 in make_getF() (located in luaconf.h)
- -- * Original Reader typedef:
- -- const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz);
- -- * This Lua chunk reader implementation:
- -- returns string or nil, no arguments to function
- ------------------------------------------------------------------------
- ------------------------------------------------------------------------
- -- create a chunk reader from a source string
- ------------------------------------------------------------------------
- function luaZ:make_getS(buff)
- local b = buff
- return function() -- chunk reader anonymous function here
- if not b then return nil end
- local data = b
- b = nil
- return data
- end
- end
- ------------------------------------------------------------------------
- -- create a chunk reader from a source file
- ------------------------------------------------------------------------
- function luaZ:make_getF(filename)
- local LUAL_BUFFERSIZE = 512
- local h = io.open(filename, "r")
- if not h then return nil end
- return function() -- chunk reader anonymous function here
- if not h or io.type(h) == "closed file" then return nil end
- local buff = h:read(LUAL_BUFFERSIZE)
- if not buff then h:close(); h = nil end
- return buff
- end
- end
- ------------------------------------------------------------------------
- -- creates a zio input stream
- -- returns the ZIO structure, z
- ------------------------------------------------------------------------
- function luaZ:init(reader, data)
- if not reader then return end
- local z = {}
- z.reader = reader
- z.data = data or ""
- z.name = name
- -- set up additional data for reading
- if not data or data == "" then z.n = 0 else z.n = #data end
- z.p = 0
- return z
- end
- ------------------------------------------------------------------------
- -- fill up input buffer
- ------------------------------------------------------------------------
- function luaZ:fill(z)
- local buff = z.reader()
- z.data = buff
- if not buff or buff == "" then return "EOZ" end
- z.n, z.p = #buff - 1, 1
- return string.sub(buff, 1, 1)
- end
- ------------------------------------------------------------------------
- -- get next character from the input stream
- -- * local n, p are used to optimize code generation
- ------------------------------------------------------------------------
- function luaZ:zgetc(z)
- local n, p = z.n, z.p + 1
- if n > 0 then
- z.n, z.p = n - 1, p
- return string.sub(z.data, p, p)
- else
- return self:fill(z)
- end
- end
- local luaZfunc = luaZ
- --[[--------------------------------------------------------------------
- llex.lua
- Lua lexical analyzer in Lua
- This file is part of Yueliang.
- Copyright (c) 2005-2006 Kein-Hong Man <khman@users.sf.net>
- The COPYRIGHT file describes the conditions
- under which this software may be distributed.
- See the ChangeLog for more information.
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- Notes:
- -- * intended to 'imitate' llex.c code; performance is not a concern
- -- * tokens are strings; code structure largely retained
- -- * deleted stuff (compared to llex.c) are noted, comments retained
- -- * nextc() returns the currently read character to simplify coding
- -- here; next() in llex.c does not return anything
- -- * compatibility code is marked with "--Unknown command """, use #help to get a list
- --
- -- Added:
- -- * luaX:chunkid (function luaO_chunkid from lobject.c)
- -- * luaX:str2d (function luaO_str2d from lobject.c)
- -- * luaX.LUA_QS used in luaX:lexerror (from luaconf.h)
- -- * luaX.LUA_COMPAT_LSTR in luaX:read_long_string (from luaconf.h)
- -- * luaX.MAX_INT used in luaX:inclinenumber (from llimits.h)
- --
- -- To use the lexer:
- -- (1) luaX:init() to initialize the lexer
- -- (2) luaX:setinput() to set the input stream to lex
- -- (3) call luaX:next() or luaX:luaX:lookahead() to get tokens,
- -- until "TK_EOS": luaX:next()
- -- * since EOZ is returned as a string, be careful when regexp testing
- --
- -- Not implemented:
- -- * luaX_newstring: not required by this Lua implementation
- -- * buffer MAX_SIZET size limit (from llimits.h) test not implemented
- -- in the interest of performance
- -- * locale-aware number handling is largely redundant as Lua's
- -- tonumber() function is already capable of this
- --
- -- Changed in 5.1.x:
- -- * TK_NAME token order moved down
- -- * string representation for TK_NAME, TK_NUMBER, TK_STRING changed
- -- * token struct renamed to lower case (LS -> ls)
- -- * LexState struct: removed nestlevel, added decpoint
- -- * error message functions have been greatly simplified
- -- * token2string renamed to luaX_tokens, exposed in llex.h
- -- * lexer now handles all kinds of newlines, including CRLF
- -- * shbang first line handling removed from luaX:setinput;
- -- it is now done in lauxlib.c (luaL_loadfile)
- -- * next(ls) macro renamed to nextc(ls) due to new luaX_next function
- -- * EXTRABUFF and MAXNOCHECK removed due to lexer changes
- -- * checkbuffer(ls, len) macro deleted
- -- * luaX:read_numeral now has 3 support functions: luaX:trydecpoint,
- -- luaX:buffreplace and (luaO_str2d from lobject.c) luaX:str2d
- -- * luaX:read_numeral is now more promiscuous in slurping characters;
- -- hexadecimal numbers was added, locale-aware decimal points too
- -- * luaX:skip_sep is new; used by luaX:read_long_string
- -- * luaX:read_long_string handles new-style long blocks, with some
- -- optional compatibility code
- -- * luaX:llex: parts changed to support new-style long blocks
- -- * luaX:llex: readname functionality has been folded in
- -- * luaX:llex: removed test for control characters
- --
- --------------------------------------------------------------------]]
- local luaZ = luaZfunc
- local luaX = {}
- -- FIRST_RESERVED is not required as tokens are manipulated as strings
- -- TOKEN_LEN deleted; maximum length of a reserved word not needed
- ------------------------------------------------------------------------
- -- "ORDER RESERVED" deleted; enumeration in one place: luaX.RESERVED
- ------------------------------------------------------------------------
- -- terminal symbols denoted by reserved words: TK_AND to TK_WHILE
- -- other terminal symbols: TK_NAME to TK_EOS
- luaX.RESERVED = [[
- TK_AND and
- TK_BREAK break
- TK_DO do
- TK_ELSE else
- TK_ELSEIF elseif
- TK_END end
- TK_FALSE false
- TK_FOR for
- TK_FUNCTION function
- TK_IF if
- TK_IN in
- TK_LOCAL local
- TK_NIL nil
- TK_NOT not
- TK_OR or
- TK_REPEAT repeat
- TK_RETURN return
- TK_THEN then
- TK_TRUE true
- TK_UNTIL until
- TK_WHILE while
- TK_CONCAT ..
- TK_DOTS ...
- TK_EQ ==
- TK_GE >=
- TK_LE <=
- TK_NE ~=
- TK_NAME <name>
- TK_NUMBER <number>
- TK_STRING <string>
- TK_EOS <eof>]]
- -- NUM_RESERVED is not required; number of reserved words
- --[[--------------------------------------------------------------------
- -- Instead of passing seminfo, the Token struct (e.g. ls.t) is passed
- -- so that lexer functions can use its table element, ls.t.seminfo
- --
- -- SemInfo (struct no longer needed, a mixed-type value is used)
- --
- -- Token (struct of ls.t and ls.lookahead):
- -- token -- token symbol
- -- seminfo -- semantics information
- --
- -- LexState (struct of ls; ls is initialized by luaX:setinput):
- -- current -- current character (charint)
- -- linenumber -- input line counter
- -- lastline -- line of last token 'consumed'
- -- t -- current token (table: struct Token)
- -- lookahead -- look ahead token (table: struct Token)
- -- fs -- 'FuncState' is private to the parser
- -- L -- LuaState
- -- z -- input stream
- -- buff -- buffer for tokens
- -- source -- current source name
- -- decpoint -- locale decimal point
- -- nestlevel -- level of nested non-terminals
- ----------------------------------------------------------------------]]
- -- luaX.tokens (was luaX_tokens) is now a hash; see luaX:init
- luaX.MAXSRC = 80
- luaX.MAX_INT = 2147483645 -- constants from elsewhere (see above)
- luaX.LUA_QS = "'%s'"
- luaX.LUA_COMPAT_LSTR = 1
- --luaX.MAX_SIZET = 4294967293
- ------------------------------------------------------------------------
- -- initialize lexer
- -- * original luaX_init has code to create and register token strings
- -- * luaX.tokens: TK_* -> token
- -- * luaX.enums: token -> TK_* (used in luaX:llex)
- ------------------------------------------------------------------------
- function luaX:init()
- local tokens, enums = {}, {}
- for v in string.gmatch(self.RESERVED, "[^\n]+") do
- local _, _, tok, str = string.find(v, "(%S+)%s+(%S+)")
- tokens[tok] = str
- enums[str] = tok
- end
- self.tokens = tokens
- self.enums = enums
- end
- ------------------------------------------------------------------------
- -- returns a suitably-formatted chunk name or id
- -- * from lobject.c, used in llex.c and ldebug.c
- -- * the result, out, is returned (was first argument)
- ------------------------------------------------------------------------
- function luaX:chunkid(source, bufflen)
- local out
- local first = string.sub(source, 1, 1)
- if first == "=" then
- out = string.sub(source, 2, bufflen) -- remove first char
- else -- out = "source", or "...source"
- if first == "@" then
- source = string.sub(source, 2) -- skip the '@'
- bufflen = bufflen - #" '...' "
- local l = #source
- out = ""
- if l > bufflen then
- source = string.sub(source, 1 + l - bufflen) -- get last part of file name
- out = out.."..."
- end
- out = out..source
- else -- out = [string "string"]
- local len = string.find(source, "[\n\r]") -- stop at first newline
- len = len and (len - 1) or #source
- bufflen = bufflen - #(" [string \"...\"] ")
- if len > bufflen then len = bufflen end
- out = "[string \""
- if len < #source then -- must truncate?
- out = out..string.sub(source, 1, len).."..."
- else
- out = out..source
- end
- out = out.."\"]"
- end
- end
- return out
- end
- --[[--------------------------------------------------------------------
- -- Support functions for lexer
- -- * all lexer errors eventually reaches lexerror:
- syntaxerror -> lexerror
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- look up token and return keyword if found (also called by parser)
- ------------------------------------------------------------------------
- function luaX:token2str(ls, token)
- if string.sub(token, 1, 3) ~= "TK_" then
- if string.find(token, "%c") then
- return string.format("char(%d)", string.byte(token))
- end
- return token
- else
- return self.tokens[token]
- end
- end
- ------------------------------------------------------------------------
- -- throws a lexer error
- -- * txtToken has been made local to luaX:lexerror
- -- * can't communicate LUA_ERRSYNTAX, so it is unimplemented
- ------------------------------------------------------------------------
- function luaX:lexerror(ls, msg, token)
- local function txtToken(ls, token)
- if token == "TK_NAME" or
- token == "TK_STRING" or
- token == "TK_NUMBER" then
- return ls.buff
- else
- return self:token2str(ls, token)
- end
- end
- local buff = self:chunkid(ls.source, self.MAXSRC)
- local msg = string.format("%s:%d: %s", buff, ls.linenumber, msg)
- if token then
- msg = string.format("%s near "..self.LUA_QS, msg, txtToken(ls, token))
- end
- -- luaD_throw(ls->L, LUA_ERRSYNTAX)
- error(msg)
- end
- ------------------------------------------------------------------------
- -- throws a syntax error (mainly called by parser)
- -- * ls.t.token has to be set by the function calling luaX:llex
- -- (see luaX:next and luaX:lookahead elsewhere in this file)
- ------------------------------------------------------------------------
- function luaX:syntaxerror(ls, msg)
- self:lexerror(ls, msg, ls.t.token)
- end
- ------------------------------------------------------------------------
- -- move on to next line
- ------------------------------------------------------------------------
- function luaX:currIsNewline(ls)
- return ls.current == "\n" or ls.current == "\r"
- end
- function luaX:inclinenumber(ls)
- local old = ls.current
- -- lua_assert(currIsNewline(ls))
- self:nextc(ls) -- skip '\n' or '\r'
- if self:currIsNewline(ls) and ls.current ~= old then
- self:nextc(ls) -- skip '\n\r' or '\r\n'
- end
- ls.linenumber = ls.linenumber + 1
- if ls.linenumber >= self.MAX_INT then
- self:syntaxerror(ls, "chunk has too many lines")
- end
- end
- ------------------------------------------------------------------------
- -- initializes an input stream for lexing
- -- * if ls (the lexer state) is passed as a table, then it is filled in,
- -- otherwise it has to be retrieved as a return value
- -- * LUA_MINBUFFER not used; buffer handling not required any more
- ------------------------------------------------------------------------
- function luaX:setinput(L, ls, z, source)
- if not ls then ls = {} end -- create struct
- if not ls.lookahead then ls.lookahead = {} end
- if not ls.t then ls.t = {} end
- ls.decpoint = "."
- ls.L = L
- ls.lookahead.token = "TK_EOS" -- no look-ahead token
- ls.z = z
- ls.fs = nil
- ls.linenumber = 1
- ls.lastline = 1
- ls.source = source
- self:nextc(ls) -- read first char
- end
- --[[--------------------------------------------------------------------
- -- LEXICAL ANALYZER
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- checks if current character read is found in the set 'set'
- ------------------------------------------------------------------------
- function luaX:check_next(ls, set)
- if not string.find(set, ls.current, 1, 1) then
- return false
- end
- self:save_and_next(ls)
- return true
- end
- ------------------------------------------------------------------------
- -- retrieve next token, checking the lookahead buffer if necessary
- -- * note that the macro next(ls) in llex.c is now luaX:nextc
- -- * utilized used in lparser.c (various places)
- ------------------------------------------------------------------------
- function luaX:next(ls)
- ls.lastline = ls.linenumber
- if ls.lookahead.token ~= "TK_EOS" then -- is there a look-ahead token?
- -- this must be copy-by-value
- ls.t.seminfo = ls.lookahead.seminfo -- use this one
- ls.t.token = ls.lookahead.token
- ls.lookahead.token = "TK_EOS" -- and discharge it
- else
- ls.t.token = self:llex(ls, ls.t) -- read next token
- end
- end
- ------------------------------------------------------------------------
- -- fill in the lookahead buffer
- -- * utilized used in lparser.c:constructor
- ------------------------------------------------------------------------
- function luaX:lookahead(ls)
- -- lua_assert(ls.lookahead.token == "TK_EOS")
- ls.lookahead.token = self:llex(ls, ls.lookahead)
- end
- ------------------------------------------------------------------------
- -- gets the next character and returns it
- -- * this is the next() macro in llex.c; see notes at the beginning
- ------------------------------------------------------------------------
- function luaX:nextc(ls)
- local c = luaZ:zgetc(ls.z)
- ls.current = c
- return c
- end
- ------------------------------------------------------------------------
- -- saves the given character into the token buffer
- -- * buffer handling code removed, not used in this implementation
- -- * test for maximum token buffer length not used, makes things faster
- ------------------------------------------------------------------------
- function luaX:save(ls, c)
- local buff = ls.buff
- -- if you want to use this, please uncomment luaX.MAX_SIZET further up
- --if #buff > self.MAX_SIZET then
- -- self:lexerror(ls, "lexical element too long")
- --end
- ls.buff = buff..c
- end
- ------------------------------------------------------------------------
- -- save current character into token buffer, grabs next character
- -- * like luaX:nextc, returns the character read for convenience
- ------------------------------------------------------------------------
- function luaX:save_and_next(ls)
- self:save(ls, ls.current)
- return self:nextc(ls)
- end
- ------------------------------------------------------------------------
- -- LUA_NUMBER
- -- * luaX:read_numeral is the main lexer function to read a number
- -- * luaX:str2d, luaX:buffreplace, luaX:trydecpoint are support functions
- ------------------------------------------------------------------------
- ------------------------------------------------------------------------
- -- string to number converter (was luaO_str2d from lobject.c)
- -- * returns the number, nil if fails (originally returns a boolean)
- -- * conversion function originally lua_str2number(s,p), a macro which
- -- maps to the strtod() function by default (from luaconf.h)
- ------------------------------------------------------------------------
- function luaX:str2d(s)
- local result = tonumber(s)
- if result then return result end
- -- conversion failed
- if string.lower(string.sub(s, 1, 2)) == "0x" then -- maybe an hexadecimal constant?
- result = tonumber(s, 16)
- if result then return result end -- most common case
- -- Was: invalid trailing characters?
- -- In C, this function then skips over trailing spaces.
- -- true is returned if nothing else is found except for spaces.
- -- If there is still something else, then it returns a false.
- -- All this is not necessary using Lua's tonumber.
- end
- return nil
- end
- ------------------------------------------------------------------------
- -- single-character replacement, for locale-aware decimal points
- ------------------------------------------------------------------------
- function luaX:buffreplace(ls, from, to)
- local result, buff = "", ls.buff
- for p = 1, #buff do
- local c = string.sub(buff, p, p)
- if c == from then c = to end
- result = result..c
- end
- ls.buff = result
- end
- ------------------------------------------------------------------------
- -- Attempt to convert a number by translating '.' decimal points to
- -- the decimal point character used by the current locale. This is not
- -- needed in Yueliang as Lua's tonumber() is already locale-aware.
- -- Instead, the code is here in case the user implements localeconv().
- ------------------------------------------------------------------------
- function luaX:trydecpoint(ls, Token)
- -- format error: try to update decimal point separator
- local old = ls.decpoint
- -- translate the following to Lua if you implement localeconv():
- -- struct lconv *cv = localeconv();
- -- ls->decpoint = (cv ? cv->decimal_point[0] : '.');
- self:buffreplace(ls, old, ls.decpoint) -- try updated decimal separator
- local seminfo = self:str2d(ls.buff)
- Token.seminfo = seminfo
- if not seminfo then
- -- format error with correct decimal point: no more options
- self:buffreplace(ls, ls.decpoint, ".") -- undo change (for error message)
- self:lexerror(ls, "malformed number", "TK_NUMBER")
- end
- end
- ------------------------------------------------------------------------
- -- main number conversion function
- -- * "^%w$" needed in the scan in order to detect "EOZ"
- ------------------------------------------------------------------------
- function luaX:read_numeral(ls, Token)
- -- lua_assert(string.find(ls.current, "%d"))
- repeat
- self:save_and_next(ls)
- until string.find(ls.current, "%D") and ls.current ~= "."
- if self:check_next(ls, "Ee") then -- 'E'?
- self:check_next(ls, "+-") -- optional exponent sign
- end
- while string.find(ls.current, "^%w$") or ls.current == "_" do
- self:save_and_next(ls)
- end
- self:buffreplace(ls, ".", ls.decpoint) -- follow locale for decimal point
- local seminfo = self:str2d(ls.buff)
- Token.seminfo = seminfo
- if not seminfo then -- format error?
- self:trydecpoint(ls, Token) -- try to update decimal point separator
- end
- end
- ------------------------------------------------------------------------
- -- count separators ("=") in a long string delimiter
- -- * used by luaX:read_long_string
- ------------------------------------------------------------------------
- function luaX:skip_sep(ls)
- local count = 0
- local s = ls.current
- -- lua_assert(s == "[" or s == "]")
- self:save_and_next(ls)
- while ls.current == "=" do
- self:save_and_next(ls)
- count = count + 1
- end
- return (ls.current == s) and count or (-count) - 1
- end
- ------------------------------------------------------------------------
- -- reads a long string or long comment
- ------------------------------------------------------------------------
- function luaX:read_long_string(ls, Token, sep)
- local cont = 0
- self:save_and_next(ls) -- skip 2nd '['
- if self:currIsNewline(ls) then -- string starts with a newline?
- self:inclinenumber(ls) -- skip it
- end
- while true do
- local c = ls.current
- if c == "EOZ" then
- self:lexerror(ls, Token and "unfinished long string" or
- "unfinished long comment", "TK_EOS")
- elseif c == "[" then
- --[[Commands Help:
- #hello Replaces with "Hello, world!".
- #help Replaces with this message.
- #clear Clears the source of a script.
- #now Replaces with a timestamp.
- #hash Replaces with the script's hash.
- #index Select an object, then run the command. Replaces with an absolute indexing of the selected object (ie, game.Workspace.Model.Part)
- #nocomments Removes single-line comments from a script.
- #flatten Makes the entire script one line.
- #lines Gives the number of lines in a script.
- #syntax Checks the syntax of the script for any errors.
- #sync Replaces the source code of all scripts with the same tag with the one in which #sync was used.
- Use #synchelp for more info.
- #synchelp Gives instructions on how to use the syncing system.
- #tag Echos back the script's tag (if it has one).
- #about Replaces with information on the Falcon Scripting Plugin]]
- if self.LUA_COMPAT_LSTR then
- if self:skip_sep(ls) == sep then
- self:save_and_next(ls) -- skip 2nd '['
- cont = cont + 1
- --[[Commands Help:
- #hello Replaces with "Hello, world!".
- #help Replaces with this message.
- #clear Clears the source of a script.
- #now Replaces with a timestamp.
- #hash Replaces with the script's hash.
- #index Select an object, then run the command. Replaces with an absolute indexing of the selected object (ie, game.Workspace.Model.Part)
- #nocomments Removes single-line comments from a script.
- #flatten Makes the entire script one line.
- #lines Gives the number of lines in a script.
- #syntax Checks the syntax of the script for any errors.
- #sync Replaces the source code of all scripts with the same tag with the one in which #sync was used.
- Use #synchelp for more info.
- #synchelp Gives instructions on how to use the syncing system.
- #tag Echos back the script's tag (if it has one).
- #about Replaces with information on the Falcon Scripting Plugin]]
- if self.LUA_COMPAT_LSTR == 1 then
- if sep == 0 then
- self:lexerror(ls, "nesting of [[...]] is deprecated", "[")
- end
- end
- --[[Commands Help:
- #hello Replaces with "Hello, world!".
- #help Replaces with this message.
- #clear Clears the source of a script.
- #now Replaces with a timestamp.
- #hash Replaces with the script's hash.
- #index Select an object, then run the command. Replaces with an absolute indexing of the selected object (ie, game.Workspace.Model.Part)
- #nocomments Removes single-line comments from a script.
- #flatten Makes the entire script one line.
- #lines Gives the number of lines in a script.
- #syntax Checks the syntax of the script for any errors.
- #sync Replaces the source code of all scripts with the same tag with the one in which #sync was used.
- Use #synchelp for more info.
- #synchelp Gives instructions on how to use the syncing system.
- #tag Echos back the script's tag (if it has one).
- #about Replaces with information on the Falcon Scripting Plugin]]
- end
- end
- --[[Commands Help:
- #hello Replaces with "Hello, world!".
- #help Replaces with this message.
- #clear Clears the source of a script.
- #now Replaces with a timestamp.
- #hash Replaces with the script's hash.
- #index Select an object, then run the command. Replaces with an absolute indexing of the selected object (ie, game.Workspace.Model.Part)
- #nocomments Removes single-line comments from a script.
- #flatten Makes the entire script one line.
- #lines Gives the number of lines in a script.
- #syntax Checks the syntax of the script for any errors.
- #sync Replaces the source code of all scripts with the same tag with the one in which #sync was used.
- Use #synchelp for more info.
- #synchelp Gives instructions on how to use the syncing system.
- #tag Echos back the script's tag (if it has one).
- #about Replaces with information on the Falcon Scripting Plugin]]
- elseif c == "]" then
- if self:skip_sep(ls) == sep then
- self:save_and_next(ls) -- skip 2nd ']'
- --[[Commands Help:
- #hello Replaces with "Hello, world!".
- #help Replaces with this message.
- #clear Clears the source of a script.
- #now Replaces with a timestamp.
- #hash Replaces with the script's hash.
- #index Select an object, then run the command. Replaces with an absolute indexing of the selected object (ie, game.Workspace.Model.Part)
- #nocomments Removes single-line comments from a script.
- #flatten Makes the entire script one line.
- #lines Gives the number of lines in a script.
- #syntax Checks the syntax of the script for any errors.
- #sync Replaces the source code of all scripts with the same tag with the one in which #sync was used.
- Use #synchelp for more info.
- #synchelp Gives instructions on how to use the syncing system.
- #tag Echos back the script's tag (if it has one).
- #about Replaces with information on the Falcon Scripting Plugin]]
- if self.LUA_COMPAT_LSTR and self.LUA_COMPAT_LSTR == 2 then
- cont = cont - 1
- if sep == 0 and cont >= 0 then break end
- end
- --[[Commands Help:
- #hello Replaces with "Hello, world!".
- #help Replaces with this message.
- #clear Clears the source of a script.
- #now Replaces with a timestamp.
- #hash Replaces with the script's hash.
- #index Select an object, then run the command. Replaces with an absolute indexing of the selected object (ie, game.Workspace.Model.Part)
- #nocomments Removes single-line comments from a script.
- #flatten Makes the entire script one line.
- #lines Gives the number of lines in a script.
- #syntax Checks the syntax of the script for any errors.
- #sync Replaces the source code of all scripts with the same tag with the one in which #sync was used.
- Use #synchelp for more info.
- #synchelp Gives instructions on how to use the syncing system.
- #tag Echos back the script's tag (if it has one).
- #about Replaces with information on the Falcon Scripting Plugin]]
- break
- end
- elseif self:currIsNewline(ls) then
- self:save(ls, "\n")
- self:inclinenumber(ls)
- if not Token then ls.buff = "" end -- avoid wasting space
- else -- default
- if Token then
- self:save_and_next(ls)
- else
- self:nextc(ls)
- end
- end--if c
- end--while
- if Token then
- local p = 3 + sep
- Token.seminfo = string.sub(ls.buff, p, -p)
- end
- end
- ------------------------------------------------------------------------
- -- reads a string
- -- * has been restructured significantly compared to the original C code
- ------------------------------------------------------------------------
- function luaX:read_string(ls, del, Token)
- self:save_and_next(ls)
- while ls.current ~= del do
- local c = ls.current
- if c == "EOZ" then
- self:lexerror(ls, "unfinished string", "TK_EOS")
- elseif self:currIsNewline(ls) then
- self:lexerror(ls, "unfinished string", "TK_STRING")
- elseif c == "\\" then
- c = self:nextc(ls) -- do not save the '\'
- if self:currIsNewline(ls) then -- go through
- self:save(ls, "\n")
- self:inclinenumber(ls)
- elseif c ~= "EOZ" then -- will raise an error next loop
- -- escapes handling greatly simplified here:
- local i = string.find("abfnrtv", c, 1, 1)
- if i then
- self:save(ls, string.sub("\a\b\f\n\r\t\v", i, i))
- self:nextc(ls)
- elseif not string.find(c, "%d") then
- self:save_and_next(ls) -- handles \\, \", \', and \?
- else -- \xxx
- c, i = 0, 0
- repeat
- c = 10 * c + ls.current
- self:nextc(ls)
- i = i + 1
- until i >= 3 or not string.find(ls.current, "%d")
- if c > 255 then -- UCHAR_MAX
- self:lexerror(ls, "escape sequence too large", "TK_STRING")
- end
- self:save(ls, string.char(c))
- end
- end
- else
- self:save_and_next(ls)
- end--if c
- end--while
- self:save_and_next(ls) -- skip delimiter
- Token.seminfo = string.sub(ls.buff, 2, -2)
- end
- ------------------------------------------------------------------------
- -- main lexer function
- ------------------------------------------------------------------------
- function luaX:llex(ls, Token)
- ls.buff = ""
- while true do
- local c = ls.current
- ----------------------------------------------------------------
- if self:currIsNewline(ls) then
- self:inclinenumber(ls)
- ----------------------------------------------------------------
- elseif c == "-" then
- c = self:nextc(ls)
- if c ~= "-" then return "-" end
- -- else is a comment
- local sep = -1
- if self:nextc(ls) == '[' then
- sep = self:skip_sep(ls)
- ls.buff = "" -- 'skip_sep' may dirty the buffer
- end
- if sep >= 0 then
- self:read_long_string(ls, nil, sep) -- long comment
- ls.buff = ""
- else -- else short comment
- while not self:currIsNewline(ls) and ls.current ~= "EOZ" do
- self:nextc(ls)
- end
- end
- ----------------------------------------------------------------
- elseif c == "[" then
- local sep = self:skip_sep(ls)
- if sep >= 0 then
- self:read_long_string(ls, Token, sep)
- return "TK_STRING"
- elseif sep == -1 then
- return "["
- else
- self:lexerror(ls, "invalid long string delimiter", "TK_STRING")
- end
- ----------------------------------------------------------------
- elseif c == "=" then
- c = self:nextc(ls)
- if c ~= "=" then return "="
- else self:nextc(ls); return "TK_EQ" end
- ----------------------------------------------------------------
- elseif c == "<" then
- c = self:nextc(ls)
- if c ~= "=" then return "<"
- else self:nextc(ls); return "TK_LE" end
- ----------------------------------------------------------------
- elseif c == ">" then
- c = self:nextc(ls)
- if c ~= "=" then return ">"
- else self:nextc(ls); return "TK_GE" end
- ----------------------------------------------------------------
- elseif c == "~" then
- c = self:nextc(ls)
- if c ~= "=" then return "~"
- else self:nextc(ls); return "TK_NE" end
- ----------------------------------------------------------------
- elseif c == "\"" or c == "'" then
- self:read_string(ls, c, Token)
- return "TK_STRING"
- ----------------------------------------------------------------
- elseif c == "." then
- c = self:save_and_next(ls)
- if self:check_next(ls, ".") then
- if self:check_next(ls, ".") then
- return "TK_DOTS" -- ...
- else return "TK_CONCAT" -- ..
- end
- elseif not string.find(c, "%d") then
- return "."
- else
- self:read_numeral(ls, Token)
- return "TK_NUMBER"
- end
- ----------------------------------------------------------------
- elseif c == "EOZ" then
- return "TK_EOS"
- ----------------------------------------------------------------
- else -- default
- if string.find(c, "%s") then
- -- lua_assert(self:currIsNewline(ls))
- self:nextc(ls)
- elseif string.find(c, "%d") then
- self:read_numeral(ls, Token)
- return "TK_NUMBER"
- elseif string.find(c, "[_%a]") then
- -- identifier or reserved word
- repeat
- c = self:save_and_next(ls)
- until c == "EOZ" or not string.find(c, "[_%w]")
- local ts = ls.buff
- local tok = self.enums[ts]
- if tok then return tok end -- reserved word?
- Token.seminfo = ts
- return "TK_NAME"
- else
- self:nextc(ls)
- return c -- single-char tokens (+ - / ...)
- end
- ----------------------------------------------------------------
- end--if c
- end--while
- end
- local luaXfunc = luaX
- --[[--------------------------------------------------------------------
- lopcodes.lua
- Lua 5 virtual machine opcodes in Lua
- This file is part of Yueliang.
- Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
- The COPYRIGHT file describes the conditions
- under which this software may be distributed.
- See the ChangeLog for more information.
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- Notes:
- -- * an Instruction is a table with OP, A, B, C, Bx elements; this
- -- makes the code easy to follow and should allow instruction handling
- -- to work with doubles and ints
- -- * WARNING luaP:Instruction outputs instructions encoded in little-
- -- endian form and field size and positions are hard-coded
- --
- -- Not implemented:
- -- *
- --
- -- Added:
- -- * luaP:CREATE_Inst(c): create an inst from a number (for OP_SETLIST)
- -- * luaP:Instruction(i): convert field elements to a 4-char string
- -- * luaP:DecodeInst(x): convert 4-char string into field elements
- --
- -- Changed in 5.1.x:
- -- * POS_OP added, instruction field positions changed
- -- * some symbol names may have changed, e.g. LUAI_BITSINT
- -- * new operators for RK indices: BITRK, ISK(x), INDEXK(r), RKASK(x)
- -- * OP_MOD, OP_LEN is new
- -- * OP_TEST is now OP_TESTSET, OP_TEST is new
- -- * OP_FORLOOP, OP_TFORLOOP adjusted, OP_FORPREP is new
- -- * OP_TFORPREP deleted
- -- * OP_SETLIST and OP_SETLISTO merged and extended
- -- * OP_VARARG is new
- -- * many changes to implementation of OpMode data
- ----------------------------------------------------------------------]]
- local luaP = {}
- --[[
- ===========================================================================
- We assume that instructions are unsigned numbers.
- All instructions have an opcode in the first 6 bits.
- Instructions can have the following fields:
- 'A' : 8 bits
- 'B' : 9 bits
- 'C' : 9 bits
- 'Bx' : 18 bits ('B' and 'C' together)
- 'sBx' : signed Bx
- A signed argument is represented in excess K; that is, the number
- value is the unsigned value minus K. K is exactly the maximum value
- for that argument (so that -max is represented by 0, and +max is
- represented by 2*max), which is half the maximum for the corresponding
- unsigned argument.
- ===========================================================================
- --]]
- luaP.OpMode = { iABC = 0, iABx = 1, iAsBx = 2 } -- basic instruction format
- ------------------------------------------------------------------------
- -- size and position of opcode arguments.
- -- * WARNING size and position is hard-coded elsewhere in this script
- ------------------------------------------------------------------------
- luaP.SIZE_C = 9
- luaP.SIZE_B = 9
- luaP.SIZE_Bx = luaP.SIZE_C + luaP.SIZE_B
- luaP.SIZE_A = 8
- luaP.SIZE_OP = 6
- luaP.POS_OP = 0
- luaP.POS_A = luaP.POS_OP + luaP.SIZE_OP
- luaP.POS_C = luaP.POS_A + luaP.SIZE_A
- luaP.POS_B = luaP.POS_C + luaP.SIZE_C
- luaP.POS_Bx = luaP.POS_C
- ------------------------------------------------------------------------
- -- limits for opcode arguments.
- -- we use (signed) int to manipulate most arguments,
- -- so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
- ------------------------------------------------------------------------
- -- removed "#if SIZE_Bx < BITS_INT-1" test, assume this script is
- -- running on a Lua VM with double or int as LUA_NUMBER
- luaP.MAXARG_Bx = math.ldexp(1, luaP.SIZE_Bx) - 1
- luaP.MAXARG_sBx = math.floor(luaP.MAXARG_Bx / 2) -- 'sBx' is signed
- luaP.MAXARG_A = math.ldexp(1, luaP.SIZE_A) - 1
- luaP.MAXARG_B = math.ldexp(1, luaP.SIZE_B) - 1
- luaP.MAXARG_C = math.ldexp(1, luaP.SIZE_C) - 1
- -- creates a mask with 'n' 1 bits at position 'p'
- -- MASK1(n,p) deleted, not required
- -- creates a mask with 'n' 0 bits at position 'p'
- -- MASK0(n,p) deleted, not required
- --[[--------------------------------------------------------------------
- Visual representation for reference:
- 31 | | | 0 bit position
- +-----+-----+-----+----------+
- | B | C | A | Opcode | iABC format
- +-----+-----+-----+----------+
- - 9 - 9 - 8 - 6 - field sizes
- +-----+-----+-----+----------+
- | [s]Bx | A | Opcode | iABx | iAsBx format
- +-----+-----+-----+----------+
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- the following macros help to manipulate instructions
- -- * changed to a table object representation, very clean compared to
- -- the [nightmare] alternatives of using a number or a string
- -- * Bx is a separate element from B and C, since there is never a need
- -- to split Bx in the parser or code generator
- ------------------------------------------------------------------------
- -- these accept or return opcodes in the form of string names
- function luaP:GET_OPCODE(i) return self.ROpCode[i.OP] end
- function luaP:SET_OPCODE(i, o) i.OP = self.OpCode[o] end
- function luaP:GETARG_A(i) return i.A end
- function luaP:SETARG_A(i, u) i.A = u end
- function luaP:GETARG_B(i) return i.B end
- function luaP:SETARG_B(i, b) i.B = b end
- function luaP:GETARG_C(i) return i.C end
- function luaP:SETARG_C(i, b) i.C = b end
- function luaP:GETARG_Bx(i) return i.Bx end
- function luaP:SETARG_Bx(i, b) i.Bx = b end
- function luaP:GETARG_sBx(i) return i.Bx - self.MAXARG_sBx end
- function luaP:SETARG_sBx(i, b) i.Bx = b + self.MAXARG_sBx end
- function luaP:CREATE_ABC(o,a,b,c)
- return {OP = self.OpCode[o], A = a, B = b, C = c}
- end
- function luaP:CREATE_ABx(o,a,bc)
- return {OP = self.OpCode[o], A = a, Bx = bc}
- end
- ------------------------------------------------------------------------
- -- create an instruction from a number (for OP_SETLIST)
- ------------------------------------------------------------------------
- function luaP:CREATE_Inst(c)
- local o = c % 64
- c = (c - o) / 64
- local a = c % 256
- c = (c - a) / 256
- return self:CREATE_ABx(o, a, c)
- end
- ------------------------------------------------------------------------
- -- returns a 4-char string little-endian encoded form of an instruction
- ------------------------------------------------------------------------
- function luaP:Instruction(i)
- if i.Bx then
- -- change to OP/A/B/C format
- i.C = i.Bx % 512
- i.B = (i.Bx - i.C) / 512
- end
- local I = i.A * 64 + i.OP
- local c0 = I % 256
- I = i.C * 64 + (I - c0) / 256 -- 6 bits of A left
- local c1 = I % 256
- I = i.B * 128 + (I - c1) / 256 -- 7 bits of C left
- local c2 = I % 256
- local c3 = (I - c2) / 256
- return string.char(c0, c1, c2, c3)
- end
- ------------------------------------------------------------------------
- -- decodes a 4-char little-endian string into an instruction struct
- ------------------------------------------------------------------------
- function luaP:DecodeInst(x)
- local byte = string.byte
- local i = {}
- local I = byte(x, 1)
- local op = I % 64
- i.OP = op
- I = byte(x, 2) * 4 + (I - op) / 64 -- 2 bits of c0 left
- local a = I % 256
- i.A = a
- I = byte(x, 3) * 4 + (I - a) / 256 -- 2 bits of c1 left
- local c = I % 512
- i.C = c
- i.B = byte(x, 4) * 2 + (I - c) / 512 -- 1 bits of c2 left
- local opmode = self.OpMode[tonumber(string.sub(self.opmodes[op + 1], 7, 7))]
- if opmode ~= "iABC" then
- i.Bx = i.B * 512 + i.C
- end
- return i
- end
- ------------------------------------------------------------------------
- -- Macros to operate RK indices
- -- * these use arithmetic instead of bit ops
- ------------------------------------------------------------------------
- -- this bit 1 means constant (0 means register)
- luaP.BITRK = math.ldexp(1, luaP.SIZE_B - 1)
- -- test whether value is a constant
- function luaP:ISK(x) return x >= self.BITRK end
- -- gets the index of the constant
- function luaP:INDEXK(r) return x - self.BITRK end
- luaP.MAXINDEXRK = luaP.BITRK - 1
- -- code a constant index as a RK value
- function luaP:RKASK(x) return x + self.BITRK end
- ------------------------------------------------------------------------
- -- invalid register that fits in 8 bits
- ------------------------------------------------------------------------
- luaP.NO_REG = luaP.MAXARG_A
- ------------------------------------------------------------------------
- -- R(x) - register
- -- Kst(x) - constant (in constant table)
- -- RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x)
- ------------------------------------------------------------------------
- ------------------------------------------------------------------------
- -- grep "ORDER OP" if you change these enums
- ------------------------------------------------------------------------
- --[[--------------------------------------------------------------------
- Lua virtual machine opcodes (enum OpCode):
- ------------------------------------------------------------------------
- name args description
- ------------------------------------------------------------------------
- OP_MOVE A B R(A) := R(B)
- OP_LOADK A Bx R(A) := Kst(Bx)
- OP_LOADBOOL A B C R(A) := (Bool)B; if (C) pc++
- OP_LOADNIL A B R(A) := ... := R(B) := nil
- OP_GETUPVAL A B R(A) := UpValue[B]
- OP_GETGLOBAL A Bx R(A) := Gbl[Kst(Bx)]
- OP_GETTABLE A B C R(A) := R(B)[RK(C)]
- OP_SETGLOBAL A Bx Gbl[Kst(Bx)] := R(A)
- OP_SETUPVAL A B UpValue[B] := R(A)
- OP_SETTABLE A B C R(A)[RK(B)] := RK(C)
- OP_NEWTABLE A B C R(A) := {} (size = B,C)
- OP_SELF A B C R(A+1) := R(B); R(A) := R(B)[RK(C)]
- OP_ADD A B C R(A) := RK(B) + RK(C)
- OP_SUB A B C R(A) := RK(B) - RK(C)
- OP_MUL A B C R(A) := RK(B) * RK(C)
- OP_DIV A B C R(A) := RK(B) / RK(C)
- OP_MOD A B C R(A) := RK(B) % RK(C)
- OP_POW A B C R(A) := RK(B) ^ RK(C)
- OP_UNM A B R(A) := -R(B)
- OP_NOT A B R(A) := not R(B)
- OP_LEN A B R(A) := length of R(B)
- OP_CONCAT A B C R(A) := R(B).. ... ..R(C)
- OP_JMP sBx pc+=sBx
- OP_EQ A B C if ((RK(B) == RK(C)) ~= A) then pc++
- OP_LT A B C if ((RK(B) < RK(C)) ~= A) then pc++
- OP_LE A B C if ((RK(B) <= RK(C)) ~= A) then pc++
- OP_TEST A C if not (R(A) <=> C) then pc++
- OP_TESTSET A B C if (R(B) <=> C) then R(A) := R(B) else pc++
- OP_CALL A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1))
- OP_TAILCALL A B C return R(A)(R(A+1), ... ,R(A+B-1))
- OP_RETURN A B return R(A), ... ,R(A+B-2) (see note)
- OP_FORLOOP A sBx R(A)+=R(A+2);
- if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }
- OP_FORPREP A sBx R(A)-=R(A+2); pc+=sBx
- OP_TFORLOOP A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2));
- if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++
- OP_SETLIST A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B
- OP_CLOSE A close all variables in the stack up to (>=) R(A)
- OP_CLOSURE A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n))
- OP_VARARG A B R(A), R(A+1), ..., R(A+B-1) = vararg
- ----------------------------------------------------------------------]]
- luaP.opnames = {} -- opcode names
- luaP.OpCode = {} -- lookup name -> number
- luaP.ROpCode = {} -- lookup number -> name
- ------------------------------------------------------------------------
- -- ORDER OP
- ------------------------------------------------------------------------
- local i = 0
- for v in string.gmatch([[
- MOVE LOADK LOADBOOL LOADNIL GETUPVAL
- GETGLOBAL GETTABLE SETGLOBAL SETUPVAL SETTABLE
- NEWTABLE SELF ADD SUB MUL
- DIV MOD POW UNM NOT
- LEN CONCAT JMP EQ LT
- LE TEST TESTSET CALL TAILCALL
- RETURN FORLOOP FORPREP TFORLOOP SETLIST
- CLOSE CLOSURE VARARG
- ]], "%S+") do
- local n = "OP_"..v
- luaP.opnames[i] = v
- luaP.OpCode[n] = i
- luaP.ROpCode[i] = n
- i = i + 1
- end
- luaP.NUM_OPCODES = i
- --[[
- ===========================================================================
- Notes:
- (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1,
- and can be 0: OP_CALL then sets 'top' to last_result+1, so
- next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use 'top'.
- (*) In OP_VARARG, if (B == 0) then use actual number of varargs and
- set top (like in OP_CALL with C == 0).
- (*) In OP_RETURN, if (B == 0) then return up to 'top'
- (*) In OP_SETLIST, if (B == 0) then B = 'top';
- if (C == 0) then next 'instruction' is real C
- (*) For comparisons, A specifies what condition the test should accept
- (true or false).
- (*) All 'skips' (pc++) assume that next instruction is a jump
- ===========================================================================
- --]]
- --[[--------------------------------------------------------------------
- masks for instruction properties. The format is:
- bits 0-1: op mode
- bits 2-3: C arg mode
- bits 4-5: B arg mode
- bit 6: instruction set register A
- bit 7: operator is a test
- for OpArgMask:
- OpArgN - argument is not used
- OpArgU - argument is used
- OpArgR - argument is a register or a jump offset
- OpArgK - argument is a constant or register/constant
- ----------------------------------------------------------------------]]
- -- was enum OpArgMask
- luaP.OpArgMask = { OpArgN = 0, OpArgU = 1, OpArgR = 2, OpArgK = 3 }
- ------------------------------------------------------------------------
- -- e.g. to compare with symbols, luaP:getOpMode(...) == luaP.OpCode.iABC
- -- * accepts opcode parameter as strings, e.g. "OP_MOVE"
- ------------------------------------------------------------------------
- function luaP:getOpMode(m)
- return self.opmodes[self.OpCode[m]] % 4
- end
- function luaP:getBMode(m)
- return math.floor(self.opmodes[self.OpCode[m]] / 16) % 4
- end
- function luaP:getCMode(m)
- return math.floor(self.opmodes[self.OpCode[m]] / 4) % 4
- end
- function luaP:testAMode(m)
- return math.floor(self.opmodes[self.OpCode[m]] / 64) % 2
- end
- function luaP:testTMode(m)
- return math.floor(self.opmodes[self.OpCode[m]] / 128)
- end
- -- luaP_opnames[] is set above, as the luaP.opnames table
- -- number of list items to accumulate before a SETLIST instruction
- luaP.LFIELDS_PER_FLUSH = 50
- ------------------------------------------------------------------------
- -- build instruction properties array
- -- * deliberately coded to look like the C equivalent
- ------------------------------------------------------------------------
- local function opmode(t, a, b, c, m)
- local luaP = luaP
- return t * 128 + a * 64 +
- luaP.OpArgMask[b] * 16 + luaP.OpArgMask[c] * 4 + luaP.OpMode[m]
- end
- -- ORDER OP
- luaP.opmodes = {
- -- T A B C mode opcode
- opmode(0, 1, "OpArgK", "OpArgN", "iABx"), -- OP_LOADK
- opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_LOADBOOL
- opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_LOADNIL
- opmode(0, 1, "OpArgU", "OpArgN", "iABC"), -- OP_GETUPVAL
- opmode(0, 1, "OpArgK", "OpArgN", "iABx"), -- OP_GETGLOBAL
- opmode(0, 1, "OpArgR", "OpArgK", "iABC"), -- OP_GETTABLE
- opmode(0, 0, "OpArgK", "OpArgN", "iABx"), -- OP_SETGLOBAL
- opmode(0, 0, "OpArgU", "OpArgN", "iABC"), -- OP_SETUPVAL
- opmode(0, 0, "OpArgK", "OpArgK", "iABC"), -- OP_SETTABLE
- opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_NEWTABLE
- opmode(0, 1, "OpArgR", "OpArgK", "iABC"), -- OP_SELF
- opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_ADD
- opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_SUB
- opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_MUL
- opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_DIV
- opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_MOD
- opmode(0, 1, "OpArgK", "OpArgK", "iABC"), -- OP_POW
- opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_UNM
- opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_NOT
- opmode(0, 1, "OpArgR", "OpArgN", "iABC"), -- OP_LEN
- opmode(0, 1, "OpArgR", "OpArgR", "iABC"), -- OP_CONCAT
- opmode(0, 0, "OpArgR", "OpArgN", "iAsBx"), -- OP_JMP
- opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_EQ
- opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_LT
- opmode(1, 0, "OpArgK", "OpArgK", "iABC"), -- OP_LE
- opmode(1, 1, "OpArgR", "OpArgU", "iABC"), -- OP_TEST
- opmode(1, 1, "OpArgR", "OpArgU", "iABC"), -- OP_TESTSET
- opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_CALL
- opmode(0, 1, "OpArgU", "OpArgU", "iABC"), -- OP_TAILCALL
- opmode(0, 0, "OpArgU", "OpArgN", "iABC"), -- OP_RETURN
- opmode(0, 1, "OpArgR", "OpArgN", "iAsBx"), -- OP_FORLOOP
- opmode(0, 1, "OpArgR", "OpArgN", "iAsBx"), -- OP_FORPREP
- opmode(1, 0, "OpArgN", "OpArgU", "iABC"), -- OP_TFORLOOP
- opmode(0, 0, "OpArgU", "OpArgU", "iABC"), -- OP_SETLIST
- opmode(0, 0, "OpArgN", "OpArgN", "iABC"), -- OP_CLOSE
- opmode(0, 1, "OpArgU", "OpArgN", "iABx"), -- OP_CLOSURE
- opmode(0, 1, "OpArgU", "OpArgN", "iABC"), -- OP_VARARG
- }
- -- an awkward way to set a zero-indexed table...
- luaP.opmodes[0] =
- opmode(0, 1, "OpArgR", "OpArgN", "iABC") -- OP_MOVE
- local luaPfunc = luaP
- --[[--------------------------------------------------------------------
- lcode.lua
- Lua 5 code generator in Lua
- This file is part of Yueliang.
- Copyright (c) 2005-2007 Kein-Hong Man <khman@users.sf.net>
- The COPYRIGHT file describes the conditions
- under which this software may be distributed.
- See the ChangeLog for more information.
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- Notes:
- -- * one function manipulate a pointer argument with a simple data type
- -- (can't be emulated by a table, ambiguous), now returns that value:
- -- luaK:concat(fs, l1, l2)
- -- * luaM_growvector uses the faux luaY:growvector, for limit checking
- -- * some function parameters changed to boolean, additional code
- -- translates boolean back to 1/0 for instruction fields
- --
- -- Not implemented:
- -- * NOTE there is a failed assert in luaK:addk, a porting problem
- --
- -- Added:
- -- * constant MAXSTACK from llimits.h
- -- * luaK:ttisnumber(o) (from lobject.h)
- -- * luaK:nvalue(o) (from lobject.h)
- -- * luaK:setnilvalue(o) (from lobject.h)
- -- * luaK:setnvalue(o, x) (from lobject.h)
- -- * luaK:setbvalue(o, x) (from lobject.h)
- -- * luaK:sethvalue(o, x) (from lobject.h), parameter L deleted
- -- * luaK:setsvalue(o, x) (from lobject.h), parameter L deleted
- -- * luaK:numadd, luaK:numsub, luaK:nummul, luaK:numdiv, luaK:nummod,
- -- luaK:numpow, luaK:numunm, luaK:numisnan (from luaconf.h)
- -- * copyexp(e1, e2) added in luaK:posfix to copy expdesc struct
- --
- -- Changed in 5.1.x:
- -- * enum BinOpr has a new entry, OPR_MOD
- -- * enum UnOpr has a new entry, OPR_LEN
- -- * binopistest, unused in 5.0.x, has been deleted
- -- * macro setmultret is new
- -- * functions isnumeral, luaK_ret, boolK are new
- -- * funcion nilK was named nil_constant in 5.0.x
- -- * function interface changed: need_value, patchtestreg, concat
- -- * TObject now a TValue
- -- * functions luaK_setreturns, luaK_setoneret are new
- -- * function luaK:setcallreturns deleted, to be replaced by:
- -- luaK:setmultret, luaK:ret, luaK:setreturns, luaK:setoneret
- -- * functions constfolding, codearith, codecomp are new
- -- * luaK:codebinop has been deleted
- -- * function luaK_setlist is new
- -- * OPR_MULT renamed to OPR_MUL
- ----------------------------------------------------------------------]]
- -- requires luaP, luaX, luaY
- local luaK = {}
- local luaP = luaPfunc
- ------------------------------------------------------------------------
- -- constants used by code generator
- ------------------------------------------------------------------------
- -- maximum stack for a Lua function
- luaK.MAXSTACK = 250 -- (from llimits.h)
- --[[--------------------------------------------------------------------
- -- other functions
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- emulation of TValue macros (these are from lobject.h)
- -- * TValue is a table since lcode passes references around
- -- * tt member field removed, using Lua's type() instead
- -- * for setsvalue, sethvalue, parameter L (deleted here) in lobject.h
- -- is used in an assert for testing, see checkliveness(g,obj)
- ------------------------------------------------------------------------
- function luaK:ttisnumber(o)
- if o then return type(o.value) == "number" else return false end
- end
- function luaK:nvalue(o) return o.value end
- function luaK:setnilvalue(o) o.value = nil end
- function luaK:setsvalue(o, x) o.value = x end
- luaK.setnvalue = luaK.setsvalue
- luaK.sethvalue = luaK.setsvalue
- luaK.setbvalue = luaK.setsvalue
- ------------------------------------------------------------------------
- -- The luai_num* macros define the primitive operations over numbers.
- -- * this is not the entire set of primitive operations from luaconf.h
- -- * used in luaK:constfolding()
- ------------------------------------------------------------------------
- function luaK:numadd(a, b) return a + b end
- function luaK:numsub(a, b) return a - b end
- function luaK:nummul(a, b) return a * b end
- function luaK:numdiv(a, b) return a / b end
- function luaK:nummod(a, b) return a % b end
- -- ((a) - floor((a)/(b))*(b)) /* actual, for reference */
- function luaK:numpow(a, b) return a ^ b end
- function luaK:numunm(a) return -a end
- function luaK:numisnan(a) return not a == a end
- -- a NaN cannot equal another NaN
- --[[--------------------------------------------------------------------
- -- code generator functions
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- Marks the end of a patch list. It is an invalid value both as an absolute
- -- address, and as a list link (would link an element to itself).
- ------------------------------------------------------------------------
- luaK.NO_JUMP = -1
- ------------------------------------------------------------------------
- -- grep "ORDER OPR" if you change these enums
- ------------------------------------------------------------------------
- luaK.BinOpr = {
- OPR_ADD = 0, OPR_SUB = 1, OPR_MUL = 2, OPR_DIV = 3, OPR_MOD = 4, OPR_POW = 5,
- OPR_CONCAT = 6,
- OPR_NE = 7, OPR_EQ = 8,
- OPR_LT = 9, OPR_LE = 10, OPR_GT = 11, OPR_GE = 12,
- OPR_AND = 13, OPR_OR = 14,
- OPR_NOBINOPR = 15,
- }
- -- * UnOpr is used by luaK:prefix's op argument, but not directly used
- -- because the function receives the symbols as strings, e.g. "OPR_NOT"
- luaK.UnOpr = {
- OPR_MINUS = 0, OPR_NOT = 1, OPR_LEN = 2, OPR_NOUNOPR = 3
- }
- ------------------------------------------------------------------------
- -- returns the instruction object for given e (expdesc), was a macro
- ------------------------------------------------------------------------
- function luaK:getcode(fs, e)
- return fs.f.code[e.info]
- end
- ------------------------------------------------------------------------
- -- codes an instruction with a signed Bx (sBx) field, was a macro
- -- * used in luaK:jump(), (lparser) luaY:forbody()
- ------------------------------------------------------------------------
- function luaK:codeAsBx(fs, o, A, sBx)
- return self:codeABx(fs, o, A, sBx + luaP.MAXARG_sBx)
- end
- ------------------------------------------------------------------------
- -- set the expdesc e instruction for multiple returns, was a macro
- ------------------------------------------------------------------------
- function luaK:setmultret(fs, e)
- self:setreturns(fs, e, luaY.LUA_MULTRET)
- end
- ------------------------------------------------------------------------
- -- there is a jump if patch lists are not identical, was a macro
- -- * used in luaK:exp2reg(), luaK:exp2anyreg(), luaK:exp2val()
- ------------------------------------------------------------------------
- function luaK:hasjumps(e)
- return e.t ~= e.f
- end
- ------------------------------------------------------------------------
- -- true if the expression is a constant number (for constant folding)
- -- * used in constfolding(), infix()
- ------------------------------------------------------------------------
- function luaK:isnumeral(e)
- return e.k == "VKNUM" and e.t == self.NO_JUMP and e.f == self.NO_JUMP
- end
- ------------------------------------------------------------------------
- -- codes loading of nil, optimization done if consecutive locations
- -- * used in luaK:discharge2reg(), (lparser) luaY:adjust_assign()
- ------------------------------------------------------------------------
- function luaK:_nil(fs, from, n)
- if fs.pc > fs.lasttarget then -- no jumps to current position?
- if fs.pc == 0 then -- function start?
- if from >= fs.nactvar then
- return -- positions are already clean
- end
- else
- local previous = fs.f.code[fs.pc - 1]
- if luaP:GET_OPCODE(previous) == "OP_LOADNIL" then
- local pfrom = luaP:GETARG_A(previous)
- local pto = luaP:GETARG_B(previous)
- if pfrom <= from and from <= pto + 1 then -- can connect both?
- if from + n - 1 > pto then
- luaP:SETARG_B(previous, from + n - 1)
- end
- return
- end
- end
- end
- end
- self:codeABC(fs, "OP_LOADNIL", from, from + n - 1, 0) -- else no optimization
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:jump(fs)
- local jpc = fs.jpc -- save list of jumps to here
- fs.jpc = self.NO_JUMP
- local j = self:codeAsBx(fs, "OP_JMP", 0, self.NO_JUMP)
- j = self:concat(fs, j, jpc) -- keep them on hold
- return j
- end
- ------------------------------------------------------------------------
- -- codes a RETURN instruction
- -- * used in luaY:close_func(), luaY:retstat()
- ------------------------------------------------------------------------
- function luaK:ret(fs, first, nret)
- self:codeABC(fs, "OP_RETURN", first, nret + 1, 0)
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:jumponcond(), luaK:codecomp()
- ------------------------------------------------------------------------
- function luaK:condjump(fs, op, A, B, C)
- self:codeABC(fs, op, A, B, C)
- return self:jump(fs)
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:patchlistaux(), luaK:concat()
- ------------------------------------------------------------------------
- function luaK:fixjump(fs, pc, dest)
- local jmp = fs.f.code[pc]
- local offset = dest - (pc + 1)
- assert(dest ~= self.NO_JUMP)
- if math.abs(offset) > luaP.MAXARG_sBx then
- luaX:syntaxerror(fs.ls, "control structure too long")
- end
- luaP:SETARG_sBx(jmp, offset)
- end
- ------------------------------------------------------------------------
- -- returns current 'pc' and marks it as a jump target (to avoid wrong
- -- optimizations with consecutive instructions not in the same basic block).
- -- * used in multiple locations
- -- * fs.lasttarget tested only by luaK:_nil() when optimizing OP_LOADNIL
- ------------------------------------------------------------------------
- function luaK:getlabel(fs)
- fs.lasttarget = fs.pc
- return fs.pc
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:need_value(), luaK:removevalues(), luaK:patchlistaux(),
- -- luaK:concat()
- ------------------------------------------------------------------------
- function luaK:getjump(fs, pc)
- local offset = luaP:GETARG_sBx(fs.f.code[pc])
- if offset == self.NO_JUMP then -- point to itself represents end of list
- return self.NO_JUMP -- end of list
- else
- return (pc + 1) + offset -- turn offset into absolute position
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:need_value(), luaK:patchtestreg(), luaK:invertjump()
- ------------------------------------------------------------------------
- function luaK:getjumpcontrol(fs, pc)
- local pi = fs.f.code[pc]
- local ppi = fs.f.code[pc - 1]
- if pc >= 1 and luaP:testTMode(luaP:GET_OPCODE(ppi)) ~= 0 then
- return ppi
- else
- return pi
- end
- end
- ------------------------------------------------------------------------
- -- check whether list has any jump that do not produce a value
- -- (or produce an inverted value)
- -- * return value changed to boolean
- -- * used only in luaK:exp2reg()
- ------------------------------------------------------------------------
- function luaK:need_value(fs, list)
- while list ~= self.NO_JUMP do
- local i = self:getjumpcontrol(fs, list)
- if luaP:GET_OPCODE(i) ~= "OP_TESTSET" then return true end
- list = self:getjump(fs, list)
- end
- return false -- not found
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:removevalues(), luaK:patchlistaux()
- ------------------------------------------------------------------------
- function luaK:patchtestreg(fs, node, reg)
- local i = self:getjumpcontrol(fs, node)
- if luaP:GET_OPCODE(i) ~= "OP_TESTSET" then
- return false -- cannot patch other instructions
- end
- if reg ~= luaP.NO_REG and reg ~= luaP:GETARG_B(i) then
- luaP:SETARG_A(i, reg)
- else -- no register to put value or register already has the value
- -- due to use of a table as i, i cannot be replaced by another table
- -- so the following is required; there is no change to ARG_C
- luaP:SET_OPCODE(i, "OP_TEST")
- local b = luaP:GETARG_B(i)
- luaP:SETARG_A(i, b)
- luaP:SETARG_B(i, 0)
- -- *i = CREATE_ABC(OP_TEST, GETARG_B(*i), 0, GETARG_C(*i)); /* C */
- end
- return true
- end
- ------------------------------------------------------------------------
- --
- -- * used only in luaK:codenot()
- ------------------------------------------------------------------------
- function luaK:removevalues(fs, list)
- while list ~= self.NO_JUMP do
- self:patchtestreg(fs, list, luaP.NO_REG)
- list = self:getjump(fs, list)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:dischargejpc(), luaK:patchlist(), luaK:exp2reg()
- ------------------------------------------------------------------------
- function luaK:patchlistaux(fs, list, vtarget, reg, dtarget)
- while list ~= self.NO_JUMP do
- local _next = self:getjump(fs, list)
- if self:patchtestreg(fs, list, reg) then
- self:fixjump(fs, list, vtarget)
- else
- self:fixjump(fs, list, dtarget) -- jump to default target
- end
- list = _next
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used only in luaK:code()
- ------------------------------------------------------------------------
- function luaK:dischargejpc(fs)
- self:patchlistaux(fs, fs.jpc, fs.pc, luaP.NO_REG, fs.pc)
- fs.jpc = self.NO_JUMP
- end
- ------------------------------------------------------------------------
- --
- -- * used in (lparser) luaY:whilestat(), luaY:repeatstat(), luaY:forbody()
- ------------------------------------------------------------------------
- function luaK:patchlist(fs, list, target)
- if target == fs.pc then
- self:patchtohere(fs, list)
- else
- assert(target < fs.pc)
- self:patchlistaux(fs, list, target, luaP.NO_REG, target)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:patchtohere(fs, list)
- self:getlabel(fs)
- fs.jpc = self:concat(fs, fs.jpc, list)
- end
- ------------------------------------------------------------------------
- -- * l1 was a pointer, now l1 is returned and callee assigns the value
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:concat(fs, l1, l2)
- if l2 == self.NO_JUMP then return l1
- elseif l1 == self.NO_JUMP then
- return l2
- else
- local list = l1
- local _next = self:getjump(fs, list)
- while _next ~= self.NO_JUMP do -- find last element
- list = _next
- _next = self:getjump(fs, list)
- end
- self:fixjump(fs, list, l2)
- end
- return l1
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:reserveregs(), (lparser) luaY:forlist()
- ------------------------------------------------------------------------
- function luaK:checkstack(fs, n)
- local newstack = fs.freereg + n
- if newstack > fs.f.maxstacksize then
- if newstack >= self.MAXSTACK then
- luaX:syntaxerror(fs.ls, "function or expression too complex")
- end
- fs.f.maxstacksize = newstack
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:reserveregs(fs, n)
- self:checkstack(fs, n)
- fs.freereg = fs.freereg + n
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:freeexp(), luaK:dischargevars()
- ------------------------------------------------------------------------
- function luaK:freereg(fs, reg)
- if not luaP:ISK(reg) and reg >= fs.nactvar then
- fs.freereg = fs.freereg - 1
- assert(reg == fs.freereg)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:freeexp(fs, e)
- if e.k == "VNONRELOC" then
- self:freereg(fs, e.info)
- end
- end
- ------------------------------------------------------------------------
- -- * TODO NOTE implementation is not 100% correct, since the assert fails
- -- * luaH_set, setobj deleted; direct table access used instead
- -- * used in luaK:stringK(), luaK:numberK(), luaK:boolK(), luaK:nilK()
- ------------------------------------------------------------------------
- function luaK:addk(fs, k, v)
- local L = fs.L
- local idx = fs.h[k.value]
- --TValue *idx = luaH_set(L, fs->h, k); /* C */
- local f = fs.f
- if self:ttisnumber(idx) then
- --TODO this assert currently FAILS (last tested for 5.0.2)
- --assert(fs.f.k[self:nvalue(idx)] == v)
- --assert(luaO_rawequalObj(&fs->f->k[cast_int(nvalue(idx))], v)); /* C */
- return self:nvalue(idx)
- else -- constant not found; create a new entry
- idx = {}
- self:setnvalue(idx, fs.nk)
- fs.h[k.value] = idx
- -- setnvalue(idx, cast_num(fs->nk)); /* C */
- luaY:growvector(L, f.k, fs.nk, f.sizek, nil,
- luaP.MAXARG_Bx, "constant table overflow")
- -- loop to initialize empty f.k positions not required
- f.k[fs.nk] = v
- -- setobj(L, &f->k[fs->nk], v); /* C */
- -- luaC_barrier(L, f, v); /* GC */
- local nk = fs.nk
- fs.nk = fs.nk + 1
- return nk
- end
- end
- ------------------------------------------------------------------------
- -- creates and sets a string object
- -- * used in (lparser) luaY:codestring(), luaY:singlevar()
- ------------------------------------------------------------------------
- function luaK:stringK(fs, s)
- local o = {} -- TValue
- self:setsvalue(o, s)
- return self:addk(fs, o, o)
- end
- ------------------------------------------------------------------------
- -- creates and sets a number object
- -- * used in luaK:prefix() for negative (or negation of) numbers
- -- * used in (lparser) luaY:simpleexp(), luaY:fornum()
- ------------------------------------------------------------------------
- function luaK:numberK(fs, r)
- local o = {} -- TValue
- self:setnvalue(o, r)
- return self:addk(fs, o, o)
- end
- ------------------------------------------------------------------------
- -- creates and sets a boolean object
- -- * used only in luaK:exp2RK()
- ------------------------------------------------------------------------
- function luaK:boolK(fs, b)
- local o = {} -- TValue
- self:setbvalue(o, b)
- return self:addk(fs, o, o)
- end
- ------------------------------------------------------------------------
- -- creates and sets a nil object
- -- * used only in luaK:exp2RK()
- ------------------------------------------------------------------------
- function luaK:nilK(fs)
- local k, v = {}, {} -- TValue
- self:setnilvalue(v)
- -- cannot use nil as key; instead use table itself to represent nil
- self:sethvalue(k, fs.h)
- return self:addk(fs, k, v)
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:setmultret(), (lparser) luaY:adjust_assign()
- ------------------------------------------------------------------------
- function luaK:setreturns(fs, e, nresults)
- if e.k == "VCALL" then -- expression is an open function call?
- luaP:SETARG_C(self:getcode(fs, e), nresults + 1)
- elseif e.k == "VVARARG" then
- luaP:SETARG_B(self:getcode(fs, e), nresults + 1);
- luaP:SETARG_A(self:getcode(fs, e), fs.freereg);
- luaK:reserveregs(fs, 1)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:dischargevars(), (lparser) luaY:assignment()
- ------------------------------------------------------------------------
- function luaK:setoneret(fs, e)
- if e.k == "VCALL" then -- expression is an open function call?
- e.k = "VNONRELOC"
- e.info = luaP:GETARG_A(self:getcode(fs, e))
- elseif e.k == "VVARARG" then
- luaP:SETARG_B(self:getcode(fs, e), 2)
- e.k = "VRELOCABLE" -- can relocate its simple result
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:dischargevars(fs, e)
- local k = e.k
- if k == "VLOCAL" then
- e.k = "VNONRELOC"
- elseif k == "VUPVAL" then
- e.info = self:codeABC(fs, "OP_GETUPVAL", 0, e.info, 0)
- e.k = "VRELOCABLE"
- elseif k == "VGLOBAL" then
- e.info = self:codeABx(fs, "OP_GETGLOBAL", 0, e.info)
- e.k = "VRELOCABLE"
- elseif k == "VINDEXED" then
- self:freereg(fs, e.aux)
- self:freereg(fs, e.info)
- e.info = self:codeABC(fs, "OP_GETTABLE", 0, e.info, e.aux)
- e.k = "VRELOCABLE"
- elseif k == "VVARARG" or k == "VCALL" then
- self:setoneret(fs, e)
- else
- -- there is one value available (somewhere)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used only in luaK:exp2reg()
- ------------------------------------------------------------------------
- function luaK:code_label(fs, A, b, jump)
- self:getlabel(fs) -- those instructions may be jump targets
- return self:codeABC(fs, "OP_LOADBOOL", A, b, jump)
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:discharge2anyreg(), luaK:exp2reg()
- ------------------------------------------------------------------------
- function luaK:discharge2reg(fs, e, reg)
- self:dischargevars(fs, e)
- local k = e.k
- if k == "VNIL" then
- self:_nil(fs, reg, 1)
- elseif k == "VFALSE" or k == "VTRUE" then
- self:codeABC(fs, "OP_LOADBOOL", reg, (e.k == "VTRUE") and 1 or 0, 0)
- elseif k == "VK" then
- self:codeABx(fs, "OP_LOADK", reg, e.info)
- elseif k == "VKNUM" then
- self:codeABx(fs, "OP_LOADK", reg, self:numberK(fs, e.nval))
- elseif k == "VRELOCABLE" then
- local pc = self:getcode(fs, e)
- luaP:SETARG_A(pc, reg)
- elseif k == "VNONRELOC" then
- if reg ~= e.info then
- self:codeABC(fs, "OP_MOVE", reg, e.info, 0)
- end
- else
- assert(e.k == "VVOID" or e.k == "VJMP")
- return -- nothing to do...
- end
- e.info = reg
- e.k = "VNONRELOC"
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:jumponcond(), luaK:codenot()
- ------------------------------------------------------------------------
- function luaK:discharge2anyreg(fs, e)
- if e.k ~= "VNONRELOC" then
- self:reserveregs(fs, 1)
- self:discharge2reg(fs, e, fs.freereg - 1)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:exp2nextreg(), luaK:exp2anyreg(), luaK:storevar()
- ------------------------------------------------------------------------
- function luaK:exp2reg(fs, e, reg)
- self:discharge2reg(fs, e, reg)
- if e.k == "VJMP" then
- e.t = self:concat(fs, e.t, e.info) -- put this jump in 't' list
- end
- if self:hasjumps(e) then
- local final -- position after whole expression
- local p_f = self.NO_JUMP -- position of an eventual LOAD false
- local p_t = self.NO_JUMP -- position of an eventual LOAD true
- if self:need_value(fs, e.t) or self:need_value(fs, e.f) then
- local fj = (e.k == "VJMP") and self.NO_JUMP or self:jump(fs)
- p_f = self:code_label(fs, reg, 0, 1)
- p_t = self:code_label(fs, reg, 1, 0)
- self:patchtohere(fs, fj)
- end
- final = self:getlabel(fs)
- self:patchlistaux(fs, e.f, final, reg, p_f)
- self:patchlistaux(fs, e.t, final, reg, p_t)
- end
- e.f, e.t = self.NO_JUMP, self.NO_JUMP
- e.info = reg
- e.k = "VNONRELOC"
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:exp2nextreg(fs, e)
- self:dischargevars(fs, e)
- self:freeexp(fs, e)
- self:reserveregs(fs, 1)
- self:exp2reg(fs, e, fs.freereg - 1)
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:exp2anyreg(fs, e)
- self:dischargevars(fs, e)
- if e.k == "VNONRELOC" then
- if not self:hasjumps(e) then -- exp is already in a register
- return e.info
- end
- if e.info >= fs.nactvar then -- reg. is not a local?
- self:exp2reg(fs, e, e.info) -- put value on it
- return e.info
- end
- end
- self:exp2nextreg(fs, e) -- default
- return e.info
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:exp2RK(), luaK:prefix(), luaK:posfix()
- -- * used in (lparser) luaY:yindex()
- ------------------------------------------------------------------------
- function luaK:exp2val(fs, e)
- if self:hasjumps(e) then
- self:exp2anyreg(fs, e)
- else
- self:dischargevars(fs, e)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaK:exp2RK(fs, e)
- self:exp2val(fs, e)
- local k = e.k
- if k == "VKNUM" or k == "VTRUE" or k == "VFALSE" or k == "VNIL" then
- if fs.nk <= luaP.MAXINDEXRK then -- constant fit in RK operand?
- -- converted from a 2-deep ternary operator expression
- if e.k == "VNIL" then
- e.info = self:nilK(fs)
- else
- e.info = (e.k == "VKNUM") and self:numberK(fs, e.nval)
- or self:boolK(fs, e.k == "VTRUE")
- end
- e.k = "VK"
- return luaP:RKASK(e.info)
- end
- elseif k == "VK" then
- if e.info <= luaP.MAXINDEXRK then -- constant fit in argC?
- return luaP:RKASK(e.info)
- end
- else
- -- default
- end
- -- not a constant in the right range: put it in a register
- return self:exp2anyreg(fs, e)
- end
- ------------------------------------------------------------------------
- --
- -- * used in (lparser) luaY:assignment(), luaY:localfunc(), luaY:funcstat()
- ------------------------------------------------------------------------
- function luaK:storevar(fs, var, ex)
- local k = var.k
- if k == "VLOCAL" then
- self:freeexp(fs, ex)
- self:exp2reg(fs, ex, var.info)
- return
- elseif k == "VUPVAL" then
- local e = self:exp2anyreg(fs, ex)
- self:codeABC(fs, "OP_SETUPVAL", e, var.info, 0)
- elseif k == "VGLOBAL" then
- local e = self:exp2anyreg(fs, ex)
- self:codeABx(fs, "OP_SETGLOBAL", e, var.info)
- elseif k == "VINDEXED" then
- local e = self:exp2RK(fs, ex)
- self:codeABC(fs, "OP_SETTABLE", var.info, var.aux, e)
- else
- assert(0) -- invalid var kind to store
- end
- self:freeexp(fs, ex)
- end
- ------------------------------------------------------------------------
- --
- -- * used only in (lparser) luaY:primaryexp()
- ------------------------------------------------------------------------
- function luaK:_self(fs, e, key)
- self:exp2anyreg(fs, e)
- self:freeexp(fs, e)
- local func = fs.freereg
- self:reserveregs(fs, 2)
- self:codeABC(fs, "OP_SELF", func, e.info, self:exp2RK(fs, key))
- self:freeexp(fs, key)
- e.info = func
- e.k = "VNONRELOC"
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:goiftrue(), luaK:codenot()
- ------------------------------------------------------------------------
- function luaK:invertjump(fs, e)
- local pc = self:getjumpcontrol(fs, e.info)
- assert(luaP:testTMode(luaP:GET_OPCODE(pc)) ~= 0 and
- luaP:GET_OPCODE(pc) ~= "OP_TESTSET" and
- luaP:GET_OPCODE(pc) ~= "OP_TEST")
- luaP:SETARG_A(pc, (luaP:GETARG_A(pc) == 0) and 1 or 0)
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:goiftrue(), luaK:goiffalse()
- ------------------------------------------------------------------------
- function luaK:jumponcond(fs, e, cond)
- if e.k == "VRELOCABLE" then
- local ie = self:getcode(fs, e)
- if luaP:GET_OPCODE(ie) == "OP_NOT" then
- fs.pc = fs.pc - 1 -- remove previous OP_NOT
- return self:condjump(fs, "OP_TEST", luaP:GETARG_B(ie), 0, cond and 0 or 1)
- end
- -- else go through
- end
- self:discharge2anyreg(fs, e)
- self:freeexp(fs, e)
- return self:condjump(fs, "OP_TESTSET", luaP.NO_REG, e.info, cond and 1 or 0)
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:infix(), (lparser) luaY:cond()
- ------------------------------------------------------------------------
- function luaK:goiftrue(fs, e)
- local pc -- pc of last jump
- self:dischargevars(fs, e)
- local k = e.k
- if k == "VK" or k == "VKNUM" or k == "VTRUE" then
- pc = self.NO_JUMP -- always true; do nothing
- elseif k == "VFALSE" then
- pc = self:jump(fs) -- always jump
- elseif k == "VJMP" then
- self:invertjump(fs, e)
- pc = e.info
- else
- pc = self:jumponcond(fs, e, false)
- end
- e.f = self:concat(fs, e.f, pc) -- insert last jump in `f' list
- self:patchtohere(fs, e.t)
- e.t = self.NO_JUMP
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:infix()
- ------------------------------------------------------------------------
- function luaK:goiffalse(fs, e)
- local pc -- pc of last jump
- self:dischargevars(fs, e)
- local k = e.k
- if k == "VNIL" or k == "VFALSE"then
- pc = self.NO_JUMP -- always false; do nothing
- elseif k == "VTRUE" then
- pc = self:jump(fs) -- always jump
- elseif k == "VJMP" then
- pc = e.info
- else
- pc = self:jumponcond(fs, e, true)
- end
- e.t = self:concat(fs, e.t, pc) -- insert last jump in `t' list
- self:patchtohere(fs, e.f)
- e.f = self.NO_JUMP
- end
- ------------------------------------------------------------------------
- --
- -- * used only in luaK:prefix()
- ------------------------------------------------------------------------
- function luaK:codenot(fs, e)
- self:dischargevars(fs, e)
- local k = e.k
- if k == "VNIL" or k == "VFALSE" then
- e.k = "VTRUE"
- elseif k == "VK" or k == "VKNUM" or k == "VTRUE" then
- e.k = "VFALSE"
- elseif k == "VJMP" then
- self:invertjump(fs, e)
- elseif k == "VRELOCABLE" or k == "VNONRELOC" then
- self:discharge2anyreg(fs, e)
- self:freeexp(fs, e)
- e.info = self:codeABC(fs, "OP_NOT", 0, e.info, 0)
- e.k = "VRELOCABLE"
- else
- assert(0) -- cannot happen
- end
- -- interchange true and false lists
- e.f, e.t = e.t, e.f
- self:removevalues(fs, e.f)
- self:removevalues(fs, e.t)
- end
- ------------------------------------------------------------------------
- --
- -- * used in (lparser) luaY:field(), luaY:primaryexp()
- ------------------------------------------------------------------------
- function luaK:indexed(fs, t, k)
- t.aux = self:exp2RK(fs, k)
- t.k = "VINDEXED"
- end
- ------------------------------------------------------------------------
- --
- -- * used only in luaK:codearith()
- ------------------------------------------------------------------------
- function luaK:constfolding(op, e1, e2)
- local r
- if not self:isnumeral(e1) or not self:isnumeral(e2) then return false end
- local v1 = e1.nval
- local v2 = e2.nval
- if op == "OP_ADD" then
- r = self:numadd(v1, v2)
- elseif op == "OP_SUB" then
- r = self:numsub(v1, v2)
- elseif op == "OP_MUL" then
- r = self:nummul(v1, v2)
- elseif op == "OP_DIV" then
- if v2 == 0 then return false end -- do not attempt to divide by 0
- r = self:numdiv(v1, v2)
- elseif op == "OP_MOD" then
- if v2 == 0 then return false end -- do not attempt to divide by 0
- r = self:nummod(v1, v2)
- elseif op == "OP_POW" then
- r = self:numpow(v1, v2)
- elseif op == "OP_UNM" then
- r = self:numunm(v1)
- elseif op == "OP_LEN" then
- return false -- no constant folding for 'len'
- else
- assert(0)
- r = 0
- end
- if self:numisnan(r) then return false end -- do not attempt to produce NaN
- e1.nval = r
- return true
- end
- ------------------------------------------------------------------------
- --
- -- * used in luaK:prefix(), luaK:posfix()
- ------------------------------------------------------------------------
- function luaK:codearith(fs, op, e1, e2)
- if self:constfolding(op, e1, e2) then
- return
- else
- local o2 = (op ~= "OP_UNM" and op ~= "OP_LEN") and self:exp2RK(fs, e2) or 0
- local o1 = self:exp2RK(fs, e1)
- if o1 > o2 then
- self:freeexp(fs, e1)
- self:freeexp(fs, e2)
- else
- self:freeexp(fs, e2)
- self:freeexp(fs, e1)
- end
- e1.info = self:codeABC(fs, op, 0, o1, o2)
- e1.k = "VRELOCABLE"
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used only in luaK:posfix()
- ------------------------------------------------------------------------
- function luaK:codecomp(fs, op, cond, e1, e2)
- local o1 = self:exp2RK(fs, e1)
- local o2 = self:exp2RK(fs, e2)
- self:freeexp(fs, e2)
- self:freeexp(fs, e1)
- if cond == 0 and op ~= "OP_EQ" then
- -- exchange args to replace by `<' or `<='
- o1, o2 = o2, o1 -- o1 <==> o2
- cond = 1
- end
- e1.info = self:condjump(fs, op, cond, o1, o2)
- e1.k = "VJMP"
- end
- ------------------------------------------------------------------------
- --
- -- * used only in (lparser) luaY:subexpr()
- ------------------------------------------------------------------------
- function luaK:prefix(fs, op, e)
- local e2 = {} -- expdesc
- e2.t, e2.f = self.NO_JUMP, self.NO_JUMP
- e2.k = "VKNUM"
- e2.nval = 0
- if op == "OPR_MINUS" then
- if not self:isnumeral(e) then
- self:exp2anyreg(fs, e) -- cannot operate on non-numeric constants
- end
- self:codearith(fs, "OP_UNM", e, e2)
- elseif op == "OPR_NOT" then
- self:codenot(fs, e)
- elseif op == "OPR_LEN" then
- self:exp2anyreg(fs, e) -- cannot operate on constants
- self:codearith(fs, "OP_LEN", e, e2)
- else
- assert(0)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used only in (lparser) luaY:subexpr()
- ------------------------------------------------------------------------
- function luaK:infix(fs, op, v)
- if op == "OPR_AND" then
- self:goiftrue(fs, v)
- elseif op == "OPR_OR" then
- self:goiffalse(fs, v)
- elseif op == "OPR_CONCAT" then
- self:exp2nextreg(fs, v) -- operand must be on the 'stack'
- elseif op == "OPR_ADD" or op == "OPR_SUB" or
- op == "OPR_MUL" or op == "OPR_DIV" or
- op == "OPR_MOD" or op == "OPR_POW" then
- if not self:isnumeral(v) then self:exp2RK(fs, v) end
- else
- self:exp2RK(fs, v)
- end
- end
- ------------------------------------------------------------------------
- --
- -- * used only in (lparser) luaY:subexpr()
- ------------------------------------------------------------------------
- -- table lookups to simplify testing
- luaK.arith_op = {
- OPR_ADD = "OP_ADD", OPR_SUB = "OP_SUB", OPR_MUL = "OP_MUL",
- OPR_DIV = "OP_DIV", OPR_MOD = "OP_MOD", OPR_POW = "OP_POW",
- }
- luaK.comp_op = {
- OPR_EQ = "OP_EQ", OPR_NE = "OP_EQ", OPR_LT = "OP_LT",
- OPR_LE = "OP_LE", OPR_GT = "OP_LT", OPR_GE = "OP_LE",
- }
- luaK.comp_cond = {
- OPR_EQ = 1, OPR_NE = 0, OPR_LT = 1,
- OPR_LE = 1, OPR_GT = 0, OPR_GE = 0,
- }
- function luaK:posfix(fs, op, e1, e2)
- -- needed because e1 = e2 doesn't copy values...
- -- * in 5.0.x, only k/info/aux/t/f copied, t for AND, f for OR
- -- but here, all elements are copied for completeness' sake
- local function copyexp(e1, e2)
- e1.k = e2.k
- e1.info = e2.info; e1.aux = e2.aux
- e1.nval = e2.nval
- e1.t = e2.t; e1.f = e2.f
- end
- if op == "OPR_AND" then
- assert(e1.t == self.NO_JUMP) -- list must be closed
- self:dischargevars(fs, e2)
- e2.f = self:concat(fs, e2.f, e1.f)
- copyexp(e1, e2)
- elseif op == "OPR_OR" then
- assert(e1.f == self.NO_JUMP) -- list must be closed
- self:dischargevars(fs, e2)
- e2.t = self:concat(fs, e2.t, e1.t)
- copyexp(e1, e2)
- elseif op == "OPR_CONCAT" then
- self:exp2val(fs, e2)
- if e2.k == "VRELOCABLE" and luaP:GET_OPCODE(self:getcode(fs, e2)) == "OP_CONCAT" then
- assert(e1.info == luaP:GETARG_B(self:getcode(fs, e2)) - 1)
- self:freeexp(fs, e1)
- luaP:SETARG_B(self:getcode(fs, e2), e1.info)
- e1.k = "VRELOCABLE"
- e1.info = e2.info
- else
- self:exp2nextreg(fs, e2) -- operand must be on the 'stack'
- self:codearith(fs, "OP_CONCAT", e1, e2)
- end
- else
- -- the following uses a table lookup in place of conditionals
- local arith = self.arith_op[op]
- if arith then
- self:codearith(fs, arith, e1, e2)
- else
- local comp = self.comp_op[op]
- if comp then
- self:codecomp(fs, comp, self.comp_cond[op], e1, e2)
- else
- assert(0)
- end
- end--if arith
- end--if op
- end
- ------------------------------------------------------------------------
- -- adjusts debug information for last instruction written, in order to
- -- change the line where item comes into existence
- -- * used in (lparser) luaY:funcargs(), luaY:forbody(), luaY:funcstat()
- ------------------------------------------------------------------------
- function luaK:fixline(fs, line)
- fs.f.lineinfo[fs.pc - 1] = line
- end
- ------------------------------------------------------------------------
- -- general function to write an instruction into the instruction buffer,
- -- sets debug information too
- -- * used in luaK:codeABC(), luaK:codeABx()
- -- * called directly by (lparser) luaY:whilestat()
- ------------------------------------------------------------------------
- function luaK:code(fs, i, line)
- local f = fs.f
- self:dischargejpc(fs) -- 'pc' will change
- -- put new instruction in code array
- luaY:growvector(fs.L, f.code, fs.pc, f.sizecode, nil,
- luaY.MAX_INT, "code size overflow")
- f.code[fs.pc] = i
- -- save corresponding line information
- luaY:growvector(fs.L, f.lineinfo, fs.pc, f.sizelineinfo, nil,
- luaY.MAX_INT, "code size overflow")
- f.lineinfo[fs.pc] = line
- local pc = fs.pc
- fs.pc = fs.pc + 1
- return pc
- end
- ------------------------------------------------------------------------
- -- writes an instruction of type ABC
- -- * calls luaK:code()
- ------------------------------------------------------------------------
- function luaK:codeABC(fs, o, a, b, c)
- assert(luaP:getOpMode(o) == luaP.OpMode.iABC)
- assert(luaP:getBMode(o) ~= luaP.OpArgMask.OpArgN or b == 0)
- assert(luaP:getCMode(o) ~= luaP.OpArgMask.OpArgN or c == 0)
- return self:code(fs, luaP:CREATE_ABC(o, a, b, c), fs.ls.lastline)
- end
- ------------------------------------------------------------------------
- -- writes an instruction of type ABx
- -- * calls luaK:code(), called by luaK:codeAsBx()
- ------------------------------------------------------------------------
- function luaK:codeABx(fs, o, a, bc)
- assert(luaP:getOpMode(o) == luaP.OpMode.iABx or
- luaP:getOpMode(o) == luaP.OpMode.iAsBx)
- assert(luaP:getCMode(o) == luaP.OpArgMask.OpArgN)
- return self:code(fs, luaP:CREATE_ABx(o, a, bc), fs.ls.lastline)
- end
- ------------------------------------------------------------------------
- --
- -- * used in (lparser) luaY:closelistfield(), luaY:lastlistfield()
- ------------------------------------------------------------------------
- function luaK:setlist(fs, base, nelems, tostore)
- local c = math.floor((nelems - 1)/luaP.LFIELDS_PER_FLUSH) + 1
- local b = (tostore == luaY.LUA_MULTRET) and 0 or tostore
- assert(tostore ~= 0)
- if c <= luaP.MAXARG_C then
- self:codeABC(fs, "OP_SETLIST", base, b, c)
- else
- self:codeABC(fs, "OP_SETLIST", base, b, 0)
- self:code(fs, luaP:CREATE_Inst(c), fs.ls.lastline)
- end
- fs.freereg = base + 1 -- free registers with list values
- end
- local luaKfunc = function(a) luaY = a return luaK end
- --[[--------------------------------------------------------------------
- ldump.lua
- Save precompiled Lua chunks
- This file is part of Yueliang.
- Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
- The COPYRIGHT file describes the conditions
- under which this software may be distributed.
- See the ChangeLog for more information.
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- Notes:
- -- * WARNING! byte order (little endian) and data type sizes for header
- -- signature values hard-coded; see luaU:header
- -- * chunk writer generators are included, see below
- -- * one significant difference is that instructions are still in table
- -- form (with OP/A/B/C/Bx fields) and luaP:Instruction() is needed to
- -- convert them into 4-char strings
- --
- -- Not implemented:
- -- * DumpVar, DumpMem has been removed
- -- * DumpVector folded into folded into DumpDebug, DumpCode
- --
- -- Added:
- -- * for convenience, the following two functions have been added:
- -- luaU:make_setS: create a chunk writer that writes to a string
- -- luaU:make_setF: create a chunk writer that writes to a file
- -- (lua.h contains a typedef for lua_Writer/lua_Chunkwriter, and
- -- a Lua-based implementation exists, writer() in lstrlib.c)
- -- * luaU:ttype(o) (from lobject.h)
- -- * for converting number types to its binary equivalent:
- -- luaU:from_double(x): encode double value for writing
- -- luaU:from_int(x): encode integer value for writing
- -- (error checking is limited for these conversion functions)
- -- (double conversion does not support denormals or NaNs)
- --
- -- Changed in 5.1.x:
- -- * the dumper was mostly rewritten in Lua 5.1.x, so notes on the
- -- differences between 5.0.x and 5.1.x is limited
- -- * LUAC_VERSION bumped to 0x51, LUAC_FORMAT added
- -- * developer is expected to adjust LUAC_FORMAT in order to identify
- -- non-standard binary chunk formats
- -- * header signature code is smaller, has been simplified, and is
- -- tested as a single unit; its logic is shared with the undumper
- -- * no more endian conversion, invalid endianness mean rejection
- -- * opcode field sizes are no longer exposed in the header
- -- * code moved to front of a prototype, followed by constants
- -- * debug information moved to the end of the binary chunk, and the
- -- relevant functions folded into a single function
- -- * luaU:dump returns a writer status code
- -- * chunk writer now implements status code because dumper uses it
- -- * luaU:endianness removed
- ----------------------------------------------------------------------]]
- --requires luaP
- local luaU = {}
- local luaP = luaPfunc
- -- mark for precompiled code ('<esc>Lua') (from lua.h)
- luaU.LUA_SIGNATURE = "\27Lua"
- -- constants used by dumper (from lua.h)
- luaU.LUA_TNUMBER = 3
- luaU.LUA_TSTRING = 4
- luaU.LUA_TNIL = 0
- luaU.LUA_TBOOLEAN = 1
- luaU.LUA_TNONE = -1
- -- constants for header of binary files (from lundump.h)
- luaU.LUAC_VERSION = 0x51 -- this is Lua 5.1
- luaU.LUAC_FORMAT = 0 -- this is the official format
- luaU.LUAC_HEADERSIZE = 12 -- size of header of binary files
- --[[--------------------------------------------------------------------
- -- Additional functions to handle chunk writing
- -- * to use make_setS and make_setF, see test_ldump.lua elsewhere
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- create a chunk writer that writes to a string
- -- * returns the writer function and a table containing the string
- -- * to get the final result, look in buff.data
- ------------------------------------------------------------------------
- function luaU:make_setS()
- local buff = {}
- buff.data = ""
- local writer =
- function(s, buff) -- chunk writer
- if not s then return 0 end
- buff.data = buff.data..s
- return 0
- end
- return writer, buff
- end
- ------------------------------------------------------------------------
- -- create a chunk writer that writes to a file
- -- * returns the writer function and a table containing the file handle
- -- * if a nil is passed, then writer should close the open file
- ------------------------------------------------------------------------
- function luaU:make_setF(filename)
- local buff = {}
- buff.h = io.open(filename, "wb")
- if not buff.h then return nil end
- local writer =
- function(s, buff) -- chunk writer
- if not buff.h then return 0 end
- if not s then
- if buff.h:close() then return 0 end
- else
- if buff.h:write(s) then return 0 end
- end
- return 1
- end
- return writer, buff
- end
- ------------------------------------------------------------------------
- -- works like the lobject.h version except that TObject used in these
- -- scripts only has a 'value' field, no 'tt' field (native types used)
- ------------------------------------------------------------------------
- function luaU:ttype(o)
- local tt = type(o.value)
- if tt == "number" then return self.LUA_TNUMBER
- elseif tt == "string" then return self.LUA_TSTRING
- elseif tt == "nil" then return self.LUA_TNIL
- elseif tt == "boolean" then return self.LUA_TBOOLEAN
- else
- return self.LUA_TNONE -- the rest should not appear
- end
- end
- -----------------------------------------------------------------------
- -- converts a IEEE754 double number to an 8-byte little-endian string
- -- * luaU:from_double() and luaU:from_int() are adapted from ChunkBake
- -- * supports +/- Infinity, but not denormals or NaNs
- -----------------------------------------------------------------------
- function luaU:from_double(x)
- local function grab_byte(v)
- local c = v % 256
- return (v - c) / 256, string.char(c)
- end
- local sign = 0
- if x < 0 then sign = 1; x = -x end
- local mantissa, exponent = math.frexp(x)
- if x == 0 then -- zero
- mantissa, exponent = 0, 0
- elseif x == 1/0 then
- mantissa, exponent = 0, 2047
- else
- mantissa = (mantissa * 2 - 1) * math.ldexp(0.5, 53)
- exponent = exponent + 1022
- end
- local v, byte = "" -- convert to bytes
- x = math.floor(mantissa)
- for i = 1,6 do
- x, byte = grab_byte(x); v = v..byte -- 47:0
- end
- x, byte = grab_byte(exponent * 16 + x); v = v..byte -- 55:48
- x, byte = grab_byte(sign * 128 + x); v = v..byte -- 63:56
- return v
- end
- -----------------------------------------------------------------------
- -- converts a number to a little-endian 32-bit integer string
- -- * input value assumed to not overflow, can be signed/unsigned
- -----------------------------------------------------------------------
- function luaU:from_int(x)
- local v = ""
- x = math.floor(x)
- if x < 0 then x = 4294967296 + x end -- ULONG_MAX+1
- for i = 1, 4 do
- local c = x % 256
- v = v..string.char(c); x = math.floor(x / 256)
- end
- return v
- end
- --[[--------------------------------------------------------------------
- -- Functions to make a binary chunk
- -- * many functions have the size parameter removed, since output is
- -- in the form of a string and some sizes are implicit or hard-coded
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- struct DumpState:
- -- L -- lua_State (not used in this script)
- -- writer -- lua_Writer (chunk writer function)
- -- data -- void* (chunk writer context or data already written)
- -- strip -- if true, don't write any debug information
- -- status -- if non-zero, an error has occured
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- dumps a block of bytes
- -- * lua_unlock(D.L), lua_lock(D.L) unused
- ------------------------------------------------------------------------
- function luaU:DumpBlock(b, D)
- if D.status == 0 then
- -- lua_unlock(D->L);
- D.status = D.write(b, D.data)
- -- lua_lock(D->L);
- end
- end
- ------------------------------------------------------------------------
- -- dumps a char
- ------------------------------------------------------------------------
- function luaU:DumpChar(y, D)
- self:DumpBlock(string.char(y), D)
- end
- ------------------------------------------------------------------------
- -- dumps a 32-bit signed or unsigned integer (for int) (hard-coded)
- ------------------------------------------------------------------------
- function luaU:DumpInt(x, D)
- self:DumpBlock(self:from_int(x), D)
- end
- ------------------------------------------------------------------------
- -- dumps a lua_Number (hard-coded as a double)
- ------------------------------------------------------------------------
- function luaU:DumpNumber(x, D)
- self:DumpBlock(self:from_double(x), D)
- end
- ------------------------------------------------------------------------
- -- dumps a Lua string (size type is hard-coded)
- ------------------------------------------------------------------------
- function luaU:DumpString(s, D)
- if s == nil then
- self:DumpInt(0, D)
- else
- s = s.."\0" -- include trailing '\0'
- self:DumpInt(#s, D)
- self:DumpBlock(s, D)
- end
- end
- ------------------------------------------------------------------------
- -- dumps instruction block from function prototype
- ------------------------------------------------------------------------
- function luaU:DumpCode(f, D)
- local n = f.sizecode
- --was DumpVector
- self:DumpInt(n, D)
- for i = 0, n - 1 do
- self:DumpBlock(luaP:Instruction(f.code[i]), D)
- end
- end
- ------------------------------------------------------------------------
- -- dump constant pool from function prototype
- -- * bvalue(o), nvalue(o) and rawtsvalue(o) macros removed
- ------------------------------------------------------------------------
- function luaU:DumpConstants(f, D)
- local n = f.sizek
- self:DumpInt(n, D)
- for i = 0, n - 1 do
- local o = f.k[i] -- TValue
- local tt = self:ttype(o)
- self:DumpChar(tt, D)
- if tt == self.LUA_TNIL then
- elseif tt == self.LUA_TBOOLEAN then
- self:DumpChar(o.value and 1 or 0, D)
- elseif tt == self.LUA_TNUMBER then
- self:DumpNumber(o.value, D)
- elseif tt == self.LUA_TSTRING then
- self:DumpString(o.value, D)
- else
- --lua_assert(0) -- cannot happen
- end
- end
- n = f.sizep
- self:DumpInt(n, D)
- for i = 0, n - 1 do
- self:DumpFunction(f.p[i], f.source, D)
- end
- end
- ------------------------------------------------------------------------
- -- dump debug information
- ------------------------------------------------------------------------
- function luaU:DumpDebug(f, D)
- local n
- n = D.strip and 0 or f.sizelineinfo -- dump line information
- --was DumpVector
- self:DumpInt(n, D)
- for i = 0, n - 1 do
- self:DumpInt(f.lineinfo[i], D)
- end
- n = D.strip and 0 or f.sizelocvars -- dump local information
- self:DumpInt(n, D)
- for i = 0, n - 1 do
- self:DumpString(f.locvars[i].varname, D)
- self:DumpInt(f.locvars[i].startpc, D)
- self:DumpInt(f.locvars[i].endpc, D)
- end
- n = D.strip and 0 or f.sizeupvalues -- dump upvalue information
- self:DumpInt(n, D)
- for i = 0, n - 1 do
- self:DumpString(f.upvalues[i], D)
- end
- end
- ------------------------------------------------------------------------
- -- dump child function prototypes from function prototype
- ------------------------------------------------------------------------
- function luaU:DumpFunction(f, p, D)
- local source = f.source
- if source == p or D.strip then source = nil end
- self:DumpString(source, D)
- self:DumpInt(f.lineDefined, D)
- self:DumpInt(f.lastlinedefined, D)
- self:DumpChar(f.nups, D)
- self:DumpChar(f.numparams, D)
- self:DumpChar(f.is_vararg, D)
- self:DumpChar(f.maxstacksize, D)
- self:DumpCode(f, D)
- self:DumpConstants(f, D)
- self:DumpDebug(f, D)
- end
- ------------------------------------------------------------------------
- -- dump Lua header section (some sizes hard-coded)
- ------------------------------------------------------------------------
- function luaU:DumpHeader(D)
- local h = self:header()
- assert(#h == self.LUAC_HEADERSIZE) -- fixed buffer now an assert
- self:DumpBlock(h, D)
- end
- ------------------------------------------------------------------------
- -- make header (from lundump.c)
- -- returns the header string
- ------------------------------------------------------------------------
- function luaU:header()
- local x = 1
- return self.LUA_SIGNATURE..
- string.char(
- self.LUAC_VERSION,
- self.LUAC_FORMAT,
- x, -- endianness (1=little)
- 4, -- sizeof(int)
- 4, -- sizeof(size_t)
- 4, -- sizeof(Instruction)
- 8, -- sizeof(lua_Number)
- 0) -- is lua_Number integral?
- end
- ------------------------------------------------------------------------
- -- dump Lua function as precompiled chunk
- -- (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
- -- * w, data are created from make_setS, make_setF
- ------------------------------------------------------------------------
- function luaU:dump(L, f, w, data, strip)
- local D = {} -- DumpState
- D.L = L
- D.write = w
- D.data = data
- D.strip = strip
- D.status = 0
- self:DumpHeader(D)
- self:DumpFunction(f, nil, D)
- -- added: for a chunk writer writing to a file, this final call with
- -- nil data is to indicate to the writer to close the file
- D.write(nil, D.data)
- return D.status
- end
- local luaUfunc = luaU
- --[[--------------------------------------------------------------------
- lparser.lua
- Lua 5 parser in Lua
- This file is part of Yueliang.
- Copyright (c) 2005-2007 Kein-Hong Man <khman@users.sf.net>
- The COPYRIGHT file describes the conditions
- under which this software may be distributed.
- See the ChangeLog for more information.
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- Notes:
- -- * some unused C code that were not converted are kept as comments
- -- * LUA_COMPAT_VARARG option changed into a comment block
- -- * for value/size specific code added, look for 'NOTE: '
- --
- -- Not implemented:
- -- * luaX_newstring not needed by this Lua implementation
- -- * luaG_checkcode() in assert is not currently implemented
- --
- -- Added:
- -- * some constants added from various header files
- -- * luaY.LUA_QS used in error_expected, check_match (from luaconf.h)
- -- * luaY:LUA_QL needed for error messages (from luaconf.h)
- -- * luaY:growvector (from lmem.h) -- skeleton only, limit checking
- -- * luaY.SHRT_MAX (from <limits.h>) for registerlocalvar
- -- * luaY:newproto (from lfunc.c)
- -- * luaY:int2fb (from lobject.c)
- -- * NOTE: HASARG_MASK, for implementing a VARARG_HASARG bit operation
- -- * NOTE: value-specific code for VARARG_NEEDSARG to replace a bitop
- --
- -- Changed in 5.1.x:
- -- * various code changes are not detailed...
- -- * names of constants may have changed, e.g. added a LUAI_ prefix
- -- * struct expkind: added VKNUM, VVARARG; VCALL's info changed?
- -- * struct expdesc: added nval
- -- * struct FuncState: upvalues data type changed to upvaldesc
- -- * macro hasmultret is new
- -- * function checklimit moved to parser from lexer
- -- * functions anchor_token, errorlimit, checknext are new
- -- * checknext is new, equivalent to 5.0.x's check, see check too
- -- * luaY:next and luaY:lookahead moved to lexer
- -- * break keyword no longer skipped in luaY:breakstat
- -- * function new_localvarstr replaced by new_localvarliteral
- -- * registerlocalvar limits local variables to SHRT_MAX
- -- * create_local deleted, new_localvarliteral used instead
- -- * constant LUAI_MAXUPVALUES increased to 60
- -- * constants MAXPARAMS, LUA_MAXPARSERLEVEL, MAXSTACK removed
- -- * function interface changed: singlevaraux, singlevar
- -- * enterlevel and leavelevel uses nCcalls to track call depth
- -- * added a name argument to main entry function, luaY:parser
- -- * function luaY_index changed to yindex
- -- * luaY:int2fb()'s table size encoding format has been changed
- -- * luaY:log2() no longer needed for table constructors
- -- * function code_params deleted, functionality folded in parlist
- -- * vararg flags handling (is_vararg) changes; also see VARARG_*
- -- * LUA_COMPATUPSYNTAX section for old-style upvalues removed
- -- * repeatstat() calls chunk() instead of block()
- -- * function interface changed: cond, test_then_block
- -- * while statement implementation considerably simplified; MAXEXPWHILE
- -- and EXTRAEXP no longer required, no limits to the complexity of a
- -- while condition
- -- * repeat, forbody statement implementation has major changes,
- -- mostly due to new scoping behaviour of local variables
- -- * OPR_MULT renamed to OPR_MUL
- ----------------------------------------------------------------------]]
- --requires luaP, luaX, luaK
- local luaY = {}
- local luaX = luaXfunc
- local luaK = luaKfunc(luaY)
- local luaP = luaPfunc
- --[[--------------------------------------------------------------------
- -- Expression descriptor
- -- * expkind changed to string constants; luaY:assignment was the only
- -- function to use a relational operator with this enumeration
- -- VVOID -- no value
- -- VNIL -- no value
- -- VTRUE -- no value
- -- VFALSE -- no value
- -- VK -- info = index of constant in 'k'
- -- VKNUM -- nval = numerical value
- -- VLOCAL -- info = local register
- -- VUPVAL, -- info = index of upvalue in 'upvalues'
- -- VGLOBAL -- info = index of table; aux = index of global name in 'k'
- -- VINDEXED -- info = table register; aux = index register (or 'k')
- -- VJMP -- info = instruction pc
- -- VRELOCABLE -- info = instruction pc
- -- VNONRELOC -- info = result register
- -- VCALL -- info = instruction pc
- -- VVARARG -- info = instruction pc
- } ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- * expdesc in Lua 5.1.x has a union u and another struct s; this Lua
- -- implementation ignores all instances of u and s usage
- -- struct expdesc:
- -- k -- (enum: expkind)
- -- info, aux -- (int, int)
- -- nval -- (lua_Number)
- -- t -- patch list of 'exit when true'
- -- f -- patch list of 'exit when false'
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- struct upvaldesc:
- -- k -- (lu_byte)
- -- info -- (lu_byte)
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- state needed to generate code for a given function
- -- struct FuncState:
- -- f -- current function header (table: Proto)
- -- h -- table to find (and reuse) elements in 'k' (table: Table)
- -- prev -- enclosing function (table: FuncState)
- -- ls -- lexical state (table: LexState)
- -- L -- copy of the Lua state (table: lua_State)
- -- bl -- chain of current blocks (table: BlockCnt)
- -- pc -- next position to code (equivalent to 'ncode')
- -- lasttarget -- 'pc' of last 'jump target'
- -- jpc -- list of pending jumps to 'pc'
- -- freereg -- first free register
- -- nk -- number of elements in 'k'
- -- np -- number of elements in 'p'
- -- nlocvars -- number of elements in 'locvars'
- -- nactvar -- number of active local variables
- -- upvalues[LUAI_MAXUPVALUES] -- upvalues (table: upvaldesc)
- -- actvar[LUAI_MAXVARS] -- declared-variable stack
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- constants used by parser
- -- * picks up duplicate values from luaX if required
- ------------------------------------------------------------------------
- luaY.LUA_QS = luaX.LUA_QS or "'%s'" -- (from luaconf.h)
- luaY.SHRT_MAX = 32767 -- (from <limits.h>)
- luaY.LUAI_MAXVARS = 200 -- (luaconf.h)
- luaY.LUAI_MAXUPVALUES = 60 -- (luaconf.h)
- luaY.MAX_INT = luaX.MAX_INT or 2147483645 -- (from llimits.h)
- -- * INT_MAX-2 for 32-bit systems
- luaY.LUAI_MAXCCALLS = 200 -- (from luaconf.h)
- luaY.VARARG_HASARG = 1 -- (from lobject.h)
- -- NOTE: HASARG_MASK is value-specific
- luaY.HASARG_MASK = 2 -- this was added for a bitop in parlist()
- luaY.VARARG_ISVARARG = 2
- -- NOTE: there is some value-specific code that involves VARARG_NEEDSARG
- luaY.VARARG_NEEDSARG = 4
- luaY.LUA_MULTRET = -1 -- (lua.h)
- --[[--------------------------------------------------------------------
- -- other functions
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- LUA_QL describes how error messages quote program elements.
- -- CHANGE it if you want a different appearance. (from luaconf.h)
- ------------------------------------------------------------------------
- function luaY:LUA_QL(x)
- return "'"..x.."'"
- end
- ------------------------------------------------------------------------
- -- this is a stripped-down luaM_growvector (from lmem.h) which is a
- -- macro based on luaM_growaux (in lmem.c); all the following does is
- -- reproduce the size limit checking logic of the original function
- -- so that error behaviour is identical; all arguments preserved for
- -- convenience, even those which are unused
- -- * set the t field to nil, since this originally does a sizeof(t)
- -- * size (originally a pointer) is never updated, their final values
- -- are set by luaY:close_func(), so overall things should still work
- ------------------------------------------------------------------------
- function luaY:growvector(L, v, nelems, size, t, limit, e)
- if nelems >= limit then
- error(e) -- was luaG_runerror
- end
- end
- ------------------------------------------------------------------------
- -- initialize a new function prototype structure (from lfunc.c)
- -- * used only in open_func()
- ------------------------------------------------------------------------
- function luaY:newproto(L)
- local f = {} -- Proto
- -- luaC_link(L, obj2gco(f), LUA_TPROTO); /* GC */
- f.k = {}
- f.sizek = 0
- f.p = {}
- f.sizep = 0
- f.code = {}
- f.sizecode = 0
- f.sizelineinfo = 0
- f.sizeupvalues = 0
- f.nups = 0
- f.upvalues = {}
- f.numparams = 0
- f.is_vararg = 0
- f.maxstacksize = 0
- f.lineinfo = {}
- f.sizelocvars = 0
- f.locvars = {}
- f.lineDefined = 0
- f.lastlinedefined = 0
- f.source = nil
- return f
- end
- ------------------------------------------------------------------------
- -- converts an integer to a "floating point byte", represented as
- -- (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
- -- eeeee != 0 and (xxx) otherwise.
- ------------------------------------------------------------------------
- function luaY:int2fb(x)
- local e = 0 -- exponent
- while x >= 16 do
- x = math.floor((x + 1) / 2)
- e = e + 1
- end
- if x < 8 then
- return x
- else
- return ((e + 1) * 8) + (x - 8)
- end
- end
- --[[--------------------------------------------------------------------
- -- parser functions
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- true of the kind of expression produces multiple return values
- ------------------------------------------------------------------------
- function luaY:hasmultret(k)
- return k == "VCALL" or k == "VVARARG"
- end
- ------------------------------------------------------------------------
- -- convenience function to access active local i, returns entry
- ------------------------------------------------------------------------
- function luaY:getlocvar(fs, i)
- return fs.f.locvars[ fs.actvar[i] ]
- end
- ------------------------------------------------------------------------
- -- check a limit, string m provided as an error message
- ------------------------------------------------------------------------
- function luaY:checklimit(fs, v, l, m)
- if v > l then self:errorlimit(fs, l, m) end
- end
- --[[--------------------------------------------------------------------
- -- nodes for block list (list of active blocks)
- -- struct BlockCnt:
- -- previous -- chain (table: BlockCnt)
- -- breaklist -- list of jumps out of this loop
- -- nactvar -- # active local variables outside the breakable structure
- -- upval -- true if some variable in the block is an upvalue (boolean)
- -- isbreakable -- true if 'block' is a loop (boolean)
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- prototypes for recursive non-terminal functions
- ------------------------------------------------------------------------
- -- prototypes deleted; not required in Lua
- ------------------------------------------------------------------------
- -- reanchor if last token is has a constant string, see close_func()
- -- * used only in close_func()
- ------------------------------------------------------------------------
- function luaY:anchor_token(ls)
- if ls.t.token == "TK_NAME" or ls.t.token == "TK_STRING" then
- -- not relevant to Lua implementation of parser
- -- local ts = ls.t.seminfo
- -- luaX_newstring(ls, getstr(ts), ts->tsv.len); /* C */
- end
- end
- ------------------------------------------------------------------------
- -- throws a syntax error if token expected is not there
- ------------------------------------------------------------------------
- function luaY:error_expected(ls, token)
- luaX:syntaxerror(ls,
- string.format(self.LUA_QS.." expected", luaX:token2str(ls, token)))
- end
- ------------------------------------------------------------------------
- -- prepares error message for display, for limits exceeded
- -- * used only in checklimit()
- ------------------------------------------------------------------------
- function luaY:errorlimit(fs, limit, what)
- local msg = (fs.f.linedefined == 0) and
- string.format("main function has more than %d %s", limit, what) or
- string.format("function at line %d has more than %d %s",
- fs.f.linedefined, limit, what)
- luaX:lexerror(fs.ls, msg, 0)
- end
- ------------------------------------------------------------------------
- -- tests for a token, returns outcome
- -- * return value changed to boolean
- ------------------------------------------------------------------------
- function luaY:testnext(ls, c)
- if ls.t.token == c then
- luaX:next(ls)
- return true
- else
- return false
- end
- end
- ------------------------------------------------------------------------
- -- check for existence of a token, throws error if not found
- ------------------------------------------------------------------------
- function luaY:check(ls, c)
- if ls.t.token ~= c then
- self:error_expected(ls, c)
- end
- end
- ------------------------------------------------------------------------
- -- verify existence of a token, then skip it
- ------------------------------------------------------------------------
- function luaY:checknext(ls, c)
- self:check(ls, c)
- luaX:next(ls)
- end
- ------------------------------------------------------------------------
- -- throws error if condition not matched
- ------------------------------------------------------------------------
- function luaY:check_condition(ls, c, msg)
- if not c then luaX:syntaxerror(ls, msg) end
- end
- ------------------------------------------------------------------------
- -- verifies token conditions are met or else throw error
- ------------------------------------------------------------------------
- function luaY:check_match(ls, what, who, where)
- if not self:testnext(ls, what) then
- if where == ls.linenumber then
- self:error_expected(ls, what)
- else
- luaX:syntaxerror(ls, string.format(
- self.LUA_QS.." expected (to close "..self.LUA_QS.." at line %d)",
- luaX:token2str(ls, what), luaX:token2str(ls, who), where))
- end
- end
- end
- ------------------------------------------------------------------------
- -- expect that token is a name, return the name
- ------------------------------------------------------------------------
- function luaY:str_checkname(ls)
- self:check(ls, "TK_NAME")
- local ts = ls.t.seminfo
- luaX:next(ls)
- return ts
- end
- ------------------------------------------------------------------------
- -- initialize a struct expdesc, expression description data structure
- ------------------------------------------------------------------------
- function luaY:init_exp(e, k, i)
- e.f, e.t = luaK.NO_JUMP, luaK.NO_JUMP
- e.k = k
- e.info = i
- end
- ------------------------------------------------------------------------
- -- adds given string s in string pool, sets e as VK
- ------------------------------------------------------------------------
- function luaY:codestring(ls, e, s)
- self:init_exp(e, "VK", luaK:stringK(ls.fs, s))
- end
- ------------------------------------------------------------------------
- -- consume a name token, adds it to string pool, sets e as VK
- ------------------------------------------------------------------------
- function luaY:checkname(ls, e)
- self:codestring(ls, e, self:str_checkname(ls))
- end
- ------------------------------------------------------------------------
- -- creates struct entry for a local variable
- -- * used only in new_localvar()
- ------------------------------------------------------------------------
- function luaY:registerlocalvar(ls, varname)
- local fs = ls.fs
- local f = fs.f
- self:growvector(ls.L, f.locvars, fs.nlocvars, f.sizelocvars,
- nil, self.SHRT_MAX, "too many local variables")
- -- loop to initialize empty f.locvar positions not required
- f.locvars[fs.nlocvars] = {} -- LocVar
- f.locvars[fs.nlocvars].varname = varname
- -- luaC_objbarrier(ls.L, f, varname) /* GC */
- local nlocvars = fs.nlocvars
- fs.nlocvars = fs.nlocvars + 1
- return nlocvars
- end
- ------------------------------------------------------------------------
- -- creates a new local variable given a name and an offset from nactvar
- -- * used in fornum(), forlist(), parlist(), body()
- ------------------------------------------------------------------------
- function luaY:new_localvarliteral(ls, v, n)
- self:new_localvar(ls, v, n)
- end
- ------------------------------------------------------------------------
- -- register a local variable, set in active variable list
- ------------------------------------------------------------------------
- function luaY:new_localvar(ls, name, n)
- local fs = ls.fs
- self:checklimit(fs, fs.nactvar + n + 1, self.LUAI_MAXVARS, "local variables")
- fs.actvar[fs.nactvar + n] = self:registerlocalvar(ls, name)
- end
- ------------------------------------------------------------------------
- -- adds nvars number of new local variables, set debug information
- ------------------------------------------------------------------------
- function luaY:adjustlocalvars(ls, nvars)
- local fs = ls.fs
- fs.nactvar = fs.nactvar + nvars
- for i = nvars, 1, -1 do
- self:getlocvar(fs, fs.nactvar - i).startpc = fs.pc
- end
- end
- ------------------------------------------------------------------------
- -- removes a number of locals, set debug information
- ------------------------------------------------------------------------
- function luaY:removevars(ls, tolevel)
- local fs = ls.fs
- while fs.nactvar > tolevel do
- fs.nactvar = fs.nactvar - 1
- self:getlocvar(fs, fs.nactvar).endpc = fs.pc
- end
- end
- ------------------------------------------------------------------------
- -- returns an existing upvalue index based on the given name, or
- -- creates a new upvalue struct entry and returns the new index
- -- * used only in singlevaraux()
- ------------------------------------------------------------------------
- function luaY:indexupvalue(fs, name, v)
- local f = fs.f
- for i = 0, f.nups - 1 do
- if fs.upvalues[i].k == v.k and fs.upvalues[i].info == v.info then
- assert(f.upvalues[i] == name)
- return i
- end
- end
- -- new one
- self:checklimit(fs, f.nups + 1, self.LUAI_MAXUPVALUES, "upvalues")
- self:growvector(fs.L, f.upvalues, f.nups, f.sizeupvalues,
- nil, self.MAX_INT, "")
- -- loop to initialize empty f.upvalues positions not required
- f.upvalues[f.nups] = name
- -- luaC_objbarrier(fs->L, f, name); /* GC */
- assert(v.k == "VLOCAL" or v.k == "VUPVAL")
- -- this is a partial copy; only k & info fields used
- fs.upvalues[f.nups] = { k = v.k, info = v.info }
- local nups = f.nups
- f.nups = f.nups + 1
- return nups
- end
- ------------------------------------------------------------------------
- -- search the local variable namespace of the given fs for a match
- -- * used only in singlevaraux()
- ------------------------------------------------------------------------
- function luaY:searchvar(fs, n)
- for i = fs.nactvar - 1, 0, -1 do
- if n == self:getlocvar(fs, i).varname then
- return i
- end
- end
- return -1 -- not found
- end
- ------------------------------------------------------------------------
- -- * mark upvalue flags in function states up to a given level
- -- * used only in singlevaraux()
- ------------------------------------------------------------------------
- function luaY:markupval(fs, level)
- local bl = fs.bl
- while bl and bl.nactvar > level do bl = bl.previous end
- if bl then bl.upval = true end
- end
- ------------------------------------------------------------------------
- -- handle locals, globals and upvalues and related processing
- -- * search mechanism is recursive, calls itself to search parents
- -- * used only in singlevar()
- ------------------------------------------------------------------------
- function luaY:singlevaraux(fs, n, var, base)
- if fs == nil then -- no more levels?
- self:init_exp(var, "VGLOBAL", luaP.NO_REG) -- default is global variable
- return "VGLOBAL"
- else
- local v = self:searchvar(fs, n) -- look up at current level
- if v >= 0 then
- self:init_exp(var, "VLOCAL", v)
- if base == 0 then
- self:markupval(fs, v) -- local will be used as an upval
- end
- return "VLOCAL"
- else -- not found at current level; try upper one
- if self:singlevaraux(fs.prev, n, var, 0) == "VGLOBAL" then
- return "VGLOBAL"
- end
- var.info = self:indexupvalue(fs, n, var) -- else was LOCAL or UPVAL
- var.k = "VUPVAL" -- upvalue in this level
- return "VUPVAL"
- end--if v
- end--if fs
- end
- ------------------------------------------------------------------------
- -- consume a name token, creates a variable (global|local|upvalue)
- -- * used in prefixexp(), funcname()
- ------------------------------------------------------------------------
- function luaY:singlevar(ls, var)
- local varname = self:str_checkname(ls)
- local fs = ls.fs
- if self:singlevaraux(fs, varname, var, 1) == "VGLOBAL" then
- var.info = luaK:stringK(fs, varname) -- info points to global name
- end
- end
- ------------------------------------------------------------------------
- -- adjust RHS to match LHS in an assignment
- -- * used in assignment(), forlist(), localstat()
- ------------------------------------------------------------------------
- function luaY:adjust_assign(ls, nvars, nexps, e)
- local fs = ls.fs
- local extra = nvars - nexps
- if self:hasmultret(e.k) then
- extra = extra + 1 -- includes call itself
- if extra <= 0 then extra = 0 end
- luaK:setreturns(fs, e, extra) -- last exp. provides the difference
- if extra > 1 then luaK:reserveregs(fs, extra - 1) end
- else
- if e.k ~= "VVOID" then luaK:exp2nextreg(fs, e) end -- close last expression
- if extra > 0 then
- local reg = fs.freereg
- luaK:reserveregs(fs, extra)
- luaK:_nil(fs, reg, extra)
- end
- end
- end
- ------------------------------------------------------------------------
- -- tracks and limits parsing depth, assert check at end of parsing
- ------------------------------------------------------------------------
- function luaY:enterlevel(ls)
- ls.L.nCcalls = ls.L.nCcalls + 1
- if ls.L.nCcalls > self.LUAI_MAXCCALLS then
- luaX:lexerror(ls, "chunk has too many syntax levels", 0)
- end
- end
- ------------------------------------------------------------------------
- -- tracks parsing depth, a pair with luaY:enterlevel()
- ------------------------------------------------------------------------
- function luaY:leavelevel(ls)
- ls.L.nCcalls = ls.L.nCcalls - 1
- end
- ------------------------------------------------------------------------
- -- enters a code unit, initializes elements
- ------------------------------------------------------------------------
- function luaY:enterblock(fs, bl, isbreakable)
- bl.breaklist = luaK.NO_JUMP
- bl.isbreakable = isbreakable
- bl.nactvar = fs.nactvar
- bl.upval = false
- bl.previous = fs.bl
- fs.bl = bl
- assert(fs.freereg == fs.nactvar)
- end
- ------------------------------------------------------------------------
- -- leaves a code unit, close any upvalues
- ------------------------------------------------------------------------
- function luaY:leaveblock(fs)
- local bl = fs.bl
- fs.bl = bl.previous
- self:removevars(fs.ls, bl.nactvar)
- if bl.upval then
- luaK:codeABC(fs, "OP_CLOSE", bl.nactvar, 0, 0)
- end
- -- a block either controls scope or breaks (never both)
- assert(not bl.isbreakable or not bl.upval)
- assert(bl.nactvar == fs.nactvar)
- fs.freereg = fs.nactvar -- free registers
- luaK:patchtohere(fs, bl.breaklist)
- end
- ------------------------------------------------------------------------
- -- implement the instantiation of a function prototype, append list of
- -- upvalues after the instantiation instruction
- -- * used only in body()
- ------------------------------------------------------------------------
- function luaY:pushclosure(ls, func, v)
- local fs = ls.fs
- local f = fs.f
- self:growvector(ls.L, f.p, fs.np, f.sizep, nil,
- luaP.MAXARG_Bx, "constant table overflow")
- -- loop to initialize empty f.p positions not required
- f.p[fs.np] = func.f
- fs.np = fs.np + 1
- -- luaC_objbarrier(ls->L, f, func->f); /* C */
- self:init_exp(v, "VRELOCABLE", luaK:codeABx(fs, "OP_CLOSURE", 0, fs.np - 1))
- for i = 0, func.f.nups - 1 do
- local o = (func.upvalues[i].k == "VLOCAL") and "OP_MOVE" or "OP_GETUPVAL"
- luaK:codeABC(fs, o, 0, func.upvalues[i].info, 0)
- end
- end
- ------------------------------------------------------------------------
- -- opening of a function
- ------------------------------------------------------------------------
- function luaY:open_func(ls, fs)
- local L = ls.L
- local f = self:newproto(ls.L)
- fs.f = f
- fs.prev = ls.fs -- linked list of funcstates
- fs.ls = ls
- fs.L = L
- ls.fs = fs
- fs.pc = 0
- fs.lasttarget = -1
- fs.jpc = luaK.NO_JUMP
- fs.freereg = 0
- fs.nk = 0
- fs.np = 0
- fs.nlocvars = 0
- fs.nactvar = 0
- fs.bl = nil
- f.source = ls.source
- f.maxstacksize = 2 -- registers 0/1 are always valid
- fs.h = {} -- constant table; was luaH_new call
- -- anchor table of constants and prototype (to avoid being collected)
- -- sethvalue2s(L, L->top, fs->h); incr_top(L); /* C */
- -- setptvalue2s(L, L->top, f); incr_top(L);
- end
- ------------------------------------------------------------------------
- -- closing of a function
- ------------------------------------------------------------------------
- function luaY:close_func(ls)
- local L = ls.L
- local fs = ls.fs
- local f = fs.f
- self:removevars(ls, 0)
- luaK:ret(fs, 0, 0) -- final return
- -- luaM_reallocvector deleted for f->code, f->lineinfo, f->k, f->p,
- -- f->locvars, f->upvalues; not required for Lua table arrays
- f.sizecode = fs.pc
- f.sizelineinfo = fs.pc
- f.sizek = fs.nk
- f.sizep = fs.np
- f.sizelocvars = fs.nlocvars
- f.sizeupvalues = f.nups
- --assert(luaG_checkcode(f)) -- currently not implemented
- assert(fs.bl == nil)
- ls.fs = fs.prev
- -- the following is not required for this implementation; kept here
- -- for completeness
- -- L->top -= 2; /* remove table and prototype from the stack */
- -- last token read was anchored in defunct function; must reanchor it
- if fs then self:anchor_token(ls) end
- end
- ------------------------------------------------------------------------
- -- parser initialization function
- -- * note additional sub-tables needed for LexState, FuncState
- ------------------------------------------------------------------------
- function luaY:parser(L, z, buff, name)
- local lexstate = {} -- LexState
- lexstate.t = {}
- lexstate.lookahead = {}
- local funcstate = {} -- FuncState
- funcstate.upvalues = {}
- funcstate.actvar = {}
- -- the following nCcalls initialization added for convenience
- L.nCcalls = 0
- lexstate.buff = buff
- luaX:setinput(L, lexstate, z, name)
- self:open_func(lexstate, funcstate)
- funcstate.f.is_vararg = self.VARARG_ISVARARG -- main func. is always vararg
- luaX:next(lexstate) -- read first token
- self:chunk(lexstate)
- self:check(lexstate, "TK_EOS")
- self:close_func(lexstate)
- assert(funcstate.prev == nil)
- assert(funcstate.f.nups == 0)
- assert(lexstate.fs == nil)
- return funcstate.f
- end
- --[[--------------------------------------------------------------------
- -- GRAMMAR RULES
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- parse a function name suffix, for function call specifications
- -- * used in primaryexp(), funcname()
- ------------------------------------------------------------------------
- function luaY:field(ls, v)
- -- field -> ['.' | ':'] NAME
- local fs = ls.fs
- local key = {} -- expdesc
- luaK:exp2anyreg(fs, v)
- luaX:next(ls) -- skip the dot or colon
- self:checkname(ls, key)
- luaK:indexed(fs, v, key)
- end
- ------------------------------------------------------------------------
- -- parse a table indexing suffix, for constructors, expressions
- -- * used in recfield(), primaryexp()
- ------------------------------------------------------------------------
- function luaY:yindex(ls, v)
- -- index -> '[' expr ']'
- luaX:next(ls) -- skip the '['
- self:expr(ls, v)
- luaK:exp2val(ls.fs, v)
- self:checknext(ls, "]")
- end
- --[[--------------------------------------------------------------------
- -- Rules for Constructors
- ----------------------------------------------------------------------]]
- --[[--------------------------------------------------------------------
- -- struct ConsControl:
- -- v -- last list item read (table: struct expdesc)
- -- t -- table descriptor (table: struct expdesc)
- -- nh -- total number of 'record' elements
- -- na -- total number of array elements
- -- tostore -- number of array elements pending to be stored
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- parse a table record (hash) field
- -- * used in constructor()
- ------------------------------------------------------------------------
- function luaY:recfield(ls, cc)
- -- recfield -> (NAME | '['exp1']') = exp1
- local fs = ls.fs
- local reg = ls.fs.freereg
- local key, val = {}, {} -- expdesc
- if ls.t.token == "TK_NAME" then
- self:checklimit(fs, cc.nh, self.MAX_INT, "items in a constructor")
- self:checkname(ls, key)
- else -- ls->t.token == '['
- self:yindex(ls, key)
- end
- cc.nh = cc.nh + 1
- self:checknext(ls, "=")
- local rkkey = luaK:exp2RK(fs, key)
- self:expr(ls, val)
- luaK:codeABC(fs, "OP_SETTABLE", cc.t.info, rkkey, luaK:exp2RK(fs, val))
- fs.freereg = reg -- free registers
- end
- ------------------------------------------------------------------------
- -- emit a set list instruction if enough elements (LFIELDS_PER_FLUSH)
- -- * used in constructor()
- ------------------------------------------------------------------------
- function luaY:closelistfield(fs, cc)
- if cc.v.k == "VVOID" then return end -- there is no list item
- luaK:exp2nextreg(fs, cc.v)
- cc.v.k = "VVOID"
- if cc.tostore == luaP.LFIELDS_PER_FLUSH then
- luaK:setlist(fs, cc.t.info, cc.na, cc.tostore) -- flush
- cc.tostore = 0 -- no more items pending
- end
- end
- ------------------------------------------------------------------------
- -- emit a set list instruction at the end of parsing list constructor
- -- * used in constructor()
- ------------------------------------------------------------------------
- function luaY:lastlistfield(fs, cc)
- if cc.tostore == 0 then return end
- if self:hasmultret(cc.v.k) then
- luaK:setmultret(fs, cc.v)
- luaK:setlist(fs, cc.t.info, cc.na, self.LUA_MULTRET)
- cc.na = cc.na - 1 -- do not count last expression (unknown number of elements)
- else
- if cc.v.k ~= "VVOID" then
- luaK:exp2nextreg(fs, cc.v)
- end
- luaK:setlist(fs, cc.t.info, cc.na, cc.tostore)
- end
- end
- ------------------------------------------------------------------------
- -- parse a table list (array) field
- -- * used in constructor()
- ------------------------------------------------------------------------
- function luaY:listfield(ls, cc)
- self:expr(ls, cc.v)
- self:checklimit(ls.fs, cc.na, self.MAX_INT, "items in a constructor")
- cc.na = cc.na + 1
- cc.tostore = cc.tostore + 1
- end
- ------------------------------------------------------------------------
- -- parse a table constructor
- -- * used in funcargs(), simpleexp()
- ------------------------------------------------------------------------
- function luaY:constructor(ls, t)
- -- constructor -> '{' [ field { fieldsep field } [ fieldsep ] ] '}'
- -- field -> recfield | listfield
- -- fieldsep -> ',' | ';'
- local fs = ls.fs
- local line = ls.linenumber
- local pc = luaK:codeABC(fs, "OP_NEWTABLE", 0, 0, 0)
- local cc = {} -- ConsControl
- cc.v = {}
- cc.na, cc.nh, cc.tostore = 0, 0, 0
- cc.t = t
- self:init_exp(t, "VRELOCABLE", pc)
- self:init_exp(cc.v, "VVOID", 0) -- no value (yet)
- luaK:exp2nextreg(ls.fs, t) -- fix it at stack top (for gc)
- self:checknext(ls, "{")
- repeat
- assert(cc.v.k == "VVOID" or cc.tostore > 0)
- if ls.t.token == "}" then break end
- self:closelistfield(fs, cc)
- local c = ls.t.token
- if c == "TK_NAME" then -- may be listfields or recfields
- luaX:lookahead(ls)
- if ls.lookahead.token ~= "=" then -- expression?
- self:listfield(ls, cc)
- else
- self:recfield(ls, cc)
- end
- elseif c == "[" then -- constructor_item -> recfield
- self:recfield(ls, cc)
- else -- constructor_part -> listfield
- self:listfield(ls, cc)
- end
- until not self:testnext(ls, ",") and not self:testnext(ls, ";")
- self:check_match(ls, "}", "{", line)
- self:lastlistfield(fs, cc)
- luaP:SETARG_B(fs.f.code[pc], self:int2fb(cc.na)) -- set initial array size
- luaP:SETARG_C(fs.f.code[pc], self:int2fb(cc.nh)) -- set initial table size
- end
- -- }======================================================================
- ------------------------------------------------------------------------
- -- parse the arguments (parameters) of a function declaration
- -- * used in body()
- ------------------------------------------------------------------------
- function luaY:parlist(ls)
- -- parlist -> [ param { ',' param } ]
- local fs = ls.fs
- local f = fs.f
- local nparams = 0
- f.is_vararg = 0
- if ls.t.token ~= ")" then -- is 'parlist' not empty?
- repeat
- local c = ls.t.token
- if c == "TK_NAME" then -- param -> NAME
- self:new_localvar(ls, self:str_checkname(ls), nparams)
- nparams = nparams + 1
- elseif c == "TK_DOTS" then -- param -> `...'
- luaX:next(ls)
- -- [[
- -- #if defined(LUA_COMPAT_VARARG)
- -- use `arg' as default name
- self:new_localvarliteral(ls, "arg", nparams)
- nparams = nparams + 1
- f.is_vararg = self.VARARG_HASARG + self.VARARG_NEEDSARG
- -- #endif
- --]]
- f.is_vararg = f.is_vararg + self.VARARG_ISVARARG
- else
- luaX:syntaxerror(ls, "<name> or "..self:LUA_QL("...").." expected")
- end
- until f.is_vararg ~= 0 or not self:testnext(ls, ",")
- end--if
- self:adjustlocalvars(ls, nparams)
- -- NOTE: the following works only when HASARG_MASK is 2!
- f.numparams = fs.nactvar - (f.is_vararg % self.HASARG_MASK)
- luaK:reserveregs(fs, fs.nactvar) -- reserve register for parameters
- end
- ------------------------------------------------------------------------
- -- parse function declaration body
- -- * used in simpleexp(), localfunc(), funcstat()
- ------------------------------------------------------------------------
- function luaY:body(ls, e, needself, line)
- -- body -> '(' parlist ')' chunk END
- local new_fs = {} -- FuncState
- new_fs.upvalues = {}
- new_fs.actvar = {}
- self:open_func(ls, new_fs)
- new_fs.f.lineDefined = line
- self:checknext(ls, "(")
- if needself then
- self:new_localvarliteral(ls, "self", 0)
- self:adjustlocalvars(ls, 1)
- end
- self:parlist(ls)
- self:checknext(ls, ")")
- self:chunk(ls)
- new_fs.f.lastlinedefined = ls.linenumber
- self:check_match(ls, "TK_END", "TK_FUNCTION", line)
- self:close_func(ls)
- self:pushclosure(ls, new_fs, e)
- end
- ------------------------------------------------------------------------
- -- parse a list of comma-separated expressions
- -- * used is multiple locations
- ------------------------------------------------------------------------
- function luaY:explist1(ls, v)
- -- explist1 -> expr { ',' expr }
- local n = 1 -- at least one expression
- self:expr(ls, v)
- while self:testnext(ls, ",") do
- luaK:exp2nextreg(ls.fs, v)
- self:expr(ls, v)
- n = n + 1
- end
- return n
- end
- ------------------------------------------------------------------------
- -- parse the parameters of a function call
- -- * contrast with parlist(), used in function declarations
- -- * used in primaryexp()
- ------------------------------------------------------------------------
- function luaY:funcargs(ls, f)
- local fs = ls.fs
- local args = {} -- expdesc
- local nparams
- local line = ls.linenumber
- local c = ls.t.token
- if c == "(" then -- funcargs -> '(' [ explist1 ] ')'
- if line ~= ls.lastline then
- luaX:syntaxerror(ls, "ambiguous syntax (function call x new statement)")
- end
- luaX:next(ls)
- if ls.t.token == ")" then -- arg list is empty?
- args.k = "VVOID"
- else
- self:explist1(ls, args)
- luaK:setmultret(fs, args)
- end
- self:check_match(ls, ")", "(", line)
- elseif c == "{" then -- funcargs -> constructor
- self:constructor(ls, args)
- elseif c == "TK_STRING" then -- funcargs -> STRING
- self:codestring(ls, args, ls.t.seminfo)
- luaX:next(ls) -- must use 'seminfo' before 'next'
- else
- luaX:syntaxerror(ls, "function arguments expected")
- return
- end
- assert(f.k == "VNONRELOC")
- local base = f.info -- base register for call
- if self:hasmultret(args.k) then
- nparams = self.LUA_MULTRET -- open call
- else
- if args.k ~= "VVOID" then
- luaK:exp2nextreg(fs, args) -- close last argument
- end
- nparams = fs.freereg - (base + 1)
- end
- self:init_exp(f, "VCALL", luaK:codeABC(fs, "OP_CALL", base, nparams + 1, 2))
- luaK:fixline(fs, line)
- fs.freereg = base + 1 -- call remove function and arguments and leaves
- -- (unless changed) one result
- end
- --[[--------------------------------------------------------------------
- -- Expression parsing
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- parses an expression in parentheses or a single variable
- -- * used in primaryexp()
- ------------------------------------------------------------------------
- function luaY:prefixexp(ls, v)
- -- prefixexp -> NAME | '(' expr ')'
- local c = ls.t.token
- if c == "(" then
- local line = ls.linenumber
- luaX:next(ls)
- self:expr(ls, v)
- self:check_match(ls, ")", "(", line)
- luaK:dischargevars(ls.fs, v)
- elseif c == "TK_NAME" then
- self:singlevar(ls, v)
- else
- luaX:syntaxerror(ls, "unexpected symbol")
- end--if c
- return
- end
- ------------------------------------------------------------------------
- -- parses a prefixexp (an expression in parentheses or a single variable)
- -- or a function call specification
- -- * used in simpleexp(), assignment(), exprstat()
- ------------------------------------------------------------------------
- function luaY:primaryexp(ls, v)
- -- primaryexp ->
- -- prefixexp { '.' NAME | '[' exp ']' | ':' NAME funcargs | funcargs }
- local fs = ls.fs
- self:prefixexp(ls, v)
- while true do
- local c = ls.t.token
- if c == "." then -- field
- self:field(ls, v)
- elseif c == "[" then -- '[' exp1 ']'
- local key = {} -- expdesc
- luaK:exp2anyreg(fs, v)
- self:yindex(ls, key)
- luaK:indexed(fs, v, key)
- elseif c == ":" then -- ':' NAME funcargs
- local key = {} -- expdesc
- luaX:next(ls)
- self:checkname(ls, key)
- luaK:_self(fs, v, key)
- self:funcargs(ls, v)
- elseif c == "(" or c == "TK_STRING" or c == "{" then -- funcargs
- luaK:exp2nextreg(fs, v)
- self:funcargs(ls, v)
- else
- return
- end--if c
- end--while
- end
- ------------------------------------------------------------------------
- -- parses general expression types, constants handled here
- -- * used in subexpr()
- ------------------------------------------------------------------------
- function luaY:simpleexp(ls, v)
- -- simpleexp -> NUMBER | STRING | NIL | TRUE | FALSE | ... |
- -- constructor | FUNCTION body | primaryexp
- local c = ls.t.token
- if c == "TK_NUMBER" then
- self:init_exp(v, "VKNUM", 0)
- v.nval = ls.t.seminfo
- elseif c == "TK_STRING" then
- self:codestring(ls, v, ls.t.seminfo)
- elseif c == "TK_NIL" then
- self:init_exp(v, "VNIL", 0)
- elseif c == "TK_TRUE" then
- self:init_exp(v, "VTRUE", 0)
- elseif c == "TK_FALSE" then
- self:init_exp(v, "VFALSE", 0)
- elseif c == "TK_DOTS" then -- vararg
- local fs = ls.fs
- self:check_condition(ls, fs.f.is_vararg ~= 0,
- "cannot use "..self:LUA_QL("...").." outside a vararg function");
- -- NOTE: the following substitutes for a bitop, but is value-specific
- local is_vararg = fs.f.is_vararg
- if is_vararg >= self.VARARG_NEEDSARG then
- fs.f.is_vararg = is_vararg - self.VARARG_NEEDSARG -- don't need 'arg'
- end
- self:init_exp(v, "VVARARG", luaK:codeABC(fs, "OP_VARARG", 0, 1, 0))
- elseif c == "{" then -- constructor
- self:constructor(ls, v)
- return
- elseif c == "TK_FUNCTION" then
- luaX:next(ls)
- self:body(ls, v, false, ls.linenumber)
- return
- else
- self:primaryexp(ls, v)
- return
- end--if c
- luaX:next(ls)
- end
- ------------------------------------------------------------------------
- -- Translates unary operators tokens if found, otherwise returns
- -- OPR_NOUNOPR. getunopr() and getbinopr() are used in subexpr().
- -- * used in subexpr()
- ------------------------------------------------------------------------
- function luaY:getunopr(op)
- if op == "TK_NOT" then
- return "OPR_NOT"
- elseif op == "-" then
- return "OPR_MINUS"
- elseif op == "#" then
- return "OPR_LEN"
- else
- return "OPR_NOUNOPR"
- end
- end
- ------------------------------------------------------------------------
- -- Translates binary operator tokens if found, otherwise returns
- -- OPR_NOBINOPR. Code generation uses OPR_* style tokens.
- -- * used in subexpr()
- ------------------------------------------------------------------------
- luaY.getbinopr_table = {
- ["+"] = "OPR_ADD",
- ["-"] = "OPR_SUB",
- ["*"] = "OPR_MUL",
- ["/"] = "OPR_DIV",
- ["%"] = "OPR_MOD",
- ["^"] = "OPR_POW",
- ["TK_CONCAT"] = "OPR_CONCAT",
- ["TK_NE"] = "OPR_NE",
- ["TK_EQ"] = "OPR_EQ",
- ["<"] = "OPR_LT",
- ["TK_LE"] = "OPR_LE",
- [">"] = "OPR_GT",
- ["TK_GE"] = "OPR_GE",
- ["TK_AND"] = "OPR_AND",
- ["TK_OR"] = "OPR_OR",
- }
- function luaY:getbinopr(op)
- local opr = self.getbinopr_table[op]
- if opr then return opr else return "OPR_NOBINOPR" end
- end
- ------------------------------------------------------------------------
- -- the following priority table consists of pairs of left/right values
- -- for binary operators (was a static const struct); grep for ORDER OPR
- -- * the following struct is replaced:
- -- static const struct {
- -- lu_byte left; /* left priority for each binary operator */
- -- lu_byte right; /* right priority */
- -- } priority[] = { /* ORDER OPR */
- ------------------------------------------------------------------------
- luaY.priority = {
- {6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, -- `+' `-' `/' `%'
- {10, 9}, {5, 4}, -- power and concat (right associative)
- {3, 3}, {3, 3}, -- equality
- {3, 3}, {3, 3}, {3, 3}, {3, 3}, -- order
- {2, 2}, {1, 1} -- logical (and/or)
- }
- luaY.UNARY_PRIORITY = 8 -- priority for unary operators
- ------------------------------------------------------------------------
- -- Parse subexpressions. Includes handling of unary operators and binary
- -- operators. A subexpr is given the rhs priority level of the operator
- -- immediately left of it, if any (limit is -1 if none,) and if a binop
- -- is found, limit is compared with the lhs priority level of the binop
- -- in order to determine which executes first.
- ------------------------------------------------------------------------
- ------------------------------------------------------------------------
- -- subexpr -> (simpleexp | unop subexpr) { binop subexpr }
- -- where 'binop' is any binary operator with a priority higher than 'limit'
- -- * for priority lookups with self.priority[], 1=left and 2=right
- -- * recursively called
- -- * used in expr()
- ------------------------------------------------------------------------
- function luaY:subexpr(ls, v, limit)
- self:enterlevel(ls)
- local uop = self:getunopr(ls.t.token)
- if uop ~= "OPR_NOUNOPR" then
- luaX:next(ls)
- self:subexpr(ls, v, self.UNARY_PRIORITY)
- luaK:prefix(ls.fs, uop, v)
- else
- self:simpleexp(ls, v)
- end
- -- expand while operators have priorities higher than 'limit'
- local op = self:getbinopr(ls.t.token)
- while op ~= "OPR_NOBINOPR" and self.priority[luaK.BinOpr[op] + 1][1] > limit do
- local v2 = {} -- expdesc
- luaX:next(ls)
- luaK:infix(ls.fs, op, v)
- -- read sub-expression with higher priority
- local nextop = self:subexpr(ls, v2, self.priority[luaK.BinOpr[op] + 1][2])
- luaK:posfix(ls.fs, op, v, v2)
- op = nextop
- end
- self:leavelevel(ls)
- return op -- return first untreated operator
- end
- ------------------------------------------------------------------------
- -- Expression parsing starts here. Function subexpr is entered with the
- -- left operator (which is non-existent) priority of -1, which is lower
- -- than all actual operators. Expr information is returned in parm v.
- -- * used in multiple locations
- ------------------------------------------------------------------------
- function luaY:expr(ls, v)
- self:subexpr(ls, v, 0)
- end
- -- }====================================================================
- --[[--------------------------------------------------------------------
- -- Rules for Statements
- ----------------------------------------------------------------------]]
- ------------------------------------------------------------------------
- -- checks next token, used as a look-ahead
- -- * returns boolean instead of 0|1
- -- * used in retstat(), chunk()
- ------------------------------------------------------------------------
- function luaY:block_follow(token)
- if token == "TK_ELSE" or token == "TK_ELSEIF" or token == "TK_END"
- or token == "TK_UNTIL" or token == "TK_EOS" then
- return true
- else
- return false
- end
- end
- ------------------------------------------------------------------------
- -- parse a code block or unit
- -- * used in multiple functions
- ------------------------------------------------------------------------
- function luaY:block(ls)
- -- block -> chunk
- local fs = ls.fs
- local bl = {} -- BlockCnt
- self:enterblock(fs, bl, false)
- self:chunk(ls)
- assert(bl.breaklist == luaK.NO_JUMP)
- self:leaveblock(fs)
- end
- ------------------------------------------------------------------------
- -- structure to chain all variables in the left-hand side of an
- -- assignment
- -- struct LHS_assign:
- -- prev -- (table: struct LHS_assign)
- -- v -- variable (global, local, upvalue, or indexed) (table: expdesc)
- ------------------------------------------------------------------------
- ------------------------------------------------------------------------
- -- check whether, in an assignment to a local variable, the local variable
- -- is needed in a previous assignment (to a table). If so, save original
- -- local value in a safe place and use this safe copy in the previous
- -- assignment.
- -- * used in assignment()
- ------------------------------------------------------------------------
- function luaY:check_conflict(ls, lh, v)
- local fs = ls.fs
- local extra = fs.freereg -- eventual position to save local variable
- local conflict = false
- while lh do
- if lh.v.k == "VINDEXED" then
- if lh.v.info == v.info then -- conflict?
- conflict = true
- lh.v.info = extra -- previous assignment will use safe copy
- end
- if lh.v.aux == v.info then -- conflict?
- conflict = true
- lh.v.aux = extra -- previous assignment will use safe copy
- end
- end
- lh = lh.prev
- end
- if conflict then
- luaK:codeABC(fs, "OP_MOVE", fs.freereg, v.info, 0) -- make copy
- luaK:reserveregs(fs, 1)
- end
- end
- ------------------------------------------------------------------------
- -- parse a variable assignment sequence
- -- * recursively called
- -- * used in exprstat()
- ------------------------------------------------------------------------
- function luaY:assignment(ls, lh, nvars)
- local e = {} -- expdesc
- -- test was: VLOCAL <= lh->v.k && lh->v.k <= VINDEXED
- local c = lh.v.k
- self:check_condition(ls, c == "VLOCAL" or c == "VUPVAL" or c == "VGLOBAL"
- or c == "VINDEXED", "syntax error")
- if self:testnext(ls, ",") then -- assignment -> ',' primaryexp assignment
- local nv = {} -- LHS_assign
- nv.v = {}
- nv.prev = lh
- self:primaryexp(ls, nv.v)
- if nv.v.k == "VLOCAL" then
- self:check_conflict(ls, lh, nv.v)
- end
- self:checklimit(ls.fs, nvars, self.LUAI_MAXCCALLS - ls.L.nCcalls,
- "variables in assignment")
- self:assignment(ls, nv, nvars + 1)
- else -- assignment -> '=' explist1
- self:checknext(ls, "=")
- local nexps = self:explist1(ls, e)
- if nexps ~= nvars then
- self:adjust_assign(ls, nvars, nexps, e)
- if nexps > nvars then
- ls.fs.freereg = ls.fs.freereg - (nexps - nvars) -- remove extra values
- end
- else
- luaK:setoneret(ls.fs, e) -- close last expression
- luaK:storevar(ls.fs, lh.v, e)
- return -- avoid default
- end
- end
- self:init_exp(e, "VNONRELOC", ls.fs.freereg - 1) -- default assignment
- luaK:storevar(ls.fs, lh.v, e)
- end
- ------------------------------------------------------------------------
- -- parse condition in a repeat statement or an if control structure
- -- * used in repeatstat(), test_then_block()
- ------------------------------------------------------------------------
- function luaY:cond(ls)
- -- cond -> exp
- local v = {} -- expdesc
- self:expr(ls, v) -- read condition
- if v.k == "VNIL" then v.k = "VFALSE" end -- 'falses' are all equal here
- luaK:goiftrue(ls.fs, v)
- return v.f
- end
- ------------------------------------------------------------------------
- -- parse a break statement
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:breakstat(ls)
- -- stat -> BREAK
- local fs = ls.fs
- local bl = fs.bl
- local upval = false
- while bl and not bl.isbreakable do
- if bl.upval then upval = true end
- bl = bl.previous
- end
- if not bl then
- luaX:syntaxerror(ls, "no loop to break")
- end
- if upval then
- luaK:codeABC(fs, "OP_CLOSE", bl.nactvar, 0, 0)
- end
- bl.breaklist = luaK:concat(fs, bl.breaklist, luaK:jump(fs))
- end
- ------------------------------------------------------------------------
- -- parse a while-do control structure, body processed by block()
- -- * with dynamic array sizes, MAXEXPWHILE + EXTRAEXP limits imposed by
- -- the function's implementation can be removed
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:whilestat(ls, line)
- -- whilestat -> WHILE cond DO block END
- local fs = ls.fs
- local bl = {} -- BlockCnt
- luaX:next(ls) -- skip WHILE
- local whileinit = luaK:getlabel(fs)
- local condexit = self:cond(ls)
- self:enterblock(fs, bl, true)
- self:checknext(ls, "TK_DO")
- self:block(ls)
- luaK:patchlist(fs, luaK:jump(fs), whileinit)
- self:check_match(ls, "TK_END", "TK_WHILE", line)
- self:leaveblock(fs)
- luaK:patchtohere(fs, condexit) -- false conditions finish the loop
- end
- ------------------------------------------------------------------------
- -- parse a repeat-until control structure, body parsed by chunk()
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:repeatstat(ls, line)
- -- repeatstat -> REPEAT block UNTIL cond
- local fs = ls.fs
- local repeat_init = luaK:getlabel(fs)
- local bl1, bl2 = {}, {} -- BlockCnt
- self:enterblock(fs, bl1, true) -- loop block
- self:enterblock(fs, bl2, false) -- scope block
- luaX:next(ls) -- skip REPEAT
- self:chunk(ls)
- self:check_match(ls, "TK_UNTIL", "TK_REPEAT", line)
- local condexit = self:cond(ls) -- read condition (inside scope block)
- if not bl2.upval then -- no upvalues?
- self:leaveblock(fs) -- finish scope
- luaK:patchlist(ls.fs, condexit, repeat_init) -- close the loop
- else -- complete semantics when there are upvalues
- self:breakstat(ls) -- if condition then break
- luaK:patchtohere(ls.fs, condexit) -- else...
- self:leaveblock(fs) -- finish scope...
- luaK:patchlist(ls.fs, luaK:jump(fs), repeat_init) -- and repeat
- end
- self:leaveblock(fs) -- finish loop
- end
- ------------------------------------------------------------------------
- -- parse the single expressions needed in numerical for loops
- -- * used in fornum()
- ------------------------------------------------------------------------
- function luaY:exp1(ls)
- local e = {} -- expdesc
- self:expr(ls, e)
- local k = e.k
- luaK:exp2nextreg(ls.fs, e)
- return k
- end
- ------------------------------------------------------------------------
- -- parse a for loop body for both versions of the for loop
- -- * used in fornum(), forlist()
- ------------------------------------------------------------------------
- function luaY:forbody(ls, base, line, nvars, isnum)
- -- forbody -> DO block
- local bl = {} -- BlockCnt
- local fs = ls.fs
- self:adjustlocalvars(ls, 3) -- control variables
- self:checknext(ls, "TK_DO")
- local prep = isnum and luaK:codeAsBx(fs, "OP_FORPREP", base, luaK.NO_JUMP)
- or luaK:jump(fs)
- self:enterblock(fs, bl, false) -- scope for declared variables
- self:adjustlocalvars(ls, nvars)
- luaK:reserveregs(fs, nvars)
- self:block(ls)
- self:leaveblock(fs) -- end of scope for declared variables
- luaK:patchtohere(fs, prep)
- local endfor = isnum and luaK:codeAsBx(fs, "OP_FORLOOP", base, luaK.NO_JUMP)
- or luaK:codeABC(fs, "OP_TFORLOOP", base, 0, nvars)
- luaK:fixline(fs, line) -- pretend that `OP_FOR' starts the loop
- luaK:patchlist(fs, isnum and endfor or luaK:jump(fs), prep + 1)
- end
- ------------------------------------------------------------------------
- -- parse a numerical for loop, calls forbody()
- -- * used in forstat()
- ------------------------------------------------------------------------
- function luaY:fornum(ls, varname, line)
- -- fornum -> NAME = exp1,exp1[,exp1] forbody
- local fs = ls.fs
- local base = fs.freereg
- self:new_localvarliteral(ls, "(for index)", 0)
- self:new_localvarliteral(ls, "(for limit)", 1)
- self:new_localvarliteral(ls, "(for step)", 2)
- self:new_localvar(ls, varname, 3)
- self:checknext(ls, '=')
- self:exp1(ls) -- initial value
- self:checknext(ls, ",")
- self:exp1(ls) -- limit
- if self:testnext(ls, ",") then
- self:exp1(ls) -- optional step
- else -- default step = 1
- luaK:codeABx(fs, "OP_LOADK", fs.freereg, luaK:numberK(fs, 1))
- luaK:reserveregs(fs, 1)
- end
- self:forbody(ls, base, line, 1, true)
- end
- ------------------------------------------------------------------------
- -- parse a generic for loop, calls forbody()
- -- * used in forstat()
- ------------------------------------------------------------------------
- function luaY:forlist(ls, indexname)
- -- forlist -> NAME {,NAME} IN explist1 forbody
- local fs = ls.fs
- local e = {} -- expdesc
- local nvars = 0
- local base = fs.freereg
- -- create control variables
- self:new_localvarliteral(ls, "(for generator)", nvars)
- nvars = nvars + 1
- self:new_localvarliteral(ls, "(for state)", nvars)
- nvars = nvars + 1
- self:new_localvarliteral(ls, "(for control)", nvars)
- nvars = nvars + 1
- -- create declared variables
- self:new_localvar(ls, indexname, nvars)
- nvars = nvars + 1
- while self:testnext(ls, ",") do
- self:new_localvar(ls, self:str_checkname(ls), nvars)
- nvars = nvars + 1
- end
- self:checknext(ls, "TK_IN")
- local line = ls.linenumber
- self:adjust_assign(ls, 3, self:explist1(ls, e), e)
- luaK:checkstack(fs, 3) -- extra space to call generator
- self:forbody(ls, base, line, nvars - 3, false)
- end
- ------------------------------------------------------------------------
- -- initial parsing for a for loop, calls fornum() or forlist()
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:forstat(ls, line)
- -- forstat -> FOR (fornum | forlist) END
- local fs = ls.fs
- local bl = {} -- BlockCnt
- self:enterblock(fs, bl, true) -- scope for loop and control variables
- luaX:next(ls) -- skip `for'
- local varname = self:str_checkname(ls) -- first variable name
- local c = ls.t.token
- if c == "=" then
- self:fornum(ls, varname, line)
- elseif c == "," or c == "TK_IN" then
- self:forlist(ls, varname)
- else
- luaX:syntaxerror(ls, self:LUA_QL("=").." or "..self:LUA_QL("in").." expected")
- end
- self:check_match(ls, "TK_END", "TK_FOR", line)
- self:leaveblock(fs) -- loop scope (`break' jumps to this point)
- end
- ------------------------------------------------------------------------
- -- parse part of an if control structure, including the condition
- -- * used in ifstat()
- ------------------------------------------------------------------------
- function luaY:test_then_block(ls)
- -- test_then_block -> [IF | ELSEIF] cond THEN block
- luaX:next(ls) -- skip IF or ELSEIF
- local condexit = self:cond(ls)
- self:checknext(ls, "TK_THEN")
- self:block(ls) -- `then' part
- return condexit
- end
- ------------------------------------------------------------------------
- -- parse an if control structure
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:ifstat(ls, line)
- -- ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END
- local fs = ls.fs
- local escapelist = luaK.NO_JUMP
- local flist = self:test_then_block(ls) -- IF cond THEN block
- while ls.t.token == "TK_ELSEIF" do
- escapelist = luaK:concat(fs, escapelist, luaK:jump(fs))
- luaK:patchtohere(fs, flist)
- flist = self:test_then_block(ls) -- ELSEIF cond THEN block
- end
- if ls.t.token == "TK_ELSE" then
- escapelist = luaK:concat(fs, escapelist, luaK:jump(fs))
- luaK:patchtohere(fs, flist)
- luaX:next(ls) -- skip ELSE (after patch, for correct line info)
- self:block(ls) -- 'else' part
- else
- escapelist = luaK:concat(fs, escapelist, flist)
- end
- luaK:patchtohere(fs, escapelist)
- self:check_match(ls, "TK_END", "TK_IF", line)
- end
- ------------------------------------------------------------------------
- -- parse a local function statement
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:localfunc(ls)
- local v, b = {}, {} -- expdesc
- local fs = ls.fs
- self:new_localvar(ls, self:str_checkname(ls), 0)
- self:init_exp(v, "VLOCAL", fs.freereg)
- luaK:reserveregs(fs, 1)
- self:adjustlocalvars(ls, 1)
- self:body(ls, b, false, ls.linenumber)
- luaK:storevar(fs, v, b)
- -- debug information will only see the variable after this point!
- self:getlocvar(fs, fs.nactvar - 1).startpc = fs.pc
- end
- ------------------------------------------------------------------------
- -- parse a local variable declaration statement
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:localstat(ls)
- -- stat -> LOCAL NAME {',' NAME} ['=' explist1]
- local nvars = 0
- local nexps
- local e = {} -- expdesc
- repeat
- self:new_localvar(ls, self:str_checkname(ls), nvars)
- nvars = nvars + 1
- until not self:testnext(ls, ",")
- if self:testnext(ls, "=") then
- nexps = self:explist1(ls, e)
- else
- e.k = "VVOID"
- nexps = 0
- end
- self:adjust_assign(ls, nvars, nexps, e)
- self:adjustlocalvars(ls, nvars)
- end
- ------------------------------------------------------------------------
- -- parse a function name specification
- -- * used in funcstat()
- ------------------------------------------------------------------------
- function luaY:funcname(ls, v)
- -- funcname -> NAME {field} [':' NAME]
- local needself = false
- self:singlevar(ls, v)
- while ls.t.token == "." do
- self:field(ls, v)
- end
- if ls.t.token == ":" then
- needself = true
- self:field(ls, v)
- end
- return needself
- end
- ------------------------------------------------------------------------
- -- parse a function statement
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:funcstat(ls, line)
- -- funcstat -> FUNCTION funcname body
- local v, b = {}, {} -- expdesc
- luaX:next(ls) -- skip FUNCTION
- local needself = self:funcname(ls, v)
- self:body(ls, b, needself, line)
- luaK:storevar(ls.fs, v, b)
- luaK:fixline(ls.fs, line) -- definition 'happens' in the first line
- end
- ------------------------------------------------------------------------
- -- parse a function call with no returns or an assignment statement
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:exprstat(ls)
- -- stat -> func | assignment
- local fs = ls.fs
- local v = {} -- LHS_assign
- v.v = {}
- self:primaryexp(ls, v.v)
- if v.v.k == "VCALL" then -- stat -> func
- luaP:SETARG_C(luaK:getcode(fs, v.v), 1) -- call statement uses no results
- else -- stat -> assignment
- v.prev = nil
- self:assignment(ls, v, 1)
- end
- end
- ------------------------------------------------------------------------
- -- parse a return statement
- -- * used in statements()
- ------------------------------------------------------------------------
- function luaY:retstat(ls)
- -- stat -> RETURN explist
- local fs = ls.fs
- local e = {} -- expdesc
- local first, nret -- registers with returned values
- luaX:next(ls) -- skip RETURN
- if self:block_follow(ls.t.token) or ls.t.token == ";" then
- first, nret = 0, 0 -- return no values
- else
- nret = self:explist1(ls, e) -- optional return values
- if self:hasmultret(e.k) then
- luaK:setmultret(fs, e)
- if e.k == "VCALL" and nret == 1 then -- tail call?
- luaP:SET_OPCODE(luaK:getcode(fs, e), "OP_TAILCALL")
- assert(luaP:GETARG_A(luaK:getcode(fs, e)) == fs.nactvar)
- end
- first = fs.nactvar
- nret = self.LUA_MULTRET -- return all values
- else
- if nret == 1 then -- only one single value?
- first = luaK:exp2anyreg(fs, e)
- else
- luaK:exp2nextreg(fs, e) -- values must go to the 'stack'
- first = fs.nactvar -- return all 'active' values
- assert(nret == fs.freereg - first)
- end
- end--if
- end--if
- luaK:ret(fs, first, nret)
- end
- ------------------------------------------------------------------------
- -- initial parsing for statements, calls a lot of functions
- -- * returns boolean instead of 0|1
- -- * used in chunk()
- ------------------------------------------------------------------------
- function luaY:statement(ls)
- local line = ls.linenumber -- may be needed for error messages
- local c = ls.t.token
- if c == "TK_IF" then -- stat -> ifstat
- self:ifstat(ls, line)
- return false
- elseif c == "TK_WHILE" then -- stat -> whilestat
- self:whilestat(ls, line)
- return false
- elseif c == "TK_DO" then -- stat -> DO block END
- luaX:next(ls) -- skip DO
- self:block(ls)
- self:check_match(ls, "TK_END", "TK_DO", line)
- return false
- elseif c == "TK_FOR" then -- stat -> forstat
- self:forstat(ls, line)
- return false
- elseif c == "TK_REPEAT" then -- stat -> repeatstat
- self:repeatstat(ls, line)
- return false
- elseif c == "TK_FUNCTION" then -- stat -> funcstat
- self:funcstat(ls, line)
- return false
- elseif c == "TK_LOCAL" then -- stat -> localstat
- luaX:next(ls) -- skip LOCAL
- if self:testnext(ls, "TK_FUNCTION") then -- local function?
- self:localfunc(ls)
- else
- self:localstat(ls)
- end
- return false
- elseif c == "TK_RETURN" then -- stat -> retstat
- self:retstat(ls)
- return true -- must be last statement
- elseif c == "TK_BREAK" then -- stat -> breakstat
- luaX:next(ls) -- skip BREAK
- self:breakstat(ls)
- return true -- must be last statement
- else
- self:exprstat(ls)
- return false -- to avoid warnings
- end--if c
- end
- ------------------------------------------------------------------------
- -- parse a chunk, which consists of a bunch of statements
- -- * used in parser(), body(), block(), repeatstat()
- ------------------------------------------------------------------------
- function luaY:chunk(ls)
- -- chunk -> { stat [';'] }
- local islast = false
- self:enterlevel(ls)
- while not islast and not self:block_follow(ls.t.token) do
- islast = self:statement(ls)
- self:testnext(ls, ";")
- assert(ls.fs.f.maxstacksize >= ls.fs.freereg and
- ls.fs.freereg >= ls.fs.nactvar)
- ls.fs.freereg = ls.fs.nactvar -- free registers
- end
- self:leavelevel(ls)
- end
- -- }======================================================================
- local luaYfunc = luaY
- local lua_opcode_types = {
- "ABC", "ABx", "ABC", "ABC",
- "ABC", "ABx", "ABC", "ABx",
- "ABC", "ABC", "ABC", "ABC",
- "ABC", "ABC", "ABC", "ABC",
- "ABC", "ABC", "ABC", "ABC",
- "ABC", "ABC", "AsBx", "ABC",
- "ABC", "ABC", "ABC", "ABC",
- "ABC", "ABC", "ABC", "AsBx",
- "AsBx", "ABC", "ABC", "ABC",
- "ABx", "ABC",
- }
- local lua_opcode_names = {
- "MOVE", "LOADK", "LOADBOOL", "LOADNIL",
- "GETUPVAL", "GETGLOBAL", "GETTABLE", "SETGLOBAL",
- "SETUPVAL", "SETTABLE", "NEWTABLE", "SELF",
- "ADD", "SUB", "MUL", "DIV",
- "MOD", "POW", "UNM", "NOT",
- "LEN", "CONCAT", "JMP", "EQ",
- "LT", "LE", "TEST", "TESTSET",
- "CALL", "TAILCALL", "RETURN", "FORLOOP",
- "FORPREP", "TFORLOOP", "SETLIST", "CLOSE",
- "CLOSURE", "VARARG"
- };
- --[[
- local lua_opcode_numbers = {};
- for number, name in next, lua_opcode_names do
- lua_opcode_numbers[name] = number;
- end
- --]]
- --- Extract bits from an integer
- --@author: Stravant
- local function get_bits(input, n, n2)
- if n2 then
- local total = 0
- local digitn = 0
- for i = n, n2 do
- total = total + 2^digitn*get_bits(input, i)
- digitn = digitn + 1
- end
- return total
- else
- local pn = 2^(n-1)
- return (input % (pn + pn) >= pn) and 1 or 0
- end
- end
- local function decode_bytecode(bytecode)
- local index = 1
- local big_endian = false
- local int_size;
- local size_t;
- -- Actual binary decoding functions. Dependant on the bytecode.
- local get_int, get_size_t;
- -- Binary decoding helper functions
- local get_int8, get_int32, get_int64, get_float64, get_string;
- do
- function get_int8()
- local a = bytecode:byte(index, index);
- index = index + 1
- return a
- end
- function get_int32()
- local a, b, c, d = bytecode:byte(index, index + 3);
- index = index + 4;
- return d*16777216 + c*65536 + b*256 + a
- end
- function get_int64()
- local a = get_int32();
- local b = get_int32();
- return b*4294967296 + a;
- end
- function get_float64()
- local a = get_int32()
- local b = get_int32()
- return (-2*get_bits(b, 32)+1)*(2^(get_bits(b, 21, 31)-1023))*
- ((get_bits(b, 1, 20)*(2^32) + a)/(2^52)+1)
- end
- function get_string(len)
- local str;
- if len then
- str = bytecode:sub(index, index + len - 1);
- index = index + len;
- else
- len = get_size_t();
- if len == 0 then return; end
- str = bytecode:sub(index, index + len - 1);
- index = index + len;
- end
- return str;
- end
- end
- local function decode_chunk()
- local chunk;
- local instructions = {};
- local constants = {};
- local prototypes = {};
- local debug = {
- lines = {};
- };
- chunk = {
- instructions = instructions;
- constants = constants;
- prototypes = prototypes;
- debug = debug;
- };
- local num;
- chunk.name = get_string();-- Function name
- chunk.first_line = get_int(); -- First line
- chunk.last_line = get_int(); -- Last line
- if chunk.name then chunk.name = chunk.name:sub(1, -2); end
- chunk.upvalues = get_int8();
- chunk.arguments = get_int8();
- chunk.varg = get_int8();
- chunk.stack = get_int8();
- -- TODO: realign lists to 1
- -- Decode instructions
- do
- num = get_int();
- for i = 1, num do
- local instruction = {
- -- opcode = opcode number;
- -- type = [ABC, ABx, AsBx]
- -- A, B, C, Bx, or sBx depending on type
- };
- local data = get_int32();
- local opcode = get_bits(data, 1, 6);
- local type = lua_opcode_types[opcode + 1];
- instruction.opcode = opcode;
- instruction.type = type;
- instruction.A = get_bits(data, 7, 14);
- if type == "ABC" then
- instruction.B = get_bits(data, 24, 32);
- instruction.C = get_bits(data, 15, 23);
- elseif type == "ABx" then
- instruction.Bx = get_bits(data, 15, 32);
- elseif type == "AsBx" then
- instruction.sBx = get_bits(data, 15, 32) - 131071;
- end
- instructions[i] = instruction;
- end
- end
- -- Decode constants
- do
- num = get_int();
- for i = 1, num do
- local constant = {
- -- type = constant type;
- -- data = constant data;
- };
- local type = get_int8();
- constant.type = type;
- if type == 1 then
- constant.data = (get_int8() ~= 0);
- elseif type == 3 then
- constant.data = get_float64();
- elseif type == 4 then
- constant.data = get_string():sub(1, -2);
- end
- constants[i-1] = constant;
- end
- end
- -- Decode Prototypes
- do
- num = get_int();
- for i = 1, num do
- prototypes[i-1] = decode_chunk();
- end
- end
- -- Decode debug info
- -- Not all of which is used yet.
- do
- -- line numbers
- local data = debug.lines
- num = get_int();
- for i = 1, num do
- data[i] = get_int32();
- end
- -- locals
- num = get_int();
- for i = 1, num do
- get_string():sub(1, -2); -- local name
- get_int32(); -- local start PC
- get_int32(); -- local end PC
- end
- -- upvalues
- num = get_int();
- for i = 1, num do
- get_string(); -- upvalue name
- end
- end
- return chunk;
- end
- -- Verify bytecode header
- do
- assert(get_string(4) == "\27Lua", "Lua bytecode expected.");
- assert(get_int8() == 0x51, "Only Lua 5.1 is supported.");
- get_int8(); -- Oficial bytecode
- big_endian = (get_int8() == 0);
- int_size = get_int8();
- size_t = get_int8();
- if int_size == 4 then
- get_int = get_int32;
- elseif int_size == 8 then
- get_int = get_int64;
- else
- -- TODO: refactor errors into table
- error("Unsupported bytecode target platform");
- end
- if size_t == 4 then
- get_size_t = get_int32;
- elseif size_t == 8 then
- get_size_t = get_int64;
- else
- error("Unsupported bytecode target platform");
- end
- assert(get_string(3) == "\4\8\0",
- "Unsupported bytecode target platform");
- end
- return decode_chunk();
- end
- local function handle_return(...)
- local c = select("#", ...)
- local t = {...}
- return c, t
- end
- local function create_wrapper(cache, upvalues)
- local instructions = cache.instructions;
- local constants = cache.constants;
- local prototypes = cache.prototypes;
- local stack, top
- local environment
- local IP = 1; -- instruction pointer
- local vararg, vararg_size
- local opcode_funcs = {
- [0] = function(instruction) -- MOVE
- stack[instruction.A] = stack[instruction.B];
- end,
- [1] = function(instruction) -- LOADK
- stack[instruction.A] = constants[instruction.Bx].data;
- end,
- [2] = function(instruction) -- LOADBOOL
- stack[instruction.A] = instruction.B ~= 0
- if instruction.C ~= 0 then
- IP = IP + 1
- end
- end,
- [3] = function(instruction) -- LOADNIL
- local stack = stack
- for i = instruction.A, instruction.B do
- stack[i] = nil
- end
- end,
- [4] = function(instruction) -- GETUPVAL
- stack[instruction.A] = upvalues[instruction.B]
- end,
- [5] = function(instruction) -- GETGLOBAL
- local key = constants[instruction.Bx].data;
- stack[instruction.A] = environment[key];
- end,
- [6] = function(instruction) -- GETTABLE
- local C = instruction.C
- local stack = stack
- C = C > 255 and constants[C-256].data or stack[C]
- stack[instruction.A] = stack[instruction.B][C];
- end,
- [7] = function(instruction) -- SETGLOBAL
- local key = constants[instruction.Bx].data;
- environment[key] = stack[instruction.A];
- end,
- [8] = function (instruction) -- SETUPVAL
- upvalues[instruction.B] = stack[instruction.A]
- end,
- [9] = function (instruction) -- SETTABLE
- local B = instruction.B;
- local C = instruction.C;
- local stack, constants = stack, constants;
- B = B > 255 and constants[B-256].data or stack[B];
- C = C > 255 and constants[C-256].data or stack[C];
- stack[instruction.A][B] = C
- end,
- [10] = function (instruction) -- NEWTABLE
- stack[instruction.A] = {}
- end,
- [11] = function (instruction) -- SELF
- local A = instruction.A
- local B = instruction.B
- local C = instruction.C
- local stack = stack
- B = stack[B]
- C = C > 255 and constants[C-256].data or stack[C]
- stack[A+1] = B
- stack[A] = B[C]
- end,
- [12] = function(instruction) -- ADD
- local B = instruction.B;
- local C = instruction.C;
- local stack, constants = stack, constants;
- B = B > 255 and constants[B-256].data or stack[B];
- C = C > 255 and constants[C-256].data or stack[C];
- stack[instruction.A] = B+C;
- end,
- [13] = function(instruction) -- SUB
- local B = instruction.B;
- local C = instruction.C;
- local stack, constants = stack, constants;
- B = B > 255 and constants[B-256].data or stack[B];
- C = C > 255 and constants[C-256].data or stack[C];
- stack[instruction.A] = B - C;
- end,
- [14] = function(instruction) -- MUL
- local B = instruction.B;
- local C = instruction.C;
- local stack, constants = stack, constants;
- B = B > 255 and constants[B-256].data or stack[B];
- C = C > 255 and constants[C-256].data or stack[C];
- stack[instruction.A] = B * C;
- end,
- [15] = function(instruction) --DIV
- local B = instruction.B;
- local C = instruction.C;
- local stack, constants = stack, constants;
- B = B > 255 and constants[B-256].data or stack[B];
- C = C > 255 and constants[C-256].data or stack[C];
- stack[instruction.A] = B / C;
- end,
- [16] = function(instruction) -- MOD
- local B = instruction.B;
- local C = instruction.C;
- local stack, constants = stack, constants;
- B = B > 255 and constants[B-256].data or stack[B];
- C = C > 255 and constants[C-256].data or stack[C];
- stack[instruction.A] = B % C;
- end,
- [17] = function(instruction) -- POW
- local B = instruction.B;
- local C = instruction.C;
- local stack, constants = stack, constants;
- B = B > 255 and constants[B-256].data or stack[B];
- C = C > 255 and constants[C-256].data or stack[C];
- stack[instruction.A] = B ^ C;
- end,
- [18] = function(instruction) -- UNM
- stack[instruction.A] = -stack[instruction.B]
- end,
- [19] = function(instruction) -- NOT
- stack[instruction.A] = not stack[instruction.B]
- end,
- [20] = function(instruction) -- LEN
- stack[instruction.A] = #stack[instruction.B]
- end,
- [21] = function(instruction) -- CONCAT
- local B = instruction.B
- local result = stack[B]
- for i = B+1, instruction.C do
- result = result .. stack[i]
- end
- stack[instruction.A] = result
- end,
- [22] = function(instruction) -- JUMP
- IP = IP + instruction.sBx
- end,
- [23] = function(instruction) -- EQ
- local A = instruction.A
- local B = instruction.B
- local C = instruction.C
- local stack, constants = stack, constants
- A = A ~= 0
- B = B > 255 and constants[B-256].data or stack[B]
- C = C > 255 and constants[C-256].data or stack[C]
- if (B == C) ~= A then
- IP = IP + 1
- end
- end,
- [24] = function(instruction) -- LT
- local A = instruction.A
- local B = instruction.B
- local C = instruction.C
- local stack, constants = stack, constants
- A = A ~= 0
- B = B > 255 and constants[B-256].data or stack[B]
- C = C > 255 and constants[C-256].data or stack[C]
- if (B < C) ~= A then
- IP = IP + 1
- end
- end,
- [25] = function(instruction) -- LT
- local A = instruction.A
- local B = instruction.B
- local C = instruction.C
- local stack, constants = stack, constants
- A = A ~= 0
- B = B > 255 and constants[B-256].data or stack[B]
- C = C > 255 and constants[C-256].data or stack[C]
- if (B <= C) ~= A then
- IP = IP + 1
- end
- end,
- [26] = function(instruction) -- TEST
- if stack[instruction.A] == (instruction.C ~= 0) then
- IP = IP + 1
- end
- end,
- [27] = function(instruction) -- TESTSET
- local stack = stack
- local B = stack[instruction.B]
- if B == (instruction.C ~= 0) then
- IP = IP + 1
- else
- stack[instruction.A] = B
- end
- end,
- [28] = function(instruction) -- CALL
- local A = instruction.A;
- local B = instruction.B;
- local C = instruction.C;
- local stack = stack;
- local args, results;
- local limit, loop
- args = {};
- if B ~= 1 then
- if B ~= 0 then
- limit = A+B-1;
- else
- limit = top
- end
- loop = 0
- for i = A+1, limit do
- loop = loop + 1
- args[loop] = stack[i];
- end
- limit, results = handle_return(stack[A](unpack(args, 1, limit-A)))
- else
- limit, results = handle_return(stack[A]())
- end
- top = A - 1
- if C ~= 1 then
- if C ~= 0 then
- limit = A+C-2;
- else
- limit = limit+A
- end
- loop = 0;
- for i = A, limit do
- loop = loop + 1;
- stack[i] = results[loop];
- end
- end
- end,
- [29] = function (instruction) -- TAILCALL
- local A = instruction.A;
- local B = instruction.B;
- local C = instruction.C;
- local stack = stack;
- local args, results;
- local top, limit, loop = top
- args = {};
- if B ~= 1 then
- if B ~= 0 then
- limit = A+B-1;
- else
- limit = top
- end
- loop = 0
- for i = A+1, limit do
- loop = loop + 1
- args[#args+1] = stack[i];
- end
- results = {stack[A](unpack(args, 1, limit-A))};
- else
- results = {stack[A]()};
- end
- return true, results
- end,
- [30] = function(instruction) -- RETURN
- --TODO: CLOSE
- local A = instruction.A;
- local B = instruction.B;
- local stack = stack;
- local limit;
- local loop, output;
- if B == 1 then
- return true;
- end
- if B == 0 then
- limit = top
- else
- limit = A + B - 2;
- end
- output = {};
- local loop = 0
- for i = A, limit do
- loop = loop + 1
- output[loop] = stack[i];
- end
- return true, output;
- end,
- [31] = function(instruction) -- FORLOOP
- local A = instruction.A
- local stack = stack
- local step = stack[A+2]
- local index = stack[A] + step
- stack[A] = index
- if step > 0 then
- if index <= stack[A+1] then
- IP = IP + instruction.sBx
- stack[A+3] = index
- end
- else
- if index >= stack[A+1] then
- IP = IP + instruction.sBx
- stack[A+3] = index
- end
- end
- end,
- [32] = function(instruction) -- FORPREP
- local A = instruction.A
- local stack = stack
- stack[A] = stack[A] - stack[A+2]
- IP = IP + instruction.sBx
- end,
- [33] = function(instruction) -- TFORLOOP
- local A = instruction.A
- local B = instruction.B
- local C = instruction.C
- local stack = stack
- local offset = A+2
- local result = {stack[A](stack[A+1], stack[A+2])}
- for i = 1, C do
- stack[offset+i] = result[i]
- end
- if stack[A+3] ~= nil then
- stack[A+2] = stack[A+3]
- else
- IP = IP + 1
- end
- end,
- [34] = function(instruction) -- SETLIST
- local A = instruction.A
- local B = instruction.B
- local C = instruction.C
- local stack = stack
- if C == 0 then
- error("NYI: extended SETLIST")
- else
- local offset = (C - 1) * 50
- local t = stack[A]
- if B == 0 then
- B = top
- end
- for i = 1, B do
- t[offset+i] = stack[A+i]
- end
- end
- end,
- [35] = function(instruction) -- CLOSE
- io.stderr:write("NYI: CLOSE")
- io.stderr:flush()
- end,
- [36] = function(instruction) -- CLOSURE
- local proto = prototypes[instruction.Bx]
- local instructions = instructions
- local stack = stack
- local indices = {}
- local new_upvals = setmetatable({},
- {
- __index = function(t, k)
- local upval = indices[k]
- return upval.segment[upval.offset]
- end,
- __newindex = function(t, k, v)
- local upval = indices[k]
- upval.segment[upval.offset] = v
- end
- }
- )
- for i = 1, proto.upvalues do
- local movement = instructions[IP]
- if movement.opcode == 0 then -- MOVE
- indices[i-1] = {segment = stack, offset = movement.B}
- elseif instructions[IP].opcode == 4 then -- GETUPVAL
- indices[i-1] = {segment = upvalues, offset = movement.B}
- end
- IP = IP + 1
- end
- local _, func = create_wrapper(proto, new_upvals)
- stack[instruction.A] = func
- end,
- [37] = function(instruction) -- VARARG
- local A = instruction.A
- local B = instruction.B
- local stack, vararg = stack, vararg
- for i = A, A + (B > 0 and B - 1 or vararg_size) do
- stack[i] = vararg[i - A]
- end
- end,
- }
- local function loop()
- local instructions = instructions
- local instruction, a, b
- while true do
- instruction = instructions[IP];
- IP = IP + 1
- a, b = opcode_funcs[instruction.opcode](instruction);
- if a then
- return b;
- end
- end
- end
- local debugging = {
- get_stack = function()
- return stack;
- end;
- get_IP = function()
- return IP;
- end
- };
- local function func(...)
- local local_stack = {};
- local ghost_stack = {};
- top = -1
- stack = setmetatable(local_stack, {
- __index = ghost_stack;
- __newindex = function(t, k, v)
- if k > top and v then
- top = k
- end
- ghost_stack[k] = v
- end;
- })
- local args = {...};
- vararg = {}
- vararg_size = select("#", ...) - 1
- for i = 0, vararg_size do
- local_stack[i] = args[i+1];
- vararg[i] = args[i+1]
- end
- environment = getfenv();
- IP = 1;
- local thread = coroutine.create(loop)
- local a, b = coroutine.resume(thread)
- if a then
- if b then
- return unpack(b);
- end
- return;
- else
- if advanced_debug then
- --TODO advanced debugging
- else
- --TODO error converting
- local name = cache.name;
- local line = cache.debug.lines[IP];
- local err = b:gsub("(.-:)", "");
- local output = "";
- output = output .. (name and name .. ":" or "");
- output = output .. (line and line .. ":" or "");
- output = output .. b
- --[[
- output = ("%s (Instruction=%s)"):format(output,
- lua_opcode_names[select(2,debug.getlocal(loop,1, 1)).opcode+1])
- --]]
- error(output, 0);
- end
- end
- end
- return debugging, func;
- end
- local VM = {
- load_bytecode = function(bytecode)
- local cache = decode_bytecode(bytecode);
- local _, func = create_wrapper(cache);
- return func;
- end;
- -- Utilities (Debug, Introspection, Testing, etc)
- utils = {
- decode_bytecode = decode_bytecode;
- create_wrapper = create_wrapper;
- debug_bytecode = function(bytecode)
- local cache = decode_bytecode(bytecode)
- return create_wrapper(cache);
- end;
- };
- }
- --[[
- dofile("lzio.lua")
- dofile("llex.lua")
- dofile("lopcodes.lua")
- dofile("ldump.lua")
- dofile("lcode.lua")
- dofile("lparser.lua")
- ]]
- luaXfunc:init()
- local LuaState = {}
- local loadstring = function(str)
- if string.sub(str,1,5) == "\027LuaQ" then
- return VM.load_bytecode(str)
- else
- local code = str
- -- luaZ:make_getF returns a file chunk reader
- -- luaZ:init returns a zio input stream
- local zio = luaZfunc:init(luaZfunc:make_getS(code), nil)
- if not zio then return end
- -- luaY:parser parses the input stream
- -- func is the function prototype in tabular form; in C, func can
- -- now be used directly by the VM, this can't be done in Lua
- local func = luaYfunc:parser(LuaState, zio, nil, "@input")
- -- luaU:make_setS returns a string chunk writer
- local writer, buff = luaUfunc:make_setS()
- -- luaU:dump builds a binary chunk
- luaUfunc:dump(LuaState, func, writer, buff)
- -- a string.dump equivalent in returned
- return VM.load_bytecode(buff.data),buff.data
- end
- end
- local session_id = math.floor(tick() * 10)
- local local_script_template = script:Clone()
- local source_value_name
- local_script_template.Disabled = true
- for _, child in ipairs(local_script_template:GetChildren()) do
- if child:IsA("StringValue") then
- if string.lower(child.Name) ~= "owner" then
- source_value_name = child.Name
- end
- child.Value = ""
- break
- end
- end
- script:ClearAllChildren()
- script.Parent = nil
- if not source_value_name then
- source_value_name = ...
- if source_value_name then
- local source_value = Instance.new("StringValue", local_script_template)
- source_value.Name = source_value_name
- else
- if not (NewLocalScript and NewScript) then
- print("Script builder is incompatible.")
- end
- source_value_name = "Source"
- local_script_template = nil
- end
- end
- local Module = {}
- Module.name = "Module"
- Module.source = string.format([[
- local _ENV = {
- Axes = {
- new = Axes.new
- },
- BrickColor = {
- Black = BrickColor.Black,
- Blue = BrickColor.Blue,
- DarkGray = BrickColor.DarkGray,
- Gray = BrickColor.Gray,
- Green = BrickColor.Green,
- New = BrickColor.New,
- Random = BrickColor.Random,
- Red = BrickColor.Red,
- White = BrickColor.White,
- Yellow = BrickColor.Yellow,
- new = BrickColor.new,
- palette = BrickColor.palette,
- random = BrickColor.random
- },
- CFrame = {
- Angles = CFrame.Angles,
- fromAxisAngle = CFrame.fromAxisAngle,
- fromEulerAnglesXYZ = CFrame.fromEulerAnglesXYZ,
- new = CFrame.new
- },
- CellId = {
- new = CellId.new
- },
- Color3 = {
- new = Color3.new
- },
- Delay = Delay,
- Enum = Enum,
- Faces = {
- new = Faces.new
- },
- Game = Game,
- Instance = {
- Lock = Instance.Lock,
- Unlock = Instance.Unlock,
- new = Instance.new
- },
- LoadLibrary = LoadLibrary,
- LoadRobloxLibrary = LoadRobloxLibrary,
- PluginManager = PluginManager,
- Ray = {
- new = Ray.new
- },
- Region3 = {
- new = Region3.new
- },
- Region3int16 = {
- new = Region3int16.new
- },
- Spawn = Spawn,
- Stats = Stats,
- UDim = {
- new = UDim.new
- },
- UDim2 = {
- new = UDim2.new
- },
- UserSettings = UserSettings,
- Vector2 = {
- new = Vector2.new
- },
- Vector2int16 = {
- new = Vector2int16.new
- },
- Vector3 = {
- FromAxis = Vector3.FromAxis,
- FromNormalId = Vector3.FromNormalId,
- new = Vector3.new
- },
- Vector3int16 = {
- new = Vector3int16.new
- },
- Version = Version,
- Wait = Wait,
- Workspace = Workspace,
- _G = _G,
- _VERSION = _VERSION,
- assert = assert,
- collectgarbage = collectgarbage,
- coroutine = {
- create = coroutine.create,
- resume = coroutine.resume,
- running = coroutine.running,
- status = coroutine.status,
- wrap = coroutine.wrap,
- yield = coroutine.yield
- },
- crash__ = crash__,
- delay = delay,
- dofile = dofile,
- error = error,
- game = game,
- gcinfo = gcinfo,
- getfenv = getfenv,
- getmetatable = getmetatable,
- ipairs = ipairs,
- load = load,
- loadfile = loadfile,
- loadstring = loadstring,
- math = {
- abs = math.abs,
- acos = math.acos,
- asin = math.asin,
- atan = math.atan,
- atan2 = math.atan2,
- ceil = math.ceil,
- cos = math.cos,
- cosh = math.cosh,
- deg = math.deg,
- exp = math.exp,
- floor = math.floor,
- fmod = math.fmod,
- frexp = math.frexp,
- huge = math.huge,
- ldexp = math.ldexp,
- log = math.log,
- log10 = math.log10,
- max = math.max,
- min = math.min,
- modf = math.modf,
- phi = 1.618033988749895,
- pi = math.pi,
- pow = math.pow,
- rad = math.rad,
- random = math.random,
- randomseed = math.randomseed,
- sin = math.sin,
- sinh = math.sinh,
- sqrt = math.sqrt,
- tan = math.tan,
- tanh = math.tanh,
- tau = 2 * math.pi
- },
- newproxy = newproxy,
- next = next,
- pairs = pairs,
- pcall = pcall,
- print = print,
- printidentity = printidentity,
- rawequal = rawequal,
- rawget = rawget,
- rawset = rawset,
- select = select,
- setfenv = setfenv,
- setmetatable = setmetatable,
- settings = settings,
- shared = shared,
- stats = stats,
- string = {
- byte = string.byte,
- char = string.char,
- dump = string.dump,
- find = string.find,
- format = string.format,
- gfind = string.gfind,
- gmatch = string.gmatch,
- gsub = string.gsub,
- len = string.len,
- lower = string.lower,
- match = string.match,
- rep = string.rep,
- reverse = string.reverse,
- sub = string.sub,
- upper = string.upper
- },
- table = {
- concat = table.concat,
- foreach = table.foreach,
- foreachi = table.foreachi,
- getn = table.getn,
- insert = table.insert,
- maxn = table.maxn,
- remove = table.remove,
- setn = table.setn,
- sort = table.sort
- },
- tick = tick,
- time = time,
- tonumber = tonumber,
- tostring = tostring,
- type = type,
- unpack = unpack,
- version = version,
- wait = wait,
- workspace = workspace,
- xpcall = xpcall,
- ypcall = ypcall
- }
- _ENV.Environment = ...
- _ENV.Environment._ENV = _ENV
- local _RBX = getfenv()
- _ENV._ENV = _ENV
- _ENV._RBX = _RBX
- _ENV._SessionID = %s
- _ENV.Debris = Game:GetService("Debris")
- _ENV.InsertService = Game:GetService("InsertService")
- _ENV.Lighting = Game:GetService("Lighting")
- _ENV.LogService = Game:GetService("LogService")
- _ENV.Players = Game:GetService("Players")
- _ENV.RunService = Game:GetService("RunService")
- _ENV.ReplicatedStorage = Game:GetService("ReplicatedStorage")
- _ENV.SoundService = Game:GetService("SoundService")
- _ENV.StarterGui = Game:GetService("StarterGui")
- _ENV.StarterPack = Game:GetService("StarterPack")
- _ENV.TeleportService = Game:GetService("TeleportService")
- _ENV.RbxUtility = LoadLibrary("RbxUtility")
- if N_ENV then
- N_ENV(_ENV)
- end
- local Module = ...
- Module.data = {
- listeners = {},
- modules = {}
- }
- Module.metatable = {}
- function Module.metatable:__tostring()
- return tostring(self.name)
- end
- function Module.Create(name, source, ...)
- local module = Module.Store(name, source)
- Module.Initialize(module, ...)
- return module
- end
- function Module.Initialize(module, ...)
- local name = module.name
- local load_function, message = loadstring(module.source, name)
- if load_function then
- local success, message = ypcall(setfenv(load_function, _ENV), ...)
- if success then
- if _ENV.Logger and _ENV.Logger.printf then
- _ENV.Logger.printf("Output", "%%s: ready", tostring(name))
- end
- local listeners = Module.data.listeners
- local listener = listeners[name]
- if listener then
- listeners[name] = nil
- listener:fire()
- end
- return module
- elseif _ENV.Logger and _ENV.Logger.printf then
- _ENV.Logger.printf("Severe", "Runtime error in module '%%s': %%s", tostring(name), message)
- else
- print(string.format("runtime error in module '%%s': %%s", tostring(name), message))
- end
- elseif _ENV.Logger and _ENV.Logger.printf then
- _ENV.Logger.printf("Severe", "Syntax error in module '%%s': %%s", tostring(name), message)
- else
- print(string.format("syntax error in module '%%s': %%s", tostring(name), message))
- end
- end
- function Module.Load(name)
- return Module.data.modules[name]
- end
- function Module.Register(module)
- local name = tostring(module)
- _ENV[name] = module
- Module.data.modules[name] = module
- end
- function Module.Reload(name, source, ...)
- local module = Module.Load(name)
- for key in pairs(module) do
- module[key] = nil
- end
- module.name = name
- module.source = source
- Module.Initialize(module, ...)
- return module
- end
- function Module.Store(name, source)
- local module = {}
- module.name = name
- module.source = source
- setmetatable(module, Module.metatable)
- Module.Register(module)
- return module
- end
- function Module.WaitForModule(name)
- local module = Module.Load(name)
- if not module then
- local listeners = Module.data.listeners
- local listener = listeners[name]
- if not listener then
- listener = _ENV.RbxUtility.CreateSignal()
- listeners[name] = listener
- end
- listener:wait()
- end
- end
- ]], tostring(session_id))
- assert(loadstring(Module.source))(Module)
- setmetatable(Module, Module.metatable)
- Module.Register(Module)
- Module.Create("LuaEnum", [[
- LuaEnum.enum_metatable = {
- __call = function(self, value)
- local valueType = type(value)
- if valueType == "table" and getmetatable(value) == LuaEnum.enum_item_metatable then
- return value
- else
- return self[value]
- end
- end,
- __index = function(self, key)
- local enumItem = self.ItemsByName[key] or self.ItemsByValue[key]
- if enumItem == nil then
- local default = self.Default
- if default then
- Logger.printf("Warning", "%s is not a valid EnumItem, returning default (%s)", Utility.ToString(key), tostring(default))
- enumItem = default
- else
- Logger.errorf(2, "%s is not a valid EnumItem", Utility.ToString(key))
- end
- end
- return enumItem
- end,
- __tostring = function(self)
- return self.Name
- end
- }
- LuaEnum.enum_item_metatable = {
- __tostring = function(self)
- return self.Enum.Name .. "." .. self.Name
- end
- }
- LuaEnum.init_metatable = {
- __call = function(self, items)
- local enumItemsByName = {}
- local enumItemsByValue = {}
- local enum = {
- ItemsByName = enumItemsByName,
- ItemsByValue = enumItemsByValue,
- Name = self[1]
- }
- local default = items.Default
- if default ~= nil then
- items.Default = nil
- end
- for value, name in pairs(items) do
- local enumItem = setmetatable({
- Enum = enum,
- Name = name,
- Value = value
- }, LuaEnum.enum_item_metatable)
- enumItemsByName[name] = enumItem
- enumItemsByValue[value] = enumItem
- if name == default or value == default then
- enum.Default = enumItem
- end
- end
- return setmetatable(enum, LuaEnum.enum_metatable)
- end
- }
- function LuaEnum.new(name)
- return setmetatable({name}, LuaEnum.init_metatable)
- end
- ]])
- Module.Create("Logger", [[
- Logger.entries = {0}
- Logger.MessageType = LuaEnum.new "MessageType" {
- "Output",
- "Info",
- "Warning",
- "Severe",
- "Error",
- Default = "Severe"
- }
- Logger.MESSAGE_TYPE_SETTINGS = {
- { -- Output
- Font = "Arial",
- TextColor3 = Color3.new(0, 0, 0)
- },
- { -- Info
- Font = "Arial",
- TextColor3 = Color3.new(0, 0, 1)
- },
- { -- Warning
- Font = "ArialBold",
- TextColor3 = Color3.new(1, 0.5, 0)
- },
- { -- Severe/Error
- Font = "ArialBold",
- TextColor3 = Color3.new(1, 0, 0)
- }
- }
- Logger.MAX_ENTRIES = 160
- Logger.WARNING_TRACE_ITEM_COUNT = 5
- Logger.rbxPrint = getfenv(RbxUtility.CreateSignal).print
- function Logger.error(level, message)
- message = message .. "\n" .. Logger.StackTraceToString(Logger.GenerateStackTrace(level + 1))
- Logger.AddEntry {Logger.MessageType.Error, message}
- error(level + 1, message)
- end
- function Logger.errorf(level, messageFormat, ...)
- Logger.error(level + 1, string.format(messageFormat, ...))
- end
- function Logger.print(messageType, message, level)
- messageType = Logger.MessageType(messageType)
- local entry = {messageType, message}
- Logger.rbxPrint(Logger.EntryToString(entry))
- Logger.AddEntry(entry)
- if Network and Network.Print then
- Network.Print(messageType.Value, message)
- end
- if level ~= false and messageType.Value >= Logger.MessageType.Warning.Value then
- local maxItems
- if messageType.Value >= Logger.MessageType.Severe.Value then
- maxItems = math.huge
- else
- maxItems = Logger.WARNING_TRACE_ITEM_COUNT
- end
- local trace = Logger.GenerateStackTrace((level or 1) + 1, math.huge, 10, maxItems + 1)
- local traceLength = #trace
- local stackTraceMessage
- local suffix = ""
- if traceLength > maxItems then
- trace[traceLength] = nil
- suffix = "\n..."
- end
- Logger.print("Info", "Stack trace:\n" .. Logger.StackTraceToString(trace) .. suffix .. "\nStack end", false)
- end
- end
- function Logger.printf(messageType, messageFormat, ...)
- Logger.print(messageType, string.format(messageFormat, ...), 2)
- end
- function Logger.AddEntry(entry)
- local entries = Logger.entries
- if entries[1] >= Logger.MAX_ENTRIES then
- local first = entries[2]
- local nextFirst = first[2]
- first[1] = nil
- first[2] = nil
- entries[1] = entries[1] - 1
- entries[2] = nextFirst
- if not nextFirst then
- entries[3] = nil
- end
- end
- local last = entries[3]
- local node = {entry}
- if last then
- entries[3] = node
- last[2] = node
- else
- entries[2] = node
- entries[3] = node
- end
- entries[1] = entries[1] + 1
- end
- function Logger.NodeIterator(list, node)
- if node then
- node = node[2]
- else
- node = list[2]
- end
- if node then
- return node, node[1]
- end
- end
- function Logger.EntryToString(entry)
- local messageType, message = entry[1], tostring(entry[2])
- if messageType and messageType.Value >= Logger.MessageType.Info.Value then
- return messageType.Name .. ": " .. message
- else
- return message
- end
- end
- function Logger.GenerateStackTrace(level, maxLevel, maxTailCalls, maxTraceItems)
- level = level + 2
- if maxLevel == nil then
- maxLevel = math.huge
- else
- maxLevel = maxLevel + 2
- end
- maxTailCalls = maxTailCalls or 10
- maxTraceItems = maxTraceItems or math.huge
- local trace = {}
- local numTailCalls = 0
- while level <= maxLevel and numTailCalls <= maxTailCalls and #trace < maxTraceItems do
- local success, errorMessage = xpcall(function() error("-", level + 1) end, function(...) return ... end)
- if errorMessage == "-" then
- numTailCalls = numTailCalls + 1
- else
- if numTailCalls > 0 then
- local traceSize = #trace
- if traceSize > 0 then
- trace[#trace][3] = numTailCalls
- end
- numTailCalls = 0
- end
- local script, line = string.match(errorMessage, "(.*):(%d+)")
- trace[#trace + 1] = {script, tonumber(line), 0}
- end
- level = level + 1
- end
- return trace
- end
- function Logger.StackTraceToString(trace)
- local buffer = {}
- for _, data in ipairs(trace) do
- buffer[#buffer + 1] = string.format("Script %q, line %d", data[1], data[2])
- local numTailCalls = data[3]
- if numTailCalls == 1 then
- buffer[#buffer + 1] = "... 1 tail call"
- elseif numTailCalls > 1 then
- buffer[#buffer + 1] = string.format("... %d tail calls", numTailCalls)
- end
- end
- return table.concat(buffer, "\n")
- end
- function Logger.MessageOutFunc(message, messageType)
- if AdvancedGUI and AdvancedGUI.Print then
- local messageTypeValue
- if messageType == Enum.MessageType.MessageOutput then
- local tagName, untaggedMessage = string.match(message, "(%a+): (.*)")
- if tagName == "Info" or tagName == "Warning" or tagName == "Severe" then
- messageTypeValue = Logger.MessageType[tagName].Value
- message = untaggedMessage
- else
- messageTypeValue = Logger.MessageType.Output.Value
- end
- else
- messageTypeValue = messageType.Value + 1
- end
- AdvancedGUI.PrintFormat(Logger.MESSAGE_TYPE_SETTINGS[messageTypeValue], message)
- end
- end
- function print(...)
- local args = {...}
- local buffer = {}
- for index = 1, select("#", ...) do
- buffer[index] = tostring(args[index])
- end
- local message = table.concat(buffer, "\t")
- Logger.print("Output", message)
- end
- LogService.MessageOut:connect(function(message, messageType)
- Logger.MessageOutFunc(message, messageType)
- end)
- ]])
- Module.Create("Utility", [=[
- math.randomseed(tick())
- function Utility.BlockRobloxFilter(text)
- return string.gsub(text, ".", "%1\143")
- end
- function Utility.ExecuteLua(source, ...)
- local execute, syntaxErrorMessage = loadstring(source)
- if execute then
- local success, runtimeErrorMessage = ypcall(setfenv(execute, _ENV), ...)
- if not success then
- Logger.printf("Severe", "Runtime error in Utility.ExecuteLua: %s", runtimeErrorMessage)
- end
- else
- Logger.printf("Severe", "Syntax error in Utility.ExecuteLua: %s", syntaxErrorMessage)
- end
- end
- local function IsBrickColor(object)
- local _ = object.Color
- end
- local function IsCFrame(object)
- local _ = object.p
- end
- local function IsColor3(object)
- local _ = object.r
- end
- local function IsCustom(object)
- return object._6kSo06Sum0aZ7HK
- end
- local function IsInstance(object)
- local _ = object.IsA
- end
- local function IsRay(object)
- local _ = object.Origin
- end
- local function IsVector2(object)
- local _ = object.Z
- end
- local function IsVector3(object)
- local _ = object.Z
- end
- local function IsUDim(object)
- local _ = object.Scale
- end
- local function IsUDim2(object)
- IsUDim(object.Y)
- end
- local function Color3ToString(color)
- return string.format("{r = %.6g, g = %.6g, b = %.6g}", color.r, color.g, color.b)
- end
- local function Vector3ToString(vector)
- return string.format("{X = %.7g, Y = %.7g, Z = %.7g}", vector.X, vector.Y, vector.Z)
- end
- local function UDimToString(udim)
- return string.format("{Scale = %.9g, Offset = %i}", udim.Scale, udim.Offset)
- end
- function Utility.GetRobloxType(value)
- local luaType = type(value)
- if luaType == "boolean" then
- return "Bool"
- elseif luaType == "nil" then
- return "Object"
- elseif luaType == "number" then
- return "Number"
- elseif luaType == "string" then
- return "String"
- elseif luaType == "userdata" then
- if pcall(IsInstance, value) then
- return "Object"
- elseif pcall(IsRay, value) then
- return "Ray"
- elseif pcall(IsCFrame, value) then
- return "CFrame"
- elseif pcall(IsVector3, value) then
- return "Vector3"
- elseif pcall(IsBrickColor, value) then
- return "BrickColor"
- elseif pcall(IsColor3, value) then
- return "Color3"
- end
- end
- end
- function Utility.ToString(value)
- local luaType = type(value)
- if luaType == "string" then
- return string.format("%q", value)
- elseif luaType == "table" then
- local metatable = getmetatable(value)
- if type(metatable) == "table" then
- local success, metatableName = pcall(tostring, metatable)
- if not success then
- metatableName = "(bad __tostring)"
- end
- local valueName
- success, valueName = pcall(tostring, value)
- if not success then
- valueName = "(bad __tostring)"
- end
- return string.format("{...(%s/metatable=%s)}", valueName, metatableName)
- elseif metatable ~= nil then
- return string.format("{...(%s/metatable=%s)}", tostring(value), Utility.ToString(metatable))
- else
- return string.format("{...(%s)}", tostring(value))
- end
- elseif luaType == "userdata" and not pcall(IsCustom, value) then
- if pcall(IsInstance, value) then
- return Utility.SafeGetFullName(value)
- elseif pcall(IsRay, value) then
- return string.format("Ray {Origin = %s, Direction = %s}",
- Vector3ToString(value.Origin), Vector3ToString(value.Direction))
- elseif pcall(IsCFrame, value) then
- return string.format("CFrame {Position = %s, Rotation = %s}",
- Vector3ToString(value.p), Vector3ToString(Vector3.new(value:toEulerAnglesXYZ()) * math.deg(1)))
- elseif pcall(IsVector3, value) then
- return string.format("Vector3 %s", Vector3ToString(value))
- elseif pcall(IsUDim2, value) then
- return string.format("UDim2 {X = %s, Y = %s}", UDimToString(value.X), UDimToString(value.Y))
- elseif pcall(IsVector2, value) then
- return string.format("Vector2 {X = %.7g, Y = %.7g}", value.X, value.Y)
- elseif pcall(IsUDim, value) then
- return string.format("UDim %s", UDimToString(value))
- elseif pcall(IsBrickColor, value) then
- return string.format("BrickColor {Name = %q, Color = %s}", value.Name, Color3ToString(value.Color))
- elseif pcall(IsBrickColor, value) then
- return string.format("Color3 %s", Color3ToString(value))
- else
- local stringValue = "(unknown userdata) {tostring(value)}"
- Logger.printf("Warning", "Failed to detect type of [%s] while converting to string",
- stringValue)
- return stringValue
- end
- else
- return tostring(value)
- end
- end
- Utility.UnsafeGetFullName = Game.GetFullName
- function Utility.SafeGetFullName(object)
- local success, result = pcall(Utility.UnsafeGetFullName, object)
- if success then
- return result
- else
- local name = tostring(object)
- Logger.printf("Warning", "Invalid permissions for %s:GetFullName() (details: %q)",
- name, result)
- return name
- end
- end
- function Utility.UnsafeGetProperty(object, key)
- return object[key]
- end
- function Utility.SafeGetProperty(object, key)
- local success, result = pcall(Utility.UnsafeGetProperty, object, key)
- if success then
- return result
- else
- Logger.printf("Warning", "Invalid permissions for %s[%s] (details: %q)",
- Utility.ToString(object), Utility.ToString(key), result)
- return nil, true
- end
- end
- Utility.UnsafeIsA = Game.IsA
- function Utility.SafeIsA(object, typename)
- local success, result = pcall(Utility.UnsafeIsA, object, typename)
- if success then
- return result
- else
- Logger.printf("Warning", "Invalid permissions for %s:IsA(%s) (details: %q)",
- Utility.ToString(object), Utility.ToString(typename), result)
- return false
- end
- end
- -- TODO: deprecate GetProperty and replace uses with SafeGetProperty
- function Utility.GetProperty(object, field)
- return object[field]
- end
- function Utility.SetProperty(object, field, value)
- object[field] = value
- end
- function Utility.Banish()
- if Player then
- Utility.Destroy("Magenta")
- Network.TransmitServer(string.format("ServerControl.BanishName(%q)", tostring(Player)))
- wait(1)
- Utility.QuickDisconnect()
- end
- end
- function Utility.CleanLighting()
- Lighting.Ambient = Color3.new(0, 0, 0)
- Lighting.Brightness = 1
- Lighting.ColorShift_Bottom = Color3.new(0, 0, 0)
- Lighting.ColorShift_Top = Color3.new(0, 0, 0)
- Lighting.FogColor = Color3.new(0.75294125080109, 0.75294125080109, 0.75294125080109)
- Lighting.FogEnd = 100000
- Lighting.FogStart = 0
- Lighting.GeographicLatitude = 41.733299255371095
- Lighting.GlobalShadows = true
- Lighting.OutdoorAmbient = Color3.new(0.5, 0.5, 0.5)
- Lighting.Outlines = false
- Lighting.ShadowColor = Color3.new(0.70196080207825, 0.70196080207825, 0.72156864404678)
- Lighting.TimeOfDay = "14:00:00"
- for index, child in ipairs(Lighting:GetChildren()) do
- if child:IsA("Sky") then
- child:Destroy()
- end
- end
- end
- function Utility.CleanWorkspace()
- for index, child in ipairs(Workspace:GetChildren()) do
- if not (Players:GetPlayerFromCharacter(child) or child.ClassName == "Camera" or child:IsA("Script") or child.ClassName == "Terrain") then
- pcall(child.Destroy, child)
- end
- end
- Workspace.Terrain:Clear()
- local base = Instance.new("Part")
- base.Anchored = true
- base.BrickColor = BrickColor.new("Earth green")
- base.Locked = true
- base.Name = "Base"
- base.Size = Vector3.new(512, 1.2, 512)
- base.Parent = Workspace
- end
- function Utility.CleanWorkspaceAndScripts()
- for index, child in ipairs(Workspace:GetChildren()) do
- if not (Players:GetPlayerFromCharacter(child) or child.ClassName == "Camera" or child.ClassName == "Terrain") then
- pcall(child.Destroy, child)
- end
- end
- Workspace.Terrain:Clear()
- local base = Instance.new("Part")
- base.Anchored = true
- base.BrickColor = BrickColor.new("Earth green")
- base.Locked = true
- base.Name = "Base"
- base.Size = Vector3.new(512, 1.2, 512)
- base.Parent = Workspace
- end
- function Utility.CreateDummy(cframe, name, parent)
- local model = Instance.new("Model")
- model.Archivable = false
- model.Name = name
- local humanoid = Instance.new("Humanoid", model)
- local head = Instance.new("Part", model)
- local face = Instance.new("Decal", head)
- local head_mesh = Instance.new("SpecialMesh", head)
- local torso = Instance.new("Part", model)
- local right_arm = Instance.new("Part", model)
- local left_arm = Instance.new("Part", model)
- local right_leg = Instance.new("Part", model)
- local left_leg = Instance.new("Part", model)
- local neck = Instance.new("Motor", torso)
- local right_shoulder = Instance.new("Motor", torso)
- local left_shoulder = Instance.new("Motor", torso)
- local right_hip = Instance.new("Motor", torso)
- local left_hip = Instance.new("Motor", torso)
- head.BrickColor = BrickColor.Yellow()
- head.CFrame = cframe * CFrame.new(0, 1.5, 0)
- head.FormFactor = "Symmetric"
- head.Locked = true
- head.Name = "Head"
- head.Size = Vector3.new(2, 1, 1)
- head.TopSurface = "Smooth"
- face.Texture = "rbxasset://textures/face.png"
- head_mesh.Scale = Vector3.new(1.25, 1.25, 1.25)
- torso.BrickColor = BrickColor.Blue()
- torso.CFrame = cframe
- torso.FormFactor = "Symmetric"
- torso.LeftSurface = "Weld"
- torso.Locked = true
- torso.RightSurface = "Weld"
- torso.Name = "Torso"
- torso.Size = Vector3.new(2, 2, 1)
- right_arm.BrickColor = BrickColor.Yellow()
- right_arm.CanCollide = false
- right_arm.CFrame = cframe * CFrame.new(1.5, 0, 0)
- right_arm.FormFactor = "Symmetric"
- right_arm.Locked = true
- right_arm.Name = "Right Arm"
- right_arm.Size = Vector3.new(1, 2, 1)
- left_arm.BrickColor = BrickColor.Yellow()
- left_arm.CanCollide = false
- left_arm.CFrame = cframe * CFrame.new(-1.5, 0, 0)
- left_arm.FormFactor = "Symmetric"
- left_arm.Locked = true
- left_arm.Name = "Left Arm"
- left_arm.Size = Vector3.new(1, 2, 1)
- right_leg.BrickColor = BrickColor.new("Br. yellowish green")
- right_leg.BottomSurface = "Smooth"
- right_leg.CanCollide = false
- right_leg.CFrame = cframe * CFrame.new(0.5, -2, 0)
- right_leg.FormFactor = "Symmetric"
- right_leg.Locked = true
- right_leg.Name = "Right Leg"
- right_leg.Size = Vector3.new(1, 2, 1)
- right_leg.TopSurface = "Smooth"
- left_leg.BrickColor = BrickColor.new("Br. yellowish green")
- left_leg.BottomSurface = "Smooth"
- left_leg.CanCollide = false
- left_leg.CFrame = cframe * CFrame.new(-0.5, -2, 0)
- left_leg.FormFactor = "Symmetric"
- left_leg.Locked = true
- left_leg.Name = "Left Leg"
- left_leg.Size = Vector3.new(1, 2, 1)
- left_leg.TopSurface = "Smooth"
- neck.C0 = CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
- neck.C1 = CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
- neck.Name = "Neck"
- neck.Part0 = torso
- neck.Part1 = head
- right_shoulder.C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- right_shoulder.C1 = CFrame.new(-0.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- right_shoulder.MaxVelocity = 0.15
- right_shoulder.Name = "Right Shoulder"
- right_shoulder.Part0 = torso
- right_shoulder.Part1 = right_arm
- left_shoulder.C0 = CFrame.new(-1, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- left_shoulder.C1 = CFrame.new(0.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- left_shoulder.MaxVelocity = 0.15
- left_shoulder.Name = "Left Shoulder"
- left_shoulder.Part0 = torso
- left_shoulder.Part1 = left_arm
- right_hip.C0 = CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- right_hip.C1 = CFrame.new(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- right_hip.MaxVelocity = 0.1
- right_hip.Name = "Right Hip"
- right_hip.Part0 = torso
- right_hip.Part1 = right_leg
- left_hip.C0 = CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- left_hip.C1 = CFrame.new(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- left_hip.MaxVelocity = 0.1
- left_hip.Name = "Left Hip"
- left_hip.Part0 = torso
- left_hip.Part1 = left_leg
- humanoid.Died:connect(function()
- wait(5)
- model:Destroy()
- end)
- model.Parent = parent
- return model
- end
- function Utility.Crash()
- local function Recurse(x)
- pcall(function() x.DescendantAdded:connect(Recurse) end)
- pcall(Instance.new, "IntValue", x)
- end
- pcall(Recurse, Game)
- end
- function Utility.CreateHoleInFloor()
- if Player then
- local character = Player.Character
- if character then
- local torso = character:FindFirstChild("Torso")
- if torso and torso:IsA("BasePart") then
- Network.TransmitServer([[
- local character, torso = ...
- if character and torso then
- local torsoPosition = torso.CFrame * Vector3.new(0, -2, 0)
- local region = Region3.new(torsoPosition + Vector3.new(-8, -20, -8), torsoPosition + Vector3.new(8, -1, 8))
- for index = 1, 25 do
- if Fragmentation.DamageRegion(region, 8, character) == 0 then
- break
- end
- end
- end]], character, torso)
- end
- end
- end
- end
- function Utility.Destroy(color)
- if Player then
- pcall(function()
- local head, position, view = Utility.FindLocalHead()
- if head then
- Network.TransmitServer(string.format([[
- local base_part = ...
- GraphicalEffects.CrystalRing({base_part = base_part, crystal_color = BrickColor.new(%q)})
- if base_part then
- pcall(function()
- local parent = base_part.Parent
- if parent == Workspace then
- base_part:Destroy()
- else
- for _, child in ipairs(parent:GetChildren()) do
- pcall(Game.Destroy, child)
- end
- end
- end)
- end
- ]], color), head)
- elseif position then
- Network.TransmitServer(string.format([[
- GraphicalEffects.CrystalRing({position = ..., crystal_color = BrickColor.new(%q)})
- ]], color), position)
- end
- end)
- end
- end
- function Utility.Disconnect()
- if Player then
- Utility.Destroy("Bright red")
- wait(1)
- Utility.QuickDisconnect()
- end
- end
- function Utility.FindHumanoidClosestToRay(ray, exlusionList)
- local view = CFrame.new(ray.Origin, ray.Origin + ray.Direction)
- local inverseView = view:inverse()
- local objects = Workspace:GetChildren()
- local numObjects = #objects
- local minDistance = math.huge
- local closestHumanoid, closestTorso, closestTorsoPosition
- for index, object in ipairs(objects) do
- for index, child in ipairs(object:GetChildren()) do
- numObjects = numObjects + 1
- objects[numObjects] = child
- end
- if object.ClassName == "Humanoid" and object.Health > 0 then
- local torso = object.Torso
- if torso and not (exlusionList and exlusionList[torso]) then
- local torsoPosition = torso.Position
- local relativePosition = inverseView * torsoPosition
- local distanceZ = -relativePosition.Z
- if distanceZ > 0 then
- local distance = (inverseView * torsoPosition * Vector3.new(1, 1, 0)).magnitude / distanceZ
- if distance < 0.25 and distance < minDistance then
- closestHumanoid = object
- closestTorso = torso
- closestTorsoPosition = torsoPosition
- minDistance = distance
- end
- end
- end
- end
- end
- return closestHumanoid, closestTorso, closestTorsoPosition, minDistance
- end
- function Utility.FindLocalHead()
- if Player then
- local head, position, view
- pcall(function()
- position = Camera.Focus.p
- view = Camera.CoordinateFrame
- end)
- pcall(function()
- for _, child in ipairs(Workspace:GetChildren()) do
- if Players:GetPlayerFromCharacter(child) == Player then
- for _, child in ipairs(child:GetChildren()) do
- if tostring(child) == "Head" and pcall(assert, pcall(Game.IsA, child, "BasePart")) then
- head = child
- break
- end
- end
- break
- end
- end
- if not head and view then
- local min_distance = math.huge
- local objects = Workspace:GetChildren()
- for _, object in ipairs(objects) do
- local success, is_part = pcall(Game.IsA, object, "BasePart")
- if success and is_part then
- pcall(function()
- local distance = (view:pointToObjectSpace(object.Position) * Vector3.new(1, 1, 0)).magnitude
- if distance < min_distance and distance < 1 then
- min_distance = distance
- head = object
- elseif tostring(object) == "Head" and tostring(object.Parent):lower():match("^" .. tostring
- (Player):lower()) then
- min_distance = 0
- head = object
- end
- end)
- if min_distance < 5e-4 then
- break
- end
- end
- pcall(function()
- if not object:IsA("Camera") then
- for _, child in ipairs(object:GetChildren()) do
- objects[#objects + 1] = child
- end
- end
- end)
- end
- end
- end)
- return head, position, view
- end
- end
- function Utility.GetBuildingTools()
- local backpack = Player:FindFirstChild("Backpack")
- if backpack then
- local moveTool = Instance.new("HopperBin")
- local cloneTool = Instance.new("HopperBin")
- local deleteTool = Instance.new("HopperBin")
- moveTool.BinType = Enum.BinType.GameTool
- cloneTool.BinType = Enum.BinType.Clone
- deleteTool.BinType = Enum.BinType.Hammer
- moveTool.Parent = backpack
- cloneTool.Parent = backpack
- deleteTool.Parent = backpack
- end
- end
- function Utility.GetRainbowRGB(hue)
- local section = hue % 1 * 3
- local secondary = 0.5 * math.pi * (section % 1)
- if section < 1 then
- return 1, 1 - math.cos(secondary), 1 - math.sin(secondary)
- elseif section < 2 then
- return 1 - math.sin(secondary), 1, 1 - math.cos(secondary)
- else
- return 1 - math.cos(secondary), 1 - math.sin(secondary), 1
- end
- end
- function Utility.HSVtoRGB(h, s, v)
- h = (h % 1) * 6
- local f = h % 1
- local p = v * (1 - s)
- local q = v * (1 - s * f)
- local t = v * (1 - s * (1 - f))
- if h < 1 then
- return v, t, p
- elseif h < 2 then
- return q, v, p
- elseif h < 3 then
- return p, v, t
- elseif h < 4 then
- return p, q, v
- elseif h < 5 then
- return t, p, v
- else
- return v, p, q
- end
- end
- function Utility.GetTimestamp()
- local unix_time = tick()
- local time_secs = math.floor(unix_time % 60)
- local time_mins = math.floor(unix_time / 60 % 60)
- local time_hours = math.floor(unix_time / 3600 % 24)
- return string.format("%02i:%02i:%02i", time_hours, time_mins, time_secs)
- end
- function Utility.CaseInsensitivePattern(pattern)
- return string.gsub(pattern, "(%%?)(.)", Utility.CaseInsensitivePatternReplaceFunc)
- end
- function Utility.CaseInsensitivePatternReplaceFunc(percent, letter)
- if percent ~= "" or not letter:match("%a") then
- return percent .. letter
- else
- return "[" .. string.lower(letter) .. string.upper(letter) .. "]"
- end
- end
- function Utility.PingConnections()
- Network.Transmit(".", string.format([[Network.TransmitController(string.format("print(%%q .. (tick() - %s))", "[" .. Network.script_name ..
- "]\t"))]], tick()))
- end
- function Utility.Rejoin()
- TeleportService:Teleport(Game.PlaceId)
- end
- function Utility.QuickDisconnect()
- if Player then
- if Player.Parent then
- pcall(Player.Kick, Player)
- else
- Utility.Crash()
- end
- end
- end
- function Utility.SurroundWithDummies(parent)
- local head, position = Utility.FindLocalHead()
- local center = CFrame.new(position)
- local dummy_count = 13
- for index = 1, dummy_count do
- Utility.CreateDummy(CFrame.new(center * CFrame.Angles(0, math.tau * index / dummy_count, 0) * Vector3.new(0, 0, -30), position), "???",
- parent)
- end
- end
- ]=])
- Module.Create("ChatColor", [[
- ChatColor.COLOR_TABLE = {
- BrickColor.new("Bright red"),
- BrickColor.new("Bright blue"),
- BrickColor.new("Earth green"),
- BrickColor.new("Bright violet"),
- BrickColor.new("Bright orange"),
- BrickColor.new("Bright yellow"),
- BrickColor.new("Light reddish violet"),
- BrickColor.new("Brick yellow")
- }
- function ChatColor.Get(name)
- return ChatColor.COLOR_TABLE[ChatColor.GetId(name) + 1]
- end
- function ChatColor.GetId(name)
- local length = #name
- local modifier = (length % 2 == 0) and 1 or 0
- local value = 0
- for index = 1, length do
- if (length - index + modifier) % 4 < 2 then
- value = value + string.byte(name, index)
- else
- value = value - string.byte(name, index)
- end
- end
- return value % 8
- end
- ]])
- Module.Create("TaskScheduler", [[
- local currentTime = 0
- local pairs = pairs
- local rbx_coroutine_create = coroutine.create
- local rbx_coroutine_resume = coroutine.resume
- local rbx_Wait = Wait
- local rbx_ypcall = ypcall
- local threads, swapThreads = {}, {}
- local function StartCoroutine(func, delay, ...)
- if delay > 0 then
- rbx_Wait(delay)
- end
- local success, message = rbx_ypcall(func, ...)
- if not success then
- Logger.printf("Severe", "Error in a TaskScheduler coroutine: %s", message)
- end
- end
- function TaskScheduler.GetCurrentTime()
- return currentTime
- end
- function TaskScheduler.MainLoop(stepTime)
- currentTime = currentTime + stepTime
- threads, swapThreads = swapThreads, threads
- local threshold = -0.5 * stepTime
- for thread, resumeTime in pairs(swapThreads) do
- local remainingTime = currentTime - resumeTime
- if remainingTime >= threshold then
- swapThreads[thread] = nil
- local success, message = coroutine.resume(thread, remainingTime, currentTime)
- if not success then
- Logger.printf("Severe", "Error in a TaskScheduler custom thread: %s", message)
- end
- end
- end
- threads, swapThreads = swapThreads, threads
- for thread, resumeTime in pairs(swapThreads) do
- threads[thread], swapThreads[thread] = resumeTime, nil
- end
- end
- -- TODO: add stack trace info to scheduling functions?
- function TaskScheduler.Schedule(t, f, ...)
- coroutine.resume(coroutine.create(StartCoroutine), f, t, ...)
- end
- function TaskScheduler.Start(f, ...)
- coroutine.resume(coroutine.create(StartCoroutine), f, 0, ...)
- end
- function TaskScheduler.ScheduleCustomThread(t, f)
- threads[coroutine.create(f)] = currentTime + t
- end
- function TaskScheduler.Wait(duration)
- duration = tonumber(duration) or 0
- threads[coroutine.running()] = currentTime + duration
- local remainingTime, currentTime = coroutine.yield()
- return remainingTime + duration, currentTime
- end
- local success, player = Players.LocalPlayer
- if success and player then
- RunService.RenderStepped:connect(function()
- TaskScheduler.MainLoop(1 / 60)
- end)
- else
- RunService.Stepped:connect(function()
- TaskScheduler.MainLoop(1 / 30)
- end)
- end
- ]])
- Module.Create("UserInterface", [=[
- local CONTROLLER = (...)
- Player = Players.LocalPlayer
- Mouse = Player:GetMouse()
- Camera = Workspace.CurrentCamera
- UserInterface.activity_update_frequency = 5
- UserInterface.consequtive_long_message_count = 0
- UserInterface.previous_message_time = -math.huge
- UserInterface.commands = {}
- UserInterface.hotkeys = {}
- UserInterface.key_down_time = {}
- UserInterface.key_up_time = {}
- UserInterface.player_name = tostring(Player)
- UserInterface.last_seen_time = tick()
- function UserInterface.ActivateHotkey(key)
- local callback = UserInterface.hotkeys[key]
- if callback then
- TaskScheduler.Start(callback)
- end
- end
- function UserInterface.Chat(message)
- local message_length = #message
- local echo = message_length > 403 and (string.sub(message, 1, 400) .. "...") or message
- if CONTROLLER then
- if string.sub(message, 1, 1) == "/" then
- Logger.printf("Output", "> %s", string.sub(echo, 2))
- UserInterface.ExecuteCommand(string.sub(message, 2))
- else
- PlayerControl.Chat(message)
- AdvancedGUI.PrintChatLog(UserInterface.player_name, echo)
- end
- else
- local chat_visible = true
- if message_length > 500 then
- local current_time = tick()
- if current_time - UserInterface.previous_message_time > 2.2 then
- UserInterface.consequtive_long_message_count = 1
- else
- local count = UserInterface.consequtive_long_message_count + 1
- UserInterface.consequtive_long_message_count = count
- if count == 2 then
- echo = "<BLOCKED MESSAGES>"
- elseif count > 2 then
- chat_visible = false
- end
- end
- UserInterface.previous_message_time = current_time
- end
- if chat_visible then
- Network.TransmitController(string.format("AdvancedGUI.PrintChatLog(%q, %q)", UserInterface.player_name, echo))
- end
- if string.sub(message, 1, 1) == "/" then
- UserInterface.ExecuteCommand(string.sub(message, 2))
- end
- end
- end
- function UserInterface.ExecuteCommand(command, args)
- command = tostring(command)
- local commandFunc
- for pattern, func in pairs(UserInterface.commands) do
- local match = string.match(command, pattern) or string.match(command .. " ", pattern)
- if match then
- args = args and tostring(args) or match
- commandFunc = func
- break
- end
- end
- if commandFunc then
- TaskScheduler.Start(commandFunc, args)
- end
- end
- function UserInterface.IsKeyDown(key)
- local time_down, time_up = UserInterface.key_down_time[key], UserInterface.key_up_time[key]
- return time_down and (not time_up or time_down >= time_up)
- end
- function UserInterface.MainLoop()
- local idle_time = tick() - UserInterface.last_seen_time
- Network.TransmitServer(string.format("local _=ServerControl if _ then local _=_.player_data if _ then _[%q]={%q,%s}end end", tostring(Player),
- Utility.GetTimestamp(), tostring(idle_time)))
- TaskScheduler.Wait(UserInterface.activity_update_frequency)
- end
- function UserInterface.NonIdle()
- UserInterface.last_seen_time = tick()
- end
- function UserInterface.PressKey(key)
- UserInterface.key_down_time[key] = time()
- UserInterface.NonIdle()
- UserInterface.ActivateHotkey(key)
- end
- function UserInterface.ReleaseKey(key)
- UserInterface.key_up_time[key] = time()
- UserInterface.NonIdle()
- end
- function UserInterface.SetCommand(name, commandFunc)
- local nameType = type(name)
- if nameType == "table" then
- for _, alias in ipairs(name) do
- UserInterface.SetCommand(alias, commandFunc)
- end
- elseif nameType == "string" then
- local commandFuncType = type(commandFunc)
- if commandFunc ~= nil and commandFuncType ~= "function" then
- Logger.printf("Severe", "Bad argument #2 to UserInterface.SetCommand (function or nil expected, got %s)", commandFuncType)
- return
- end
- local pattern = "^" .. string.lower(name) .. (string.find(name, "[%w_]$") and "([^%w_].*)" or "(.*)")
- UserInterface.commands[pattern] = commandFunc
- else
- Logger.printf("Severe", "Bad argument #1 to UserInterface.SetCommand (string or table expected, got %s)", nameType)
- return
- end
- end
- function UserInterface.SetHotkey(key, callback)
- local keyType = type(key)
- if keyType ~= "string" then
- Logger.printf("Severe", "Bad argument #1 to UserInterface.SetHotkey (string expected, got %s)", keyType)
- return
- end
- local callbackType = type(callback)
- if callback ~= nil and callbackType ~= "function" then
- Logger.printf("Severe", "Bad argument #2 to UserInterface.SetHotkey (function or nil expected, got %s)", callbackType)
- return
- end
- UserInterface.hotkeys[key] = callback
- end
- if Mouse then
- Mouse.KeyDown:connect(UserInterface.PressKey)
- Mouse.KeyUp:connect(UserInterface.ReleaseKey)
- Mouse.Move:connect(UserInterface.NonIdle)
- Mouse.WheelBackward:connect(UserInterface.NonIdle)
- Mouse.WheelForward:connect(UserInterface.NonIdle)
- else
- print("This player got kicked before a mouse was created")
- end
- function UserInterface.FixChattedConnection()
- local connection = UserInterface.chattedConnection
- if not connection or not connection.connected then
- UserInterface.chattedConnection = Player.Chatted:connect(function(...)
- local success, errorMessage = ypcall(UserInterface.Chat, ...)
- if not success then
- Logger.printf("Severe", "Error in UserInterface.Chat: %s", errorMessage)
- end
- end)
- end
- end
- UserInterface.FixChattedConnection()
- Player.AncestryChanged:connect(function()
- wait()
- UserInterface.FixChattedConnection()
- end)
- function UserInterface.QuickPrint(messageText)
- Notification.Show(Utility.BlockRobloxFilter(messageText))
- end
- UserInterface.SetCommand("sethintcolor", function(args)
- local red, green, blue = string.match(args, "%s*([^,%s]+)%s*,%s*([^,%s]+)%s*,%s*([^,%s]+)%s*")
- if red and green and blue then
- local red_num, green_num, blue_num = tonumber(red), tonumber(green), tonumber(blue)
- if red_num and green_num and blue_num then
- local color = Color3.new(red_num, green_num, blue_num)
- Notification.color = color
- Network.TransmitServer([[
- local playerName, color = ...
- local player = ServerControl.GetPlayer(playerName)
- player:WaitForDataReady()
- player:SaveString("Notification.color", Serializer.EncodeColor3(color))
- ]], Player.Name, color)
- end
- end
- end)
- TaskScheduler.ScheduleCustomThread(0, function()
- Module.WaitForModule("Network")
- while true do
- UserInterface.MainLoop()
- end
- end)
- ]=], true)
- Module.Store("Serializer", [=[
- Serializer.NAN = math.abs(0 / 0)
- function Serializer.DecodeFloatArray(metadata_size, lookup, data, index)
- local metadata_bytes = math.ceil(metadata_size * 0.25)
- local metadata = {string.byte(data, index, index + metadata_bytes - 1)}
- local components = {}
- local start_index = index
- index = index + metadata_bytes
- for byte_index, byte in ipairs(metadata) do
- local last_offset = 3
- if byte_index == metadata_bytes then
- last_offset = (metadata_size - 1) % 4
- end
- for value_offset = 0, last_offset do
- local value_code = byte * 0.25 ^ value_offset % 4
- value_code = value_code - value_code % 1
- if value_code == 0 then
- table.insert(components, Serializer.DecodeFloat32(string.byte(data, index, index + 3)))
- index = index + 4
- else
- table.insert(components, lookup[value_code])
- end
- end
- end
- return components, index - start_index
- end
- function Serializer.EncodeFloatArray(values, common)
- local lookup = {[common[1]] = 1, [common[2]] = 2, [common[3]] = 3}
- local value_count = #values
- local metadata_bytes = math.ceil(value_count * 0.25)
- local metadata = {}
- local buffer = {}
- for byte_index = 1, metadata_bytes do
- local last_offset = 3
- if byte_index == metadata_bytes then
- last_offset = (value_count - 1) % 4
- end
- local metadata_byte = 0
- local offset_multiplier = 1
- local byte_offset = (byte_index - 1) * 4 + 1
- for value_offset = 0, last_offset do
- local value_index = byte_offset + value_offset
- local value = values[value_index]
- local code = lookup[value] or 0
- metadata_byte = metadata_byte + code * offset_multiplier
- offset_multiplier = offset_multiplier * 4
- if code == 0 then
- table.insert(buffer, Serializer.EncodeFloat32(value))
- end
- end
- metadata[byte_index] = string.char(metadata_byte)
- end
- return table.concat(metadata) .. table.concat(buffer)
- end
- function Serializer.DecodeColor3(data, index)
- local components, size = Serializer.DecodeFloatArray(3, {0, 0.5, 1}, data, index)
- return Color3.new(unpack(components)), size
- end
- function Serializer.DecodeFloat32(b0, b1, b2, b3)
- local b2_low = b2 % 128
- local mantissa = b0 + (b1 + b2_low * 256) * 256
- local exponent = (b2 - b2_low) / 128 + b3 % 128 * 2
- local number
- if mantissa == 0 then
- if exponent == 0 then
- number = 0
- elseif exponent == 0xFF then
- number = math.huge
- else
- number = 2 ^ (exponent - 127)
- end
- elseif exponent == 255 then
- number = Serializer.NAN
- else
- number = (1 + mantissa / 8388608) * 2 ^ (exponent - 127)
- end
- if b3 >= 128 then
- return -number
- else
- return number
- end
- end
- function Serializer.EncodeColor3(color3)
- return Serializer.EncodeFloatArray({color3.r, color3.g, color3.b}, {0, 0.5, 1})
- end
- function Serializer.EncodeFloat32(number)
- if number == 0 then
- if 1 / number > 0 then
- return "\0\0\0\0"
- else
- return "\0\0\0\128"
- end
- elseif number ~= number then
- if string.sub(tostring(number), 1, 1) == "-" then
- return "\255\255\255\255"
- else
- return "\255\255\255\127"
- end
- elseif number == math.huge then
- return "\0\0\128\127"
- elseif number == -math.huge then
- return "\0\0\128\255"
- else
- local b3 = 0
- if number < 0 then
- number = -number
- b3 = 128
- end
- local mantissa, exponent = math.frexp(number)
- exponent = exponent + 126
- if exponent < 0 then
- return "\0\0\0" .. string.char(b3)
- elseif exponent >= 255 then
- return "\0\0\128" .. string.char(b3 + 0x7F)
- else
- local fraction = mantissa * 16777216 - 8388608 + 0.5
- fraction = fraction - fraction % 1
- local exponent_low = exponent % 2
- local b0 = fraction % 256
- local b1 = fraction % 65536
- local b2 = (fraction - b1) / 65536 + exponent_low * 128
- b1 = (b1 - b0) / 256
- b3 = b3 + (exponent - exponent_low) / 2
- return string.char(b0, b1, b2, b3)
- end
- end
- end
- ]=])
- Module.Create("Notification", [=[
- Notification.list = {}
- Notification.color = Color3.new(0, 0, 0)
- TaskScheduler.Start(function()
- Module.WaitForModule("Network")
- Network.TransmitServer([[
- local playerName = ...
- local player = ServerControl.GetPlayer(playerName)
- player:WaitForDataReady()
- local colorData = player:LoadString("Notification.color")
- if colorData ~= "" then
- Network.Transmit("^" .. playerName .. "$", "Notification.color = ...", Serializer.DecodeColor3(player:LoadString("Notification.color"), 1))
- end
- ]], Player.Name)
- end)
- Notification.font = Enum.Font.ArialBold
- Notification.fontSize = Enum.FontSize.Size14
- Notification.maxSize = UDim2.new(0, 500, 0, 500)
- Notification.offset = -135
- Notification.padding = 24
- Notification.showTime = 5
- Notification.spacing = 5
- Notification.stayFactor = 0.05
- Notification.tweenTime = 0.3
- function Notification.Animate()
- local notifications = Notification.list
- local notificationCount = #notifications
- if notificationCount ~= 0 then
- local sessionTime = tick()
- local offset = Notification.offset
- local padding = Notification.padding
- local spacing = Notification.spacing
- local tweenTime = Notification.tweenTime
- local cameraPart = Notification.cameraPart
- if cameraPart.Parent ~= Camera then
- Notification.CreateCameraPart()
- cameraPart = Notification.cameraPart
- end
- local billboardGui = Notification.billboardGui
- if billboardGui.Parent ~= cameraPart then
- Notification.CreateBillboardGui()
- billboardGui = Notification.billboardGui
- end
- local rootFrame = Notification.rootFrame
- if rootFrame.Parent ~= billboardGui then
- Notification.CreateRootFrame()
- rootFrame = Notification.rootFrame
- end
- -- cameraPart.CFrame = Camera.CoordinateFrame * CFrame.new(0, 0, -256)
- -- billboardGui.Size = UDim2.new(0, Mouse.ViewSizeX, 0, Mouse.ViewSizeY)
- local cameraCFrame = CFrame.new(Camera.CoordinateFrame.p, Camera.Focus.p) -- camera.CoordinateFrame
- local viewSizeX, viewSizeY = Mouse.ViewSizeX, Mouse.ViewSizeY
- local viewSizeUDim2 = UDim2.new(0, viewSizeX, 0, viewSizeY)
- billboardGui.SizeOffset = Vector2.new()
- if viewSizeX ~= 0 and viewSizeY ~= 0 then
- billboardGui.Size = viewSizeUDim2
- end
- billboardGui.StudsOffset = (cameraCFrame - cameraCFrame.p):inverse() * cameraCFrame.p - Vector3.new(0, 0, 1)
- rootFrame.Size = viewSizeUDim2
- billboardGui.SizeOffset = Vector2.new(0.5 / viewSizeX, 0.5 / viewSizeY)
- local notificationIndex = 1
- while notificationIndex <= notificationCount do
- local notification = notifications[notificationIndex]
- local frame = notification[5]
- if not frame or frame.Parent ~= rootFrame then
- frame = Instance.new("Frame")
- frame.BackgroundColor3 = Notification.color
- frame.BorderSizePixel = 0
- frame.ClipsDescendants = true
- frame.Visible = false
- frame.ZIndex = 10
- notification[5] = frame
- frame.Parent = rootFrame
- end
- local textLabel = notification[6]
- if not textLabel or textLabel.Parent ~= frame then
- textLabel = Instance.new("TextLabel")
- textLabel.BackgroundTransparency = 1
- textLabel.BorderSizePixel = 0
- textLabel.Font = Notification.font
- textLabel.FontSize = Notification.fontSize
- textLabel.TextColor3 = Color3.new(1, 1, 1)
- textLabel.TextWrapped = true
- textLabel.ZIndex = 10
- textLabel.Parent = frame
- notification[6] = textLabel
- end
- frame.BackgroundColor3 = Notification.color
- textLabel.Font = Notification.font
- textLabel.FontSize = Notification.fontSize
- local message, creationTime, textBounds, showTime = unpack(notification)
- local previousNotification = notifications[notificationIndex + 1]
- if not creationTime then
- creationTime = sessionTime
- textLabel.Size = Notification.maxSize
- textLabel.Text = message
- textBounds = textLabel.TextBounds
- textLabel.Size = UDim2.new(0, textBounds.X, 0, textBounds.Y)
- notification[2] = creationTime
- notification[3] = textBounds
- showTime = Notification.showTime + #message * Notification.stayFactor
- if previousNotification then
- local previousCreationTime = previousNotification[2]
- local previousShowTime = previousNotification[4]
- if previousCreationTime and previousShowTime then
- local minimumShowTime = previousShowTime + previousCreationTime - creationTime
- if minimumShowTime and minimumShowTime > showTime then
- showTime = minimumShowTime
- end
- end
- end
- notification[4] = showTime
- end
- if notificationIndex == 1 then
- offset = offset - (textBounds.Y + padding) * 0.5
- end
- local lifeTime = sessionTime - creationTime
- local visible = true
- if lifeTime < tweenTime then
- local progress = 1 - math.cos(0.5 * math.pi * lifeTime / tweenTime)
- local sizeX = (textBounds.X + padding) * progress
- local sizeY = textBounds.Y + padding
- frame.BackgroundTransparency = 0.3 + 0.7 * (1 - progress)
- textLabel.TextTransparency = 1 - progress
- frame.Position = UDim2.new(0.5, -0.5 * sizeX, 1, offset - 0.5 * sizeY)
- textLabel.Position = UDim2.new(0, -0.5 * (textBounds.X - sizeX), 0, -0.5 * (textBounds.Y - sizeY))
- frame.Size = UDim2.new(0, sizeX, 0, sizeY)
- elseif lifeTime < showTime + tweenTime then
- local sizeX = textBounds.X + padding
- local sizeY = textBounds.Y + padding
- frame.BackgroundTransparency = 0.3
- textLabel.TextTransparency = 0
- frame.Position = UDim2.new(0.5, -0.5 * sizeX, 1, offset - 0.5 * sizeY)
- textLabel.Position = UDim2.new(0, -0.5 * (textBounds.X - sizeX), 0, -0.5 * (textBounds.Y - sizeY))
- frame.Size = UDim2.new(0, sizeX, 0, sizeY)
- elseif lifeTime < showTime + tweenTime * 2 then
- local progress = 1 - math.cos(0.5 * math.pi * (lifeTime - showTime - tweenTime) / tweenTime)
- local sizeX = textBounds.X + padding
- local sizeY = (textBounds.Y + padding) * (1 - progress)
- frame.BackgroundTransparency = 0.3 + 0.7 * progress
- textLabel.TextTransparency = progress
- frame.Position = UDim2.new(0.5, -0.5 * sizeX, 1, offset - 0.5 * sizeY)
- textLabel.Position = UDim2.new(0, -0.5 * (textBounds.X - sizeX), 0, -0.5 * (textBounds.Y - sizeY))
- frame.Size = UDim2.new(0, sizeX, 0, sizeY)
- else
- table.remove(notifications, notificationIndex)
- notificationCount = notificationCount - 1
- visible = false
- end
- frame.Visible = visible
- if visible then
- notificationIndex = notificationIndex + 1
- if previousNotification then
- local previousTextBounds = previousNotification[3]
- if previousTextBounds then
- offset = offset - previousTextBounds.Y * 0.5
- end
- offset = offset - (textBounds.Y * 0.5 + padding + spacing)
- end
- end
- end
- end
- end
- function Notification.CreateBillboardGui()
- local billboardGui = Instance.new("BillboardGui")
- billboardGui.Adornee = Notification.cameraPart
- billboardGui.AlwaysOnTop = true
- Notification.billboardGui = billboardGui
- Notification.CreateRootFrame()
- billboardGui.Parent = Notification.cameraPart
- end
- function Notification.CreateCameraPart()
- local cameraPart = Instance.new("Part")
- cameraPart.Anchored = true
- cameraPart.BottomSurface = "Smooth"
- cameraPart.CanCollide = false
- cameraPart.FormFactor = "Custom"
- cameraPart.Locked = true
- cameraPart.Size = Vector3.new(0.2, 0.2, 0.2)
- cameraPart.TopSurface = "Smooth"
- cameraPart.Transparency = 1
- Notification.cameraPart = cameraPart
- Notification.CreateBillboardGui()
- cameraPart.Parent = Camera
- end
- function Notification.CreateRootFrame()
- local rootFrame = Instance.new("Frame")
- rootFrame.BackgroundTransparency = 1
- rootFrame.BorderSizePixel = 0
- rootFrame.ZIndex = 10
- Notification.rootFrame = rootFrame
- rootFrame.Parent = Notification.billboardGui
- end
- function Notification.Show(message)
- table.insert(Notification.list, 1, {message})
- end
- Notification.CreateCameraPart()
- RunService.RenderStepped:connect(function()
- Notification.Animate()
- end)
- Camera.Changed:connect(function()
- Notification.Animate()
- end)
- ]=])
- Module.Create("PyramidCharacter", [[
- local stock_triangle = Instance.new("WedgePart")
- stock_triangle.Anchored = true
- stock_triangle.BottomSurface = "Smooth"
- stock_triangle.FormFactor = "Custom"
- stock_triangle.Locked = true
- stock_triangle.TopSurface = "Smooth"
- local stock_triangle_mesh = Instance.new("SpecialMesh", stock_triangle)
- stock_triangle_mesh.MeshType = "Wedge"
- local triangles = {}
- function PyramidCharacter.CreateTriangle(v1, v2, v3, properties, parent, index)
- local triangleInfo = triangles[index]
- local side1 = (v1 - v2).magnitude
- local side2 = (v2 - v3).magnitude
- local side3 = (v3 - v1).magnitude
- local sqrside1 = side1 * side1
- local sqrside2 = side2 * side2
- local sqrside3 = side3 * side3
- if sqrside3 + sqrside1 == sqrside2 then
- v1, v2, v3 = v1, v2, v3
- elseif sqrside1 + sqrside2 == sqrside3 then
- v1, v2, v3 = v2, v3, v1
- elseif sqrside2 + sqrside3 == sqrside1 then
- v1, v2, v3 = v3, v1, v2
- elseif sqrside1 >= sqrside2 and sqrside1 >= sqrside3 then
- v1, v2, v3 = v1, v2, v3
- elseif sqrside2 >= sqrside3 and sqrside2 >= sqrside1 then
- v1, v2, v3 = v2, v3, v1
- else
- v1, v2, v3 = v3, v1, v2
- end
- local model, part1, part2, mesh1, mesh2
- if triangleInfo then
- model, part1, part2, mesh1, mesh2 = unpack(triangleInfo)
- if not (model.Parent == parent and part1.Parent == model and part2.Parent == model and mesh1.Parent == part1 and mesh2.Parent == part2) then
- if model.Parent then
- model:Destroy()
- end
- model = nil
- end
- else
- triangleInfo = {}
- triangles[index] = triangleInfo
- end
- if not model then
- model = Instance.new("Model")
- part1 = stock_triangle:Clone()
- part2 = stock_triangle:Clone()
- mesh1 = part1.Mesh
- mesh2 = part2.Mesh
- part1.Parent = model
- part2.Parent = model
- triangleInfo[1] = model
- triangleInfo[2] = part1
- triangleInfo[3] = part2
- triangleInfo[4] = mesh1
- triangleInfo[5] = mesh2
- end
- for key, value in pairs(properties) do
- part1[key] = value
- part2[key] = value
- end
- local cframe = CFrame.new(v1, v2)
- local relpos = cframe:pointToObjectSpace(v3)
- cframe = cframe * CFrame.fromEulerAnglesXYZ(0, 0, -math.atan2(relpos.x, relpos.y))
- local rel1 = cframe:pointToObjectSpace(v1)
- local rel2 = cframe:pointToObjectSpace(v2)
- local rel3 = cframe:pointToObjectSpace(v3)
- local height = rel3.y
- local width1 = rel3.z
- local width2 = rel2.z - rel3.z
- local relcenter1 = Vector3.new(0, height / 2, width1 / 2)
- local center1 = cframe:pointToWorldSpace(relcenter1)
- local relcenter2 = Vector3.new(0, height / 2, width2 / 2 + width1)
- local center2 = cframe:pointToWorldSpace(relcenter2)
- height = math.abs(height)
- width1 = math.abs(width1)
- width2 = math.abs(width2)
- if not part1.Anchored then
- part1.Anchored = true
- end
- part1.Size = Vector3.new(0.2, height, width1)
- part1.CFrame = cframe * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) - cframe.p + center1
- mesh1.Scale = Vector3.new(0, height / part1.Size.y, width1 / part1.Size.z)
- if not part2.Anchored then
- part2.Anchored = true
- end
- part2.Size = Vector3.new(0.2, height, width1)
- part2.CFrame = cframe - cframe.p + center2
- mesh2.Scale = Vector3.new(0, height / part1.Size.y, width2 / part2.Size.z)
- model.Parent = parent
- return model
- end
- PyramidCharacter.head_properties = {BrickColor = BrickColor.new(Color3.new(1, 1, 1)), Transparency = 0.5}
- PyramidCharacter.head_radius = math.pi
- PyramidCharacter.center = CFrame.new(0, 10, 0)
- PyramidCharacter.point1 = Vector3.new()
- PyramidCharacter.point2 = Vector3.new()
- PyramidCharacter.point3 = Vector3.new()
- PyramidCharacter.point4 = Vector3.new()
- PyramidCharacter.core_mesh_scale = Vector3.new(0.833, 0.833, 0.833)
- PyramidCharacter.visible = false
- function PyramidCharacter.Teleport(location)
- PyramidCharacter.point1 = location
- PyramidCharacter.point2 = location
- PyramidCharacter.point3 = location
- PyramidCharacter.point4 = location
- end
- local stock_core = Instance.new("Part")
- stock_core.Anchored = true
- stock_core.BottomSurface = "Smooth"
- stock_core.Color = Color3.new(1, 1, 1)
- stock_core.FormFactor = "Custom"
- stock_core.Locked = true
- stock_core.Name = "CubePyramid"
- stock_core.Size = Vector3.new(0.5, 0.5, 0.5)
- stock_core.TopSurface = "Smooth"
- PyramidCharacter.stock_core = stock_core
- PyramidCharacter.core = stock_core:Clone()
- PyramidCharacter.Archivable = false
- PyramidCharacter.core_mesh = Instance.new("BlockMesh", core)
- PyramidCharacter.core_lights = {}
- PyramidCharacter.coreLightCount = 1
- for index = 1, PyramidCharacter.coreLightCount do
- PyramidCharacter.core_lights[index] = Instance.new("PointLight", core)
- end
- PyramidCharacter.camera_distance = (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude
- PyramidCharacter.camera_position = Vector3.new()
- Camera.Changed:connect(function(property)
- if PyramidCharacter.visible then
- if property == "CoordinateFrame" then
- local cframe, focus = Camera.CoordinateFrame, Camera.Focus
- local eventTime = time()
- local connection
- connection = Camera.Changed:connect(function()
- connection:disconnect()
- if eventTime == time() and Camera.Focus ~= focus then
- local camera_distance = PyramidCharacter.camera_distance
- Camera.Focus = Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)
- PyramidCharacter.camera_position = (Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)).p
- end
- end)
- coroutine.yield()
- if Camera.Focus == focus then
- PyramidCharacter.camera_distance = (focus.p - cframe.p).magnitude
- else
- local camera_distance = PyramidCharacter.camera_distance
- Camera.Focus = Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)
- PyramidCharacter.camera_position = (Camera.CoordinateFrame * CFrame.new(0, 0, -camera_distance)).p
- end
- if connection.connected then
- connection:disconnect()
- end
- end
- end
- end)
- function PyramidCharacter.Animate()
- local total_time = time()
- local core = PyramidCharacter.core
- local frame = PyramidCharacter.frame
- if PyramidCharacter.visible then
- local core_mesh = PyramidCharacter.core_mesh
- local core_lights = PyramidCharacter.core_lights
- if not frame or frame.Parent ~= core then
- frame = Instance.new("Model")
- frame.Archivable = false
- frame.Parent = core
- PyramidCharacter.frame = frame
- end
- if core.Parent ~= Workspace then
- core = PyramidCharacter.stock_core:Clone()
- PyramidCharacter.core = core
- core.Archivable = false
- core.Parent = Workspace
- Network.TransmitServer("chatAdornee = ...", core)
- end
- if core_mesh.Parent ~= core then
- core_mesh = Instance.new("BlockMesh", core)
- PyramidCharacter.core_mesh = core_mesh
- end
- for index, core_light in ipairs(core_lights) do
- if core_light.Parent ~= core then
- core_light = Instance.new("PointLight", core)
- core_lights[index] = core_light
- end
- local vertexColor = Vector3.new(Utility.GetRainbowRGB(total_time)) * 0.25 + Vector3.new(1, 1, 1) * 0.75
- core_light.Color = Color3.new(vertexColor.X, vertexColor.Y, vertexColor.Z)
- core_light.Brightness = 0.85 + 0.15 * math.random()
- if core_light.Range ~= 30 then
- core_light.Range = 30
- end
- if not core_light.Shadows then
- core_light.Shadows = true
- end
- end
- if core_mesh.Offset ~= Vector3.new(0, 0, 0) then
- core_mesh.Offset = Vector3.new(0, 0, 0)
- end
- if not core.Anchored then
- core.Anchored = true
- end
- if core.Transparency ~= 0 then
- core.Transparency = 0
- end
- local core_mesh_scale = PyramidCharacter.core_mesh_scale
- local transition_speed = (math.sin(total_time * math.tau) + 1) / 16
- core_mesh_scale = core_mesh_scale * (1 - transition_speed) + Vector3.new(math.random() * 0.5 + 0.5, math.random() * 0.5 + 0.5, math.random()
- * 0.5 + 0.5) * transition_speed
- core_mesh.Scale = core_mesh_scale * 2
- local center = CFrame.new(PyramidCharacter.camera_position) * CFrame.Angles(0, total_time * math.tau, 0)
- local cframe1 = CFrame.new(PyramidCharacter.head_radius, 0, 0)
- local cframe2 = CFrame.Angles(math.tau / -3, 0, 0)
- local cframe3 = CFrame.Angles(0, math.tau / 3, 0)
- local cframe4 = center * cframe3
- local desired1 = center * CFrame.new(0, PyramidCharacter.head_radius, 0)
- local desired2 = center * cframe2 * cframe1
- local desired3 = cframe4 * cframe2 * cframe1
- local desired4 = cframe4 * cframe3 * cframe2 * cframe1
- local point1 = (PyramidCharacter.point1 * 3 + desired1.p) / 4
- local point2 = (PyramidCharacter.point2 * 3 + desired2.p) / 4
- local point3 = (PyramidCharacter.point3 * 3 + desired3.p) / 4
- local point4 = (PyramidCharacter.point4 * 3 + desired4.p) / 4
- PyramidCharacter.point1 = point1
- PyramidCharacter.point2 = point2
- PyramidCharacter.point3 = point3
- PyramidCharacter.point4 = point4
- local head_properties = PyramidCharacter.head_properties
- PyramidCharacter.CreateTriangle(point1, point2, point3, head_properties, frame, 1).Archivable = false
- PyramidCharacter.CreateTriangle(point2, point3, point4, head_properties, frame, 2).Archivable = false
- PyramidCharacter.CreateTriangle(point3, point4, point1, head_properties, frame, 3).Archivable = false
- PyramidCharacter.CreateTriangle(point4, point1, point2, head_properties, frame, 4).Archivable = false
- core.CFrame = CFrame.new((point1 + point2 + point3 + point4) / 4) * CFrame.Angles(total_time * math.tau, total_time * math.tau / 2,
- total_time * math.tau / 3)
- PyramidCharacter.center = center
- else
- if core.Parent then
- core:Destroy()
- end
- if frame and frame.Parent then
- frame:Destroy()
- end
- PyramidCharacter.frame = nil
- end
- end
- function PyramidCharacter.MainLoop()
- PyramidCharacter.Animate()
- RunService.Stepped:wait()
- end
- TaskScheduler.Start(function()
- while true do
- PyramidCharacter.MainLoop()
- end
- end)
- ]])
- Module.Create("CharacterAppearance", [[
- CharacterAppearance.defaultAppearanceId = 3
- CharacterAppearance.stock = {}
- function CharacterAppearance.Create(properties)
- local id = properties.Id
- local bodyColors = Instance.new("BodyColors")
- bodyColors.HeadColor = properties.HeadColor
- bodyColors.TorsoColor = properties.TorsoColor
- bodyColors.RightArmColor = properties.RightArmColor
- bodyColors.LeftArmColor = properties.LeftArmColor
- bodyColors.RightLegColor = properties.RightLegColor
- bodyColors.LeftLegColor = properties.LeftLegColor
- local characterObjects = {bodyColors}
- local headObjects = {}
- local data = {
- characterObjects = characterObjects,
- headObjects = headObjects,
- tshirt = properties.TShirt
- }
- for _, assetId in ipairs(properties.CharacterAssets) do
- TaskScheduler.Start(CharacterAppearance.LoadAsset, characterObjects, assetId)
- end
- for _, assetId in ipairs(properties.HeadAssets) do
- TaskScheduler.Start(CharacterAppearance.LoadAsset, headObjects, assetId)
- end
- CharacterAppearance.stock[id] = data
- end
- function CharacterAppearance.GetDefaultAppearance()
- return CharacterAppearance.stock[CharacterAppearance.defaultAppearanceId]
- end
- function CharacterAppearance.LoadAsset(objects, assetId)
- local asset = InsertService:LoadAsset(assetId)
- for _, child in ipairs(asset:GetChildren()) do
- child.Archivable = true
- table.insert(objects, child:Clone())
- end
- end
- CharacterAppearance.Create {
- Id = 1,
- HeadColor = BrickColor.new("Institutional white"),
- TorsoColor = BrickColor.new("Institutional white"),
- RightArmColor = BrickColor.new("Institutional white"),
- LeftArmColor = BrickColor.new("Institutional white"),
- RightLegColor = BrickColor.new("Institutional white"),
- LeftLegColor = BrickColor.new("Institutional white"),
- CharacterAssets = {
- 90825058, 90825211,
- 27112056, 27112052,
- 27112039, 27112025,
- 27112068, 38322996
- },
- HeadAssets = {
- 20722130,
- 8330576
- }
- }
- CharacterAppearance.Create {
- Id = 2,
- HeadColor = BrickColor.new("Institutional white"),
- TorsoColor = BrickColor.new("Institutional white"),
- RightArmColor = BrickColor.new("Institutional white"),
- LeftArmColor = BrickColor.new("Institutional white"),
- RightLegColor = BrickColor.new("Institutional white"),
- LeftLegColor = BrickColor.new("Institutional white"),
- CharacterAssets = {
- 90825058, 90825211,
- 11748356, 1029025,
- 1235488, 27112056,
- 27112052, 27112039,
- 27112025, 27112068
- },
- HeadAssets = {
- 20722130
- }
- }
- CharacterAppearance.Create {
- Id = 3,
- HeadColor = BrickColor.new("Pastel brown"),
- TorsoColor = BrickColor.new("Pastel brown"),
- RightArmColor = BrickColor.new("Pastel brown"),
- LeftArmColor = BrickColor.new("Pastel brown"),
- RightLegColor = BrickColor.new("White"),
- LeftLegColor = BrickColor.new("White"),
- CharacterAssets = {
- 134289125, 48474356,
- 100339040, 46302558,
- 153955895
- },
- HeadAssets = {},
- TShirt = "rbxassetid://148856353"
- }
- ]])
- Module.Create("PlayerControl", [[
- PlayerControl.fly_acceleration = 10
- PlayerControl.fly_basespeed = 250
- PlayerControl.fly_speed = PlayerControl.fly_basespeed
- PlayerControl.featherfallEnabled = true
- PlayerControl.pushable = false
- PlayerControl.rolling = false
- PlayerControl.rollingAngle = 0
- PlayerControl.rollingOffset = 0
- PlayerControl.rollingMaxOffset = 3
- PlayerControl.rollingSpeed = 1 / 50
- PlayerControl.characterEnabled = false
- PlayerControl.characterMode = "normal"
- local character = nil
- local flying, flyingMomentum, flyingTilt = false, Vector3.new(), 0
- local pose, regeneratingHealth, jumpDebounce = "Standing", false, false
- -- TODO: make local variables public
- local model, bodyColors, leftArmMesh, leftLegMesh, rightArmMesh, rightLegMesh, torsoMesh, wildcardHat, wildcardHandle, wildcardMesh, pants, shirt, humanoid,
- head, leftArm, leftLeg, rightArm, rightLeg, torso, rootPart, rootJoint, face, soundFreeFalling, soundGettingUp, soundRunning, leftHip, leftShoulder,
- rightHip, rightShoulder, neck, wildcardWeld, feetPart, feetWeld, feetTouchInterest, bodyGyro, bodyVelocity, headMesh, torsoLight
- local AnimateCharacter
- local chatBubbles = {}
- local chatCharacterLimit = 240
- function PlayerControl.Chat(message)
- Network.TransmitServer(string.format("ChatBubble.Create(%q)", tostring(message)))
- end
- function PlayerControl.CreateCharacter()
- local characterMode = PlayerControl.characterMode
- if characterMode == "normal" then
- if not PlayerControl.characterEnabled then
- return
- end
- local appearance = CharacterAppearance.GetDefaultAppearance()
- local active = true
- local torsoCFrame = (torso and torso.CFrame) or PlayerControl.torso_cframe or CFrame.new(0, 10, 0)
- if torsoCFrame.p.Y < -450 then
- torsoCFrame = CFrame.new(0, 10, 0)
- end
- local rootPartCFrame = (rootPart and rootPart.CFrame) or PlayerControl.torso_cframe or CFrame.new(0, 10, 0)
- if rootPartCFrame.p.Y < -450 then
- rootPartCFrame = CFrame.new(0, 10, 0)
- end
- local cameraCFrame = Camera.CoordinateFrame
- local connections = {}
- local feetTouching = {}
- local previousWalkSpeed = 0
- local prevLeftHip, prevLeftShoulder, prevRightHip, prevRightShoulder = leftHip, leftShoulder, rightHip, rightShoulder
- model = Instance.new("Model")
- humanoid = Instance.new("Humanoid", model)
- head = Instance.new("Part", model)
- leftArm = Instance.new("Part", model)
- leftLeg = Instance.new("Part", model)
- rightArm = Instance.new("Part", model)
- rightLeg = Instance.new("Part", model)
- torso = Instance.new("Part", model)
- rootPart = Instance.new("Part", model)
- soundFallingDown = Instance.new("Sound", head)
- soundFreeFalling = Instance.new("Sound", head)
- soundGettingUp = Instance.new("Sound", head)
- soundJumping = Instance.new("Sound", head)
- soundRunning = Instance.new("Sound", head)
- leftHip = Instance.new("Motor", torso)
- leftShoulder = Instance.new("Motor", torso)
- rightHip = Instance.new("Motor", torso)
- rightShoulder = Instance.new("Motor", torso)
- neck = Instance.new("Motor", torso)
- rootJoint = Instance.new("Motor", rootPart)
- feetPart = Instance.new("Part", model)
- feetWeld = Instance.new("Weld", torso)
- bodyGyro = Instance.new("BodyGyro", rootPart)
- bodyVelocity = Instance.new("BodyVelocity", rootPart)
- model.Archivable = false
- model.Name = UserInterface.player_name
- model.PrimaryPart = head
- humanoid.LeftLeg = leftLeg
- humanoid.RightLeg = rightLeg
- humanoid.Torso = rootPart
- head.CFrame = torsoCFrame * CFrame.new(0, 1.5, 0)
- head.FormFactor = "Symmetric"
- head.Locked = true
- head.Name = "Head"
- head.Size = Vector3.new(2, 1, 1)
- head.TopSurface = "Smooth"
- leftArm.CanCollide = false
- leftArm.CFrame = torsoCFrame * CFrame.new(-1.5, 0, 0)
- leftArm.FormFactor = "Symmetric"
- leftArm.Locked = true
- leftArm.Name = "Left Arm"
- leftArm.Size = Vector3.new(1, 2, 1)
- leftLeg.BottomSurface = "Smooth"
- leftLeg.CanCollide = false
- leftLeg.CFrame = torsoCFrame * CFrame.new(-0.5, -2, 0)
- leftLeg.FormFactor = "Symmetric"
- leftLeg.Locked = true
- leftLeg.Name = "Left Leg"
- leftLeg.Size = Vector3.new(1, 2, 1)
- leftLeg.TopSurface = "Smooth"
- rightArm.CanCollide = false
- rightArm.CFrame = torsoCFrame * CFrame.new(1.5, 0, 0)
- rightArm.FormFactor = "Symmetric"
- rightArm.Locked = true
- rightArm.Name = "Right Arm"
- rightArm.Size = Vector3.new(1, 2, 1)
- rightLeg.BottomSurface = "Smooth"
- rightLeg.CanCollide = false
- rightLeg.CFrame = torsoCFrame * CFrame.new(0.5, -2, 0)
- rightLeg.FormFactor = "Symmetric"
- rightLeg.Locked = true
- rightLeg.Name = "Right Leg"
- rightLeg.Size = Vector3.new(1, 2, 1)
- rightLeg.TopSurface = "Smooth"
- torso.CFrame = torsoCFrame
- torso.FormFactor = "Symmetric"
- torso.LeftSurface = "Weld"
- torso.Locked = true
- torso.RightSurface = "Weld"
- torso.Name = "Torso"
- torso.Size = Vector3.new(2, 2, 1)
- rootPart.BottomSurface = "Smooth"
- rootPart.BrickColor = BrickColor.Blue()
- rootPart.CFrame = rootPartCFrame
- rootPart.FormFactor = "Symmetric"
- rootPart.LeftSurface = "Weld"
- rootPart.Locked = true
- rootPart.RightSurface = "Weld"
- rootPart.Name = "HumanoidRootPart"
- rootPart.Size = Vector3.new(2, 2, 1)
- rootPart.TopSurface = "Smooth"
- rootPart.Transparency = 1
- soundFreeFalling.Archivable = false
- soundFreeFalling.SoundId = "rbxasset://sounds/swoosh.wav"
- soundGettingUp.Archivable = false
- soundGettingUp.SoundId = "rbxasset://sounds/hit.wav"
- soundRunning.Archivable = false
- soundRunning.SoundId = "rbxasset://sounds/bfsl-minifigfoots1.mp3"
- soundRunning.Looped = true
- leftHip.C0 = CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftHip.C1 = CFrame.new(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftHip.MaxVelocity = 0.1
- leftHip.Name = "Left Hip"
- leftHip.Part0 = torso
- leftHip.Part1 = leftLeg
- leftShoulder.C0 = CFrame.new(-1, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftShoulder.C1 = CFrame.new(0.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftShoulder.MaxVelocity = 0.15
- leftShoulder.Name = "Left Shoulder"
- leftShoulder.Part0 = torso
- leftShoulder.Part1 = leftArm
- rightHip.C0 = CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightHip.C1 = CFrame.new(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightHip.MaxVelocity = 0.1
- rightHip.Name = "Right Hip"
- rightHip.Part0 = torso
- rightHip.Part1 = rightLeg
- rightShoulder.C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightShoulder.C1 = CFrame.new(-0.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightShoulder.MaxVelocity = 0.15
- rightShoulder.Name = "Right Shoulder"
- rightShoulder.Part0 = torso
- rightShoulder.Part1 = rightArm
- if prevLeftHip then
- leftHip.CurrentAngle = prevLeftHip.CurrentAngle
- leftHip.DesiredAngle = prevLeftHip.DesiredAngle
- end
- if prevLeftShoulder then
- leftShoulder.CurrentAngle = prevLeftShoulder.CurrentAngle
- leftShoulder.DesiredAngle = prevLeftShoulder.DesiredAngle
- end
- if prevRightHip then
- rightHip.CurrentAngle = prevRightHip.CurrentAngle
- rightHip.DesiredAngle = prevRightHip.DesiredAngle
- end
- if prevRightShoulder then
- rightShoulder.CurrentAngle = prevRightShoulder.CurrentAngle
- rightShoulder.DesiredAngle = prevRightShoulder.DesiredAngle
- end
- neck.C0 = CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
- neck.C1 = CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
- neck.Name = "Neck"
- neck.Part0 = torso
- neck.Part1 = head
- rootJoint.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- rootJoint.C1 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- rootJoint.Name = "RootJoint"
- rootJoint.Part0 = rootPart
- rootJoint.Part1 = torso
- feetPart.BottomSurface = "Smooth"
- feetPart.CanCollide = false
- feetPart.CFrame = torsoCFrame * CFrame.new(0, -3.1, 0)
- feetPart.FormFactor = "Custom"
- feetPart.Locked = true
- feetPart.Name = "Platform"
- feetPart.Size = Vector3.new(1.8, 0.2, 0.8)
- feetPart.TopSurface = "Smooth"
- feetPart.Transparency = 1
- feetWeld.C0 = CFrame.new(0, -3, 0)
- feetWeld.C1 = CFrame.new(0, 0.1, 0)
- feetWeld.Name = "PlatformWeld"
- feetWeld.Part0 = torso
- feetWeld.Part1 = feetPart
- table.insert(connections, feetPart.Touched:connect(function(hit)
- feetTouching[hit] = true
- end))
- table.insert(connections, feetPart.TouchEnded:connect(function(hit)
- feetTouching[hit] = nil
- end))
- feetTouchInterest = feetPart:FindFirstChild("TouchInterest")
- bodyGyro.D = 3250
- bodyGyro.P = 400000
- bodyGyro.maxTorque = Vector3.new(1000000000, 0, 1000000000)
- bodyVelocity.P = 5000
- bodyVelocity.maxForce = Vector3.new(0, 0, 0)
- bodyVelocity.velocity = Vector3.new(0, 0, 0)
- torsoLight = Instance.new("PointLight", torso)
- torsoLight.Brightness = 0.4
- torsoLight.Color = Color3.new(1, 1, 1)
- torsoLight.Range = 16
- torsoLight.Shadows = true
- local ff1, ff2, ff3, ff4, ff5, ff6, ff7, ff8, ff9 = Instance.new("ForceField", head), Instance.new("ForceField", leftArm), Instance.new
- ("ForceField", leftLeg), Instance.new("ForceField", rightArm), Instance.new("ForceField", rightLeg), Instance.new("ForceField", torso), Instance.new
- ("ForceField", wildcardHandle), Instance.new("ForceField", feetPart), Instance.new("ForceField", rootPart)
- local forcefields = {[ff1] = head, [ff2] = leftArm, [ff3] = leftLeg, [ff4] = rightArm, [ff5] = rightLeg, [ff6] = torso, [ff7] =
- wildcardHandle, [ff8] = feetPart, [ff9] = rootPart}
- local objects = {[humanoid] = true, [head] = true, [leftArm] = true, [leftLeg] = true, [rightArm] = true, [rightLeg] = true, [torso] = true,
- [rootPart] = true, [rootJoint] = true, [soundFreeFalling] = true, [soundGettingUp] = true, [soundRunning] = true, [leftHip] = true, [leftShoulder] = true,
- [rightHip] = true, [rightShoulder] = true, [neck] = true, [feetPart] = true, [feetWeld] = true, [feetTouchInterest] = true, [bodyGyro] = true,
- [bodyVelocity] = true, [ff1] = true, [ff2] = true, [ff3] = true, [ff4] = true, [ff5] = true, [ff6] = true, [ff7] = true, [ff8] = true, [ff9] = true}
- local tshirtUrl = appearance.tshirt
- if tshirtUrl then
- local tshirt = Instance.new("Decal", torso)
- tshirt.Name = "roblox"
- tshirt.Texture = tshirtUrl
- objects[tshirt] = true
- end
- for _, template in ipairs(appearance.characterObjects) do
- local object = template:Clone()
- local newObjects = {object}
- for _, object in ipairs(newObjects) do
- objects[object] = true
- for _, child in ipairs(object:GetChildren()) do
- table.insert(newObjects, child)
- end
- end
- if object:IsA("BodyColors") then
- head.BrickColor = object.HeadColor
- leftArm.BrickColor = object.LeftArmColor
- leftLeg.BrickColor = object.LeftLegColor
- rightArm.BrickColor = object.RightArmColor
- rightLeg.BrickColor = object.RightLegColor
- torso.BrickColor = object.TorsoColor
- elseif object:IsA("Hat") then
- local handle = object:FindFirstChild("Handle")
- if handle and handle:IsA("BasePart") then
- local weld = Instance.new("Weld", head)
- weld.C0 = CFrame.new(0, 0.5, 0)
- local attachmentPos = object.AttachmentPos
- local attachmentRight = object.AttachmentRight
- local attachmentUp = object.AttachmentUp
- local attachmentForward = object.AttachmentForward
- weld.C1 = CFrame.new(attachmentPos.X, attachmentPos.Y, attachmentPos.Z,
- attachmentRight.X, attachmentUp.X, -attachmentForward.X,
- attachmentRight.Y, attachmentUp.Y, -attachmentForward.Y,
- attachmentRight.Z, attachmentUp.Z, -attachmentForward.Z)
- weld.Name = "HeadWeld"
- weld.Part0 = head
- weld.Part1 = handle
- handle.Parent = model
- local antiGravity = Instance.new("BodyForce", handle)
- antiGravity.force = Vector3.new(0, handle:GetMass() * 196.2, 0)
- objects[object] = false
- object.Parent = nil
- objects[weld] = true
- end
- end
- object.Parent = model
- end
- local facePresent = false
- local headMeshPresent = false
- for _, template in ipairs(appearance.headObjects) do
- local object = template:Clone()
- local newObjects = {object}
- for _, object in ipairs(newObjects) do
- objects[object] = true
- for _, child in ipairs(object:GetChildren()) do
- table.insert(newObjects, child)
- end
- end
- if object:IsA("DataModelMesh") then
- headMeshPresent = true
- elseif object:IsA("Decal") then
- facePresent = true
- end
- object.Parent = head
- end
- if not facePresent then
- local face = Instance.new("Decal", head)
- face.Texture = "rbxasset://textures/face.png"
- objects[face] = true
- end
- if not headMeshPresent then
- local headMesh = Instance.new("SpecialMesh", head)
- headMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
- objects[headMesh] = true
- end
- table.insert(connections, model.DescendantAdded:connect(function(object)
- local success, is_localscript = pcall(Game.IsA, object, "LocalScript")
- if success and is_localscript then
- pcall(Utility.SetProperty, object, "Disabled", true)
- local changed_connection = pcall(object.Changed.connect, object.Changed, function(property)
- if property == "Disabled" and not object.Disabled then
- pcall(Utility.SetProperty, object, "Disabled", true)
- Network.TransmitServer("(...):Destroy()", object)
- end
- end)
- end
- if not objects[object] then
- Network.TransmitServer("(...):Destroy()", object)
- end
- end))
- model.Parent = Workspace
- Player.Character = model
- Camera.CameraSubject = humanoid
- Camera.CameraType = "Track"
- Camera.CoordinateFrame = cameraCFrame
- local IsStanding
- local RegenerateHealth
- local ResetCharacter
- function IsStanding()
- return not not next(feetTouching)
- end
- function RegenerateHealth()
- if humanoid.Health < 1 then
- humanoid.Health = 100
- elseif not regeneratingHealth then
- regeneratingHealth = true
- local elapsedTime = wait(1)
- regeneratingHealth = false
- if humanoid.Health < 100 then
- humanoid.Health = math.min(humanoid.Health + elapsedTime, 100)
- end
- end
- end
- function ResetCharacter()
- for index, connection in ipairs(connections) do
- connection:disconnect()
- end
- active = false
- end
- table.insert(connections, model.AncestryChanged:connect(ResetCharacter))
- table.insert(connections, model.DescendantRemoving:connect(function(object)
- local parent = forcefields[object]
- if parent then
- forcefields[object] = nil
- local new_forcefield = Instance.new("ForceField")
- forcefields[new_forcefield] = parent
- objects[new_forcefield] = true
- new_forcefield.Parent = parent
- elseif objects[object] then
- ResetCharacter()
- end
- end))
- table.insert(connections, humanoid.HealthChanged:connect(RegenerateHealth))
- table.insert(connections, humanoid.Climbing:connect(function() pose = "Climbing" end))
- table.insert(connections, humanoid.FallingDown:connect(function(state) pose = "FallingDown" end))
- table.insert(connections, humanoid.FreeFalling:connect(function(state) pose = "FreeFall" if state then soundFreeFalling:Play() else
- soundFreeFalling:Pause() end end))
- table.insert(connections, humanoid.GettingUp:connect(function(state) pose = "GettingUp" if state then soundGettingUp:Play() else
- soundGettingUp:Pause() end end))
- table.insert(connections, humanoid.PlatformStanding:connect(function() pose = "PlatformStanding" end))
- table.insert(connections, humanoid.Seated:connect(function() pose = "Seated" end))
- table.insert(connections, humanoid.Swimming:connect(function(speed) if speed > 0 then pose = "Swimming" else pose = "Standing" end end))
- local previousRootPartCFrame = rootPart.CFrame
- TaskScheduler.Start(function()
- while active do
- local totalTime = TaskScheduler.GetCurrentTime()
- local stepTime = 1 / 60
- if not PlayerControl.characterEnabled then
- ResetCharacter()
- break
- end
- torsoLight.Brightness = 0.5 + 0.15 * math.sin(totalTime * 0.75 * math.pi)
- local featherfallEnabled = PlayerControl.IsFeatherfallEnabled()
- local rootPartCFrame = rootPart.CFrame
- if not jumpDebounce and UserInterface.IsKeyDown(" ") then
- if humanoid.Sit then
- humanoid.Sit = false
- end
- if IsStanding() then
- jumpDebounce = true
- pose = "Jumping"
- rootPart.Velocity = Vector3.new(rootPart.Velocity.X, 50, rootPart.Velocity.Z)
- torso.Velocity = Vector3.new(torso.Velocity.X, 50, torso.Velocity.Z)
- TaskScheduler.Schedule(1, function()
- if pose == "Jumping" then
- pose = "FreeFall"
- end
- jumpDebounce = false
- humanoid.Jump = false
- end)
- end
- end
- local cameraCFrame = Camera.CoordinateFrame
- local cameraDirection = cameraCFrame.lookVector
- if flying then
- if PlayerControl.rolling then
- local rootPartCFrame = rootPart.CFrame
- local speed = (rootPartCFrame - rootPartCFrame.p):pointToObjectSpace(rootPart.Velocity).Y
- local decay = 0.5 ^ stepTime
- if math.abs(speed) <= 50 then
- PlayerControl.rollingAngle = (((PlayerControl.rollingAngle + 0.5) % 1 - 0.5) * decay) % 1
- PlayerControl.rollingOffset = PlayerControl.rollingOffset * decay
- else
- PlayerControl.rollingAngle = (PlayerControl.rollingAngle + stepTime * speed *
- PlayerControl.rollingSpeed) % 1
- PlayerControl.rollingOffset = (PlayerControl.rollingOffset + PlayerControl.rollingMaxOffset * (1 /
- decay - 1)) * decay
- end
- rootJoint.C0 = (CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0) * CFrame.Angles(PlayerControl.rollingAngle *
- 2 * math.pi, 0, 0)) * CFrame.new(0, -PlayerControl.rollingOffset, 0)
- else
- rootJoint.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- PlayerControl.rollingAngle = 0
- PlayerControl.rollingOffset = 0
- end
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- rightShoulder.DesiredAngle = 0
- leftShoulder.DesiredAngle = 0
- rightHip.DesiredAngle = 0
- leftHip.DesiredAngle = 0
- bodyGyro.D = 500
- bodyGyro.P = 1e6
- bodyGyro.maxTorque = Vector3.new(1e6, 1e6, 1e6)
- bodyVelocity.P = 1250
- bodyVelocity.maxForce = Vector3.new(1e6, 1e6, 1e6)
- local movementRight = 0
- local movementForward = 0
- local movementUp = 0
- if UserInterface.IsKeyDown("a") and not UserInterface.IsKeyDown("d") then
- movementRight = -1
- elseif UserInterface.IsKeyDown("d") then
- movementRight = 1
- end
- if UserInterface.IsKeyDown("w") then
- movementUp = 0.2
- if not UserInterface.IsKeyDown("s") then
- movementForward = -1
- end
- elseif UserInterface.IsKeyDown("s") then
- movementForward = 1
- end
- local movement = PlayerControl.fly_acceleration * cameraCFrame:vectorToWorldSpace(Vector3.new(movementRight,
- movmentUp, movementForward))
- local previousMomentum = flyingMomentum
- local previousTilt = flyingTilt
- flyingMomentum = movement + flyingMomentum * (1 - PlayerControl.fly_acceleration / PlayerControl.fly_speed)
- flyingTilt = ((flyingMomentum * Vector3.new(1, 0, 1)).unit:Cross((previousMomentum * Vector3.new(1, 0, 1)).unit)).Y
- if flyingTilt ~= flyingTilt or flyingTilt == math.huge then
- flyingTilt = 0
- end
- local absoluteTilt = math.abs(flyingTilt)
- if absoluteTilt > 0.06 or absoluteTilt < 0.0001 then
- if math.abs(previousTilt) > 0.0001 then
- flyingTilt = previousTilt * 0.9
- else
- flyingTilt = 0
- end
- else
- flyingTilt = previousTilt * 0.77 + flyingTilt * 0.25
- end
- previousTilt = flyingTilt
- if flyingMomentum.magnitude < 0.1 then
- flyingMomentum = Vector3.new(0, 0, 0)
- -- bodyGyro.cframe = cameraCFrame
- else
- local momentumOrientation = CFrame.new(Vector3.new(0, 0, 0), flyingMomentum)
- local tiltOrientation = CFrame.Angles(0, 0, -20 * flyingTilt)
- bodyGyro.cframe = momentumOrientation * tiltOrientation * CFrame.Angles(-0.5 * math.pi * math.min
- (flyingMomentum.magnitude / PlayerControl.fly_speed, 1), 0, 0)
- end
- bodyVelocity.velocity = flyingMomentum + Vector3.new(0, 0.15695775618683547, 0)
- rootPart.Velocity = flyingMomentum
- previousMomentum = flyingMomentum
- else
- rootJoint.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- PlayerControl.rollingAngle = 0
- PlayerControl.rollingOffset = 0
- bodyGyro.D = 3250
- bodyGyro.P = 400000
- bodyVelocity.P = 5000
- local cameraDirection = cameraCFrame.lookVector
- local walkDirection = Vector3.new(0, 0, 0)
- local walkSpeed = 16
- if UserInterface.IsKeyDown("w") or UserInterface.IsKeyDown("\17") then
- if UserInterface.IsKeyDown("a") then
- walkDirection = Vector3.new(cameraDirection.X + cameraDirection.Z, 0, cameraDirection.Z -
- cameraDirection.X).unit
- elseif UserInterface.IsKeyDown("d") then
- walkDirection = Vector3.new(cameraDirection.X - cameraDirection.Z, 0, cameraDirection.Z +
- cameraDirection.X).unit
- else
- walkDirection = Vector3.new(cameraDirection.X, 0, cameraDirection.Z).unit
- end
- elseif UserInterface.IsKeyDown("s") or UserInterface.IsKeyDown("\18") then
- if UserInterface.IsKeyDown("a") then
- walkDirection = Vector3.new(-cameraDirection.X + cameraDirection.Z, 0, -cameraDirection.Z -
- cameraDirection.X).unit
- elseif UserInterface.IsKeyDown("d") then
- walkDirection = Vector3.new(-cameraDirection.X - cameraDirection.Z, 0, -cameraDirection.Z +
- cameraDirection.X).unit
- else
- walkDirection = Vector3.new(-cameraDirection.X, 0, -cameraDirection.Z).unit
- end
- elseif UserInterface.IsKeyDown("a") then
- walkDirection = Vector3.new(cameraDirection.Z, 0, -cameraDirection.X).unit
- elseif UserInterface.IsKeyDown("d") then
- walkDirection = Vector3.new(-cameraDirection.Z, 0, cameraDirection.X).unit
- else
- walkSpeed = 0
- end
- if walkSpeed ~= previousWalkSpeed then
- if walkSpeed > 0 then
- soundRunning:Play()
- else
- soundRunning:Pause()
- end
- end
- if walkSpeed > 0 then
- if pose ~= "Jumping" then
- if IsStanding() then
- pose = "Running"
- else
- pose = "FreeFall"
- end
- end
- bodyGyro.cframe = CFrame.new(Vector3.new(), walkDirection)
- bodyGyro.maxTorque = Vector3.new(1000000000, 1000000000, 1000000000)
- bodyVelocity.maxForce = Vector3.new(1000000, maxForceY, 1000000)
- else
- if pose ~= "Jumping" then
- if IsStanding() then
- pose = "Standing"
- else
- pose = "FreeFall"
- end
- end
- -- TODO: find and fix bug that causes torso to rotate back to some angle
- bodyGyro.maxTorque = Vector3.new(1000000000, 1000000000, 1000000000) -- Vector3.new(1000000000, 0,
- 1000000000)
- if PlayerControl.pushable then
- bodyVelocity.maxForce = Vector3.new(0, 0, 0)
- else
- bodyVelocity.maxForce = Vector3.new(1000000, 0, 1000000)
- end
- end
- if featherfallEnabled then
- local velocity = rootPart.Velocity
- if velocity.Y > 50 then
- rootPart.Velocity = Vector3.new(velocity.X, 50, velocity.Z)
- elseif velocity.Y < -50 then
- rootPart.Velocity = Vector3.new(velocity.X, -50, velocity.Z)
- end
- local distanceVector = rootPartCFrame.p - previousRootPartCFrame.p
- local offsetX, offsetY, offsetZ = distanceVector.X, distanceVector.Y, distanceVector.Z
- local MAX_MOVEMENT = 50 * 0.03333333507180214
- if offsetX > MAX_MOVEMENT then
- offsetX = MAX_MOVEMENT
- elseif offsetX < -MAX_MOVEMENT then
- offsetX = -MAX_MOVEMENT
- end
- if offsetY > MAX_MOVEMENT then
- offsetY = MAX_MOVEMENT
- elseif offsetY < -MAX_MOVEMENT then
- offsetY = -MAX_MOVEMENT
- end
- if offsetZ > MAX_MOVEMENT then
- offsetZ = MAX_MOVEMENT
- elseif offsetZ < -MAX_MOVEMENT then
- offsetZ = -MAX_MOVEMENT
- end
- local offset = Vector3.new(offsetX, offsetY, offsetZ)
- if offset ~= distanceVector then
- rootPartCFrame = previousRootPartCFrame + offset
- --rootPart.CFrame = rootPartCFrame
- end
- end
- local walkingVelocity = walkDirection * walkSpeed
- bodyVelocity.velocity = walkingVelocity
- if not jumpDebounce and math.abs(rootPart.Velocity.Y) <= 0.1 then
- rootPart.Velocity = Vector3.new(walkingVelocity.X, rootPart.Velocity.Y, walkingVelocity.Z)
- end
- previousWalkSpeed = walkSpeed
- if pose == "Jumping" or jumpDebounce then
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- rightShoulder.DesiredAngle = 3.14
- leftShoulder.DesiredAngle = -3.14
- rightHip.DesiredAngle = 0
- leftHip.DesiredAngle = 0
- elseif pose == "FreeFall" then
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- rightShoulder.DesiredAngle = 3.14
- leftShoulder.DesiredAngle = -3.14
- rightHip.DesiredAngle = 0
- leftHip.DesiredAngle = 0
- elseif pose == "Seated" then
- rightShoulder.MaxVelocity = 0.15
- leftShoulder.MaxVelocity = 0.15
- rightShoulder.DesiredAngle = 3.14 / 2
- leftShoulder.DesiredAngle = -3.14 / 2
- rightHip.DesiredAngle = 3.14 / 2
- leftHip.DesiredAngle = -3.14 / 2
- else
- local climbFudge = 0
- local amplitude
- local frequency
- if pose == "Running" then
- rightShoulder.MaxVelocity = 0.15
- leftShoulder.MaxVelocity = 0.15
- amplitude = 1
- frequency = 9
- elseif (pose == "Climbing") then
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- amplitude = 1
- frequency = 9
- climbFudge = 3.14
- else
- amplitude = 0.1
- frequency = 1
- end
- local desiredAngle = amplitude * math.sin(totalTime * frequency)
- rightShoulder.DesiredAngle = desiredAngle + climbFudge
- leftShoulder.DesiredAngle = desiredAngle - climbFudge
- rightHip.DesiredAngle = -desiredAngle
- leftHip.DesiredAngle = -desiredAngle
- end
- end
- previousRootPartCFrame = rootPartCFrame
- RunService.RenderStepped:wait()
- end
- if model.Parent ~= nil then
- model.Parent = nil
- end
- PlayerControl.CreateCharacter()
- end)
- humanoid.Health = 100
- character = model
- Network.TransmitServer("chatAdornee = ...", head)
- elseif characterMode == "pyramid" then
- if PlayerControl.characterEnabled then
- Camera.CameraType = "Fixed"
- PyramidCharacter.camera_distance = (Camera.Focus.p - Camera.CoordinateFrame.p).magnitude
- PyramidCharacter.camera_position = Camera.Focus.p
- PyramidCharacter.Teleport(Camera.Focus.p)
- PyramidCharacter.visible = true
- Player.Character = nil
- else
- PyramidCharacter.visible = false
- end
- end
- end
- function PlayerControl.GetCharacter()
- return character
- end
- function PlayerControl.GetHead()
- local characterMode = PlayerControl.characterMode
- if characterMode == "normal" then
- return head
- elseif characterMode == "pyramid" then
- return PyramidCharacter.core
- end
- end
- function PlayerControl.GetHumanoid()
- return humanoid
- end
- function PlayerControl.GetRootPart()
- return rootPart
- end
- function PlayerControl.GetTorso()
- return torso
- end
- function PlayerControl.IsEnabled()
- return PlayerControl.characterEnabled
- end
- function PlayerControl.IsFeatherfallEnabled()
- return PlayerControl.featherfallEnabled
- end
- function PlayerControl.IsPushable()
- return PlayerControl.pushable
- end
- function PlayerControl.IsRolling()
- return PlayerControl.rolling
- end
- function PlayerControl.ResetCharacter()
- if character and character.Parent then
- character.Parent = nil
- end
- PyramidCharacter.visible = false
- end
- function PlayerControl.SetEnabled(state, no_animation)
- state = not not state
- if state ~= PlayerControl.characterEnabled then
- PlayerControl.characterEnabled = state
- local characterMode = PlayerControl.characterMode
- if characterMode == "normal" then
- local torso = PlayerControl.GetRootPart()
- local rootPart = PlayerControl.GetRootPart()
- if rootPart then
- if PlayerControl.characterEnabled then
- local torso_cframe = Camera.Focus:toWorldSpace(PlayerControl.hide_torso_object_cframe)
- PlayerControl.torso_cframe = torso_cframe
- torso.CFrame = torso_cframe
- rootPart.CFrame = torso_cframe
- else
- PlayerControl.hide_torso_object_cframe = Camera.Focus:toObjectSpace(rootPart.CFrame)
- end
- else
- PlayerControl.torso_cframe = Camera.Focus
- end
- if PlayerControl.characterEnabled then
- PlayerControl.CreateCharacter()
- RunService.Stepped:wait()
- coroutine.yield()
- if not no_animation then
- Network.TransmitServer("GraphicalEffects.CrystalRing({base_part = (...), crystal_color = BrickColor.new
- (\"Institutional white\"), float_duration = 2})", PlayerControl.GetTorso())
- end
- else
- Player.Character = nil
- Camera.CameraType = "Fixed"
- if not no_animation then
- Network.TransmitServer("GraphicalEffects.CrystalRing({position = (...), crystal_color = BrickColor.new
- (\"Institutional white\"), float_duration = 2})", PlayerControl.GetTorso().Position)
- end
- end
- else
- if state then
- PlayerControl.CreateCharacter()
- RunService.Stepped:wait()
- coroutine.yield()
- if not no_animation then
- Network.TransmitServer("GraphicalEffects.CrystalRing({base_part = (...), crystal_color = BrickColor.new
- (\"Institutional white\"), float_duration = 2})", PyramidCharacter.core)
- end
- else
- PyramidCharacter.visible = false
- if not no_animation then
- Network.TransmitServer("GraphicalEffects.CrystalRing({position = (...), crystal_color = BrickColor.new
- (\"Institutional white\"), float_duration = 2})", PyramidCharacter.core.Position)
- end
- end
- end
- end
- end
- function PlayerControl.SetFeatherfallEnabled(state)
- state = not not state
- if state ~= PlayerControl.featherfallEnabled then
- PlayerControl.featherfallEnabled = state
- if state then
- Logger.print("Info", "Featherfall enabled in PlayerControl")
- else
- Logger.print("Info", "Featherfall disabled in PlayerControl")
- end
- end
- end
- function PlayerControl.SetPushable(state)
- state = not not state
- if state ~= PlayerControl.pushable then
- PlayerControl.pushable = state
- if state then
- Logger.print("Info", "Pushing enabled in PlayerControl")
- else
- Logger.print("Info", "Pushing disabled in PlayerControl")
- end
- end
- end
- function PlayerControl.SetRolling(state)
- state = not not state
- if state ~= PlayerControl.rolling then
- PlayerControl.rolling = state
- if state then
- Logger.print("Info", "Rolling fly mode enabled in PlayerControl")
- else
- Logger.print("Info", "Rolling fly mode disabled in PlayerControl")
- end
- end
- end
- function PlayerControl.StartFlying()
- PlayerControl.fly_speed = PlayerControl.fly_basespeed
- if torso then
- flyingMomentum = torso.Velocity + torso.CFrame.lookVector * 3 + Vector3.new(0, 10, 0)
- else
- flyingMomentum = Vector3.new()
- end
- flyingTilt = 0
- flying = true
- end
- function PlayerControl.StopFlying()
- if bodyGyro.cframe then
- local lookVector = bodyGyro.cframe.lookVector
- if lookVector.X ~= 0 or lookVector.Z ~= 0 then
- bodyGyro.cframe = CFrame.new(Vector3.new(), Vector3.new(lookVector.X, 0, lookVector.Z))
- end
- end
- flying = false
- end
- local previousTime = 0
- UserInterface.SetHotkey(" ", function()
- if flying then
- PlayerControl.StopFlying()
- else
- local currentTime = time()
- if currentTime - previousTime < 0.4 then
- previousTime = 0
- PlayerControl.StartFlying()
- else
- previousTime = currentTime
- end
- end
- end)
- ]])
- Module.Create("RBXInstance", [[
- RBXInstance.init_metatable = {}
- function RBXInstance.init_metatable:__call(data)
- local instance = Instance.new(self[1])
- for key, value in pairs(data) do
- if type(key) == "number" then
- value.Parent = instance
- else
- instance[key] = value
- end
- end
- return instance
- end
- function RBXInstance.new(className)
- return setmetatable({className}, RBXInstance.init_metatable)
- end
- ]])
- Module.Create("AdvancedGUI", [=[
- if not AdvancedGUI.GUI_BASE_COLOR then
- AdvancedGUI.GUI_BASE_COLOR = Color3.new(0, 0, 0)
- end
- function AdvancedGUI.GenerateChatColor(speakerName)
- local chatColor = ChatColor.Get(speakerName).Color
- local brightness = chatColor.r + chatColor.g + chatColor.b
- if brightness < 1.5 then
- chatColor = Color3.new(math.min(1, 0.4 + chatColor.r), math.min(1, 0.4 + chatColor.g), math.min(1, 0.4 + chatColor.b))
- else
- chatColor = Color3.new(math.min(1, 0.05 + chatColor.r), math.min(1, 0.05 + chatColor.g), math.min(1, 0.05 + chatColor.b))
- end
- return chatColor
- end
- GuiBase = {}
- GuiBase.__index = GuiBase
- function GuiBase:new(data)
- local instance = setmetatable({}, self)
- instance:Init(data)
- return instance
- end
- function GuiBase:Destroy()
- if self.parent then
- self.parent.children[self] = nil
- end
- for child in pairs(self.children) do
- child:Destroy()
- end
- self.m_base_instance:Destroy()
- end
- function GuiBase:GetContentInstance(child)
- return self.m_base_instance
- end
- function GuiBase:Init()
- self.children = {}
- end
- function GuiBase:IsA(className)
- return className == "GuiBase"
- end
- function GuiBase:SetParent(parent)
- if parent ~= self.parent then
- if self.parent then
- self.parent.children[self] = nil
- end
- self.parent = parent
- if parent then
- parent.children[self] = true
- self.m_base_instance.Parent = parent:GetContentInstance()
- else
- self.m_base_instance.Parent = nil
- end
- end
- end
- GuiObject = setmetatable({}, GuiBase)
- GuiObject.__index = GuiObject
- function GuiObject:Destroy()
- self.DragBegin:disconnect()
- self.DragMove:disconnect()
- self.DragStopped:disconnect()
- self.MouseButton1Click:disconnect()
- self.MouseButton1Down:disconnect()
- self.MouseButton1Up:disconnect()
- self.MouseButton2Down:disconnect()
- self.MouseButton2Up:disconnect()
- self.MouseEnter:disconnect()
- self.MouseLeave:disconnect()
- GuiBase.Destroy(self)
- end
- function GuiObject:GetAbsolutePosition()
- return self.m_base_instance.AbsolutePosition
- end
- function GuiObject:GetAbsoluteSize()
- return self.m_base_instance.AbsoluteSize
- end
- function GuiObject:GetPosition()
- return self.position
- end
- function GuiObject:GetSize()
- return self.size
- end
- function GuiObject:Init()
- GuiBase.Init(self)
- self.mouseDown = false
- self.mouseOver = false
- self.DragBegin = RbxUtility.CreateSignal()
- self.DragMove = RbxUtility.CreateSignal()
- self.DragStopped = RbxUtility.CreateSignal()
- self.MouseButton1Click = RbxUtility.CreateSignal()
- self.MouseButton1Down = RbxUtility.CreateSignal()
- self.MouseButton1Up = RbxUtility.CreateSignal()
- self.MouseButton2Down = RbxUtility.CreateSignal()
- self.MouseButton2Up = RbxUtility.CreateSignal()
- self.MouseEnter = RbxUtility.CreateSignal()
- self.MouseLeave = RbxUtility.CreateSignal()
- end
- function GuiObject:IsA(className)
- return className == "GuiObject" or GuiBase.IsA(self, className)
- end
- function GuiObject:SetActive(active)
- if active ~= self.active then
- self.active = active
- end
- end
- function GuiObject:SetBackgroundTransparency(backgroundTransparency)
- if backgroundTransparency ~= self.backgroundTransparency then
- self.backgroundTransparency = backgroundTransparency
- self.m_base_instance.BackgroundTransparency = backgroundTransparency
- end
- end
- function GuiObject:SetColor(color)
- if color ~= self.color then
- self.color = color
- self.m_base_instance.BackgroundColor3 = color
- end
- end
- function GuiObject:SetPosition(position)
- if position ~= self.position then
- self.position = position
- self.m_base_instance.Position = position
- end
- end
- function GuiObject:SetSize(size)
- if size ~= self.size then
- self.size = size
- self.m_base_instance.Size = size
- end
- end
- function GuiObject:SetVisible(visible)
- if visible ~= self.visible then
- self.visible = visible
- self.m_base_instance.Visible = visible
- end
- end
- function GuiObject:SetZIndex(zIndex)
- local stack = {self.m_base_instance}
- repeat
- local object = stack[#stack]
- stack[#stack] = nil
- for _, child in ipairs(object:GetChildren()) do
- stack[#stack + 1] = child
- end
- object.ZIndex = zIndex
- until #stack == 0
- end
- GuiServiceClass = setmetatable({}, GuiBase)
- GuiServiceClass.__index = GuiServiceClass
- function GuiServiceClass:CreateTextArea(text, font, fontSize, textColor3, textXAlignment, textYAlignment, maxWidth, minWidth)
- local totalHeight = 0
- local frame = Instance.new("Frame")
- frame.BackgroundTransparency = 1
- local label = Instance.new("TextLabel")
- label.BackgroundTransparency = 1
- label.Font = font
- label.FontSize = fontSize
- label.TextColor3 = textColor3
- label.TextTransparency = 1
- label.TextWrapped = true
- label.TextXAlignment = textXAlignment
- label.TextYAlignment = textYAlignment
- label.Parent = self.guiFrame
- local index = 1
- while true do
- local length = #text - index + 1
- if length > 1024 then
- length = 1024
- local textBlock = string.sub(text, index, index + length - 1)
- label.Text = textBlock
- local height = 0
- local width = maxWidth
- repeat
- height = height + 20
- label.Size = UDim2.new(0, width, 0, height)
- until label.TextFits
- repeat
- height = height - 1
- label.Size = UDim2.new(0, width, 0, height)
- until not label.TextFits
- repeat
- length = length - 10
- label.Text = string.sub(text, index, index + length - 1)
- until label.TextFits
- repeat
- length = length + 1
- label.Text = string.sub(text, index, index + length - 1)
- until not label.TextFits
- local overflowCharacter = string.sub(text, index + length - 1, index + length - 1)
- length = length - 1
- label.Text = string.sub(text, index, index + length - 1)
- if overflowCharacter == "\n" then
- index = index + 1
- end
- repeat
- height = height - 1
- label.Size = UDim2.new(0, width, 0, height)
- until not label.TextFits
- height = height + 1
- local blockLabel = label:Clone()
- blockLabel.Position = UDim2.new(0, 0, 0, totalHeight)
- blockLabel.Size = UDim2.new(1, 0, 0, height)
- blockLabel.Parent = frame
- totalHeight = totalHeight + height
- index = index + length
- else
- local textBlock = string.sub(text, index)
- label.Text = textBlock
- local height = 0
- local width = maxWidth
- repeat
- height = height + 20
- label.Size = UDim2.new(0, width, 0, height)
- until label.TextFits
- repeat
- height = height - 1
- label.Size = UDim2.new(0, width, 0, height)
- until not label.TextFits
- height = height + 1
- if index == 1 then
- repeat
- width = width - 10
- label.Size = UDim2.new(0, width, 0, height)
- until width < minWidth or not label.TextFits
- width = math.max(width, minWidth - 1)
- repeat
- width = width + 1
- label.Size = UDim2.new(0, width, 0, height)
- until label.TextFits
- end
- local blockLabel = label:Clone()
- blockLabel.Position = UDim2.new(0, 0, 0, totalHeight)
- blockLabel.Size = UDim2.new(1, 0, 0, height)
- blockLabel.Parent = frame
- label:Destroy()
- frame.Size = UDim2.new(0, width, 0, totalHeight + height)
- return frame
- end
- end
- end
- function GuiServiceClass:Destroy()
- self.running = false
- self.cameraPart:Destroy()
- self.cameraConnection:disconnect()
- self.keyDownConnection:disconnect()
- self.mouseButton1DownConnection:disconnect()
- self.mouseButton1UpConnection:disconnect()
- self.mouseButton2DownConnection:disconnect()
- self.mouseButton2UpConnection:disconnect()
- self.mouseMoveConnection:disconnect()
- self.steppedConnection:disconnect()
- end
- function GuiServiceClass:GetMousePosition()
- local mouse = self.mouse
- return mouse.X, mouse.Y -- mouse.X, mouse.Y + 2 -- return mouse.X - 2, mouse.Y - 3
- end
- function GuiServiceClass:GetTextBounds(text, font, fontSize, alignX, alignY, width)
- local tempLabel = self.tempLabel
- tempLabel.Font = font
- tempLabel.FontSize = fontSize
- tempLabel.Size = UDim2.new(0, width, 0, 4096)
- tempLabel.Text = text
- tempLabel.TextXAlignment = alignX
- tempLabel.TextYAlignment = alignY
- local textBounds = tempLabel.TextBounds
- tempLabel.Text = ""
- return textBounds
- end
- function GuiServiceClass:Init(data)
- GuiBase.Init(self)
- local _ = string.char
- local camera = data.Camera
- local mouse = data.Mouse
- local cameraPart = Instance.new("Part")
- local billboardGui = Instance.new("BillboardGui", cameraPart)
- guiFrame = Instance.new("Frame", billboardGui)
- cameraPart.Anchored = true
- cameraPart.BottomSurface = "Smooth"
- cameraPart.CanCollide = false
- -- cameraPart.CFrame = CFrame.new(16384, 16384, 16384)
- cameraPart.FormFactor = "Custom"
- cameraPart.Locked = true
- cameraPart.Size = Vector3.new(0.2, 0.2, 0.2)
- cameraPart.TopSurface = "Smooth"
- cameraPart.Transparency = 1
- billboardGui.Adornee = cameraPart
- billboardGui.AlwaysOnTop = true
- -- billboardGui.ExtentsOffset = Vector3.new(-16384, -16384, -16384)
- guiFrame.BackgroundTransparency = 1
- cameraPart.Parent = camera
- self.running = true
- self.m_base_instance = guiFrame
- self.billboardGui = billboardGui
- self.cameraPart = cameraPart
- self.tempLabel = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- TextTransparency = 1,
- TextWrapped = true,
- Parent = guiFrame
- }
- self.mnemonics = {}
- self.visible = true
- self.camera = camera
- self.mouse = mouse
- self.cameraConnection = camera.Changed:connect(function(property)
- self:UpdateView()
- if property == "CameraType" then
- if camera.CameraType ~= Enum.CameraType.Track and camera.CameraType ~= Enum.CameraType.Fixed then
- camera.CameraType = Enum.CameraType.Track
- end
- elseif property == "CoordinateFrame" and camera.CameraType ~= Enum.CameraType.Fixed then
- local cframe, focus = camera.CoordinateFrame, camera.Focus
- local watchOffset = focus.p - cframe.p
- local error = watchOffset.unit - cframe.lookVector
- if error.magnitude >= 1e-3 then
- local head = PlayerControl.GetHead()
- local time1, velocity1
- if head then
- time1 = time()
- velocity1 = head.Velocity
- end
- if camera.Changed:wait() == "CoordinateFrame" then
- local position = cframe.p
- if head then
- local time2 = time()
- local velocity2 = head.Velocity
- position = position + 0.5 * (velocity1 + velocity2) * (time2 - time1)
- end
- camera.CoordinateFrame = CFrame.new(position, camera.Focus.p)
- end
- end
- end
- end)
- self.keyDownConnection = mouse.KeyDown:connect(function(key) self:KeyDown(key) end)
- self.mouseButton1DownConnection = mouse.Button1Down:connect(function() self:MouseButton1Down() end)
- self.mouseButton1UpConnection = mouse.Button1Up:connect(function() self:MouseButton1Up() end)
- self.mouseButton2DownConnection = mouse.Button2Down:connect(function() self:MouseButton2Down() end)
- self.mouseButton2UpConnection = mouse.Button2Up:connect(function() self:MouseButton2Up() end)
- self.mouseMoveConnection = mouse.Move:connect(function() self:MouseMove() end)
- self.steppedConnection = RunService.RenderStepped:connect(function() self:UpdateObjects() self:UpdateView() end)
- self.mousePreviousPosition = Vector2.new(self:GetMousePosition())
- end
- function GuiServiceClass:IsA(className)
- return className == "GuiService" or GuiBase.IsA(self, className)
- end
- function GuiServiceClass:KeyDown(key)
- local mnemonicButton = self.mnemonics[string.upper(key)]
- if mnemonicButton then
- mnemonicButton.Activated:fire()
- end
- end
- function GuiServiceClass:MouseButton1Down()
- local mouse = self.mouse
- local mouseX, mouseY = self:GetMousePosition()
- local stack = {self}
- local dragObjects = {}
- self.dragObjects = dragObjects
- while #stack > 0 do
- local object = stack[#stack]
- stack[#stack] = nil
- if object.visible then
- for child in pairs(object.children) do
- stack[#stack + 1] = child
- end
- if object.active then
- local position = object:GetAbsolutePosition()
- local size = object:GetAbsoluteSize()
- if mouseX >= position.X and mouseY >= position.Y and mouseX < position.X + size.X and mouseY < position.Y + size.Y then
- object.mouseDown = true
- dragObjects[object] = true
- local mouseButton1Down = object.MouseButton1Down
- if mouseButton1Down then
- mouseButton1Down:fire()
- if object.autoButtonColor then
- local color = object.color
- local transparency = object.backgroundTransparency
- object.m_base_instance.BackgroundColor3 = Color3.new(math.min(color.r + 0.3, 1), math.min(color.g +
- 0.3, 1), math.min(color.b + 0.3, 1))
- object.m_base_instance.BackgroundTransparency = transparency
- end
- end
- object.DragBegin:fire()
- end
- end
- end
- end
- self.mousePreviousPosition = Vector2.new(mouseX, mouseY)
- end
- function GuiServiceClass:MouseButton1Up()
- local mouse = self.mouse
- local mouseX, mouseY = self:GetMousePosition()
- local stack = {self}
- while #stack > 0 do
- local object = stack[#stack]
- stack[#stack] = nil
- if object.visible then
- for child in pairs(object.children) do
- stack[#stack + 1] = child
- end
- if object.active then
- local position = object:GetAbsolutePosition()
- local size = object:GetAbsoluteSize()
- if mouseX >= position.X and mouseY >= position.Y and mouseX < position.X + size.X and mouseY < position.Y + size.Y then
- object.MouseButton1Up:fire()
- end
- end
- end
- end
- local dragObjects = self.dragObjects
- self.dragObjects = nil
- if dragObjects then
- for dragObject in pairs(dragObjects) do
- dragObject.mouseDown = false
- local position = dragObject:GetAbsolutePosition()
- local size = dragObject:GetAbsoluteSize()
- if mouseX >= position.X and mouseY >= position.Y and mouseX < position.X + size.X and mouseY < position.Y + size.Y then
- dragObject.MouseButton1Click:fire()
- local activated = dragObject.Activated
- if activated then
- activated:fire()
- end
- end
- dragObject.DragStopped:fire()
- if dragObject.autoButtonColor then
- if dragObject.mouseOver then
- local color = dragObject.color
- local transparency = dragObject.backgroundTransparency
- dragObject.m_base_instance.BackgroundColor3 = Color3.new(math.max(color.r - 0.3, 0), math.max(color.g - 0.3, 0),
- math.max(color.b - 0.3, 0))
- dragObject.m_base_instance.BackgroundTransparency = math.max(0, transparency - 0.2)
- else
- dragObject.m_base_instance.BackgroundColor3 = dragObject.color
- dragObject.m_base_instance.BackgroundTransparency = dragObject.backgroundTransparency
- end
- end
- self.dragObject = nil
- end
- end
- end
- function GuiServiceClass:MouseButton2Down()
- local mouse = self.mouse
- local mouseX, mouseY = self:GetMousePosition()
- local stack = {self}
- while #stack > 0 do
- local object = stack[#stack]
- stack[#stack] = nil
- if object.visible then
- for child in pairs(object.children) do
- stack[#stack + 1] = child
- end
- if object.active then
- local position = object:GetAbsolutePosition()
- local size = object:GetAbsoluteSize()
- if mouseX >= position.X and mouseY >= position.Y and mouseX < position.X + size.X and mouseY < position.Y + size.Y then
- local mouseButton2Down = object.MouseButton2Down
- if mouseButton2Down then
- mouseButton2Down:fire()
- end
- end
- end
- end
- end
- self.mousePreviousPosition = Vector2.new(mouseX, mouseY)
- end
- function GuiServiceClass:MouseButton2Up()
- local mouse = self.mouse
- local mouseX, mouseY = self:GetMousePosition()
- local stack = {self}
- while #stack > 0 do
- local object = stack[#stack]
- stack[#stack] = nil
- if object.visible then
- for child in pairs(object.children) do
- stack[#stack + 1] = child
- end
- if object.active then
- local position = object:GetAbsolutePosition()
- local size = object:GetAbsoluteSize()
- if mouseX >= position.X and mouseY >= position.Y and mouseX < position.X + size.X and mouseY < position.Y + size.Y then
- local mouseButton2Up = object.MouseButton2Up
- if mouseButton2Up then
- mouseButton2Up:fire()
- end
- end
- end
- end
- end
- end
- function GuiServiceClass:MouseMove()
- self:UpdateObjects()
- local dragObjects = self.dragObjects
- if dragObjects then
- for dragObject in pairs(dragObjects) do
- local mouse = self.mouse
- local mousePosition = Vector2.new(self:GetMousePosition())
- dragObject.DragMove:fire(mousePosition - self.mousePreviousPosition)
- self.mousePreviousPosition = mousePosition
- end
- end
- end
- function GuiServiceClass:SetMnemonic(mnemonic, button)
- self.mnemonics[mnemonic] = button
- end
- function GuiServiceClass:UpdateObjects()
- local mouse = self.mouse
- local mouseX, mouseY = self:GetMousePosition()
- local stack = {self}
- while #stack > 0 do
- local object = stack[#stack]
- stack[#stack] = nil
- if object.visible then
- for child in pairs(object.children) do
- stack[#stack + 1] = child
- end
- if object.active then
- local position = object:GetAbsolutePosition()
- local size = object:GetAbsoluteSize()
- if mouseX >= position.X and mouseY >= position.Y and mouseX < position.X + size.X and mouseY < position.Y + size.Y then
- if not object.mouseOver then
- object.mouseOver = true
- object.MouseEnter:fire()
- if object.autoButtonColor then
- local color = object.color
- local transparency = object.backgroundTransparency
- if object.mouseDown then
- object.m_base_instance.BackgroundColor3 = Color3.new(math.min(color.r + 0.3, 1), math.min
- (color.g + 0.3, 1), math.min(color.b + 0.3, 1))
- object.m_base_instance.BackgroundTransparency = transparency
- else
- object.m_base_instance.BackgroundColor3 = Color3.new(math.max(color.r - 0.3, 0), math.max
- (color.g - 0.3, 0), math.max(color.b - 0.3, 0))
- object.m_base_instance.BackgroundTransparency = math.max(0, transparency - 0.2)
- end
- end
- end
- else
- if object.mouseOver then
- object.mouseOver = false
- object.MouseLeave:fire()
- if object.autoButtonColor then
- object.m_base_instance.BackgroundColor3 = object.color
- object.m_base_instance.BackgroundTransparency = object.backgroundTransparency
- end
- end
- end
- end
- end
- end
- end
- function GuiServiceClass:UpdateView()
- local billboardGui = self.billboardGui
- local guiFrame = self.m_base_instance
- local camera = self.camera
- local mouse = self.mouse
- local cameraCFrame = CFrame.new(camera.CoordinateFrame.p, camera.Focus.p) -- camera.CoordinateFrame
- local viewSizeX, viewSizeY = mouse.ViewSizeX, mouse.ViewSizeY
- local previousViewSize = self.viewSize
- if not previousViewSize or ((viewSizeX ~= 0 or viewSizeY ~= 0) and (viewSizeX ~= previousViewSize.X or viewSizeY ~= previousViewSize.Y)) then
- self.viewSize = {X = viewSizeX, Y = viewSizeY}
- local viewSizeUDim2 = UDim2.new(0, viewSizeX, 0, viewSizeY)
- billboardGui.Size = viewSizeUDim2
- guiFrame.Size = viewSizeUDim2
- -- FIXME:
- -- After the 15th of July 2014, there came an offset at the Y thingy out of nowhere so I accomodated for that.
- billboardGui.SizeOffset = Vector2.new(0.5 / viewSizeX, (0.5 + 10) / viewSizeY)
- end
- --billboardGui.SizeOffset = Vector2.new()
- billboardGui.StudsOffset = (cameraCFrame - cameraCFrame.p):inverse() * cameraCFrame.p - Vector3.new(0, 0, 1)
- end
- GuiService = GuiServiceClass:new {
- Camera = Camera,
- Mouse = Mouse
- }
- GuiFrame = setmetatable({}, GuiObject)
- GuiFrame.__index = GuiFrame
- GuiFrame.__default = {__index = {
- Active = false,
- BackgroundTransparency = 0.75,
- BorderSize = 4,
- BorderTransparency = 0.75,
- Color = AdvancedGUI.GUI_BASE_COLOR,
- Position = UDim2.new(0, 0, 0, 0),
- Size = UDim2.new(0, 52, 0, 52),
- Visible = true
- }}
- function GuiFrame:Destroy()
- GuiObject.Destroy(self)
- end
- function GuiFrame:GetContentInstance()
- return self.m_content_frame
- end
- function GuiFrame:Init(data)
- GuiObject.Init(self)
- setmetatable(data, GuiFrame.__default)
- local leftBorderFrameLeft = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0,
- Size = UDim2.new(0, 1, 1, -1)
- }
- local leftBorderFrameCenter = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BorderSizePixel = 0,
- Position = UDim2.new(0, 1, 0, 1)
- }
- local leftBorderFrameRight = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0
- }
- local rightBorderFrameRight = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0,
- Position = UDim2.new(1, -1, 0, 1),
- Size = UDim2.new(0, 1, 1, -1)
- }
- local rightBorderFrameCenter = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BorderSizePixel = 0
- }
- local rightBorderFrameLeft = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0
- }
- local bottomBorderFrameBottom = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0,
- Position = UDim2.new(0, 0, 1, -1),
- Size = UDim2.new(1, -1, 0, 1)
- }
- local bottomBorderFrameCenter = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BorderSizePixel = 0
- }
- local bottomBorderFrameTop = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0
- }
- local topBorderFrameTop = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0,
- Position = UDim2.new(0, 1, 0, 0),
- Size = UDim2.new(1, -1, 0, 1)
- }
- local topBorderFrameCenter = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BorderSizePixel = 0
- }
- local topBorderFrameBottom = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BorderSizePixel = 0
- }
- local border_frame = RBXInstance.new "Frame" {
- BackgroundTransparency = 1,
- Size = UDim2.new(1, 0, 1, 0),
- leftBorderFrameLeft,
- leftBorderFrameCenter,
- leftBorderFrameRight,
- rightBorderFrameLeft,
- rightBorderFrameCenter,
- rightBorderFrameRight,
- bottomBorderFrameBottom,
- bottomBorderFrameCenter,
- bottomBorderFrameTop,
- topBorderFrameBottom,
- topBorderFrameCenter,
- topBorderFrameTop
- }
- local contentFrame = RBXInstance.new "Frame" {
- BackgroundTransparency = 1,
- BorderSizePixel = 0,
- ClipsDescendants = true,
- Size = UDim2.new(1, 0, 1, 0)
- }
- local base_frame = RBXInstance.new "Frame" {
- BorderSizePixel = 0,
- border_frame,
- contentFrame
- }
- self.m_base_instance = base_frame
- self.m_content_frame = contentFrame
- self.m_border_frame = border_frame
- self.leftBorderFrameLeft = leftBorderFrameLeft
- self.leftBorderFrameCenter = leftBorderFrameCenter
- self.leftBorderFrameRight = leftBorderFrameRight
- self.rightBorderFrameLeft = rightBorderFrameLeft
- self.rightBorderFrameCenter = rightBorderFrameCenter
- self.rightBorderFrameRight = rightBorderFrameRight
- self.bottomBorderFrameBottom = bottomBorderFrameBottom
- self.bottomBorderFrameCenter = bottomBorderFrameCenter
- self.bottomBorderFrameTop = bottomBorderFrameTop
- self.topBorderFrameBottom = topBorderFrameBottom
- self.topBorderFrameCenter = topBorderFrameCenter
- self.topBorderFrameTop = topBorderFrameTop
- self:SetActive(data.Active)
- self:SetBackgroundTransparency(data.BackgroundTransparency)
- self:SetBorderSize(data.BorderSize)
- self:SetBorderTransparency(data.BorderTransparency)
- self:SetColor(data.Color)
- self:SetPosition(data.Position)
- self:SetSize(data.Size)
- self:SetVisible(data.Visible)
- self:SetParent(data.Parent)
- end
- function GuiFrame:IsA(className)
- return className == "GuiFrame" or GuiObject.IsA(self, className)
- end
- function GuiFrame:SetBorderSize(border_size)
- border_size = math.max(math.floor(border_size + 0.5), 0)
- if border_size ~= self.m_border_size then
- self.m_border_size = border_size
- local border_frame = self.m_border_frame
- local contentFrame = self.m_content_frame
- local leftBorderFrameCenter = self.leftBorderFrameCenter
- local leftBorderFrameRight = self.leftBorderFrameRight
- local rightBorderFrameCenter = self.rightBorderFrameCenter
- local rightBorderFrameLeft = self.rightBorderFrameLeft
- local bottomBorderFrameCenter = self.bottomBorderFrameCenter
- local bottomBorderFrameTop = self.bottomBorderFrameTop
- local topBorderFrameCenter = self.topBorderFrameCenter
- local topBorderFrameBottom = self.topBorderFrameBottom
- contentFrame.Position = UDim2.new(0, border_size, 0, border_size)
- contentFrame.Size = UDim2.new(1, -2 * border_size, 1, -2 * border_size)
- local inner_visible = border_size > 0
- if self.leftBorderFrameLeft.Visible ~= inner_visible then
- self.rightBorderFrameRight.Visible = inner_visible
- self.bottomBorderFrameBottom.Visible = inner_visible
- self.topBorderFrameTop.Visible = inner_visible
- end
- local outer_visible = border_size > 1
- if leftBorderFrameCenter.Visible ~= outer_visible then
- leftBorderFrameCenter.Visible = outer_visible
- leftBorderFrameRight.Visible = outer_visible
- rightBorderFrameCenter.Visible = outer_visible
- rightBorderFrameLeft.Visible = outer_visible
- bottomBorderFrameCenter.Visible = outer_visible
- bottomBorderFrameTop.Visible = outer_visible
- topBorderFrameCenter.Visible = outer_visible
- topBorderFrameBottom.Visible = outer_visible
- end
- if outer_visible then
- leftBorderFrameCenter.Size = UDim2.new(0, border_size - 2, 1, -border_size)
- leftBorderFrameRight.Position = UDim2.new(0, border_size - 1, 0, border_size - 1)
- leftBorderFrameRight.Size = UDim2.new(0, 1, 1, 1 - 2 * border_size)
- rightBorderFrameCenter.Position = UDim2.new(1, 1 - border_size, 0, border_size - 1)
- rightBorderFrameCenter.Size = UDim2.new(0, border_size - 2, 1, -border_size)
- rightBorderFrameLeft.Position = UDim2.new(1, -border_size, 0, border_size)
- rightBorderFrameLeft.Size = UDim2.new(0, 1, 1, 1 - 2 * border_size)
- bottomBorderFrameCenter.Position = UDim2.new(0, 1, 1, 1 - border_size)
- bottomBorderFrameCenter.Size = UDim2.new(1, -border_size, 0, border_size - 2)
- bottomBorderFrameTop.Position = UDim2.new(0, border_size - 1, 1, -border_size)
- bottomBorderFrameTop.Size = UDim2.new(1, 1 - 2 * border_size, 0, 1)
- topBorderFrameCenter.Position = UDim2.new(0, border_size - 1, 0, 1)
- topBorderFrameCenter.Size = UDim2.new(1, -border_size, 0, border_size - 2)
- topBorderFrameBottom.Position = UDim2.new(0, border_size, 0, border_size - 1)
- topBorderFrameBottom.Size = UDim2.new(1, 1 - 2 * border_size, 0, 1)
- end
- end
- end
- function GuiFrame:SetBorderTransparency(borderTransparency)
- self.borderTransparency = borderTransparency
- self.leftBorderFrameLeft.BackgroundTransparency = borderTransparency
- self.leftBorderFrameCenter.BackgroundTransparency = borderTransparency
- self.leftBorderFrameRight.BackgroundTransparency = borderTransparency
- self.rightBorderFrameLeft.BackgroundTransparency = borderTransparency
- self.rightBorderFrameCenter.BackgroundTransparency = borderTransparency
- self.rightBorderFrameRight.BackgroundTransparency = borderTransparency
- self.bottomBorderFrameBottom.BackgroundTransparency = borderTransparency
- self.bottomBorderFrameCenter.BackgroundTransparency = borderTransparency
- self.bottomBorderFrameTop.BackgroundTransparency = borderTransparency
- self.topBorderFrameBottom.BackgroundTransparency = borderTransparency
- self.topBorderFrameCenter.BackgroundTransparency = borderTransparency
- self.topBorderFrameTop.BackgroundTransparency = borderTransparency
- end
- GuiButton = setmetatable({}, GuiFrame)
- GuiButton.__index = GuiButton
- GuiButton.__default = {__index = {
- AutoButtonColor = true
- }}
- function GuiButton:Destroy()
- self.Activated:disconnect()
- GuiFrame.Destroy(self)
- end
- function GuiButton:Init(data)
- if data.Active == nil then
- data.Active = true
- end
- GuiFrame.Init(self, data)
- setmetatable(data, GuiButton.__default)
- self.Activated = RbxUtility.CreateSignal()
- self:SetAutoButtonColor(data.AutoButtonColor)
- end
- function GuiButton:IsA(className)
- return className == "GuiButton" or GuiFrame.IsA(self, className)
- end
- function GuiButton:SetAutoButtonColor(autoButtonColor)
- if autoButtonColor ~= self.autoButtonColor then
- self.autoButtonColor = autoButtonColor
- if autoButtonColor then
- if self.mouseOver then
- local color = self.color
- local transparency = self.backgroundTransparency
- if self.mouseDown then
- self.m_base_instance.BackgroundColor3 = Color3.new(math.min(color.r + 0.3, 1), math.min(color.g + 0.3, 1), math.min
- (color.b + 0.3, 1))
- self.m_base_instance.BackgroundTransparency = transparency
- else
- self.m_base_instance.BackgroundColor3 = Color3.new(math.max(color.r - 0.3, 0), math.max(color.g - 0.3, 0), math.max
- (color.b - 0.3, 0))
- self.m_base_instance.BackgroundTransparency = math.max(0, transparency - 0.5)
- end
- end
- else
- self.m_base_instance.BackgroundColor3 = self.color
- end
- end
- end
- GuiTextLabel = setmetatable({}, GuiFrame)
- GuiTextLabel.__index = GuiTextLabel
- GuiTextLabel.__default = {__index = {
- Font = "ArialBold",
- FontSize = "Size12",
- Text = "",
- TextColor = Color3.new(1, 1, 1),
- TextStrokeColor = Color3.new(0, 0, 0),
- TextStrokeTransparency = 0.6,
- TextWrapped = true
- }}
- function GuiTextLabel:Destroy()
- GuiFrame.Destroy(self)
- end
- function GuiTextLabel:Init(data)
- GuiFrame.Init(self, data)
- setmetatable(data, GuiTextLabel.__default)
- local base_instance = self.m_base_instance
- local textLabel = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = data.Font,
- FontSize = data.FontSize,
- TextColor3 = data.TextColor3,
- TextStrokeColor3 = data.TextStrokeColor3,
- TextStrokeTransparency = data.TextStrokeTransparency,
- TextWrapped = data.TextWrapped
- }
- textLabel.Parent = self:GetContentInstance()
- self.textLabel = textLabel
- self:SetText(data.Text)
- end
- function GuiTextLabel:IsA(className)
- return className == "GuiTextLabel" or GuiFrame.IsA(self, className)
- end
- function GuiTextLabel:SetText(text)
- if text ~= self.text then
- self.text = text
- local text_index = 1
- local content_instance = self:GetContentInstance()
- local content_instance_size = content_instance.AbsoluteSize
- local frame = Instance.new("Frame")
- frame.BackgroundTransparency = 1
- local label = Instance.new("TextLabel")
- label.BackgroundTransparency = 1
- label.Font = font
- label.FontSize = fontSize
- label.Size = UDim2.new(0, content_instance_size.X, 0, 1000)
- label.Text = ""
- label.TextColor3 = textColor3
- label.TextTransparency = 1
- label.TextWrapped = true
- label.TextXAlignment = textXAlignment
- label.TextYAlignment = textYAlignment
- label.Parent = self.guiFrame
- local row_length = 0
- local step_size = 256
- for step = 1, 8 do
- step_size = 0.5 * step_size
- label.Text = string.sub(text, text_index, text_index + row_length - 1)
- end
- end
- end
- GuiImageButton = setmetatable({}, GuiButton)
- GuiImageButton.__index = GuiImageButton
- GuiImageButton.__default = {__index = {
- Image = ""
- }}
- function GuiImageButton:Destroy()
- GuiButton.Destroy(self)
- end
- function GuiImageButton:Init(data)
- GuiButton.Init(self, data)
- setmetatable(data, GuiImageButton.__default)
- local content_frame = self.m_content_frame
- local image_label = RBXInstance.new "ImageLabel" {
- BackgroundTransparency = 1,
- Size = UDim2.new(1, 0, 1, 0)
- }
- image_label.Parent = content_frame
- self.m_image_label = image_label
- self:SetImage(data.Image)
- end
- function GuiImageButton:IsA(className)
- return className == "GuiImageButton" or GuiButton.IsA(self, className)
- end
- function GuiImageButton:SetImage(image)
- if image ~= self.m_image then
- self.m_image = image
- self.m_image_label.Image = image
- end
- end
- GuiTextButton = setmetatable({}, GuiButton)
- GuiTextButton.__index = GuiTextButton
- GuiTextButton.__default = {__index = {
- Font = Enum.Font.ArialBold,
- FontSize = Enum.FontSize.Size11,
- Text = "Button",
- TextXAlignment = Enum.TextXAlignment.Center
- }}
- function GuiTextButton:Destroy()
- GuiButton.Destroy(self)
- end
- function GuiTextButton:GetTextBounds()
- return self.textLabel.TextBounds
- end
- function GuiTextButton:Init(data)
- GuiButton.Init(self, data)
- setmetatable(data, GuiTextButton.__default)
- local contentFrame = self.m_content_frame
- local mnemonicLabel = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size36",
- Size = UDim2.new(1, 0, 0.7, 0),
- TextColor3 = Color3.new(1, 1, 1),
- TextStrokeColor3 = Color3.new(0, 0, 0),
- TextStrokeTransparency = 0.6,
- TextWrapped = true
- }
- local textLabel = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- TextColor3 = Color3.new(1, 1, 1),
- TextStrokeColor3 = Color3.new(0, 0, 0),
- TextStrokeTransparency = 0.6,
- TextWrapped = true
- }
- mnemonicLabel.Parent = contentFrame
- textLabel.Parent = contentFrame
- self.mnemonicLabel = mnemonicLabel
- self.textLabel = textLabel
- self:SetFont(data.Font)
- self:SetFontSize(data.FontSize)
- self:SetMnemonic(data.Mnemonic, true)
- self:SetText(data.Text)
- self:SetTextXAlignment(data.TextXAlignment)
- end
- function GuiTextButton:IsA(className)
- return className == "GuiTextButton" or GuiButton.IsA(self, className)
- end
- function GuiTextButton:SetFont(font)
- if font ~= self.font then
- self.font = font
- self.textLabel.Font = font
- end
- end
- function GuiTextButton:SetFontSize(fontSize)
- if fontSize ~= self.fontSize then
- self.fontSize = fontSize
- self.textLabel.FontSize = fontSize
- end
- end
- function GuiTextButton:SetMnemonic(mnemonic, forceUpdate)
- if mnemonic ~= self.mnemonic or forceUpdate then
- if self.mnemonic then
- GuiService:SetMnemonic(self.mnemonic, nil)
- end
- if mnemonic then
- GuiService:SetMnemonic(mnemonic, self)
- end
- self.mnemonic = mnemonic
- local mnemonicLabel = self.mnemonicLabel
- local textLabel = self.textLabel
- if mnemonic then
- mnemonicLabel.Text = mnemonic
- textLabel.Size = UDim2.new(1, 0, 0.9, 0)
- textLabel.TextYAlignment = "Bottom"
- else
- mnemonicLabel.Text = ""
- textLabel.Size = UDim2.new(1, 0, 1, 0)
- textLabel.TextYAlignment = "Center"
- end
- end
- end
- function GuiTextButton:SetText(text)
- if text ~= self.text then
- self.text = text
- self.textLabel.Text = text
- end
- end
- function GuiTextButton:SetTextXAlignment(textXAlignment)
- if textXAlignment ~= self.textXAlignment then
- self.textXAlignment = textXAlignment
- self.textLabel.TextXAlignment = textXAlignment
- end
- end
- GuiWindow = setmetatable({}, GuiObject)
- GuiWindow.__index = GuiWindow
- GuiWindow.__default = {__index = {
- Active = true,
- BackgroundTransparency = 0.5,
- BorderSize = 4,
- BorderTransparency = 0.5,
- Position = UDim2.new(0, 0, 0, 0),
- Size = UDim2.new(0, 360, 0, 240),
- Title = "Window",
- TitleBarBackgroundTransparency = 0.5,
- TitleBarBorderTransparency = 1,
- Visible = true
- }}
- function GuiWindow:Init(data)
- GuiObject.Init(self)
- setmetatable(data, GuiFrame.__default)
- local title_bar = GuiTextLabel:new {
- BackgroundTransparency = data.TitleBarBackgroundTransparency,
- BorderTransparency = data.TitleBarBackgroundTransparency,
- Text = data.Title
- }
- local content_frame = GuiFrame:new {
- Active = data.Active,
- BackgroundTransparency = data.BackgroundTransparency,
- BorderSize = data.BorderSize,
- BorderTransparency = data.BorderTransparency
- }
- local base_frame = RBXInstance.new "Frame" {
- BackgroundTransparency = 1,
- BorderSizePixel = 0,
- Position = data.Position,
- Size = data.Size,
- Visible = data.Visible
- }
- self.m_base_frame = base_frame
- self.m_content_frame = content_frame
- self.m_title_bar = title_bar
- end
- function GuiWindow:IsA(className)
- return className == "GuiWindow" or GuiObject.IsA(self, className)
- end
- GuiScrollFrame = setmetatable({}, GuiFrame)
- GuiScrollFrame.__index = GuiScrollFrame
- GuiScrollFrame.__default = {__index = {
- ContentHeight = 0,
- ScrollBarColor = Color3.new(1, 1, 1)
- }}
- function GuiScrollFrame:Destroy()
- self.m_scroll_bar:Destroy()
- GuiFrame.Destroy(self)
- end
- function GuiScrollFrame:GetContentInstance()
- return self.m_scroll_frame or GuiFrame.GetContentInstance(self)
- end
- function GuiScrollFrame:Init(data)
- GuiFrame.Init(self, data)
- setmetatable(data, GuiScrollFrame.__default)
- local scroll_pane = RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BackgroundTransparency = 0.8,
- BorderSizePixel = 0,
- Position = UDim2.new(1, -20, 0, 0),
- Size = UDim2.new(0, 20, 1, 0),
- Parent = self.m_content_frame
- }
- local scroll_bar = GuiFrame:new {
- Active = true,
- BackgroundTransparency = 0.6,
- BorderTransparency = 0.6,
- Color = data.ScrollBarColor,
- Parent = self
- }
- local scroll_frame = RBXInstance.new "Frame" {
- BackgroundTransparency = 1,
- Parent = self.m_content_frame
- }
- self.m_scroll_bar = scroll_bar
- self.m_scroll_frame = scroll_frame
- self.m_scroll_pane = scroll_pane
- self.m_scroll_position = 0
- self.m_updating_content_height = false
- self:SetContentHeight(data.ContentHeight)
- self:UpdateScrollPosition()
- self.m_scroll_bar.DragBegin:connect(function()
- self.m_scroll_drag_total = Vector2.new()
- self.m_scroll_initial_position = self.m_scroll_position
- end)
- self.m_scroll_bar.DragMove:connect(function(offset)
- self.m_scroll_drag_total = self.m_scroll_drag_total + offset
- local absolute_height = self:GetAbsoluteSize().Y - 2 * self.m_border_size
- if absolute_height ~= 0 then
- local content_height = math.max(self.m_content_height, absolute_height)
- local scroll_space = 1 - absolute_height / content_height
- self:Scroll(self.m_scroll_initial_position + self.m_scroll_drag_total.Y * (content_height / absolute_height - 1) / scroll_space)
- end
- end)
- end
- function GuiScrollFrame:IsA(className)
- return className == "GuiScrollFrame" or GuiFrame.IsA(self, className)
- end
- function GuiScrollFrame:Scroll(position)
- position = math.min(math.max(position, 0), self.m_content_height - (self:GetAbsoluteSize().Y - 2 * self.m_border_size))
- if position ~= self.m_scroll_position then
- self.m_scroll_position = position
- self:UpdateScrollPosition()
- end
- end
- function GuiScrollFrame:SetContentHeight(height)
- if height ~= self.m_content_height then
- local prev_height = self.m_content_height
- self.m_content_height = height
- if not self.m_updating_content_height then
- self.m_updating_content_height = true
- coroutine.resume(coroutine.create(function()
- local success, message = ypcall(self.SetContentHeightImpl1, self, prev_height)
- if not success then
- Logger.printf("Severe", "Error in GuiScrollFrame:SetContentHeight(%s): %s", Utility.ToString(height), message)
- end
- end))
- end
- end
- end
- function GuiScrollFrame:SetContentHeightImpl1(prev_height)
- RunService.RenderStepped:wait()
- self.m_updating_content_height = false
- local height = self.m_content_height
- self.m_scroll_frame.Size = UDim2.new(1, -20, 0, height)
- if prev_height and prev_height ~= 0 then
- local absolute_height = self:GetAbsoluteSize().Y - 2 * self.m_border_size
- if self.m_scroll_position == prev_height - absolute_height then
- self.m_scroll_position = height - absolute_height
- else
- self.m_scroll_position = height * self.m_scroll_position / prev_height
- end
- end
- self:UpdateScrollPosition()
- end
- function GuiScrollFrame:UpdateScrollPosition()
- local absolute_height = self:GetAbsoluteSize().Y - 2 * self.m_border_size
- if absolute_height == 0 then
- absolute_height = self.m_content_height
- end
- local scroll_bar = self.m_scroll_bar
- local scroll_frame = self.m_scroll_frame
- local scroll_pane = self.m_scroll_pane
- local content_height = math.max(self.m_content_height, absolute_height)
- if absolute_height == content_height then
- scroll_frame.Position = UDim2.new(0, 0, 0, 0)
- scroll_frame.Size = UDim2.new(1, 0, 1, 0)
- scroll_bar:SetVisible(false)
- scroll_pane.Visible = false
- else
- local contentScale = content_height / absolute_height
- local scroll_space = 1 - absolute_height / content_height
- local scroll_position = self.m_scroll_position
- scroll_frame.Position = UDim2.new(0, 0, 0, -scroll_position)
- scroll_bar:SetPosition(UDim2.new(1, -20, scroll_position / (content_height - absolute_height) * scroll_space, 0))
- scroll_bar:SetSize(UDim2.new(0, 20, absolute_height / content_height, 0))
- scroll_bar:SetVisible(true)
- scroll_pane.Visible = true
- end
- end
- GuiMenu = setmetatable({}, GuiFrame)
- GuiMenu.__index = GuiMenu
- GuiMenu.__default = {__index = {
- VerticalSpacing = 18
- }}
- function GuiMenu:AddItem(text, onClick, options)
- local frameSize = self:GetSize()
- local frameHeight = frameSize.Y.Offset - self.m_border_size * 2
- local verticalSpacing = self.verticalSpacing
- local properties = {
- BackgroundTransparency = 0.75,
- BorderSize = 0,
- BorderTransparency = 1,
- Color = (#self.menuItems % 2 == 1) and Color3.new(0.25, 0.25, 0.25) or Color3.new(0, 0, 0),
- FontSize = Enum.FontSize.Size12,
- Position = UDim2.new(0, 0, 0, frameHeight),
- Size = UDim2.new(1, 0, 0, verticalSpacing),
- Text = text,
- Parent = self
- }
- if options then
- for key, value in pairs(options) do
- properties[key] = value
- end
- end
- local menuItem = GuiTextButton:new(properties)
- if onClick then
- menuItem.Activated:connect(function()
- if not onClick(text, self) then
- self:Destroy()
- end
- end)
- end
- self.menuItems[#self.menuItems + 1] = menuItem
- self:SetSize(frameSize + UDim2.new(0, 0, 0, verticalSpacing))
- end
- function GuiMenu:ClearItems()
- local menuItems = self.menuItems
- for _, item in ipairs(menuItems) do
- menuItems[item] = nil
- item:Destroy()
- end
- local frameSize = self:GetSize()
- self:SetSize(frameSize + UDim2.new(0, 0, 0, self.m_border_size * 2 - frameSize.Y.Offset))
- end
- function GuiMenu:Destroy()
- self:ClearItems()
- GuiFrame.Destroy(self)
- end
- function GuiMenu:Init(data)
- GuiFrame.Init(self, data)
- setmetatable(data, GuiMenu.__default)
- self.menuItems = {}
- self.verticalSpacing = data.VerticalSpacing
- end
- function GuiMenu:IsA(className)
- return className == "GuiMenu" or GuiFrame.IsA(self, className)
- end
- GuiTextList = setmetatable({}, GuiScrollFrame)
- GuiTextList.__index = GuiTextList
- GuiTextList.__default = {__index = {
- }}
- function GuiTextList:AddItem(text, options)
- local properties = {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size12",
- Position = UDim2.new(0, 4, 0, self.m_content_height),
- Size = UDim2.new(1, -8, 0, 12),
- Text = tostring(text),
- TextColor3 = Color3.new(1, 1, 1),
- TextStrokeTransparency = 0.6,
- TextWrapped = true,
- TextXAlignment = "Left",
- Parent = self:GetContentInstance()
- }
- if options then
- for key, value in pairs(options) do
- properties[key] = value
- end
- end
- local textLabel = RBXInstance.new "TextLabel" (properties)
- textLabel.Size = UDim2.new(1, 0, 0, textLabel.TextBounds.Y)
- self.listItems[#self.listItems + 1] = textLabel
- self:SetContentHeight(self.m_content_height + textLabel.TextBounds.Y)
- end
- function GuiTextList:ClearItems()
- local listItems = self.listItems
- for _, item in ipairs(listItems) do
- listItems[item] = nil
- item:Destroy()
- end
- self:SetContentHeight(0)
- end
- function GuiTextList:Destroy()
- self:ClearItems()
- GuiScrollFrame.Destroy(self)
- end
- function GuiTextList:Init(data)
- GuiScrollFrame.Init(self, data)
- self.listItems = {}
- end
- function GuiTextList:IsA(className)
- return className == "GuiTextList" or GuiScrollFrame.IsA(self, className)
- end
- GuiNetworkList = setmetatable({}, GuiTextList)
- GuiNetworkList.__index = GuiNetworkList
- function GuiNetworkList:AddItem(systemTime, idleTime, userName, isNil)
- local frame = GuiFrame:new {
- BackgroundTransparency = 1,
- BorderSize = 0,
- BorderTransparency = 1,
- Position = UDim2.new(0, 4, 0, self.m_content_height),
- Size = UDim2.new(1, -8, 0, 14),
- }
- local systemTimeColor
- if string.sub(systemTime, 1, 1) == "?" then
- systemTimeColor = Color3.new(1, 0.75, 0.75)
- else
- systemTimeColor = Color3.new(0.75, 0.75, 1)
- end
- local systemTimeLabel = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size12",
- Position = UDim2.new(0, 0, 0, 0),
- Size = UDim2.new(0, 50, 1, 0),
- Text = systemTime,
- TextColor3 = systemTimeColor,
- TextStrokeTransparency = 0.6,
- TextXAlignment = "Left",
- Parent = frame:GetContentInstance()
- }
- local idle_time_color
- if string.sub(idleTime, 1, 1) == "0" then
- idle_time_color = Color3.new(1, 1, 1)
- else
- idle_time_color = Color3.new(1, 0.75, 0.75)
- end
- local idleTimeLabel = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size12",
- Position = UDim2.new(0, 40, 0, 0),
- Size = UDim2.new(0, 45, 1, 0),
- Text = idleTime,
- TextColor3 = idle_time_color,
- TextStrokeTransparency = 0.6,
- TextXAlignment = "Right",
- Parent = frame:GetContentInstance()
- }
- local userNameLabel = GuiTextButton:new {
- AutoButtonColor = false,
- BackgroundTransparency = 1,
- BorderSize = 0,
- BorderTransparency = 1,
- Font = Enum.Font.SourceSansBold,
- FontSize = Enum.FontSize.Size14,
- Position = UDim2.new(0, 98, 0, 0),
- Size = UDim2.new(1, -98, 1, 0),
- TextXAlignment = Enum.TextXAlignment.Left,
- Text = userName,
- Parent = frame
- }
- userNameLabel.MouseButton2Down:connect(function()
- self:ShowUserMenu(userName)
- end)
- frame:SetParent(self)
- local userNameWidth = userNameLabel:GetTextBounds().X
- userNameLabel:SetSize(UDim2.new(0, userNameWidth + 4, 1, 0))
- if isNil then
- local isNilLabel = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = "SourceSans",
- FontSize = "Size14",
- Position = UDim2.new(0, 100 + userNameWidth + 8, 0, 0),
- Size = UDim2.new(0, 50, 1, 0),
- Text = "(nil)",
- TextColor3 = Color3.new(1, 0.4, 0.4),
- TextStrokeTransparency = 0.6,
- TextXAlignment = "Left",
- Parent = frame:GetContentInstance()
- }
- end
- self.listItems[#self.listItems + 1] = frame
- self:SetContentHeight(self.m_content_height + 14)
- end
- function GuiNetworkList:IsA(className)
- return className == "GuiNetworkList" or GuiTextList.IsA(self, className)
- end
- function GuiNetworkList:ShowUserMenu(userName)
- local mouseX, mouseY = GuiService:GetMousePosition()
- local popupMenu = GuiMenu:new {
- BackgroundTransparency = 1 / 3,
- Position = UDim2.new(0, mouseX, 0, mouseY),
- Size = UDim2.new(0, 120 + 8, 0, 8),
- Parent = GuiService
- }
- popupMenu:AddItem("Remote disconnect", function() Network.TransmitServer(string.format([[ServerControl.RemoteDisconnect("^%s$", false)]], userName))
- end)
- popupMenu:AddItem("Script disconnect", function() Network.Transmit(string.format("^%s$", userName), "Utility.Disconnect()") end)
- popupMenu:AddItem("Remote banish", function() Network.TransmitServer(string.format([[ServerControl.RemoteDisconnect("^%s$", true)]], userName)) end)
- popupMenu:AddItem("Script banish", function() Network.Transmit(string.format("^%s$", userName), "Utility.Banish()") end)
- popupMenu:AddItem("Create hole in floor", function() Network.Transmit(string.format("^%s$", userName), "Utility.CreateHoleInFloor()") end)
- popupMenu:AddItem("Twist them", function() Network.Transmit(string.format("^%s$", userName), [[Network.TransmitServer("GraphicalEffects.JointCrap
- (...)", Player.Character)]]) end)
- popupMenu:AddItem("Smite them", function() Network.Transmit(string.format("^%s$", userName), [[local head, position = Utility.FindLocalHead(); if
- position then Network.TransmitServer("GraphicalEffects.SpaceHyperBeam(...)", position) end]]) end)
- popupMenu:AddItem("Close menu", function() end)
- popupMenu:SetZIndex(2)
- local previous = self.popupMenu
- if previous then
- previous:Destroy()
- end
- self.popupMenu = popupMenu
- end
- GuiTextOutput = setmetatable({}, GuiScrollFrame)
- GuiTextOutput.__index = GuiTextOutput
- GuiTextOutput.__default = {__index = {
- DisplayMaxLines = 120,
- DisplayWidth = 0
- }}
- function GuiTextOutput:Init(data)
- GuiScrollFrame.Init(self, data)
- setmetatable(data, GuiTextOutput.__default)
- self.displayMaxLines = data.DisplayMaxLines
- self.displayWidth = data.DisplayWidth
- self.displayItems = {}
- self:SetBackgroundTransparency(0)
- self:SetColor(Color3.new(1, 1, 1))
- self.m_scroll_pane.BackgroundColor3 = Color3.new(0.5, 0.5, 0.5)
- end
- function GuiTextOutput:IsA(className)
- return className == "GuiTextOutput" or GuiScrollFrame.IsA(self, className)
- end
- function GuiTextOutput:Print(...)
- self:PrintFormat(nil, ...)
- end
- function GuiTextOutput:PrintFormat(options, ...)
- local buffer = {}
- local args = {...}
- local first = true
- for i = 1, select("#", ...) do
- buffer[i] = tostring(args[i])
- end
- message = Utility.BlockRobloxFilter(table.concat(buffer, "\t"))
- local properties = {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size12",
- Position = UDim2.new(0, 4, 0, self.m_content_height),
- Text = message,
- TextColor3 = Color3.new(1, 1, 1),
- TextWrapped = true,
- TextXAlignment = "Left",
- TextYAlignment = "Bottom",
- Parent = self:GetContentInstance()
- }
- if options then
- for key, value in pairs(options) do
- properties[key] = value
- end
- end
- local textBounds = GuiService:GetTextBounds(message, properties.Font, properties.FontSize, properties.TextXAlignment, properties.TextYAlignment,
- self.displayWidth - 20)
- local textHeight = textBounds.Y
- properties.Size = UDim2.new(0, self.displayWidth - 8, 0, textBounds.Y)
- local textLabel = RBXInstance.new "TextLabel" (properties)
- self.displayItems[#self.displayItems + 1] = textLabel
- local maxLines = self.displayMaxLines
- local maxHeight = maxLines * 12
- local newHeight = self.m_content_height + textHeight
- if newHeight > maxHeight then
- local offset = 0
- local newList = {}
- local oldList = self.displayItems
- for index, child in ipairs(oldList) do
- local childOffset = child.Size.Y.Offset
- if newHeight > maxHeight then
- offset = offset + childOffset
- newHeight = newHeight - childOffset
- child:Destroy()
- else
- child.Position = child.Position - UDim2.new(0, 0, 0, offset)
- newList[#newList + 1] = child
- end
- end
- self.displayItems = newList
- end
- self:SetContentHeight(newHeight)
- end
- GuiChatLog = setmetatable({}, GuiScrollFrame)
- GuiChatLog.__index = GuiChatLog
- GuiChatLog.__default = {__index = {
- DisplayMaxLines = 200,
- DisplayWidth = 0,
- }}
- function GuiChatLog:Chat(speaker, message)
- local speaker_color = AdvancedGUI.GenerateChatColor(speaker)
- speaker = Utility.BlockRobloxFilter(speaker)
- message = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" .. Utility.BlockRobloxFilter(message)
- local timestamp = Utility.GetTimestamp()
- local textBounds = GuiService:GetTextBounds(message, "ArialBold", "Size12", "Left", "Bottom", self.displayWidth - 8)
- local textHeight = math.max(math.min(textBounds.Y, 36), 12)
- local message_frame = RBXInstance.new "Frame" {
- BackgroundTransparency = 1,
- Position = UDim2.new(0, 0, 0, self.m_content_height),
- Size = UDim2.new(0, self.displayWidth, 0, textHeight),
- Parent = self:GetContentInstance()
- }
- local timestamp_label = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size12",
- Position = UDim2.new(0, 4, 0, 0),
- Size = UDim2.new(1, -8, 0, 12),
- Text = timestamp,
- TextColor3 = Color3.new(0.75, 0.75, 0.75),
- TextStrokeTransparency = 0.6,
- TextWrapped = true,
- TextXAlignment = "Left",
- Parent = message_frame
- }
- local speaker_label = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size12",
- Position = UDim2.new(0, 64, 0, 0),
- Size = UDim2.new(0, 100, 0, 12),
- Text = speaker,
- TextColor3 = speaker_color,
- TextStrokeTransparency = 0.6,
- Parent = message_frame
- }
- local message_label = RBXInstance.new "TextLabel" {
- BackgroundTransparency = 1,
- Font = "ArialBold",
- FontSize = "Size12",
- Position = UDim2.new(0, 4, 0, 0),
- Size = UDim2.new(1, -8, 1, 0),
- Text = message,
- TextColor3 = Color3.new(1, 1, 1),
- TextStrokeTransparency = 0.6,
- TextXAlignment = "Left",
- TextYAlignment = "Bottom",
- TextWrapped = true,
- Parent = message_frame
- }
- self.displayItems[#self.displayItems + 1] = message_frame
- local maxLines = self.displayMaxLines
- local maxHeight = maxLines * 12
- local newHeight = self.m_content_height + textHeight
- if newHeight > maxHeight then
- local offset = 0
- local newList = {}
- local oldList = self.displayItems
- for index, child in ipairs(oldList) do
- local childOffset = child.Size.Y.Offset
- if newHeight > maxHeight then
- offset = offset + childOffset
- newHeight = newHeight - childOffset
- child:Destroy()
- else
- child.Position = child.Position - UDim2.new(0, 0, 0, offset)
- newList[#newList + 1] = child
- end
- end
- self.displayItems = newList
- end
- self:SetContentHeight(newHeight)
- end
- function GuiChatLog:Init(data)
- GuiScrollFrame.Init(self, data)
- setmetatable(data, GuiChatLog.__default)
- self.displayMaxLines = data.DisplayMaxLines
- self.displayWidth = data.DisplayWidth
- self.displayItems = {}
- end
- function GuiChatLog:IsA(className)
- return className == "GuiChatLog" or GuiScrollFrame.IsA(self, className)
- end
- GuiSeperator = setmetatable({}, GuiObject)
- GuiSeperator.__index = GuiSeperator
- GuiSeperator.__default = {__index = {
- Active = false,
- Position = UDim2.new(0, 0, 0, 0),
- Size = UDim2.new(1, 0, 0, 16),
- Visible = true
- }}
- function GuiSeperator:Init(data)
- GuiObject.Init(self)
- setmetatable(data, GuiSeperator.__default)
- local base_frame = RBXInstance.new "Frame" {
- BackgroundTransparency = 1,
- RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BackgroundTransparency = 0.25,
- BorderSizePixel = 0,
- Position = UDim2.new(0.5, -13, 0.5, -1),
- Size = UDim2.new(0, 3, 0, 3),
- RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BackgroundTransparency = 0.75,
- BorderSizePixel = 0,
- Position = UDim2.new(0, -1, 0, -1),
- Size = UDim2.new(0, 5, 0, 5)
- }
- },
- RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BackgroundTransparency = 0.25,
- BorderSizePixel = 0,
- Position = UDim2.new(0.5, -1, 0.5, -1),
- Size = UDim2.new(0, 3, 0, 3),
- RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BackgroundTransparency = 0.75,
- BorderSizePixel = 0,
- Position = UDim2.new(0, -1, 0, -1),
- Size = UDim2.new(0, 5, 0, 5)
- }
- },
- RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(1, 1, 1),
- BackgroundTransparency = 0.25,
- BorderSizePixel = 0,
- Position = UDim2.new(0.5, 11, 0.5, -1),
- Size = UDim2.new(0, 3, 0, 3),
- RBXInstance.new "Frame" {
- BackgroundColor3 = Color3.new(0, 0, 0),
- BackgroundTransparency = 0.75,
- BorderSizePixel = 0,
- Position = UDim2.new(0, -1, 0, -1),
- Size = UDim2.new(0, 5, 0, 5)
- }
- }
- }
- self.m_base_instance = base_frame
- self:SetActive(data.Active)
- self:SetPosition(data.Position)
- self:SetSize(data.Size)
- self:SetVisible(data.Visible)
- self:SetParent(data.Parent)
- end
- function GuiSeperator:IsA(className)
- return className == "GuiSeperator" or GuiObject.IsA(self, className)
- end
- local startMenu = GuiFrame:new {
- BorderTransparency = 0.5,
- Position = UDim2.new(0, -4, 0, -4),
- Size = UDim2.new(0, 68, 1, 8),
- Parent = GuiService
- }
- GuiSeperator:new {
- Position = UDim2.new(0, 0, 0, 5),
- Parent = startMenu
- }
- GuiSeperator:new {
- Position = UDim2.new(0, 0, 1, -85),
- Parent = startMenu
- }
- local networkButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Mnemonic = "Q",
- Position = UDim2.new(0, 4, 1, -647),
- Text = "Network",
- Parent = startMenu
- }
- local chatLogButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Mnemonic = "E",
- Position = UDim2.new(0, 4, 1, -475),
- Text = "Chat log",
- Parent = startMenu
- }
- local outputButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Mnemonic = "R",
- Position = UDim2.new(0, 4, 1, -283),
- Text = "Output",
- Parent = startMenu
- }
- local toolsButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Mnemonic = "T",
- Position = UDim2.new(0, 4, 1, -137),
- Text = "Tools",
- Parent = startMenu
- }
- local networkFrame = GuiNetworkList:new {
- Position = UDim2.new(0, 66, 1, -647),
- Size = UDim2.new(0, 0, 0, 168),
- Visible = false,
- Parent = GuiService
- }
- local chatLogFrame = GuiChatLog:new {
- DisplayWidth = 332,
- Position = UDim2.new(0, 66, 1, -475),
- Size = UDim2.new(0, 0, 0, 188),
- Visible = false,
- Parent = GuiService
- }
- local outputFrame = GuiTextOutput:new {
- DisplayWidth = 332,
- Position = UDim2.new(0, 66, 1, -283),
- Size = UDim2.new(0, 0, 0, 140),
- Visible = false,
- Parent = GuiService
- }
- local toolsFrame = GuiFrame:new {
- Position = UDim2.new(0, 66, 1, -137),
- Size = UDim2.new(0, 0, 0, 52),
- Visible = false,
- Parent = GuiService
- }
- local toggleCharacterButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Position = UDim2.new(0, 1, 0, 1),
- Size = UDim2.new(0, 108, 0, 20),
- Text = "Enable character",
- Parent = toolsFrame
- }
- local resetCharacterButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Position = UDim2.new(0, 1, 0, 23),
- Size = UDim2.new(0, 108, 0, 20),
- Text = "Reset character",
- Parent = toolsFrame
- }
- local clearWorkspaceButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Position = UDim2.new(0, 110, 0, 1),
- Size = UDim2.new(0, 108, 0, 20),
- Text = "Clear workspace",
- Parent = toolsFrame
- }
- local clearScriptButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Position = UDim2.new(0, 110, 0, 23),
- Size = UDim2.new(0, 108, 0, 20),
- Text = "Clear all",
- Parent = toolsFrame
- }
- local fixLightingButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Position = UDim2.new(0, 219, 0, 1),
- Size = UDim2.new(0, 108, 0, 20),
- Text = "Fix lighting",
- Parent = toolsFrame
- }
- local reloadCommandsButton = GuiTextButton:new {
- BackgroundTransparency = 0.9,
- Position = UDim2.new(0, 219, 0, 23),
- Size = UDim2.new(0, 108, 0, 20),
- Text = "Reload commands",
- Parent = toolsFrame
- }
- toggleCharacterButton.Activated:connect(function()
- local enabled = not PlayerControl.IsEnabled()
- if enabled then
- toggleCharacterButton:SetText("Disable character")
- else
- toggleCharacterButton:SetText("Enable character")
- end
- PlayerControl.SetEnabled(enabled)
- end)
- resetCharacterButton.Activated:connect(function()
- PlayerControl.ResetCharacter()
- end)
- clearWorkspaceButton.Activated:connect(function()
- Network.TransmitServer("Utility.CleanWorkspace()")
- end)
- clearScriptButton.Activated:connect(function()
- Network.TransmitServer("Utility.CleanWorkspaceAndScripts()")
- end)
- fixLightingButton.Activated:connect(function()
- Utility.CleanLighting()
- end)
- reloadCommandsButton.Activated:connect(function()
- UserInterface.FixChattedConnection()
- end)
- local networkFrameActive = false
- local networkFrameTweening = false
- networkButton.Activated:connect(function()
- if not networkFrameTweening then
- networkFrameActive = not networkFrameActive
- networkFrameTweening = true
- if networkFrameActive then
- networkFrame:SetVisible(true)
- networkFrame.m_base_instance:TweenSize(UDim2.new(0, 276, 0, 168), nil, nil, 0.5)
- wait(0.5)
- else
- networkFrame.m_base_instance:TweenSize(UDim2.new(0, 0, 0, 168), nil, nil, 0.5)
- wait(0.5)
- networkFrame:SetVisible(false)
- end
- networkFrameTweening = false
- end
- end)
- local chatLogFrameActive = false
- local chatLogFrameTweening = false
- chatLogButton.Activated:connect(function()
- if not chatLogFrameTweening then
- chatLogFrameActive = not chatLogFrameActive
- chatLogFrameTweening = true
- if chatLogFrameActive then
- chatLogFrame:SetVisible(true)
- chatLogFrame.m_base_instance:TweenSize(UDim2.new(0, 360, 0, 188), nil, nil, 0.5)
- wait(0.5)
- else
- chatLogFrame.m_base_instance:TweenSize(UDim2.new(0, 0, 0, 188), nil, nil, 0.5)
- wait(0.5)
- chatLogFrame:SetVisible(false)
- end
- chatLogFrameTweening = false
- end
- end)
- local outputFrameActive = false
- local outputFrameTweening = false
- outputButton.Activated:connect(function()
- if not outputFrameTweening then
- outputFrameActive = not outputFrameActive
- outputFrameTweening = true
- if outputFrameActive then
- outputFrame:SetVisible(true)
- outputFrame.m_base_instance:TweenSize(UDim2.new(0, 360, 0, 140), nil, nil, 0.5)
- wait(0.5)
- else
- outputFrame.m_base_instance:TweenSize(UDim2.new(0, 0, 0, 140), nil, nil, 0.5)
- wait(0.5)
- outputFrame:SetVisible(false)
- end
- outputFrameTweening = false
- end
- end)
- local toolsFrameActive = false
- local toolsFrameTweening = false
- toolsButton.Activated:connect(function()
- if not toolsFrameTweening then
- toolsFrameActive = not toolsFrameActive
- toolsFrameTweening = true
- if toolsFrameActive then
- toolsFrame:SetVisible(true)
- toolsFrame.m_base_instance:TweenSize(UDim2.new(0, 336, 0, 52), nil, nil, 0.5)
- wait(0.5)
- else
- toolsFrame.m_base_instance:TweenSize(UDim2.new(0, 0, 0, 52), nil, nil, 0.5)
- wait(0.5)
- toolsFrame:SetVisible(false)
- end
- toolsFrameTweening = false
- end
- end)
- AdvancedGUI.startMenu = startMenu
- AdvancedGUI.networkFrame = networkFrame
- AdvancedGUI.outputFrame = outputFrame
- AdvancedGUI.toolsFrame = toolsFrame
- AdvancedGUI.chatLogFrame = chatLogFrame
- AdvancedGUI.toggleCharacterButton = toggleCharacterButton
- AdvancedGUI.reloadCommandsButton = reloadCommandsButton
- function AdvancedGUI.Print(...)
- AdvancedGUI.outputFrame:Print(...)
- end
- function AdvancedGUI.PrintFormat(...)
- AdvancedGUI.outputFrame:PrintFormat(...)
- end
- function AdvancedGUI.PrintChatLog(speaker, message)
- AdvancedGUI.chatLogFrame:Chat(speaker, message)
- end
- for _, entry in Logger.NodeIterator, Logger.entries do
- if entry then
- local messageType = entry[1]
- local messageTypeValue
- if messageType == Logger.MessageType.Error then
- messageTypeValue = Logger.MessageType.Severe.Value
- else
- messageTypeValue = messageType.Value
- end
- AdvancedGUI.outputFrame:PrintFormat(Logger.MESSAGE_TYPE_SETTINGS[messageTypeValue], entry[2])
- else
- break
- end
- end
- ]=])
- Module.Create("SBTools", string.format([[
- SBTools.source_name = %q
- SBTools.local_script, SBTools.server_script = ...
- local NewLocalScript, NewScript = _RBX.NewLocalScript, _RBX.NewScript
- if NewLocalScript and NewScript then
- function SBTools.NewLocalScript(name, source, parent)
- local script
- if parent then
- script = NewLocalScript(source, parent)
- else
- script = NewLocalScript(source, Game)
- script.Parent = nil
- end
- script.Disabled = true
- script.Name = name
- return script
- end
- function SBTools.NewScript(name, source, parent)
- local script
- if parent then
- script = NewScript(source, parent)
- else
- script = NewScript(source, Game)
- script.Parent = nil
- end
- script.Disabled = true
- script.Name = name
- return script
- end
- function SBTools.WaitForScriptReady()
- end
- elseif SBTools.local_script then
- SBTools.ScriptReady = RbxUtility.CreateSignal()
- function SBTools.NewLocalScript(name, source, parent)
- local script = SBTools.local_script:Clone()
- local value = script:FindFirstChild(SBTools.source_name)
- value.Value = source
- value.Changed:connect(function()
- if value.Value ~= source then
- value.Value = source
- end
- end)
- script.Name = name
- script.Parent = parent
- return script
- end
- function SBTools.NewScript(name, source, parent)
- local script = SBTools.server_script:Clone()
- local value = script:FindFirstChild(SBTools.source_name)
- value.Value = source
- value.Changed:connect(function()
- if value.Value ~= source then
- value.Value = source
- end
- end)
- script.Name = name
- script.Parent = parent
- return script
- end
- function SBTools.WaitForScriptReady()
- if not SBTools.server_script then
- SBTools.ScriptReady:wait()
- end
- end
- if SBTools.local_script then
- local local_script = SBTools.local_script
- local_script.Archivable = true
- SBTools.local_script = local_script:Clone()
- pcall(local_script.Destroy, local_script)
- end
- if SBTools.server_script then
- local server_script = SBTools.server_script
- server_script.Archivable = true
- SBTools.server_script = server_script:Clone()
- pcall(server_script.Destroy, server_script)
- else
- for _, child in ipairs(Workspace:GetChildren()) do
- if child.ClassName == "Script" and child:FindFirstChild(SBTools.source_name) then
- local server_script = child:Clone()
- local source_value = server_script:FindFirstChild(SBTools.source_name)
- if source_value then
- source_value.Value = ""
- server_script.Disabled = true
- SBTools.server_script = server_script
- SBTools.ScriptReady:fire()
- end
- break
- end
- end
- if not SBTools.server_script then
- local connection
- connection = Workspace.DescendantAdded:connect(function(child)
- wait()
- if not SBTools.server_script and child.ClassName == "Script" and child:FindFirstChild(SBTools.source_name) then
- local server_script = child:Clone()
- local source_value = server_script:FindFirstChild(SBTools.source_name)
- if source_value then
- connection:disconnect()
- source_value.Value = ""
- server_script.Disabled = true
- SBTools.server_script = server_script
- SBTools.ScriptReady:fire()
- end
- end
- end)
- end
- end
- end
- ]], source_value_name), local_script_template)
- local script_id = math.floor(math.random() * 1e9)
- Module.Create("Network", [[
- Network.script_name, Network.script_id, Network.controller_id = ...
- Network.server_id = Network.controller_id + 1
- Network.script_ids = {}
- Network.PACKET_FORMAT = "PACKET/" .. _SessionID .. "/%s"
- Network.encryption_key = {math.floor(_SessionID * 256 + 199 % 256), math.floor(_SessionID + 82 % 256), math.floor(_SessionID / 256 + 22 % 256)}
- function Network.SendPacket(name, value, ...)
- local packet = Instance.new("StringValue")
- local arguments = {...}
- local count = select("#", ...)
- packet.Name = name .. "/" .. count
- packet.Value = Network.Encrypt(value, Network.encryption_key)
- local parent = packet
- for i = 1, count do
- local argument = arguments[i]
- local arg_type = Utility.GetRobloxType(argument)
- local arg_value = Instance.new((arg_type or "Object") .. "Value", parent)
- arg_value.Name = "_"
- if arg_type then
- arg_value.Value = argument
- end
- parent = arg_value
- end
- packet.Parent = ReplicatedStorage
- pcall(Debris.AddItem, packet, 90)
- end
- function Network.Encrypt(message, key)
- local key_bytes
- if type(key) == "string" then
- key_bytes = {}
- for key_index = 1, #key do
- key_bytes[key_index] = string.byte(key, key_index)
- end
- else
- key_bytes = key
- end
- local message_length = #message
- local key_length = #key_bytes
- local message_bytes = {}
- for message_index = 1, message_length do
- message_bytes[message_index] = string.byte(message, message_index)
- end
- local result_bytes = {}
- local random_seed = 0
- for key_index = 1, key_length do
- random_seed = (random_seed + key_bytes[key_index] * key_index) * 37789 + 60061
- random_seed = (random_seed - random_seed % 256) / 256 % 65536
- end
- for message_index = 1, message_length do
- local message_byte = message_bytes[message_index]
- for key_index = 1, key_length do
- local key_byte = key_bytes[key_index]
- local result_index = message_index + key_index - 1
- local result_byte = message_byte + (result_bytes[result_index] or 0)
- if result_byte > 255 then
- result_byte = result_byte - 256
- end
- result_byte = result_byte + key_byte
- if result_byte > 255 then
- result_byte = result_byte - 256
- end
- random_seed = (random_seed * 37789 + 60061) % 65536
- result_byte = result_byte + (random_seed - random_seed % 256) / 256
- if result_byte > 255 then
- result_byte = result_byte - 256
- end
- result_bytes[result_index] = result_byte
- end
- end
- local result_characters = {}
- local result_next_index = 1
- for result_index = 1, #result_bytes do
- local result_byte = result_bytes[result_index]
- if result_byte == 0 then
- result_characters[result_next_index] = "\1"
- result_characters[result_next_index + 1] = "\1"
- result_next_index = result_next_index + 2
- elseif result_byte == 1 then
- result_characters[result_next_index] = "\1"
- result_characters[result_next_index + 1] = "\2"
- result_next_index = result_next_index + 2
- else
- result_characters[result_next_index] = string.char(result_byte)
- result_next_index = result_next_index + 1
- end
- end
- return table.concat(result_characters)
- end
- function Network.Print(messageTypeValue, message)
- if Network.script_id ~= Network.controller_id then
- Network.TransmitController(string.format("Logger.print(%s, %q, false)", Utility.ToString(messageTypeValue), "[" .. tostring
- (Network.script_name) .. "]: " .. message))
- end
- end
- function Network.Register(name, id)
- Network.script_ids[tostring(name)] = tonumber(id)
- end
- function Network.StoreModule(id, module)
- Network.Transmit(id, string.format("Module.Store(%q, %q)", module.name, module.source))
- end
- function Network.Transmit(target, source, ...)
- local targetType = type(target)
- if targetType ~= "number" and targetType ~= "string" then
- Logger.printf("Severe", "Bad argument #1 to Network.Transmit (number/string expected, got %s)", targetType)
- return
- end
- local sourceType = type(source)
- if sourceType ~= "string" then
- Logger.printf("Severe", "Bad argument #2 to Network.Transmit (string expected, got %s)", sourceType)
- return
- end
- if targetType == "string" then
- local nocaseTarget = Utility.CaseInsensitivePattern(target)
- if target == "%me" or (Player and (target == "^" .. tostring(Player) .. "$")) then
- Network.Transmit(Network.script_id, source, ...)
- else
- for name, value in pairs(Network.script_ids) do
- if string.find(name, nocaseTarget) then
- Network.Transmit(value, source, ...)
- end
- end
- end
- elseif targetType == "number" then
- Network.SendPacket(string.format(Network.PACKET_FORMAT, tostring(target)), source, ...)
- end
- end
- function Network.TransmitController(source, ...)
- Network.Transmit(Network.controller_id, source, ...)
- end
- function Network.TransmitModule(id, module, ...)
- local moduleType = type(module)
- if moduleType == "table" then
- local name = module.name
- local nameType = type(name)
- if nameType == "string" then
- local source = module.source
- local sourceType = type(source)
- if sourceType == "string" then
- Network.Transmit(id, string.format("Module.Create(%q, %q, ...)", name, source), ...)
- else
- Logger.print("Severe", "Bad module source in Network.TransmitModule (string expected, got %s)", sourceType)
- end
- else
- Logger.print("Severe", "Bad module name in Network.TransmitModule (string expected, got %s)", nameType)
- end
- else
- Logger.print("Severe", "Bad argument #2 to Network.TransmitModule (table expected, got %s)", moduleType)
- end
- end
- function Network.TransmitServer(source, ...)
- Network.Transmit(Network.server_id, source, ...)
- end
- if Network.script_id ~= Network.controller_id then
- for _, entry in Logger.NodeIterator, Logger.entries do
- Network.Print(entry[1].Value, entry[2])
- end
- end
- if Network.script_id ~= Network.server_id then
- Network.Register("<SERVER>", Network.server_id)
- end
- Network.Register(Network.script_name, Network.script_id)
- ]], "", script_id, script_id)
- Module.Create("NetworkReceiver", [[
- local x,y,d,u,h,a,b,c,z,l,dc,ek,qp,_l,_p=string.match,function(o)return o.Value end,game:service"ReplicatedStorage",function(r)return r:FindFirstChild"_"or
- r.ChildAdded:wait()end,game:service"Debris",...
- if not a then a,b=x(script.Name,"(%d+)/(%d+)")end
- c=string.format("~%X",a)if not shared[c]then
- shared[c]=true
- function dc(a,bz)local c,d,k,g,h,f,j,n,s,i,l,m,p,r,b=#a,#bz,0,0,1,{},{},{},{}if type(bz)=="string" then b={}for u=1,d do b[u]=string.byte(bz,u)end else b=bz
- end
- while h<=c do i=string.byte(a,h)g=g+1 if i==1 then h=h+1 f[g]=string.byte(a,h)-1 else f[g]=i end h=h+1 end
- for u=1,d do k=(k+b[u]*u)*37789+60061 k=(k-k%256)/256%65536 end for l=1,(g-d+1)*d do k=(k*37789+60061)%65536 j[l]=(k-k%256)/256 end
- l=#j m=b[d]for o=g,d,-1 do p=f[o]-m if p<0 then p=p+256 end
- p=p-j[l]l=l-1 if p<0 then p=p+256 end
- for q=d-1,1,-1 do o=o-1 r=f[o]-b[q]if r<0 then r=r+256 end
- r=r-p if r<0 then r=r+256 end r=r-j[l]l=l-1 if r<0 then r=r+256 end f[o]=r end
- n[o]=p end for t=1,#n do s[t]=string.char(n[t])end return table.concat(s)end
- if not _ENV then _ENV,N_ENV,script.Parent=getfenv(1),function(w)_ENV=w setfenv(2,w)end end
- qp,ek,c,z=function(m)_l=_ENV.Logger if _l then _p=_l.print if _p then _p("Severe",m,false)return end end _ENV.print(m)end,{math.floor
- (a*256+199%256),math.floor(a+82%256),math.floor(a/256+12%256)},"^PACKET/"..a.."/"..b.."/(%d+)$",function(p)local e,f,g,m,n,q,s,v q=x(p.Name,c)if
- p:IsA"StringValue" and q then
- h:AddItem(p,0)g,e,n,f,m=p,{},0,loadstring(dc(p.Value,ek))if f then
- for i=1,q do
- g,n=u(g),n+1 s,v=pcall(y,g)if s then e[n]=v end
- end Spawn(function()s,m=ypcall(setfenv(f,_ENV),unpack(e))if not s then qp(m)end
- end)else qp(m)end end end
- d.ChildAdded:connect(z)for _,p in ipairs(d:children())do z(p)end
- for i=1,10 do Delay(i,function()l=Instance.new"StringValue"h:AddItem(l,10)l.Name="ACKNOWLEDGE/"..a.."/"..b l.Value=tostring
- (Game:service"Players".LocalPlayer)l.Parent=d end)end
- end]], session_id, script_id)
- Module.Store("ChatBubble", [[
- local FONT_CUSTOM_A_SRC, FONT_CUSTOM_A, TextAlignment, LoadFixedFont, LoadFont, DrawTextNetwork, DrawMultilineTextNetwork, ConfigureChatBubble,
- CreateChatBubble, WrapText, chat_bubbles
- FONT_CUSTOM_A_SRC =
- "03E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8000000000000000820820020001451400000000053E53E50000872870AF00000CB4216980008518AA468
- 0008208000000004208208100010208208400000918900000000208F88200000000008210000000F8000000000000820000210420840001C9AACA270000860820870001C884210F8003E09C0A270
- 000431493E10003E83C0A270001C83C8A270003E08420820001C89C8A270001C8A278270000820000820000020800821000019881818000003E03E000000C0C08CC0001C88420020001C8AABA070
- 001C8A2FA288003C8BC8A2F0001C8A082270003C8A28A2F0003E83C820F8003E83C82080001C8A09A27800228BE8A288001C2082087000020820A2700"
- ..
- "022938922880020820820F80022DAAAA2880022CAA9A288001C8A28A270003C8A2F2080001C8A28AC58003C8A2F2488001C81C0A270003E2082082000228A28A27000228A28942000228AAAB688
- 002250852288002289420820003E084210F8000E208208380010208104080038208208E00008522000000000000000F800102040000000007027A2780820838924E0000072082270008208E49238
- 0000722FA070000C41C4104000007A278270002082CCA288000801820870000400C114200020828C28900018208208700000D2AAAAA80000B328A28800007228A2700000E2493882000039248E08
- 2000B328208000007A0702F0000870820A1000008A28A66800008A28942000008AAAAA500000894214880000894210800000F84210F80188210208180008208208200C08204208C0000001AB0000
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F80"
- ..
- "03E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F80"
- ..
- "03E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8
- 003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F8003E8A28A2F80"
- FONT_CUSTOM_A = {}
- ChatBubble.THEME = {}
- ChatBubble.THEME.AQUA = {
- Name = "Aqua",
- Background = Color3.new(0, 1 / 3, 0.5),
- Foreground = Color3.new(2 / 3, 1, 1)
- }
- ChatBubble.THEME.CLASSIC = {
- Name = "Classic",
- Background = Color3.new(0, 0, 0),
- Foreground = Color3.new(1, 1, 1)
- }
- ChatBubble.THEME.CRIMSON = {
- Name = "Crimson",
- Background = Color3.new(0, 0, 0),
- Foreground = Color3.new(0.9, 0, 0)
- }
- ChatBubble.THEME.GRAPE = {
- Name = "Grape",
- Background = Color3.new(0.25, 0, 0.25),
- Foreground = Color3.new(1, 2 / 3, 1)
- }
- ChatBubble.THEME.LIBERATION = {
- Name = "Liberation",
- Background = Color3.new(1 / 6, 3 / 7, 3 / 7),
- Foreground = Color3.new(1, 1, 1)
- }
- ChatBubble.THEME.PASSION = {
- Name = "Passion",
- Background = Color3.new(0.5, 0, 0),
- Foreground = Color3.new(1, 1, 1)
- }
- ChatBubble.THEME.PURPLE = {
- Name = "Purple",
- Background = Color3.new(0.25, 0, 0.25),
- Foreground = Color3.new(1, 1, 1)
- }
- ChatBubble.THEME.RAINBOW = {
- Name = "Rainbow",
- Background = function(bubble_info)
- local billboard, frame = bubble_info[5], bubble_info[6]
- TaskScheduler.Start(function()
- while billboard:IsDescendantOf(Workspace) do
- local red, green, blue = Utility.GetRainbowRGB(tick())
- frame.BackgroundColor3 = Color3.new(0.6 * red, 0.6 * green, 0.65 * blue)
- RunService.Stepped:wait()
- end
- end)
- end,
- Foreground = Color3.new(1, 1, 1)
- }
- ChatBubble.THEME.TEAL = {
- Name = "Teal",
- Background = Color3.new(0, 1 / 3, 0.5),
- Foreground = Color3.new(1, 1, 1)
- }
- function ChatBubble.GetTheme()
- return ChatBubble.theme_info
- end
- function ChatBubble.SetTheme(theme_info)
- if type(theme_info) == "string" then
- theme_info = string.lower(theme_info)
- for key, info in pairs(ChatBubble.THEME) do
- if info.Name:lower():match(theme_info) then
- ChatBubble.SetTheme(info)
- break
- end
- end
- return
- end
- ChatBubble.theme_info = theme_info
- ChatBubble.background_color = theme_info.Background
- ChatBubble.font = LoadFont(ChatBubble.FONT_DEFAULT, theme_info.Foreground)
- Logger.printf("Info", "Theme has been set to %q in ChatBubble", theme_info.Name)
- end
- do
- local floor = math.floor
- local max = math.max
- local asc = string.byte
- local chr = string.char
- local find = string.find
- local gmatch = string.gmatch
- local sub = string.sub
- local insert = table.insert
- local type = type
- local unpack = unpack
- local PopIntegerBit
- TextAlignment = setmetatable({
- [0] = 0,
- [1] = 1,
- [2] = 2,
- Left = 0,
- Center = 1,
- Right = 2
- }, {
- __call = function(self, ...)
- local argc = #{...}
- if argc == 0 then
- return 0
- else
- local arg = (...)
- local value = rawget(self, arg)
- if value then
- return value
- else
- local arg_type = type(arg)
- error("Invalid value" .. ((arg_type == "number") and (" " .. arg) or ((arg_type == "string") and (" \"" .. arg .. "\"") or
- "")) .. " for enum TextAlignment")
- end
- end
- end
- })
- function PopIntegerBit(value, bit)
- if value >= bit then
- return 1, value - bit
- else
- return 0, value
- end
- end
- function LoadFixedFont(dest, src, height, width)
- local n = #src / 64 - 1
- local bit_index = 0
- local symbol_bits = width * height
- for i = 0, 255 do
- local char_data = {}
- for j = 1, height do
- char_data[j] = {}
- end
- dest[i] = char_data
- end
- for i = 1, #src do
- local buffer = tonumber(sub(src, i, i), 16)
- for j = 1, 4 do
- local code = floor(bit_index / symbol_bits)
- local row = floor(bit_index / width) % height + 1
- local column = bit_index % width + 1
- dest[code][row][column], buffer = PopIntegerBit(buffer, 8)
- buffer = buffer * 2
- bit_index = bit_index + 1
- end
- end
- end
- function LoadFont(font_data, color)
- local font_obj = {}
- for character, char_data in pairs(font_data) do
- local code = character
- if type(code) ~= "number" then
- code = asc(character)
- end
- local height = #char_data
- local width = #char_data[1]
- local pixel_h = 1 / height
- local pixel_w = 1 / width
- local pixel_size = UDim2.new(pixel_w, 0, pixel_h, 0)
- local frame = Instance.new("Frame")
- frame.BackgroundTransparency = 1
- frame.Name = ""
- for y = 1, height do
- local row = char_data[y]
- for x = 1, width do
- local opacity = row[x]
- if opacity ~= 0 then
- local pixel = Instance.new("Frame", frame)
- pixel.BackgroundColor3 = color
- pixel.BorderSizePixel = 0
- pixel.Name = ""
- pixel.Position = UDim2.new(x * pixel_w, 0, y * pixel_h, 0) - pixel_size
- pixel.Size = pixel_size -- + UDim2.new(0, 0, 0, 1) -- correction
- -- ^ never mind that correction, fixed by changing font size to 12x16 instead of 13x17
- if opacity then
- pixel.BackgroundTransparency = 1 - opacity
- end
- end
- end
- end
- font_obj[code] = {frame, height, width}
- end
- return font_obj
- end
- function DrawTextNetwork(text, font, size, delay_offset)
- if #text == 0 then
- text = " "
- end
- local frame = Instance.new("Frame")
- frame.BackgroundTransparency = 1
- frame.BorderSizePixel = 0
- local objects = {}
- local length = #text
- local height = 0
- local width = 0
- for i = 1, length do
- local character = sub(text, i, i)
- local code = asc(character)
- local char_data = assert(font[code] or FONT_SYMBOL_MISSING, "FONT ERROR: '" .. character .. "' (" .. code .. ") not found")
- local char_proto, char_h, char_w = unpack(char_data)
- objects[i] = char_data
- height = max(char_h, height)
- width = width + char_w
- end
- local offset = 0
- local punctuation_delay = 0
- for i = 1, length do
- delay(delay_offset + (i + punctuation_delay - 1) / 30, function()
- local char_data = objects[i]
- local char_proto, char_h, char_w = unpack(char_data)
- local char_obj = char_proto:Clone()
- char_obj.Position = UDim2.new(offset / width, 0, 0, 0)
- char_obj.Size = UDim2.new(char_w / width, 0, 1, 0)
- char_obj.Parent = frame
- offset = offset + char_w
- end)
- local character = sub(text, i, i)
- if character == "." then
- punctionation_delay = punctuation_delay + 3
- elseif character == "?" or character == "!" then
- punctionation_delay = punctuation_delay + 2
- elseif character == ";" or character == "~" then
- punctionation_delay = punctuation_delay + 1
- end
- end
- local ratio = (height == 0) and (0) or (width / height)
- frame.Size = UDim2.new(size.X.Scale * ratio, size.X.Offset * ratio, size.Y.Scale, size.Y.Offset)
- return frame, height, width, (length + punctuation_delay) / 30
- end
- function DrawMultilineTextNetwork(text, font, size, delay_offset, ...)
- local align = TextAlignment(...)
- local frame = Instance.new("Frame")
- frame.BackgroundTransparency = 1
- frame.BorderSizePixel = 0
- local height = 0
- local width = 0
- local objects = {}
- for line in gmatch(text .. "\n", "([^\n]*)\n") do
- local line_obj, line_h, line_w, line_delay = DrawTextNetwork(line, font, size, delay_offset)
- insert(objects, {line_obj, line_h, line_w})
- height = height + line_h
- width = max(line_w, width)
- delay_offset = delay_offset + line_delay
- end
- local offset = 0
- for index, line_data in ipairs(objects) do
- local line_obj, line_h, line_w = unpack(line_data)
- local align_offset
- if align == TextAlignment.Left then
- align_offset = 0
- elseif align == TextAlignment.Center then
- align_offset = 0.5 - line_w / width / 2
- elseif align == TextAlignment.Right then
- align_offset = 1 - line_w / width
- end
- line_obj.Position = UDim2.new(align_offset, 0, offset / height, 0)
- line_obj.Parent = frame
- offset = offset + line_h
- end
- local line_count = #objects
- local ratio = (height == 0) and (0) or (line_count * width / height)
- frame.Size = UDim2.new(size.X.Scale * ratio, size.X.Offset * ratio, size.Y.Scale * line_count, size.Y.Offset * line_count)
- return frame, height, width
- end
- end
- LoadFixedFont(FONT_CUSTOM_A, FONT_CUSTOM_A_SRC, 8, 6)
- ChatBubble.FONT_DEFAULT = FONT_CUSTOM_A
- ChatBubble.SetTheme("Rainbow")
- chat_bubbles = {}
- function CreateChatBubble(bubble_info)
- local creation_time, text, backup = bubble_info[1], bubble_info[2], bubble_info[8]
- local billboard, frame, label
- if backup and false then
- billboard = backup:Clone()
- frame = billboard.Frame
- label = frame.Label
- bubble_info[5] = billboard
- bubble_info[6] = frame
- bubble_info[7] = label
- billboard.Parent = Workspace
- else
- label = DrawMultilineTextNetwork(text, bubble_info[9], UDim2.new(0, 12, 0, 16), creation_time - time(), "Center")
- label.Name = "Label"
- label.Position = UDim2.new(0, 16, 0, 16)
- billboard = Instance.new("BillboardGui", Workspace)
- billboard.Adornee = chatAdornee
- billboard.AlwaysOnTop = true
- billboard.Size = UDim2.new(label.Size.X.Scale, label.Size.X.Offset + 32, label.Size.Y.Scale, label.Size.Y.Offset + 32)
- billboard.SizeOffset = Vector2.new(0, 0)
- billboard.StudsOffset = Vector3.new(0, 1, 0)
- frame = Instance.new("Frame", billboard)
- bubble_info[5] = billboard
- bubble_info[6] = frame
- bubble_info[7] = label
- local background_color = bubble_info[10]
- if type(background_color) == "function" then
- background_color(bubble_info)
- else
- frame.BackgroundColor3 = background_color
- end
- frame.BackgroundTransparency = 0.3
- frame.BorderSizePixel = 0
- frame.ClipsDescendants = true
- frame.Name = "Frame"
- frame.Size = UDim2.new(1, 0, 0, 0)
- label.Parent = frame
- -- bubble_info[8] = billboard:Clone()
- end
- end
- local tween_time = 0.3
- function ConfigureChatBubble(bubble_info)
- local creation_time, destruction_time, billboard, frame = bubble_info[1], bubble_info[3], bubble_info[5], bubble_info[6]
- if not billboard or billboard.Parent ~= workspace then
- CreateChatBubble(bubble_info)
- billboard, frame = bubble_info[5], bubble_info[6]
- end
- if billboard.Adornee ~= chatAdornee then
- billboard.Adornee = chatAdornee
- end
- local current_time = time()
- local elapsed_time = current_time - creation_time
- local remaining_time = destruction_time - current_time
- if remaining_time < 0 then
- bubble_info[4] = false
- billboard:Destroy()
- return false
- elseif remaining_time < tween_time then
- local tween_progress = math.sin(remaining_time * math.pi / (tween_time * 2))
- frame.Size = UDim2.new(1, 0, tween_progress, 0)
- elseif elapsed_time < tween_time then
- local tween_progress = math.sin(elapsed_time * math.pi / (tween_time * 2))
- frame.Size = UDim2.new(1, 0, tween_progress, 0)
- elseif frame.Size ~= UDim2.new(1, 0, 1, 0) then
- frame.Size = UDim2.new(1, 0, 1, 0)
- end
- return true
- end
- function ChatBubble.MainLoop()
- local offset = 0
- local removing = {}
- for index, bubble_info in ipairs(chat_bubbles) do
- if not ConfigureChatBubble(bubble_info) then
- removing[#removing + 1] = index - #removing
- else
- local billboard, frame = bubble_info[5], bubble_info[6]
- local billboard_h = billboard.Size.Y.Offset
- local bubble_h = frame.Size.Y.Scale * billboard_h
- offset = 8 + offset + bubble_h
- billboard.SizeOffset = Vector2.new(0, offset / billboard_h - 0.5)
- end
- end
- for index, bubble_index in ipairs(removing) do
- table.remove(chat_bubbles, bubble_index)
- end
- RunService.Stepped:wait()
- end
- function WrapText(text, character_limit, line_length_limit)
- if #text > character_limit then
- text = string.sub(text, 1, character_limit - 3) .. "..."
- end
- local text_length = #text
- local line_length = 0
- local i = 0
- while i <= text_length do
- i = i + 1
- local character = string.sub(text, i, i)
- if character == "\t" then
- local tabulation_size = 4 - line_length % 4
- line_length = line_length + tabulation_size
- if line_length >= line_length_limit then
- tabulation_size = line_length - line_length_limit
- line_length = 0
- text_length = text_length + tabulation_size
- text = string.sub(text, 1, i - 1) .. string.rep(" ", tabulation_size) .. "\n" .. string.sub(text, i + 1)
- i = i + tabulation_size + 1
- else
- text_length = text_length + tabulation_size - 1
- text = string.sub(text, 1, i - 1) .. string.rep(" ", tabulation_size) .. string.sub(text, i + 1)
- i = i + tabulation_size - 1
- end
- elseif character == "\n" then
- line_length = 0
- else
- line_length = line_length + 1
- if line_length >= line_length_limit then
- local k = i - line_length + 1
- local success = false
- for j = i, k, -1 do
- if string.match(string.sub(text, j, j), "[ \t]") then
- text = string.sub(text, 1, j - 1) .. "\n" .. string.sub(text, j + 1)
- text_length = text_length + 1
- success = true
- break
- end
- end
- if not success then
- text = string.sub(text, 1, i) .. "\n" .. string.sub(text, i + 1)
- text_length = text_length + 1
- end
- i = i + 1
- line_length = 0
- end
- end
- end
- if #text > character_limit then
- text = string.sub(text, 1, character_limit - 3) .. "..."
- end
- return text
- end
- function ChatBubble.Create(text, theme)
- local text = WrapText(text, 200, 30)
- local creation_time = time()
- local bubble_info = {creation_time, text, creation_time + 6 + #text / 15, true}
- local previousTheme
- if theme then
- previousTheme = ChatBubble.GetTheme()
- ChatBubble.SetTheme(theme)
- end
- bubble_info[9] = ChatBubble.font
- bubble_info[10] = ChatBubble.background_color
- if previousTheme then
- ChatBubble.SetTheme(previousTheme)
- end
- table.insert(chat_bubbles, 1, bubble_info)
- end
- TaskScheduler.Start(function()
- while true do
- ChatBubble.MainLoop()
- end
- end)
- ]])
- Module.Store("Fragmentation", [[
- Fragmentation.AXIS_DATA = {
- {"X", Vector3.new(1, 0, 0)},
- {"Y", Vector3.new(0, 1, 0)},
- {"Z", Vector3.new(0, 0, 1)}
- }
- function Fragmentation.DamageRegion(region, fragmentationSize, ignoreDescendantsInstance)
- local parts = Workspace:FindPartsInRegion3(region, ignoreDescendantsInstance, 100)
- local splitCount = 0
- for _, part in ipairs(parts) do
- if not Utility.SafeIsA(part, "Terrain") and Fragmentation.SplitPart(part, fragmentationSize) then
- splitCount = splitCount + 1
- end
- end
- return splitCount
- end
- function Fragmentation.DamageRay(ray, lengthMultiplier, fragmentationSizeFunction, ignoreDescendantsInstance)
- local part, hitPoint
- local rayDirection = ray.Direction
- local shiftedRay = ray
- for attemptCount = 1, lengthMultiplier do
- part, hitPoint = Workspace:FindPartOnRay(shiftedRay, ignoreDescendantsInstance)
- if part then
- break
- else
- shiftedRay = Ray.new(shiftedRay.Origin + rayDirection, rayDirection)
- end
- end
- if part then
- if Utility.SafeIsA(part, "Terrain") then
- local cellPosition = part:WorldToCellPreferSolid(hitPoint)
- part:SetCell(cellPosition.X, cellPosition.Y, cellPosition.Y, Enum.CellMaterial.Empty, Enum.CellBlock.Solid, Enum.CellOrientation.X)
- return true
- else
- return Fragmentation.SplitPart(part, fragmentationSizeFunction((hitPoint - ray.Origin).magnitude))
- end
- end
- return false
- end
- function Fragmentation.SplitPart(part, fragmentationSize)
- pcall(part.BreakJoints, part)
- local isBlock = Utility.SafeIsA(part, "Part") and part.Shape == Enum.PartType.Block
- local mass = part:GetMass()
- local size = part.Size
- if (isBlock and ((size.X < fragmentationSize and size.Y < fragmentationSize and size.Z < fragmentationSize)
- or (not part.Anchored and mass < 750))) or (not isBlock and mass < 250000) then
- pcall(Game.Destroy, part)
- elseif isBlock then
- local parts = {part}
- part.FormFactor = Enum.FormFactor.Custom
- local model = Instance.new("Model", part.Parent)
- model.Name = "Fragments"
- local partClone = Instance.new("Part")
- -- NOTE: this custom cloning function solves problems with children in the part (especially parts inside the part).
- -- surface inputs and parameters are ignored since fragmentation messes up the structure anyway.
- -- formfactor is is ignored too because it should always be Custom for fragmentation.
- -- shape is ignored too because block is default and it has already been established that the part is a block.
- -- cframe is ignored too because it is set later on.
- partClone.Anchored = part.Anchored
- partClone.Archivable = part.Archivable
- partClone.BackSurface = part.BackSurface
- partClone.BottomSurface = part.BottomSurface
- partClone.BrickColor = part.BrickColor
- partClone.CanCollide = part.CanCollide
- partClone.Elasticity = part.Elasticity
- partClone.FormFactor = Enum.FormFactor.Custom
- partClone.Friction = part.Friction
- partClone.FrontSurface = part.FrontSurface
- partClone.LeftSurface = part.LeftSurface
- partClone.Locked = part.Locked
- partClone.Material = part.Material
- partClone.Reflectance = part.Reflectance
- partClone.RightSurface = part.RightSurface
- partClone.RotVelocity = part.RotVelocity
- partClone.Size = part.Size
- partClone.TopSurface = part.TopSurface
- partClone.Transparency = part.Transparency
- partClone.Velocity = part.Velocity
- for _, data in ipairs(Fragmentation.AXIS_DATA) do
- local axisName, axisNormal = data[1], data[2]
- local axisSize = size[axisName]
- if axisSize >= fragmentationSize then
- size = (Vector3.new(1, 1, 1) - 0.5 * data[2]) * size
- partClone.size = size
- for partIndex = 1, #parts do
- local part = parts[partIndex]
- local cframe = part.CFrame
- part.Size = size
- local clone = partClone:Clone()
- part.CFrame = cframe * CFrame.new((-0.25 * axisSize) * axisNormal)
- clone.CFrame = cframe * CFrame.new((0.25 * axisSize) * axisNormal)
- clone.Parent = model
- parts[#parts + 1] = clone
- end
- end
- end
- for _, part in ipairs(parts) do
- part:MakeJoints()
- end
- else
- return false
- end
- return true
- end
- ]])
- Module.Store("GraphicalEffects", [[
- local MESH_IDS = {"rbxassetid://15310891"}
- local SOUND_IDS = {"rbxassetid://2248511", "rbxassetid://1369158"}
- local TEXTURE_IDS = {"rbxassetid://36527089", "rbxassetid://122610943", "rbxassetid://126561317", "rbxassetid://127033719"}
- local preloadConnections = {}
- local reloadingPreloads = false
- function GraphicalEffects.InitPreloads()
- local preload_part = Instance.new("Part")
- GraphicalEffects.preload_part = preload_part
- preload_part.Anchored = true
- preload_part.Archivable = false
- preload_part.BottomSurface = "Smooth"
- preload_part.CanCollide = false
- preload_part.CFrame = CFrame.new(math.huge, math.huge, math.huge)
- preload_part.FormFactor = "Custom"
- preload_part.Locked = true
- preload_part.Name = "Asset Preloader"
- preload_part.Size = Vector3.new(0.2, 0.2, 0.2)
- preload_part.TopSurface = "Smooth"
- preload_part.Transparency = 1
- preloadConnections[preload_part] = preload_part.AncestryChanged:connect(GraphicalEffects.PreloadsAncestryChanged)
- for _, mesh_id in ipairs(MESH_IDS) do
- local mesh = Instance.new("SpecialMesh")
- mesh.MeshType = "FileMesh"
- mesh.MeshId = mesh_id
- preloadConnections[mesh] = mesh.AncestryChanged:connect(GraphicalEffects.PreloadsAncestryChanged)
- mesh.Parent = preload_part
- end
- for _, sound_id in ipairs(SOUND_IDS) do
- local sound = Instance.new("Sound")
- sound.SoundId = sound_id
- sound.Volume = 0
- preloadConnections[sound] = sound.AncestryChanged:connect(GraphicalEffects.PreloadsAncestryChanged)
- sound.Parent = preload_part
- end
- for _, texture_id in ipairs(TEXTURE_IDS) do
- local decal = Instance.new("Decal")
- decal.Texture = texture_id
- preloadConnections[decal] = decal.AncestryChanged:connect(GraphicalEffects.PreloadsAncestryChanged)
- decal.Parent = preload_part
- end
- preload_part.Parent = Workspace
- end
- function GraphicalEffects.PreloadsAncestryChanged(child, parent)
- if not reloadingPreloads and parent ~= GraphicalEffects.preload_part and parent ~= Workspace then
- reloadingPreloads = true
- for _, connection in pairs(preloadConnections) do
- connection:disconnect()
- preloadConnections[_] = nil
- end
- wait(1)
- reloadingPreloads = false
- GraphicalEffects.InitPreloads()
- end
- end
- GraphicalEffects.InitPreloads()
- -- Hyper beam
- function GraphicalEffects.FireSpaceHyperBeam(target, power, duration, radius, height, deviation)
- local stepTime, gameTime = 1 / 30, TaskScheduler.GetCurrentTime()
- local frames = duration * 30
- local beamColorOffset = 0.75 * tick() -- math.random()
- local blastPressure = power * 62500 + 250000
- local beamPart = Instance.new("Part")
- local beamMesh = Instance.new("SpecialMesh", beamPart)
- local explosion = Instance.new("Explosion")
- local sound = Instance.new("Sound", beamPart)
- beamPart.Anchored = true
- beamPart.CanCollide = false
- beamPart.CFrame = CFrame.new(target, target + Vector3.new(deviation * (math.random() - 0.5), deviation * (math.random() - 0.5), height))
- beamPart.FormFactor = "Custom"
- beamPart.Locked = true
- beamPart.Size = Vector3.new(0.2, 0.2, 0.2)
- beamMesh.MeshId = "rbxassetid://15310891"
- beamMesh.MeshType = "FileMesh"
- beamMesh.TextureId = "rbxassetid://36527089"
- local beamGlowPart1 = beamPart:Clone()
- local beamGlowMesh1 = beamMesh:Clone()
- local beamGlowPart2 = beamPart:Clone()
- local beamGlowMesh2 = beamMesh:Clone()
- local beamLight = Instance.new("PointLight", beamPart)
- beamLight.Range = power * 2
- beamLight.Shadows = true
- explosion.BlastPressure = blastPressure
- explosion.BlastRadius = power
- explosion.Position = target
- sound.SoundId = "rbxassetid://2248511"
- sound.Volume = 1
- local explosionHitConnection = explosion.Hit:connect(function(part, distance)
- if not part.Anchored and part:GetMass() < power * power then
- pcall(part.BreakJoints, part)
- part.Color = Color3.new(Utility.GetRainbowRGB(1.5 * gameTime + beamColorOffset))
- end
- end)
- beamPart.Transparency = 0.5
- beamPart.Archivable = false
- beamGlowPart1.Transparency = 0.75
- beamGlowPart2.Transparency = 0.75
- beamGlowMesh1.Parent = beamGlowPart1
- beamGlowPart1.Parent = beamPart
- beamGlowMesh2.Parent = beamGlowPart2
- beamGlowPart2.Parent = beamPart
- beamPart.Parent = workspace
- explosion.Parent = workspace
- for frame = 1, frames do
- local progress = frame / frames
- local alpha = 1 - math.sin(0.5 * math.pi * progress)
- local scale = 0.4 * alpha
- local glowScale1 = alpha * (0.5 + 0.5 * math.sin(math.tau * (8 * gameTime + beamColorOffset)))
- local glowScale2 = alpha * (0.5 + 0.5 * math.cos(math.tau * (8 * gameTime + beamColorOffset)))
- local vertexColor = Vector3.new(Utility.GetRainbowRGB(1.5 * gameTime + beamColorOffset))
- beamLight.Brightness = 1 - progress
- beamLight.Color = Color3.new(vertexColor.x, vertexColor.y, vertexColor.z)
- beamMesh.Scale = Vector3.new(radius * scale, 9000, radius * scale)
- beamMesh.VertexColor = vertexColor
- beamGlowMesh1.Scale = Vector3.new(1.2 * radius * glowScale1, 9000, 1.2 * radius * glowScale1)
- beamGlowMesh1.VertexColor = vertexColor
- beamGlowMesh2.Scale = Vector3.new(1.2 * radius * glowScale2, 9000, 1.2 * radius * glowScale2)
- beamGlowMesh2.VertexColor = vertexColor
- RunService.Stepped:wait()
- gameTime = TaskScheduler.GetCurrentTime()
- if frame <= 2 then
- local explosion = Instance.new("Explosion")
- explosion.BlastPressure = (1 - progress) * blastPressure
- explosion.BlastRadius = (1 - progress) * power
- explosion.Position = target
- explosion.Parent = Workspace
- if frame == 2 then
- sound:Play()
- end
- end
- end
- pcall(beamPart.Destroy, beamPart)
- explosionHitConnection:disconnect()
- end
- function GraphicalEffects.SpaceHyperBeam(target, power, duration, radius, height, deviation)
- TaskScheduler.Start(GraphicalEffects.FireSpaceHyperBeam, target, power or 12, duration or 1.5, radius or 6, height or 600, deviation or 20)
- end
- -- Magic Circle
- GraphicalEffects.magicCircleData = {}
- GraphicalEffects.MAGIC_CIRCLE_DEFAULT_OFFSET = 6.25
- function GraphicalEffects.AnimateMagicCircle(data)
- local frame, direction, magic_circle_model, magic_circle_part, magic_circle_light, magic_circle_decal_back, magic_circle_decal_front, duration,
- stay, magic_circle_adornee_func, magic_circle_offset = unpack(data)
- frame = frame + 1
- data[1] = frame
- local transparency = (frame / duration) ^ stay
- local opacity = 1 - transparency
- if frame == duration then
- pcall(Game.Destroy, magic_circle_model)
- GraphicalEffects.magicCircleData[data] = nil
- else
- if magic_circle_model.Parent ~= Workspace then
- pcall(Utility.SetProperty, magic_circle_model, "Parent", Workspace)
- end
- local magic_circle_adornee = magic_circle_adornee_func()
- magic_circle_position = magic_circle_adornee.Position + direction * magic_circle_offset
- local magic_circle_cframe = CFrame.new(magic_circle_position, magic_circle_position + direction) * CFrame.Angles(0, 0, math.tau * frame /
- 25)
- magic_circle_part.CFrame = magic_circle_cframe
- magic_circle_light.Brightness = opacity
- magic_circle_decal_back.Transparency = transparency
- magic_circle_decal_front.Transparency = transparency
- end
- end
- function GraphicalEffects.CreateMagicCircle(target, magic_circle_scale, magic_circle_image, light_color, duration, stay, magic_circle_adornee_func,
- magic_circle_offset)
- local magic_circle_adornee = magic_circle_adornee_func()
- if magic_circle_adornee then
- local origin = magic_circle_adornee.Position
- local direction = (target - origin).unit
- local magic_circle_position = origin + direction * magic_circle_offset
- local magic_circle_cframe = CFrame.new(magic_circle_position, magic_circle_position + direction)
- local magic_circle_model = Instance.new("Model")
- local magic_circle_part = Instance.new("Part", magic_circle_model)
- local magic_circle_mesh = Instance.new("BlockMesh", magic_circle_part)
- local magic_circle_light = Instance.new("PointLight", magic_circle_part)
- local magic_circle_decal_back = Instance.new("Decal", magic_circle_part)
- local magic_circle_decal_front = Instance.new("Decal", magic_circle_part)
- magic_circle_model.Archivable = false
- magic_circle_part.Anchored = true
- magic_circle_part.BottomSurface = "Smooth"
- magic_circle_part.CanCollide = false
- magic_circle_part.CFrame = magic_circle_cframe
- magic_circle_part.FormFactor = "Custom"
- magic_circle_part.Locked = true
- magic_circle_part.Size = Vector3.new(0.2, 0.2, 0.2)
- magic_circle_part.TopSurface = "Smooth"
- magic_circle_part.Transparency = 1
- magic_circle_mesh.Scale = Vector3.new(60, 60, 0) * magic_circle_scale
- magic_circle_light.Color = light_color
- magic_circle_light.Range = 16 * magic_circle_scale
- magic_circle_light.Shadows = true
- magic_circle_decal_back.Face = "Back"
- magic_circle_decal_back.Texture = magic_circle_image
- magic_circle_decal_front.Face = "Front"
- magic_circle_decal_front.Texture = magic_circle_image
- magic_circle_model.Parent = Workspace
- local data = {0, direction, magic_circle_model, magic_circle_part, magic_circle_light, magic_circle_decal_back, magic_circle_decal_front,
- duration, stay, magic_circle_adornee_func, magic_circle_offset}
- GraphicalEffects.magicCircleData[data] = true
- return data
- end
- end
- -- Laser of Death
- GraphicalEffects.LASER_WIDTH = 0.15
- GraphicalEffects.LASER_MAGIC_CIRCLE_DISTANCE = 6.25
- GraphicalEffects.laser_data = {}
- --GraphicalEffects.fragmentation = {}
- function GraphicalEffects.AnimateLaserOfDeath(data)
- local frame, directionOrientation, direction, magic_circle_model, laser_part, laser_mesh, magic_circle_part, magic_circle_light,
- magic_circle_decal_back, magic_circle_decal_front, sound, laser_scale, fragmentation_size, duration, laser_lights, laser_effects, stay, light_effects =
- unpack(data)
- local laser_color = laser_part.Color
- frame = frame + 1
- data[1] = frame
- local transparency = (frame / duration) ^ stay
- local opacity = 1 - transparency
- if frame == 2 then
- sound:Play()
- end
- if frame == duration then
- pcall(Game.Destroy, magic_circle_model)
- GraphicalEffects.laser_data[data] = nil
- else
- if magic_circle_model.Parent ~= Workspace then
- pcall(Utility.SetProperty, magic_circle_model, "Parent", Workspace)
- end
- local laser_distance = 0
- local origin = chatAdornee.CFrame
- if not light_effects then
- direction = (origin * directionOrientation - origin.p).unit
- end
- local magic_circle_position = origin.p + direction * GraphicalEffects.LASER_MAGIC_CIRCLE_DISTANCE
- local magic_circle_cframe = CFrame.new(magic_circle_position, magic_circle_position + direction) * CFrame.Angles(0, 0, math.tau * frame /
- 25)
- local loop_scale = (laser_scale - 1) / 10
- for x_offset = -loop_scale, loop_scale, 2 do
- for y_offset = -loop_scale, loop_scale, 2 do
- local origin_position = magic_circle_cframe * Vector3.new(x_offset, y_offset, 0)
- for index = 1, 8 do
- local part, position
- for ray_index = 1, 10 do
- local ray = Ray.new(origin_position + direction * (999 * (ray_index - 1)), direction * 999)
- part, position = Workspace:FindPartOnRay(ray, magic_circle_model)
- if part then
- break
- end
- end
- if part then
- laser_distance = (position - origin_position).magnitude
- if frame % 8 == 1 and index == 1 then
- Instance.new("Explosion", Workspace).Position = position
- end
- if not part:IsA("Terrain") then
- pcall(part.BreakJoints, part)
- local is_block = part:IsA("Part") and part.Shape == Enum.PartType.Block
- local mass = part:GetMass()
- local size = part.Size
- if (is_block and ((size.X < fragmentation_size and size.Y < fragmentation_size and size.Z <
- fragmentation_size) or (not part.Anchored and mass < 750))) or (not is_block and mass < 250000) then
- local part_transparency = math.max(part.Transparency + 0.007 * fragmentation_size, 0.5)
- if part_transparency >= 0.5 then -- temporarily to minimize debris
- pcall(Game.Destroy, part)
- else
- local cframe = part.CFrame
- part.Anchored = false
- part.BrickColor = BrickColor.new("Medium stone grey")
- part.CanCollide = true
- if part:IsA("FormFactorPart") then
- part.FormFactor = "Custom"
- end
- part.Size = size - Vector3.new(0.135, 0.135, 0.135) * fragmentation_size
- part.Transparency = part_transparency
- part.CFrame = cframe + direction * 5
- part.Velocity = part.Velocity + direction * 40
- end
- elseif is_block then
- local parts = {part}
- local model = Instance.new("Model", part.Parent)
- model.Name = "Fragments"
- if size.X >= fragmentation_size then
- size = Vector3.new(0.5, 1, 1) * size
- local archivable = part.Archivable
- local cframe = part.CFrame
- part.FormFactor = "Custom"
- part.Size = size
- part.Archivable = true
- local part_clone = part:Clone()
- part.Archivable = archivable
- part_clone.Archivable = archivable
- part.CFrame = cframe * CFrame.new(-0.5 * size.X, 0, 0)
- part_clone.CFrame = cframe * CFrame.new(0.5 * size.X, 0, 0)
- part_clone.Parent = model
- parts[2] = part_clone
- end
- if size.Y >= fragmentation_size then
- size = Vector3.new(1, 0.5, 1) * size
- for part_index = 1, #parts do
- local part = parts[part_index]
- local archivable = part.Archivable
- local cframe = part.CFrame
- part.FormFactor = "Custom"
- part.Size = size
- part.Archivable = true
- local part_clone = part:Clone()
- part.Archivable = archivable
- part_clone.Archivable = archivable
- part.CFrame = cframe * CFrame.new(0, -0.5 * size.Y, 0)
- part_clone.CFrame = cframe * CFrame.new(0, 0.5 * size.Y, 0)
- part_clone.Parent = model
- table.insert(parts, part_clone)
- end
- end
- if size.Z >= fragmentation_size then
- size = Vector3.new(1, 1, 0.5) * size
- for part_index = 1, #parts do
- local part = parts[part_index]
- local archivable = part.Archivable
- local cframe = part.CFrame
- part.FormFactor = "Custom"
- part.Size = size
- part.Archivable = true
- local part_clone = part:Clone()
- part.Archivable = archivable
- part_clone.Archivable = archivable
- part.CFrame = cframe * CFrame.new(0, 0, -0.5 * size.Z)
- part_clone.CFrame = cframe * CFrame.new(0, 0, 0.5 * size.Z)
- part_clone.Parent = model
- table.insert(parts, part_clone)
- end
- end
- for _, part in ipairs(parts) do
- part:MakeJoints()
- end
- else
- break
- end
- end
- else
- laser_distance = 9990
- break
- end
- end
- end
- end
- local laser_cframe = magic_circle_cframe * CFrame.Angles(-0.5 * math.pi, 0, 0)
- local laser_width = GraphicalEffects.LASER_WIDTH * opacity * laser_scale
- local laser_mesh_offset = Vector3.new(0, 0.5 * laser_distance, 0)
- laser_part.CFrame = laser_cframe
- if laser_effects then
- local laser_effect_data_1, laser_effect_data_2 = laser_effects[1], laser_effects[2]
- local laser_effect_1, laser_effect_mesh_1 = laser_effect_data_1[1], laser_effect_data_1[2]
- local laser_effect_2, laser_effect_mesh_2 = laser_effect_data_2[1], laser_effect_data_2[2]
- laser_effect_1.CFrame = laser_cframe
- laser_effect_2.CFrame = laser_cframe
- laser_effect_mesh_1.Offset = laser_mesh_offset
- laser_effect_mesh_2.Offset = laser_mesh_offset
- local game_time = time()
- local effect_scale_1 = 0.5 + 0.5 * math.sin(16 * math.pi * game_time)
- local effect_scale_2 = 0.5 + 0.5 * math.cos(16 * math.pi * game_time)
- laser_effect_mesh_1.Scale = 5 * Vector3.new(laser_width * effect_scale_1, laser_distance, laser_width * effect_scale_1)
- laser_effect_mesh_2.Scale = 5 * Vector3.new(laser_width * effect_scale_2, laser_distance, laser_width * effect_scale_2)
- laser_width = laser_width * 0.25
- end
- laser_mesh.Offset = laser_mesh_offset
- laser_mesh.Scale = 5 * Vector3.new(laser_width, laser_distance, laser_width)
- magic_circle_part.CFrame = magic_circle_cframe
- magic_circle_light.Brightness = opacity
- magic_circle_decal_back.Transparency = transparency
- magic_circle_decal_front.Transparency = transparency
- if light_effects then
- for index, data in ipairs(laser_lights) do
- local laser_spotlight_part, laser_spotlight = data[1], data[2]
- local laser_spotlight_offset = 30 * (index - 1)
- if laser_spotlight_offset <= laser_distance then
- laser_spotlight_part.CFrame = magic_circle_cframe * CFrame.new(0, 0, -laser_spotlight_offset)
- laser_spotlight.Brightness = opacity
- laser_spotlight.Enabled = true
- else
- laser_spotlight.Enabled = false
- end
- end
- end
- end
- end
- function GraphicalEffects.ShootLaserOfDeath(target, data)
- if chatAdornee then
- data = data or {}
- local brickcolor = data.brickcolor or BrickColor.new("Really black")
- local duration = data.duration or 40
- local fragmentation_size = data.fragmentation_size or 3
- local laser_scale = data.laser_scale or 1
- local light_color = data.light_color or Color3.new(1, 0.5, 1)
- local magic_circle_image = data.magic_circle_image or "rbxassetid://122610943"
- local magic_circle_scale = data.magic_circle_scale or 1
- local sound_volume = data.sound_volume or 1 / 3
- local special_effects = data.special_effects
- local stay = data.stay or 4
- local origin = chatAdornee.CFrame
- local directionOrientation = origin:pointToObjectSpace(target)
- local direction = (target - origin.p).unit
- local magic_circle_position = origin.p + direction * GraphicalEffects.LASER_MAGIC_CIRCLE_DISTANCE
- local magic_circle_cframe = CFrame.new(magic_circle_position, magic_circle_position + direction)
- local magic_circle_model = Instance.new("Model")
- local laser_part = Instance.new("Part", magic_circle_model)
- local laser_mesh = Instance.new("CylinderMesh", laser_part)
- local magic_circle_part = Instance.new("Part", magic_circle_model)
- local magic_circle_mesh = Instance.new("BlockMesh", magic_circle_part)
- local magic_circle_light = Instance.new("PointLight", magic_circle_part)
- local magic_circle_decal_back = Instance.new("Decal", magic_circle_part)
- local magic_circle_decal_front = Instance.new("Decal", magic_circle_part)
- local sound = Instance.new("Sound", magic_circle_part)
- sound.Pitch = 1.25
- sound.SoundId = "rbxassetid://2248511"
- sound.Volume = sound_volume
- magic_circle_model.Archivable = false
- laser_part.Anchored = true
- laser_part.BottomSurface = "Smooth"
- laser_part.BrickColor = brickcolor
- laser_part.CanCollide = false
- laser_part.CFrame = magic_circle_cframe * CFrame.Angles(-0.5 * math.pi, 0, 0)
- laser_part.FormFactor = "Custom"
- laser_part.Locked = true
- laser_part.Size = Vector3.new(0.2, 0.2, 0.2)
- laser_part.TopSurface = "Smooth"
- laser_mesh.Offset = Vector3.new(0, 0, 0)
- laser_mesh.Name = "Mesh"
- laser_mesh.Scale = 5 * laser_scale * Vector3.new(GraphicalEffects.LASER_WIDTH, 0, GraphicalEffects.LASER_WIDTH)
- magic_circle_part.Anchored = true
- magic_circle_part.BottomSurface = "Smooth"
- magic_circle_part.CanCollide = false
- magic_circle_part.CFrame = magic_circle_cframe
- magic_circle_part.FormFactor = "Custom"
- magic_circle_part.Locked = true
- magic_circle_part.Size = Vector3.new(0.2, 0.2, 0.2)
- magic_circle_part.TopSurface = "Smooth"
- magic_circle_part.Transparency = 1
- magic_circle_mesh.Scale = Vector3.new(60, 60, 0) * magic_circle_scale
- magic_circle_light.Color = light_color
- magic_circle_light.Range = 16 * magic_circle_scale
- magic_circle_light.Shadows = true
- magic_circle_decal_back.Face = "Back"
- magic_circle_decal_back.Texture = magic_circle_image
- magic_circle_decal_front.Face = "Front"
- magic_circle_decal_front.Texture = magic_circle_image
- magic_circle_model.Parent = Workspace
- local laser_color = brickcolor.Color
- local laser_lights = {}
- local light_effects = laser_color.r + laser_color.g + laser_color.b > 0.25
- if light_effects then
- local laser_spotlight_part_template = Instance.new("Part")
- local laser_spotlight_light_template = Instance.new("SpotLight", laser_spotlight_part_template)
- laser_spotlight_part_template.Anchored = true
- laser_spotlight_part_template.Anchored = true
- laser_spotlight_part_template.BottomSurface = "Smooth"
- laser_spotlight_part_template.CanCollide = false
- laser_spotlight_part_template.FormFactor = "Custom"
- laser_spotlight_part_template.Locked = true
- laser_spotlight_part_template.Size = Vector3.new(0.2, 0.2, 0.2)
- laser_spotlight_part_template.TopSurface = "Smooth"
- laser_spotlight_part_template.Transparency = 1
- laser_spotlight_light_template.Angle = 45
- laser_spotlight_light_template.Color = laser_color
- laser_spotlight_light_template.Enabled = true
- laser_spotlight_light_template.Name = "Light"
- laser_spotlight_light_template.Range = 60
- for index = 1, 40 do
- local laser_spotlight_part = laser_spotlight_part_template:Clone()
- laser_spotlight_part.CFrame = magic_circle_cframe * CFrame.new(0, 0, -30 * (index - 1))
- laser_spotlight_part.Parent = magic_circle_model
- laser_lights[index] = {laser_spotlight_part, laser_spotlight_part.Light}
- end
- end
- local laser_effects
- if special_effects then
- laser_effects = {}
- local laser_effect_1 = laser_part:Clone()
- laser_effect_1.BrickColor = special_effects
- laser_effect_1.Transparency = 0.5
- local laser_effect_2 = laser_effect_1:Clone()
- laser_effects[1], laser_effects[2] = {laser_effect_1, laser_effect_1.Mesh}, {laser_effect_2, laser_effect_2.Mesh}
- laser_effect_1.Parent = magic_circle_model
- laser_effect_2.Parent = magic_circle_model
- end
- GraphicalEffects.laser_data[{0, directionOrientation, direction, magic_circle_model, laser_part, laser_mesh, magic_circle_part,
- magic_circle_light, magic_circle_decal_back, magic_circle_decal_front, sound, laser_scale, fragmentation_size, duration, laser_lights, laser_effects, stay,
- light_effects}] = true
- end
- end
- -- Sapient Rock
- function GraphicalEffects.SpawnSapientRock(position)
- local part = Instance.new("Part", Workspace)
- local size = 8 + math.random(0, 5)
- part.BottomSurface = "Smooth"
- part.TopSurface = "Smooth"
- part.Material = "Slate"
- part.Locked = true
- part.Shape = "Ball"
- part.FormFactor = "Custom"
- part.Size = Vector3.new(size, size, size)
- part.Position = position
- local bodypos = Instance.new("BodyPosition", part)
- bodypos.maxForce = Vector3.new(0, 0, 0)
- local angry = false
- local damage_ready = true
- local torso_following
- local torso_changed = -1000
- local touched_conn = part.Touched:connect(function(hit)
- local character = hit.Parent
- if character then
- local humanoid
- for _, child in ipairs(character:GetChildren()) do
- if child:IsA("Humanoid") then
- humanoid = child
- break
- end
- end
- if humanoid then
- if angry then
- if damage_ready then
- damage_ready = false
- humanoid:TakeDamage(100)
- wait(1)
- damage_ready = true
- angry = false
- part.BrickColor = BrickColor.new("Medium stone grey")
- end
- else
- local torso = humanoid.Torso
- if torso then
- torso_following = torso
- torso_changed = tick()
- end
- end
- end
- end
- end)
- TaskScheduler.Start(function()
- while part.Parent == Workspace do
- if torso_following then
- bodypos.position = torso_following.Position
- if tick() - torso_changed > 60 or not torso_following.Parent then
- torso_following = nil
- bodypos.maxForce = Vector3.new(0, 0, 0)
- angry = false
- part.BrickColor = BrickColor.new("Medium stone grey")
- else
- local speed = angry and Vector3.new(16, 16, 16) or Vector3.new(6, 0, 6)
- bodypos.maxForce = part:GetMass() * speed
- if part.Position.Y < -250 then
- part.Velocity = Vector3.new()
- part.Position = torso_following.Position + Vector3.new(0, 80, 0)
- part.BrickColor = BrickColor.new("Bright red")
- angry = true
- torso_changed = tick()
- end
- end
- end
- RunService.Stepped:wait()
- end
- touched_conn:disconnect()
- end)
- TaskScheduler.Start(function()
- while part.Parent == Workspace do
- wait(25 + math.random() * 10)
- local next_size = 8 + math.random() * 5
- if math.random(100) == 1 then
- next_size = next_size * (2 + 6 * math.random())
- end
- next_size = math.floor(next_size + 0.5)
- local start_time = tick()
- local mesh = Instance.new("SpecialMesh", part)
- mesh.MeshType = "Sphere"
- repeat
- local elapsed_time = tick() - start_time
- local alpha = math.cos(elapsed_time * math.pi * 0.5)
- local interpolated_size = size * alpha + next_size * (1 - alpha)
- local size_vector = Vector3.new(interpolated_size, interpolated_size, interpolated_size)
- local cframe = part.CFrame
- part.Size = size_vector
- part.CFrame = cframe
- mesh.Scale = size_vector / part.Size
- RunService.Stepped:wait()
- until tick() - start_time >= 1
- mesh:Destroy()
- local cframe = part.CFrame
- part.Size = Vector3.new(next_size, next_size, next_size)
- part.CFrame = cframe
- size = next_size
- end
- end)
- end
- -- Crystal ring
- function GraphicalEffects.CrystalRing(data)
- data = data or {}
- local crystal_count = data.crystal_count or 10
- local crystal_color = data.crystal_color or BrickColor.new("Bright red")
- local crystal_scale = data.crystal_scale or Vector3.new(2 / 3, 2, 2 / 3)
- local radius = radius or 1.25 * crystal_count / math.pi
- local spawn_duration = data.spawn_duration or 0.065
- local full_spawn_duration = spawn_duration * crystal_count
- local float_duration = data.float_duration or 5
- local wave_amplitude = data.wave_amplitude or 0.5
- local wave_period = data.wave_period or 1
- local appear_duration = data.appear_duration or 0.1
- local disappear_duration = data.disappear_duration or 0.5
- local base_part = data.base_part
- local offset_cframe
- if data.position then
- offset_cframe = CFrame.new(data.position)
- if base_part then
- offset_cframe = base_part.CFrame:toObjectSpace(offset_cframe)
- end
- else
- offset_cframe = CFrame.new()
- end
- local crystal_template = Instance.new("Part")
- crystal_template.Anchored = true
- crystal_template.Locked = true
- crystal_template.CanCollide = false
- crystal_template.BottomSurface = "Smooth"
- crystal_template.TopSurface = "Smooth"
- crystal_template.BrickColor = crystal_color
- crystal_template.FormFactor = "Symmetric"
- crystal_template.Size = Vector3.new(1, 1, 1)
- local crystal_light = Instance.new("PointLight", crystal_template)
- crystal_light.Brightness = 0.1 / crystal_count
- crystal_light.Color = crystal_color.Color
- crystal_light.Name = "Light"
- crystal_light.Range = radius
- crystal_light.Shadows = true
- local crystal_mesh = Instance.new("SpecialMesh", crystal_template)
- crystal_mesh.MeshId = "rbxassetid://9756362"
- crystal_mesh.MeshType = "FileMesh"
- crystal_mesh.Name = "Mesh"
- crystal_mesh.Scale = crystal_scale
- local crystal_model = Instance.new("Model")
- crystal_model.Archivable = false
- crystal_model.Name = "Crystal Model"
- crystal_model.Parent = Workspace
- local crystals = {}
- local lights = {}
- local meshes = {}
- for index = 1, crystal_count do
- local crystal = crystal_template:Clone()
- crystal.Parent = crystal_model
- crystals[index] = crystal
- lights[index] = crystal.Light
- meshes[index] = crystal.Mesh
- end
- local start_time = tick()
- repeat
- local base_cframe = offset_cframe
- if base_part then
- base_cframe = base_part.CFrame * base_cframe
- end
- local elapsed_time = tick() - start_time
- for index, crystal in ipairs(crystals) do
- local crystal_time = elapsed_time - index * spawn_duration
- local disappear_time = crystal_time - float_duration
- local offset
- if crystal_time < 0 then
- offset = 0
- elseif crystal_time < appear_duration then
- offset = radius * crystal_time / appear_duration
- else
- offset = radius
- end
- local wave_offset
- if disappear_time >= 0 then
- local disappear_progress = disappear_time / disappear_duration
- if disappear_progress > 1 then
- if crystal.Parent then
- crystal:Destroy()
- end
- else
- local inverse_progress = 1 - disappear_progress
- local light = lights[index]
- local mesh = meshes[index]
- crystal.BrickColor = BrickColor.new("Really black")
- light.Brightness = 2 * inverse_progress
- light.Range = 2 * radius
- mesh.Scale = crystal_scale * inverse_progress
- end
- wave_offset = 0
- else
- wave_offset = wave_amplitude * math.sin(math.tau * (elapsed_time - index / crystal_count * 3) / wave_period)
- end
- local rotation_angle = (tick() * 0.5 + (index - 1) / crystal_count) % 1 * math.tau
- crystal.CFrame = base_cframe * CFrame.Angles(0, rotation_angle, 0) * CFrame.new(0, wave_offset, -offset)
- end
- RunService.Stepped:wait()
- until elapsed_time >= float_duration + full_spawn_duration + disappear_duration
- if crystal_model.Parent then
- crystal_model:Destroy()
- end
- end
- -- Missiles
- GraphicalEffects.missileData = {}
- GraphicalEffects.missileParts = {}
- function GraphicalEffects.AnimateMissile(data)
- local frame, missilePart, targetPart, timeCreated, direction, touchedConnection, explodeRequested, bodyGyro, swooshSound, magicCircleData, lifeTime,
- pointOnPart, flipped = unpack(data)
- frame = frame + 1
- data[1] = frame
- if flipped then
- direction = -direction
- end
- if frame <= 10 then
- if frame == 2 then
- swooshSound:Play()
- end
- missilePart.Anchored = true
- local progress = frame / 10
- missilePart.Size = Vector3.new(1, 1, progress * 4)
- local magicCirclePart = magicCircleData[4]
- local magicCirclePosition = magicCirclePart.Position
- local missileOffset = 2 * progress * direction
- local missilePosition = magicCirclePosition + missileOffset
- missilePart.CFrame = CFrame.new(missilePosition, missilePosition + direction)
- --missilePart.Transparency = 0.5 * (1 - progress)
- if frame == 10 then
- touchedConnection = missilePart.Touched:connect(function(hit)
- if hit.CanCollide and hit.Parent and not GraphicalEffects.missileParts[hit] then
- touchedConnection:disconnect()
- data[7] = true
- end
- end)
- data[6] = touchedConnection
- end
- else
- missilePart.Anchored = false
- local missilePosition = missilePart.Position
- local targetPosition = targetPart.CFrame * pointOnPart
- local distanceVector = targetPosition - missilePosition
- local elapsedTime = time() - timeCreated
- local targetParent = targetPart.Parent
- if explodeRequested or (targetParent and distanceVector.magnitude < 10) or elapsedTime > lifeTime then
- GraphicalEffects.missileData[data] = nil
- GraphicalEffects.missileParts[missilePart] = nil
- touchedConnection:disconnect()
- if missilePart.Parent then
- missilePart:Destroy()
- local explosion = Instance.new("Explosion")
- explosion.BlastRadius = 12.5
- explosion.Position = missilePosition
- local explosionHitConnection = explosion.Hit:connect(function(hit, distance)
- local missileData = GraphicalEffects.missileParts[hit]
- if missileData and distance < 3 then
- missileData[7] = true
- else
- pcall(hit.BreakJoints, hit)
- end
- end)
- explosion.Parent = Workspace
- TaskScheduler.Schedule(1, explosionHitConnection.disconnect, explosionHitConnection)
- end
- else
- local targetInWorkspace = targetPart:IsDescendantOf(Workspace)
- if targetInWorkspace then
- direction = distanceVector.unit
- data[5] = direction
- end
- local speed = 14 + elapsedTime * 10
- local gyroD
- if elapsedTime < 42.5 and targetInWorkspace then
- gyroD = 1000 - elapsedTime * 15
- else
- gyroD = 100
- bodyGyro.maxTorque = Vector3.new(0, 0, 0)
- if elapsedTime + 7.5 < lifeTime then
- data[11] = elapsedTime + 7.5
- end
- end
- bodyGyro.D = gyroD
- bodyGyro.cframe = CFrame.new(Vector3.new(), direction)
- missilePart.Velocity = missilePart.CFrame.lookVector * speed
- end
- end
- end
- function GraphicalEffects.ShootMissile(targetPart, pointOnPart, direction, magic_circle_adornee_func, magic_circle_offset, flipped)
- if not magic_circle_offset then
- magic_circle_offset = GraphicalEffects.MAGIC_CIRCLE_DEFAULT_OFFSET
- end
- local targetPosition = targetPart.Position
- local headPosition = chatAdornee.Position
- local origin = CFrame.new(headPosition, headPosition + direction) + direction * magic_circle_offset
- local missilePart = Instance.new("Part")
- local antiGravityForce = Instance.new("BodyForce", missilePart)
- local bodyGyro = Instance.new("BodyGyro", missilePart)
- local explosionSound = Instance.new("Sound", missilePart)
- local swooshSound = Instance.new("Sound", missilePart)
- antiGravityForce.force = Vector3.new(0, 196.2 * 4, 0)
- bodyGyro.D = 1000
- bodyGyro.maxTorque = Vector3.new(1, 1, 1)
- explosionSound.PlayOnRemove = true
- explosionSound.SoundId = "rbxasset://sounds/collide.wav"
- explosionSound.Volume = 1
- missilePart.Anchored = true
- missilePart.BackSurface = "Studs"
- missilePart.BottomSurface = "Studs"
- missilePart.BrickColor = BrickColor.Red()
- missilePart.CFrame = origin
- missilePart.FormFactor = "Custom"
- missilePart.FrontSurface = "Studs"
- missilePart.LeftSurface = "Studs"
- missilePart.Locked = true
- missilePart.RightSurface = "Studs"
- missilePart.Size = Vector3.new(1, 1, 0.2)
- missilePart.TopSurface = "Studs"
- --missilePart.Transparency = 0.5
- swooshSound.Looped = true
- swooshSound.SoundId = "rbxasset://sounds/Rocket whoosh 01.wav"
- swooshSound.Volume = 0.7
- local magicCircleData = GraphicalEffects.CreateMagicCircle(headPosition + direction * 1000, 0.875, "rbxassetid://127033719", Color3.new(1, 1, 1),
- 40, 4, magic_circle_adornee_func or function() return chatAdornee end, magic_circle_offset)
- local data = {0, missilePart, targetPart, time(), direction, false, false, bodyGyro, swooshSound, magicCircleData, 50, pointOnPart, flipped}
- missilePart.Parent = Workspace
- GraphicalEffects.missileData[data] = true
- GraphicalEffects.missileParts[missilePart] = data
- end
- -- Joint crap
- function GraphicalEffects.CubicInterpolate(y0, y1, y2, y3, mu)
- local a0, a1, a2, a3, mu2
- mu2 = mu * mu
- a0 = y3 - y2 - y0 + y1
- a1 = y0 - y1 - a0
- a2 = y2 - y0
- a3 = y1
- return a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3
- end
- function GraphicalEffects.JointCrap(model, cycletime)
- if model then
- local cycletime = cycletime or (0.75 * (1 + math.random() * 4))
- local offsetradius = 0.75
- local rotationoffset = math.pi
- local joints = {}
- local stack = model:GetChildren()
- while #stack ~= 0 do
- local object = stack[#stack]
- table.remove(stack)
- for index, child in ipairs(object:GetChildren()) do
- table.insert(stack, child)
- end
- if object:IsA("JointInstance") then
- table.insert(joints, object)
- end
- end
- local rot0 = {}
- local rot1 = {}
- local rot2 = {}
- local rot3 = {}
- local rot4 = {}
- for index, joint in ipairs(joints) do
- local pos = Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5).unit * offsetradius
- local rot = Vector3.new(math.random(), math.random(), math.random()) * rotationoffset
- rot0[index] = {joint.C0, joint.C1}
- rot = Vector3.new(rot.x % (math.tau), rot.y % (math.tau), rot.z % (math.tau))
- rot2[index] = {pos, rot}
- pos = Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5).unit * offsetradius
- rot = rot + Vector3.new(math.random(), math.random(), math.random()) * rotationoffset
- rot = Vector3.new(rot.x % (math.tau), rot.y % (math.tau), rot.z % (math.tau))
- rot3[index] = {pos, rot}
- pos = Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5).unit * offsetradius
- rot = rot + Vector3.new(math.random(), math.random(), math.random()) * rotationoffset
- rot = Vector3.new(rot.x % (math.tau), rot.y % (math.tau), rot.z % (math.tau))
- rot4[index] = {pos, rot}
- end
- while model.Parent do
- for i, j in ipairs(joints) do
- local pos = Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5).unit * offsetradius
- local rot = rot4[i][2] + Vector3.new(math.random(), math.random(), math.random()) * rotationoffset
- rot = Vector3.new(rot.x % (math.tau), rot.y % (math.tau), rot.z % (math.tau))
- rot1[i], rot2[i], rot3[i], rot4[i] = rot2[i], rot3[i], rot4[i], {pos, rot}
- end
- local start = tick()
- while true do
- local ctime = tick()
- local elapsed = ctime - start
- if elapsed > cycletime then
- break
- end
- local progress = elapsed / cycletime
- for index, joint in ipairs(joints) do
- local v0, v1, v2, v3, v4 = rot0[index], rot1[index], rot2[index], rot3[index], rot4[index]
- local p1, p2, p3, p4, r1, r2, r3, r4 = v1[1], v2[1], v3[1], v4[1], v1[2], v2[2], v3[2], v4[2]
- local px = GraphicalEffects.CubicInterpolate(p1.x, p2.x, p3.x, p4.x, progress)
- local py = GraphicalEffects.CubicInterpolate(p1.y, p2.y, p3.y, p4.y, progress)
- local pz = GraphicalEffects.CubicInterpolate(p1.z, p2.z, p3.z, p4.z, progress)
- local rx = GraphicalEffects.CubicInterpolate(r1.x, r2.x, r3.x, r4.x, progress)
- local ry = GraphicalEffects.CubicInterpolate(r1.y, r2.y, r3.y, r4.y, progress)
- local rz = GraphicalEffects.CubicInterpolate(r1.z, r2.z, r3.z, r4.z, progress)
- local cframe = CFrame.new(px, py, pz) * CFrame.Angles(rx, ry, rz)
- joint.C0 = v0[1] * cframe
- joint.C1 = v0[2] * cframe:inverse()
- end
- RunService.Stepped:wait()
- end
- end
- end
- end
- -- Destruction spell
- do
- GraphicalEffects.destructionSpellSpeed = 5
- GraphicalEffects.destructionSpellEffectSize = 2
- GraphicalEffects.destructionSpellExplosionRate = 10
- GraphicalEffects.destructionSpellFadeDuration = 120
- local partProto = Instance.new("Part")
- local partProtoDecal1 = Instance.new("Decal", partProto)
- local partProtoDecal2 = Instance.new("Decal", partProto)
- local partProtoGyro = Instance.new("BodyGyro", partProto)
- local partProtoPosition = Instance.new("BodyPosition", partProto)
- partProto.CanCollide = false
- partProto.FormFactor = "Custom"
- partProto.Transparency = 1
- partProtoDecal1.Face = "Bottom"
- partProtoDecal1.Texture = "rbxassetid://106508453"
- partProtoDecal2.Face = "Top"
- partProtoDecal2.Texture = "rbxassetid://106508453"
- partProtoGyro.Name = "gyro"
- partProtoGyro.P = 1e6
- partProtoGyro.maxTorque = Vector3.new(1e9, 1e9, 1e9)
- partProtoPosition.Name = "pos"
- partProtoPosition.P = 1e4
- partProtoPosition.maxForce = Vector3.new(1e9, 1e9, 1e9)
- function GraphicalEffects.DestructionSpell(nodes)
- local destroyTable = {}
- local regionSizeX, regionSizeY, regionSizeZ
- local function MagicalDestroyUnchecked(part)
- local partSize = part.Size
- if partSize.X < regionSizeX and partSize.Y < regionSizeY and partSize.Z < regionSizeZ then
- destroyTable[part] = true
- part.Material = "Plastic"
- local beginTransparency = part.Transparency
- local fadeDuration = GraphicalEffects.destructionSpellFadeDuration
- for i = 1, fadeDuration do
- RunService.Stepped:wait()
- part.Transparency = beginTransparency + (1 - beginTransparency) * (i / fadeDuration)
- end
- pcall(Game.Destroy, part)
- destroyTable[part] = nil
- end
- end
- local function MagicalDestroy(part)
- if not destroyTable[part] then
- MagicalDestroyUnchecked(part)
- end
- end
- local function MagicalNodeFinalize(part, gyro, pos, conn)
- part.Anchored = true
- pcall(gyro.Destroy, gyro)
- pcall(pos.Destroy, pos)
- conn:disconnect()
- end
- local model = Instance.new("Model")
- model.Archivable = false
- model.Name = "Nolix Wrath"
- model.Parent = Workspace
- local connections = {}
- local parts = {}
- local partsHit = {}
- local cleanupList = {}
- local explosionRate = GraphicalEffects.destructionSpellExplosionRate
- local effectSize = GraphicalEffects.destructionSpellEffectSize
- partProto.Size = Vector3.new(effectSize, 0.2, effectSize)
- local speed = GraphicalEffects.destructionSpellSpeed
- local rateTimer = 0
- local partRotation = CFrame.Angles(0, 0.5 * math.pi, 0)
- local minX, minY, minZ, maxX, maxY, maxZ = math.huge, math.huge, math.huge, -math.huge, -math.huge, -math.huge
- for index = 4, #nodes do
- local v0, v1, v2, v3 = nodes[index - 3], nodes[index - 2], nodes[index - 1], nodes[index]
- local p1 = v1
- local count = math.ceil((v2 - v1).magnitude / effectSize)
- local linearStep = (v2 - v1) / count
- for i = 1, count do
- local alpha = i / count
- local p2 = GraphicalEffects.CubicInterpolate(v0, v1, v2, v3, alpha)
- local center = 0.5 * (p1 + p2)
- local offset = p2 - p1
- local partId = #parts + 1
- local hitList = {}
- partsHit[partId] = hitList
- local part = partProto:Clone()
- local gyro = part.gyro
- local pos = part.pos
- local cframe = CFrame.new(center, center + offset) * partRotation
- part.CFrame = cframe
- gyro.cframe = cframe
- pos.position = center
- local posX, posY, posZ = center.X, center.Y, center.Z
- if posX < minX then minX = posX end
- if posY < minY then minY = posY end
- if posZ < minZ then minZ = posZ end
- if posX > maxX then maxX = posX end
- if posY > maxY then maxY = posY end
- if posZ > maxZ then maxZ = posZ end
- Instance.new("BlockMesh", part).Scale = Vector3.new(offset.magnitude, 0, effectSize)
- parts[partId] = part
- destroyTable[part] = true
- local conn = part.Touched:connect(function(hit)
- if not destroyTable[hit] then
- hitList[hit] = true
- end
- end)
- part.Parent = model
- p1 = p2
- TaskScheduler.Schedule(0.125, MagicalNodeFinalize, part, gyro, pos, conn)
- rateTimer = rateTimer + 1
- while rateTimer >= speed do
- RunService.Stepped:wait()
- rateTimer = rateTimer - speed
- end
- end
- end
- local center = Vector3.new(minX + maxX, minY + maxY, minZ + maxZ) * 0.5
- regionSizeX, regionSizeY, regionSizeZ = maxX - minX, maxY - minY, maxZ - minZ
- wait(0.5)
- rateTimer = 0
- for index, part in pairs(parts) do
- if index % explosionRate == 1 then
- local partSize = part.Size
- if partSize.X < regionSizeX and partSize.Y < regionSizeY and partSize.Z < regionSizeZ then
- local explosion = Instance.new("Explosion")
- explosion.BlastPressure = 0
- local position = part.Position
- explosion.BlastRadius = (position - center).magnitude * 0.5
- explosion.Position = (position + center) * 0.5
- connections[#connections + 1] = explosion.Hit:connect(MagicalDestroy)
- explosion.Parent = model
- end
- end
- pcall(part.Destroy, part)
- destroyTable[part] = nil
- local hitList = partsHit[index]
- for hit in pairs(hitList) do
- local partSize = hit.Size
- if partSize.X < regionSizeX and partSize.Y < regionSizeY and partSize.Z < regionSizeZ
- and hit.Parent and not destroyTable[hit] then
- TaskScheduler.Start(MagicalDestroyUnchecked, hit)
- local explosion = Instance.new("Explosion")
- explosion.BlastPressure = 0
- explosion.BlastRadius = hit:GetMass() ^ (1 / 3) * 2
- explosion.Position = hit.Position
- connections[#connections + 1] = explosion.Hit:connect(MagicalDestroy)
- explosion.Parent = model
- end
- end
- rateTimer = rateTimer + 1
- while rateTimer >= 4 * speed do
- RunService.Stepped:wait()
- rateTimer = rateTimer - 4 * speed
- end
- end
- wait(0.25)
- for _, connection in ipairs(connections) do
- connection:disconnect()
- end
- end
- end
- -- MainLoop
- function GraphicalEffects.MainLoop()
- RunService.Stepped:wait()
- for data in pairs(GraphicalEffects.magicCircleData) do
- GraphicalEffects.AnimateMagicCircle(data)
- end
- for data in pairs(GraphicalEffects.laser_data) do
- GraphicalEffects.AnimateLaserOfDeath(data)
- end
- for data in pairs(GraphicalEffects.missileData) do
- GraphicalEffects.AnimateMissile(data)
- end
- end
- TaskScheduler.Start(function()
- while true do
- GraphicalEffects.MainLoop()
- end
- end)
- ]])
- Module.Store("ServerControl", [=[
- for _, child in ipairs(Game:GetChildren()) do
- local success, className = pcall(function() return child.ClassName end)
- if success and className == "NetworkServer" then
- NetworkServer = child
- break
- end
- end
- ServerControl.banished_names = {}
- for _, name in ipairs({
- "12345678910jaijai",
- "56awesome56",
- "aleksa12432",
- "blowup998",
- "christmasboy",
- "coolythe94",
- "dalvo546",
- "ENCRYPTEDis",
- "fanoftheforgotten",
- "goldenarrow97",
- "Guest101632",
- "hgbvcgdhgfds",
- "IlIlXxxxxxXX12",
- "InfiniteDeathKiller",
- "JTHKILL99",
- "liIlilILLIilIlil",
- "LuaHat",
- "LuaScriptPro",
- "missKittyCatlove",
- "MsDaisyroses",
- "robloxmaster4491",
- "rojdi3",
- "s3sss3x",
- "SBDESTROYER1",
- "ScriptGuider",
- "Scriptralize",
- "ScriptTestingAccount",
- "Scrupting",
- "SomeMayCallMeATroll",
- "starwill1",
- "Starwill3",
- "Toothyepic",
- "trefor123"
- }) do
- ServerControl.banished_names[name:lower()] = true
- end
- for _, player in ipairs(Players:GetPlayers()) do
- local playerName = tostring(player)
- if ServerControl.banished_names[playerName:lower()] then
- Logger.printf("Info", "Player %s has been kicked", playerName)
- player:Kick()
- end
- end
- ServerControl.LONG_STRING = string.rep("0123456789", 20001)
- ServerControl.player_data = {}
- function ServerControl.BanishName(name)
- ServerControl.banished_names[name:lower()] = true
- end
- ServerControl.authorizedRemoteEvents = {}
- ServerControl.MAX_MESSAGES = 2
- ServerControl.message_list = {}
- function ServerControl.BlockMessageSpam(object)
- local message_list = ServerControl.message_list
- local message_count = #message_list + 1
- message_list[message_count] = object
- if message_count > ServerControl.MAX_MESSAGES then
- local new_message_count = 0
- local new_message_list = {}
- for message_index = 1, message_count do
- local message_object = message_list[message_index]
- local success, in_workspace = pcall(Game.IsDescendantOf, message_object, Workspace)
- if success and in_workspace then
- new_message_count = new_message_count + 1
- new_message_list[new_message_count] = message_object
- end
- end
- while new_message_count > ServerControl.MAX_MESSAGES do
- local message_object = new_message_list[1]
- Debris:AddItem(message_object, 0)
- table.remove(new_message_list, 1)
- new_message_count = new_message_count - 1
- end
- ServerControl.message_list = new_message_list
- end
- end
- function ServerControl.FilterReplicatedStorage(child)
- if child.ClassName == "RemoteEvent" and not ServerControl.authorizedRemoteEvents[child] then
- Spawn(function()
- child:Destroy()
- Logger.printf("Info", "removed remote event %q from ReplicatedStorage", tostring(child))
- end)
- end
- end
- function ServerControl.GetPlayer(playerName)
- if NetworkServer then
- for _, replicator in ipairs(NetworkServer:GetChildren()) do
- if replicator:IsA("NetworkReplicator") then
- local player = replicator:GetPlayer()
- if player and tostring(player) == playerName then
- return player
- end
- end
- end
- end
- end
- function ServerControl.ListConnectedPlayers()
- if NetworkServer then
- for _, replicator in ipairs(NetworkServer:GetChildren()) do
- if replicator:IsA("NetworkReplicator") then
- local player = replicator:GetPlayer()
- if player then
- Logger.print("Output", tostring(player))
- else
- Logger.print("Output", "(joining)")
- end
- end
- end
- end
- end
- ServerControl.previous_player_list = {}
- function ServerControl.MainLoop()
- wait(1)
- for _, player in ipairs(Players:GetChildren()) do
- ypcall(function()
- if player:IsA("Player") then
- TaskScheduler.Schedule(ServerControl.ConnectPlayer, player)
- end
- end)
- end
- local buffer = {"AdvancedGUI.networkFrame:ClearItems()"}
- local player_list = {}
- local different = false
- local replicator_count = 0
- if NetworkServer then
- for index, replicator in ipairs(NetworkServer:GetChildren()) do
- if replicator:IsA("NetworkReplicator") then
- local player = replicator:GetPlayer()
- local item_text
- if player then
- local system_time, idle_time, user_name, is_nil
- user_name = tostring(player)
- local player_data = ServerControl.player_data[user_name]
- if player_data then
- system_time = player_data[1]
- local idle_time_raw = player_data[2]
- local seconds = idle_time_raw % 60
- local minutes = (idle_time_raw - seconds) / 60
- idle_time = string.format("%i:%04.1f", minutes, seconds)
- else
- system_time = "??:??:??"
- idle_time = "?:??.?"
- end
- is_nil = not player.Parent
- item_text = string.format("%s %s %s %s", system_time, idle_time, user_name, tostring(is_nil))
- buffer[#buffer + 1] = string.format("AdvancedGUI.networkFrame:AddItem(%q, %q, %q, %s)", system_time, idle_time,
- user_name, tostring(is_nil))
- else
- item_text = "(joining the game)"
- buffer[#buffer + 1] = "GuiTextList.AddItem(AdvancedGUI.networkFrame, \"(joining the game)\")"
- end
- different = different or ServerControl.previous_player_list[index] ~= item_text
- replicator_count = replicator_count + 1
- player_list[index] = item_text
- end
- end
- else
- buffer[#buffer + 1] = string.format("AdvancedGUI.networkFrame:AddItem(\"<OFFLINE MODE>\")")
- different = different or ServerControl.previous_player_list[1] ~= "<OFFLINE MODE>"
- replicator_count = 1
- player_list[1] = "<OFFLINE MODE>"
- end
- if different or #ServerControl.previous_player_list ~= replicator_count then
- Network.TransmitController(table.concat(buffer, "\n"))
- ServerControl.previous_player_list = player_list
- end
- end
- ServerControl.connected_players = {}
- ServerControl.connection_signals = {}
- ServerControl.next_script_id = Network.script_id + 1
- ServerControl.module_signal_packet_name = "MODULE_READY/" .. _SessionID .. "/" .. Network.server_id
- function ServerControl.ConnectPlayer(player, forced)
- if forced or not ServerControl.connected_players[player] then
- ServerControl.connected_players[player] = 1
- local valid, is_player = pcall(Game.IsA, player, "Player")
- is_player = is_player == true or not valid
- local is_controller = is_player and player.userId == ControllerInfo.user_id
- local new_script_id
- if is_controller then
- new_script_id = Network.controller_id
- else
- new_script_id = ServerControl.next_script_id
- ServerControl.next_script_id = new_script_id + 1
- end
- local network_receiver_script = SBTools.NewLocalScript(_SessionID .. "/" .. new_script_id, NetworkReceiver.source)
- local marker_label = "ACKNOWLEDGE/" .. _SessionID .. "/" .. new_script_id
- TaskScheduler.Start(function()
- local connection_established = false
- local listener
- listener = ReplicatedStorage.ChildAdded:connect(function(child)
- if child.Name == marker_label then
- listener:disconnect()
- local player_name = child.Value
- Debris:AddItem(child, 0)
- connection_established = true
- Network.Register(player_name, new_script_id)
- if not is_controller then
- Network.TransmitController(string.format("Network.Register(%q, %s)", player_name, tostring(new_script_id)))
- end
- local signal = RbxUtility.CreateSignal()
- ServerControl.connection_signals[new_script_id] = signal
- Network.Transmit(new_script_id, string.format([[
- local Module = {}
- Module.name = "Module"
- Module.source = %q
- loadstring(Module.source)(Module)
- setmetatable(Module, Module.metatable)
- Module.Register(Module)
- local packet = Instance.new("IntValue")
- packet.Name = %q
- packet.Value = %s
- packet.Parent = Game:GetService("ReplicatedStorage")
- ]], Module.source, ServerControl.module_signal_packet_name, tostring(new_script_id)))
- signal:wait()
- if ServerControl.connected_players[player] == 1 then
- ServerControl.connected_players[player] = 2
- ServerControl.connection_signals[new_script_id] = nil
- Network.Transmit(new_script_id, "")
- Network.TransmitModule(new_script_id, LuaEnum)
- Network.TransmitModule(new_script_id, Logger)
- Network.TransmitModule(new_script_id, Utility)
- Network.TransmitModule(new_script_id, TaskScheduler)
- Network.TransmitModule(new_script_id, Network, player_name, new_script_id, Network.controller_id)
- if is_controller then
- Network.TransmitModule(new_script_id, UserInterface, true)
- Network.TransmitModule(new_script_id, PyramidCharacter)
- Network.TransmitModule(new_script_id, CharacterAppearance)
- Network.TransmitModule(new_script_id, PlayerControl)
- Network.TransmitModule(new_script_id, ChatColor)
- Network.TransmitModule(new_script_id, RBXInstance)
- Network.TransmitModule(new_script_id, AdvancedGUI)
- Network.TransmitModule(new_script_id, ControllerCommands)
- local local_script_forward, server_script_forward
- if SBTools.local_script and SBTools.server_script then
- local_script_forward = SBTools.local_script:Clone()
- server_script_forward = SBTools.server_script:Clone()
- local_script_forward.Parent = ReplicatedStorage
- server_script_forward.Parent = ReplicatedStorage
- end
- Network.TransmitModule(new_script_id, SBTools, local_script_forward, server_script_forward)
- Network.StoreModule(new_script_id, NetworkReceiver)
- Network.StoreModule(new_script_id, ChatBubble)
- Network.StoreModule(new_script_id, Fragmentation)
- Network.StoreModule(new_script_id, GraphicalEffects)
- Network.StoreModule(new_script_id, ServerControl)
- else
- Network.TransmitModule(new_script_id, UserInterface)
- end
- Network.TransmitModule(new_script_id, Notification)
- end
- end
- end)
- repeat
- if is_player then
- local success, errorMessage = ypcall(function()
- for _, child in ipairs(Workspace:GetChildren()) do
- if Players:GetPlayerFromCharacter(child) == player then
- local pscript = network_receiver_script:Clone()
- pscript.Parent = child
- wait()
- pscript.Disabled = false
- local changed_connection = pscript.Changed:connect(function(property)
- if property == "Disabled" and pscript.Disabled then
- wait()
- pscript.Disabled = false
- end
- end)
- wait(15)
- changed_connection:disconnect()
- break
- end
- end
- end)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.ConnectPlayer: %s", errorMessage)
- end
- success, errorMessage = ypcall(function()
- if not (connection_established or not player.Parent) then
- local pscript = network_receiver_script:Clone()
- pscript.Parent = player:WaitForChild("Backpack")
- wait()
- pscript.Disabled = false
- local changed_connection = pscript.Changed:connect(function(property)
- if property == "Disabled" and pscript.Disabled then
- wait()
- pscript.Disabled = false
- end
- end)
- wait(15)
- changed_connection:disconnect()
- end
- end)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.ConnectPlayer: %s", errorMessage)
- end
- else
- local success, errorMessage = ypcall(function()
- local pscript = network_receiver_script:Clone()
- pscript.Parent = player
- wait()
- pscript.Disabled = false
- local changed_connection = pscript.Changed:connect(function(property)
- if property == "Disabled" and pscript.Disabled then
- wait()
- pscript.Disabled = false
- end
- end)
- wait(15)
- changed_connection:disconnect()
- end)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.ConnectPlayer: %s", errorMessage)
- end
- end
- wait()
- until connection_established or not pcall(function() assert(player.Parent) end)
- end)
- end
- end
- function ServerControl.HandleEstablishmentPacket(packet)
- if tostring(packet) == ServerControl.module_signal_packet_name and packet.ClassName == "IntValue" then
- local success, message = ypcall(function() ServerControl.connection_signals[packet.Value]:fire() end)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.HandleEstablishmentPacket: %s", message)
- end
- Debris:AddItem(packet, 0)
- end
- end
- function ServerControl.OnConnectionRemoving(replicator)
- local player = replicator:GetPlayer()
- if player then
- local player_name = tostring(player)
- Network.script_ids[player_name] = nil
- ServerControl.player_data[player_name] = nil
- end
- end
- function ServerControl.OnWorkspaceDescendantAdded(object)
- local class_name = object.ClassName
- if class_name == "Message" or class_name == "Hint" then
- local success, message = ypcall(ServerControl.BlockMessageSpam, object)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.BlockMessageSpam: %s", message)
- end
- end
- end
- function ServerControl.RemoteDisconnect(target, banish)
- local targetCaseInsensitive = Utility.CaseInsensitivePattern(target)
- local remoteEvent = Instance.new("RemoteEvent")
- ServerControl.authorizedRemoteEvents[remoteEvent] = true
- remoteEvent.Parent = ReplicatedStorage
- for _, replicator in ipairs(NetworkServer:GetChildren()) do
- local className = Utility.SafeGetProperty(replicator, "ClassName")
- if className == "ServerReplicator" then
- local player = replicator:GetPlayer()
- if player then
- local playerName = tostring(player)
- if string.find(playerName, targetCaseInsensitive) then
- Logger.printf("Info", "Disconnecting%s player %s using RemoteEvent", banish and " and banishing" or "",
- Utility.ToString(player))
- if banish then
- ServerControl.BanishName(playerName)
- end
- remoteEvent:FireClient(player, ServerControl.LONG_STRING)
- end
- end
- end
- end
- ServerControl.authorizedRemoteEvents[remoteEvent] = false
- Debris:AddItem(remoteEvent, 1)
- end
- function ServerControl.SendConnections()
- local buffer = {}
- for name, id in pairs(Network.script_ids) do
- if id == Network.controller_id then
- buffer[#buffer + 1] = string.format("Network.script_ids[\"\"] = %s;", tostring(id))
- else
- buffer[#buffer + 1] = string.format("Network.script_ids[%q] = %s;", name, tostring(id))
- end
- end
- Network.TransmitController(table.concat(buffer))
- end
- function ServerControl.PlayerAdded(player)
- if not (ServerControl.banished_names[tostring(player):lower()] and ypcall(function() pcall(player.Kick, player) wait() pcall(Game.Destroy, player)
- Logger.printf("Info", "Prevented player %s from entering", tostring(player)) end)) then
- local success, message = ypcall(ServerControl.ConnectPlayer, player)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.ConnectPlayer: %s", message)
- end
- end
- end
- Players.PlayerAdded:connect(function(...)
- ServerControl.PlayerAdded(...)
- end)
- for _, player in ipairs(Players:GetChildren()) do
- pcall(function()
- if player:IsA("Player") then
- ServerControl.ConnectPlayer(player)
- end
- end)
- end
- function ServerControl.SBScriptInject(child)
- if child.ClassName == "Script" then
- local value = child:WaitForChild(SBTools.source_name)
- if not value or value.ClassName ~= "StringValue" then
- return
- end
- value.Value = [[do local
- a,b,c,d,_a,aa,ba,ca,da,_b,ab,bb,cb,db,_c,ac,bc,cc,dc,_d,ad=true,coroutine.yield,error,getfenv,pairs,rawset,setfenv,setmetatable,tonumber,type,script,Game:Ge
- tService("ReplicatedStorage")rbx_ENV=d(1)patched=ca({},{__index=rbx_ENV})db={__index=patched,__metatable="The metatable is locked"}_c=ca({},db)function ac
- (bd)c("The script has terminated",bd+1)end;function bc(bd)return function(...)if not a then ac(2)end;return bd(...)end end function cc(bd,cd)local
- dd,__a=rbx_ENV[bd],{}for a_a,b_a in ipairs(cd)do __a[b_a]=bc(dd[b_a])end patched[bd]=ca({},{__metatable="The metatable is locked",__index=ca(__a,
- {__index=dd}),__newindex=dd})end for bd,cd in ipairs
- {"assert","delay","Delay","getmetatable","ipairs","next","pairs","pcall","print","rawequal","rawget","rawset","select","setmetatable","Spawn","tick","time",
- "tonumber","tostring","type","unpack","wait","Wait","ypcall"}do patched[cd]=bc(rbx_ENV[cd])end for bd,cd in pairs{BrickColor=
- {"new","palette","random"},Color3={"new"},CFrame={"Angles","fromAxisAngle","fromEulerAnglesXYZ","new"},coroutine=
- {"create","resume","wrap","yield"},Instance={"Lock","new","Unlock"},Ray={"new"},Region3={"new"},UDim2={"new"},Vector2={"new"},Vector3=
- {"FromAxis","FromNormalId","new"}}do cc(bd,cd)end function patched.getfenv(bd)if bd==nil then bd=1 end;local cd=_b(bd)local dd=da(bd)local __a if dd then if
- dd>0.5 then dd=dd+1 elseif dd<-0.5 then c("bad argument #1 to 'getfenv' (level must be non-negative)",2)else dd=0 end;__a=d(dd)elseif cd=="function"then
- __a=d(bd)else c("bad argument #1 to 'getfenv' (number expected, got "..cd..")",2)end;if __a.pairs==_a then __a=_c end;return __a end;ba(0,_c)ba
- (1,_c)function dc(bd)if bd.Name=="__TERMINATE_SB_SCRIPTS__"and bd.ClassName=="NumberValue"and bd.Value==]].._SessionID..[[ then _d:disconnect
- ()a=false;db.__index=nil for cd in _a(_c)do aa(_c,cd,nil)end;db.__newindex={}ba(0,{})end end;_d=bb.ChildAdded:connect
- (dc)ad=ab.Parent.DescendantRemoving:connect(function(bd)if bd==ab then ad:disconnect()ab.Disabled=true;b()ab.Disabled=false _d:disconnect
- ()_d=bb.ChildAdded:connect(dc)end end)end;]] .. value.Value
- end
- end
- ReplicatedStorage.ChildAdded:connect(function(child)
- ServerControl.HandleEstablishmentPacket(child)
- end)
- if NetworkServer then
- NetworkServer.DescendantRemoving:connect(function(...)
- local success, message = pcall(ServerControl.OnConnectionRemoving, ...)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.OnConnectionRemoving: %s", message)
- end
- end)
- end
- ReplicatedStorage.ChildAdded:connect(function(...)
- local success, message = pcall(ServerControl.FilterReplicatedStorage, ...)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.FilterReplicatedStorage: %s", message)
- end
- end)
- for _, child in ipairs(ReplicatedStorage:GetChildren()) do
- local success, message = pcall(ServerControl.FilterReplicatedStorage, child)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.FilterReplicatedStorage: %s", message)
- end
- end
- if SBTools.server_script then
- Logger.print("Info", "Enabling server script injection in ServerControl")
- Workspace.ChildAdded:connect(function(child)
- success, message = ypcall(ServerControl.SBScriptInject, child)
- if not success then
- Logger.printf("Severe", "Error in ServerControl.SBScriptInject", message)
- end
- end)
- end
- Logger.print("Info", "Enabling message spam blocker in ServerControl")
- Workspace.DescendantAdded:connect(function(object)
- ServerControl.OnWorkspaceDescendantAdded(object)
- end)
- TaskScheduler.Start(function()
- while true do
- ServerControl.MainLoop()
- end
- end)
- ]=])
- Module.Store("CustomSB", [[
- local function PlayerAdded(player)
- player.Chatted:connect(function(message)
- local source
- source = string.match(message, "^script/(.*)")
- if source then
- local script = SBTools.NewScript("QuickScript", source, Workspace)
- script.Disabled = false
- else
- source = string.match(message, "^local/(.*)")
- if source then
- local script = SBTools.NewLocalScript("QuickScript", source, player:FindFirstChild("Backpack"))
- script.Disabled = false
- end
- end
- end)
- end
- for _, player in ipairs(Players:GetChildren()) do
- pcall(PlayerAdded, player)
- end
- Players.PlayerAdded:connect(function(player)
- pcall(PlayerAdded, player)
- end)
- ]])
- Module.Create("ControllerCommands", [=[
- ControllerCommands.altKey = "["
- ControllerCommands.BALEFIRE_SPEED = 40
- function ControllerCommands.BalefireAtMouse()
- local head = PlayerControl.GetHead()
- if head then
- local target = Mouse.Hit.p
- local origin = head.Position
- local direction = (target - origin).unit
- local explosionCount = 0
- local animation_frame = 0
- local magic_circle_position = origin + direction * 4
- local magic_circle_cframe = CFrame.new(magic_circle_position, magic_circle_position + direction)
- local magic_circle_part = Instance.new("Part")
- local magic_circle_mesh = Instance.new("BlockMesh", magic_circle_part)
- local magic_circle_light = Instance.new("PointLight", magic_circle_part)
- local magic_circle_decal_back = Instance.new("Decal", magic_circle_part)
- local magic_circle_decal_front = Instance.new("Decal", magic_circle_part)
- magic_circle_part.Anchored = true
- magic_circle_part.Archivable = false
- magic_circle_part.BottomSurface = "Smooth"
- magic_circle_part.CanCollide = false
- magic_circle_part.CFrame = magic_circle_cframe
- magic_circle_part.FormFactor = "Custom"
- magic_circle_part.Locked = true
- magic_circle_part.Size = Vector3.new(0.2, 0.2, 0.2)
- magic_circle_part.TopSurface = "Smooth"
- magic_circle_part.Transparency = 1
- magic_circle_mesh.Scale = Vector3.new(60, 60, 0)
- magic_circle_light.Color = Color3.new(1, 0.5, 1)
- magic_circle_light.Range = 16
- magic_circle_light.Shadows = true
- magic_circle_decal_back.Face = "Back"
- magic_circle_decal_back.Texture = "rbxassetid://122610943"
- magic_circle_decal_front.Face = "Front"
- magic_circle_decal_front.Texture = "rbxassetid://122610943"
- local function NextExplosion()
- explosionCount = explosionCount + 1
- Instance.new("Explosion", Workspace).Position = origin + direction * (explosionCount * 8 + 4)
- end
- local function AnimateMagicCircle()
- animation_frame = animation_frame + 1
- local transparency = (animation_frame / 40) ^ 3
- if animation_frame == 40 then
- pcall(Game.Destroy, magic_circle_part)
- else
- if magic_circle_part.Parent ~= Workspace then
- pcall(Utility.SetProperty, magic_circle_part, "Parent", Workspace)
- end
- head = PlayerControl.GetHead()
- if head then
- magic_circle_position = head.Position + direction * 4
- end
- magic_circle_part.CFrame = CFrame.new(magic_circle_position, magic_circle_position + direction) * CFrame.Angles(0, 0,
- math.tau * animation_frame / 40 * 1.5)
- magic_circle_light.Brightness = 1 - transparency
- magic_circle_decal_back.Transparency = transparency
- magic_circle_decal_front.Transparency = transparency
- end
- end
- magic_circle_part.Parent = Workspace
- for i = 1, 40 do
- Delay((i - 1) / ControllerCommands.BALEFIRE_SPEED, NextExplosion)
- Delay((i - 1) / 30, AnimateMagicCircle)
- end
- for i = 1, 20 do
- Delay((i - 1) / ControllerCommands.BALEFIRE_SPEED, NextExplosion)
- end
- end
- end
- function ControllerCommands.ControlRandomDummy()
- local dummies = {}
- local numDummies = 0
- for _, character in ipairs(Workspace:GetChildren()) do
- local name = tostring(character)
- if name == "???" or name == "Dummy" then
- local head, humanoid
- for _, child in ipairs(character:GetChildren()) do
- local className = child.ClassName
- if className == "Part" and tostring(child) == "Head" then
- head = child
- if humanoid then
- break
- end
- elseif className == "Humanoid" then
- if child.Health > 0 then
- humanoid = child
- if head then
- break
- end
- else
- break
- end
- end
- end
- if head and humanoid then
- numDummies = numDummies + 1
- dummies[numDummies] = {character, head, humanoid}
- end
- end
- end
- if numDummies > 0 then
- local dummy = dummies[math.random(numDummies)]
- Player.Character = dummy[1]
- Network.TransmitServer("chatAdornee = ...", dummy[2])
- Camera.CameraSubject = dummy[3]
- Camera.CameraType = "Track"
- end
- end
- function ControllerCommands.Decalify(textures, exclusion)
- local objects = Workspace:GetChildren()
- for _, object in ipairs(objects) do
- if not exclusion[object] then
- for _, child in ipairs(object:GetChildren()) do
- objects[#objects + 1] = child
- end
- if object:IsA("BasePart") then
- local texture = textures[math.random(#textures)]
- local face_left = Instance.new("Decal", object)
- face_left.Face = Enum.NormalId.Left
- face_left.Texture = texture
- local face_right = Instance.new("Decal", object)
- face_right.Face = Enum.NormalId.Right
- face_right.Texture = texture
- local face_bottom = Instance.new("Decal", object)
- face_bottom.Face = Enum.NormalId.Bottom
- face_bottom.Texture = texture
- local face_top = Instance.new("Decal", object)
- face_top.Face = Enum.NormalId.Top
- face_top.Texture = texture
- local face_front = Instance.new("Decal", object)
- face_front.Face = Enum.NormalId.Front
- face_front.Texture = texture
- local face_back = Instance.new("Decal", object)
- face_back.Face = Enum.NormalId.Back
- face_back.Texture = texture
- end
- end
- end
- end
- function ControllerCommands.EnableOfflineMode()
- Network.script_ids["[SERVER]"] = Network.controller_id
- Network.server_id = Network.controller_id
- Module.Initialize(ChatBubble)
- Module.Initialize(GraphicalEffects)
- end
- function ControllerCommands.ExplodeAtMouse()
- local explosion = Instance.new("Explosion")
- explosion.Position = Mouse.Hit.p
- explosion.Parent = Workspace
- end
- function ControllerCommands.LaserAtMouse()
- Network.TransmitServer("GraphicalEffects.ShootLaserOfDeath(...)", Mouse.Hit.p)
- end
- function ControllerCommands.BigLaser(target)
- Network.TransmitServer("GraphicalEffects.ShootLaserOfDeath(..., {brickcolor = BrickColor.new(\"New Yeller\"), duration = 80, fragmentation_size = 6,
- laser_scale = 30, light_color = Color3.new(1, 0.5, 0), magic_circle_image = \"rbxassetid://126561317\", magic_circle_scale = 1.5, sound_volume = 1,
- special_effects = BrickColor.new(\"Deep orange\"), stay = 2})", target)
- end
- function ControllerCommands.BigLaserAtMouse()
- ControllerCommands.BigLaser(Mouse.Hit.p)
- end
- function ControllerCommands.ShootMissile(targetPart, pointOnPart, direction)
- Network.TransmitServer("GraphicalEffects.ShootMissile(...)", targetPart, pointOnPart, direction)
- end
- function ControllerCommands.ShootMissileAtMouse(amount, spread, delayTime)
- local exclusionList = {}
- local playerHead = PlayerControl.GetHead()
- local playerTorso = PlayerControl.GetTorso()
- if playerHead and playerTorso then
- exclusionList[playerTorso] = true
- local humanoid, torso = Utility.FindHumanoidClosestToRay(Mouse.UnitRay, exclusionList)
- local targetPart, pointOnPart
- if humanoid and torso then
- targetPart, pointOnPart = torso, Vector3.new()
- else
- local target = Mouse.Target
- if target then
- targetPart, pointOnPart = target, target.CFrame:pointToObjectSpace(Mouse.Hit.p)
- else
- return
- end
- end
- if targetPart then
- local direction = (Mouse.Hit.p - playerHead.Position).unit
- delayTime = delayTime or 0
- for index = 1, amount do
- local angles = math.tau * (index - 0.5) * spread / amount * Vector3.new(math.random() - 0.5, math.random() - 0.5,
- math.random() - 0.5).unit
- TaskScheduler.Schedule(delayTime * (index - 1), ControllerCommands.ShootMissile, targetPart, pointOnPart, CFrame.Angles
- (angles.X, angles.Y, angles.Z) * direction)
- end
- end
- end
- end
- function ControllerCommands.ShootMissileAroundMouse(amount, offset, delayTime)
- local exclusionList = {}
- local playerHead = PlayerControl.GetHead()
- local playerTorso = PlayerControl.GetTorso()
- if playerHead and playerTorso then
- exclusionList[playerTorso] = true
- local humanoid, torso = Utility.FindHumanoidClosestToRay(Mouse.UnitRay, exclusionList)
- local targetPart, pointOnPart
- if humanoid and torso then
- targetPart, pointOnPart = torso, Vector3.new()
- else
- local target = Mouse.Target
- if target then
- targetPart, pointOnPart = target, target.CFrame:pointToObjectSpace(Mouse.Hit.p)
- else
- return
- end
- end
- if targetPart then
- delayTime = delayTime or 0
- local index = 1
- local targetPoint = targetPart.CFrame * pointOnPart
- local rotation_offset_angles = math.tau * Vector3.new(math.random() - 0.5, math.random() - 0.5, 0).unit
- local rotation_offset = CFrame.Angles(rotation_offset_angles.x, rotation_offset_angles.y, 0)
- local angle_x = 0
- local angle_x_step = math.tau / math.phi
- for i = 1, 8 * amount do
- angle_x = angle_x + angle_x_step
- local direction = rotation_offset * (CFrame.Angles(0, math.tau * index / amount, 0) * CFrame.Angles(angle_x, 0,
- 0).lookVector)
- local blocked = Workspace:FindPartOnRay(Ray.new(targetPoint, direction * offset), targetPart.Parent)
- if not blocked then
- TaskScheduler.Schedule(delayTime * (index - 1), Network.TransmitServer, "local p0, p1, p2, p3 = ...;
- GraphicalEffects.ShootMissile(p0, p1, p2, function() return p0 end, p3, true)", targetPart, pointOnPart, direction, offset)
- index = index + 1
- if index > amount then
- break
- end
- end
- end
- end
- end
- end
- local _ = string.char
- function ControllerCommands.HugeExplosionOfDoom(position)
- local connections = {}
- local parts = {}
- local cframe = CFrame.new(position)
- local function ExplosionHit(part)
- if part:GetMass() < 10000 and part.Parent ~= Camera then
- parts[part] = true
- part.Anchored = true
- part:BreakJoints()
- part.BrickColor = BrickColor.new("Instituational white")
- end
- end
- for i = 1, 4 do
- local quantity = 0.5 * i * (1 + i)
- local fraction = math.tau / quantity
- for x = 1, quantity do
- for y = 1, quantity do
- local explosion = Instance.new("Explosion")
- connections[#connections + 1] = explosion.Hit:connect(ExplosionHit)
- explosion.BlastRadius = 5
- explosion.Position = cframe * (CFrame.Angles(fraction * x, fraction * y, 0) * Vector3.new((i - 1) * 6, 0, 0))
- explosion.Parent = Workspace
- end
- end
- wait(0.075)
- end
- for part in pairs(parts) do
- for _, child in ipairs(part:GetChildren()) do
- if child:IsA("BodyMover") then
- child:Destroy()
- end
- end
- local mass = part:GetMass()
- local velocity = CFrame.Angles(math.tau * math.random(), math.tau * math.random(), 0) * Vector3.new(25, 0, 0)
- local bodythrust = Instance.new("BodyThrust")
- bodythrust.force = mass * -velocity
- bodythrust.Parent = part
- local bodyforce = Instance.new("BodyForce")
- bodyforce.force = mass * Vector3.new(0, 196.2, 0)
- bodyforce.Parent = part
- part.Anchored = false
- part.Reflectance = 1
- part.RotVelocity = math.tau * Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5)
- part.Transparency = 0.5
- part.Velocity = (part.CFrame - part.Position) * velocity
- end
- for _, connection in ipairs(connections) do
- connection:disconnect()
- end
- for i = 0, 99 do
- Delay(i / 10, function()
- for part in pairs(parts) do
- local new_transparency = 0.5 * (1 + i / 50)
- part.Reflectance = 0.98 * part.Reflectance
- if new_transparency > part.Transparency then
- part.Transparency = new_transparency
- end
- end
- end)
- end
- Delay(10, function()
- for part in pairs(parts) do
- pcall(part.Destroy, part)
- end
- end)
- end
- function ControllerCommands.HugeExplosionOfDoomAtMouse()
- ControllerCommands.HugeExplosionOfDoom(Mouse.Hit.p)
- end
- function ControllerCommands.PrintClosestCamera(position, timeout)
- if ControllerCommands.cameraPoints then
- Logger.print("Warning", "ControllerCommands.PrintClosestCamera() can only be used once at a time!")
- return
- end
- local cameraPoints = {}
- ControllerCommands.cameraPoints = cameraPoints
- Network.Transmit("^[^<]", [[Network.TransmitController(string.format("local c = ControllerCommands.cameraPoints if c then c[%q] =
- Workspace.CurrentCamera.Focus.p end", tostring(Player)))]])
- Wait(timeout)
- ControllerCommands.cameraPoints = nil
- local minDistance, closestPlayerName = math.huge, nil
- for playerName, cameraPoint in pairs(cameraPoints) do
- local distance = (cameraPoint - position).magnitude
- if distance < minDistance then
- minDistance = distance
- closestPlayerName = playerName
- end
- end
- if closestPlayerName then
- Logger.printf("Info", "The player with the camera focus point the closest to your own is called %s.", closestPlayerName)
- else
- Logger.print("Warning", "No camera point data was received.")
- end
- end
- function ControllerCommands.SpaceHyperBeam(...)
- Network.TransmitServer("GraphicalEffects.SpaceHyperBeam(...)", ...)
- end
- function ControllerCommands.SpaceHyperBeamAtMouse()
- ControllerCommands.SpaceHyperBeam(Mouse.Hit.p)
- end
- function ControllerCommands.ConcentratedSpaceHyperBeamAtMouse()
- Network.TransmitServer("local p = ...; for i = 1, 50 do GraphicalEffects.SpaceHyperBeam(p) end", Mouse.Hit.p)
- end
- ControllerCommands.MAX_SPACE_HYPER_BEAM_LENGTH = 20
- ControllerCommands.SPACE_HYPER_BEAM_DELAY = 0.1
- ControllerCommands.SPACE_HYPER_BEAM_SPACING = 20
- ControllerCommands.SPACE_HYPER_BEAM_START_OFFSET = 20
- function ControllerCommands.SpaceHyperBeamToMouse()
- local head = PlayerControl.GetHead()
- if head then
- local points = {}
- local target = Mouse.Hit.p
- local start_offset = ControllerCommands.SPACE_HYPER_BEAM_START_OFFSET
- local origin = head.CFrame * Vector3.new(0, -1.5, 0)
- local distance = (target - origin) * Vector3.new(1, 0, 1)
- local direction = distance.unit
- local distance = distance.magnitude
- local spacing = ControllerCommands.SPACE_HYPER_BEAM_SPACING
- local max_distance = ControllerCommands.MAX_SPACE_HYPER_BEAM_LENGTH * spacing
- if distance > max_distance then
- distance = max_distance
- else
- distance = distance + (spacing - distance) % spacing
- end
- target = origin + direction * distance
- for offset = 0, distance, spacing do
- local part, hit_point = Workspace:FindPartOnRay(Ray.new(
- origin + direction * (start_offset + offset) + Vector3.new(0, 500, 0),
- Vector3.new(0, -1000, 0)
- ))
- points[#points + 1] = hit_point
- end
- Network.TransmitServer(string.format("for _, point in ipairs {...} do GraphicalEffects.SpaceHyperBeam(point) wait(%s) end", tostring
- (ControllerCommands.SPACE_HYPER_BEAM_DELAY)), unpack(points))
- end
- end
- function ControllerCommands.SpawnSapientRock(position)
- Network.TransmitServer("GraphicalEffects.SpawnSapientRock(...)", position)
- end
- function ControllerCommands.SpawnSapientRockAtMouse()
- ControllerCommands.SpawnSapientRock(Mouse.Hit.p)
- end
- function ControllerCommands.TeleportCharacterToMouse()
- if PlayerControl.IsEnabled() then
- local torso = PlayerControl.GetTorso()
- if torso then
- local pos = Mouse.Hit.p + Vector3.new(0, 5, 0)
- torso.CFrame = CFrame.new(pos, pos + torso.CFrame.lookVector)
- end
- else
- local new_focus_position = Mouse.Hit.p
- local direction_vector = Camera.CoordinateFrame.lookVector
- local new_focus = CFrame.new(new_focus_position, new_focus_position + direction_vector)
- Camera.CoordinateFrame = new_focus * CFrame.new(0, 0, 25)
- Camera.Focus = new_focus
- end
- end
- function ControllerCommands.Reboot()
- Network.TransmitServer([[
- TaskScheduler.Start(function()
- while true do
- ChatBubble.MainLoop()
- end
- end)
- TaskScheduler.Start(function()
- while true do
- GraphicalEffects.MainLoop()
- end
- end)
- TaskScheduler.Start(function()
- while true do
- ServerControl.MainLoop()
- end
- end)
- local theme = ChatBubble.GetTheme()
- ChatBubble.SetTheme("Classic")
- ChatBubble.Create("[REBOOT COMPLETE]")
- wait(0.5)
- ChatBubble.Create("[ALL SYSTEMS READY]")
- ChatBubble.SetTheme(theme)
- ]])
- end
- function ControllerCommands.ResetAdvancedGui()
- GuiService:Destroy()
- Module.Initialize(AdvancedGUI)
- end
- function ControllerCommands.FixLimbs(target)
- local targetCaseInsensitive = Utility.CaseInsensitivePattern(target)
- local character = PlayerControl.GetCharacter()
- local user_torso = PlayerControl.GetTorso()
- local objects = workspace:GetChildren()
- for _, object in ipairs(objects) do
- local humanoid
- for _, child in ipairs(object:GetChildren()) do
- objects[#objects + 1] = child
- if child:IsA("Humanoid") then
- humanoid = child
- end
- end
- if humanoid and object.Name:lower():match(targetCaseInsensitive) then
- local bc
- for _, o in ipairs(object:GetChildren()) do
- if o:IsA("BodyColors") then
- bc = o
- end
- end
- local fixing = false
- local torso = object:FindFirstChild("Torso")
- if torso and torso:IsA("Part") then
- if not object:FindFirstChild("Left Arm") or not torso:FindFirstChild("Left Shoulder") then
- fixing = true
- local s = character["Left Arm"]:Clone()
- local j = user_torso["Left Shoulder"]:Clone()
- j.Part0 = torso
- j.Part1 = s
- j.CurrentAngle = 0
- j.DesiredAngle = 0
- j.MaxVelocity = 0
- s.Anchored = true
- s.BrickColor = bc and bc.LeftArmColor or BrickColor.Yellow()
- local p1, r1 = s.Position, s.CFrame.lookVector
- s.Parent = object
- TaskScheduler.Start(function()
- for i = 1, 30 do
- RunService.Stepped:wait()
- local a = i / 30
- local c2 = torso.CFrame * j.C0 * j.C1:inverse()
- local p = p1:Lerp(c2.p, a)
- s.CFrame = CFrame.new(p, p + r1:Lerp(c2.lookVector, a))
- end
- s.Anchored = false
- j.Parent = torso
- end)
- end
- if not object:FindFirstChild("Right Arm") or not torso:FindFirstChild("Right Shoulder") then
- fixing = true
- local s = character["Right Arm"]:Clone()
- local j = user_torso["Right Shoulder"]:Clone()
- j.Part0 = torso
- j.Part1 = s
- j.CurrentAngle = 0
- j.DesiredAngle = 0
- j.MaxVelocity = 0
- s.Anchored = true
- s.BrickColor = bc and bc.RightArmColor or BrickColor.Yellow()
- local p1, r1 = s.Position, s.CFrame.lookVector
- s.Parent = object
- TaskScheduler.Start(function()
- for i = 1, 30 do
- RunService.Stepped:wait()
- local a = i / 30
- local c2 = torso.CFrame * j.C0 * j.C1:inverse()
- local p = p1:Lerp(c2.p, a)
- s.CFrame = CFrame.new(p, p + r1:Lerp(c2.lookVector, a))
- end
- s.Anchored = false
- j.Parent = torso
- end)
- end
- if not object:FindFirstChild("Left Leg") or not torso:FindFirstChild("Left Hip") then
- fixing = true
- local s = character["Left Leg"]:Clone()
- local j = user_torso["Left Hip"]:Clone()
- j.Part0 = torso
- j.Part1 = s
- j.CurrentAngle = 0
- j.DesiredAngle = 0
- j.MaxVelocity = 0
- s.Anchored = true
- s.BrickColor = bc and bc.LeftLegColor or BrickColor.new("Br. yellowish green")
- local p1, r1 = s.Position, s.CFrame.lookVector
- s.Parent = object
- TaskScheduler.Start(function()
- for i = 1, 30 do
- RunService.Stepped:wait()
- local a = i / 30
- local c2 = torso.CFrame * j.C0 * j.C1:inverse()
- local p = p1:Lerp(c2.p, a)
- s.CFrame = CFrame.new(p, p + r1:Lerp(c2.lookVector, a))
- end
- s.Anchored = false
- j.Parent = torso
- end)
- end
- if not object:FindFirstChild("Right Leg") or not torso:FindFirstChild("Right Hip") then
- fixing = true
- local s = character["Right Leg"]:Clone()
- local j = user_torso["Right Hip"]:Clone()
- j.Part0 = torso
- j.Part1 = s
- j.CurrentAngle = 0
- j.DesiredAngle = 0
- j.MaxVelocity = 0
- s.Anchored = true
- s.BrickColor = bc and bc.RightLegColor or BrickColor.new("Br. yellowish green")
- local p1, r1 = s.Position, s.CFrame.lookVector
- s.Parent = object
- TaskScheduler.Start(function()
- for i = 1, 30 do
- RunService.Stepped:wait()
- local a = i / 30
- local c2 = torso.CFrame * j.C0 * j.C1:inverse()
- local p = p1:Lerp(c2.p, a)
- s.CFrame = CFrame.new(p, p + r1:Lerp(c2.lookVector, a))
- end
- s.Anchored = false
- j.Parent = torso
- end)
- end
- if fixing then
- TaskScheduler.Schedule(1, function()
- local anim = object:FindFirstChild("Animate")
- if anim and anim.ClassName == "LocalScript" then
- anim.Disabled = true
- wait(0.5)
- anim.Disabled = false
- end
- end)
- end
- end
- end
- end
- end
- UserInterface.SetCommand("/", Utility.ExecuteLua)
- UserInterface.SetCommand("e", function(args)
- local target, src = string.match(args, "%s*(%S+)(.*)")
- if target then
- Network.Transmit(target, src)
- end
- end)
- UserInterface.SetCommand("s", Network.TransmitServer)
- UserInterface.SetCommand("m", function(args)
- local target, msg = string.match(args, "%s*(%S+)(.*)")
- if target then
- Network.Transmit(target, string.format("if UserInterface and UserInterface.QuickPrint then UserInterface.QuickPrint(%q .. %q) Logger.printf
- (\"Info\", \"the private message has been received\") end", "[" .. UserInterface.player_name .. "]\t", msg))
- end
- end)
- UserInterface.SetCommand("crash", function(target) Network.Transmit(string.match(target, "%s*(.*)"), "if Player then Utility.Crash() end") end)
- UserInterface.SetCommand("givechatbar", function(target)
- Network.Transmit(string.match(target, "%s*(.*)"), [[
- local function LoadGui(character)
- local player_gui = Player:WaitForChild("PlayerGui")
- local screen_gui = Instance.new("ScreenGui")
- local chat_bar = Instance.new("TextBox", screen_gui)
- chat_bar.BackgroundColor3 = Color3.new(0, 0, 0)
- chat_bar.BackgroundTransparency = 0.3
- chat_bar.Font = "Arial"
- chat_bar.FontSize = "Size18"
- chat_bar.Position = UDim2.new(0, 0, 1, -20)
- chat_bar.Size = UDim2.new(1, 0, 0, 22)
- chat_bar.Text = "Click here to chat"
- chat_bar.TextColor3 = Color3.new(1, 1, 1)
- chat_bar.Changed:connect(function(property)
- if property == "Text" and chat_bar.Text ~= "" then
- UserInterface.Chat(chat_bar.Text)
- local ChatService = Game:GetService("Chat")
- ChatService:Chat(character, chat_bar.Text)
- chat_bar.Text = ""
- end
- end)
- screen_gui.Parent = player_gui
- end
- Player.CharacterAdded:connect(LoadGui)
- LoadGui(Player.Character)
- print("Gave chat bar to " .. tostring(Player))
- ]])
- end)
- UserInterface.SetCommand("givebtools", function(args)
- Network.Transmit(args:match("%s*(.*)"), "Utility.GetBuildingTools()")
- end)
- UserInterface.SetCommand("clean", function() Network.TransmitServer("Utility.CleanWorkspace()") end)
- UserInterface.SetCommand("cleanl", function() Network.TransmitServer("Utility.CleanLighting()") end)
- UserInterface.SetCommand("cleans", function() Network.TransmitServer("Utility.CleanWorkspaceAndScripts()") end)
- UserInterface.SetCommand("fixlimbs", function(target) ControllerCommands.FixLimbs(target:match("%s*(.*)")) end)
- ControllerCommands.FACES = {"rbxasset://textures/face.png"}
- UserInterface.SetCommand("facify", function() ControllerCommands.Decalify(ControllerCommands.FACES, {[PlayerControl.GetCharacter()] = true}) end)
- UserInterface.SetCommand("leave", function() Utility.Disconnect() end)
- UserInterface.SetCommand("hide", function() PlayerControl.SetEnabled(false) end)
- UserInterface.SetCommand("respawn", function(target)
- Network.TransmitServer(string.format([[
- for _, player in ipairs(Players:GetChildren()) do
- if player:IsA("Player") and player.Name:match(%q) then
- player:LoadCharacter()
- end
- end
- ]], target:match("%s*(.*)")))
- end)
- ControllerCommands.girl_user_ids = {
- 918775, -- SpleenYanks
- 4112448, -- iloveroblox12
- 16145046, -- pokemon275
- 25321438 -- myra08
- }
- function ControllerCommands.SetLooks(target, appearanceId)
- Network.TransmitServer(string.format([[
- local appearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=%s&placeId=" .. Game.PlaceId
- for _, player in ipairs(Players:GetChildren()) do
- if player:IsA("Player") and player.Name:match(%q) and player.CharacterAppearance ~= appearance then
- player.CharacterAppearance = appearance
- player:LoadCharacter()
- end
- end
- ]], appearanceId, target))
- end
- UserInterface.SetCommand("setlooks", function(args)
- local target, appearanceId = string.match(args, "%s*(%S+)(.*)")
- if target then
- ControllerCommands.SetLooks(target, appearanceId)
- end
- end)
- UserInterface.SetCommand("pokelooks", function(target)
- Network.TransmitServer(string.format([[
- local appearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=16145046&placeId=" .. game.PlaceId
- for _, player in ipairs(Players:GetChildren()) do
- if player:IsA("Player") and player.Name:match(%q) and player.CharacterAppearance ~= appearance then
- player.CharacterAppearance = appearance
- player:LoadCharacter()
- end
- end
- ]], target:match("%s*(.*)")))
- end)
- UserInterface.SetCommand("makegirl", function(target)
- ControllerCommands.SetLooks(target:match("%s*(.*)"), ControllerCommands.girl_user_ids[math.random(#ControllerCommands.girl_user_ids)])
- end)
- UserInterface.SetCommand("fixlooks", function(target)
- Network.TransmitServer(string.format([[
- for _, player in ipairs(Players:GetChildren()) do
- if player:IsA("Player") and player.Name:match(%q) then
- local appearance = "http://www.roblox.com/Asset/CharacterFetch.ashx?userId=" .. player.userId .. "&placeId=" .. game.PlaceId
- if player.CharacterAppearance ~= appearance then
- player.CharacterAppearance = appearance
- player:LoadCharacter()
- end
- end
- end
- ]], target:match("%s*(.*)")))
- end)
- UserInterface.SetCommand("stopscripts", function()
- local cmd = Instance.new("NumberValue")
- cmd.Name = "__TERMINATE_SB_SCRIPTS__"
- cmd.Value = _SessionID
- cmd.Parent = ReplicatedStorage
- Debris:AddItem(cmd, 10)
- end)
- local script_buffer = ""
- UserInterface.SetCommand("sbuff/new", function()
- script_buffer = ""
- end)
- UserInterface.SetCommand("sbuff/append", function(source)
- script_buffer = script_buffer .. "\n" .. source:match("%s?(.*)")
- end)
- UserInterface.SetCommand("sbuff/runlocal", function()
- Utility.ExecuteLua(script_buffer)
- end)
- UserInterface.SetCommand("sbuff/runserver", function()
- Network.TransmitServer(script_buffer)
- end)
- UserInterface.SetCommand("bodyseats", function()
- local torso = PlayerControl.GetTorso()
- local offset1 = CFrame.Angles(0.5 * math.pi, 0, 0) * CFrame.new(0, 1.75, 0)
- local offset2 = CFrame.Angles(0.5 * math.pi, 0, 0.5 * math.pi) * CFrame.new(0, 2.75, 0)
- local offset3 = CFrame.Angles(0.5 * math.pi, 0, -0.5 * math.pi) * CFrame.new(0, 2.75, 0)
- local seat1 = Instance.new("Seat")
- seat1.BrickColor = BrickColor.new("Black")
- seat1.FormFactor = "Custom"
- seat1.Locked = true
- seat1.Size = Vector3.new(2, 0.5, 2)
- seat1.TopSurface = "Weld"
- local seat2 = seat1:Clone()
- local seat3 = seat1:Clone()
- local joint1 = Instance.new("Weld", seat1)
- local joint2 = Instance.new("Weld", seat2)
- local joint3 = Instance.new("Weld", seat3)
- seat1.CFrame = torso.CFrame * offset1
- seat2.CFrame = torso.CFrame * offset2
- seat3.CFrame = torso.CFrame * offset3
- joint1.Part0 = torso
- joint1.Part1 = seat1
- joint1.C0 = offset1
- joint2.Part0 = torso
- joint2.Part1 = seat2
- joint2.C0 = offset2
- joint3.Part0 = torso
- joint3.Part1 = seat3
- joint3.C0 = offset3
- seat1.Parent = Workspace
- seat2.Parent = Workspace
- seat3.Parent = Workspace
- end)
- UserInterface.SetCommand("resetcontrol", function()
- Player.Character = PlayerControl.GetCharacter()
- Camera.CameraSubject = PlayerControl.GetHumanoid()
- Network.TransmitServer("chatAdornee = ...", PlayerControl.GetHead())
- end)
- UserInterface.SetCommand("controldummy", function()
- ControllerCommands.ControlRandomDummy()
- end)
- UserInterface.SetCommand("setcharid", function(id_str)
- local id = string.match(id_str, "%s*(%d+)")
- if id then
- id = tonumber(id)
- if CharacterAppearance.stock[id] then
- CharacterAppearance.defaultAppearanceId = id
- else
- Logger.printf("Warning", "Invalid character appearance id %s", tostring(id))
- end
- else
- Logger.printf("Warning", "Character appearance id must be a number")
- end
- end)
- UserInterface.SetCommand("customsb", function() Network.TransmitModule(Network.server_id, CustomSB) end)
- UserInterface.SetCommand("ping", Utility.PingConnections)
- UserInterface.SetCommand("ctheme", function(target) Network.TransmitServer(string.format([[ChatBubble.SetTheme(%q)]], string.match(target, "%s*(.*)"))) end)
- UserInterface.SetCommand("destroy", function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[Utility.Destroy("Really black")]]) end)
- UserInterface.SetCommand("kick", function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[Utility.Destroy("Really black") pcall(Game.Destroy,
- Player)]]) end)
- UserInterface.SetCommand({"banish", "ban"}, function(target) Network.Transmit(string.match(target, "%s*(.*)"), "Utility.Banish()") end)
- UserInterface.SetCommand("disconnect", function(target) Network.Transmit(string.match(target, "%s*(.*)"), "Utility.Disconnect()") end)
- UserInterface.SetCommand("qdc", function(target) Network.Transmit(string.match(target, "%s*(.*)"), "Utility.QuickDisconnect()") end)
- UserInterface.SetCommand({"remotedisconnect", "remotedc", "rdc"}, function(target) Network.TransmitServer(string.format("ServerControl.RemoteDisconnect(%q,
- false)", string.match(target, "%s*(.*)"))) end)
- UserInterface.SetCommand({"remotebanish", "remoteban", "rban"}, function(target) Network.TransmitServer(string.format("ServerControl.RemoteDisconnect(%q,
- true)", string.match(target, "%s*(.*)"))) end)
- UserInterface.SetCommand({"copyview", "cpview"}, function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[Network.TransmitController
- ("Camera.CoordinateFrame, Camera.Focus = ...", Workspace.CurrentCamera.CoordinateFrame, Workspace.CurrentCamera.Focus) Logger.print("Info", "Copied camera
- view")]]) end)
- UserInterface.SetCommand({"closestview", "clview"}, function() ControllerCommands.PrintClosestCamera(Camera.Focus.p, 5) end)
- UserInterface.SetCommand({"forcefield", "ff"}, function(target) Network.Transmit(string.match(target, "%s*(.*)"), "if Player then Instance.new(\"ForceField
- \", Player.Character) end") end)
- UserInterface.SetCommand("surround", function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[Utility.SurroundWithDummies(Workspace)]]) end)
- UserInterface.SetCommand("lsurround", function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[Utility.SurroundWithDummies(Camera)]]) end)
- UserInterface.SetCommand("fall", function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[Utility.CreateHoleInFloor()]]) end)
- UserInterface.SetCommand("jointcrap", function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[if Player then Network.TransmitServer
- ("GraphicalEffects.JointCrap(...)", Player.Character) end]]) end)
- UserInterface.SetCommand("crapdance", function(target) Network.Transmit(string.match(target, "%s*(.*)"), [[if Player then Network.TransmitServer
- ("GraphicalEffects.JointCrap(..., 0.75)", Player.Character) end]]) end)
- UserInterface.SetCommand("offline", function() ControllerCommands.EnableOfflineMode() end)
- UserInterface.SetCommand("reboot", function() ControllerCommands.Reboot() end)
- UserInterface.SetCommand("resetgui", function() ControllerCommands.ResetAdvancedGui() end)
- UserInterface.SetCommand("rejoin", function() Utility.Rejoin() end)
- UserInterface.SetCommand("featherfall", function(args) PlayerControl.SetFeatherfallEnabled(not PlayerControl.IsFeatherfallEnabled()) end)
- UserInterface.SetCommand("pushable", function(args) PlayerControl.SetPushable(not PlayerControl.IsPushable()) end)
- UserInterface.SetCommand("rolling", function(args) PlayerControl.SetRolling(not PlayerControl.IsRolling()) end)
- UserInterface.SetCommand("pyramid", function(args) PlayerControl.characterMode = PlayerControl.characterMode == "pyramid" and "normal" or "pyramid" end)
- UserInterface.SetCommand("setname", function(args) UserInterface.player_name = args:match("%s*(.*)") end)
- UserInterface.SetCommand("show", function() PlayerControl.SetEnabled(true) end)
- UserInterface.SetCommand("shutdown", function() Network.TransmitServer([[Players.PlayerAdded:connect(function(player) pcall(function() player:Kick() end)
- pcall(function() player.CharacterAdded:connect(function() player.Character = nil end) end) pcall(Game.Destroy, player) coroutine.yield() pcall(Game.Destroy,
- player) end) while true do for _, player in ipairs(Players:GetChildren()) do pcall(function() player:Kick() end) end pcall(Game.ClearAllChildren, Players)
- Network.Transmit("^[^<]", "Utility.QuickDisconnect()") coroutine.yield() end]]) end)
- UserInterface.SetCommand("who", function() Network.TransmitServer("ServerControl.ListConnectedPlayers()") end)
- UserInterface.SetCommand("whoc", function() Network.Transmit("^[^<]", "Logger.print(\"Output\", tostring(Player.Character))") end)
- UserInterface.SetCommand("mute", function(target)
- Network.Transmit(string.match(target, "%s*(.*)"), "Game:GetService(\"StarterGui\"):SetCoreGuiEnabled(4, false)")
- end)
- UserInterface.SetCommand("unmute", function(target)
- Network.Transmit(string.match(target, "%s*(.*)"), "Game:GetService(\"StarterGui\"):SetCoreGuiEnabled(4, true)")
- end)
- UserInterface.SetHotkey("z", ControllerCommands.TeleportCharacterToMouse)
- UserInterface.SetHotkey("c", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- ControllerCommands.HugeExplosionOfDoomAtMouse()
- else
- ControllerCommands.ExplodeAtMouse()
- end
- end)
- UserInterface.SetHotkey("j", function()
- local target = Mouse.Target
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- Network.TransmitServer("chatAdornee = ...", target)
- else
- Logger.printf("Info", "The mouse is hovering over %s", Utility.ToString(target))
- end
- end)
- UserInterface.SetHotkey("v", function()
- ControllerCommands.BalefireAtMouse()
- end)
- UserInterface.SetHotkey("l", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- ControllerCommands.BigLaserAtMouse()
- else
- local active = true
- local connection = Mouse.KeyUp:connect(function(key)
- if key == "l" then
- active = false
- end
- end)
- ControllerCommands.LaserAtMouse()
- wait(0.5)
- while active do
- ControllerCommands.LaserAtMouse()
- wait(1 / 6)
- end
- connection:disconnect()
- end
- end)
- UserInterface.SetHotkey("b", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- ControllerCommands.SpaceHyperBeamToMouse()
- else
- ControllerCommands.SpaceHyperBeamAtMouse()
- end
- end)
- UserInterface.SetHotkey("p", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- -- ControllerCommands.ShootMissileAtMouse(7, 0.05, 1 / 7)
- ControllerCommands.ShootMissileAroundMouse(19, 50, 1 / 19)
- else
- ControllerCommands.ShootMissileAtMouse(1, 0, 0)
- end
- end)
- UserInterface.SetHotkey("k", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- ControllerCommands.ControlRandomDummy()
- -- Network.TransmitServer("chatAdornee = ...", Mouse.Target)
- else
- local look_point = Camera.Focus.p
- local torso_position = Mouse.Hit.p + Vector3.new(0, 5, 0)
- local dummy = Utility.CreateDummy(CFrame.new(torso_position, Vector3.new(look_point.X, torso_position.Y, look_point.Z)), "???", Workspace)
- if UserInterface.IsKeyDown("x") then
- ControllerCommands.ActivateTelekinesis(dummy:FindFirstChild("Torso"))
- end
- end
- end)
- UserInterface.SetHotkey(";", function()
- local target_part = Mouse.Target
- if target_part then
- Network.TransmitServer("ServerControl.ConnectPlayer(...)", target_part, UserInterface.IsKeyDown(ControllerCommands.altKey))
- end
- end)
- do
- local activated = false
- local connection
- local nodes
- local function AddNode()
- local target = Mouse.Target
- if target then
- local point = target.CFrame:inverse() * Mouse.Hit.p
- local start = time()
- Mouse.Button1Up:wait()
- local elapsed = time() - start
- for i = 0, elapsed, 0.125 do
- nodes[#nodes + 1] = {target, Vector3.new(math.random() - 0.5, math.random() - 0.5, math.random() - 0.5).unit * (1 + i * 15) + point}
- end
- end
- end
- UserInterface.SetHotkey("m", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- if activated and not deactivating then
- connection:disconnect()
- connection = nil
- nodes = nil
- activated = false
- end
- else
- if activated then
- if #nodes >= 3 then
- nodes[1] = nodes[#nodes]
- nodes[#nodes + 1] = nodes[2]
- nodes[#nodes + 1] = nodes[3]
- local buffer = {}
- for index, node in ipairs(nodes) do
- local point = node[1].CFrame * node[2]
- buffer[index] = "Vector3.new(" .. tostring(point) .. ")"
- end
- Network.TransmitServer("GraphicalEffects.DestructionSpell {" .. table.concat(buffer, ",") .. "}")
- elseif #nodes == 2 then
- local part = nodes[1][1]
- pcall(part.Destroy, part)
- end
- connection:disconnect()
- connection = nil
- nodes = nil
- activated = false
- else
- activated = true
- nodes = {false}
- connection = Mouse.Button1Down:connect(AddNode)
- end
- end
- end)
- end
- UserInterface.SetHotkey("n", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- else
- ControllerCommands.telekinesis_target = Mouse.Target
- end
- end)
- function ControllerCommands.ActivateTelekinesis(part)
- if part then
- local removedItems = {}
- for _, child in ipairs(part:GetChildren()) do
- if child:IsA("BodyMover") then
- removedItems[#removedItems + 1] = child
- child.Parent = nil
- end
- end
- local damage_debounce = {}
- local mass = part:GetMass()
- local gripDistance = (Mouse.Origin.p - Mouse.Hit.p).magnitude
- local connection = part.Touched:connect(function(hit)
- if UserInterface.IsKeyDown("n") then
- local joint_name
- if hit.Name == "Torso" then
- local joint_name = ({
- ["Head"] = "Neck",
- ["Left Arm"] = "Left Shoulder",
- ["Left Leg"] = "Left Hip",
- ["Right Arm"] = "Right Shoulder",
- ["Right Leg"] = "Right Hip"
- })[part.Name]
- end
- local joint
- if joint_name then
- joint = Instance.new("Motor")
- joint.Name = joint_name
- local hit_parent = hit.Parent
- if hit_parent then
- TaskScheduler.Schedule(1, function()
- local anim = hit.Parent:FindFirstChild("Animate")
- if anim and anim.ClassName == "LocalScript" then
- anim.Disabled = true
- wait(0.5)
- anim.Disabled = false
- end
- end)
- end
- else
- joint = Instance.new("Weld")
- end
- local center = CFrame.new((hit.Position + part.Position) * 0.5)
- joint.C0 = hit.CFrame:toObjectSpace(center)
- joint.C1 = part.CFrame:toObjectSpace(center)
- joint.Part0 = hit
- joint.Part1 = part
- joint.Parent = hit
- part.Velocity = Vector3.new()
- end
- local character = PlayerControl.GetCharacter()
- if not hit.Anchored and hit.CanCollide and not (character and hit:IsDescendantOf(character)) then
- local hit_model = hit
- local hit_humanoid
- while hit_model and hit_model.Parent ~= workspace do
- hit_model = hit_model.Parent
- end
- if hit_model and hit_model:IsA("Model") then
- for _, child in ipairs(hit_model:GetChildren()) do
- if child:IsA("Humanoid") then
- hit_humanoid = child
- break
- end
- end
- end
- local speed_diff = (part.Velocity - hit.Velocity).magnitude
- if hit_humanoid then
- if not damage_debounce[hit_humanoid] and hit.Velocity.magnitude > 100 and speed_diff >= 100 then
- local damage = 0.75 * speed_diff
- damage_debounce[hit_humanoid] = true
- hit_humanoid:TakeDamage(damage)
- wait(2)
- damage_debounce[hit_humanoid] = nil
- end
- else
- if speed_diff * speed_diff > hit:GetMass() then
- hit:BreakJoints()
- end
- end
- end
- end)
- local bodyPosition = Instance.new("BodyPosition", part)
- bodyPosition.maxForce = Vector3.new(1e6, 1e6, 1e6) * mass
- while UserInterface.IsKeyDown("x") do
- if UserInterface.IsKeyDown("f") then
- gripDistance = gripDistance * 1.033 + 2
- end
- if UserInterface.IsKeyDown("g") then
- gripDistance = gripDistance / 1.033 - 2
- end
- local targetPosition
- local targetPart = ControllerCommands.telekinesis_target
- if UserInterface.IsKeyDown(ControllerCommands.altKey) and targetPart then
- targetPosition = targetPart.Position
- targetPosition = targetPosition + (targetPosition - part.Position).unit * 100
- --bodyPosition.maxForce = Vector3.new(2e6, 2e6, 2e6)
- else
- targetPosition = Mouse.Origin.p + Mouse.Hit.lookVector * gripDistance
- --bodyPosition.maxForce = Vector3.new(1e6, 1e6, 1e6)
- end
- bodyPosition.position = targetPosition
- RunService.Stepped:wait()
- end
- for _, child in ipairs(removedItems) do
- pcall(Utility.SetProperty, child, "Parent", part)
- end
- part:MakeJoints()
- Debris:AddItem(bodyPosition, 0)
- TaskScheduler.Schedule(3, function() connection:disconnect() end)
- end
- end
- UserInterface.SetHotkey("x", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- ControllerCommands.telekinesis_target = Mouse.Target
- else
- ControllerCommands.ActivateTelekinesis(Mouse.Target)
- end
- end)
- UserInterface.SetHotkey("u", function()
- if UserInterface.IsKeyDown(ControllerCommands.altKey) then
- ControllerCommands.SpawnSapientRockAtMouse()
- else
- local part = Instance.new("Part", workspace)
- local size = 8 + math.random() * 5
- part.BottomSurface = "Smooth"
- part.TopSurface = "Smooth"
- part.Material = "Slate"
- part.Shape = "Ball"
- part.Size = Vector3.new(size, size, size)
- part.Position = Mouse.Hit.p
- if UserInterface.IsKeyDown("x") then
- ControllerCommands.ActivateTelekinesis(part)
- end
- end
- end)
- UserInterface.SetHotkey("]", function()
- local target = Mouse.Target
- if target then
- target:BreakJoints()
- end
- end)
- shared.Chat = UserInterface.Chat
- if Network.server_id then
- Network.TransmitServer("ServerControl.SendConnections()")
- end
- ]=])
- Module.Create("LaunchServer", [==[
- UserInterface.SetCommand("stopservercontrol", function() Network.TransmitServer("ServerControl = {}") end) -- for emergencies
- if Player.Parent then
- Player:Destroy()
- Player.Character = nil
- end
- Logger.print("Info", "Waiting for cross-network scripting in LaunchServer")
- SBTools.WaitForScriptReady()
- Logger.print("Info", "Cross-network scripting is ready in LaunchServer")
- local server_script = SBTools.NewScript(_SessionID .. "/" .. Network.server_id, NetworkReceiver.source, Workspace)
- wait(0.5)
- server_script.Disabled = false
- local signal_name = "MODULE_READY/" .. _SessionID .. "/" .. Network.controller_id
- Network.TransmitServer(string.format([=[
- local Module = {}
- Module.name = "Module"
- Module.source = %q
- loadstring(Module.source)(Module)
- setmetatable(Module, Module.metatable)
- Module.Register(Module)
- Module.Create("ControllerInfo", [[
- ControllerInfo.user_id = %d
- ]])
- local packet = Instance.new("IntValue")
- packet.Name = %q
- packet.Parent = Game:GetService("ReplicatedStorage")
- ]=], Module.source, Player.userId, signal_name))
- local connection
- connection = ReplicatedStorage.ChildAdded:connect(function(child)
- if child.Name == signal_name then
- Logger.print("Info", "Received start-up signal from server in LaunchServer")
- connection:disconnect()
- Network.TransmitModule(Network.server_id, LuaEnum)
- Network.TransmitModule(Network.server_id, Logger)
- local local_script_forward, server_script_forward
- if SBTools.local_script and SBTools.server_script then
- local_script_forward = SBTools.local_script:Clone()
- server_script_forward = SBTools.server_script:Clone()
- local_script_forward.Parent = ReplicatedStorage
- server_script_forward.Parent = ReplicatedStorage
- end
- Network.TransmitModule(Network.server_id, SBTools, local_script_forward, server_script_forward)
- Network.TransmitModule(Network.server_id, Utility)
- Network.TransmitModule(Network.server_id, TaskScheduler)
- Network.TransmitModule(Network.server_id, Network, "<SERVER>", Network.server_id, Network.controller_id)
- Network.StoreModule(Network.server_id, NetworkReceiver)
- Network.StoreModule(Network.server_id, UserInterface)
- Network.StoreModule(Network.server_id, Notification)
- Network.TransmitModule(Network.server_id, Serializer)
- Network.TransmitModule(Network.server_id, ServerControl)
- Network.TransmitModule(Network.server_id, ChatBubble)
- Network.TransmitModule(Network.server_id, Fragmentation)
- Network.TransmitModule(Network.server_id, GraphicalEffects)
- Network.StoreModule(Network.server_id, ChatColor)
- Network.StoreModule(Network.server_id, PyramidCharacter)
- Network.StoreModule(Network.server_id, CharacterAppearance)
- Network.StoreModule(Network.server_id, PlayerControl)
- Network.StoreModule(Network.server_id, RBXInstance)
- Network.StoreModule(Network.server_id, AdvancedGUI)
- Network.StoreModule(Network.server_id, ControllerCommands)
- Debris:AddItem(child, 0)
- end
- end)
- ]==])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement