mcdevs-wiki-extractor 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +14 -0
- package/.github/workflows/ci.yml +25 -0
- package/.github/workflows/commands.yml +22 -0
- package/.github/workflows/publish.yml +34 -0
- package/README.md +35 -3
- package/bin/entities_to_json.js +12 -12
- package/bin/protocol_comments_to_json.js +11 -11
- package/bin/protocol_to_json.js +11 -11
- package/index.js +4 -4
- package/lib/common/table_parser.js +75 -95
- package/lib/common/toOldNames.js +98 -0
- package/lib/entities_extractor.js +54 -48
- package/lib/protocol_extractor.js +286 -428
- package/lib/relink.js +10 -0
- package/package.json +8 -4
- package/test/test_protocol_extractor.js +220 -221
- package/.npmignore +0 -1
- package/circle.yml +0 -3
|
@@ -1,543 +1,401 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const WikiTextParser = require('parse-wikitext')
|
|
2
|
+
const async = require('async')
|
|
3
|
+
const R = require('ramda')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const pandoc = require('pdc')
|
|
6
|
+
const path = require('path')
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
const wikiTextParser = new WikiTextParser('wiki.vg')
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const parseWikiTable = require('./common/table_parser').parseWikiTable
|
|
11
|
+
const getFirstTable = require('./common/table_parser').getFirstTable
|
|
12
|
+
const tableToRows = require('./common/table_parser').tableToRows
|
|
13
|
+
const toOldNames = require('./common/toOldNames').transformPacketName
|
|
10
14
|
|
|
11
15
|
module.exports = {
|
|
12
|
-
tableToRows:tableToRows,
|
|
13
|
-
parseWikiTable:parseWikiTable,
|
|
14
|
-
tableToPacket:tableToPacket,
|
|
15
|
-
writeProtocol:writeProtocol,
|
|
16
|
-
writeComments:writeComments
|
|
17
|
-
}
|
|
16
|
+
tableToRows: tableToRows,
|
|
17
|
+
parseWikiTable: parseWikiTable,
|
|
18
|
+
tableToPacket: tableToPacket,
|
|
19
|
+
writeProtocol: writeProtocol,
|
|
20
|
+
writeComments: writeComments
|
|
21
|
+
}
|
|
18
22
|
|
|
19
|
-
function writeComments(protocolFilePath,cb)
|
|
20
|
-
{
|
|
23
|
+
function writeComments (protocolFilePath, cb) {
|
|
21
24
|
async.waterfall([
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
25
|
+
getProtocolComments
|
|
26
|
+
],
|
|
27
|
+
function (err, protocol) {
|
|
28
|
+
if (err) { return cb(err) }
|
|
29
|
+
// console.log(JSON.stringify(protocol,null,2));
|
|
30
|
+
fs.writeFile(protocolFilePath, JSON.stringify(protocol, null, 2), cb)
|
|
31
|
+
}
|
|
32
|
+
)
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
function writeProtocol(protocolFilePath,cb)
|
|
35
|
-
{
|
|
35
|
+
function writeProtocol (protocolFilePath, cb) {
|
|
36
36
|
async.waterfall([
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
);
|
|
37
|
+
getProtocol
|
|
38
|
+
],
|
|
39
|
+
function (err, protocol) {
|
|
40
|
+
if (err) { return cb(err) }
|
|
41
|
+
// console.log(JSON.stringify(protocol,null,2));
|
|
42
|
+
fs.writeFile(protocolFilePath, JSON.stringify(protocol, null, 2), cb)
|
|
43
|
+
}
|
|
44
|
+
)
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
function
|
|
50
|
-
{
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
cb(err);
|
|
55
|
-
return;
|
|
47
|
+
function retrieveProtocol (cb) {
|
|
48
|
+
wikiTextParser.getArticle('Protocol', function (err, data) {
|
|
49
|
+
if (err) {
|
|
50
|
+
cb(err)
|
|
51
|
+
return
|
|
56
52
|
}
|
|
57
|
-
|
|
58
|
-
cb(err,sectionObject)
|
|
59
|
-
})
|
|
53
|
+
const sectionObject = wikiTextParser.pageToSectionObject(data)
|
|
54
|
+
cb(err, sectionObject)
|
|
55
|
+
})
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
function getProtocol(cb) {
|
|
58
|
+
function getProtocol (cb) {
|
|
63
59
|
async.waterfall([
|
|
64
60
|
retrieveProtocol,
|
|
65
61
|
extractProtocol.bind(null, parsePacket),
|
|
66
|
-
transformProtocol.bind(null, initialPacket, appendPacketToProto, transformPacket,
|
|
67
|
-
],cb)
|
|
62
|
+
transformProtocol.bind(null, initialPacket, appendPacketToProto, transformPacket, toOldNames)
|
|
63
|
+
], cb)
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
function getProtocolComments(cb) {
|
|
66
|
+
function getProtocolComments (cb) {
|
|
71
67
|
async.waterfall([
|
|
72
68
|
retrieveProtocol,
|
|
73
69
|
extractProtocol.bind(null, commentsForPacket),
|
|
74
|
-
transformProtocol.bind(null, function() { return {}
|
|
75
|
-
],cb)
|
|
70
|
+
transformProtocol.bind(null, function () { return {} }, function (obj, name, v) { obj[name] = v; return obj }, function (v) { return v }, toOldNames)
|
|
71
|
+
], cb)
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
function extractProtocol(fnPacket, sectionObject,cb)
|
|
79
|
-
|
|
80
|
-
var notStates = ["content", "Definitions", "Packet format"];
|
|
81
|
-
|
|
82
|
-
var protocol = Object
|
|
83
|
-
.keys(sectionObject)
|
|
84
|
-
.filter(function(key) {
|
|
85
|
-
return notStates.indexOf(key) == -1;
|
|
86
|
-
})
|
|
87
|
-
.reduce(function(protocol, state) {
|
|
88
|
-
protocol[state] = Object
|
|
89
|
-
.keys(sectionObject[state])
|
|
90
|
-
.filter(function(key) {
|
|
91
|
-
return key != "content"
|
|
92
|
-
})
|
|
93
|
-
.reduce(function(stateO, direction) {
|
|
94
|
-
stateO[direction] = Object
|
|
95
|
-
.keys(sectionObject[state][direction])
|
|
96
|
-
.filter(function(key) {
|
|
97
|
-
return key != "content"
|
|
98
|
-
})
|
|
99
|
-
.reduce(function(packetsO, packetName) {
|
|
100
|
-
packetsO[packetName] = fnPacket(sectionObject[state][direction][packetName]['content']);
|
|
101
|
-
return packetsO;
|
|
102
|
-
}, {});
|
|
103
|
-
return stateO;
|
|
104
|
-
}, {});
|
|
105
|
-
return protocol;
|
|
106
|
-
}, {});
|
|
74
|
+
function extractProtocol (fnPacket, sectionObject, cb) {
|
|
75
|
+
const notStates = R.omit(['content', 'Definitions', 'Packet format'])
|
|
107
76
|
|
|
108
|
-
|
|
77
|
+
async.mapValues(notStates(sectionObject), function (state, stateName, cb) {
|
|
78
|
+
async.mapValues(notStates(state), function (direction, directionName, cb) {
|
|
79
|
+
async.mapValues(notStates(direction), function (packet, packetName, cb) {
|
|
80
|
+
fnPacket(packet.content, cb)
|
|
81
|
+
}, cb)
|
|
82
|
+
}, cb)
|
|
83
|
+
}, cb)
|
|
109
84
|
}
|
|
110
85
|
|
|
111
|
-
function commentsForPacket(packetText) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if(!afterFirstTable && line
|
|
118
|
-
inTable=
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
86
|
+
function commentsForPacket (packetText, cb) {
|
|
87
|
+
let afterFirstTable = false
|
|
88
|
+
let inTable = false
|
|
89
|
+
const table = parseWikiTable(getFirstTable(packetText))
|
|
90
|
+
const id = table.length > 0 && table[0]['Packet ID'] && table[0]['Packet ID'].toLowerCase()
|
|
91
|
+
const packet = packetText.reduce(function (acc, line) {
|
|
92
|
+
if (!afterFirstTable && line === '{| class="wikitable"') { inTable = true } else if (inTable && line === ' |}') {
|
|
93
|
+
inTable = false
|
|
94
|
+
afterFirstTable = true
|
|
95
|
+
} else if (afterFirstTable) { acc.after.push(line) } else if (!inTable) { acc.before.push(line) }
|
|
96
|
+
return acc
|
|
97
|
+
}, { before: [], after: [], id: id })
|
|
98
|
+
pandoc(packet.before.join('\n'), 'mediawiki', 'markdown_github', ['-F', path.join(__dirname, 'relink.js')], function (err, result) {
|
|
99
|
+
if (err) return cb(err)
|
|
100
|
+
packet.before = result.split('\n')
|
|
101
|
+
pandoc(packet.after.join('\n'), 'mediawiki', 'markdown_github', ['-F', path.join(__dirname, 'relink.js')], function (err, result) {
|
|
102
|
+
if (err) return cb(err)
|
|
103
|
+
packet.after = result.split('\n')
|
|
104
|
+
return cb(null, packet)
|
|
105
|
+
})
|
|
106
|
+
})
|
|
129
107
|
}
|
|
130
108
|
|
|
131
|
-
function parsePacket(packetText)
|
|
132
|
-
|
|
133
|
-
return tableToPacket(parseWikiTable(getFirstTable(packetText)));
|
|
109
|
+
function parsePacket (packetText, cb) {
|
|
110
|
+
cb(null, tableToPacket(parseWikiTable(getFirstTable(packetText))))
|
|
134
111
|
}
|
|
135
112
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
packet["fields"]=table
|
|
144
|
-
.filter(function(value){
|
|
145
|
-
return !value["Field Name"] || value["Field Name"]!="''no fields''"
|
|
113
|
+
function tableToPacket (table) {
|
|
114
|
+
const packet = {}
|
|
115
|
+
if (table.length === 0 || table[0]['Packet ID'] === undefined) { return null }
|
|
116
|
+
packet.id = table[0]['Packet ID']
|
|
117
|
+
packet.fields = table
|
|
118
|
+
.filter(function (value) {
|
|
119
|
+
return !value['Field Name'] || value['Field Name'] !== "''no fields''"
|
|
146
120
|
})
|
|
147
|
-
.map(function(value){
|
|
148
|
-
|
|
149
|
-
//console.log(value);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return packet
|
|
121
|
+
.map(function (value) {
|
|
122
|
+
if (value['Field Name'] === undefined || value['Field Type'] === undefined) {
|
|
123
|
+
// console.log(value);
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
name: value['Field Name'],
|
|
128
|
+
type: value['Field Type']
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
return packet
|
|
158
132
|
}
|
|
159
133
|
|
|
160
|
-
function initialPacket() {
|
|
134
|
+
function initialPacket () {
|
|
161
135
|
return {
|
|
162
136
|
types: {
|
|
163
137
|
packet: ['container', [
|
|
164
138
|
{
|
|
165
|
-
name:
|
|
166
|
-
type: [
|
|
167
|
-
type:
|
|
139
|
+
name: 'name',
|
|
140
|
+
type: ['mapper', {
|
|
141
|
+
type: 'varint',
|
|
168
142
|
mappings: {}
|
|
169
143
|
}]
|
|
170
144
|
}, {
|
|
171
|
-
name:
|
|
172
|
-
type: [
|
|
173
|
-
compareTo:
|
|
145
|
+
name: 'params',
|
|
146
|
+
type: ['switch', {
|
|
147
|
+
compareTo: 'name',
|
|
174
148
|
fields: {}
|
|
175
149
|
}]
|
|
176
150
|
}
|
|
177
151
|
]]
|
|
178
152
|
}
|
|
179
|
-
}
|
|
153
|
+
}
|
|
180
154
|
}
|
|
181
155
|
|
|
182
|
-
function appendPacketToProto(state, name, packet) {
|
|
183
|
-
state.types[
|
|
184
|
-
state.types.packet[1][0].type[1].mappings[packet.id] = name
|
|
185
|
-
state.types.packet[1][1].type[1].fields[name] =
|
|
186
|
-
return state
|
|
156
|
+
function appendPacketToProto (state, name, packet) {
|
|
157
|
+
state.types['packet_' + name] = ['container', packet.fields]
|
|
158
|
+
state.types.packet[1][0].type[1].mappings[packet.id] = name
|
|
159
|
+
state.types.packet[1][1].type[1].fields[name] = 'packet_' + name
|
|
160
|
+
return state
|
|
187
161
|
}
|
|
188
162
|
|
|
189
163
|
// transforms
|
|
190
|
-
function transformProtocol(initialState, addToPacket, transformPacket, transformPacketName, protocol,cb)
|
|
191
|
-
|
|
192
|
-
var transformedProtocol = Object
|
|
164
|
+
function transformProtocol (initialState, addToPacket, transformPacket, transformPacketName, protocol, cb) {
|
|
165
|
+
let transformedProtocol = Object
|
|
193
166
|
.keys(protocol)
|
|
194
|
-
.reduce(function(transformedProtocol, state) {
|
|
195
|
-
|
|
167
|
+
.reduce(function (transformedProtocol, state) {
|
|
168
|
+
const transformedState = transformState(state)
|
|
196
169
|
transformedProtocol[transformedState] = Object
|
|
197
170
|
.keys(protocol[state])
|
|
198
|
-
.reduce(function(stateO, direction) {
|
|
199
|
-
|
|
171
|
+
.reduce(function (stateO, direction) {
|
|
172
|
+
const transformedDirection = transformDirection(direction)
|
|
200
173
|
stateO[transformedDirection] = Object
|
|
201
174
|
.keys(protocol[state][direction])
|
|
202
|
-
.reduce(function(packetsO, packetName) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return addToPacket(packetsO, transformedPacketName, transformedPacket)
|
|
206
|
-
}, initialState())
|
|
207
|
-
return stateO
|
|
208
|
-
}, {})
|
|
209
|
-
return transformedProtocol
|
|
210
|
-
}, {})
|
|
211
|
-
transformedProtocol=reorder([
|
|
212
|
-
cb(null,transformedProtocol)
|
|
175
|
+
.reduce(function (packetsO, packetName) {
|
|
176
|
+
const transformedPacket = transformPacket(protocol[state][direction][packetName], transformedState, transformedDirection)
|
|
177
|
+
const transformedPacketName = transformPacketName(packetName, transformedState, transformedDirection, transformedPacket ? transformedPacket.id : null)
|
|
178
|
+
return addToPacket(packetsO, transformedPacketName, transformedPacket)
|
|
179
|
+
}, initialState())
|
|
180
|
+
return stateO
|
|
181
|
+
}, {})
|
|
182
|
+
return transformedProtocol
|
|
183
|
+
}, {})
|
|
184
|
+
transformedProtocol = reorder(['handshaking', 'status', 'login', 'play'], transformedProtocol)
|
|
185
|
+
cb(null, transformedProtocol)
|
|
213
186
|
}
|
|
214
187
|
|
|
215
188
|
function reorder (order, obj) {
|
|
216
|
-
return order.reduce
|
|
217
|
-
rslt[prop] = obj[prop]
|
|
218
|
-
return rslt
|
|
219
|
-
}, {})
|
|
189
|
+
return order.reduce(function (rslt, prop) {
|
|
190
|
+
rslt[prop] = obj[prop]
|
|
191
|
+
return rslt
|
|
192
|
+
}, {})
|
|
220
193
|
}
|
|
221
194
|
|
|
222
|
-
function transformPacket(packet,state,direction)
|
|
223
|
-
{
|
|
224
|
-
|
|
225
|
-
return null;
|
|
226
|
-
var transformedId=transformId(packet["id"]);
|
|
195
|
+
function transformPacket (packet, state, direction) {
|
|
196
|
+
if (!packet) { return null }
|
|
197
|
+
const transformedId = transformId(packet.id)
|
|
227
198
|
return {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function transformId(id)
|
|
234
|
-
{
|
|
235
|
-
return id ? id.toLowerCase() : null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function transformField(field,state,direction,id)
|
|
239
|
-
{
|
|
240
|
-
return field ? {
|
|
241
|
-
"name":transformFieldName(field["name"],state,direction,id),
|
|
242
|
-
"type":transformFieldType(field["type"])
|
|
243
|
-
} : null;
|
|
199
|
+
id: transformedId,
|
|
200
|
+
fields: packet.fields ? packet.fields.map(function (field) { return transformField(field, state, direction, transformedId) }) : null
|
|
201
|
+
}
|
|
244
202
|
}
|
|
245
203
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
{
|
|
249
|
-
return state.toLowerCase();
|
|
204
|
+
function transformId (id) {
|
|
205
|
+
return id ? id.toLowerCase() : null
|
|
250
206
|
}
|
|
251
207
|
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
208
|
+
function transformField (field, state, direction, id) {
|
|
209
|
+
return field
|
|
210
|
+
? {
|
|
211
|
+
name: transformFieldName(field.name, state, direction, id),
|
|
212
|
+
type: transformFieldType(field.type)
|
|
213
|
+
}
|
|
214
|
+
: null
|
|
256
215
|
}
|
|
257
216
|
|
|
258
|
-
function
|
|
259
|
-
|
|
260
|
-
return name.split(" ").map(function(word){return word.toLowerCase();}).join("_");
|
|
217
|
+
function transformState (state) {
|
|
218
|
+
return state.toLowerCase()
|
|
261
219
|
}
|
|
262
220
|
|
|
263
|
-
function
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
words[0]=words[0].toLowerCase();
|
|
267
|
-
for(i=1;i<words.length;i++) words[i]=words[i].charAt(0).toUpperCase()+words[i].slice(1).toLowerCase();
|
|
268
|
-
return words.join("");
|
|
221
|
+
function transformDirection (direction) {
|
|
222
|
+
if (direction === 'Serverbound') return 'toServer'
|
|
223
|
+
if (direction === 'Clientbound') return 'toClient'
|
|
269
224
|
}
|
|
270
225
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
},
|
|
277
|
-
"status": {
|
|
278
|
-
"toClient": {
|
|
279
|
-
"response":"server_info",
|
|
280
|
-
"pong":"ping"
|
|
281
|
-
},
|
|
282
|
-
"toServer": {
|
|
283
|
-
"request":"ping_start"
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
"login": {
|
|
287
|
-
"toClient": {
|
|
288
|
-
"disconnect":"disconnect",
|
|
289
|
-
"encryption_request":"encryption_begin",
|
|
290
|
-
"login_success":"success",
|
|
291
|
-
"set_compression":"compress"
|
|
292
|
-
},
|
|
293
|
-
"toServer": {
|
|
294
|
-
"encryption_response":"encryption_begin"
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
"play": {
|
|
298
|
-
"toClient":{
|
|
299
|
-
"join_game":"login",
|
|
300
|
-
"chat_message":"chat",
|
|
301
|
-
"time_update":"update_time",
|
|
302
|
-
"player_position_and_look":"position",
|
|
303
|
-
"held_item_change":"held_item_slot",
|
|
304
|
-
"use_bed":"bed",
|
|
305
|
-
"spawn_player":"named_entity_spawn",
|
|
306
|
-
"collect_item":"collect",
|
|
307
|
-
"spawn_object":"spawn_entity",
|
|
308
|
-
"spawn_mob":"spawn_entity_living",
|
|
309
|
-
"spawn_painting":"spawn_entity_painting",
|
|
310
|
-
"spawn_experience_orb":"spawn_entity_experience_orb",
|
|
311
|
-
"destroy_entities":"entity_destroy",
|
|
312
|
-
"entity_relative_move":"rel_entity_move",
|
|
313
|
-
"entity_look_and_relative_move":"entity_move_look",
|
|
314
|
-
"entity_head_look":"entity_head_rotation",
|
|
315
|
-
"set_experience":"experience",
|
|
316
|
-
"entity_properties":"entity_update_attributes",
|
|
317
|
-
"chunk_data":"map_chunk",
|
|
318
|
-
"effect":"world_event",
|
|
319
|
-
"particle":"world_particles",
|
|
320
|
-
"change_game_state":"game_state_change",
|
|
321
|
-
"spawn_global_entity":"spawn_entity_weather",
|
|
322
|
-
"window_property":"craft_progress_bar",
|
|
323
|
-
"confirm_transaction":"transaction",
|
|
324
|
-
"update_block_entity":"tile_entity_data",
|
|
325
|
-
"open_sign_editor":"open_sign_entity",
|
|
326
|
-
"player_list_item":"player_info",
|
|
327
|
-
"player_abilities":"abilities",
|
|
328
|
-
"update_score":"scoreboard_score",
|
|
329
|
-
"display_scoreboard":"scoreboard_display_objective",
|
|
330
|
-
"plugin_message":"custom_payload",
|
|
331
|
-
"disconnect":"kick_disconnect",
|
|
332
|
-
"server_difficulty":"difficulty",
|
|
333
|
-
"player_list_header_and_footer":"playerlist_header"
|
|
334
|
-
},
|
|
335
|
-
"toServer": {
|
|
336
|
-
"chat_message":"chat",
|
|
337
|
-
"player":"flying",
|
|
338
|
-
"player_position":"position",
|
|
339
|
-
"player_look":"look",
|
|
340
|
-
"player_position_and_look":"position_look",
|
|
341
|
-
"player_digging":"block_dig",
|
|
342
|
-
"player_block_placement":"block_place",
|
|
343
|
-
"held_item_change":"held_item_slot",
|
|
344
|
-
"animation":"arm_animation",
|
|
345
|
-
"click_window":"window_click",
|
|
346
|
-
"confirm_transaction":"transaction",
|
|
347
|
-
"creative_inventory_action":"set_creative_slot",
|
|
348
|
-
"player_abilities":"abilities",
|
|
349
|
-
"client_settings":"settings",
|
|
350
|
-
"client_status":"client_command",
|
|
351
|
-
"plugin_message":"custom_payload",
|
|
352
|
-
"resource_pack_status":"resource_pack_receive"
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
function toOldNames(name,state,direction)
|
|
358
|
-
{
|
|
359
|
-
var x = oldNames[state] && oldNames[state][direction] && oldNames[state][direction][name] ? oldNames[state][direction][name] : name;
|
|
360
|
-
console.log(state, direction, name, x);
|
|
361
|
-
return x;
|
|
226
|
+
function toCamelCase (name) {
|
|
227
|
+
const words = name.split(' ')
|
|
228
|
+
words[0] = words[0].toLowerCase()
|
|
229
|
+
for (let i = 1; i < words.length; i++) words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1).toLowerCase()
|
|
230
|
+
return words.join('')
|
|
362
231
|
}
|
|
363
232
|
|
|
364
|
-
function
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
fieldType
|
|
372
|
-
|
|
373
|
-
if(fieldType.indexOf(
|
|
374
|
-
if(fieldType.indexOf(
|
|
375
|
-
if(fieldType.indexOf(
|
|
376
|
-
if(fieldType.indexOf(
|
|
377
|
-
if(fieldType.indexOf(
|
|
378
|
-
if(fieldType.indexOf(
|
|
379
|
-
|
|
380
|
-
if(fieldType.indexOf("short")!=-1) return "i16";
|
|
381
|
-
if(fieldType.indexOf("uint")!=-1) return "u32";
|
|
382
|
-
if(fieldType.indexOf("int")!=-1) return "i32";
|
|
383
|
-
if(fieldType.indexOf("ulong")!=-1) return "u64";
|
|
384
|
-
if(fieldType.indexOf("long")!=-1) return "i64";
|
|
385
|
-
return fieldType;
|
|
233
|
+
function transformFieldType (fieldType) {
|
|
234
|
+
fieldType = fieldType.toLowerCase().replace('unsigned ', 'u').replace('boolean', 'bool').replace('[[chat]]', 'string')
|
|
235
|
+
.replace('angle', 'byte').replace('uuid', 'UUID')
|
|
236
|
+
if (fieldType.indexOf('varint') !== -1) return 'varint'
|
|
237
|
+
if (fieldType.indexOf('slot') !== -1) return 'slot'
|
|
238
|
+
if (fieldType.indexOf('entity metadata') !== -1) return 'entityMetadata'
|
|
239
|
+
if (fieldType.indexOf('nbt') !== -1) return 'restBuffer'
|
|
240
|
+
if (fieldType.indexOf('ubyte') !== -1) return 'u8'
|
|
241
|
+
if (fieldType.indexOf('byte') !== -1) return 'i8'
|
|
242
|
+
if (fieldType.indexOf('ushort') !== -1) return 'u16'
|
|
243
|
+
if (fieldType.indexOf('short') !== -1) return 'i16'
|
|
244
|
+
if (fieldType.indexOf('uint') !== -1) return 'u32'
|
|
245
|
+
if (fieldType.indexOf('int') !== -1) return 'i32'
|
|
246
|
+
if (fieldType.indexOf('ulong') !== -1) return 'u64'
|
|
247
|
+
if (fieldType.indexOf('long') !== -1) return 'i64'
|
|
248
|
+
return fieldType
|
|
386
249
|
}
|
|
387
250
|
|
|
388
251
|
// specific has priority over general
|
|
389
252
|
|
|
390
253
|
// specific
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
254
|
+
const newToOldFieldNamesSpecific = {
|
|
255
|
+
status: {
|
|
256
|
+
toClient: {
|
|
257
|
+
'0x01': {
|
|
258
|
+
payload: 'time'
|
|
396
259
|
}
|
|
397
260
|
},
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
261
|
+
toServer: {
|
|
262
|
+
'0x01': {
|
|
263
|
+
payload: 'time'
|
|
401
264
|
}
|
|
402
265
|
}
|
|
403
266
|
},
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
267
|
+
login: {
|
|
268
|
+
toServer: {
|
|
269
|
+
'0x00': {
|
|
270
|
+
name: 'username'
|
|
408
271
|
}
|
|
409
272
|
}
|
|
410
273
|
},
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
274
|
+
play: {
|
|
275
|
+
toClient: {
|
|
276
|
+
'0x01': {
|
|
277
|
+
gamemode: 'gameMode'
|
|
415
278
|
},
|
|
416
|
-
|
|
417
|
-
|
|
279
|
+
'0x0e': {
|
|
280
|
+
data: 'objectData'
|
|
418
281
|
},
|
|
419
|
-
|
|
420
|
-
|
|
282
|
+
'0x21': {
|
|
283
|
+
data: 'chunkData'
|
|
421
284
|
},
|
|
422
|
-
|
|
423
|
-
|
|
285
|
+
'0x2b': {
|
|
286
|
+
value: 'gameMode'
|
|
424
287
|
},
|
|
425
|
-
|
|
426
|
-
|
|
288
|
+
'0x2f': {
|
|
289
|
+
slotData: 'item'
|
|
427
290
|
},
|
|
428
|
-
|
|
429
|
-
|
|
291
|
+
'0x30': {
|
|
292
|
+
slotData: 'items'
|
|
430
293
|
},
|
|
431
|
-
|
|
432
|
-
|
|
294
|
+
'0x32': {
|
|
295
|
+
actionNumber: 'action'
|
|
433
296
|
},
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
297
|
+
'0x3b': {
|
|
298
|
+
mode: 'action',
|
|
299
|
+
objectiveName: 'name'
|
|
437
300
|
},
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
301
|
+
'0x3c': {
|
|
302
|
+
scoreName: 'itemName',
|
|
303
|
+
objectiveName: 'scoreName'
|
|
441
304
|
},
|
|
442
|
-
|
|
443
|
-
|
|
305
|
+
'0x3d': {
|
|
306
|
+
scoreName: 'name'
|
|
444
307
|
}
|
|
445
308
|
},
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
309
|
+
toServer: {
|
|
310
|
+
'0x02': {
|
|
311
|
+
type: 'mouse'
|
|
449
312
|
},
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
313
|
+
'0x08': {
|
|
314
|
+
face: 'direction',
|
|
315
|
+
cursorPositionX: 'cursorX',
|
|
316
|
+
cursorPositionY: 'cursorY',
|
|
317
|
+
cursorPositionZ: 'cursorZ'
|
|
455
318
|
},
|
|
456
|
-
|
|
457
|
-
|
|
319
|
+
'0x09': {
|
|
320
|
+
slot: 'slotId'
|
|
458
321
|
},
|
|
459
|
-
|
|
460
|
-
|
|
322
|
+
'0x0b': {
|
|
323
|
+
payload: 'actionId'
|
|
461
324
|
},
|
|
462
|
-
|
|
463
|
-
|
|
325
|
+
'0x0c': {
|
|
326
|
+
flags: 'jump'
|
|
464
327
|
},
|
|
465
|
-
|
|
466
|
-
|
|
328
|
+
'0x0e': {
|
|
329
|
+
actionNumber: 'action'
|
|
467
330
|
},
|
|
468
|
-
|
|
469
|
-
|
|
331
|
+
'0x0f': {
|
|
332
|
+
actionNumber: 'action'
|
|
470
333
|
},
|
|
471
|
-
|
|
472
|
-
|
|
334
|
+
'0x16': {
|
|
335
|
+
actionId: 'payload'
|
|
473
336
|
}
|
|
474
337
|
}
|
|
475
338
|
}
|
|
476
|
-
}
|
|
339
|
+
}
|
|
477
340
|
|
|
478
341
|
// should probably be converted entirely in the specific format
|
|
479
342
|
// general
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
};
|
|
526
|
-
|
|
527
|
-
function toOldFieldName(fieldName,state,direction,id)
|
|
528
|
-
{
|
|
529
|
-
if(newToOldFieldNamesSpecific[state]
|
|
530
|
-
&& newToOldFieldNamesSpecific[state][direction]
|
|
531
|
-
&& newToOldFieldNamesSpecific[state][direction][id]
|
|
532
|
-
&& newToOldFieldNamesSpecific[state][direction][id][fieldName])
|
|
533
|
-
return newToOldFieldNamesSpecific[state][direction][id][fieldName];
|
|
534
|
-
if(newToOldFieldNamesGeneral[fieldName])
|
|
535
|
-
return newToOldFieldNamesGeneral[fieldName];
|
|
536
|
-
return fieldName;
|
|
343
|
+
const newToOldFieldNamesGeneral = {
|
|
344
|
+
serverAddress: 'serverHost',
|
|
345
|
+
jsonResponse: 'response',
|
|
346
|
+
jsonData: 'message',
|
|
347
|
+
worldAge: 'age',
|
|
348
|
+
timeOfDay: 'time',
|
|
349
|
+
playerUuid: 'playerUUID',
|
|
350
|
+
deltaX: 'dX',
|
|
351
|
+
deltaY: 'dY',
|
|
352
|
+
deltaZ: 'dZ',
|
|
353
|
+
chunkX: 'x',
|
|
354
|
+
chunkZ: 'z',
|
|
355
|
+
'ground-upContinuous': 'groundUp',
|
|
356
|
+
primaryBitMask: 'bitMap',
|
|
357
|
+
size: 'chunkDataLength',
|
|
358
|
+
blockId: 'type',
|
|
359
|
+
blockType: 'blockId',
|
|
360
|
+
recordCount: 'count',
|
|
361
|
+
records: 'affectedBlockOffsets',
|
|
362
|
+
disableRelativeVolume: 'global',
|
|
363
|
+
effectPositionX: 'x',
|
|
364
|
+
effectPositionY: 'y',
|
|
365
|
+
effectPositionZ: 'z',
|
|
366
|
+
particleCount: 'particles',
|
|
367
|
+
windowType: 'inventoryType',
|
|
368
|
+
numberOfSlots: 'slotCount',
|
|
369
|
+
line1: 'text1',
|
|
370
|
+
line2: 'text2',
|
|
371
|
+
line3: 'text3',
|
|
372
|
+
line4: 'text4',
|
|
373
|
+
objectiveValue: 'displayText',
|
|
374
|
+
teamName: 'team',
|
|
375
|
+
teamDisplayName: 'name',
|
|
376
|
+
teamPrefix: 'prefix',
|
|
377
|
+
teamSuffix: 'suffix',
|
|
378
|
+
targetX: 'x',
|
|
379
|
+
targetY: 'y',
|
|
380
|
+
targetZ: 'z',
|
|
381
|
+
feetY: 'y',
|
|
382
|
+
button: 'mouseButton',
|
|
383
|
+
clickedItem: 'item',
|
|
384
|
+
lookedAtBlock: 'block',
|
|
385
|
+
chatMode: 'chatFlags',
|
|
386
|
+
displayedSkinParts: 'skinParts',
|
|
387
|
+
targetPlayer: 'target'
|
|
537
388
|
}
|
|
538
389
|
|
|
539
|
-
function
|
|
540
|
-
|
|
541
|
-
|
|
390
|
+
function toOldFieldName (fieldName, state, direction, id) {
|
|
391
|
+
if (newToOldFieldNamesSpecific[state] &&
|
|
392
|
+
newToOldFieldNamesSpecific[state][direction] &&
|
|
393
|
+
newToOldFieldNamesSpecific[state][direction][id] &&
|
|
394
|
+
newToOldFieldNamesSpecific[state][direction][id][fieldName]) { return newToOldFieldNamesSpecific[state][direction][id][fieldName] }
|
|
395
|
+
if (newToOldFieldNamesGeneral[fieldName]) { return newToOldFieldNamesGeneral[fieldName] }
|
|
396
|
+
return fieldName
|
|
542
397
|
}
|
|
543
398
|
|
|
399
|
+
function transformFieldName (fieldName, state, direction, id) {
|
|
400
|
+
return toOldFieldName(toCamelCase(fieldName), state, direction, id)
|
|
401
|
+
}
|