def _get_subclass_data(mission: MissionType, v: Dict[str, Any]): parents = set(find_parent_classes(mission.get_source())) for subtype, support_class in MISSION_TYPES.items(): if subtype in parents: v['type'] = support_class.get_friendly_name() support_class.export(mission, v) return
def gather_dcsc_properties(species_cls: ExportTableItem, *, alt=False, report=False) -> DinoCharacterStatusComponent: ''' Gather combined DCSC properties from a species, respecting CharacterStatusComponentPriority. ''' assert species_cls.asset and species_cls.asset.loader if not inherits_from(species_cls, PDC_CLS): raise ValueError("Supplied export should be a species character class") loader: AssetLoader = species_cls.asset.loader dcscs: List[Tuple[float, ExportTableItem]] = list() proxy: DinoCharacterStatusComponent = get_proxy_for_type(DCSC_CLS, loader) with ue_parsing_context(properties=True): # Gather DCSCs as we traverse from UObject back towards this species class for cls_name in find_parent_classes(species_cls, include_self=True): if not cls_name.startswith('/Game'): continue asset: UAsset = loader[cls_name] for dcsc_export in _get_dcscs_for_species(asset): # Calculate the priority of this DCSC pri_prop = get_property(dcsc_export, "CharacterStatusComponentPriority") if pri_prop is None: dcsc_cls = loader.load_related( dcsc_export.klass.value).default_export pri_prop = get_property( dcsc_cls, "CharacterStatusComponentPriority") pri = 0 if pri_prop is None else float(pri_prop) if report: print( f'DCSC from {asset.assetname} = {dcsc_export.fullname} (pri {pri_prop} = {pri})' ) dcscs.append((pri, dcsc_export)) # Order the DCSCs by CharacterStatusComponentPriority value, descending # Python's sort is stable, so it will maintain the gathered order of exports with identical priorities (e.g. Deinonychus) dcscs.sort(key=lambda p: p[0]) # Collect properties from each DCSC in order props: Dict[str, Dict[int, UEBase]] = defaultdict( lambda: defaultdict(lambda: None)) # type: ignore if dcscs: extract_properties_from_export(dcscs[-1][1], props, skip_top=alt, recurse=True, report=False) proxy.update(props) return proxy
def output_result(result: str): indent = ' ' print(result) if args.subs: for sub_cls_name in find_sub_classes(result): print(f'{indent}{sub_cls_name}') if args.parents: for i, parent_cls_name in enumerate(find_parent_classes(result)): if args.no_script and not parent_cls_name.startswith('/Game'): break print(f'{indent*(i+1)}{parent_cls_name}')
def find_gatherer_for_export(export: ExportTableItem) -> Optional[Type[MapGathererBase]]: try: parents = set(find_parent_classes(export, include_self=True)) except (AssetLoadException, MissingParent): return None for helper in ALL_GATHERERS: if parents & helper.get_ue_types(): if helper.do_early_checks(export): return helper return None
def _get_item_sets_override(asset_ref): loader = asset_ref.asset.loader asset = loader.load_related(asset_ref) assert asset.default_export for node in find_parent_classes(asset.default_export): if not node.startswith('/Game/'): break asset = loader[node] assert asset.default_export sets = asset.default_export.properties.get_property('ItemSets', fallback=None) if sets: return sets.values return []
def _gather_lootitemset_data(asset_ref): loader = asset_ref.asset.loader asset = loader.load_related(asset_ref) assert asset.default_export d = dict() for node in find_parent_classes(asset.default_export): if not node.startswith('/Game/'): break asset = loader[node] assert asset.default_export item_set = asset.default_export.properties.get_property('ItemSet', fallback=None) if item_set: set_data = item_set.as_dict() for key, value in set_data.items(): if key not in d: d[key] = value return d
def gather_inherited_struct_fields(leaf_export: ExportTableItem, field: str, defaults: Dict[str, Any], index: int = 0) -> Dict[str, Any]: loader = leaf_export.asset.loader output = dict(defaults) # Make sure this is always the default export, and not e.g. default class. leaf_export = leaf_export.asset.default_export for kls in reversed(list(find_parent_classes(leaf_export))): if not kls.startswith('/Game'): continue # Load the asset and get its default export (the CDO). # find_parent_classes gives us merely a list of parent classes, and not "parent" CDOs. asset = loader[kls] super_export = asset.default_export _gather_props_from_export(super_export, field, index, output) return output