diff --git a/src/d/menu/d_menu_map_common.cpp b/src/d/menu/d_menu_map_common.cpp index cc9338ef746..b4a60f2b05e 100644 --- a/src/d/menu/d_menu_map_common.cpp +++ b/src/d/menu/d_menu_map_common.cpp @@ -179,7 +179,6 @@ SECTION_SDATA2 static f32 lit_3882 = 1.0f; // matches with literals #ifdef NONMATCHING void dMenuMapCommon_c::initiate(JKRArchive* arc) { - // Links the images on the map zoomed out to the ones zoomed in ResTIMG* mp_image; mp_image = (ResTIMG*)arc->getResource('TIMG', "tt_map_icon_boss_s_ci8_16_00.bti"); @@ -467,6 +466,7 @@ SECTION_SDATA2 static f32 lit_4013 = 180.0f; /* 801C38E4-801C3EC4 1BE224 05E0+00 0/0 2/2 0/0 .text drawIcon__16dMenuMapCommon_cFffff */ +//unfinished #ifdef NONMATCHING void dMenuMapCommon_c::drawIcon(f32 param_0, f32 param_1, f32 param_2, f32 param_3) { s16 tmp[128]; @@ -603,7 +603,7 @@ asm void dMenuMapCommon_c::moveLightDropAnime() { */ #ifdef NONMATCHING float dMenuMapCommon_c::getIconSizeX(u8 index) { - for (int i = 0; iI', "ROOT".encode('ascii'))[0] +ROOT = struct.unpack(">I", "ROOT".encode("ascii"))[0] + def chunks(lst, n): for i in range(0, len(lst), n): - yield lst[i:i + n] + yield lst[i : i + n] + @dataclass class StringTable: - """ RARC String Table """ + """RARC String Table""" strings: Dict[int, str] = field(default_factory=dict) @@ -37,7 +39,7 @@ class StringTable: @dataclass class Directory: - """ RARC Directory """ + """RARC Directory""" index: int name_hash: int @@ -53,17 +55,17 @@ class Directory: @dataclass class File(Directory): - """ RARC File """ + """RARC File""" @dataclass class Folder(Directory): - """ RARC Folder """ + """RARC Folder""" @dataclass class Node: - """ RARC Node """ + """RARC Node""" identifier: int name_offset: int @@ -76,8 +78,10 @@ class Node: rarc: "RARC" = field(default=None, repr=False) def files_and_folders(self, depth): - """ Generator for eacg file and directory of this node """ - for directory in self.rarc._directories[self.directory_index:][:self.directory_count]: + """Generator for eacg file and directory of this node""" + for directory in self.rarc._directories[self.directory_index :][ + : self.directory_count + ]: yield depth, directory if isinstance(directory, Folder): if directory.data_offset < len(self.rarc._nodes): @@ -89,7 +93,7 @@ class Node: @dataclass class RARC: - """ + """ RARC - Archive of files and folder """ @@ -121,29 +125,29 @@ class RARC: @property def files_and_folders(self): - """ Generator for each file and directory """ + """Generator for each file and directory""" yield from self._root.files_and_folders(0) def read_string_table(rarc, data): - buffer = data[rarc.string_table_offset:][:rarc.string_table_length] + buffer = data[rarc.string_table_offset :][: rarc.string_table_length] rarc.string_table = StringTable() offset = 0 - for string in str(buffer,'shift-jis').split('\0'): + for string in str(buffer, "shift-jis").split("\0"): rarc.string_table.strings[offset] = string - offset += len(bytearray(string,"shift-jis")) + 1 + offset += len(bytearray(string, "shift-jis")) + 1 def read_node(rarc, buffer): - node = Node(*struct.unpack('>IIHHI', buffer)) + node = Node(*struct.unpack(">IIHHI", buffer)) node.name = rarc.string_table.get(node.name_offset) node.rarc = rarc return node def read_nodes(rarc, data): - buffer = data[rarc.node_offset:][:rarc.node_count * NODE_SIZE] + buffer = data[rarc.node_offset :][: rarc.node_count * NODE_SIZE] rarc._nodes = [] for node_buffer in chunks(buffer, NODE_SIZE): node = read_node(rarc, node_buffer) @@ -153,35 +157,34 @@ def read_nodes(rarc, data): def read_directory(rarc, buffer, file_data): - header = struct.unpack('>HHHHIII', buffer) + header = struct.unpack(">HHHHIII", buffer) if header[0] == 0xFFFF: directory = Folder(*header) else: directory = File(*header) - directory.data = file_data[directory.data_offset:][:directory.data_length] + directory.data = file_data[directory.data_offset :][: directory.data_length] directory.name = rarc.string_table.get(directory.name_offset) directory.rarc = rarc return directory def read_directories(rarc, data, file_data): - buffer = data[rarc.directory_offset:][:rarc.directory_count * DIRECTORY_SIZE] + buffer = data[rarc.directory_offset :][: rarc.directory_count * DIRECTORY_SIZE] rarc._directories = [] for directory_buffer in chunks(buffer, DIRECTORY_SIZE): - rarc._directories.append(read_directory( - rarc, directory_buffer, file_data)) + rarc._directories.append(read_directory(rarc, directory_buffer, file_data)) def read(buffer) -> RARC: - """ Read and parse RARC from buffer. """ + """Read and parse RARC from buffer.""" # TODO: Add error checking - header = struct.unpack('>IIIIIIII', buffer[:32]) - info = struct.unpack('>IIIIIIHHI', buffer[32:][:32]) + header = struct.unpack(">IIIIIIII", buffer[:32]) + info = struct.unpack(">IIIIIIHHI", buffer[32:][:32]) rarc = RARC(*header, *info) data = buffer[32:] - file_data = data[rarc.file_offset:][:rarc.file_length] + file_data = data[rarc.file_offset :][: rarc.file_length] read_string_table(rarc, data) read_nodes(rarc, data) @@ -189,31 +192,43 @@ def read(buffer) -> RARC: return rarc -def extract_node(node,arcData,write_function,parentDir,dirNames) -> str: - os.mkdir(Path(parentDir)/node.name) - for i in range(node.directory_index,node.directory_count+node.directory_index): + +def extract_node(node, arcData, write_function, parentDir, dirNames) -> str: + os.mkdir(Path(parentDir) / node.name) + for i in range(node.directory_index, node.directory_count + node.directory_index): dir = arcData._directories[i] - dirNames[i] = str(Path(parentDir)/Path(node.name)) + "/" + dir.name - if type(dir) == Folder and dir.name != '.' and dir.name != '..': - for j,node2 in enumerate(arcData._nodes): + dirNames[i] = str(Path(parentDir) / Path(node.name)) + "/" + dir.name + if type(dir) == Folder and dir.name != "." and dir.name != "..": + for j, node2 in enumerate(arcData._nodes): if dir.data_offset == j: - dirNames = extract_node(node2,arcData,write_function,Path(parentDir)/node.name,dirNames) + dirNames = extract_node( + node2, + arcData, + write_function, + Path(parentDir) / node.name, + dirNames, + ) break elif type(dir) == File: - dirNames[i] = write_function(Path(parentDir)/Path(node.name)/dir.name,dir.data) - + dirNames[i] = write_function( + Path(parentDir) / Path(node.name) / dir.name, dir.data + ) + return dirNames -def extract_to_directory(directory,data,write_function): - print("Extracting "+str(directory)) + +def extract_to_directory(directory, data, write_function): + print("Extracting " + str(directory)) os.mkdir(directory) arcData = read(data) cwd = os.getcwd() os.chdir(directory) - dirNames = extract_node(arcData._root,arcData,write_function,"./",[None]*len(arcData._directories)) - + dirNames = extract_node( + arcData._root, arcData, write_function, "./", [None] * len(arcData._directories) + ) + files_data = "" - for i,dir in enumerate(arcData._directories): + for i, dir in enumerate(arcData._directories): directoryIndicator = "" specialType = "" indexToUse = str(dir.index).zfill(len(str(len(arcData._directories)))) @@ -221,39 +236,54 @@ def extract_to_directory(directory,data,write_function): directoryIndicator = "/" indexToUse = "Folder" if dir.type != 0x200 and dir.type != 0x1100 and dir.type != 0x9500: - specialType = ":"+hex(dir.type) - files_data = files_data + indexToUse + ":" + str(dirNames[i]) + directoryIndicator + specialType + '\n' - - + specialType = ":" + hex(dir.type) + files_data = ( + files_data + + indexToUse + + ":" + + str(dirNames[i]) + + directoryIndicator + + specialType + + "\n" + ) + fileDataLines = files_data.splitlines() - #fileDataLines.sort(key=lambda x : int(x.split(":")[0])) - filesFile = open("_files.txt","w") + # fileDataLines.sort(key=lambda x : int(x.split(":")[0])) + filesFile = open("_files.txt", "w") for line in fileDataLines: - filesFile.write(line+'\n') + filesFile.write(line + "\n") os.chdir(cwd) return directory + def computeHash(string): hash = 0 for char in string: - hash = hash*3 + hash = hash * 3 hash = hash + ord(char) hash = ctypes.c_ushort(hash) hash = hash.value return hash + def getNodeIdent(fullName): - if len(fullName)<4: + if len(fullName) < 4: fullName = fullName.upper() - for i in range(4-len(fullName)): + for i in range(4 - len(fullName)): fullName = fullName + " " else: fullName = fullName.upper()[:4] - return struct.unpack('>I', fullName.encode('ascii'))[0] + return struct.unpack(">I", fullName.encode("ascii"))[0] -def parseDirForPack(fileDataLines,path,convertFunction,nodes,dirs,currentNode,stringTable,data): - for i in range(currentNode.directory_index,currentNode.directory_count+currentNode.directory_index): + +def parseDirForPack( + fileDataLines, path, convertFunction, nodes, dirs, currentNode, stringTable, data +): + for i in range( + currentNode.directory_index, + currentNode.directory_count + currentNode.directory_index, + ): currentLine = fileDataLines[i].split(":") dirId = currentLine[0] if dirId == "Folder": @@ -262,96 +292,155 @@ def parseDirForPack(fileDataLines,path,convertFunction,nodes,dirs,currentNode,st dirId = int(dirId) currentLineName = currentLine[1] specialDirType = 0 - if len(currentLine)>2: - specialDirType = int(currentLine[2],16) - if currentLineName[-1] == '/': + if len(currentLine) > 2: + specialDirType = int(currentLine[2], 16) + if currentLineName[-1] == "/": currentLineName = currentLineName[0:-1] dirName = currentLineName.split("/")[-1] - if dirName == '.' or dirName == '..' or (os.path.isdir(path/currentLineName) and len(os.path.splitext(dirName)[1])==0): + if ( + dirName == "." + or dirName == ".." + or ( + os.path.isdir(path / currentLineName) + and len(os.path.splitext(dirName)[1]) == 0 + ) + ): stringTableOffset = 0 nodeIndex = nodes.index(currentNode) - if dirName == '..': + if dirName == "..": if currentNode.parent == None: nodeIndex = 0xFFFFFFFF else: nodeIndex = nodes.index(currentNode.parent) stringTableOffset = 2 - if dirName != '.' and dirName != '..': - stringTableOffset = len(bytearray(stringTable,"shift-jis")) + if dirName != "." and dirName != "..": + stringTableOffset = len(bytearray(stringTable, "shift-jis")) stringTable = stringTable + dirName + "\0" dirsInCurrentDir = [] - for j,line in enumerate(fileDataLines): + for j, line in enumerate(fileDataLines): split = line.split(":")[1].split("/") - if split[-1] == '': + if split[-1] == "": split.pop() if currentLineName == "/".join(split[0:-1]): dirsInCurrentDir.append(j) - newNode = Node(getNodeIdent(dirName),stringTableOffset,computeHash(dirName),len(dirsInCurrentDir),dirsInCurrentDir[0],dirName) + newNode = Node( + getNodeIdent(dirName), + stringTableOffset, + computeHash(dirName), + len(dirsInCurrentDir), + dirsInCurrentDir[0], + dirName, + ) newNode.parent = currentNode nodes.append(newNode) - nodeIndex = len(nodes)-1 - stringTable,nodes,dirs,data = parseDirForPack(fileDataLines,path,convertFunction,nodes,dirs,newNode,stringTable,data) - dirs[i] = Folder(dirId,computeHash(dirName),0x200,stringTableOffset,nodeIndex,16,0,dirName) + nodeIndex = len(nodes) - 1 + stringTable, nodes, dirs, data = parseDirForPack( + fileDataLines, + path, + convertFunction, + nodes, + dirs, + newNode, + stringTable, + data, + ) + dirs[i] = Folder( + dirId, + computeHash(dirName), + 0x200, + stringTableOffset, + nodeIndex, + 16, + 0, + dirName, + ) else: - realFileName, fileData = convertFunction(currentLineName,path,None,True) + realFileName, fileData = convertFunction(currentLineName, path, None, True) realFileName = os.path.basename(realFileName) - stringTableOffset = len(bytearray(stringTable,"shift-jis")) + stringTableOffset = len(bytearray(stringTable, "shift-jis")) stringTable = stringTable + realFileName + "\0" fileType = 0x1100 - if fileData[:4] == bytearray("Yaz0","utf-8"): + if fileData[:4] == bytearray("Yaz0", "utf-8"): fileType = 0x9500 if specialDirType != 0: fileType = specialDirType - dirs[i] = File(dirId,computeHash(realFileName),fileType,stringTableOffset,len(data),len(fileData),0,realFileName) + dirs[i] = File( + dirId, + computeHash(realFileName), + fileType, + stringTableOffset, + len(data), + len(fileData), + 0, + realFileName, + ) data = data + fileData - fileEndPadding = (0x20-(len(data)%0x20)) + fileEndPadding = 0x20 - (len(data) % 0x20) if fileEndPadding == 0x20: fileEndPadding = 0 data = data + bytearray(fileEndPadding) - return stringTable,nodes,dirs,data + return stringTable, nodes, dirs, data -def convert_dir_to_arc(sourceDir,convertFunction): - #print("Converting "+str(sourceDir)) - fileData = open(sourceDir/"_files.txt","r").read() + +def convert_dir_to_arc(sourceDir, convertFunction): + # print("Converting "+str(sourceDir)) + fileData = open(sourceDir / "_files.txt", "r").read() fileDataLinesFull = fileData.splitlines() - #fileDataLinesFull.sort(key=lambda x : int(x.split(":")[0])) + # fileDataLinesFull.sort(key=lambda x : int(x.split(":")[0])) fileDataLines = [] for line in fileDataLinesFull: - #fileDataLines.append(":".join(line.split(":")[1:])) #this should map directory ids to their index directly + # fileDataLines.append(":".join(line.split(":")[1:])) #this should map directory ids to their index directly fileDataLines.append(line) rootName = fileDataLines[0].split(":")[1].split("/")[0] nodes = [] dirs = [None] * len(fileDataLines) stringTable = ".\0..\0" - nodes.append(Node(getNodeIdent("ROOT"),len(stringTable),computeHash(rootName),len(os.listdir(sourceDir/rootName))+2,0,rootName)) - stringTable = stringTable+rootName+"\0" + nodes.append( + Node( + getNodeIdent("ROOT"), + len(stringTable), + computeHash(rootName), + len(os.listdir(sourceDir / rootName)) + 2, + 0, + rootName, + ) + ) + stringTable = stringTable + rootName + "\0" data = bytearray(0) - stringTable,nodes,dirs,data = parseDirForPack(fileDataLines,sourceDir,convertFunction,nodes,dirs,nodes[0],stringTable,data) - - dirOffset = 32+(len(nodes)*16) - dirOffsetPadding = (0x20-(dirOffset%0x20)) + stringTable, nodes, dirs, data = parseDirForPack( + fileDataLines, + sourceDir, + convertFunction, + nodes, + dirs, + nodes[0], + stringTable, + data, + ) + + dirOffset = 32 + (len(nodes) * 16) + dirOffsetPadding = 0x20 - (dirOffset % 0x20) if dirOffsetPadding == 0x20: dirOffsetPadding = 0 dirOffset = dirOffset + dirOffsetPadding - stringTableOffset = dirOffset+(len(dirs)*20) - stringTablePadding = (0x20-(stringTableOffset%0x20)) + stringTableOffset = dirOffset + (len(dirs) * 20) + stringTablePadding = 0x20 - (stringTableOffset % 0x20) stringTableOffset = stringTableOffset + stringTablePadding - stringTableLen = len(bytearray(stringTable,"shift-jis")) - fileOffset = stringTableOffset+stringTableLen - fileOffsetPadding = (0x20-(fileOffset%0x20)) + stringTableLen = len(bytearray(stringTable, "shift-jis")) + fileOffset = stringTableOffset + stringTableLen + fileOffsetPadding = 0x20 - (fileOffset % 0x20) if fileOffsetPadding == 0x20: fileOffsetPadding = 0 fileOffset = fileOffset + fileOffsetPadding - - fileLength = fileOffset+len(data) + fileLength = fileOffset + len(data) mMemLength = len(data) aMemLength = 0 - + fileCount = len(dirs) folderCount = 0 for dir in dirs: @@ -360,27 +449,89 @@ def convert_dir_to_arc(sourceDir,convertFunction): if aMemLength == 0 and dir.type == 0xA500: aMemLength = mMemLength mMemLength = 0 - #hacky way to detect rels.arc + # hacky way to detect rels.arc if folderCount == 2: - fileCount = fileCount - 2 #probably wrong + fileCount = fileCount - 2 # need to check on the logic for this - arcHeader = RARC(1380012611,fileLength,32,fileOffset,len(data),mMemLength,aMemLength,0,len(nodes),32,len(dirs),dirOffset,stringTableLen+stringTablePadding,stringTableOffset,fileCount,256,0) - headerData = struct.pack(">IIIIIIIIIIIIIIHHI",1380012611,fileLength,32,fileOffset,len(data),mMemLength,aMemLength,0,len(nodes),32,len(dirs),dirOffset,stringTableLen+fileOffsetPadding,stringTableOffset,fileCount,256,0) + arcHeader = RARC( + 1380012611, + fileLength, + 32, + fileOffset, + len(data), + mMemLength, + aMemLength, + 0, + len(nodes), + 32, + len(dirs), + dirOffset, + stringTableLen + stringTablePadding, + stringTableOffset, + fileCount, + 256, + 0, + ) + headerData = struct.pack( + ">IIIIIIIIIIIIIIHHI", + 1380012611, + fileLength, + 32, + fileOffset, + len(data), + mMemLength, + aMemLength, + 0, + len(nodes), + 32, + len(dirs), + dirOffset, + stringTableLen + fileOffsetPadding, + stringTableOffset, + fileCount, + 256, + 0, + ) nodeData = bytearray() for node in nodes: - nodeData = nodeData + struct.pack(">IIHHI",node.identifier,node.name_offset,node.name_hash,node.directory_count,node.directory_index) - + nodeData = nodeData + struct.pack( + ">IIHHI", + node.identifier, + node.name_offset, + node.name_hash, + node.directory_count, + node.directory_index, + ) + dirOffsetPaddingData = bytearray(dirOffsetPadding) dirData = bytearray() for dir in dirs: - dirData = dirData + struct.pack(">HHHHIII",dir.index,dir.name_hash,dir.type,dir.name_offset,dir.data_offset,dir.data_length,dir.unknown0) + dirData = dirData + struct.pack( + ">HHHHIII", + dir.index, + dir.name_hash, + dir.type, + dir.name_offset, + dir.data_offset, + dir.data_length, + dir.unknown0, + ) stringTablePaddingData = bytearray(stringTablePadding) - stringTableData = bytearray(stringTable,"shift-jis") + stringTableData = bytearray(stringTable, "shift-jis") fileOffsetPaddingData = bytearray(fileOffsetPadding) fullData = bytearray() - fullData = headerData + nodeData + dirOffsetPaddingData + dirData + stringTablePaddingData + stringTableData + fileOffsetPaddingData + data + fullData = ( + headerData + + nodeData + + dirOffsetPaddingData + + dirData + + stringTablePaddingData + + stringTableData + + fileOffsetPaddingData + + data + ) return fullData diff --git a/tools/package_game_assets.py b/tools/package_game_assets.py index 8a2d5fd9e93..be662831c2e 100644 --- a/tools/package_game_assets.py +++ b/tools/package_game_assets.py @@ -9,25 +9,33 @@ import ctypes import oead import libarc + def getMaxDateFromDir(path): maxTime = 0 - for root,dirs,files in os.walk(str(path)): + for root, dirs, files in os.walk(str(path)): for file in files: - time = os.path.getmtime(Path(root+"/"+file)) + time = os.path.getmtime(Path(root + "/" + file)) if time > maxTime: maxTime = time return maxTime + convertDefinitions = [ - {"sourceExtension" : ".arc", "destExtension" : ".arc", "convertFunction" : libarc.convert_dir_to_arc, "exceptions": ["game/files/res/Object/HomeBtn.c.arc/archive/dat/speakerse.arc"]} + { + "sourceExtension": ".arc", + "destExtension": ".arc", + "convertFunction": libarc.convert_dir_to_arc, + "exceptions": ["game/files/res/Object/HomeBtn.c.arc/archive/dat/speakerse.arc"], + } ] -def convertEntry(file,path,destPath,returnData): + +def convertEntry(file, path, destPath, returnData): split = os.path.splitext(file) mustBeCompressed = False destFileName = file if split[0].split(".")[-1] == "c": - destFileName = split[0][0:-2]+split[-1] + destFileName = split[0][0:-2] + split[-1] mustBeCompressed = True sourceExtension = split[-1] data = None @@ -38,57 +46,59 @@ def convertEntry(file,path,destPath,returnData): extractDef = extractData if extractData["exceptions"] != None: for exception in extractData["exceptions"]: - if str(path/file)==exception: + if str(path / file) == exception: extractDef = None break - + if extractDef != None: - destFileName = os.path.splitext(destFileName)[0]+extractDef["destExtension"] + destFileName = os.path.splitext(destFileName)[0] + extractDef["destExtension"] targetTime = 0 - if destPath != None and os.path.exists(destPath/destFileName): - targetTime = os.path.getmtime(destPath/destFileName) + if destPath != None and os.path.exists(destPath / destFileName): + targetTime = os.path.getmtime(destPath / destFileName) sourceTime = 0 if targetTime != 0: - if os.path.isdir(path/file): - sourceTime = getMaxDateFromDir(path/file) + if os.path.isdir(path / file): + sourceTime = getMaxDateFromDir(path / file) else: - sourceTime = os.path.getmtime(path/file) + sourceTime = os.path.getmtime(path / file) if returnData == False and sourceTime < targetTime: return destFileName - + if extractDef != None: - data = extractDef["convertFunction"](path/file,convertEntry) + data = extractDef["convertFunction"](path / file, convertEntry) if mustBeCompressed == True: if data == None: - data = open(path/file,"rb").read() + data = open(path / file, "rb").read() data = oead.yaz0.compress(data) if returnData == True: if data == None and returnData == True: - data = open(path/file,"rb").read() - return destFileName,data + data = open(path / file, "rb").read() + return destFileName, data else: - print(str(path/file)+" -> "+str(destPath/destFileName)) + print(str(path / file) + " -> " + str(destPath / destFileName)) if data != None: - open(destPath/destFileName,"wb").write(data) + open(destPath / destFileName, "wb").write(data) else: - shutil.copy(path/file,destPath/destFileName) + shutil.copy(path / file, destPath / destFileName) return destFileName + def copy(path, destPath): for file in os.listdir(path): split = os.path.splitext(file) - if len(split[1])==0 and os.path.isdir(path/file): - #is a standard directory - if not Path(destPath/file).exists(): - os.mkdir(destPath/file) - copy(path/file,destPath/file) + if len(split[1]) == 0 and os.path.isdir(path / file): + # is a standard directory + if not Path(destPath / file).exists(): + os.mkdir(destPath / file) + copy(path / file, destPath / file) else: - #either a file or directory that needs to be converted - convertEntry(file,path,destPath,False) + # either a file or directory that needs to be converted + convertEntry(file, path, destPath, False) -#copy(Path("srcArc"),Path("arcDest")) + +# copy(Path("srcArc"),Path("arcDest")) aMemRels = """d_a_alldie.rel d_a_andsw2.rel @@ -258,41 +268,46 @@ def copyRelFiles(gamePath, buildPath, aMemList, mMemList): relNew.close() else: relArcPaths.append(fullPath) - - if os.path.exists(buildPath/"RELS.arc") == False: - os.mkdir(buildPath/"RELS.arc") - os.mkdir(buildPath/"RELS.arc/rels") - os.mkdir(buildPath/"RELS.arc/rels/mmem") - os.mkdir(buildPath/"RELS.arc/rels/amem") - filesTxtData = "Folder:rels/amem/\nFolder:rels/mmem/\nFolder:rels/./\nFolder:rels/../\n" - for i,rel in enumerate(aMemRels.splitlines()): - filesTxtData = filesTxtData + str(i+4) + ":rels/amem/" + rel + ":0xa500\n" + if os.path.exists(buildPath / "RELS.arc") == False: + os.mkdir(buildPath / "RELS.arc") + os.mkdir(buildPath / "RELS.arc/rels") + os.mkdir(buildPath / "RELS.arc/rels/mmem") + os.mkdir(buildPath / "RELS.arc/rels/amem") + + filesTxtData = ( + "Folder:rels/amem/\nFolder:rels/mmem/\nFolder:rels/./\nFolder:rels/../\n" + ) + for i, rel in enumerate(aMemRels.splitlines()): + filesTxtData = filesTxtData + str(i + 4) + ":rels/amem/" + rel + ":0xa500\n" filesTxtData = filesTxtData + "Folder:rels/amem/./\nFolder:rels/amem/../\n" - for i,rel in enumerate(mMemRels.splitlines()): - filesTxtData = filesTxtData + str(i+83) + ":rels/mmem/" + rel + ":0xa500\n" + for i, rel in enumerate(mMemRels.splitlines()): + filesTxtData = filesTxtData + str(i + 83) + ":rels/mmem/" + rel + ":0xa500\n" filesTxtData = filesTxtData + "Folder:rels/mmem/./\nFolder:rels/mmem/../\n" - open(buildPath/"RELS.arc/_files.txt","w").write(filesTxtData) + open(buildPath / "RELS.arc/_files.txt", "w").write(filesTxtData) for rel in relArcPaths: for rel2 in aMemRels.splitlines(): if str(rel).find(rel2) != -1: - sourceRel = open(rel,"rb").read() - open(buildPath/"RELS.arc/rels/amem/"/rel2,"wb").write(oead.yaz0.compress(sourceRel)) + sourceRel = open(rel, "rb").read() + open(buildPath / "RELS.arc/rels/amem/" / rel2, "wb").write( + oead.yaz0.compress(sourceRel) + ) break for rel2 in mMemRels.splitlines(): if str(rel).find(rel2) != -1: - sourceRel = open(rel,"rb").read() - open(buildPath/"RELS.arc/rels/mmem/"/rel2,"wb").write(oead.yaz0.compress(sourceRel)) + sourceRel = open(rel, "rb").read() + open(buildPath / "RELS.arc/rels/mmem/" / rel2, "wb").write( + oead.yaz0.compress(sourceRel) + ) break print("Creating RELS.arc") - open(buildPath/"dolzel2/game/files/RELS.arc","wb").write(libarc.convert_dir_to_arc(buildPath/"RELS.arc",convertEntry)) - + open(buildPath / "dolzel2/game/files/RELS.arc", "wb").write( + libarc.convert_dir_to_arc(buildPath / "RELS.arc", convertEntry) + ) - - -def main(gamePath, buildPath,copyCode): +def main(gamePath, buildPath, copyCode): if not gamePath.exists(): gamePath.mkdir(parents=True, exist_ok=True) @@ -309,11 +324,11 @@ def main(gamePath, buildPath,copyCode): os.chdir(previousDir) print("Copying game files...") - if os.path.exists(buildPath/"dolzel2") == False: - os.mkdir(buildPath/"dolzel2") - if os.path.exists(buildPath/"dolzel2"/"game") == False: - os.mkdir(buildPath/"dolzel2/game") - copy(gamePath, Path(buildPath/"dolzel2/game").absolute()) + if os.path.exists(buildPath / "dolzel2") == False: + os.mkdir(buildPath / "dolzel2") + if os.path.exists(buildPath / "dolzel2" / "game") == False: + os.mkdir(buildPath / "dolzel2/game") + copy(gamePath, Path(buildPath / "dolzel2/game").absolute()) if copyCode != "noCopyCode": print( @@ -321,9 +336,12 @@ def main(gamePath, buildPath,copyCode): + " -> " + str(buildPath / "dolzel2/game/sys/main.dol") ) - shutil.copyfile(buildPath / "dolzel2/main_shift.dol", buildPath / "dolzel2/game/sys/main.dol") + shutil.copyfile( + buildPath / "dolzel2/main_shift.dol", + buildPath / "dolzel2/game/sys/main.dol", + ) - copyRelFiles(gamePath,buildPath, aMemRels.splitlines(), mMemRels.splitlines()) + copyRelFiles(gamePath, buildPath, aMemRels.splitlines(), mMemRels.splitlines()) if __name__ == "__main__":