def generateAiScripts(self, baseFolder, targetFolder, dcx=True): """ Extract all unique .lua files from .laubnd files so they can be easily accessed. """ SN_RGX = r"[1-9][0-9][0-9][0-9][0-9][0-9]_(battle|logic).lua" inputFiles = [ "m10_00_00_00", "m10_01_00_00", "m10_02_00_00", "m11_00_00_00", "m12_00_00_00", "m12_01_00_00", "m13_00_00_00", "m13_01_00_00", "m13_02_00_00", "m14_00_00_00", "m14_01_00_00", "m15_00_00_00", "m15_01_00_00", "m16_00_00_00", "m17_00_00_00", "m18_00_00_00", "m18_01_00_00" ] tempList = [] for iFile in inputFiles: fullName = baseFolder + iFile + '.luabnd' if (dcx): fullName += '.dcx' with open(fullName, 'rb') as f: content = f.read() bndcontent = content if (dcx): dcxHandler = DCXHandler() bndcontent = dcxHandler.open_dcx(content) data = bnd_rebuilder.unpack_bnd(bndcontent) for item in data: strName = item[1].decode('shift_jis') match = re.search(SN_RGX, strName) if not (match == None): if not strName in tempList: tempList.append(strName) fileName = match.group(0) if not (os.path.isfile(targetFolder + fileName)): with open(targetFolder + fileName, 'wb') as wf: wf.write(item[2])
def open(self, mapName): filename = "event/{0}.emevd{1}".format(mapName, ".dcx" if self.dcx else "") # Create a backup if not os.path.isfile(filename + ".bak"): with open(filename, 'rb') as origf: with open(filename + '.bak', 'wb') as bakf: bakf.write(origf.read()) self.disableRespawnEventIndex = 0 self.tailCutEventIndex = 0 self.eventHandler = EmevdHandler() with open(filename, 'rb') as f: content = f.read() if (self.dcx): dcxh = DCXHandler() content = dcxh.open_dcx(content) self.eventHandler.read(content) self.currentDisableRespawnEventID = self.disableRespawnEventIDs[ mapName] self.currentTailCutEventID = self.currentDisableRespawnEventID + 200 self.currentItemLotAwardEventID = self.currentDisableRespawnEventID - 200 self.templates[ idxDisableRespawn].eventId = self.currentDisableRespawnEventID self.eventHandler.events.append(self.templates[idxDisableRespawn]) self.templates[idxTailCut].eventId = self.currentTailCutEventID self.eventHandler.events.append(self.templates[idxTailCut]) self.templates[ idxItemLotAwardOnKill].eventId = self.currentItemLotAwardEventID self.eventHandler.events.append(self.templates[idxItemLotAwardOnKill]) self.EnableUndeadDragonsGravity(mapName)
class BndData(): """ Class to handle .luabnd files and adding the .lua files to them. """ def __init__(self): self.luabnd_content = [] self.luabnd_maxIndex = 1 self.basePath = b'N:\\FRPG\\data\\INTERROOT_win32\\script\\ai\\out\\bin\\' self.basePathRemaster = b'N:\\FRPG\\data\\INTERROOT_x64\\script\\ai\\out\\bin\\' self.dcxhandler = None self.useDCXCompression = False def open(self, filename, dcx=True): """ Opens .luabnd file with filename @filename. """ self.luabnd_content = [] self.luabnd_maxIndex = 0 self.useDCX = dcx fullname = filename if (self.useDCX): fullname += '.dcx' with open(fullname, 'rb') as f: content = f.read() bndcontent = content if (self.useDCX): self.dcxhandler = DCXHandler() bndcontent = self.dcxhandler.open_dcx(content) self.luabnd_content = bnd_rebuilder.unpack_bnd(bndcontent) luagnlBytes = b'' luainfoBytes = b'' self.luabnd_maxIndex = 0 for item in self.luabnd_content: if (item[0] == 1000000): luagnlBytes = item[2] elif (item[0] == 1000001): luainfoBytes = item[2] else: if (item[0] > self.luabnd_maxIndex): self.luabnd_maxIndex = item[0] return (luagnlBytes, luainfoBytes) def save(self, filename, luagnlBytes, luainfoBytes): """ Save the luabnd file as @filename. """ if (not self.useDCX): if (not os.path.isfile(filename + '.bak')): with open(filename + '.bak', 'wb') as bakf: with open(filename, 'rb') as oldf: bakf.write(oldf.read()) new_content = [] for i in range(len(self.luabnd_content)): if (self.luabnd_content[i][0] == 1000000): new_content.append((self.luabnd_content[i][0], self.luabnd_content[i][1], luagnlBytes)) elif (self.luabnd_content[i][0] == 1000001): new_content.append((self.luabnd_content[i][0], self.luabnd_content[i][1], luainfoBytes)) else: new_content.append(self.luabnd_content[i]) if (self.useDCX): self.dcxhandler.save_dcx(filename + '.dcx', bnd_rebuilder.repack_bnd(new_content)) else: with open(filename, 'wb') as f: f.write(bnd_rebuilder.repack_bnd(new_content)) def add(self, scriptName, newBytes): """ Add a .lua file with the name @scriptName and contents @newBytes to the currently opened .luabnd file """ newPath = self.basePath + byteread.EncodeString(scriptName) if (self.useDCX): newPath = self.basePathRemaster + byteread.EncodeString(scriptName) dta = (self.luabnd_maxIndex + 1, newPath, newBytes) self.luabnd_content.insert(-2, dta) self.luabnd_maxIndex += 1 def addAuto(self, scriptName): """ Adds <scriptName>.lua to currently opened .luabnd file. """ if not (scriptName == ""): with open('enemyRandomizerData\\aiscripts\\' + scriptName, 'rb') as aif: data = aif.read() self.add(scriptName, data) def delete(self, index): del self.luabnd_content[index] def generateAiScripts(self, baseFolder, targetFolder, dcx=True): """ Extract all unique .lua files from .laubnd files so they can be easily accessed. """ SN_RGX = r"[1-9][0-9][0-9][0-9][0-9][0-9]_(battle|logic).lua" inputFiles = [ "m10_00_00_00", "m10_01_00_00", "m10_02_00_00", "m11_00_00_00", "m12_00_00_00", "m12_01_00_00", "m13_00_00_00", "m13_01_00_00", "m13_02_00_00", "m14_00_00_00", "m14_01_00_00", "m15_00_00_00", "m15_01_00_00", "m16_00_00_00", "m17_00_00_00", "m18_00_00_00", "m18_01_00_00" ] tempList = [] for iFile in inputFiles: fullName = baseFolder + iFile + '.luabnd' if (dcx): fullName += '.dcx' with open(fullName, 'rb') as f: content = f.read() bndcontent = content if (dcx): dcxHandler = DCXHandler() bndcontent = dcxHandler.open_dcx(content) data = bnd_rebuilder.unpack_bnd(bndcontent) for item in data: strName = item[1].decode('shift_jis') match = re.search(SN_RGX, strName) if not (match == None): if not strName in tempList: tempList.append(strName) fileName = match.group(0) if not (os.path.isfile(targetFolder + fileName)): with open(targetFolder + fileName, 'wb') as wf: wf.write(item[2])
if (os.path.isdir(inFile)): inFiles = [ f for f in os.listdir(inFile) if os.path.isfile(os.path.join(inFile, f)) ] if not os.path.isdir(outFile): os.makedirs(outFile) if (toDkscript): for inF in inFiles: if ".emevd" in inF: try: eh = EmevdHandler() with open(inFile + inF, 'rb') as f: if (useDCX): dcxh = DCXHandler() eh.read(dcxh.open_dcx(f.read())) else: eh.read(f.read()) outF = inF.replace('.emevd', '.dkscript') if (useDCX): outF = inF.replace('.emevd.dcx', '.dkscript') with open(outFile + outF, 'w') as f: f.write(eh.export_dkscript()) print("Converted '" + inF + "' to .dkscript") except: print("Failed to convert '" + inF + "' to .dkscript") raise ValueError("---")
def AddEverythingToCommon(self, useDCX): """ Collects all effects from individual map effect files and adds them to CommonEffects """ inputFiles = ['m10', 'm10_00', 'm10_01', 'm10_02', 'm11', 'm12', 'm12_00', 'm12_01', 'm13', 'm13_00', 'm13_01', 'm13_02', 'm14', 'm14_00', 'm14_01', 'm15', 'm15_00', 'm15_01', 'm16', 'm17', 'm18', 'm18_00', 'm18_01'] MODEL_PATTERN = r'.*s1([0-9][0-9][0-9])[0-9].*' TPF_PATTERN = r'.*s1([0-9][0-9][0-9])[0-9].*' ENEMY_EFFECT_ID_PATTERN = r'.*00([1-9][0-9][0-9][0-9][0-9]).ffx' ENEMY_MODEL_ID_PATTERN = r'.*s([1-9][0-9][0-9][0-9][0-9]).flver' ENEMY_TPF_ID_PATTERN = r'.*s([1-9][0-9][0-9][0-9][0-9]).tpf' tempList = [] self.ffx_files.clear() for iFile in inputFiles: openFileName = 'sfx\\FRPG_SfxBnd_' + iFile + '.ffxbnd' if (useDCX): openFileName += '.dcx' with open(openFileName, 'rb') as f: upcontent = f.read() content = upcontent if (useDCX): dcxh = DCXHandler() content = dcxh.open_dcx(upcontent) data = bnd_rebuilder.unpack_bnd(content) for item in data: strName = item[1].decode('shift_jis') if not strName in tempList: if (useDCX): enFXMatch = re.match(ENEMY_EFFECT_ID_PATTERN, strName) if (enFXMatch != None): fid = int(enFXMatch.group(1)) if (fid < 20001): # prev = 60001 below as well in 2 locations tempList.append(strName) self.ffx_files.append(item) else: enMDLMatch = re.match(ENEMY_MODEL_ID_PATTERN, strName) if (enMDLMatch != None): fid = int(enMDLMatch.group(1)) if (fid < 20001): tempList.append(strName) self.ffx_files.append(item) else: enTPFMatch = re.match(ENEMY_TPF_ID_PATTERN, strName) if (enTPFMatch != None): fid = int(enTPFMatch.group(1)) if (fid < 20001): tempList.append(strName) self.ffx_files.append(item) else: tempList.append(strName) self.ffx_files.append(item) existingEffects = [] lastIndex = 0 lastIndexTpf = 0 lastIndexMdl = 0 ffxEntries = [] tpfEntries = [] mdlEntries = [] openFileName = 'sfx\\FRPG_SfxBnd_CommonEffects.ffxbnd' if (useDCX): openFileName += '.dcx' oldCheckSum = sha256_checksum(openFileName) writeSuccessful = True with open(openFileName, 'rb') as f: upcontent = f.read() content = upcontent if (useDCX): dcxh = DCXHandler() content = dcxh.open_dcx(upcontent) data = bnd_rebuilder.unpack_bnd(content) for item in data: strName = item[1].decode('shift_jis') if not strName in existingEffects: existingEffects.append(strName) if (item[0] < 100000): ffxEntries.append(item) if (item[0] > lastIndex): lastIndex = item[0] elif (item[0] < 200000): tpfEntries.append(item) if (item[0] > lastIndexTpf): lastIndexTpf = item[0] else: mdlEntries.append(item) if (item[0] > lastIndexMdl): lastIndexMdl = item[0] if (not os.path.isfile(openFileName + '.bak')): with open(openFileName + '.bak', 'wb') as f2: f2.write(upcontent) oldLen = len(ffxEntries) + len(tpfEntries) + len(mdlEntries) lastIndex += 1 lastIndexTpf += 1 lastIndexMdl += 1 for i, ffx in enumerate(self.ffx_files): strName = ffx[1].decode('shift_jis') if not strName in existingEffects: if (ffx[0] < 100000): newEntry = (lastIndex, ffx[1], ffx[2]) lastIndex += 1 ffxEntries.append(newEntry) elif (ffx[0] < 200000): newEntry = (lastIndexTpf, ffx[1], ffx[2]) lastIndexTpf += 1 tpfEntries.append(newEntry) else: newEntry = (lastIndexMdl, ffx[1], ffx[2]) lastIndexMdl += 1 mdlEntries.append(newEntry) newContent = [] newContent += ffxEntries newContent += tpfEntries newContent += mdlEntries print("[FFX] Effect data gathered: " + str(len(newContent))) if not len(newContent) == oldLen: if (useDCX): print("[FFX] Saving and recompressing sfx\\FRPG_SfxBnd_CommonEffects.ffxbnd.dcx. This takes quite a while with the Remaster.") dcxh = DCXHandler() temp = dcxh.open_file('sfx\\FRPG_SfxBnd_CommonEffects.ffxbnd.dcx') dcxh.save_dcx('sfx\\FRPG_SfxBnd_CommonEffects.ffxbnd.dcx', bnd_rebuilder.repack_bnd(newContent)) else: print("[FFX] Saving sfx\\FRPG_SfxBnd_CommonEffects.ffxbnd.") with open('sfx\\FRPG_SfxBnd_CommonEffects.ffxbnd', 'wb') as f: f.write(bnd_rebuilder.repack_bnd(newContent)) newCheckSum = sha256_checksum(openFileName) if (oldCheckSum == newCheckSum): writeSuccessful = False print('[FFX] sfx\\FRPG_SfxBnd_CommonEffects.ffxbnd saved') if not useDCX: for iFile in inputFiles: data = [] with open('sfx\\FRPG_SfxBnd_' + iFile + '.ffxbnd', 'rb') as f: content = f.read() data = bnd_rebuilder.unpack_bnd(content) if not (os.path.isfile('sfx\\FRPG_SfxBnd_' + iFile + '.ffxbnd.bak')): with open('sfx\\FRPG_SfxBnd_' + iFile + '.ffxbnd.bak', 'wb') as bakf: bakf.write(content) with open('sfx\\FRPG_SfxBnd_' + iFile + '.ffxbnd', 'wb') as sf: sf.write(bnd_rebuilder.repack_bnd(data[:1])) print('[FFX] Clean-up complete') else: print('[FFX] Ignored cleanup (REMASTERED Version being used)') print("[FFX] Done") return writeSuccessful