Skip to content

Commit

Permalink
Disable PSTITLEIMG for single disc game PSP conversions
Browse files Browse the repository at this point in the history
Some single disc games only works on old versions on POPS for PSP
and those old versions on POPS do not support the PSTITLEIMG section.

So, when generating a EBOOT for PSP and if it is a single disc
then generate it witout a PSTITLEIMG and only a single PSISOIMG section
so that it is compatible with old POPS versions.

Mortal Kombat Trilogy is one such example which only works on
POPS v 3.02.

Signed-off-by: Ronnie Sahlberg <[email protected]>
  • Loading branch information
sahlberg committed Aug 7, 2024
1 parent a90495d commit 3477db0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
7 changes: 5 additions & 2 deletions pop-fe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ def bcd(i):
return toc


def generate_pbp(dest_file, disc_ids, game_title, icon0, pic0, pic1, cue_files, cu2_files, img_files, aea_files, magic_word, snd0=None, whole_disk=True, subchannels=[], configs=None, logo=None):
def generate_pbp(dest_file, disc_ids, game_title, icon0, pic0, pic1, cue_files, cu2_files, img_files, aea_files, magic_word, snd0=None, whole_disk=True, subchannels=[], configs=None, logo=None, no_pstitleimg=False):
print('Create PBP file for', game_title) if verbose else None

SECTLEN = 2352
Expand All @@ -2731,6 +2731,8 @@ def generate_pbp(dest_file, disc_ids, game_title, icon0, pic0, pic1, cue_files,
p.disc_ids = disc_ids
p.game_title = game_title
p.subchannels = subchannels
if no_pstitleimg:
p.no_pstitleimg = no_pstitleimg
if magic_word:
p.magic_word = magic_word
if configs:
Expand Down Expand Up @@ -2867,7 +2869,8 @@ def create_psp(dest, disc_ids, game_title, icon0, pic0, pic1, cue_files, cu2_fil
for i in range(len(magic_word)):
magic_word[i] = magic_word[i] & 0x72D0EE59

generate_pbp(dest_file, disc_ids, game_title, icon0, pic0, pic1, cue_files, cu2_files, img_files, aea_files, magic_word, snd0=snd0_data, whole_disk=whole_disk, subchannels=subchannels, configs=configs, logo=logo)
no_pstitleimg = True if len(disc_ids) == 1 else False
generate_pbp(dest_file, disc_ids, game_title, icon0, pic0, pic1, cue_files, cu2_files, img_files, aea_files, magic_word, snd0=snd0_data, whole_disk=whole_disk, subchannels=subchannels, configs=configs, logo=logo, no_pstitleimg=no_pstitleimg)

if manual:
print('Installing manual as', f + '/DOCUMENT.DAT')
Expand Down
69 changes: 46 additions & 23 deletions popstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,7 @@ def __init__(self):
self._striptracks = False
# complevel is >0 for PSP and ==0 for PS3
self._complevel = 1
self._no_pstitleimg = False
self._disc_ids = ['SLUS00000']
self._game_title = 'TITLE'
self._icon0 = None
Expand Down Expand Up @@ -2578,6 +2579,14 @@ def complevel(self):
def complevel(self, value):
self._complevel = value

@property
def no_pstitleimg(self):
return self._no_pstitleimg

@no_pstitleimg.setter
def no_pstitleimg(self, value):
self._no_pstitleimg = value

@property
def striptracks(self):
return self._striptracks
Expand Down Expand Up @@ -2719,7 +2728,7 @@ def bcd(i):
# Block #1
buf = bytearray(1024)
buf[:12] = b'PSISOIMG0000'
struct.pack_into('<I', buf, 12, isosize + 0x100000)
struct.pack_into('<I', buf, 12, isosize + 0x100000)
fh.write(buf)

# Block #2
Expand Down Expand Up @@ -2859,6 +2868,12 @@ def bcd(i):

end_offset = end_offset + 0x2d31

# update the length at offset 0x1220
fh.seek(p2_offset)
buf = bytearray(4)
struct.pack_into('<I', buf, 0, end_offset)
fh.write(buf)

if len(att):
fh.seek(att_offset)
fh.write(att)
Expand Down Expand Up @@ -3179,16 +3194,22 @@ def create_pbp(self):
fh.write(_datapspbody)

# Start of DATA.PSAR
_pstitle = bytearray(_pstitledata)
if not self._no_pstitleimg:
_pstitle = bytearray(_pstitledata)

# skip past _pstitle, we will write it later
fh.seek(_psar_offset + len(_pstitle))
# skip past _pstitle, we will write it later
fh.seek(_psar_offset + len(_pstitle))
else:
# If there is no PSTITLEIMG then the PSISOIMG will be aligned
# on the next 0x10000 boundary.
fh.seek( (fh.tell() + 0x10000) & 0xffff0000 )

disc_num = 0
psiso_offsets = []
for img_toc in self._img_toc:
fh.seek((fh.tell() + 0x7fff) & 0xffff8000)
struct.pack_into('<I', _pstitle, 0x200 + disc_num * 4, fh.tell() - _psar_offset)
if not self._no_pstitleimg:
struct.pack_into('<I', _pstitle, 0x200 + disc_num * 4, fh.tell() - _psar_offset)
psiso_offsets.append(fh.tell())
self.encode_psiso(fh, disc_num, img_toc)
fh.seek(0, 2)
Expand All @@ -3198,26 +3219,28 @@ def create_pbp(self):
# Add padding before STARTDAT
fh.seek((fh.tell() + 0x0f) & 0xfffffff0)

# update PSTITLEIMG
x = fh.tell()
_pstitle[:16] = b'PSTITLEIMG000000'
# update offset to STARTDAT
struct.pack_into('<I', _pstitle, 0x10, x - _psar_offset)
struct.pack_into('<I', _pstitle, 0x284, x - _psar_offset + 0x2d31)
# Update game id
gid = self._disc_ids[0]
_pstitle[0x264:0x264 + 11] = bytes('_' + gid[0:4] + '_' + gid[4:9], encoding='utf-8')
# Update game name
_t = bytes(self._game_title, encoding='utf-8')
_pstitle[0x30c:0x30c + len(_t)] = _t
print('Writing PSTITLEIMG.DAT') if self._verbose else None
fh.seek(_psar_offset)
fh.write(_pstitle)

if self._iso_bin_dat:
self.create_iso_bin_dat(fh, _pstitle, psiso_offsets)

if not self._no_pstitleimg:
# update PSTITLEIMG
_pstitle[:16] = b'PSTITLEIMG000000'
# update offset to STARTDAT
struct.pack_into('<I', _pstitle, 0x10, x - _psar_offset)
struct.pack_into('<I', _pstitle, 0x284, x - _psar_offset + 0x2d31)
# Update game id
gid = self._disc_ids[0]
_pstitle[0x264:0x264 + 11] = bytes('_' + gid[0:4] + '_' + gid[4:9], encoding='utf-8')
# Update game name
_t = bytes(self._game_title, encoding='utf-8')
_pstitle[0x30c:0x30c + len(_t)] = _t
print('Writing PSTITLEIMG.DAT') if self._verbose else None
fh.seek(_psar_offset)
fh.write(_pstitle)

if self._iso_bin_dat:
self.create_iso_bin_dat(fh, _pstitle, psiso_offsets)

fh.seek(x)

print('Writing STARTDAT header') if self._verbose else None
struct.pack_into('<I', _startdatheader, 20, len(self._logo))
fh.write(_startdatheader)
Expand Down

0 comments on commit 3477db0

Please sign in to comment.