I am putting this here for posterity's sake, but if you know how to use Python 3 this may be a better cross platform solution. I haven't done extensive testing with this, and it could possibly use some cleanup, but it was serviceable to get me what I wanted. This should work for both KOTOR 1 and 2:
import os
def load_files(directory):
try:
os.makedirs(directory + '/edited_files')
except FileExistsError:
pass
file_names = os.listdir(directory)
for file_name in file_names:
relative_path = directory + '/' + file_name
if os.path.isfile(relative_path):
with open(relative_path, mode='rb') as file:
file_bytes = None
file_check = file.read(4)
if file_check == b'RIFF':
file.seek(0x3A)
file_bytes = file.read()
else:
file.seek(0x1D6)
file_check = file.read(4)
if file_check == b'RIFF':
file.seek(0x1D6)
file_bytes = file.read()
with open(directory + '/edited_files/' + file_name, mode='wb') as edited_file:
try:
edited_file.write(file_bytes)
except TypeError:
print('Failed to write ' + file_name)
if __name__ == '__main__':
kotor1_directory = 'kotor1/streammusic'
kotor2_directory = 'kotor2/streammusic'
load_files(kotor1_directory)
load_files(kotor2_directory)
Post edited August 17, 2024 by positron01