Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $ps3_ip="192.168.11.206";
- $ps3_ftp_user="ps3";
- $ps3_ftp_pass="";
- // Override PSN Packages into software category
- $override['software'] = array(
- 'NPEA90124',
- 'NPIA00025',
- 'NPUP00030',
- 'NPUP10028'
- );
- // Override PSN Packages (Disc Games) into PS3 Games category
- $override['ps3'] = array(
- 'NPUA80472',
- 'NPUA80480',
- 'NPUA80638',
- 'NPUA80657',
- 'NPUA80662',
- 'NPUB30575',
- 'NPUB30606',
- 'NPUB30638',
- 'NPUB30700',
- 'NPUB30704',
- 'NPUB30715',
- 'NPUB30886',
- 'NPUB30923',
- 'NPUB30932',
- 'NPUB30985',
- 'NPUB31052',
- 'NPUB31083',
- 'NPUB31133',
- 'NPUB31136',
- 'NPUB31154',
- 'NPUB31241',
- 'NPUB31247',
- 'NPUB31257',
- 'NPUB31306'
- );
- echo "\n";
- echo "Please note that mygames.txt output will be cleaner than\n";
- echo "what is shown on this console.\n\n";
- echo "Connecting to PS3... Please wait...\n";
- $ps3ftp = ftp_connect($ps3_ip);
- $login_result = ftp_login($ps3ftp, $ps3_ftp_user, $ps3_ftp_pass);
- echo "Connected, scanning games...\n";
- $content['ps1'] = scanISO($ps3ftp,'ps1');
- $content['ps2'] = scanISO($ps3ftp,'ps2');
- $content['ps3'] = scanISO($ps3ftp,'ps3');
- $content['dvd'] = scanISO($ps3ftp,'dvd');
- $content = scanFolder($ps3ftp,$content,'game');
- // scanFolder might work with /dev_hdd0/GAMES and GAMEZ but is not tested
- echo "Done, disconnecting from PS3...\n";
- ftp_close($ps3ftp);
- echo "Generating mygames.txt... ";
- $out = "";
- if (@$content['ps1']) { $out .= processData($content['ps1'],"PLAYSTATION(R) 1 Games"); }
- if (@$content['ps2']) { $out .= processData($content['ps2'],"PLAYSTATION(R) 2 Games"); }
- if (@$content['ps3']) { $out .= processData($content['ps3'],"PLAYSTATION(R) 3 Games"); }
- if (@$content['psp']) { $out .= processData($content['psp'],"PLAYSTATION(R) Portable Games"); }
- if (@$content['psn']) { $out .= processData($content['psn'],"PLAYSTATION(R) Network Games"); }
- if (@$content['software']) { $out .= processData($content['software'],"PLAYSTATION(R) 3 Software"); }
- if (@$content['dvd']) { $out .= processData($content['dvd'],"DVD Video ISOs"); }
- // Generate mygames.txt
- $out = preg_replace("/\n/","\r\n",$out);
- $fp = fopen("mygames.txt","w+");
- fwrite($fp,$out);
- fclose($fp);
- echo "Done.\n";
- /* -------------- Functions -------------- */
- function removeUnwantedWording($iso) {
- $iso = preg_replace("/ \(Trial Version\)/","",$iso);
- $iso = preg_replace("/ Trial Version/","",$iso);
- $iso = preg_replace("/: \Trial/","",$iso);
- $iso = preg_replace("/ Trial$/","",$iso);
- $iso = preg_replace("/ Demo$/","",$iso);
- $iso = preg_replace("/ \(Disc [0-9]\)/","",$iso);
- $iso = preg_replace("/^GT Academy 2013$/","SEN Enabler",$iso);
- $iso = preg_replace("/ Unknown CFW\!$/","",$iso);
- return $iso;
- }
- function checkOverride($s,$k) {
- global $override;
- if (@$override[$k]) {
- return in_array($s,$override[$k]);
- }
- return false;
- }
- function isBlacklisted($id) {
- global $blacklist;
- if (@$blacklist) {
- return in_array($id,$blacklist);
- }
- return false;
- }
- function readParamSFO($data,$force_max = false) {
- $keytable_offset = unpack('I',substr($data,8,4))[1];
- $data_offset = unpack('I',substr($data,12,4))[1];
- $table_entries = unpack('I',substr($data,16,4))[1];
- $keytable = array_filter(explode("\0",substr($data,$keytable_offset,($data_offset - $keytable_offset))));
- $idxtable = substr($data,20,($keytable_offset-20));
- $data = substr($data,$data_offset,-1);
- $pos = 0;
- $i = 1;
- while ($pos < strlen($idxtable)) {
- $key[$i]['start'] = unpack('I',substr($idxtable,$pos,2)."\0\0")[1];
- $pos = $pos + 2;
- $key[$i]['fmt'] = unpack('I',substr($idxtable,$pos,2)."\0\0")[1];
- $pos = $pos + 2;
- $key[$i]['len'] = unpack('I',substr($idxtable,$pos,4))[1];
- $pos = $pos + 4;
- $key[$i]['max_len'] = unpack('I',substr($idxtable,$pos,4))[1];
- $pos = $pos + 4;
- $key[$i]['offset'] = unpack('I',substr($idxtable,$pos,4))[1];
- $pos = $pos + 4;
- $i++;
- }
- $i = 0;
- foreach ($key as $k) {
- if ($force_max) {
- $pm = substr($data,$k['offset'],$k['max_len']);
- } else {
- $pm = substr($data,$k['offset'],$k['len']);
- }
- $param[$keytable[$i]] = trim($pm);
- $i++;
- }
- return $param;
- }
- function getNameFromISO($iso) {
- $p1 = strpos($iso,'[') + 1;
- $p2 = strpos($iso,']',$p1);
- return substr($iso,$p1,($p2 - strlen($iso)));
- }
- function scanISO($ftp,$dir) {
- // Assumes filename is XXXX#####-[Game Name].iso (or .bin)
- // Falls back to entire filename as title.
- switch (strtolower($dir)) {
- case "psx":
- // no break to allow it to hit ps1 processing
- $dir = "ps1";
- case "ps1":
- $rdir = "PSXISO";
- break;
- case "ps2":
- $rdir = "PS2ISO";
- break;
- case "ps3":
- $rdir = "PS3ISO";
- break;
- case "dvd":
- $rdir = "DVDISO";
- break;
- case "bd":
- $rdir = "BDISO";
- break;
- default:
- return false;
- break;
- }
- $res = [];
- $ftptmp = ftp_mlsd($ftp,"/dev_hdd0/".$rdir);
- foreach ($ftptmp as $d) {
- if (strtolower(substr($d['name'],(strlen($d['name']) - 3),3)) == "bin" || strtolower(substr($d['name'],(strlen($d['name']) - 3),3)) == "iso") {
- if (preg_match("/^[MSNUB][A-Z]{3}[0-9]{5}/",$d['name'])) {
- $v = getNameFromISO($d['name']);
- } else {
- $v = substr($d['name'],0,(strlen($d['name']) - 4));
- }
- echo strtoupper($dir).": ".$v."\n";
- $res[] = removeUnwantedWording($v)." (ISO)";
- }
- }
- sort($res);
- $res = array_unique($res);
- return $res;
- }
- function scanFolder($ftp,$content,$dir,$filter = true) {
- $ftptmp = ftp_mlsd($ftp,"/dev_hdd0/".$dir);
- $res = [];
- foreach ($ftptmp as $d) {
- // is XXXX#####, starts with N or U, is a directory, isn't blacklisted (by id)
- if ((preg_match("/^[NU][A-Z]{3}[0-9]{5}$/",$d['name']) && $d['type'] == 'dir' && !isBlacklisted($d['name'])) || !$filter) {
- ob_start();
- $result = ftp_get($ftp, "php://output", "/dev_hdd0/".$dir."/".$d['name']."/PARAM.SFO", FTP_BINARY);
- $ps3sfo = ob_get_contents();
- ob_end_clean();
- if (strlen(@$ps3sfo) > 0) {
- $pdecode = readParamSFO($ps3sfo);
- if (@$pdecode['BOOTABLE']) {
- $v = preg_replace("/\n/"," ",$pdecode['TITLE']);
- switch (substr($pdecode['TITLE_ID'],0,2)) {
- case "UL":
- case "UC":
- $pdecode = readParamSFO($ps3sfo,1);
- $v = preg_replace("/\n/"," ",$pdecode['TITLE']);
- echo "PSP (Pkg): ".$v."\n";
- $content['psp'][] = $v." (Installed)";
- break;
- case "SC":
- case "SL":
- // PS1 & PS2 both use the same TITLE_ID scheme, but PS2 games start at 20000
- // so assume any ID less than 20000 is a PS1 game.
- $ser = substr($pdecode['TITLE_ID'],4,5);
- if (intval($ser) >= 20000) {
- echo "PS2: ".removeUnwantedWording($v)."\n";
- $content['ps2'][] = removeUnwantedWording($v)." (PSN Install)";
- } else {
- echo "PS1: ".removeUnwantedWording($v)."\n";
- $content['ps1'][] = removeUnwantedWording($v)." (PSN Install)";
- }
- break;
- default:
- // Fell back to generic PSN Package, so check overrides
- if (checkOverride($pdecode['TITLE_ID'],'ps1')) {
- echo "PS1: ".removeUnwantedWording($v)."\n";
- $content['ps1'][] = removeUnwantedWording($v)." (PSN Install)";
- }
- elseif (checkOverride($pdecode['TITLE_ID'],'ps2')) {
- echo "PS2: ".removeUnwantedWording($v)."\n";
- $content['ps2'][] = removeUnwantedWording($v)." (PSN Install)";
- }
- elseif (checkOverride($pdecode['TITLE_ID'],'ps3')) {
- echo "PS3: ".removeUnwantedWording($v)."\n";
- $content['ps3'][] = removeUnwantedWording($v)." (PSN Install)";
- }
- elseif (checkOverride($pdecode['TITLE_ID'],'software')) {
- echo "Software: ".removeUnwantedWording($v)."\n";
- $content['software'][] = removeUnwantedWording($v);
- }
- else {
- echo "PSN: ".removeUnwantedWording($v)." (".$pdecode['TITLE_ID'].")\n";
- $content['psn'][] = removeUnwantedWording($v);
- }
- break;
- }
- }
- }
- } elseif ($dir == 'game' && preg_match("/^[A-Z0-9]{9}$/",$d['name']) && (!preg_match("/^B[A-Z0-9]{8}$/",$d['name']) || $d['name'] == "BLES80608")) {
- ob_start();
- $result = ftp_get($ftp, "php://output", "/dev_hdd0/".$dir."/".$d['name']."/PARAM.SFO", FTP_BINARY);
- $ps3sfo = ob_get_contents();
- ob_end_clean();
- $pdecode = readParamSFO($ps3sfo,1);
- $v = preg_replace("/\n/"," ",$pdecode['TITLE']);
- echo "Software: ".removeUnwantedWording($v)." (".$pdecode['TITLE_ID'].")\n";
- $content['software'][] = removeUnwantedWording($v);
- }
- }
- return $content;
- }
- function processData($d,$s) {
- natcasesort($d);
- $out = " *----* ".$s." *----* \n";
- foreach ($d as $f) {
- $out .= " - ".$f."\n";
- }
- return $out."\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement