View difference between Paste ID: vULSsak9 and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | #!/usr/bin/python |
2 | ||
3 | import os, sys, subprocess, shutil | |
4 | ||
5 | # working directory for messing with big files | |
6 | curr_dir=os.path.realpath(os.path.dirname(__file__)) | |
7 | ||
8 | # path of unself, make_self_npdrm, make_package_npdrm, and psn_package_npdrm.exe | |
9 | tools_dir=os.path.join(curr_dir, 'bin') | |
10 | ||
11 | def do(cmd): | |
12 | """ shorthand for running comands """ | |
13 | #print cmd | |
14 | p=subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
15 | return p.communicate() | |
16 | ||
17 | ||
18 | try: | |
19 | sfo=os.path.realpath(sys.argv[1]) | |
20 | gamedir = os.path.realpath(os.path.dirname(sys.argv[1])) | |
21 | except IndexError: | |
22 | print "You need to specify the location of the PARAM.SFO file." | |
23 | sys.exit(1) | |
24 | ||
25 | ||
26 | # get gameid | |
27 | gameid='BRKN00000' | |
28 | with open(sfo, 'read') as f: | |
29 | gameid=f.read()[-24:-15] | |
30 | ||
31 | print "Files need to be copied from PS3_GAME to PS3 into /dev_hdd0/G%s (don't copy USRDIR/EBOOT.bin.)" % gameid[2:] | |
32 | ||
33 | # make a copy of important files for package | |
34 | os.mkdir(os.path.join(curr_dir, gameid+'-pkg')) | |
35 | os.mkdir(os.path.join(curr_dir, gameid+'-pkg', 'USRDIR')) | |
36 | ||
37 | shutil.copyfile(os.path.join(gamedir, 'ICON0.PNG'), os.path.join(curr_dir, gameid+'-pkg','ICON0.PNG')) | |
38 | # shutil.copyfile(os.path.join(gamedir, 'USRDIR','EBOOT.BIN'), os.path.join(curr_dir, gameid + '-EBOOT.BIN.orig')) | |
39 | ||
40 | try: | |
41 | shutil.copyfile(os.path.join(gamedir, 'PIC1.PNG'), os.path.join(curr_dir, gameid+'-pkg','PIC1.PNG')) | |
42 | except: | |
43 | pass | |
44 | ||
45 | # unself EBOOT | |
46 | do("%s %s %s" % (os.path.join(tools_dir,'unself'), os.path.join(gamedir, 'USRDIR', 'EBOOT.BIN'), 'eboot_out.elf')) | |
47 | ||
48 | # find & replace | |
49 | b='' | |
50 | with open('eboot_out.elf', 'read') as f: | |
51 | b=f.read() | |
52 | with open('eboot_out.elf', 'write') as f: | |
53 | b = b.replace('dev_bdvd', 'dev_hdd0').replace('PS3_GAME','G' + gameid[2:]) | |
54 | f.write(b) | |
55 | ||
56 | with open(sfo, 'read') as f: | |
57 | b=f.read() | |
58 | with open(os.path.join(curr_dir, gameid+'-pkg','PARAM.SFO'), 'write') as f: | |
59 | b = b.replace('DG%c%cLibrary programs' %(0,0), 'HG%c%cLibrary programs' %(0,0)) | |
60 | f.write(b) | |
61 | ||
62 | ||
63 | # re-self EBOOT | |
64 | do('%s eboot_out.elf %s UP0001-%s_00-0000111122223333' % (os.path.join(tools_dir,'make_self_npdrm'), os.path.join(curr_dir, gameid+'-pkg', 'USRDIR', 'EBOOT.BIN'), gameid)) | |
65 | ||
66 | # make conf file for pkg | |
67 | with open(os.path.join(curr_dir,gameid +'.conf'), 'write') as f: | |
68 | f.write("""Content-ID = UP0001-%s_00-0000111122223333 | |
69 | k_licensee = 0x00000000000000000000000000000000 | |
70 | DRM_Type = Free | |
71 | Content_Type = Game_Exec | |
72 | PackageVersion = 01.00""" %(gameid)) | |
73 | ||
74 | #TODO: this doesn't work! I use wine and psn_package_npdrm to do it.) | |
75 | ||
76 | #make pkg | |
77 | #do('%s %s %s' % (os.path.join(tools_dir,'make_package_npdrm'), os.path.join(curr_dir, gameid + '.conf'), os.path.join(curr_dir, gameid+'-pkg'))) | |
78 | ||
79 | do('wine %s %s %s' % (os.path.join(tools_dir,'psn_package_npdrm.exe'), os.path.join(curr_dir, gameid + '.conf'), os.path.join(curr_dir, gameid+'-pkg'))) | |
80 | ||
81 | ||
82 | # cleanup | |
83 | os.unlink('eboot_out.elf') | |
84 | os.unlink(os.path.join(curr_dir, gameid + '.conf')) | |
85 | shutil.rmtree(os.path.join(curr_dir, gameid+'-pkg')) |