-
-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support 1.21.3 #1347
support 1.21.3 #1347
Changes from 4 commits
42c687a
11d8dd2
fc763bb
60ba34d
e32ce27
27071c7
980465f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable no-return-assign */ | ||
const UUID = require('uuid-1345') | ||
const minecraft = require('./minecraft') | ||
|
||
|
@@ -41,7 +42,7 @@ module.exports = { | |
code += '}' | ||
return compiler.wrapCode(code) | ||
}], | ||
arrayWithLengthOffset: ['parametrizable', (compiler, array) => { | ||
arrayWithLengthOffset: ['parametrizable', (compiler, array) => { // TODO: remove | ||
let code = '' | ||
if (array.countType) { | ||
code += 'const { value: count, size: countSize } = ' + compiler.callType(array.countType) + '\n' | ||
|
@@ -61,6 +62,56 @@ module.exports = { | |
code += '}\n' | ||
code += 'return { value: data, size }' | ||
return compiler.wrapCode(code) | ||
}], | ||
bitflags: ['parametrizable', (compiler, { type, flags, shift, big }) => { | ||
let fstr = JSON.stringify(flags) | ||
if (Array.isArray(flags)) { | ||
fstr = '{' | ||
for (const [k, v] of Object.entries(flags)) fstr += `"${v}": ${big ? (1n << BigInt(k)) : (1 << k)}` + (big ? 'n,' : ',') | ||
fstr += '}' | ||
} else if (shift) { | ||
fstr = '{' | ||
for (const key in flags) fstr += `"${key}": ${1 << flags[key]},` | ||
fstr += '}' | ||
} | ||
return compiler.wrapCode(` | ||
const { value: _value, size } = ${compiler.callType(type, 'offset')} | ||
const value = { _value } | ||
const flags = ${fstr} | ||
for (const key in flags) { | ||
value[key] = (_value & flags[key]) == flags[key] | ||
} | ||
return { value, size } | ||
`.trim()) | ||
}], | ||
registryEntryHolder: ['parametrizable', (compiler, opts) => { | ||
return compiler.wrapCode(` | ||
const { value: n, size: nSize } = ${compiler.callType('varint')} | ||
if (n !== 0) { | ||
return { value: { ${opts.baseName}: n - 1 }, size: nSize } | ||
} else { | ||
const holder = ${compiler.callType(opts.otherwise.type)} | ||
return { value: { ${opts.otherwise.name}: holder.data }, size: nSize + holder.size } | ||
} | ||
`.trim()) | ||
}], | ||
registryEntryHolderSet: ['parametrizable', (compiler, opts) => { | ||
return compiler.wrapCode(` | ||
const { value: n, size: nSize } = ${compiler.callType('varint')} | ||
if (n === 0) { | ||
const base = ${compiler.callType(opts.base.type)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return { value: { ${opts.base.name}: base.value }, size: base.size + nSize } | ||
} else { | ||
const set = [] | ||
let accSize = nSize | ||
for (let i = 0; i < n - 1; i++) { | ||
const entry = ${compiler.callType(opts.otherwise.type)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
set.push(entry.value) | ||
accSize += entry.size | ||
} | ||
return { value: { ${opts.otherwise.name}: set }, size: accSize } | ||
} | ||
`.trim()) | ||
}] | ||
}, | ||
Write: { | ||
|
@@ -106,6 +157,58 @@ module.exports = { | |
code += '}\n' | ||
code += 'return offset' | ||
return compiler.wrapCode(code) | ||
}], | ||
bitflags: ['parametrizable', (compiler, { type, flags, shift, big }) => { | ||
let fstr = JSON.stringify(flags) | ||
if (Array.isArray(flags)) { | ||
fstr = '{' | ||
for (const [k, v] of Object.entries(flags)) fstr += `"${v}": ${big ? (1n << BigInt(k)) : (1 << k)}` + (big ? 'n,' : ',') | ||
fstr += '}' | ||
} else if (shift) { | ||
fstr = '{' | ||
for (const key in flags) fstr += `"${key}": ${1 << flags[key]},` | ||
fstr += '}' | ||
} | ||
return compiler.wrapCode(` | ||
const flags = ${fstr} | ||
let val = value._value ${big ? '|| 0n' : ''} | ||
for (const key in flags) { | ||
if (value[key]) val |= flags[key] | ||
} | ||
return (ctx.${type})(val, buffer, offset) | ||
`.trim()) | ||
}], | ||
registryEntryHolder: ['parametrizable', (compiler, opts) => { | ||
const baseName = `value.${opts.baseName}` | ||
const otherwiseName = `value.${opts.otherwise.name}` | ||
return compiler.wrapCode(` | ||
if (${baseName}) { | ||
offset = ${compiler.callType(`${baseName} + 1`, 'varint')} | ||
} else if (${otherwiseName}) { | ||
offset = ${compiler.callType(`${otherwiseName}`, opts.otherwise.type)} | ||
} else { | ||
throw new Error('registryEntryHolder type requires "${baseName}" or "${otherwiseName}" fields to be set') | ||
} | ||
return offset | ||
`.trim()) | ||
}], | ||
registryEntryHolderSet: ['parametrizable', (compiler, opts) => { | ||
const baseName = `value.${opts.base.name}` | ||
const otherwiseName = `value.${opts.otherwise.name}` | ||
return compiler.wrapCode(` | ||
if (${baseName}) { | ||
offset = ${compiler.callType(0, 'varint')} | ||
offset = ${compiler.callType(`${baseName}`, opts.base.type)} | ||
} else if (${otherwiseName}) { | ||
offset = ${compiler.callType(`${otherwiseName}.length + 1`, 'varint')} | ||
for (let i = 0; i < ${otherwiseName}.length; i++) { | ||
offset = ${compiler.callType(opts.otherwise.type)} | ||
} | ||
} else { | ||
throw new Error('registryEntryHolder type requires "${baseName}" or "${otherwiseName}" fields to be set') | ||
} | ||
return offset | ||
`.trim()) | ||
}] | ||
}, | ||
SizeOf: { | ||
|
@@ -149,6 +252,60 @@ module.exports = { | |
} | ||
code += 'return size' | ||
return compiler.wrapCode(code) | ||
}], | ||
bitflags: ['parametrizable', (compiler, { type, flags, shift, big }) => { | ||
let fstr = JSON.stringify(flags) | ||
if (Array.isArray(flags)) { | ||
fstr = '{' | ||
for (const [k, v] of Object.entries(flags)) fstr += `"${v}": ${big ? (1n << BigInt(k)) : (1 << k)}` + (big ? 'n,' : ',') | ||
fstr += '}' | ||
} else if (shift) { | ||
fstr = '{' | ||
for (const key in flags) fstr += `"${key}": ${1 << flags[key]},` | ||
fstr += '}' | ||
} | ||
return compiler.wrapCode(` | ||
const flags = ${fstr} | ||
let val = value._value ${big ? '|| 0n' : ''} | ||
for (const key in flags) { | ||
if (value[key]) val |= flags[key] | ||
} | ||
return (ctx.${type})(val) | ||
`.trim()) | ||
}], | ||
registryEntryHolder: ['parametrizable', (compiler, opts) => { | ||
const baseName = `value.${opts.baseName}` | ||
const otherwiseName = `value.${opts.otherwise.name}` | ||
return compiler.wrapCode(` | ||
let size = 0 | ||
if (${baseName}) { | ||
size += ${compiler.callType(`${baseName} + 1`, 'varint')} | ||
} else if (${otherwiseName}) { | ||
size += ${compiler.callType(`${otherwiseName}`, opts.otherwise.type)} | ||
} else { | ||
throw new Error('registryEntryHolder type requires "${baseName}" or "${otherwiseName}" fields to be set') | ||
} | ||
return size | ||
`.trim()) | ||
}], | ||
registryEntryHolderSet: ['parametrizable', (compiler, opts) => { | ||
const baseName = `value.${opts.base.name}` | ||
const otherwiseName = `value.${opts.otherwise.name}` | ||
return compiler.wrapCode(` | ||
let size = 0 | ||
if (${baseName}) { | ||
size += ${compiler.callType(0, 'varint')} | ||
size += ${compiler.callType(`${baseName}`, opts.base.type)} | ||
} else if (${otherwiseName}) { | ||
size += ${compiler.callType(`${otherwiseName}.length + 1`, 'varint')} | ||
for (let i = 0; i < ${otherwiseName}.length; i++) { | ||
size += ${compiler.callType(opts.otherwise.type)} | ||
} | ||
} else { | ||
throw new Error('registryEntryHolder type requires "${baseName}" or "${otherwiseName}" fields to be set') | ||
} | ||
return size | ||
`.trim()) | ||
}] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is bit flags here instead of protodef?