aboutsummaryrefslogtreecommitdiff
path: root/codegen/lib/code/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'codegen/lib/code/utils.py')
-rw-r--r--codegen/lib/code/utils.py72
1 files changed, 12 insertions, 60 deletions
diff --git a/codegen/lib/code/utils.py b/codegen/lib/code/utils.py
index 62b4627b..9bfb3504 100644
--- a/codegen/lib/code/utils.py
+++ b/codegen/lib/code/utils.py
@@ -1,7 +1,6 @@
# utilities specifically for codegen
from lib.utils import to_camel_case, to_snake_case, get_dir_location
-from lib.mappings import Mappings
from typing import Optional
import os
@@ -10,8 +9,7 @@ def burger_type_to_rust_type(
burger_type,
field_name: Optional[str] = None,
instruction=None,
- mappings: Optional[Mappings] = None,
- obfuscated_class_name: Optional[str] = None,
+ class_name: Optional[str] = None,
):
is_var = False
uses = set()
@@ -90,7 +88,7 @@ def burger_type_to_rust_type(
# depends on context
field_type_rs = "todo!()"
elif burger_type == "enum":
- if not instruction or not mappings or not obfuscated_class_name:
+ if not instruction or not class_name:
field_type_rs = 'todo!("enum")'
else:
# generate the whole enum :)
@@ -98,57 +96,20 @@ def burger_type_to_rust_type(
enum_field = instruction["field"]
# enums with a.b() as the field
if "." in enum_field:
- enum_first_part_name = mappings.get_field_type(
- obfuscated_class_name, enum_field.split(".")[0]
- )
- enum_first_part_obfuscated_name = (
- mappings.get_class_from_deobfuscated_name(enum_first_part_name)
- )
- print(
- "enum_first_part_obfuscated_name", enum_first_part_obfuscated_name
- )
+ enum_first_part_name = enum_field.split("/")[0]
+ print("enum_first_part_name", enum_first_part_name)
print("enum field", enum_field.split(".")[1].split("(")[0])
- try:
- enum_name = mappings.get_method_type(
- enum_first_part_obfuscated_name,
- enum_field.split(".")[1].split("(")[0],
- "",
- )
- except KeyError:
- # sometimes enums are fields instead of methods
- enum_name = mappings.get_field_type(
- enum_first_part_obfuscated_name,
- enum_field.split(".")[1].split("(")[0],
- )
+ enum_name = enum_field.split("$")[1].split("(")[0]
print("hm", enum_name)
else:
- try:
- enum_name = mappings.get_field_type(
- obfuscated_class_name, enum_field
- )
- except Exception:
- enum_name = mappings.get_class(obfuscated_class_name)
- print(
- f"failed getting {obfuscated_class_name}.{enum_field} but continuing with {enum_name} anyways"
- )
+ enum_name = enum_field or class_name
print("enum_name", enum_name)
- enum_obfuscated_name = mappings.get_class_from_deobfuscated_name(enum_name)
+ enum_obfuscated_name = enum_name
print("enum_obfuscated_name", enum_obfuscated_name)
enum_variants = []
- for obfuscated_field_name in mappings.fields[enum_obfuscated_name]:
- field_name = mappings.get_field(
- enum_obfuscated_name, obfuscated_field_name
- )
-
- # get the type just to make sure it's actually a variant and not something else
- field_type = mappings.get_field_type(
- enum_obfuscated_name, obfuscated_field_name
- )
- if field_type != enum_name:
- continue
-
- enum_variants.append(field_name)
+ raise RuntimeError("TODO: extracting enum variants")
+ enum_variants.append(field_name)
field_type_rs = to_camel_case(enum_name.split(".")[-1].split("$")[-1])
extra_code.append("")
@@ -165,28 +126,19 @@ def burger_type_to_rust_type(
field_type_rs = f"Vec<{field_type_rs}>"
# sometimes burger gives us a slightly incorrect type
- if mappings and instruction:
+ if instruction:
if field_type_rs == "Vec<u8>":
field = instruction["field"]
if field.endswith(".copy()"):
field = field[:-7]
- try:
- array_type = mappings.get_field_type(obfuscated_class_name, field)
- except KeyError:
- print("Error getting array type", field)
- return field_type_rs, is_var, uses, extra_code
+ array_type = field
if array_type == "net.minecraft.network.FriendlyByteBuf":
field_type_rs = "UnsizedByteArray"
uses.add("azalea_buf::UnsizedByteArray")
else:
print("instruction that we errored on:", instruction)
- deobfuscated_class_name = (
- mappings.get_class(obfuscated_class_name) if obfuscated_class_name else None
- )
- raise Exception(
- f"Unknown field type: {burger_type} ({deobfuscated_class_name or obfuscated_class_name})"
- )
+ raise Exception(f"Unknown field type: {burger_type} ({class_name})")
return field_type_rs, is_var, uses, extra_code