/
DataModelBrowser.go
165 lines (140 loc) · 5.5 KB
/
DataModelBrowser.go
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package main
import (
"fmt"
"os"
"github.com/Gskartwii/roblox-dissector/datamodel"
"github.com/Gskartwii/roblox-dissector/peer"
"github.com/robloxapi/rbxfile"
"github.com/robloxapi/rbxfile/xml"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
)
func showChildren(rootNode *gui.QStandardItem, children []*datamodel.Instance) {
for _, instance := range children {
row := showReplicationInstance(instance, instance.Parent())
instance.PropertiesMutex.RLock()
if len(instance.Properties) > 0 {
row[0].AppendRow([]*gui.QStandardItem{showProperties(instance.Properties, 0)})
}
instance.PropertiesMutex.RUnlock()
if len(instance.Children) > 0 {
childrenRootItem := NewQStandardItemF("%d children", len(instance.Children))
showChildren(childrenRootItem, instance.Children)
row[0].AppendRow([]*gui.QStandardItem{childrenRootItem, nil, nil, nil, nil, nil})
}
rootNode.AppendRow(row)
}
}
type InstanceProperty struct {
Instance *rbxfile.Instance
Name string
}
func findScripts(instances []*rbxfile.Instance, propertyList []InstanceProperty) []InstanceProperty {
for _, instance := range instances {
for name, property := range instance.Properties {
thisType := property.Type()
if thisType == rbxfile.TypeProtectedString {
propertyList = append(propertyList, InstanceProperty{
Instance: instance,
Name: name,
})
}
}
propertyList = findScripts(instance.Children, propertyList)
}
return propertyList
}
func dumpScripts(location string, instances []*rbxfile.Instance, parent widgets.QWidget_ITF) error {
instList := findScripts(instances, nil)
progressDialog := widgets.NewQProgressDialog2("Dumping scripts...", "Cancel", 0, len(instList), parent, 0)
progressDialog.SetWindowTitle("Dumping scripts")
progressDialog.SetWindowModality(core.Qt__WindowModal)
for i, instProp := range instList {
file, err := os.Create(fmt.Sprintf("%s/%s.%d.rbxc", location, instProp.Instance.GetFullName(), i))
if err != nil {
progressDialog.Cancel()
return err
}
_, err = file.Write([]byte(instProp.Instance.Properties[instProp.Name].(rbxfile.ValueProtectedString)))
if err != nil {
progressDialog.Cancel()
return err
}
err = file.Close()
if err != nil {
progressDialog.Cancel()
return err
}
// HACK: We clear the script source here to prevent issues with the XML parser
// This may be unexpected in the case of Studio, where the source code is not protected
delete(instProp.Instance.Properties, instProp.Name)
if progressDialog.WasCanceled() {
return nil
}
progressDialog.SetValue(i)
}
progressDialog.SetValue(len(instList))
return nil
}
func DumpDataModel(context *peer.CommunicationContext, parent widgets.QWidget_ITF) {
writableClone := context.DataModel.ToRbxfile()
location := widgets.QFileDialog_GetExistingDirectory(parent, "Select directory to dump DataModel to", "", 0)
writer, err := os.OpenFile(location+"/datamodel.rbxlx", os.O_RDWR|os.O_CREATE, 0666)
defer writer.Close()
if err != nil {
widgets.QMessageBox_Critical(parent, "Error while creating RBXLX", err.Error(), widgets.QMessageBox__Ok, widgets.QMessageBox__NoButton)
return
}
if LumikideEnabled {
err = LumikideProcessContext(parent, context, writableClone)
if err != nil {
widgets.QMessageBox_Critical(parent, "Error while processing with Lumikide", err.Error(), widgets.QMessageBox__Ok, widgets.QMessageBox__NoButton)
return
}
} else {
println("Lumikide disabled at compile time, skipping processing.")
}
scriptData, err := os.OpenFile(location+"/scriptKeys", os.O_RDWR|os.O_CREATE, 0666)
defer scriptData.Close()
if err != nil {
widgets.QMessageBox_Critical(parent, "Error while dumping script keys", err.Error(), widgets.QMessageBox__Ok, widgets.QMessageBox__NoButton)
return
}
_, err = fmt.Fprintf(scriptData, "Script key: %d\nCore script key: %d", context.ScriptKey, context.CoreScriptKey)
if err != nil {
widgets.QMessageBox_Critical(parent, "Error while dumping script keys", err.Error(), widgets.QMessageBox__Ok, widgets.QMessageBox__NoButton)
return
}
err = dumpScripts(location, writableClone.Instances, parent)
if err != nil {
widgets.QMessageBox_Critical(parent, "Error while dumping scripts", err.Error(), widgets.QMessageBox__Ok, widgets.QMessageBox__NoButton)
return
}
err = xml.Serialize(writer, nil, writableClone)
if err != nil {
widgets.QMessageBox_Critical(parent, "Error while serializing place", err.Error(), widgets.QMessageBox__Ok, widgets.QMessageBox__NoButton)
return
}
}
func NewDataModelBrowser(context *peer.CommunicationContext, dataModel *datamodel.DataModel, parent widgets.QWidget_ITF) {
subWindow := widgets.NewQWidget(parent, core.Qt__Window)
subWindowLayout := widgets.NewQVBoxLayout2(subWindow)
subWindowLayout.SetAlign(core.Qt__AlignTop)
subWindow.SetWindowTitle("Data Model")
takeSnapshotButton := widgets.NewQPushButton2("Dump DataModel (RBXLX) and scripts (RBXC)...", nil)
takeSnapshotButton.ConnectReleased(func() {
DumpDataModel(context, subWindow)
})
subWindowLayout.AddWidget(takeSnapshotButton, 0, 0)
instanceList := widgets.NewQTreeView(subWindow)
standardModel := NewProperSortModel(subWindow)
standardModel.SetHorizontalHeaderLabels([]string{"Name", "Type", "Value", "Reference", "Parent", "Path"})
rootNode := standardModel.InvisibleRootItem()
showChildren(rootNode, dataModel.Instances)
instanceList.SetModel(standardModel)
instanceList.SetSelectionMode(0)
instanceList.SetSortingEnabled(true)
subWindowLayout.AddWidget(instanceList, 0, 0)
subWindow.Show()
}