Advertisement
VailMe

RemoteC

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