From 0a314bca16f6de199c319ffb0d84a5d5c3a61387 Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 24 May 2022 20:28:08 -0500 Subject: rename code-generator to codegen --- codegen/lib/download.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 codegen/lib/download.py (limited to 'codegen/lib/download.py') diff --git a/codegen/lib/download.py b/codegen/lib/download.py new file mode 100644 index 00000000..284591ab --- /dev/null +++ b/codegen/lib/download.py @@ -0,0 +1,89 @@ +from .mappings import Mappings +import requests +import json +import os + +# make sure the downloads directory exists +if not os.path.exists('downloads'): + os.mkdir('downloads') + + +def get_burger(): + if not os.path.exists('downloads/Burger'): + with open('burger.json', 'w') as f: + json.dump(requests.get( + 'https://api.github.com/repos/Burger/Burger/releases/latest').json(), f) + print('\033[92mDownloading Burger...\033[m') + os.system( + 'cd downloads && git clone https://github.com/pokechu22/Burger && cd Burger && git pull') + + print('\033[92mInstalling dependencies...\033[m') + os.system('cd downloads/Burger && pip install six jawa') + + +def get_version_manifest(): + if not os.path.exists(f'downloads/version_manifest.json'): + print( + f'\033[92mDownloading version manifest...\033[m') + version_manifest_data = requests.get( + 'https://launchermeta.mojang.com/mc/game/version_manifest.json').json() + with open(f'downloads/version_manifest.json', 'w') as f: + json.dump(version_manifest_data, f) + else: + with open(f'downloads/version_manifest.json', 'r') as f: + version_manifest_data = json.load(f) + return version_manifest_data + + +def get_version_data(version_id: str): + if not os.path.exists(f'downloads/{version_id}.json'): + version_manifest_data = get_version_manifest() + + print( + f'\033[92mGetting data for \033[1m{version_id}..\033[m') + package_url = next( + filter(lambda v: v['id'] == version_id, version_manifest_data['versions']))['url'] + package_data = requests.get(package_url).json() + with open(f'downloads/{version_id}.json', 'w') as f: + json.dump(package_data, f) + else: + with open(f'downloads/{version_id}.json', 'r') as f: + package_data = json.load(f) + return package_data + + +def get_client_jar(version_id: str): + if not os.path.exists(f'downloads/client-{version_id}.jar'): + package_data = get_version_data(version_id) + print('\033[92mDownloading client jar...\033[m') + client_jar_url = package_data['downloads']['client']['url'] + with open(f'downloads/client-{version_id}.jar', 'wb') as f: + f.write(requests.get(client_jar_url).content) + + +def get_burger_data_for_version(version_id: str): + if not os.path.exists(f'downloads/burger-{version_id}.json'): + get_burger() + get_client_jar(version_id) + + os.system( + f'cd downloads/Burger && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json' + ) + with open(f'downloads/burger-{version_id}.json', 'r') as f: + return json.load(f) + + +def get_mappings_for_version(version_id: str): + if not os.path.exists(f'downloads/mappings-{version_id}.txt'): + package_data = get_version_data(version_id) + + client_mappings_url = package_data['downloads']['client_mappings']['url'] + + mappings_text = requests.get(client_mappings_url).text + + with open(f'downloads/mappings-{version_id}.txt', 'w') as f: + f.write(mappings_text) + else: + with open(f'downloads/mappings-{version_id}.txt', 'r') as f: + mappings_text = f.read() + return Mappings.parse(mappings_text) -- cgit v1.2.3 From c851204dd0c4b9eee8acc12c4de56b90e1bf041b Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 25 May 2022 20:09:48 -0500 Subject: Fix detecting changed packet ids --- codegen/lib/download.py | 8 ++++++-- codegen/migrate.py | 16 ++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'codegen/lib/download.py') diff --git a/codegen/lib/download.py b/codegen/lib/download.py index 284591ab..5030f8f3 100644 --- a/codegen/lib/download.py +++ b/codegen/lib/download.py @@ -41,8 +41,12 @@ def get_version_data(version_id: str): print( f'\033[92mGetting data for \033[1m{version_id}..\033[m') - package_url = next( - filter(lambda v: v['id'] == version_id, version_manifest_data['versions']))['url'] + try: + package_url = next( + filter(lambda v: v['id'] == version_id, version_manifest_data['versions']))['url'] + except StopIteration: + raise ValueError( + f'No version with id {version_id} found. Maybe delete downloads/version_manifest.json and try again?') package_data = requests.get(package_url).json() with open(f'downloads/{version_id}.json', 'w') as f: json.dump(package_data, f) diff --git a/codegen/migrate.py b/codegen/migrate.py index 304351d3..c623fd58 100644 --- a/codegen/migrate.py +++ b/codegen/migrate.py @@ -38,8 +38,8 @@ for packet, packet_name in old_packets.items(): if packet_name not in old_packets.values(): removed_packets.append(packet) print('Removed packet:', packet) -for (direction, state), packets in group_packets(removed_packets).items(): - lib.code.packet.remove_packet_ids(packets, direction, state) +# for (direction, state), packets in group_packets(removed_packets).items(): +# lib.code.packet.remove_packet_ids(packets, direction, state) print() @@ -47,13 +47,13 @@ print() changed_packets: dict[PacketIdentifier, int] = {} for old_packet, old_packet_name in old_packets.items(): for new_packet, new_packet_name in new_packets.items(): - if old_packet.direction == new_packet.direction and old_packet.state == new_packet.state and old_packet.packet_id != new_packet.packet_id: + if old_packet_name == new_packet_name and old_packet.direction == new_packet.direction and old_packet.state == new_packet.state and old_packet.packet_id != new_packet.packet_id: changed_packets[old_packet] = new_packet.packet_id print('Changed packet id:', old_packet, '->', new_packet, f'({new_packet_name})') break -for (direction, state), packets in group_packets(list(changed_packets.keys())).items(): - lib.code.packet.remove_packet_ids(packets, direction, state) +# for (direction, state), packets in group_packets(list(changed_packets.keys())).items(): +# lib.code.packet.remove_packet_ids(packets, direction, state) print() @@ -64,9 +64,9 @@ for packet, packet_name in new_packets.items(): if packet_name not in old_packets.values(): added_packets.append(packet) print('Added packet:', packet) -for packet in added_packets: - lib.code.packet.generate_packet( - new_burger_data[0]['packets']['packet'], new_mappings, packet.packet_id, packet.direction, packet.state) +# for packet in added_packets: +# lib.code.packet.generate_packet( +# new_burger_data[0]['packets']['packet'], new_mappings, packet.packet_id, packet.direction, packet.state) lib.code.utils.fmt() print('Done!') -- cgit v1.2.3 From 05af65d16c06b6c2fd71908df6a68c5a8c57ba18 Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 8 Jun 2022 18:32:28 -0500 Subject: no burger.json --- codegen/lib/download.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'codegen/lib/download.py') diff --git a/codegen/lib/download.py b/codegen/lib/download.py index 5030f8f3..7d14a3a3 100644 --- a/codegen/lib/download.py +++ b/codegen/lib/download.py @@ -10,9 +10,6 @@ if not os.path.exists('downloads'): def get_burger(): if not os.path.exists('downloads/Burger'): - with open('burger.json', 'w') as f: - json.dump(requests.get( - 'https://api.github.com/repos/Burger/Burger/releases/latest').json(), f) print('\033[92mDownloading Burger...\033[m') os.system( 'cd downloads && git clone https://github.com/pokechu22/Burger && cd Burger && git pull') -- cgit v1.2.3