Пример #1
0
    def __init__(self, materialPath=None, resolver=lambda x: hex(x)):
        super().__init__()
        self.path = materialPath if materialPath else ""
        self.material = MRL3(resolver)
        self.restorePoint = None
        if materialPath:
            with open(materialPath, "rb") as matFile:
                self.material.marshall(FileLike(matFile.read()))
        else:
            self.material.create()
        self.oldHash = self.material.generateHash()
        self.ui = Ui_Form()
        self.ui.setupUi(self)

        self.setupMaterialList()

        self.createPages(self.ui.MaterialHeaderView, self.material.Materials,
                         HeaderWidget)
        self.createPages(self.ui.ResourceBinding, self.material.Materials,
                         ResourceWidget)
        self.createPages(self.ui.ParameterView, self.material.Materials,
                         ParameterWidget)
        self.setupResourceList()

        self.ui.MaterialSelectorView.selectionModel().currentChanged.connect(
            self.pageSyncro)
Пример #2
0
 def compatibilize(self, materialPath):
     with open(materialPath, "rb") as mrl3File:
         data = mrl3File.read()
     if data[4] == 12:
         if all((data[i] == self.ibunkn[i - 4] for i in range(0x4, 0x10))):
             data = bytearray(data)
             data[0x4:0x10] = self.ibrunkn
             with open(materialPath, "wb") as mrl3File:
                 mrl3File.write(data)
     return
     m = BaseMrl3()
     m.marshall(FileLike(data))
     resources = m.Textures
     self.updateHeader(m.Header)
     for i in range(len(m.Materials)):
         try:
             m.Materials[i] = self.compatibilizeMaterial(
                 resources, m.Materials[i])
         except:
             #print("Error Updating %s"%materialPath + str(e))
             raise
     m.updateCountsAndOffsets()
     newMat = m.serialize()
     with open(materialPath, "wb") as mrl3File:
         mrl3File.write(newMat)
 def add(self, path):
     path = Path(path)
     with open(path,"rb") as matf:
         mat = MRL3()
         mat.marshall(FileLike(matf.read()))
         hashes = mat.getMaterialHashes()
     self.expand(OrderedDict([(path.resolve().as_posix(), hashes)]))
Пример #4
0
 def compatibilize(self, cclPath):
     with open(cclPath, "rb") as cclFile:
         c = CCL()
         c.marshall(FileLike(cclFile.read()))
         self.updateCursedBytes(c)
     with open(cclPath, "wb") as cclFile:
         cclFile.write(c.serialize())
Пример #5
0
    def dropMimeData(self, data, action, row, column, parent):
        if action == QtCore.Qt.IgnoreAction:
            return True
        if column > 0:
            return False
        num_rows = self.rowCount(QtCore.QModelIndex())
        if num_rows <= 0:
            return False

        if row < 0:
            if parent.isValid():
                row = parent.row()
            else:
                return False
        encoded_data = FileLike(data.data("custom/MaterialResource"))
        new_items = []
        while (encoded_data):
            cObj = self.default_type()
            cObj = self.list[0].__class__(
            ) if type(cObj) is DefaultType else cObj
            cObj.marshall(encoded_data)
            new_items.append(cObj)
        self.list[row:row] = new_items
        self.lastInsert = row
        self.lastInsertLength = len(new_items)
        self.pendingRemoveRowsAfterDrop = True
        self.swapOcurred.emit(self.lastSource, row)
        return True
Пример #6
0
 def compatibilize(self,ctcPath):
     with open(ctcPath,"rb") as ctcFile:
         data = ctcFile.read()
         if data[5] == b'\x1C':
             return
         c = Ctc()
         c.marshall(FileLike(data))
         self.updateCtc(c)
     with open(ctcPath,"wb") as ctcFile:
         ctcFile.write(c.serialize())
 def marshall(self, file):
     if getattr(file, "skip", False) == False: file = FileLike(file.read())
     self.Header.marshall(file)
     file.seek(self.Header.textureOffset)
     self.Textures = [MRL3Texture() for _ in range(self.Header.textureCount)]
     [mat.marshall(file) for mat in self.Textures]
     file.seek(self.Header.materialOffset)
     self.Materials = [MRL3Material(self.Resolver, self.Textures) for _ in range(self.Header.materialCount)]
     [mat.marshall(file) for mat in self.Materials]
Пример #8
0
 def loadAlternatives(self, alternativeList):
     self.altMap = {}
     self.altResources = {}
     for filename in alternativeList:
         try:
             m = BaseMrl3()
             with open(filename, "rb") as matfile:
                 m.marshall(FileLike(matfile.read()))
             for entry in m.Materials:
                 self.altMap[entry.Header.shaderHash] = entry
                 self.altResources[entry.Header.shaderHash] = m.Textures
         except:
             pass
     return
Пример #9
0
 def loadMaterialTable(self):
     try:
         listPath = appPath(r"Master_MtList_i.mrl3")
     except:
         listPath = r"..\Master_MtList_i.mrl3"
     im = IBMrl3()
     with open(self.resource_path(listPath), "rb") as tFile:
         data = tFile.read()
         im.marshall(FileLike(data))
     self.masterTable = im
     self.hashMap = {
         entry.Header.shaderHash: entry
         for entry in reversed(im.Materials)
     }
     self.masterResources = im.Textures
Пример #10
0
 def expand(self, files):
     dictList = []
     for file in files:
         try:
             with open(file, "rb") as matf:
                 mat = MRL3()
                 mat.marshall(FileLike(matf.read()))
                 hashes = mat.getMaterialHashes()
         except:
             hashes = []
         dictList += [(self.resolveHashToName(hashId), file)
                      for hashId in hashes]
     materialDict = {}
     for key, ele in dictList:
         if key not in materialDict: materialDict[key] = []
         materialDict[key].append(ele)
     self.MaterialSources.expand(materialDict)
     return
Пример #11
0
 def marshall(self, file):
     if getattr(file, "skip", False) == False: file = FileLike(file.read())
     self.Header.marshall(file)
     if self.Header.unknArr == MRL3Header.baseSignature:
         raise ValueError(
             "MHW Base Game Mrl3 is not compatible with the Current Editor or MHW Iceborne. Please use the updater tool first."
         )
     file.seek(self.Header.textureOffset)
     self.Textures = QTexList(
         [MRL3Texture() for _ in range(self.Header.textureCount)])
     [mat.marshall(file) for mat in self.Textures]
     file.seek(self.Header.materialOffset)
     self.Materials = QMatList([
         MRL3Material(self.Resolver, self.Textures)
         for _ in range(self.Header.materialCount)
     ], self)
     [mat.marshall(file) for mat in self.Materials]
            try:
                mx = currentResources.index(str(tex))+1
            except:
                currentResources.append(str(tex))
                self.Textures.insertRow(len(self.Textures))
                self.Textures[-1] = tex
                self.Textures.setData(self.Textures.index(len(self.Textures)-1,0,QtCore.QModelIndex()),str(tex),QtCore.Qt.EditRole)
                mx = len(self.Textures)
            mapper[ix]=mx
        for material in reversed(mrl3.Materials):
            for resource in material.resourceBindings:
                resource.setIdx( mapper[resource.texIdx] if resource.texIdx in mapper else resource.texIdx )
            material.ResourceData = self.Textures
            self.Materials.insertRow(row)
            self.Materials.setData(self.Materials.index(row,0,QtCore.QModelIndex()),material,QtCore.Qt.EditRole)
            
    def generateHash(self):
        return hashlib.blake2b(self.serialize()).digest()
    
  
if "__main__" in __name__:
    from pathlib import Path
    testPath = Path(r"E:\IBProjects\ArmorPorts\Lightning - Copy\otomo\equip\ot035\body\mod\ot_body035.mrl3")#E:\MHW\Merged\Master_MtList.mrl3")
    m = MRL3()
    with open(testPath,"rb") as tFile:
        data = tFile.read()
        m.marshall(FileLike(data))
    for ix,(b,j) in enumerate(zip(data, m.serialize())):
        if b!=j:
            print (ix)
            break
Пример #13
0
        return __idxChange__

    def resync(self):
        currentIx = self.currentSelection()
        if currentIx == -1:
            return
        self.ui.ResourceIx.setValue(
            self.material.resourceBindings[currentIx].texIdx)
        self.syncIx(currentIx)

    def sync(self):
        currentIx = self.currentSelection()
        self.syncIx(currentIx)

    def syncIx(self, currentIx):
        currentTexIx = self.material.resourceBindings[currentIx].texIdx
        resourcePaths = self.material.ResourceData
        materialPath = str(resourcePaths[currentTexIx - 1]).replace(
            "\x00", "") if 0 < currentTexIx <= len(resourcePaths) else ""
        self.ui.ResourceLabel.setText(materialPath)


if "__main__" in __name__:
    from common.FileLike import FileLike
    from mrl3.MaterialMrl3 import MRL3
    app = QtWidgets.QApplication(sys.argv)
    material = MRL3()
    with open(r"E:\MHW\Merged\Master_MtList.mrl3", "rb") as matFile:
        material.marshall(FileLike(matFile.read()))
    window = ResourceWidget(material.Materials[0])
    sys.exit(app.exec_())
Пример #14
0
 def __getitem__(self, field):
     struct = self.structures[field]
     return {"size":len(struct()),"serializer":(lambda x: x.serialize()), "deserializer":(lambda x: struct().marshall(FileLike(x)))}
Пример #15
0
 def __init__(self, path):
     with open(str(path),"rb") as data:
         datum = FileLike(data.read())
         self.data = capClass().marshall(datum)
 def __init__(self, path=None):
     if path is not None:
         with open(path, "rb") as inf:
             self.marshall(FileLike(inf.read()))