-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextracter2.lua
More file actions
137 lines (118 loc) · 5.35 KB
/
extracter2.lua
File metadata and controls
137 lines (118 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---------------------------------------------------------------
-- export‑selected.remodel.lua
-- Dumps scripts from the most‑used developer services only.
---------------------------------------------------------------
local INPUT_FILE = "game2.rbxl" -- change if needed
local OUTPUT_ROOT = "exported2"
----------------------------------------------------------------
-- helpers (same sanitise & path‑safety as before)
----------------------------------------------------------------
local ILLEGAL = '[<>:"/\\|%?%*%z\1-\31]'
local RESERVED_WIN = { "CON","PRN","AUX","NUL",
"COM1","COM2","COM3","COM4","COM5","COM6","COM7","COM8","COM9",
"LPT1","LPT2","LPT3","LPT4","LPT5","LPT6","LPT7","LPT8","LPT9" }
local function sanitise(name)
name = name:gsub(ILLEGAL, "_"):gsub("[%.%s]+$", "")
if #name == 0 then name = "_" end
if #name > 100 then name = name:sub(1,100) .. "…" end
for _, r in ipairs(RESERVED_WIN) do
if name:upper() == r then name = "_" .. name end
end
return name
end
local function safeJoin(base, name)
local p = base .. "/" .. name
if #p > 240 then
local excess = #p - 240
base = base:sub(1, #base-excess-3) .. "…"
p = base .. "/" .. name
end
return p
end
local function writeScript(inst, filePath)
local ok, src = pcall(remodel.getRawProperty, inst, "Source")
if ok and src then
local writeOk, writeErr = pcall(remodel.writeFile, filePath .. ".lua", src)
if writeOk then
print("Success: " .. filePath .. ".lua")
else
print("ERROR writing file: " .. filePath .. ".lua - " .. tostring(writeErr))
end
else
print("WARNING: Could not read source from " .. (inst.Name or inst.ClassName) .. " - " .. tostring(src))
end
end
local exportCount = 0
local function export(inst, basePath, depth)
depth = depth or 0
local indent = string.rep(" ", depth)
-- Safety check for infinite recursion
if depth > 50 then
print("WARNING: Maximum depth reached at " .. (inst.Name or inst.ClassName))
return
end
local instName = inst.Name or inst.ClassName or "_"
print(indent .. "Processing: " .. instName .. " (" .. inst.ClassName .. ")")
local this = sanitise(instName)
local here = safeJoin(basePath, this)
-- Better error handling for directory creation
local dirOk, dirErr = pcall(remodel.createDirAll, here)
if not dirOk then
print("ERROR: Could not create directory " .. here .. " - " .. tostring(dirErr))
return
end
local cls = inst.ClassName
if cls == "Script" or cls == "LocalScript" or cls == "ModuleScript" then
exportCount = exportCount + 1
writeScript(inst, here)
end
-- Better error handling for getting children
local childOk, children = pcall(function() return inst:GetChildren() end)
if not childOk then
print("WARNING: Could not get children of " .. instName .. " - " .. tostring(children))
return
end
for i, child in ipairs(children) do
-- Add progress indicator for large numbers of children
if #children > 10 and i % 10 == 0 then
print(indent .. " Progress: " .. i .. "/" .. #children .. " children processed")
end
-- Wrap each child export in error handling
local exportOk, exportErr = pcall(export, child, here, depth + 1)
if not exportOk then
print("ERROR: Failed to export child " .. (child.Name or child.ClassName) .. " - " .. tostring(exportErr))
end
end
end
----------------------------------------------------------------
-- load place
----------------------------------------------------------------
local okPlace, place = pcall(remodel.readPlaceFile, INPUT_FILE)
assert(okPlace and place, "Cannot open "..INPUT_FILE)
print("> Exporting scripts from "..INPUT_FILE.." …")
-- List only the developer‑facing services we want
local TARGET_SERVICES = {
{ place.ServerScriptService, "ServerScriptService" },
{ place.ServerStorage, "ServerStorage" },
{ place.ReplicatedStorage, "ReplicatedStorage" },
{ place.StarterPlayer and
place.StarterPlayer.StarterPlayerScripts, "StarterPlayerScripts" },
{ place.StarterGui, "StarterGui" },
{ place.StarterPack, "StarterPack" },
{ place.Workspace, "Workspace" },
}
for _, pair in ipairs(TARGET_SERVICES) do
local svc, label = pair[1], pair[2]
if svc then
print("\n=== Exporting " .. label .. " ===")
local serviceOk, serviceErr = pcall(export, svc, OUTPUT_ROOT .. "/" .. label)
if not serviceOk then
print("ERROR: Failed to export service " .. label .. " - " .. tostring(serviceErr))
else
print("=== Completed " .. label .. " ===")
end
else
print("WARNING: Service " .. label .. " not found or is nil")
end
end
print("\n> Finished! Exported " .. exportCount .. " scripts to \"" .. OUTPUT_ROOT .. "\".")