diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-08-20 15:17:07 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-20 15:17:07 -0500 |
| commit | dbb2092ac002790c07ad21cf7d12aabb477a2e74 (patch) | |
| tree | 5d5bb1e6dbca8250292a9e0b1edc7325699bbbaf /codegen/lib/mappings.py | |
| parent | ac4d675d44a93a6625f508263c650206a7ff1f98 (diff) | |
| download | azalea-drasl-dbb2092ac002790c07ad21cf7d12aabb477a2e74.tar.xz | |
Implement ALL packets (#16)
* add a couple more packets and improve codegen
* enums in packet codegen
* fix enums and MORE PACKETS
* make unsigned numbers the default
* codegen can make hashmaps
* UnsizedByteArray in codegen
* Vec and Option
* enum codgen works in more situations
* ServerboundInteractPacket
* Fix error with new error system
* More packets
* more packets
* more packets
* guess what was added
* yeah it's more packets
* add more packets
* packets
* start adding ClientboundBossEventPacket
* finish boss event packet
* improve codegen for linux
* start on command suggestions packet
* rename declare_commands to commands
* más paquetes
* fix generating custom payload packet
* more packets
* mehr Pakete
* improve codegen for movement packets
* rename move packets to have "packet" at the end
* fix some unused variable warns
* addere plus facis
* pli da pakoj
* plus de paquets
* più pacchetti
* make ChatFormatting a macro in azalea-chat
* change a match to matches! macro
* update SetPlayerTeam to use ChatFormatting
* ClientboundSetScorePacket & fix clippy warnings
* finish game state :tada:
* add remaining packets for other states
* fix error in ping.rs
Diffstat (limited to 'codegen/lib/mappings.py')
| -rw-r--r-- | codegen/lib/mappings.py | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/codegen/lib/mappings.py b/codegen/lib/mappings.py index fb3e8bda..6cf6273f 100644 --- a/codegen/lib/mappings.py +++ b/codegen/lib/mappings.py @@ -1,16 +1,23 @@ +from typing import Optional + + class Mappings: - __slots__ = ('classes', 'fields', 'methods') + __slots__ = ('classes', 'fields', 'methods', 'field_types', 'method_types') - def __init__(self, classes, fields, methods): + def __init__(self, classes, fields, methods, field_types, method_types): self.classes = classes self.fields = fields self.methods = methods + self.field_types = field_types + self.method_types = method_types @staticmethod def parse(mappings_txt): classes = {} fields = {} methods = {} + field_types = {} + method_types = {} current_obfuscated_class_name = None @@ -26,21 +33,28 @@ class Mappings: real_name_with_parameters = real_name_with_parameters_and_line.split( ':')[-1] - real_name = real_name_with_parameters.split('(')[0] - parameters = real_name_with_parameters.split('(')[1] + real_type, real_name = real_name_with_parameters.split('(')[ + 0].split(' ') + parameters = real_name_with_parameters.split('(')[1].split(')')[ + 0] if current_obfuscated_class_name not in methods: methods[current_obfuscated_class_name] = {} + method_types[current_obfuscated_class_name] = {} methods[current_obfuscated_class_name][ f'{obfuscated_name}({parameters})'] = real_name + method_types[current_obfuscated_class_name][ + f'{obfuscated_name}({parameters})'] = real_type else: # otherwise, it's a field real_name_with_type, obfuscated_name = line.strip().split(' -> ') - real_name = real_name_with_type.split(' ')[1] + real_type, real_name = real_name_with_type.split(' ') if current_obfuscated_class_name not in fields: fields[current_obfuscated_class_name] = {} + field_types[current_obfuscated_class_name] = {} fields[current_obfuscated_class_name][obfuscated_name] = real_name + field_types[current_obfuscated_class_name][obfuscated_name] = real_type else: # otherwise it's a class real_name, obfuscated_name = line.strip(':').split(' -> ') @@ -48,7 +62,7 @@ class Mappings: classes[obfuscated_name] = real_name - return Mappings(classes, fields, methods) + return Mappings(classes, fields, methods, field_types, method_types) def get_field(self, obfuscated_class_name, obfuscated_field_name): return self.fields.get(obfuscated_class_name, {}).get(obfuscated_field_name) @@ -57,4 +71,17 @@ class Mappings: return self.classes[obfuscated_class_name] def get_method(self, obfuscated_class_name, obfuscated_method_name, obfuscated_signature): + print(obfuscated_class_name, self.methods[obfuscated_class_name]) return self.methods[obfuscated_class_name][f'{obfuscated_method_name}({obfuscated_signature})'] + + def get_field_type(self, obfuscated_class_name, obfuscated_field_name) -> str: + return self.field_types[obfuscated_class_name][obfuscated_field_name] + + def get_method_type(self, obfuscated_class_name, obfuscated_method_name, obfuscated_signature) -> str: + return self.method_types[obfuscated_class_name][f'{obfuscated_method_name}({obfuscated_signature})'] + + def get_class_from_deobfuscated_name(self, deobfuscated_name) -> Optional[str]: + for obfuscated_name, real_name in self.classes.items(): + if real_name == deobfuscated_name: + return obfuscated_name + return None |
