mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 20:35:45 +01:00
Compare commits
4 Commits
e3a8063124
...
e018e1ff1b
| Author | SHA1 | Date | |
|---|---|---|---|
| e018e1ff1b | |||
| 1b09d3d7f1 | |||
| e4b90246c5 | |||
| c15046e017 |
@@ -9,26 +9,12 @@
|
|||||||
#include "../util/compat/endian.h"
|
#include "../util/compat/endian.h"
|
||||||
#include "../util/intdef.h"
|
#include "../util/intdef.h"
|
||||||
|
|
||||||
// WARN: does not have public-facing definition
|
|
||||||
int nbt_primsize(u8 tag) {
|
|
||||||
switch (tag) {
|
|
||||||
case NBT_I8: return 1;
|
|
||||||
case NBT_I16: return 2;
|
|
||||||
case NBT_I32: // fall through
|
|
||||||
case NBT_F32: return 4;
|
|
||||||
case NBT_I64: // fall through
|
|
||||||
case NBT_F64: return 8;
|
|
||||||
default: return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const u8 *nbt_nexttag(const u8 *restrict buf) {
|
const u8 *nbt_nexttag(const u8 *restrict buf) {
|
||||||
const u8 *tag, *ptr, *tmp;
|
const u8 *tag, *ptr;
|
||||||
tag = buf;
|
|
||||||
uint dpt = 0;
|
uint dpt = 0;
|
||||||
size_t mems = 0;
|
|
||||||
|
|
||||||
// looping through the named tags
|
tag = buf;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ptr = tag + be16toh(*(u16 *)(tag + 1)) + 3; // set `ptr` to start of data
|
ptr = tag + be16toh(*(u16 *)(tag + 1)) + 3; // set `ptr` to start of data
|
||||||
mems = 0;
|
mems = 0;
|
||||||
@@ -41,10 +27,10 @@ const u8 *nbt_nexttag(const u8 *restrict buf) {
|
|||||||
case NBT_I64: // fall through
|
case NBT_I64: // fall through
|
||||||
case NBT_F64: ptr += 8; break;
|
case NBT_F64: ptr += 8; break;
|
||||||
|
|
||||||
case NBT_ARR_I64: mems += sizeof(i64) - sizeof(i32); __attribute__((fallthrough));
|
case NBT_ARR_I8: ptr += 4 + (i32)be32toh(*(u32 *)ptr) * 1; break;
|
||||||
case NBT_ARR_I32: mems += sizeof(i32) - sizeof(i8); __attribute__((fallthrough));
|
case NBT_ARR_I32: ptr += 4 + (i32)be32toh(*(u32 *)ptr) * 4; break;
|
||||||
case NBT_ARR_I8: ptr += (mems + 1) * (i32)be32toh(*(u32 *)(ptr)) + 4; break;
|
case NBT_ARR_I64: ptr += 4 + (i32)be32toh(*(u32 *)ptr) * 8; break;
|
||||||
case NBT_STR: ptr += be16toh(*(u16 *)(ptr)) + 2; break;
|
case NBT_STR: ptr += 2 + (u16)be16toh(*(u16 *)ptr) * 1; break;
|
||||||
|
|
||||||
case NBT_END: dpt--; break;
|
case NBT_END: dpt--; break;
|
||||||
case NBT_COMPOUND: dpt++; break;
|
case NBT_COMPOUND: dpt++; break;
|
||||||
@@ -68,7 +54,7 @@ static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) {
|
|||||||
|
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
// integral types
|
// integral types
|
||||||
case NBT_I8: *dat = *ptr; return ptr;
|
case NBT_I8: *dat = *ptr; return ptr + 1;
|
||||||
case NBT_I16: *(u16 *)dat = be16toh(*(u16 *)ptr); return ptr + 2;
|
case NBT_I16: *(u16 *)dat = be16toh(*(u16 *)ptr); return ptr + 2;
|
||||||
case NBT_I32: // fall through
|
case NBT_I32: // fall through
|
||||||
case NBT_F32: *(u32 *)dat = be16toh(*(u32 *)ptr); return ptr + 4;
|
case NBT_F32: *(u32 *)dat = be16toh(*(u32 *)ptr); return ptr + 4;
|
||||||
@@ -87,7 +73,7 @@ static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) {
|
|||||||
default: return NULL;
|
default: return NULL;
|
||||||
}
|
}
|
||||||
if (!arrlen) return NULL;
|
if (!arrlen) return NULL;
|
||||||
return ptr + nbt_primsize(*buf);
|
return ptr; // TODO: return end of array
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nbt_procdat nbt_initproc(struct nbt_path const *restrict pats, uint npats) {
|
struct nbt_procdat nbt_initproc(struct nbt_path const *restrict pats, uint npats) {
|
||||||
|
|||||||
Reference in New Issue
Block a user