Skip to content

Commit

Permalink
add psx support for #11
Browse files Browse the repository at this point in the history
  • Loading branch information
evertonstz committed May 31, 2020
1 parent cadde42 commit 8cdb971
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions pynps/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import hashlib
import configparser
import ctypes
from pathlib import Path
from time import time
from datetime import datetime
from json import dumps
Expand Down Expand Up @@ -115,6 +116,7 @@ def progress_bar(number, symbol="#", fill_width=20, open_symbol="[", close_symbo
# sys.exit(1)



def download_save_state(dict, DBFOLDER, id, tag=False):
"""saves downloads sessions"""

Expand Down Expand Up @@ -501,6 +503,35 @@ def check_wget(location, CONFIGFOLDER):
else:
return False

def get_game_name(filename: str):
"""
retrieves game name from pbp file
:param filename: path to pbp file
:return: game name or False
"""
gamename = b''
with open(filename, 'rb') as eboot:
pbp_bytes = eboot.read()
# check the bytes for information that confirms the pbpfile is from a psx game
# PSISOIMG is for single disc games and PSTITLEI is for multi-disc games
if b'PSISOIMG' in pbp_bytes or b'PSTITLEI' in pbp_bytes:
eboot.seek(int('0x358', base=16))
while True:
current_byte = eboot.read(1)
if current_byte == b'\x00':
break
else:
try:
gamename += current_byte
except UnicodeDecodeError:
break
else:
return False
gamename = gamename.decode()
if len(gamename) > 31:
return gamename.replace(' ', '')[:21].replace('\x00', '')
else:
return gamename.replace('\x00', '')

def check_pkg2zip(location, CONFIGFOLDER):
"""this function is used to detect a pkg2zip
Expand All @@ -521,7 +552,6 @@ def check_pkg2zip(location, CONFIGFOLDER):
def run_pkg2zip(file, output_location, PKG2ZIP, args, extraction_folder, zrif=False): # OK!
"""this fuction is used to extract a pkg with pkg2zip"""
def runner( list, cwd):

p = subprocess.Popen(list, cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
Expand Down Expand Up @@ -578,7 +608,13 @@ def runner( list, cwd):
for x in args:
run_lst.insert(1, x)
process = runner(run_lst, cwd=output_location)


# create a txt file inside the folder with the game's name
if process == True:
g_name = get_game_name(extraction_folder+"/EBOOT.PBP")
if g_name != False:
Path(extraction_folder+"/"+g_name+".txt").touch()

return process


Expand Down

0 comments on commit 8cdb971

Please sign in to comment.