示例#1
0
    def setup_defs(self):
        this_class = type(self)
        if not this_class.defs:
            print("    Loading definitions in %s" %
                  self.handler_class.default_defs_path)
            this_class.defs = defs = {}

            # these imports were moved here because their defs would otherwise
            # be built when this module was imported, which is not good practice
            from reclaimer.stubbs.defs.antr import antr_def as antr_def
            from reclaimer.stubbs.defs.mode import mode_def as mode_def
            from reclaimer.stubbs.defs.mode import pc_mode_def as pc_mode_def
            from reclaimer.stubbs.defs.coll import fast_coll_def as coll_def
            from reclaimer.stubbs.defs.sbsp import fast_sbsp_def as sbsp_def

            this_class.handler = self.handler_class(
                build_reflexive_cache=False,
                build_raw_data_cache=False,
                debug=2)
            this_class.defs = dict(this_class.handler.defs)

            if self.engine == "stubbspc":
                this_class.defs["mode"] = pc_mode_def
            else:
                this_class.defs["mode"] = mode_def
            this_class.defs["antr"] = antr_def
            this_class.defs["coll"] = coll_def
            this_class.defs["sbsp"] = sbsp_def
            this_class.defs = FrozenDict(this_class.defs)

        # make a shallow copy for this instance to manipulate
        self.defs = dict(self.defs)
示例#2
0
'''
This module contains generic structures that fit various needs.

These structures are not meant to be used as is(except void_desc)
and need to be included in a descriptor before it is sanitized.

Critical keys will be missing if they aren't sanitized.
'''

from supyr_struct.defs.frozen_dict import FrozenDict
from supyr_struct.field_types import Void, BytearrayRaw

void_desc = FrozenDict(NAME='voided', TYPE=Void, NAME_MAP={})


def remaining_data_length(node=None, parent=None, attr_index=None,
                          rawdata=None, new_value=None, *args, **kwargs):
    '''
    Size getter for the amount of data left in the rawdata
    starting at kwargs['offset'] + kwargs['root_offset']

    If not provided, offset and root_offset default to 0.
    '''
    if new_value is not None:
        # there is no size to set for an open ended data stream
        return

    if rawdata is not None:
        # the data is being initially read
        return (len(rawdata) - kwargs.get('offset', 0) +
                kwargs.get('root_offset', 0))
示例#3
0
     H1_TAG_SUPERCLASSES
from refinery.util import int_to_fourcc, is_reserved_tag
from refinery.windows.actions_window import RefineryActionsWindow

from supyr_struct.defs.frozen_dict import FrozenDict

no_op = lambda *a, **kw: None

def _ensure_backslash_for_folder(folder_path):
    '''
    Directories must end with a backslash for them to be identified as
    directories in the ExplorerHierarchyTree.
    '''
    return str(folder_path).rstrip('\\') + '\\'

TREE_SORT_METHODS = FrozenDict(
    {0: "name", 4:"pointer", 5:"pointer", 6:"index_id"})


class ExplorerHierarchyTree(HierarchyFrame):
    active_map = None
    tags_tree = None
    valid_classes = None

    tree_id_to_index_ref = None

    queue_tree = None
    sibling_tree_frames = None
    sort_by = "name"
    reverse_sorted = False

    def __init__(self, *args, **kwargs):
示例#4
0
DATA_DIR_MACRO = DIR_MACRO + ( (), "data")
TAGS_DIR_MACRO = DIR_MACRO + ( (), "tags")


DIRECTIVES = FrozenDict({
    "k": (),
    "c": (),
    "cwd": (
        ("directory", ) + DIR_MACRO,
        ),
    "debug": (
        ("enable", ) + BOOL_MACRO,
        ("time", "float", "0.0", (0, float("inf"))),
        ),
    "set": (
        ("var-name", )  + STR_NO_PAREN_MACRO,
        ("var-value", ) + STR_MACRO,
        ),
    "del": (
        ("var-name", ) + STR_NO_PAREN_MACRO,
        ),
    "run": (
        ("exec-path", ) + FILE_MACRO,
        ),
    "w": (
        ("time", ) + FLOAT_MACRO,
        ),
    })

TOOL_COMMANDS = FrozenDict({
    "animations": (
        ("source-directory", ) + DATA_DIR_MACRO,
示例#5
0
'''
This module contains generic structures that fit various needs.

These structures are not meant to be used as is(except void_desc)
and need to be included in a descriptor before it is sanitized.

Critical keys will be missing if they aren't sanitized.
'''
import supyr_struct

from supyr_struct.defs.frozen_dict import FrozenDict

void_desc = FrozenDict(NAME='voided',
                       TYPE=supyr_struct.field_types.Void,
                       NAME_MAP={})


def remaining_data_length(node=None,
                          parent=None,
                          attr_index=None,
                          rawdata=None,
                          new_value=None,
                          *args,
                          **kwargs):
    '''
    Size getter for the amount of data left in the rawdata
    starting at kwargs['offset'] + kwargs['root_offset']

    If not provided, offset and root_offset default to 0.
    '''
    if new_value is not None:
示例#6
0
    def __init__(self, def_id_or_desc, *desc_entries, **kwargs):
        '''
        Initializes a BlockDef.

        Instead of passing a complete descriptor as a keyword argument,
        the int keyed entries in a descriptor may be passed as positional
        arguments and the str keyed entries as keyword arguments.

        Positional arguments:
        # str:
        def_id --------- An identifier string used for naming and keeping
                         track of BlockDefs. Used as the NAME entry in the
                         top level of the descriptor if one doesnt exist.

        Optional positional arguments:
        # dict:
        *desc_entries -- Dictionaries formatted as descriptors. A descriptor
                         will be built from all supplied positional arguments
                         and all keyword arguments(if the keyword is in the
                         desc_keywords set). Positional arguments are keyed
                         under the index they are located at in desc_entries,
                         and keyword arguments are keyed under their keyword.
                         If a FieldType is not supplied under the TYPE keyword,
                         the BlockDef will default to using Container.
                         If supplying a descriptor in this way, do not provide
                         one through the "descriptor" keyword as well. Doing
                         so will raise a TypeError

        Optional keyword arguments:
        # dict:
        descriptor ----- A dictionary which stores a detailed and well formed
                         tree of other detailed and well formed dictionaries
                         which each describe some type of data or structure.
                         Most descriptors are only required to have NAME and
                         TYPE entries, but depending on the FieldType instance
                         in the TYPE, other entries may be required.
                         If supplying a descriptor in this way, do not provide
                         one through positional arguments and desc_keyword
                         named arguments. Doing so will raise a TypeError
        subdefs -------- Used for storing individual or related pieces of
                         the structure.

        # str:
        align_mode ----- The alignment method to use for aligning containers
                         and their attributes to whole byte boundaries based
                         on each ones byte size. Valid values for this are
                         ALIGN_NONE and ALIGN_AUTO.
        endian --------- The default endianness to use for every field in the
                         descriptor. This can be overridden by specifying the
                         endianness per field. Endian carries over from outer
                         field to inner fields
        '''
        if self._initialized:
            return

        if isinstance(def_id_or_desc, dict):
            self.descriptor = def_id_or_desc
            def_id = def_id_or_desc["NAME"]
        else:
            def_id = def_id_or_desc

        if not hasattr(self, "descriptor"):
            self.descriptor = {}
        if not hasattr(self, "subdefs"):
            self.subdefs = {}

        self.align_mode = kwargs.pop("align_mode", self.align_mode)
        self.descriptor = kwargs.pop("descriptor", self.descriptor)
        self.endian = kwargs.pop("endian", self.endian)
        self.sani_warn = bool(kwargs.pop("sani_warn", self.sani_warn))
        self.subdefs = dict(kwargs.pop("subdefs", self.subdefs))
        self.def_id = def_id
        self._initialized = True

        # make sure def_id is valid
        if not isinstance(self.def_id, str):
            raise TypeError("Invalid type for 'def_id'. Expected %s, got %s." %
                            (str, type(self.def_id)))

        # make sure the endian value is valid
        if not isinstance(self.endian, str):
            raise TypeError("Invalid type for 'endian'. Expected %s, got %s." %
                            (str, type(self.endian)))

        if self.endian not in ('<', '', '>'):
            raise ValueError(
                "Invalid endianness character provided. Valid characters " +
                "are '<' for little, '>' for big, and '' for none.")

        # whether or not a descriptor should be built from the
        # keyword arguments and optional positional arguments.
        build_desc = (desc_entries
                      or not desc_keywords.isdisjoint(kwargs.keys()))

        if self.descriptor and build_desc:
            raise TypeError(
                ("A descriptor already exists or was provided for the " +
                 "'%s' BlockDef, but individual BlockDef arguments were " +
                 "also supplied.\nCannot accept positional arguments " +
                 "when a descriptor exists.") % self.def_id)

        # determine how to get/make this BlockDefs descriptor
        if build_desc:
            self.descriptor = self.make_desc(*desc_entries, **kwargs)
            self.descriptor = FrozenDict(self.sanitize(self.descriptor))
        elif isinstance(self.descriptor, BlockDef):
            self.subdefs.update(self.descriptor.subdefs)
            self.descriptor = FrozenDict(self.descriptor.descriptor)
        elif self.descriptor and kwargs.get('sanitize', True):
            self.descriptor = FrozenDict(self.sanitize(self.descriptor))

        self.make_subdefs()
示例#7
0
DEF_SHOW = frozenset(('type', 'name', 'value', 'offset', 'flags', 'size',
                      'steptrees', 'trueonly'))

# the most important things to show
MOST_SHOW = frozenset(("name", "value", "type", "offset", "steptrees", "flags",
                       "size", "index", "filepath", "binsize", "ramsize"))

# The things shown when printing a Block or Tag
# and one of the strings in 'show' is 'all'.
ALL_SHOW = frozenset(
    ("name", "value", "type", "offset", "steptrees", "flags", "unique", "size",
     "index", "raw", "filepath", "parent_id", "node_id", "node_cls", "binsize",
     "ramsize"))

SHOW_SETS = FrozenDict(min=MIN_SHOW,
                       default=DEF_SHOW,
                       most=MOST_SHOW,
                       all=ALL_SHOW)


def add_desc_keywords(*keywords):
    '''
    Adds the supplied positional arguments to the desc_keywords and
    reserved_desc_names sets and to this objects global namespace.

    Used for when you need to add new descriptor keywords.
    '''
    g = globals()
    for kw in keywords:
        g[kw] = kw
        desc_keywords.add(kw)
        reserved_desc_names.add(kw)
示例#8
0
import sys
from pathlib import Path

from binilla import editor_constants as b_e_c
from binilla.editor_constants import *
from binilla.widgets.binilla_widget import BinillaWidget
from binilla.widgets.font_config import FontConfig

from supyr_struct.defs.frozen_dict import FrozenDict

v2_mozz_color_names = v1_color_names + ("active_tags_directory", )
mozz_color_names = color_names + ("active_tags_directory", )
mozz_font_names = font_names + ("font_tag_preview", )

channel_name_map = FrozenDict(a='alpha', r='red', g='green', b='blue')
channel_offset_map = FrozenDict(a=24, r=16, g=8, b=0)

TITLE_WIDTH = b_e_c.TITLE_WIDTH = 28
DEF_STRING_ENTRY_WIDTH = b_e_c.TITLE_WIDTH = 30

if b_e_c.IS_WIN:
    FONT_TAG_PREVIEW_FONT_FAMILY = "System"
    FONT_TAG_PREVIEW_FONT_SIZE = 12
else:
    FONT_TAG_PREVIEW_FONT_FAMILY = "FreeMono"
    FONT_TAG_PREVIEW_FONT_SIZE = 12

FONT_TAG_PREVIEW_FONT_WEIGHT = "normal"
FONT_TAG_PREVIEW_FONT_SLANT = "roman"
示例#9
0
    "NONE",
))

H1_TAG_SUPERCLASSES = FrozenDict(
    shader_environment=("shader", "NONE"),
    shader_model=("shader", "NONE"),
    shader_transparent_generic=("shader", "NONE"),
    shader_transparent_chicago=("shader", "NONE"),
    shader_transparent_chicago_extended=("shader", "NONE"),
    shader_plasma=("shader", "NONE"),
    shader_meter=("shader", "NONE"),
    shader_water=("shader", "NONE"),
    shader_glass=("shader", "NONE"),
    biped=("unit", "object"),
    vehicle=("unit", "object"),
    weapon=("item", "object"),
    equipment=("item", "object"),
    garbage=("item", "object"),
    device_machine=("device", "object"),
    device_control=("device", "object"),
    device_light_fixture=("device", "object"),
    projectile=("object", "NONE"),
    scenery=("object", "NONE"),
    placeholder=("object", "NONE"),
    sound_scenery=("object", "NONE"),
    effect_postprocess_generic=("effect_postprocess", "NONE"),
    shader_postprocess_generic=("shader_postprocess", "NONE"),
)

del FrozenDict