Created
November 8, 2023 05:00
-
-
Save srifqi/613a8b68984753f50c029e71b08d0264 to your computer and use it in GitHub Desktop.
Minetest World: MapBlock De-serialization Test in Version 29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Minetest World: MapBlock De-serialization Test\n", | |
"-------" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pyzstd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"raw_bytes = []\n", | |
"with open('mt/map-blocks-61763-data', 'rb') as f:\n", | |
"\traw_bytes = f.read()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"29" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"map_version = raw_bytes[0]\n", | |
"map_version" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"data = pyzstd.decompress(raw_bytes[1:])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(3, 65535, 931, 0, 14)" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"flags = int(data[0])\n", | |
"lighting_complete = int.from_bytes(data[1:3], byteorder='big')\n", | |
"timestamp = int.from_bytes(data[3:7], byteorder='big')\n", | |
"name_id_mapping_version = int(data[7])\n", | |
"num_name_id_mappings = int.from_bytes(data[8:10], byteorder='big')\n", | |
"(flags, lighting_complete, timestamp, name_id_mapping_version, num_name_id_mappings)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"13 16 b'mcl_core:granite'\n", | |
"0 14 b'mcl_core:stone'\n", | |
"1 13 b'mcl_core:dirt'\n", | |
"2 24 b'mcl_core:dirt_with_grass'\n", | |
"3 3 b'air'\n", | |
"4 24 b'mcl_core:stone_with_iron'\n", | |
"5 21 b'mcl_flowers:dandelion'\n", | |
"6 21 b'mcl_flowers:tallgrass'\n", | |
"7 24 b'mcl_core:stone_with_coal'\n", | |
"8 15 b'mcl_core:gravel'\n", | |
"9 17 b'mcl_core:andesite'\n", | |
"10 15 b'mcl_core:leaves'\n", | |
"11 13 b'mcl_core:tree'\n" | |
] | |
} | |
], | |
"source": [ | |
"data_pointer = 10\n", | |
"for i in range(1, num_name_id_mappings):\n", | |
"\tmap_id = int.from_bytes(data[data_pointer:(data_pointer + 2)], byteorder='big')\n", | |
"\tdata_pointer += 2\n", | |
"\tmap_name_len = int.from_bytes(data[data_pointer:(data_pointer + 2)], byteorder='big')\n", | |
"\tdata_pointer += 2\n", | |
"\tmap_name = data[data_pointer:(data_pointer + map_name_len)]\n", | |
"\tdata_pointer += map_name_len\n", | |
"\tprint('%d %d %s' % (map_id, map_name_len, map_name))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment