diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-07-29 04:56:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-29 04:56:21 +0000 |
| commit | aadf2de3cb751d563e743599a7fb345c08010f5a (patch) | |
| tree | aec2a9485c5057f1c148b87e23ee07a7a6b4978b /codegen/lib/code | |
| parent | 3e43fc6c502573f9d48d801087e72cded37a30b8 (diff) | |
| parent | 2211021105a7ce0ce9fcbc18f3b4f03b0f991a10 (diff) | |
| download | azalea-drasl-aadf2de3cb751d563e743599a7fb345c08010f5a.tar.xz | |
Merge pull request #8 from mat-1/1.19.1
Support 1.19.1. Signing stuff isn't implemented but auth isn't even in Azalea yet so that's fine.
Diffstat (limited to 'codegen/lib/code')
| -rw-r--r-- | codegen/lib/code/packet.py | 32 | ||||
| -rw-r--r-- | codegen/lib/code/utils.py | 3 | ||||
| -rw-r--r-- | codegen/lib/code/version.py | 6 |
3 files changed, 34 insertions, 7 deletions
diff --git a/codegen/lib/code/packet.py b/codegen/lib/code/packet.py index de8254e7..ffa7841c 100644 --- a/codegen/lib/code/packet.py +++ b/codegen/lib/code/packet.py @@ -110,7 +110,8 @@ def set_packets(packet_ids: list[int], packet_class_names: list[str], direction: packet_ids, packet_class_names = [list(x) for x in zip( *sorted(zip(packet_ids, packet_class_names), key=lambda pair: pair[0]))] # type: ignore - mod_rs_dir = f'../azalea-protocol/src/packets/{state}/mod.rs' + mod_rs_dir = get_dir_location( + f'../azalea-protocol/src/packets/{state}/mod.rs') with open(mod_rs_dir, 'r') as f: mod_rs = f.read().splitlines() new_mod_rs = [] @@ -140,6 +141,7 @@ def set_packets(packet_ids: list[int], packet_class_names: list[str], direction: new_mod_rs.append( make_packet_mod_rs_line(packet_id, packet_class_name) ) + required_modules.append(packet_class_name) else: ignore_lines = False continue @@ -164,7 +166,8 @@ def set_packets(packet_ids: list[int], packet_class_names: list[str], direction: def get_packets(direction: str, state: str): - mod_rs_dir = f'../azalea-protocol/src/packets/{state}/mod.rs' + mod_rs_dir = get_dir_location( + f'../azalea-protocol/src/packets/{state}/mod.rs') with open(mod_rs_dir, 'r') as f: mod_rs = f.read().splitlines() @@ -268,3 +271,28 @@ def remove_packet_ids(removing_packet_ids: list[int], direction: str, state: str new_packet_class_names.append(packet_class_name) set_packets(new_packet_ids, new_packet_class_names, direction, state) + + +def are_packet_instructions_identical(old_packet, new_packet): + old_packet = old_packet or [] + new_packet = new_packet or [] + + if len(old_packet) != len(new_packet): + return False + + for old_field, new_field in zip(old_packet, new_packet): + if old_field['operation'] != new_field['operation']: + return False + if new_field['operation'] == 'write': + if burger_type_to_rust_type(old_field.get('type')) != burger_type_to_rust_type(new_field.get('type')): + return False + else: + # comparing is too complicated here since it's possible the type has variables + # so we just don't + pass + + if 'instructions' in old_field and 'instructions' in new_field: + if not are_packet_instructions_identical(old_field['instructions'], new_field['instructions']): + return False + + return True diff --git a/codegen/lib/code/utils.py b/codegen/lib/code/utils.py index ecfff4fb..0c22d7ba 100644 --- a/codegen/lib/code/utils.py +++ b/codegen/lib/code/utils.py @@ -62,8 +62,7 @@ def burger_type_to_rust_type(burger_type): burger_type[:-2]) field_type_rs = f'Vec<{field_type_rs}>' else: - print('Unknown field type:', burger_type) - exit() + raise Exception(f'Unknown field type: {burger_type}') return field_type_rs, is_var, uses diff --git a/codegen/lib/code/version.py b/codegen/lib/code/version.py index 511d30d1..13d9472d 100644 --- a/codegen/lib/code/version.py +++ b/codegen/lib/code/version.py @@ -36,7 +36,7 @@ def set_version_id(version_id: str) -> None: def get_protocol_version() -> str: # azalea-protocol/src/packets/mod.rs # pub const PROTOCOL_VERSION: u32 = 758; - with open('../azalea-protocol/src/packets/mod.rs', 'r') as f: + with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'r') as f: mod_rs = f.read().splitlines() for line in mod_rs: if line.strip().startswith('pub const PROTOCOL_VERSION'): @@ -46,7 +46,7 @@ def get_protocol_version() -> str: def set_protocol_version(protocol_version: str) -> None: - with open('../azalea-protocol/src/packets/mod.rs', 'r') as f: + with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'r') as f: mod_rs = f.read().splitlines() for i, line in enumerate(mod_rs): if line.strip().startswith('pub const PROTOCOL_VERSION'): @@ -56,5 +56,5 @@ def set_protocol_version(protocol_version: str) -> None: raise Exception( 'Could not find protocol version in azalea-protocol/src/packets/mod.rs') - with open('../azalea-protocol/src/packets/mod.rs', 'w') as f: + with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'w') as f: f.write('\n'.join(mod_rs)) |
