Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return
print('Packing loose files...')
pack_folders = sorted(
{d for d in tmp_dir.rglob('**/*') if d.is_dir() and d.suffix in util.SARC_EXTS},
key=lambda d: len(d.parts), reverse=True
)
for folder in pack_folders:
new_tmp: Path = folder.with_suffix(folder.suffix + '.tmp')
shutil.move(folder, new_tmp)
new_sarc = sarc.SARCWriter(be=True)
for file in {f for f in new_tmp.rglob('**/*') if f.is_file()}:
new_sarc.add_file(file.relative_to(new_tmp).as_posix(), file.read_bytes())
sarc_bytes = new_sarc.get_bytes()
if str(folder.suffix).startswith('.s') and folder.suffix != '.sarc':
sarc_bytes = util.compress(sarc_bytes)
folder.write_bytes(sarc_bytes)
shutil.rmtree(new_tmp)
if not options:
options = {}
options['texts'] = {'user_only': False}
pool = Pool(cpu_count())
logged_files = generate_logs(tmp_dir, options=options, original_pool=pool)
print('Removing unnecessary files...')
if (tmp_dir / 'logs' / 'map.yml').exists():
print('Removing map units...')
for file in [file for file in logged_files if isinstance(file, Path) and \
fnmatch(file.name, '[A-Z]-[0-9]_*.smubin')]:
file.unlink()
if [file for file in (tmp_dir / 'logs').glob('*texts*')]:
try:
if file_bytes[0:4] == b"AAMP":
aamp_contents = ParameterIO.from_binary(file_bytes)
try:
file_ext = os.path.splitext(file)[1]
aamp_contents = shop_merge(
aamp_contents,
file_ext.replace(".", ""),
stuff.lists["Additions"],
stuff.lists["Removals"],
)
aamp_bytes = ParameterIO.to_binary(aamp_contents)
except: # pylint: disable=bare-except
raise RuntimeError(f"AAMP file {file} could be merged.")
del aamp_contents
new_bytes = aamp_bytes if not yazd else util.compress(aamp_bytes)
cache_merged_shop(file, new_bytes)
else:
raise ValueError("Wait, what the heck, this isn't an AAMP file?!")
except ValueError:
new_bytes = pack.get_file(file).data
print(f"Deep merging {file} failed. No changes were made.")
new_sarc.files[file] = oead.Bytes(new_bytes)
return new_sarc, failures
:param bootup_path: Path to the Bootup.pack to update, defaults to a master BCML copy
:type bootup_path: class:`pathlib.Path`, optional
:returns: Returns the RSTB size of the new gamedata.sarc
:rtype: int
"""
if not bootup_path:
master_boot = util.get_master_modpack_dir() / 'content' / 'Pack' / 'Bootup.pack'
bootup_path = master_boot if master_boot.exists() \
else util.get_game_file('Pack/Bootup.pack')
with bootup_path.open('rb') as b_file:
bootup_pack = sarc.read_file_and_make_sarc(b_file)
new_pack = sarc.make_writer_from_sarc(bootup_pack)
new_pack.delete_file('GameData/gamedata.ssarc')
gamedata_bytes = bgdata.get_bytes()
new_pack.add_file('GameData/gamedata.ssarc',
util.compress(gamedata_bytes))
(util.get_master_modpack_dir() / 'content' /
'Pack').mkdir(parents=True, exist_ok=True)
with (util.get_master_modpack_dir() / 'content' / 'Pack' / 'Bootup.pack').open('wb') as b_file:
new_pack.write(b_file)
return rstb.SizeCalculator().calculate_file_size_with_ext(gamedata_bytes, True, '.sarc')
def get_bootup_injection(self):
tmp_sarc = util.get_master_modpack_dir() / 'logs' / 'gamedata.sarc'
if tmp_sarc.exists():
return (
'GameData/gamedata.ssarc',
util.compress(tmp_sarc.read_bytes())
)
else:
return
new_sub_sarc, sub_failures = nested_patch(sub_sarc, stuff)
for failure in sub_failures:
failure[file + '//' + failure] = sub_failures[failure]
del sub_sarc
new_bytes = new_sub_sarc.get_bytes()
new_sarc.add_file(file, new_bytes if not yazd else util.compress(new_bytes))
elif isinstance(stuff, list):
try:
if file_bytes[0:4] == b'AAMP':
aamp_contents = aamp.Reader(file_bytes).parse()
for change in stuff:
aamp_contents = _aamp_merge(aamp_contents, change)
aamp_bytes = aamp.Writer(aamp_contents).get_bytes()
del aamp_contents
new_bytes = aamp_bytes if not yazd else util.compress(aamp_bytes)
cache_merged_aamp(file, new_bytes)
else:
raise ValueError('Wait, what the heck, this isn\'t an AAMP file?!')
except ValueError:
new_bytes = pack.get_file_data(file).tobytes()
print(f'Deep merging {file} failed. No changed were made.')
new_sarc.delete_file(file)
new_sarc.add_file(file, new_bytes)
return new_sarc, failures
:type entry: str
:param size: The resource size
:type size: int
"""
rstb_path = util.get_master_modpack_dir() / 'content' / 'System' / 'Resource' /\
'ResourceSizeTable.product.srsizetable'
if rstb_path.exists():
table = read_rstb(rstb_path, be=True)
else:
table = get_stock_rstb()
rstb_path.parent.mkdir(parents=True, exist_ok=True)
table.set_size(entry, size)
buf = io.BytesIO()
table.write(buf, be=True)
rstb_path.write_bytes(
util.compress(buf.getvalue())
)
:returns: A tuple with the path to the new Bootup_XXxx.pack and the RSTB size of the new
Msg_XXxx.product.sarc
:rtype: (class:`pathlib.Path`, int)
"""
new_boot_path = msbt_dir.parent / f'Bootup_{lang}.pack'
with new_boot_path.open('wb') as new_boot:
s_msg = sarc.SARCWriter(True)
for new_msbt in msbt_dir.rglob('**/*.msbt'):
with new_msbt.open('rb') as f_new:
s_msg.add_file(str(new_msbt.relative_to(msbt_dir)
).replace('\\', '/'), f_new.read())
new_msg_stream = io.BytesIO()
s_msg.write(new_msg_stream)
unyaz_bytes = new_msg_stream.getvalue()
rsize = rstb.SizeCalculator().calculate_file_size_with_ext(unyaz_bytes, True, '.sarc')
new_msg_bytes = util.compress(unyaz_bytes)
s_boot = sarc.SARCWriter(True)
s_boot.add_file(f'Message/Msg_{lang}.product.ssarc', new_msg_bytes)
s_boot.write(new_boot)
return new_boot_path, rsize
for file in [file for file in opened_sarc.list_files() if file not in files_added]:
data = opened_sarc.get_file_data(file).tobytes()
real_data = util.unyaz_if_needed(data)
if util.is_file_modded(file.replace('.s', '.'), real_data, count_new=True):
if not Path(file).suffix in util.SARC_EXTS:
del real_data
new_sarc.add_file(file, data)
files_added.append(file)
else:
if file not in nested_sarcs:
nested_sarcs[file] = []
nested_sarcs[file].append(real_data)
for file, sarcs in nested_sarcs.items():
merged_bytes = merge_sarcs(file, sarcs)[1]
if Path(file).suffix.startswith('.s') and not file.endswith('.sarc'):
merged_bytes = util.compress(merged_bytes)
new_sarc.add_file(file, merged_bytes)
files_added.append(file)
for file in [file for file in all_files if file not in files_added]:
for opened_sarc in [open_sarc for open_sarc in opened_sarcs \
if file in open_sarc.list_files()]:
new_sarc.add_file(file, opened_sarc.get_file_data(file).tobytes())
break
if 'Bootup.pack' in file_name:
for merger in [merger() for merger in mergers.get_mergers() if merger.is_bootup_injector()]:
inject = merger.get_bootup_injection()
if not inject:
continue
file, data = inject
try:
new_sarc.delete_file(file)
def get_bootup_injection(self):
tmp_sarc = util.get_master_modpack_dir() / "logs" / "effects.byml"
if tmp_sarc.exists():
return (
"Ecosystem/StatusEffectList.sbyml",
util.compress(tmp_sarc.read_bytes()),
)
return
).parse()
base_dungeons = [dungeon['Map'] for dungeon in new_static['StartPos']]
for dungeon, diff in diffs.items():
if dungeon not in base_dungeons:
new_static['StartPos'].append(diff)
else:
for key, value in diff.items():
new_static['StartPos'][base_dungeons.index(
dungeon)][key] = value
output_static = util.get_master_modpack_dir() / 'aoc' / '0010' / 'Map' / \
'CDungeon' / 'Static.smubin'
output_static.parent.mkdir(parents=True, exist_ok=True)
output_static.write_bytes(
util.compress(byml.Writer(new_static, True).get_bytes())
)