diff --git a/assets/xml/objects/object_goma.xml b/assets/xml/objects/object_goma.xml index f2429cd2b9..aba349c478 100644 --- a/assets/xml/objects/object_goma.xml +++ b/assets/xml/objects/object_goma.xml @@ -1,240 +1,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -249,10 +20,144 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -263,16 +168,113 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - + + + diff --git a/assets/xml/objects/object_goma_pal.xml b/assets/xml/objects/object_goma_pal.xml deleted file mode 100644 index dbee83f7ca..0000000000 --- a/assets/xml/objects/object_goma_pal.xml +++ /dev/null @@ -1,276 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/baseroms/gc-eu-mq-dbg/config.yml b/baseroms/gc-eu-mq-dbg/config.yml index 0d1fb268a8..9cfbac5c17 100644 --- a/baseroms/gc-eu-mq-dbg/config.yml +++ b/baseroms/gc-eu-mq-dbg/config.yml @@ -430,7 +430,7 @@ assets: - name: objects/object_gol xml_path: assets/xml/objects/object_gol.xml - name: objects/object_goma - xml_path: assets/xml/objects/object_goma_pal.xml + xml_path: assets/xml/objects/object_goma.xml - name: objects/object_goroiwa xml_path: assets/xml/objects/object_goroiwa.xml - name: objects/object_gr diff --git a/baseroms/gc-eu-mq/config.yml b/baseroms/gc-eu-mq/config.yml index 3708686934..6be2713f47 100644 --- a/baseroms/gc-eu-mq/config.yml +++ b/baseroms/gc-eu-mq/config.yml @@ -422,7 +422,7 @@ assets: - name: objects/object_gol xml_path: assets/xml/objects/object_gol.xml - name: objects/object_goma - xml_path: assets/xml/objects/object_goma_pal.xml + xml_path: assets/xml/objects/object_goma.xml - name: objects/object_goroiwa xml_path: assets/xml/objects/object_goroiwa.xml - name: objects/object_gr diff --git a/baseroms/gc-eu/config.yml b/baseroms/gc-eu/config.yml index cb55d98bb0..2befc4b021 100644 --- a/baseroms/gc-eu/config.yml +++ b/baseroms/gc-eu/config.yml @@ -422,7 +422,7 @@ assets: - name: objects/object_gol xml_path: assets/xml/objects/object_gol.xml - name: objects/object_goma - xml_path: assets/xml/objects/object_goma_pal.xml + xml_path: assets/xml/objects/object_goma.xml - name: objects/object_goroiwa xml_path: assets/xml/objects/object_goroiwa.xml - name: objects/object_gr diff --git a/baseroms/pal-1.0/config.yml b/baseroms/pal-1.0/config.yml index 37ffb7500b..f165fe32ca 100644 --- a/baseroms/pal-1.0/config.yml +++ b/baseroms/pal-1.0/config.yml @@ -434,7 +434,7 @@ assets: - name: objects/object_gol xml_path: assets/xml/objects/object_gol.xml - name: objects/object_goma - xml_path: assets/xml/objects/object_goma_pal.xml + xml_path: assets/xml/objects/object_goma.xml - name: objects/object_goroiwa xml_path: assets/xml/objects/object_goroiwa.xml - name: objects/object_gr diff --git a/baseroms/pal-1.1/config.yml b/baseroms/pal-1.1/config.yml index 45bf82b877..500df68b77 100644 --- a/baseroms/pal-1.1/config.yml +++ b/baseroms/pal-1.1/config.yml @@ -434,7 +434,7 @@ assets: - name: objects/object_gol xml_path: assets/xml/objects/object_gol.xml - name: objects/object_goma - xml_path: assets/xml/objects/object_goma_pal.xml + xml_path: assets/xml/objects/object_goma.xml - name: objects/object_goroiwa xml_path: assets/xml/objects/object_goroiwa.xml - name: objects/object_gr diff --git a/tools/assets/descriptor/base.py b/tools/assets/descriptor/base.py index 47164e0f8e..320d9101d8 100644 --- a/tools/assets/descriptor/base.py +++ b/tools/assets/descriptor/base.py @@ -281,7 +281,17 @@ def _get_resources_fileelem_to_resourcescollection_pass1( try: symbol_name = reselem.attrib["Name"] if "Offset" in reselem.attrib: - offset = int(reselem.attrib["Offset"], 16) + offset_str = reselem.attrib["Offset"] + if offset_str.startswith(".+"): + if prev_resource_end_offset is None: + raise Exception( + f"Resource {symbol_name} has a relative Offset" + " and previous resource has no known end offset" + ) + rel_offset = int(offset_str.removeprefix(".+"), 16) + offset = prev_resource_end_offset + rel_offset + else: + offset = int(offset_str, 16) else: if prev_resource_end_offset is None: raise Exception( diff --git a/tools/assets/descriptor/n64resources.py b/tools/assets/descriptor/n64resources.py index ed0a7615a2..67a9131818 100644 --- a/tools/assets/descriptor/n64resources.py +++ b/tools/assets/descriptor/n64resources.py @@ -3,6 +3,7 @@ import dataclasses import enum +from typing import Optional from xml.etree.ElementTree import Element from ..n64 import G_IM_FMT, G_IM_SIZ @@ -13,6 +14,7 @@ from .base import ( ResourcesDescCollectionsPool, ResourceHandlerNeedsPass2Exception, BaseromFileBackingMemory, + ResourceHasNoSizeError, ) from . import xml_errors @@ -27,20 +29,29 @@ class GfxMicroCode(enum.Enum): @dataclasses.dataclass(eq=False) class DListResourceDesc(ResourceDesc): + length: Optional[int] ucode: GfxMicroCode raw_pointers: set[int] = dataclasses.field(default_factory=set) """Pointers in the dlist that are fine to keep raw ("in hex") instead of using symbols""" + def get_size(self): + if self.length is None: + raise ResourceHasNoSizeError() + return self.length * 8 + def handler_DList(symbol_name, offset, collection, reselem: Element): xml_errors.check_attrib( - reselem, {"Name"}, {"Offset", "Ucode", "RawPointers"} | STATIC_ATTRIB + reselem, {"Name"}, {"Offset", "Length", "Ucode", "RawPointers"} | STATIC_ATTRIB ) + length = None + if "Length" in reselem.attrib: + length = int(reselem.attrib["Length"]) if "Ucode" in reselem.attrib: ucode = GfxMicroCode[reselem.attrib["Ucode"].upper()] else: ucode = GfxMicroCode.F3DEX2 - res = DListResourceDesc(symbol_name, offset, collection, reselem, ucode) + res = DListResourceDesc(symbol_name, offset, collection, reselem, length, ucode) raw_pointers_str = reselem.attrib.get("RawPointers") if raw_pointers_str: for rp_str in raw_pointers_str.split(","): @@ -83,6 +94,9 @@ class Vec3sArrayResourceDesc(ResourceDesc): class VtxArrayResourceDesc(ResourceDesc): count: int + def get_size(self): + return self.count * 0x10 + def handler_Array(symbol_name, offset, collection, reselem: Element): xml_errors.check_attrib(reselem, {"Name", "Count"}, {"Offset"} | STATIC_ATTRIB) diff --git a/tools/assets/descriptor/spec.md b/tools/assets/descriptor/spec.md index c038a13f82..b0a690b0a1 100644 --- a/tools/assets/descriptor/spec.md +++ b/tools/assets/descriptor/spec.md @@ -54,10 +54,17 @@ then `` refers to that ga Resource elements describe resources. Resources are pieces of data corresponding to a symbol each. -Two attributes are required on all resource elements: `Name` and `Offset`. +One attribute is required on all resource elements: `Name`. - `Name` is the name of the symbol associated to the resource. -- `Offset` is the location in bytes from the start of the file data. + +Another attribute, optional, is common to all resource elements: `Offset`. + +If `Offset` is set to a (hexadecimal) number such as `Offset="0x421"`, it specifies the location of the resource in bytes from the start of the file data. + +If `Offset` is not set, the resource is assumed to start where the previous resource ended, or at 0 if the resource is the first in the ``. + +`Offset` can also be set to be a relative offset like `Offset=".+0x421"`, which makes the resource location be that many bytes after the end of the previous resource. ## `Blob` @@ -74,12 +81,14 @@ Unstructured binary data. ## `DList` ```xml - + ``` A display list. -- Optional attributes: `Ucode`, `RawPointers` +- Optional attributes: `Length`, `Ucode`, `RawPointers` + +`Length` can be set to indicate the length (amount of `Gfx` double-words) of the dlist. If not set, the dlist length is automatic. `Ucode` (defaults to `f3dex2`) picks the graphics microcode for which to disassemble the dlist. It may be `f3dex` or `f3dex2`. diff --git a/tools/assets/descriptor/z64resources.py b/tools/assets/descriptor/z64resources.py index d5e6cf032c..f4383e62b1 100644 --- a/tools/assets/descriptor/z64resources.py +++ b/tools/assets/descriptor/z64resources.py @@ -10,13 +10,15 @@ from .base import ( ResourceDesc, ResourcesDescCollection, ResourceHandlerNeedsPass2Exception, + ResourceHasNoSizeError, ) from . import xml_errors @dataclasses.dataclass(eq=False) class CollisionResourceDesc(ResourceDesc): - pass + def get_size(self): + return 0x2C def handler_Collision(symbol_name, offset, collection, reselem: Element): @@ -26,7 +28,8 @@ def handler_Collision(symbol_name, offset, collection, reselem: Element): @dataclasses.dataclass(eq=False) class AnimationResourceDesc(ResourceDesc): - pass + def get_size(self): + return 0x10 def handler_Animation(symbol_name, offset, collection, reselem: Element): @@ -133,6 +136,14 @@ class SkeletonResourceDesc(ResourceDesc): limb_enum_none_member_name: Optional[str] limb_enum_max_member_name: Optional[str] + def get_size(self): + skel_size = { + SkeletonType.NORMAL: 0x8, + }.get(self.type) + if skel_size is None: + raise ResourceHasNoSizeError() + return skel_size + def handler_Skeleton(symbol_name, offset, collection, reselem: Element): xml_errors.check_attrib( @@ -160,6 +171,14 @@ class LimbResourceDesc(ResourceDesc): limb_type: LimbType limb_enum_member_name: Optional[str] + def get_size(self): + limb_size = { + LimbType.STANDARD: 0xC, + }.get(self.limb_type) + if limb_size is None: + raise ResourceHasNoSizeError() + return limb_size + def handler_Limb(symbol_name, offset, collection, reselem: Element): xml_errors.check_attrib(reselem, {"Name", "LimbType"}, {"Offset", "EnumName"}) @@ -179,6 +198,9 @@ class LimbTableResourceDesc(ResourceDesc): limb_type: LimbType count: int + def get_size(self): + return self.count * 4 + def handler_LimbTable(symbol_name, offset, collection, reselem: Element): xml_errors.check_attrib(reselem, {"Name", "LimbType", "Count"}, {"Offset"}) diff --git a/tools/assets/extract/extase_oot64/dlist_resources.py b/tools/assets/extract/extase_oot64/dlist_resources.py index f80a2f9954..63e8a9e92c 100644 --- a/tools/assets/extract/extase_oot64/dlist_resources.py +++ b/tools/assets/extract/extase_oot64/dlist_resources.py @@ -1215,6 +1215,11 @@ class DListResource(Resource, can_size_be_unknown=True): self.target_ucode = target_ucode self.ignored_raw_pointers: set[int] = set() + def set_length(self, length: int): + if length != ((self.range_end - self.range_start) // 8): + raise ValueError("length already set and different") + self.range_end = self.range_start + length * 8 + def try_parse_data(self, memory_context): offset = self.range_start @@ -1332,8 +1337,13 @@ class DListResource(Resource, can_size_be_unknown=True): return pygfxd.gfxd_macro_dflt() + if self.range_end is None: + dlist_data = self.file.data[self.range_start :] + else: + dlist_data = self.file.data[self.range_start : self.range_end] + size = gfxdis( - input_buffer=self.file.data[self.range_start :], + input_buffer=dlist_data, target=self.target_ucode.gfxd_ucode, vtx_callback=vtx_cb, timg_callback=timg_cb, diff --git a/tools/assets/extract/z64_resource_handlers.py b/tools/assets/extract/z64_resource_handlers.py index d0b6c2067a..c494243b92 100644 --- a/tools/assets/extract/z64_resource_handlers.py +++ b/tools/assets/extract/z64_resource_handlers.py @@ -229,6 +229,8 @@ def register_resource_handlers(): n64resources.GfxMicroCode.F3DEX2: dlist_resources.Ucode.f3dex2, }[resource_desc.ucode], ) + if resource_desc.length is not None: + res.set_length(resource_desc.length) res.ignored_raw_pointers |= resource_desc.raw_pointers return res