コード例 #1
0
ファイル: resource.py プロジェクト: rmilne/pynwn
    def from_module(mod, use_override=False, include_bioware=True, path = "C:\\NeverwinterNights\\NWN\\"):
        """Creates a ResourceManager object from a module or module director.

        :param mod: Path to module or module directory.
        :param use_override: default False, If true the overried directory in ``path`` will be used.
        :param include_bioware: default True, If false Bioware NWN BIF files will not be used.
        :param path: default "C:\\NeverwinterNights\\NWN\\", Path to NWN directory.

        **NOTES:**

        * If a directory is passed in ``mod`` it **must** contain a ``module.ifo`` file.
        * If ``include_bioware`` is ``False``, ``path`` can be any working directory
          that has the same directory stucture as the default NWN installation. I.e.
          hak files are in the subdirectory 'hak', overrides in directory 'override'.
        * When loading the module's HAKs .hak files will attempt to be loaded first.
          If no file exists, then a directory with the ``.hak`` files name will attempt
          to be loaded.


        """
        from pynwn.file.key import Key
        from pynwn.file.erf import Erf
        from pynwn.module import Module as Mod

        mgr = ResourceManager()

        # Override
        if use_override:
            mgr.add_container(DirectoryContainer(os.path.join(path, 'override')))

        # Module
        mgr.module = Mod(mod)
        mgr.add_container(mgr.module.container)

        dialog = os.path.join(path, 'dialog.tlk')
        custom = os.path.join(path, 'tlk', mgr.module.tlk + '.tlk')
        mgr.tlktable = TlkTable(open(dialog, 'rb'),
                                open(custom, 'rb'))

        # All custom haks
        for hak in mgr.module.haks:
            h_path = os.path.join(path, 'hak', hak)
            h_file = h_path + '.hak'
            if os.path.isfile(h_file):
                print("Adding HAK %s..." % (h_file))
                mgr.add_container(Erf.from_file(h_file))
            elif os.path.isdir(h_path):
                mgr.add_container(DirectoryContainer(h_path))
                print("Adding HAK directory %s..." % h_path)
            else:
                print("Error no HAK file or HAK directory found: %s" % hak)


        # First, all the base data files.
        if include_bioware:
            for key in ['xp3.key', 'xp2patch.key', 'xp2.key', 'xp1.key', 'chitin.key']:
                mgr.add_container(Key(os.path.join(path, key), path))

        return mgr
コード例 #2
0
ファイル: resource.py プロジェクト: rmilne/pynwn
    def from_module(mod, use_override=False, include_bioware=True, path="C:\\NeverwinterNights\\NWN\\"):
        """Creates a ResourceManager object from a module or module director.

        :param mod: Path to module or module directory.
        :param use_override: default False, If true the overried directory in ``path`` will be used.
        :param include_bioware: default True, If false Bioware NWN BIF files will not be used.
        :param path: default "C:\\NeverwinterNights\\NWN\\", Path to NWN directory.

        **NOTES:**

        * If a directory is passed in ``mod`` it **must** contain a ``module.ifo`` file.
        * If ``include_bioware`` is ``False``, ``path`` can be any working directory
          that has the same directory stucture as the default NWN installation. I.e.
          hak files are in the subdirectory 'hak', overrides in directory 'override'.
        * When loading the module's HAKs .hak files will attempt to be loaded first.
          If no file exists, then a directory with the ``.hak`` files name will attempt
          to be loaded.


        """
        from pynwn.file.key import Key
        from pynwn.file.erf import Erf
        from pynwn.module import Module as Mod

        mgr = ResourceManager()

        # Override
        if use_override:
            mgr.add_container(DirectoryContainer(os.path.join(path, "override")))

        # Module
        mgr.module = Mod(mod)
        mgr.add_container(mgr.module.container)

        dialog = os.path.join(path, "dialog.tlk")
        custom = os.path.join(path, "tlk", mgr.module.tlk + ".tlk")
        mgr.tlktable = TlkTable(open(dialog, "rb"), open(custom, "rb"))

        # All custom haks
        for hak in mgr.module.haks:
            h_path = os.path.join(path, "hak", hak)
            h_file = h_path + ".hak"
            if os.path.isfile(h_file):
                print("Adding HAK %s..." % (h_file))
                mgr.add_container(Erf.from_file(h_file))
            elif os.path.isdir(h_path):
                mgr.add_container(DirectoryContainer(h_path))
                print("Adding HAK directory %s..." % h_path)
            else:
                print("Error no HAK file or HAK directory found: %s" % hak)

        # First, all the base data files.
        if include_bioware:
            for key in ["xp3.key", "xp2patch.key", "xp2.key", "xp1.key", "chitin.key"]:
                mgr.add_container(Key(os.path.join(path, key), path))

        return mgr
コード例 #3
0
ファイル: module.py プロジェクト: rmilne/pynwn
    def __init__(self, module):
        if not isinstance(module, str):
            raise ValueError("Module must be instantiated with a file path to a MOD file or a directory")

        if os.path.isdir(module):
            self.container = RES.DirectoryContainer(module)
        elif os.path.isfile(module):
            # If it's a file, assume that it is a module ERF.
            self.container = Erf.from_file(module)
        else:
            msg = "File/Directory %s does not exist!" % module
            raise ValueError(msg)

        if not self.container.has_file("module.ifo"):
            raise ValueError("The %s Container has no module.ifo!" % module)

        self.gff = Gff(self.container["module.ifo"])

        self._scripts = None
        self._vars = None
        self._locstr = {}
コード例 #4
0
    def __init__(self, module):
        if not isinstance(module, str):
            raise ValueError(
                "Module must be instantiated with a file path to a MOD file or a directory"
            )

        if os.path.isdir(module):
            self.container = RES.DirectoryContainer(module)
        elif os.path.isfile(module):
            # If it's a file, assume that it is a module ERF.
            self.container = Erf.from_file(module)
        else:
            msg = "File/Directory %s does not exist!" % module
            raise ValueError(msg)

        if not self.container.has_file('module.ifo'):
            raise ValueError("The %s Container has no module.ifo!" % module)

        self.gff = Gff(self.container['module.ifo'])

        self._scripts = None
        self._vars = None
        self._locstr = {}