/
Packet97Callback.go
112 lines (88 loc) · 4.02 KB
/
Packet97Callback.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
package main
import (
"fmt"
"os"
"github.com/Gskartwii/roblox-dissector/peer"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
)
func ShowPacket97(layerLayout *widgets.QVBoxLayout, context *peer.CommunicationContext, layers *peer.PacketLayers) {
MainLayer := layers.Main.(*peer.Packet97Layer)
progress := 0
maxProgress := len(MainLayer.Schema.Enums) + len(MainLayer.Schema.Instances)
progressDialog := widgets.NewQProgressDialog2(fmt.Sprintf("Building schema view (%d enums, %d classes)", len(MainLayer.Schema.Enums), len(MainLayer.Schema.Instances)), "", 0, maxProgress, nil, 0)
progressDialog.SetCancelButton(nil)
progressDialog.SetWindowFilePath("Building schema view")
labelForEnumSchema := NewQLabelF("Enum schema (%d entries):", len(MainLayer.Schema.Enums))
layerLayout.AddWidget(labelForEnumSchema, 0, 0)
enumSchemaList := widgets.NewQTreeView(nil)
standardModel := NewProperSortModel(nil)
standardModel.SetHorizontalHeaderLabels([]string{"Name", "Size"})
enumSchemaRootNode := standardModel.InvisibleRootItem()
for _, item := range MainLayer.Schema.Enums {
nameItem := NewStringItem(item.Name)
sizeItem := NewUintItem(item.BitSize)
enumSchemaRootNode.AppendRow([]*gui.QStandardItem{nameItem, sizeItem})
progress++
progressDialog.SetValue(progress)
}
enumSchemaList.SetModel(standardModel)
enumSchemaList.SetSelectionMode(0)
enumSchemaList.SetSortingEnabled(true)
enumSchemaList.SortByColumn(0, core.Qt__AscendingOrder)
layerLayout.AddWidget(enumSchemaList, 0, 0)
labelForInstanceSchema := NewQLabelF("Instance schema (%d entries):", len(MainLayer.Schema.Instances))
layerLayout.AddWidget(labelForInstanceSchema, 0, 0)
instanceSchemaList := widgets.NewQTreeView(nil)
instanceModel := NewProperSortModel(nil)
instanceModel.SetHorizontalHeaderLabels([]string{"Name", "Type"})
instanceSchemaRootNode := instanceModel.InvisibleRootItem()
for _, item := range MainLayer.Schema.Instances {
nameItem := NewStringItem(item.Name)
instanceRow := []*gui.QStandardItem{nameItem, nil}
propertySchemaItem := NewQStandardItemF("Property schema (%d entries)", len(item.Properties))
for _, property := range item.Properties {
propertyNameItem := NewStringItem(property.Name)
propertyTypeItem := NewStringItem(property.TypeString)
propertyRow := []*gui.QStandardItem{propertyNameItem, propertyTypeItem}
propertySchemaItem.AppendRow(propertyRow)
}
nameItem.AppendRow([]*gui.QStandardItem{propertySchemaItem})
eventSchemaItem := NewQStandardItemF("Event schema (%d entries)", len(item.Events))
nameItem.AppendRow([]*gui.QStandardItem{eventSchemaItem})
for _, event := range item.Events {
eventNameItem := NewQStandardItemF("%s (%d arguments)", event.Name, len(event.Arguments))
eventRow := []*gui.QStandardItem{eventNameItem, nil}
for index, thisArgument := range event.Arguments {
eventArgumentNameItem := NewQStandardItemF("Event argument %d", index)
eventArgumentTypeItem := NewStringItem(thisArgument.TypeString)
eventSubIntRow := []*gui.QStandardItem{eventArgumentNameItem, eventArgumentTypeItem}
eventNameItem.AppendRow(eventSubIntRow)
}
eventSchemaItem.AppendRow(eventRow)
}
instanceSchemaRootNode.AppendRow(instanceRow)
progress++
progressDialog.SetValue(progress)
}
instanceSchemaList.SetModel(instanceModel)
instanceSchemaList.SetSelectionMode(0)
instanceSchemaList.SetSortingEnabled(true)
instanceSchemaList.SortByColumn(0, core.Qt__AscendingOrder)
layerLayout.AddWidget(instanceSchemaList, 0, 0)
dumpButton := widgets.NewQPushButton2("Dump...", nil)
dumpButton.ConnectReleased(func() {
schemaLocation := widgets.QFileDialog_GetSaveFileName(dumpButton, "Save schema...", "", "TXT files (*.txt)", "", 0)
schemaFile, err := os.OpenFile(schemaLocation, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
println("while opening file:", err.Error())
return
}
err = MainLayer.Schema.Dump(schemaFile)
if err != nil {
println("while encoding:", err.Error())
}
})
layerLayout.AddWidget(dumpButton, 0, 0)
}