Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local http = game:GetService("HttpService")
- local MyListID = "SaveInstanceQueue"
- local MyCardID = "SaveInstanceQueue"
- local Trello = {
- List = "SaveInstanceQueue",
- DevKey = "1593711bab1a8844f80b44774a63d7ce", -- Put Trello Dev Key here
- Token = " a9066bbf2f723c66299d780218ba09b526785cedb4577f1ac2f114031697dec4", -- Put Trello Token here
- }
- function trelloGet(address)
- if not address then return end
- return game:HttpGet(address.. "?key="..Trello.DevKey.."&token="..Trello.Token,true)
- end
- function trelloPost(address, data)
- if address == nil or data == nil then return end
- local encoded = http:JSONEncode(data)
- return game:HttpPost(address.. "?key="..Trello.DevKey.."&token="..Trello.Token, tostring(encoded),true,"application/json")
- end
- local boards = trelloGet("https://api.trello.com/1/members/me/boards")
- if not boards then return end
- local foundList = false
- for _,v in pairs(http:JSONDecode(boards)) do
- if v["id"] ~= nil then
- local lists = trelloGet("http://api.trello.com/1/boards/"..v["id"].."/lists")
- if lists then
- for x,list in pairs(http:JSONDecode(lists)) do
- if list["name"] == Trello.List then
- MyListID = list["id"]
- foundList = true
- break
- end
- end
- end
- end
- end
- if not foundList then
- local newBoard = trelloPost("https://api.trello.com/1/boards", {["name"]="SaveInstance",["desc"]="A board for RC7's SaveInstance."})
- local posted = false
- if newBoard then
- newBoard = http:JSONDecode(newBoard)
- local newList = trelloPost("https://api.trello.com/1/boards/"..newBoard["id"].."/lists", {["name"]=Trello.List})
- if newList then
- MyListID = http:JSONDecode(newList)["id"]
- end
- end
- print("A board was created for you.")
- end
- function MakeNewCard(nam)
- if MyListID == "" then
- print("NO LIST!")
- return
- end
- MyCardID = http:JSONDecode(trelloPost("https://api.trello.com/1/lists/"..MyListID.."/cards", {["name"]=nam}))["id"]
- end
- function AddZeros(num)
- if num < 10 then
- return "000"
- elseif num < 100 then
- return "00"
- elseif num < 1000 then
- return "0"
- else
- return ""
- end
- end
- function ToTrello(msg,num)
- local dat = {
- file = msg,
- name = AddZeros(num)..tostring(num),
- mimeType = ".rbxmx"
- }
- trelloPost("https://api.trello.com/1/cards/"..MyCardID.."/attachments/",dat)
- end
- local instanceCount = 0
- local saveString = ""
- local propertiesAPI = "http://wiki.roblox.com/index.php/API:Class_reference/Dump/raw?action=raw"
- local props = {}
- local savedProps = {}
- local instanceRefs = {}
- local storedInstances = {}
- local SplitAmounts = 0
- local SplitName = ""
- local skipObjects = false
- function httpGet(url)
- return game:HttpGet(url,true)
- end
- local propertiesList = httpGet(propertiesAPI)--require(script.studiotest)
- function findClass(str, clsname, addon)
- local findX, findY = string.find(str, "Class "..clsname)
- local check = string.match(string.sub(str,findX + 5),"%w+")
- findY = findY + 1
- if check ~= clsname then
- return findClass(string.sub(str,findY),clsname, addon-1 + findY)
- else
- return findY + addon
- end
- end
- function getAllProperties(cName)
- local findPos = findClass(propertiesList,cName, 0)
- local findBookmark = string.sub(propertiesList,findPos)
- local bookmarkCount = 0
- for line in string.gmatch(findBookmark,"%C+") do
- if string.sub(line,1,8) == "Property" and not string.find(line, "deprecated") and not string.find(line, "hidden") then
- local propFindCount = 0
- local propType = "Bool"
- local propName = ""
- local readOnly = false
- for w in string.gmatch(line, "%w+") do
- propFindCount = propFindCount + 1
- if propFindCount == 2 then
- propType = w
- elseif propFindCount == 4 then
- propName = w
- end
- end
- if string.find(line, "readonly") then
- readOnly = true
- end
- local propPacket = {Type = propType, Name = propName, ReadOnly = readOnly}
- table.insert(props,propPacket)
- elseif string.sub(line,1,8) ~= "Property" then
- if bookmarkCount > 0 then
- break
- end
- bookmarkCount = bookmarkCount + 1
- end
- end
- if cName ~= "Instance" then
- getAllProperties(string.match(findBookmark,"%w+"))
- end
- end
- function checkFoundProps(pname)
- for i,v in pairs(savedProps) do
- if v.ClassName == pname then
- return v
- end
- end
- return false
- end
- function getProperties(obj)
- local toFind = obj.ClassName
- local checkProps = checkFoundProps(toFind)
- if checkProps then
- return checkProps.Props
- end
- props = {}
- getAllProperties(toFind)
- local function sortProps(val1, val2)
- return val1.Name < val2.Name
- end
- table.sort(props, sortProps)
- table.insert(savedProps,{ClassName = toFind, Props = props})
- return props
- end
- function checkRef(obj)
- for i,v in pairs(instanceRefs) do
- if v.Instance == obj then
- return tostring(v.Number)
- end
- end
- return tostring(instanceCount)
- end
- function setRef(obj)
- if obj == nil then return "null" end
- for i,v in pairs(instanceRefs) do
- if v.Instance == obj then
- return "RBX"..tostring(v.Number)
- end
- end
- instanceCount = instanceCount + 1
- table.insert(instanceRefs,{Instance = obj, Number = instanceCount})
- return "RBX"..tostring(instanceCount)
- end
- function PostIt(str)
- ToTrello(str,SplitAmounts)
- SplitAmounts = SplitAmounts + 1
- end
- function writeInstance(inst)
- for i,v in pairs(inst:GetChildren()) do
- if string.len(table.concat(storedInstances)) >= 1010000 then
- PostIt(table.concat(storedInstances))
- storedInstances = {}
- end
- table.insert(storedInstances,saveString)
- saveString = ""
- instanceCount = instanceCount + 1
- local props = getProperties(v)
- if skipObjects then
- saveString = saveString..'\n<Item class="'..v.ClassName..'" referent="RBX'..tostring(instanceCount)..'">'
- else
- saveString = saveString..'\n<Item class="'..v.ClassName..'" referent="RBX'..checkRef(v)..'">'
- table.insert(instanceRefs,{Instance = v, Number = instanceCount})
- end
- saveString = saveString.."\n<Properties>"
- for i2,v2 in pairs(props) do
- ypcall(function()
- if v2.Name == "Archivable" or v2.Name == "DataCost" or v2.Name == "ClassName" or v2.Name == "RobloxLocked" or v2.Name == "Parent" then return end
- if v2.Type == "bool" then
- saveString = saveString..'\n<bool name="'..v2.Name..'">'..tostring(v[v2.Name])..'</bool>'
- elseif v2.Type == "float" then
- saveString = saveString..'\n<float name="'..v2.Name..'">'..tostring(v[v2.Name])..'</float>'
- elseif v2.Type == "int" then
- saveString = saveString..'\n<int name="'..v2.Name..'">'..tostring(v[v2.Name])..'</int>'
- elseif v2.Type == "string" then
- local cleanName = v[v2.Name]
- cleanName = string.gsub(cleanName,"&","&")
- cleanName = string.gsub(cleanName,"<","<")
- cleanName = string.gsub(cleanName,">",">")
- local success,err = pcall(function()http:JSONEncode({t = cleanName})end)
- if err then cleanName = "This name could not be saved." end
- saveString = saveString..'\n<string name="'..v2.Name..'">'..cleanName..'</string>'
- elseif v2.Type == "BrickColor" then
- saveString = saveString..'\n<int name="'..v2.Name..'">'..tostring(v[v2.Name].Number)..'</int>'
- elseif v2.Type == "Vector2" then
- saveString = saveString..'\n<Vector2 name="'..v2.Name..'">'
- saveString = saveString..'\n<X>'..v[v2.Name].x..'</X>'
- saveString = saveString..'\n<Y>'..v[v2.Name].y..'</Y>'
- saveString = saveString..'\n</Vector2>'
- elseif v2.Type == "Vector3" then
- saveString = saveString..'\n<Vector3 name="'..v2.Name..'">'
- saveString = saveString..'\n<X>'..v[v2.Name].x..'</X>'
- saveString = saveString..'\n<Y>'..v[v2.Name].y..'</Y>'
- saveString = saveString..'\n<Z>'..v[v2.Name].z..'</Z>'
- saveString = saveString..'\n</Vector3>'
- elseif v2.Type == "CoordinateFrame" then
- saveString = saveString..'\n<CoordinateFrame name="'..v2.Name..'">'
- local X,Y,Z,R00,R01,R02,R10,R11,R12,R20,R21,R22 = v[v2.Name]:components()
- saveString = saveString..'\n<X>'..X..'</X>'
- saveString = saveString..'\n<Y>'..Y..'</Y>'
- saveString = saveString..'\n<Z>'..Z..'</Z>'
- saveString = saveString..'\n<R00>'..R00..'</R00>'
- saveString = saveString..'\n<R01>'..R01..'</R01>'
- saveString = saveString..'\n<R02>'..R02..'</R02>'
- saveString = saveString..'\n<R10>'..R10..'</R10>'
- saveString = saveString..'\n<R11>'..R11..'</R11>'
- saveString = saveString..'\n<R12>'..R12..'</R12>'
- saveString = saveString..'\n<R20>'..R20..'</R20>'
- saveString = saveString..'\n<R21>'..R21..'</R21>'
- saveString = saveString..'\n<R22>'..R22..'</R22>'
- saveString = saveString..'\n</CoordinateFrame>'
- elseif v2.Type == "Content" then
- local cleanName = tostring(v[v2.Name])
- cleanName = string.gsub(cleanName,"&","&")
- cleanName = string.gsub(cleanName,"<","<")
- cleanName = string.gsub(cleanName,">",">")
- local success,err = pcall(function()http:JSONEncode({t = cleanName})end)
- if err then cleanName = "This name could not be saved." end
- saveString = saveString..'\n<Content name="'..v2.Name..'"><url>'..cleanName..'</url></Content>'
- elseif v2.Type == "UDim2" then
- saveString = saveString..'\n<UDim2 name="'..v2.Name..'">'
- saveString = saveString..'\n<XS>'..v[v2.Name].X.Scale..'</XS>'
- saveString = saveString..'\n<XO>'..v[v2.Name].X.Offset..'</XO>'
- saveString = saveString..'\n<YS>'..v[v2.Name].Y.Scale..'</YS>'
- saveString = saveString..'\n<YO>'..v[v2.Name].Y.Offset..'</YO>'
- saveString = saveString..'\n</UDim2>'
- elseif v2.Type == "Color3" then
- saveString = saveString..'\n<Color3 name="'..v2.Name..'">'
- saveString = saveString..'\n<R>'..v[v2.Name].r..'</R>'
- saveString = saveString..'\n<G>'..v[v2.Name].g..'</G>'
- saveString = saveString..'\n<B>'..v[v2.Name].b..'</B>'
- saveString = saveString..'\n</Color3>'
- elseif v2.Type == "NumberRange" then
- saveString = saveString..'\n<NumberRange name="'..v2.Name..'">'..tostring(v[v2.Name].Min).." "..tostring(v[v2.Name].Max).." "..'</NumberRange>'
- elseif v2.Type == "NumberSequence" then
- saveString = saveString..'\n<NumberSequence name="'..v2.Name..'">'
- for i3,v3 in pairs(v[v2.Name].Keypoints) do
- saveString = saveString..tostring(v3.Time).." "..tostring(v3.Value).." "..tostring(v3.Envelope).." "
- end
- saveString = saveString..'</NumberSequence>'
- elseif v2.Type == "ColorSequence" then
- local myProp = v[v2.Name].Keypoints[1]
- local myProp2 = v[v2.Name].Keypoints[2]
- saveString = saveString..'\n<ColorSequence name="'..v2.Name..'">'..tostring(myProp.Time).." "..tostring(myProp.Value.r).." "..tostring(myProp.Value.g).." "..tostring(myProp.Value.b).." 0 "..tostring(myProp2.Time).." "..tostring(myProp2.Value.r).." "..tostring(myProp2.Value.g).." "..tostring(myProp2.Value.b).." 0 "..'</ColorSequence>'
- elseif v2.Type == "Object" then
- if skipObjects then
- saveString = saveString..'\n<Ref name="'..v2.Name..'">null</Ref>'
- else
- saveString = saveString..'\n<Ref name="'..v2.Name..'">'..setRef(v[v2.Name])..'</Ref>'
- end
- elseif v[v2.Name].Value then
- saveString = saveString..'\n<token name="'..v2.Name..'">'..v[v2.Name].Value..'</token>'
- end
- end)
- end
- if v:IsA("UnionOperation") and readcsgdata then -- Had to do this, "BinaryString" type values were not in the API dump.
- --saveString = saveString..'\n<BinaryString name="ChildData">'..readcsgdata(v.ChildData)..'</BinaryString>'
- --saveString = saveString..'\n<BinaryString name="MeshData">'..readcsgdata(v.MeshData)..'</BinaryString>'
- local newUnion = v:Clone()
- newUnion.Parent = game.RobloxReplicatedStorage
- saveString = saveString..'\n<Content name="AssetId"><url>'..v.AssetId..'</url></Content>'
- saveString = saveString..'\n<Vector3 name="InitialSize">'
- saveString = saveString..'\n<X>'..v.InitialSize.x..'</X>'
- saveString = saveString..'\n<Y>'..v.InitialSize.y..'</Y>'
- saveString = saveString..'\n<Z>'..v.InitialSize.z..'</Z>'
- saveString = saveString..'\n</Vector3>'
- saveString = saveString..'\n<BinaryString name="PhysicsData">'.."<![CDATA["..readcsgdata(newUnion).."]]>"..'</BinaryString>'
- end
- saveString = saveString.."\n</Properties>"
- writeInstance(v)
- saveString = saveString.."\n</Item>"
- table.insert(storedInstances,saveString)
- saveString = ""
- end
- end
- function _G.SaveInstance(inst,fname,skipObj)
- instanceCount = 0
- instanceRefs = {}
- storedInstances = {}
- saveString = ""
- SplitName = fname
- SplitAmounts = 0
- MakeNewCard(fname)
- if skipObj then
- skipObjects = true
- else
- skipObjects = false
- end
- saveString = [[<roblox xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.roblox.com/roblox.xsd" version="4">
- <External>null</External>
- <External>nil</External>]]
- local saveFolder = Instance.new("Folder")
- inst:Clone().Parent = saveFolder
- writeInstance(saveFolder)
- saveString = saveString.."\n</roblox>"
- table.insert(storedInstances,saveString)
- --print(saveString)
- --_G.send(saveString)
- PostIt(table.concat(storedInstances))
- print("There were "..tostring(SplitAmounts).." splits.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement