예제 #1
0
#
# You should have received a copy of the GNU General Public License
# along with HSPlasma.  If not, see <http://www.gnu.org/licenses/>.

# This script extracts an object from a prp file and dumps it into anotehr file.
# The object is *not* parsed and re-packed, so this is not necessarily the same as e.g. exporting in PrpShop!
# by Diafero

import sys
import PyHSPlasma

if len(sys.argv) != 5:
    print "Usage: %s filename typename objectname outfile" % sys.argv[0]
    sys.exit(0)

rm = PyHSPlasma.plResManager()
page = rm.ReadPage(sys.argv[1], True)
type = PyHSPlasma.plFactory.ClassIndex(sys.argv[2])
if type < 0:
    print "Type '%s' is invalid" % sys.argv[2]
    sys.exit(1)
keys = rm.getKeys(page.location, type)

for key in keys:
    if key.name != sys.argv[3]: continue
    # get the data
    data = key.object.stub.getData()
    # and save it
    f = open(sys.argv[4], 'w')
    f.write(data)
    f.close()
예제 #2
0
    def run(self):
        if self._fromXML:
            return self.readQueueFromXML()

        datadir = os.path.join(self._inpath, DefaultDataDir)

        ## Only display Errors
        PyHSPlasma.plDebug.Init(PyHSPlasma.plDebug.kDLError)

        ## Create our Resource Manager
        plResMgr = PyHSPlasma.plResManager()

        ## Get Age list for progress
        self.postUpdateStatus("Loading Age files...")

        numAges = len(glob.glob(os.path.join(datadir, "*.age")))
        numAgesRead = 0
        if numAges == 0:
            self.postDialogBox(
                ("No Age files found in {0}\n\nDecompression aborted.".format(
                    datadir), 'No Ages Found', wx.OK | wx.ICON_EXCLAMATION))
            self.postQueueBuildFail(
                "No Age files found in {0}.  Aborted.".format(datadir))
            return False

        self.postUpdateStatus("{0} Ages found in {1}.\nScanning...".format(
            numAges, datadir))

        ## Flip through all ages
        self.postUpdateProgress(float(numAgesRead) / float(numAges) * 100)
        for ageFile in glob.iglob(os.path.join(datadir, "*.age")):
            fullpath = os.path.abspath(ageFile)

            self.postUpdateStatus("Scanning {0} ...".format(
                os.path.basename(ageFile)))

            ## Too fast and the message event pump gets stuck, so wait
            time.sleep(0.5)

            if self.shouldAbort(): return False

            try:
                age = plResMgr.ReadAge(fullpath, True)
            except IOError as e:
                self.postUpdateStatus(
                    "Skipping {0} - Unable to read Age.".format(
                        os.path.basename(ageFile)))
            except Exception as e:
                self.postDialogBox(("Error loading Age - {0}".format(e),
                                    "Fatal Error", wx.OK | wx.ICON_ERROR))
                self.postQueueBuildFail(
                    "Error loading Age - {0}".format(ageFile))
                return False
            else:
                try:
                    ## Get the plSoundBuffer in each page and queue sounds
                    ##  which are not set to StreamCompressed
                    for pageNum in range(0, age.getNumPages()):
                        if self.shouldAbort(): return False

                        page = plResMgr.FindPage(
                            age.getPageLoc(pageNum, plResMgr.getVer()))
                        if PyHSPlasma.plFactory.kSoundBuffer in plResMgr.getTypes(
                                page.location):
                            for key in plResMgr.getKeys(
                                    page.location,
                                    PyHSPlasma.plFactory.kSoundBuffer):
                                soundBuffer = key.object

                                if soundBuffer.fileName in self._queue.keys():
                                    channelOptions = self._queue[
                                        soundBuffer.fileName]
                                else:
                                    channelOptions = {}

                                if (soundBuffer.flags
                                        & soundBuffer.kOnlyRightChannel):
                                    channel = channelOptions["Right"] = True
                                if (soundBuffer.flags
                                        & soundBuffer.kOnlyLeftChannel):
                                    channel = channelOptions["Left"] = True
                                if not channelOptions:
                                    channelOptions["Both"] = True

                                if not (soundBuffer.flags
                                        & soundBuffer.kStreamCompressed):
                                    self._queue[
                                        soundBuffer.fileName] = channelOptions
                except MemoryError as e:
                    self.postDialogBox(
                        ("Fatal Error - Unable to process Age ({0}) - {1}".
                         format(age.name,
                                e), "Fatal Error", wx.OK | wx.ICON_ERROR))
                    self.postQueueBuildFail(
                        "Unable to process Age ({0}) - {1}".format(age.name))
                    return False

                plResMgr.UnloadAge(age.name)

            ## Onto the next
            numAgesRead = numAgesRead + 1
            self.postUpdateProgress(float(numAgesRead) / float(numAges) * 100)

        self.postUpdateStatus("{0} sound files added to queue.".format(
            len(self._queue)))
        self.postQueueBuildComplete(self._queue)
        self.postUpdateProgress(100)
        return True
예제 #3
0
def doConvert(ageName, inpath, newAgeName, outpath, newSeqPrefix,
              newPlasmaVersion):
    ## Create our Resource Manager
    plResMgr = PyHSPlasma.plResManager()

    ageFile = os.path.join(inpath, ageName)
    fullpath = os.path.abspath(ageFile)

    try:
        logging.info("Loading '{0}'...".format(ageFile))
        age = plResMgr.ReadAge(fullpath, True)
        logging.info("Age version: {0}".format(
            versionNames[plResMgr.getVer()]))
    except IOError as e:
        logging.critical("Unable to read Age: {0}".format(ageFile))
        return False
    except KeyboardInterrupt:
        logging.critical("Interrupt detected. Aborting.")
        return False
    else:
        try:
            logging.info("Processing {0}".format(age.name))

            ## Flip through pages and update to new location, if needed
            if newSeqPrefix != None:
                locs = plResMgr.getLocations()
                for pageLoc in locs:
                    logging.info(
                        "Changing page prefix for {0} (SeqPrefix: {1} --> {2})"
                        .format(pageLoc.page, age.seqPrefix, newSeqPrefix))
                    newPageLoc = updateLocation(pageLoc, newSeqPrefix)
                    plResMgr.ChangeLocation(pageLoc, newPageLoc)
            else:
                newSeqPrefix = age.seqPrefix

            ## Filter unsupported objects or objects which require conversion
            plResMgr.setVer(newPlasmaVersion, True)
            logging.info("Converting to version: {0}".format(
                versionNames[plResMgr.getVer()]))
            locs = plResMgr.getLocations()
            for pageLoc in locs:
                pageInfo = plResMgr.FindPage(pageLoc)
                plResMgr.setVer(newPlasmaVersion, True)
                logging.info("Processing page {0}: {1}".format(
                    pageLoc.page, pageInfo.page))

                if plResMgr.getVer() in unsupportedTypeList:
                    for objectType in unsupportedTypeList[plResMgr.getVer()]:
                        logging.info(
                            "Removing unsupported objects (type: {0})".format(
                                PyHSPlasma.plFactory.ClassName(objectType)))
                        removeUnsupportedObjects(plResMgr, objectType, pageLoc)
                pageInfo.age = newAgeName

                ## Write page
                pageOut = os.path.abspath(
                    os.path.join(outpath,
                                 pageInfo.getFilename(newPlasmaVersion)))
                plResMgr.WritePage(pageOut, pageInfo)

            ## Write final Age
            age.seqPrefix = newSeqPrefix
            age.name = newAgeName
            ageOut = os.path.abspath(os.path.join(outpath, age.name + ".age"))
            age.writeToFile(ageOut, newPlasmaVersion)

        except MemoryError as e:
            logging.critical("Unable to process Age ({0}) - {1}".format(
                age.name, e))
            return False
        except KeyboardInterrupt:
            logging.critical("Interrupt detected. Aborting.")
            return False
        except Exception as e:
            logging.critical("Unhandled exception: {0}".format(e))
            return False

        plResMgr.UnloadAge(age.name)
예제 #4
0
def getDecompressQueue(datadir):
    if not libPlasma:
        print(
            "\nFatal Error: PyHSPlasma module not loaded.  Reading of Age files unavailable."
        )
        return False
    ## Only display Errors
    PyHSPlasma.plDebug.Init(PyHSPlasma.plDebug.kDLError)

    ## Create our Resource Manager
    plResMgr = PyHSPlasma.plResManager()

    ## Get Age list for progress
    print("Loading Age files...")
    numAges = len(glob.glob(os.path.join(datadir, "*.age")))
    numAgesRead = 0
    if numAges == 0:
        print("No Age files found.  Quitting.")
        return False

    print("{0} Ages found in {1}.\nScanning...".format(numAges, datadir))

    ## Flip through all ages
    progress(50, float(numAgesRead) / float(numAges) * 100)
    for ageFile in glob.iglob(os.path.join(datadir, "*.age")):
        fullpath = os.path.abspath(ageFile)

        try:
            age = plResMgr.ReadAge(fullpath, True)
        except IOError as e:
            print("Warning - Unable to read Age: {0}".format(ageFile),
                  file=sys.stderr)
        except KeyboardInterrupt:
            print("\nInterrupt detected. Aborting.")
            return False
        else:
            try:
                ## Get the plSoundBuffer in each page and queue sounds
                ##  which are not set to StreamCompressed
                for pageNum in range(0, age.getNumPages()):
                    page = plResMgr.FindPage(
                        age.getPageLoc(pageNum, plResMgr.getVer()))
                    if (page == None):
                        raise Exception(
                            "Unable to completely load age " + age.name +
                            ": Can't find page " +
                            str(age.getPageLoc(pageNum, plResMgr.getVer())))
                    if PyHSPlasma.plFactory.kSoundBuffer in plResMgr.getTypes(
                            page.location):
                        for key in plResMgr.getKeys(
                                page.location,
                                PyHSPlasma.plFactory.kSoundBuffer):
                            soundBuffer = key.object

                            if soundBuffer.fileName in queue.keys():
                                channelOptions = queue[soundBuffer.fileName]
                            else:
                                channelOptions = {}

                            if (soundBuffer.flags
                                    & soundBuffer.kOnlyRightChannel):
                                channel = channelOptions["Right"] = True
                            if (soundBuffer.flags
                                    & soundBuffer.kOnlyLeftChannel):
                                channel = channelOptions["Left"] = True
                            if channelOptions == {}:
                                channelOptions["Both"] = True

                            if not (soundBuffer.flags
                                    & soundBuffer.kStreamCompressed):
                                queue[soundBuffer.fileName] = channelOptions
            except MemoryError as e:
                print(
                    "\nFatal Error - Unable to process Age ({0}) - {1}".format(
                        age.name, e),
                    file=sys.stderr)
                return False
            except KeyboardInterrupt:
                print("\nInterrupt detected. Aborting.")
                return False

            plResMgr.UnloadAge(age.name)

        ## Onto the next
        numAgesRead = numAgesRead + 1
        progress(50, float(numAgesRead) / float(numAges) * 100)

    print("{0} sound files added to queue.".format(len(queue)))
    return True
예제 #5
0
    def run(self):
        if self._fromXML:
            return self.readQueueFromXML()

        datadir = os.path.join(self._inpath, DefaultDataDir)

        ## Only display Errors
        PyHSPlasma.plDebug.Init(PyHSPlasma.plDebug.kDLError)

        ## Create our Resource Manager
        plResMgr = PyHSPlasma.plResManager()

        ## Get Age list for progress
        self.postUpdateStatus("Loading Age files...")

        numAges = len(glob.glob(os.path.join(datadir, "*.age")))
        numAgesRead = 0
        if numAges == 0:
            self.postDialogBox(("No Age files found in {0}\n\nDecompression aborted.".format(datadir), 'No Ages Found',
                                wx.OK | wx.ICON_EXCLAMATION))
            self.postQueueBuildFail("No Age files found in {0}.  Aborted.".format(datadir))
            return False

        self.postUpdateStatus("{0} Ages found in {1}.\nScanning...".format(numAges, datadir))

        ## Flip through all ages
        self.postUpdateProgress(float(numAgesRead)/float(numAges) * 100)
        for ageFile in glob.iglob(os.path.join(datadir,"*.age")):
            fullpath = os.path.abspath(ageFile)

            self.postUpdateStatus("Scanning {0} ...".format(os.path.basename(ageFile)))

            ## Too fast and the message event pump gets stuck, so wait
            time.sleep(0.5)

            if self.shouldAbort(): return False

            try:
                age = plResMgr.ReadAge(fullpath, True)
            except IOError as e:
                self.postUpdateStatus("Skipping {0} - Unable to read Age.".format(os.path.basename(ageFile)))
            except Exception as e:
                self.postDialogBox(("Error loading Age - {0}".format(e), "Fatal Error",
                                    wx.OK | wx.ICON_ERROR))
                self.postQueueBuildFail("Error loading Age - {0}".format(ageFile))
                return False
            else:
                try:
                    ## Get the plSoundBuffer in each page and queue sounds
                    ##  which are not set to StreamCompressed
                    for pageNum in range(0, age.getNumPages()):
                        if self.shouldAbort(): return False

                        page = plResMgr.FindPage(age.getPageLoc(pageNum, plResMgr.getVer()))
                        if PyHSPlasma.plFactory.kSoundBuffer in plResMgr.getTypes(page.location):
                            for key in plResMgr.getKeys(page.location, PyHSPlasma.plFactory.kSoundBuffer):
                                soundBuffer = key.object

                                if soundBuffer.fileName in self._queue.keys():
                                    channelOptions = self._queue[soundBuffer.fileName]
                                else:
                                    channelOptions = {}

                                if (soundBuffer.flags & soundBuffer.kOnlyRightChannel): channel = channelOptions["Right"] = True
                                if (soundBuffer.flags & soundBuffer.kOnlyLeftChannel): channel = channelOptions["Left"] = True
                                if channelOptions == {}: channelOptions["Both"] = True

                                if not (soundBuffer.flags & soundBuffer.kStreamCompressed):
                                    self._queue[soundBuffer.fileName] = channelOptions
                except MemoryError as e:
                    self.postDialogBox(("Fatal Error - Unable to process Age ({0}) - {1}".format(age.name, e), "Fatal Error",
                                        wx.OK | wx.ICON_ERROR))
                    self.postQueueBuildFail("Unable to process Age ({0}) - {1}".format(age.name))
                    return False

                plResMgr.UnloadAge(age.name)

            ## Onto the next
            numAgesRead = numAgesRead + 1
            self.postUpdateProgress(float(numAgesRead)/float(numAges) * 100)

        self.postUpdateStatus("{0} sound files added to queue.".format(len(self._queue)))
        self.postQueueBuildComplete(self._queue)
        self.postUpdateProgress(100)
        return True
예제 #6
0
def getDecompressQueue(datadir):
    if not libPlasma:
        print("\nFatal Error: PyHSPlasma module not loaded.  Reading of Age files unavailable.")
        return False
    ## Only display Errors
    PyHSPlasma.plDebug.Init(PyHSPlasma.plDebug.kDLError)

    ## Create our Resource Manager
    plResMgr = PyHSPlasma.plResManager()

    ## Get Age list for progress
    print("Loading Age files...")
    numAges = len(glob.glob(os.path.join(datadir, "*.age")))
    numAgesRead = 0
    if numAges == 0:
        print("No Age files found.  Quitting.")
        return False

    print("{0} Ages found in {1}.\nScanning...".format(numAges, datadir))

    ## Flip through all ages
    progress(50, float(numAgesRead)/float(numAges) * 100)
    for ageFile in glob.iglob(os.path.join(datadir,"*.age")):
        fullpath = os.path.abspath(ageFile)

        try:
            age = plResMgr.ReadAge(fullpath, True)
        except IOError as e:
            print("Warning - Unable to read Age: {0}".format(ageFile), file=sys.stderr)
        except KeyboardInterrupt:
            print("\nInterrupt detected. Aborting.")
            return False
        else:
            try:
                ## Get the plSoundBuffer in each page and queue sounds
                ##  which are not set to StreamCompressed
                for pageNum in range(0, age.getNumPages()):
                    page = plResMgr.FindPage(age.getPageLoc(pageNum, plResMgr.getVer()))
                    if (page == None):
                        raise Exception("Unable to completely load age "+age.name+": Can't find page "+str(age.getPageLoc(pageNum, plResMgr.getVer())))
                    if PyHSPlasma.plFactory.kSoundBuffer in plResMgr.getTypes(page.location):
                        for key in plResMgr.getKeys(page.location, PyHSPlasma.plFactory.kSoundBuffer):
                            soundBuffer = key.object

                            if soundBuffer.fileName in queue.keys():
                                channelOptions = queue[soundBuffer.fileName]
                            else:
                                channelOptions = {}

                            if (soundBuffer.flags & soundBuffer.kOnlyRightChannel): channel = channelOptions["Right"] = True
                            if (soundBuffer.flags & soundBuffer.kOnlyLeftChannel): channel = channelOptions["Left"] = True
                            if channelOptions == {}: channelOptions["Both"] = True

                            if not (soundBuffer.flags & soundBuffer.kStreamCompressed):
                                queue[soundBuffer.fileName] = channelOptions
            except MemoryError as e:
                print("\nFatal Error - Unable to process Age ({0}) - {1}".format(age.name, e), file=sys.stderr)
                return False
            except KeyboardInterrupt:
                print("\nInterrupt detected. Aborting.")
                return False

            plResMgr.UnloadAge(age.name)

        ## Onto the next
        numAgesRead = numAgesRead + 1
        progress(50, float(numAgesRead)/float(numAges) * 100)

    print("{0} sound files added to queue.".format(len(queue)))
    return True
예제 #7
0
def doConvert(ageName, inpath, newAgeName, outpath, newSeqPrefix, newPlasmaVersion):
    ## Create our Resource Manager
    plResMgr = PyHSPlasma.plResManager()

    ageFile  = os.path.join(inpath, ageName)
    fullpath = os.path.abspath(ageFile)

    try:
        logging.info("Loading '{0}'...".format(ageFile))
        age = plResMgr.ReadAge(fullpath, True)
        logging.info("Age version: {0}".format(versionNames[plResMgr.getVer()]))
    except IOError as e:
        logging.critical("Unable to read Age: {0}".format(ageFile))
        return False
    except KeyboardInterrupt:
        logging.critical("Interrupt detected. Aborting.")
        return False
    else:
        try:
            logging.info("Processing {0}".format(age.name))

            ## Flip through pages and update to new location, if needed
            if newSeqPrefix != None:
                locs = plResMgr.getLocations()
                for pageLoc in locs:
                    logging.info("Changing page prefix for {0} (SeqPrefix: {1} --> {2})".format(pageLoc.page, age.seqPrefix, newSeqPrefix))
                    newPageLoc = updateLocation(pageLoc, newSeqPrefix)
                    plResMgr.ChangeLocation(pageLoc, newPageLoc)
            else:
                newSeqPrefix = age.seqPrefix

            ## Filter unsupported objects or objects which require conversion
            plResMgr.setVer(newPlasmaVersion, True)
            logging.info("Converting to version: {0}".format(versionNames[plResMgr.getVer()]))
            locs = plResMgr.getLocations()
            for pageLoc in locs:
                pageInfo = plResMgr.FindPage(pageLoc)
                plResMgr.setVer(newPlasmaVersion, True)
                logging.info("Processing page {0}: {1}".format(pageLoc.page, pageInfo.page))

                if plResMgr.getVer() in unsupportedTypeList:
                    for objectType in unsupportedTypeList[plResMgr.getVer()]:
                        logging.info("Removing unsupported objects (type: {0})".format(PyHSPlasma.plFactory.ClassName(objectType)))
                        removeUnsupportedObjects(plResMgr, objectType, pageLoc)
                pageInfo.age = newAgeName

                ## Write page
                pageOut = os.path.abspath(os.path.join(outpath, pageInfo.getFilename(newPlasmaVersion)))
                plResMgr.WritePage(pageOut, pageInfo)

            ## Write final Age
            age.seqPrefix = newSeqPrefix
            age.name = newAgeName
            ageOut = os.path.abspath(os.path.join(outpath, age.name + ".age"))
            age.writeToFile(ageOut, newPlasmaVersion)

        except MemoryError as e:
            logging.critical("Unable to process Age ({0}) - {1}".format(age.name, e))
            return False
        except KeyboardInterrupt:
            logging.critical("Interrupt detected. Aborting.")
            return False
        except Exception as e:
            logging.critical("Unhandled exception: {0}".format(e))
            return False

        plResMgr.UnloadAge(age.name)