Advertisement
Upscalefanatic3

Remote To Script

Feb 10th, 2018
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.20 KB | None | 0 0
  1. if game.CoreGui:FindFirstChild("fsg") then
  2. game.CoreGui.fsg:Destroy()
  3. end
  4. local sbuilder = {}
  5. local list = {}
  6. local event = {}
  7. local bit = {}
  8. local color = {}
  9. local ui = {}
  10. local getfullname, prettytable
  11.  
  12. --sbuilder lib
  13. do
  14. function sbuilder:append(s)
  15. self.size = self.size + 1
  16. self.text[self.size] = s
  17. end
  18.  
  19. function sbuilder:concat()
  20. return table.concat(self.text, '')
  21. end
  22.  
  23. function sbuilder.new()
  24. return setmetatable({text = {}, size = 0}, {__index = sbuilder})
  25. end
  26.  
  27. setmetatable(sbuilder, {__call = sbuilder.new})
  28. end
  29.  
  30. --list lib
  31. do
  32. function list:push(v)
  33. self.size = self.size + 1
  34. self[self.size] = v
  35. end
  36.  
  37. function list:pop()
  38. local popped = self[self.size]
  39. self.size = self.size - 1
  40. return popped
  41. end
  42.  
  43. function list.new()
  44. return setmetatable({size = 0}, {__index = list})
  45. end
  46.  
  47. setmetatable(list, {__call = list.new})
  48. end
  49.  
  50. --event lib
  51. do
  52. function event.new()
  53. local event = {}
  54. local funcs = {}
  55.  
  56. function event:connect(n, f)
  57. funcs[n] = f
  58. end
  59.  
  60. function event:destroy()
  61. funcs = {}
  62. function event.connect() end
  63. end
  64.  
  65. return setmetatable(event, {
  66. __call = function(t, ...)
  67. for i,v in pairs(funcs) do
  68. v(...)
  69. end
  70. end
  71. })
  72. end
  73. end
  74.  
  75. --bit lib
  76. do
  77. function check_int(n)
  78. if (n - math.floor(n) > 0) then
  79. error("trying to use bitwise operation on non-integer!")
  80. end
  81. end
  82.  
  83. function to_bits(n)
  84. check_int(n)
  85. if (n < 0) then
  86. return to_bits(bit.bnot(math.abs(n)) + 1)
  87. end
  88. local tbl = {}
  89. local cnt = 1
  90. while (n > 0) do
  91. local last = n % 2
  92. if (last == 1) then
  93. tbl[cnt] = 1
  94. else
  95. tbl[cnt] = 0
  96. end
  97. n = (n - last) / 2
  98. cnt = cnt + 1
  99. end
  100.  
  101. return tbl
  102. end
  103.  
  104. function tbl_to_number(tbl)
  105. local n = table.getn(tbl)
  106.  
  107. local rslt = 0
  108. local power = 1
  109. for i = 1, n do
  110. rslt = rslt + tbl[i] * power
  111. power = power * 2
  112. end
  113.  
  114. return rslt
  115. end
  116.  
  117. function expand(tbl_m, tbl_n)
  118. local big = {}
  119. local small = {}
  120. if (table.getn(tbl_m) > table.getn(tbl_n)) then
  121. big = tbl_m
  122. small = tbl_n
  123. else
  124. big = tbl_n
  125. small = tbl_m
  126. end
  127. for i = table.getn(small) + 1, table.getn(big) do
  128. small[i] = 0
  129. end
  130. end
  131.  
  132. function bit.band(m, n)
  133. local tbl_m = to_bits(m)
  134. local tbl_n = to_bits(n)
  135. expand(tbl_m, tbl_n)
  136.  
  137. local tbl = {}
  138. local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
  139. for i = 1, rslt do
  140. if (tbl_m[i] == 0 or tbl_n[i] == 0) then
  141. tbl[i] = 0
  142. else
  143. tbl[i] = 1
  144. end
  145. end
  146.  
  147. return tbl_to_number(tbl)
  148. end
  149.  
  150. function bit.bor(m, n)
  151. local tbl_m = to_bits(m)
  152. local tbl_n = to_bits(n)
  153. expand(tbl_m, tbl_n)
  154.  
  155. local tbl = {}
  156. local rslt = math.max(table.getn(tbl_m), table.getn(tbl_n))
  157. for i = 1, rslt do
  158. if (tbl_m[i] == 0 and tbl_n[i] == 0) then
  159. tbl[i] = 0
  160. else
  161. tbl[i] = 1
  162. end
  163. end
  164.  
  165. return tbl_to_number(tbl)
  166. end
  167.  
  168. function bit.bnot(n)
  169. local tbl = to_bits(n)
  170. local size = math.max(table.getn(tbl), 32)
  171. for i = 1, size do
  172. if (tbl[i] == 1) then
  173. tbl[i] = 0
  174. else
  175. tbl[i] = 1
  176. end
  177. end
  178. return tblToNumber(tbl)
  179. end
  180.  
  181. function bit.rshift(n, bits)
  182. check_int(n)
  183.  
  184. local high_bit = 0
  185. if (n < 0) then
  186. -- negative
  187. n = bit.bnot(math.abs(n)) + 1
  188. high_bit = 0x80000000
  189. end
  190.  
  191. for i = 1, bits do
  192. n = n / 2
  193. n = bit.bor(math.floor(n), high_bit)
  194. end
  195. return math.floor(n)
  196. end
  197.  
  198. function bit.lshift(n, bits)
  199. check_int(n)
  200.  
  201. if (n < 0) then
  202. n = bit.bnot(math.abs(n)) + 1
  203. end
  204.  
  205. for i = 1, bits do
  206. n = n * 2
  207. end
  208. return bit.band(n, 0xFFFFFFFF)
  209. end
  210. end
  211.  
  212. --color lib
  213. do
  214. function color.hex(color)
  215. local r = bit.band(bit.rshift(color, 16), 255)
  216. local g = bit.band(bit.rshift(color, 8), 255)
  217. local b = bit.band(color, 255)
  218.  
  219. return Color3.fromRGB(r, g, b)
  220. end
  221.  
  222. color.background = color.hex(0x202020)
  223. color.foreground = color.hex(0xEFEFEF)
  224. color.border = color.hex(0x303030)
  225. end
  226.  
  227. --prettytable
  228. do
  229. function getfullname(inst)
  230. local tree = {}
  231. while inst.Parent do
  232. tree[#tree + 1] = ('"%s"'):format(inst.Name)
  233. inst = inst.Parent
  234. end
  235. local reverse = {}
  236. for i = #tree, 1, -1 do
  237. reverse[#reverse + 1] = tree[i]
  238. end
  239. return ("%s[%s]"):format(inst.Name, table.concat(reverse, ']['))
  240. end
  241. local spaces = setmetatable({}, {
  242. __index = function(t, k)
  243. local g = rawget(t, k)
  244. if g then
  245. return g
  246. else
  247. local s = string.rep(" ", k)
  248. rawset(t, k, s)
  249. return s
  250. end
  251. end
  252. })
  253. local function isnormal(s)
  254. if s:find("^[%a_][%w_]*$") then
  255. return true
  256. end
  257. return false
  258. end
  259. function prettytable(tab, usetree, upvalues, maxlevel)
  260. local stuff = {
  261. tabs = {[tab] = "base"},
  262. funcs = {},
  263. level = 0,
  264. tree = {"base"},
  265. usetree = usetree or false,
  266. upvalues = upvalues or false,
  267. maxlevel = maxlevel or 18
  268. }
  269. local function map(tab, stuff)
  270. local tree = stuff.tree
  271. local tabs = stuff.tabs
  272. local funcs = stuff.funcs
  273. local maxlevel = stuff.maxlevel
  274. local getupvalues = debug.getupvalues
  275. local usetree = stuff.usetree
  276. local upvalues = stuff.upvalues
  277. local strOut, ind, retTab = '', '', {}
  278.  
  279. for i, v in pairs(tab) do
  280. local it = type(i)
  281. local t = type(v)
  282. if it == 'string' then
  283. if isnormal(i) then
  284. ind = ('%s = '):format(i)
  285. else
  286. ind = ('["%s"] = '):format(i)
  287. end
  288. else
  289. ind = ('[%s] = '):format(tostring(i), type(i))
  290. end
  291.  
  292. tree[#tree + 1] = ind:sub(1, -4)
  293. if usetree then
  294. ind = ("%s = "):format(table.concat(tree, ''))
  295. end
  296.  
  297. if t == 'table' then
  298. if not tabs[v] then
  299. tabs[v] = ("%s"):format(table.concat(tree, ''))
  300. stuff.level = stuff.level + 1
  301. if stuff.level <= maxlevel then
  302. local inside = map(v, stuff)
  303. local empty = inside == '<empty>'
  304. inside = empty and '' or inside
  305. local ls = empty and '' or spaces[stuff.level]
  306. local rs = empty and '' or spaces[stuff.level - 1]
  307. local nl = empty and '' or '\n'
  308. strOut = ("%s{%s%s%s%s%s}"):format(ind, nl, ls, inside, nl, rs)
  309. else
  310. strOut = ("%s{...}"):format(ind)
  311. end
  312. stuff.level = stuff.level - 1
  313. else
  314. strOut = ("%s%s"):format(ind, tabs[v])
  315. end
  316. elseif t == 'function' and upvalues then
  317. if not funcs[v] then
  318. funcs[v] = ("%s"):format(table.concat(tree, ''))
  319. stuff.level = stuff.level + 1
  320. if stuff.level <= 18 then
  321. local inside = map(getupvalues(v), stuff)
  322. local empty = inside == '<empty>'
  323. inside = empty and '' or inside
  324. local ls = empty and '' or spaces[stuff.level]
  325. local rs = empty and '' or spaces[stuff.level - 1]
  326. local nl = empty and '' or '\n'
  327. strOut = ("%s--[[upvalues]] {%s%s%s%s%s}"):format(ind, nl, ls, inside, nl, rs)
  328. else
  329. strOut = ("%s--[[upvalues]] {...}"):format(ind)
  330. end
  331. stuff.level = stuff.level - 1
  332. else
  333. strOut = ("%s%s"):format(ind, funcs[v])
  334. end
  335. elseif t == 'string' then
  336. strOut = ('%s"%s"'):format(ind, v)
  337. elseif t == 'userdata' then
  338. local to = typeof(v)
  339. if to == 'Instance' then
  340. strOut = ("%s%s"):format(ind, getfullname(v))
  341. elseif to == 'userdata' then
  342. strOut = ("%s%s"):format(ind, tostring(v))
  343. else
  344. strOut = ("%s%s.new(%s)"):format(ind, typeof(v), tostring(v))
  345. end
  346. else
  347. local vt = type(v)
  348. strOut = ("%s%s%s"):format(ind, tostring(v), (vt == "function" and '' or (" --[[%s]]"):format(vt)))
  349. end
  350. retTab[#retTab + 1] = strOut
  351.  
  352. tree[#tree] = nil
  353. end
  354. return #retTab < 1 and '<empty>' or table.concat(retTab, (',\n%s'):format(spaces[stuff.level]))
  355. end
  356. return map(tab, stuff)
  357. end
  358. end
  359.  
  360. -- (remote, method, args, returns)
  361. local received = event.new()
  362.  
  363. --metatable stuff
  364. do
  365. local gmt = getrawmetatable(game)
  366. local readonly = setreadonly or make_writeable
  367.  
  368. readonly(gmt, false)
  369.  
  370. if not gmt.fireserver then
  371. gmt.fireserver = Instance.new("RemoteEvent").FireServer
  372. gmt.invokeserver = Instance.new("RemoteFunction").InvokeServer
  373. gmt.o_index = gmt.__index
  374. end
  375. if not gmt.o_namecall then
  376. gmt.o_namecall = gmt.__namecall
  377. end
  378. local o_index = gmt.o_index
  379. local o_namecall = gmt.__namecall
  380. local useindex = false
  381.  
  382. local fake = {
  383. fireserver = gmt.fireserver,
  384. invokeserver = gmt.invokeserver
  385. }
  386.  
  387. if useindex then
  388. function gmt.__index(t, k)
  389. local method = k:lower()
  390.  
  391. if fake[method] then
  392. return function(s, ...)
  393. local out = {fake[method](s, ...)}
  394.  
  395. warn("start received event")
  396. received(s, method, {...}, out)
  397. warn("end received event")
  398.  
  399. return unpack(out)
  400. end
  401. end
  402.  
  403. return o_index(t, k)
  404. end
  405. else
  406. function gmt.__namecall(u, ...)
  407. local a = {...}
  408. local method = a[#a]
  409. a[#a] = nil
  410.  
  411. if method == "FireServer" or method == "InvokeServer" then
  412. received(u, method, a, out)
  413. end
  414.  
  415. return o_namecall(u, ...)
  416. end
  417. end
  418. end
  419.  
  420. -- ui
  421. do
  422. local u2 = UDim2.new
  423. local _new = Instance.new
  424.  
  425. local function new(class, name, props, parent)
  426. local inst = _new(class)
  427. inst.Name = name
  428. if props then
  429. for i, v in pairs(props) do
  430. inst[i] = v
  431. end
  432. end
  433. if parent then
  434. inst.Parent = parent
  435. end
  436. return inst
  437. end
  438.  
  439. local function frame(name, props, parent)
  440. local temp = new("Frame", name, {
  441. BackgroundColor3 = color.background,
  442. BorderColor3 = color.border,
  443. ClipsDescendants = true
  444. })
  445. for i,v in pairs(props) do
  446. temp[i] = v
  447. end
  448. if parent then
  449. temp.Parent = parent
  450. end
  451. return temp
  452. end
  453. local function button(name, props, parent)
  454. local temp = new("TextButton", name, {
  455. BackgroundColor3 = color.background,
  456. BorderColor3 = color.border,
  457. TextColor3 = color.foreground,
  458. ClipsDescendants = true
  459. })
  460. for i,v in pairs(props) do
  461. temp[i] = v
  462. end
  463. if parent then
  464. temp.Parent = parent
  465. end
  466. return temp
  467. end
  468. local function label(name, props, parent)
  469. local temp = new("TextLabel", name, {
  470. BackgroundColor3 = color.background,
  471. BorderColor3 = color.border,
  472. TextColor3 = color.foreground,
  473. ClipsDescendants = true
  474. })
  475. for i,v in pairs(props) do
  476. temp[i] = v
  477. end
  478. if parent then
  479. temp.Parent = parent
  480. end
  481. return temp
  482. end
  483. local function scroller(name, props, parent)
  484. local temp = new("ScrollingFrame", name, {
  485. BackgroundColor3 = color.background,
  486. BorderColor3 = color.border,
  487. TopImage = "rbxasset://textures/blackBkg_square.png",
  488. MidImage = "rbxasset://textures/blackBkg_square.png",
  489. BottomImage = "rbxasset://textures/blackBkg_square.png"
  490. })
  491. for i,v in pairs(props) do
  492. temp[i] = v
  493. end
  494. if parent then
  495. temp.Parent = parent
  496. end
  497. return temp
  498. end
  499. local function textbox(name, props, parent)
  500. local temp = new("TextBox", name, {
  501. BackgroundColor3 = color.background,
  502. BorderColor3 = color.border,
  503. TextColor3 = color.foreground,
  504. MultiLine = true,
  505. ClearTextOnFocus = false,
  506. TextXAlignment = "Left",
  507. TextYAlignment = "Top",
  508. Text = "",
  509. TextWrapped = true,
  510. ClipsDescendants = true
  511. })
  512. for i,v in pairs(props) do
  513. temp[i] = v
  514. end
  515. if parent then
  516. temp.Parent = parent
  517. end
  518. return temp
  519. end
  520.  
  521. local main = new("ScreenGui", "fsg")
  522.  
  523. ui.dragbox = frame("drag", {
  524. Size = u2(0, 496, 0, 21),
  525. Position = u2(0.5, -252, 0.5, -177),
  526. Draggable = true,
  527. Active = true,
  528. Transparency = 1,
  529. ClipsDescendants = false
  530. }, main)
  531. ui.backboard = frame("back", {
  532. Size = u2(0, 500, 0, 350),
  533. Position = u2(0, -2, 0, -2)
  534. }, ui.dragbox)
  535.  
  536. -- backboard
  537. ui.bodybox = frame("body", {
  538. Size = u2(0, 496, 0, 322),
  539. Position = u2(0, 2, 0, 26),
  540. Active = true
  541. }, ui.backboard)
  542. ui.titlebox = frame("titlebar", {
  543. Size = u2(1, -4, 0, 21),
  544. Position = u2(0, 2, 0, 2)
  545. }, ui.backboard)
  546.  
  547. -- titlebox
  548. ui.minibtn = button("minimize", {
  549. Size = u2(0, 17, 0, 17),
  550. Position = u2(1, -19, 0, 2),
  551. Text = "-"
  552. }, ui.titlebox)
  553. ui.title = label("title", {
  554. Size = u2(0, 110, 0, 17),
  555. Position = u2(0.5, -65, 0, 2),
  556. Text = "FE Script Generator"
  557. }, ui.titlebox)
  558.  
  559. -- bodybox
  560. ui.events = scroller("eventcontainer", {
  561. Size = u2(0, 200, 0, 318),
  562. Position = u2(0, 2, 0, 2)
  563. }, ui.bodybox)
  564. ui.code = textbox("code", {
  565. Size = u2(0, 289, 0, 294),
  566. Position = u2(0, 205, 0, 2)
  567. }, ui.bodybox)
  568. ui.copycode = button("copy", {
  569. Size = u2(0, 80, 0, 21),
  570. Position = u2(1, -82, 1, -23),
  571. Text = "Copy Script"
  572. }, ui.bodybox)
  573.  
  574. --functions
  575. local toadd = list()
  576. local added = false
  577. function ui.sortevents()
  578. local li = 0
  579. for i,v in pairs(ui.events:GetChildren()) do
  580. v.Position = u2(0, 2, 0, (i - 1) * 22 + i * 2)
  581. li = i
  582. end
  583. ui.events.CanvasSize = u2(0, 187, 0, (li) * 22 + (li) * 2 + 1)
  584. ui.events.CanvasSize = u2(0, 0, 0, (li) * 22 + (li) * 2 + 1)
  585. end
  586.  
  587. local ecount = 0
  588. function ui.addevent(remote, method, args)
  589. ecount = ecount + 1
  590. local n = frame("event_" .. ecount, {
  591. Size = u2(0, 183, 0, 21),
  592. }, ui.events)
  593. local t = label("title", {
  594. Size = u2(0, 162, 0, 21),
  595. Text = remote.Name
  596. }, n)
  597. local sel = button("add", {
  598. Size = u2(0, 21, 0, 21),
  599. Position = u2(1, -21, 0, 0),
  600. Text = "S"
  601. }, n)
  602. sel.MouseButton1Click:connect(function()
  603. local code = sbuilder()
  604. code:append(("local remote = %s\n"):format(getfullname(remote)))
  605. code:append(("local %s\n"):format(prettytable({args = args})))
  606. code:append(("remote:%s(unpack(args))\n"):format(method))
  607. ui.code.Text = code:concat()
  608. end)
  609. ui.sortevents()
  610. end
  611.  
  612. function ui.requestaddevent(remote, method, args)
  613. toadd:push({remote, method, args})
  614. added = true
  615. end
  616.  
  617. --event stuffs
  618. do
  619. --- titlebar ---
  620. local minimized = false
  621. ui.minibtn.MouseButton1Click:connect(function()
  622. minimized = not minimized
  623. local nsize = minimized and u2(0, 138, 0, 25) or u2(0, 500, 0, 350)
  624. local dsize = minimized and u2(0, 134, 0, 21) or u2(0, 496, 0, 21)
  625. local npos = ui.dragbox.Position + (u2(0, minimized and 362 or -362, 0, 0))
  626.  
  627. ui.backboard:TweenSize(nsize, "Out", "Quad", 0.2)
  628. ui.dragbox:TweenSizeAndPosition(dsize, npos, "Out", "Quad", 0.2)
  629. end)
  630.  
  631. --- body ---
  632. ui.copycode.MouseButton1Click:connect(function()
  633. (setclipboard or Synapse.CopyString and function(s)Synapse:CopyString(s)end or function()end)(ui.code.Text)
  634. end)
  635. end
  636.  
  637. spawn(function()
  638. while true do
  639. repeat wait() until added
  640. for i = 1, toadd.size do
  641. local v = toadd:pop()
  642. ui.addevent(v[1], v[2], v[3])
  643. end
  644. added = false
  645. end
  646. end)
  647.  
  648. main.Parent = game.CoreGui
  649. end
  650.  
  651. received:connect("requestaddevent", ui.requestaddevent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement