Sandertv / gophertunnel

General purpose library for Minecraft Bedrock Edition software written in Go
MIT License
423 stars 96 forks source link

nbt: unknown tag '110' at offset 1149 during op 'Match' #40

Closed robinbraemer closed 4 years ago

robinbraemer commented 4 years ago

Thanks for the libraries! I'm using the nbt package for a java edition proxy to decode the dimension nbt in the JoinGame packet, but there is an error when trying to use a Minecraft server version 1.16+.

Here the error details (the 1.16.1 server sends the player the packet and the proxy can't read the nbt part of it):

error decoding packet (type: *packet.JoinGame, id: 25, protocol: 1.16.1(736), direction: ClientBound): nbt: unknown tag '110' at offset 1149 during op 'Match'"

code ref: https://github.com/minekube/gate/blob/690e29d172f0deebaec48fbc3dcb49983ed36667/pkg/proto/packet/joingame.go#L148

This is the complete data field (containing the nbt somewhere in the middle) of the JoinGame packet (hex encoded, use a converter like https://www.scadacore.com/tools/programming-calculators/online-hex-converter/ if that may help):

0000 001f 0100 0313 6d69 6e65 6372 6166
743a 6f76 6572 776f 726c 6414 6d69 6e65
6372 6166 743a 7468 655f 6e65 7468 6572
116d 696e 6563 7261 6674 3a74 6865 5f65
6e64 0a00 0009 0009 6469 6d65 6e73 696f
6e0a 0000 0004 0800 046e 616d 6500 136d
696e 6563 7261 6674 3a6f 7665 7277 6f72
6c64 0100 0962 6564 5f77 6f72 6b73 0101
0006 7368 7275 6e6b 0001 000b 7069 676c
696e 5f73 6166 6500 0100 0b68 6173 5f63
6569 6c69 6e67 0001 000c 6861 735f 736b
796c 6967 6874 0108 000a 696e 6669 6e69
6275 726e 001e 6d69 6e65 6372 6166 743a
696e 6669 6e69 6275 726e 5f6f 7665 7277
6f72 6c64 0100 0975 6c74 7261 7761 726d
0005 000d 616d 6269 656e 745f 6c69 6768
7400 0000 0003 000e 6c6f 6769 6361 6c5f
6865 6967 6874 0000 0100 0100 0968 6173
5f72 6169 6473 0101 0007 6e61 7475 7261
6c01 0100 1472 6573 7061 776e 5f61 6e63
686f 725f 776f 726b 7300 0008 0004 6e61
6d65 0019 6d69 6e65 6372 6166 743a 6f76
6572 776f 726c 645f 6361 7665 7301 0009
6265 645f 776f 726b 7301 0100 0673 6872
756e 6b00 0100 0b70 6967 6c69 6e5f 7361
6665 0001 000b 6861 735f 6365 696c 696e
6701 0100 0c68 6173 5f73 6b79 6c69 6768
7401 0800 0a69 6e66 696e 6962 7572 6e00
1e6d 696e 6563 7261 6674 3a69 6e66 696e
6962 7572 6e5f 6f76 6572 776f 726c 6401
0009 756c 7472 6177 6172 6d00 0500 0d61
6d62 6965 6e74 5f6c 6967 6874 0000 0000
0300 0e6c 6f67 6963 616c 5f68 6569 6768
7400 0001 0001 0009 6861 735f 7261 6964
7301 0100 076e 6174 7572 616c 0101 0014
7265 7370 6177 6e5f 616e 6368 6f72 5f77
6f72 6b73 0000 0800 0a69 6e66 696e 6962
7572 6e00 1b6d 696e 6563 7261 6674 3a69
6e66 696e 6962 7572 6e5f 6e65 7468 6572
0100 0975 6c74 7261 7761 726d 0103 000e
6c6f 6769 6361 6c5f 6865 6967 6874 0000
0080 0100 076e 6174 7572 616c 0008 0004
6e61 6d65 0014 6d69 6e65 6372 6166 743a
7468 655f 6e65 7468 6572 0100 0962 6564
5f77 6f72 6b73 0004 000a 6669 7865 645f
7469 6d65 0000 0000 0000 4650 0100 0673
6872 756e 6b01 0100 0b70 6967 6c69 6e5f
7361 6665 0101 000c 6861 735f 736b 796c
6967 6874 0001 000b 6861 735f 6365 696c
696e 6701 0500 0d61 6d62 6965 6e74 5f6c
6967 6874 3dcc cccd 0100 0968 6173 5f72
6169 6473 0001 0014 7265 7370 6177 6e5f
616e 6368 6f72 5f77 6f72 6b73 0100 0800
0a69 6e66 696e 6962 7572 6e00 186d 696e
6563 7261 6674 3a69 6e66 696e 6962 7572
6e5f 656e 6401 0009 756c 7472 6177 6172
6d00 0300 0e6c 6f67 6963 616c 5f68 6569
6768 7400 0001 0001 0007 6e61 7475 7261
6c00 0800 046e 616d 6500 116d 696e 6563
7261 6674 3a74 6865 5f65 6e64 0100 0962
6564 5f77 6f72 6b73 0004 000a 6669 7865
645f 7469 6d65 0000 0000 0000 1770 0100
0673 6872 756e 6b00 0100 0b70 6967 6c69
6e5f 7361 6665 0001 000c 6861 735f 736b
796c 6967 6874 0001 000b 6861 735f 6365
696c 696e 6700 0500 0d61 6d62 6965 6e74
5f6c 6967 6874 0000 0000 0100 0968 6173
5f72 6169 6473 0101 0014 7265 7370 6177
6e5f 616e 6368 6f72 5f77 6f72 6b73 0000
0013 6d69 6e65 6372 6166 743a 6f76 6572
776f 726c 6413 6d69 6e65 6372 6166 743a
6f76 6572 776f 726c 64e2 d3a6 044a 3443
d714 0a00 0100 00

ASCII encoding of the above hex, if that even helps:

minecraft:overworldminecraft:the_netherminecraft:the_end
        dimension
nameminecraft:overworld    bed_worksshrunkpiglin_safehas_ceilinghas_skylight
infiniburnminecraft:infiniburn_overworld  ultrawarm
ambient_lightlogical_height has_raidsnaturalrespawn_anchor_worksnameminecraft:overworld_caves bed_worksshrunkpiglin_safehas_ceilinghas_skylight
infiniburnminecraft:infiniburn_overworld  ultrawarm
ambient_lightlogical_height has_raidsnaturalrespawn_anchor_works
infiniburnminecraft:infiniburn_nether ultrawarmlogical_height€naturalnameminecraft:the_nether    bed_works
fixed_timeFPshrunkpiglin_safehas_skylighthas_ceiling
ambient_light=ÌÌÍ  has_raid
TwistedAsylumMC commented 4 years ago

Java edition has different NBT tags than Bedrock, and gophertunnel is based around Bedrock which means it does not support the Java NBT tags.

robinbraemer commented 4 years ago

What are the differences between bedrock and java NBT? Since there is BigEndian for the Java edition, I expect it to work.

TwistedAsylumMC commented 4 years ago

Java has a tag that Bedrock doesn't, but now I think about it, this isn't your issue. You somehow got a tag with the ID 110 even though the tag IDs are 0-12.

Sandertv commented 4 years ago

I suspect there's a different issue going on. I tried decoding a Java edition structure the other day which worked, so there might be some other cause for this error. I'll have a look if I can get this to work.

Sandertv commented 4 years ago

Okay I just managed to decode it correctly. Here's the offset I started decoding at:

0000 001f 0100 0313 6d69 6e65 6372 6166
743a 6f76 6572 776f 726c 6414 6d69 6e65
6372 6166 743a 7468 655f 6e65 7468 6572
116d 696e 6563 7261 6674 3a74 6865 5f65
6e64 --> 0a00 0009 0009 6469 6d65 6e73 696f
6e0a 0000 0004 0800 046e 616d 6500 136d
696e 6563 7261 6674 3a6f 7665 7277 6f72
6c64 0100 0962 6564 5f77 6f72 6b73 0101
0006 7368 7275 6e6b 0001 000b 7069 676c
696e 5f73 6166 6500 0100 0b68 6173 5f63
6569 6c69 6e67 0001 000c 6861 735f 736b
796c 6967 6874 0108 000a 696e 6669 6e69
6275 726e 001e 6d69 6e65 6372 6166 743a
696e 6669 6e69 6275 726e 5f6f 7665 7277
6f72 6c64 0100 0975 6c74 7261 7761 726d
0005 000d 616d 6269 656e 745f 6c69 6768
7400 0000 0003 000e 6c6f 6769 6361 6c5f
6865 6967 6874 0000 0100 0100 0968 6173
5f72 6169 6473 0101 0007 6e61 7475 7261
6c01 0100 1472 6573 7061 776e 5f61 6e63
686f 725f 776f 726b 7300 0008 0004 6e61
6d65 0019 6d69 6e65 6372 6166 743a 6f76
6572 776f 726c 645f 6361 7665 7301 0009
6265 645f 776f 726b 7301 0100 0673 6872
756e 6b00 0100 0b70 6967 6c69 6e5f 7361
6665 0001 000b 6861 735f 6365 696c 696e
6701 0100 0c68 6173 5f73 6b79 6c69 6768
7401 0800 0a69 6e66 696e 6962 7572 6e00
1e6d 696e 6563 7261 6674 3a69 6e66 696e
6962 7572 6e5f 6f76 6572 776f 726c 6401
0009 756c 7472 6177 6172 6d00 0500 0d61
6d62 6965 6e74 5f6c 6967 6874 0000 0000
0300 0e6c 6f67 6963 616c 5f68 6569 6768
7400 0001 0001 0009 6861 735f 7261 6964
7301 0100 076e 6174 7572 616c 0101 0014
7265 7370 6177 6e5f 616e 6368 6f72 5f77
6f72 6b73 0000 0800 0a69 6e66 696e 6962
7572 6e00 1b6d 696e 6563 7261 6674 3a69
6e66 696e 6962 7572 6e5f 6e65 7468 6572
0100 0975 6c74 7261 7761 726d 0103 000e
6c6f 6769 6361 6c5f 6865 6967 6874 0000
0080 0100 076e 6174 7572 616c 0008 0004
6e61 6d65 0014 6d69 6e65 6372 6166 743a
7468 655f 6e65 7468 6572 0100 0962 6564
5f77 6f72 6b73 0004 000a 6669 7865 645f
7469 6d65 0000 0000 0000 4650 0100 0673
6872 756e 6b01 0100 0b70 6967 6c69 6e5f
7361 6665 0101 000c 6861 735f 736b 796c
6967 6874 0001 000b 6861 735f 6365 696c
696e 6701 0500 0d61 6d62 6965 6e74 5f6c
6967 6874 3dcc cccd 0100 0968 6173 5f72
6169 6473 0001 0014 7265 7370 6177 6e5f
616e 6368 6f72 5f77 6f72 6b73 0100 0800
0a69 6e66 696e 6962 7572 6e00 186d 696e
6563 7261 6674 3a69 6e66 696e 6962 7572
6e5f 656e 6401 0009 756c 7472 6177 6172
6d00 0300 0e6c 6f67 6963 616c 5f68 6569
6768 7400 0001 0001 0007 6e61 7475 7261
6c00 0800 046e 616d 6500 116d 696e 6563
7261 6674 3a74 6865 5f65 6e64 0100 0962
6564 5f77 6f72 6b73 0004 000a 6669 7865
645f 7469 6d65 0000 0000 0000 1770 0100
0673 6872 756e 6b00 0100 0b70 6967 6c69
6e5f 7361 6665 0001 000c 6861 735f 736b
796c 6967 6874 0001 000b 6861 735f 6365
696c 696e 6700 0500 0d61 6d62 6965 6e74
5f6c 6967 6874 0000 0000 0100 0968 6173
5f72 6169 6473 0101 0014 7265 7370 6177
6e5f 616e 6368 6f72 5f77 6f72 6b73 0000
0013 6d69 6e65 6372 6166 743a 6f76 6572
776f 726c 6413 6d69 6e65 6372 6166 743a
6f76 6572 776f 726c 64e2 d3a6 044a 3443
d714 0a00 0100 00

(66 bytes in if I counted correctly)

That successfully gave me the following data:

map[dimension:[map[ambient_light:0 bed_works:1 has_ceiling:0 has_raids:1 has_skylight:1 infiniburn:minecraft:infiniburn_overworld logical_height:256 name:minecraft:overworld natural:1 piglin_safe:0 respawn_anchor_works:0 shrunk:0 ultrawarm:0] map[ambient_light:0 bed_works:1 has_ceiling:1 has_raids:1 has_skylight:1 infiniburn:minecraft:infiniburn_overworld logical_height:256 name:minecraft:overworld_caves natural:1 piglin_safe:0 respawn_anchor_works:0 shrunk:0 ultrawarm:0] map[ambient_light:0.1 bed_works:0 fixed_time:18000 has_ceiling:1 has_raids:0 has_skylight:0 infiniburn:minecraft:infiniburn_nether logical_height:128 name:minecraft:the_nether natural:0 piglin_safe:1 respawn_anchor_works:1 shrunk:1 ultrawarm:1] map[ambient_light:0 bed_works:0 fixed_time:6000 has_ceiling:0 has_raids:1 has_skylight:0 infiniburn:minecraft:infiniburn_end logical_height:256 name:minecraft:the_end natural:0 piglin_safe:0 respawn_anchor_works:0 shrunk:0 ultrawarm:0]]]

Could you let me know if comparing that to the offset you're at when decoding is any help?

robinbraemer commented 4 years ago

I'm 10 bytes in when beginning to decode the nbt starting at the 11th byte inclusive. What are you doing differently?

robinbraemer commented 4 years ago

https://github.com/minekube/gate/compare/nbtissue#diff-584e6d7b04f476d0f25658202f2ef60b

Sandertv commented 4 years ago

I just started at the first 0a byte because those indicate the start of a Compound tag. Does the data I decoded match what you expect to see when you decode it?

robinbraemer commented 4 years ago

Yes, I'm probably decoding something wrong before the nbt causing me to start at a wrong position to decode the nbt...

robinbraemer commented 4 years ago

Okay, I fixed it and am successfully start reading at byte 66. Thank you for your immediate help, add me on Discord (see bio) if you want to reach me!

Sandertv commented 4 years ago

Great. Interesting project you're working on, by the way, keep it up!