December 31, 2025Dec 31 Localization Can you make a tool that can repack custom data into Conflict: Desert Storm (PC) *.dat? Ekey already made an unpacker: https://github.com/Ekey/CE.DAT.Tool catalog.zip
January 2Jan 2 Localization Spoiler import os import struct def str2hex(s:str)->bytes: b = b'' hexstring = '0123456789ABCDEF' s = s.zfill(8) for c in range(0,len(s)-1,2): n1 = hexstring.find(s[c])<<4 n2 = hexstring.find(s[c+1]) b += struct.pack('B', n1+n2) return b def extract(fname): """extracts Conflict: Desert Storm (PC) *.dat files into dir/*.*""" directory = fname.lower().replace('.dat', '/') table = [] if not os.path.isdir(directory): os.mkdir(directory) with open(fname, 'rb') as f: while True: stream = f.read(12) if stream == b'\x00'*12: break hashed, offset, size = struct.unpack('III', stream) hashed = hex(hashed).lstrip('0x').upper().zfill(8) table.append((hashed, offset, size)) for file in table: hashed, offset, size = file path = directory+hashed with open(path, 'wb') as f2: f.seek(offset) f2.write(f.read(size)) print(f'Extracted: {hashed}') def import_(directory): """import directory into Conflict: Desert Storm (PC) *.dat file""" fname = directory.rstrip('/').rstrip('\r')+'.dat' tablesize = 0x800 table = [] files = os.listdir(directory) offset = tablesize archive = b'' print('Checking filenames...') for file in files: for c in file: if not c in '0123456789ABCDEF': raise Exception(f"{file} aren't correct filename.") with open(directory+'/'+file, 'rb') as f: f = f.read() size = len(f) table.append((file, offset, size)) archive += f offset += size print('Writing dat file table...') with open(fname, 'wb') as f2: zeros = tablesize - (len(table) * 12) for file in table: fname, offset, size = file fname = str2hex(fname) offset = struct.pack('I', offset) size = struct.pack('I', size) f2.write(fname+offset+size) f2.write(b'\x00'*zeros) #padding print('Writing all files...') f2.write(archive) def main(): print('Conflict: Desert Storm (PC) Dat Tool') inp = input('Use [e] to extract from file, and to import compile file.\n: ') while True: match inp: case 'e': inp = input('Input filename: ') extract(inp) break case 'i': inp = input('Input directory: ') import_(inp) break case _: print('try again') if __name__ == '__main__': main() input('done!') python code
Create an account or sign in to comment