forked from drizzt/GaiaManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
1951 lines (1504 loc) · 47.5 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <sys/spu_initialize.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#include <fcntl.h>
#include <pthread.h>
#include <time.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/stat.h>
#include <sys/process.h>
#include <sys/memory.h>
#include <sys/timer.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <cell/gcm.h>
#include <cell/keyboard.h>
#include <cell/sysmodule.h>
#include <cell/dbgfont.h>
#include <cell/codec/pngdec.h>
#include <cell/cell_fs.h>
#include <sysutil/sysutil_sysparam.h>
#include <sysutil/sysutil_msgdialog.h>
#include <cell/font.h>
#include <netex/net.h>
#include <netex/libnetctl.h>
#include <cell/fontFT.h>
#include <libftp.h>
#include "config.h"
#include "dialog.h"
#include "fileutils.h"
#include "i18n.h"
#include "main.h"
#include "network.h"
#include "graphics.h"
#include "parse.h"
#include "syscall8.h"
// C++ Modules
#include "sound.h"
#include "input_pad.h"
#define MAX_LIST 512
#define SETTINGS_FILE "/dev_hdd0/game/" FOLDER_NAME "/settings.cfg"
enum BmModes {
GAME = 0,
HOMEBREW = 1
};
static char hdd_folder[64] = "ASDFGHJKLMN"; // folder for games (deafult string is changed the first time it is loaded
static char hdd_folder_home[64] = FOLDER_NAME; // folder for homebrew
static t_menu_list menu_list[MAX_LIST];
static int max_menu_list = 0;
static bool direct_boot = false;
static bool disc_less = false;
static int payload_type = 0; //0 -> psgroove (or old psfreedom), 1 -> new pl3 with syscall35
static uint64_t mem_orig = 0x386000014E800020ULL;
static uint64_t mem_patched = 0xE92296887C0802A6ULL;
static uint64_t patchmode = 2; //0 -> PS3 perms normally, 1-> Psjailbreak by default, 2-> Special for games as F1 2010 (option by default)
static t_menu_list menu_homebrew_list[MAX_LIST];
static int max_menu_homebrew_list = 0;
static int *max_list = &max_menu_list;
static enum BmModes mode_list = GAME;
static int game_sel = 0;
static void *host_addr;
static int up_count = 0, down_count = 0, left_count = 0, right_count = 0;
static int counter_png = 0;
static int old_fi = -1;
static u32 fdevices = 0;
static u32 forcedevices = 0;
static char filename[1024];
static char bluray_game[64]; // name of the game
static int ftp_flags = 0;
static int unload_mod = 0;
static bool want_to_quit = false; // true when I need to quit
static int png_w = 0, png_h = 0;
time_t time_start; // time counter init
static char string1[256];
static int load_libfont_module(void);
static void ftp_on(void);
static void ftp_off(void);
static int load_modules(void);
static int unload_modules(void);
static void *png_malloc(u32 size, void *a);
static int png_free(void *ptr, void *a);
static int png_out_mapmem(u8 * buffer, size_t buf_size);
static int load_png_texture(u8 * data, char *name);
static uint32_t syscall35(const char *srcpath, const char *dstpath);
void syscall36(const char *path); // for some strange reasons it does not work as static
static void restorecall36(const char *path);
//static uint64_t peekq(uint64_t addr);
static void pokeq(uint64_t addr, uint64_t val);
static void cleanup(void);
static void fix_perm_recursive(const char *start_path);
static void sort_entries(t_menu_list * list, int *max);
static void delete_entries(t_menu_list * list, int *max, u32 flag);
static void fill_entries_from_device(char *path, t_menu_list * list, int *max, u32 flag, int sel);
#ifndef WITHOUT_SAVE_STATUS
static void parse_ini(void);
#endif
static void update_game_folder(char *ebootbin);
static void quit(void);
static void reset_game_list(int force, int sel);
static void set_hermes_mode(uint64_t mode);
static void copy_from_bluray(void);
static int load_libfont_module(void)
{
int ret;
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FONT);
if (ret == CELL_OK) {
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FREETYPE);
if (ret == CELL_OK) {
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FONTFT);
if (ret == CELL_OK) {
return ret; // Success
}
// Error handling as follows (Unload all loads)
cellSysmoduleUnloadModule(CELL_SYSMODULE_FREETYPE);
}
cellSysmoduleUnloadModule(CELL_SYSMODULE_FONT);
}
return ret; // Error end
}
/****************************************************/
/* FTP SECTION */
/****************************************************/
static void ftp_handler(CellFtpServiceEvent event, void *data __attribute__ ((unused)), size_t datalen
__attribute__ ((unused)))
{
//DPrintf("Event %i %x %i\n", event, (u32) data, datalen);
switch (event) {
case 0:
break;
case CELL_FTP_SERVICE_EVENT_SHUTDOWN:
case CELL_FTP_SERVICE_EVENT_FATAL:
case CELL_FTP_SERVICE_EVENT_STOPPED:
ftp_flags |= 4;
break;
default:
break;
}
}
static void ftp_on(void)
{
// int ret;
if (!(ftp_flags & 1)) {
// ret = sys_net_initialize_network();
// if (ret < 0)
// return;
ftp_flags |= 1;
}
if (!(ftp_flags & 2)
&& cellFtpServiceRegisterHandler(ftp_handler) >= 0) {
ftp_flags |= 2;
cellFtpServiceStart();
}
}
static void ftp_off(void)
{
if (ftp_flags & 2) {
uint64_t result;
cellFtpServiceStop(&result);
cellFtpServiceUnregisterHandler();
ftp_flags &= ~6;
}
if (ftp_flags & 1) {
sys_net_finalize_network();
ftp_flags &= ~1;
}
}
/****************************************************/
/* MODULES SECTION */
/****************************************************/
static int load_modules(void)
{
int ret;
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
if (ret != CELL_OK)
return ret;
else
unload_mod |= 1;
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_PNGDEC);
if (ret != CELL_OK)
return ret;
else
unload_mod |= 2;
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_IO);
if (ret != CELL_OK)
return ret;
else
unload_mod |= 4;
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_GCM_SYS);
if (ret != CELL_OK)
return ret;
else
unload_mod |= 8;
host_addr = memalign(0x100000, 0x100000);
if (cellGcmInit(0x10000, 0x100000, host_addr) != CELL_OK)
return -1;
if (initDisplay() != 0)
return -1;
initShader();
setDrawEnv();
if (setRenderObject())
return -1;
ret = InputPad::init();
if (ret != 0)
return ret;
setRenderTarget();
initFont();
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_NET);
if (ret < 0)
return ret;
else
unload_mod |= 16;
ret = cellSysmoduleLoadModule(CELL_SYSMODULE_HTTP);
if (ret != CELL_OK)
return ret;
else
unload_mod |= 32;
#ifndef WITHOUT_SOUND
ret = Sound::init();
if (ret != CELL_OK)
return ret;
else
unload_mod |= 64;
#endif
return ret;
}
static int unload_modules(void)
{
#ifndef WITHOUT_SAVE_STATUS
FILE *fid;
// save previous status
fid = fopen(SETTINGS_FILE, "w");
if (fid) {
fprintf(fid, "patchmode = %llu\n", patchmode);
fprintf(fid, "disc_less = %d\n", disc_less);
fprintf(fid, "direct_boot = %d\n", direct_boot);
fprintf(fid, "ftp_flags = %d\n", ftp_flags);
fprintf(fid, "hdd_folder = %s\n", hdd_folder);
fclose(fid);
}
#endif
cleanup();
ftp_off();
InputPad::free();
termFont();
free(host_addr);
#ifndef WITHOUT_SOUND
if (unload_mod & 64)
Sound::free();
#endif
if (unload_mod & 32)
cellSysmoduleUnloadModule(CELL_SYSMODULE_HTTP);
if (unload_mod & 16)
cellSysmoduleUnloadModule(CELL_SYSMODULE_NET);
if (unload_mod & 8)
cellSysmoduleUnloadModule(CELL_SYSMODULE_GCM_SYS);
if (unload_mod & 4)
cellSysmoduleUnloadModule(CELL_SYSMODULE_IO);
if (unload_mod & 2)
cellSysmoduleUnloadModule(CELL_SYSMODULE_PNGDEC);
if (unload_mod & 1)
cellSysmoduleUnloadModule(CELL_SYSMODULE_FS);
return 0;
}
SYS_PROCESS_PARAM(1001, 0x10000)
/****************************************************/
/* PNG SECTION */
/****************************************************/
typedef struct CtrlMallocArg {
u32 mallocCallCounts;
} CtrlMallocArg;
typedef struct CtrlFreeArg {
u32 freeCallCounts;
} CtrlFreeArg;
static void *png_malloc(u32 size, void *a)
{
CtrlMallocArg *arg;
arg = (CtrlMallocArg *) a;
arg->mallocCallCounts++;
return malloc(size);
}
static int png_free(void *ptr, void *a)
{
CtrlFreeArg *arg;
arg = (CtrlFreeArg *) a;
arg->freeCallCounts++;
free(ptr);
return 0;
}
static int png_out_mapmem(u8 * buffer, size_t buf_size)
{
int ret;
u32 offset;
ret = cellGcmMapMainMemory(buffer, buf_size, &offset);
if (CELL_OK != ret)
return ret;
return 0;
}
static int load_png_texture(u8 * data, char *name)
{
int ret_file, ret, ok = -1;
CellPngDecMainHandle mHandle;
CellPngDecSubHandle sHandle;
CellPngDecThreadInParam InParam;
CellPngDecThreadOutParam OutParam;
CellPngDecSrc src;
CellPngDecOpnInfo opnInfo;
CellPngDecInfo info;
CellPngDecDataOutInfo dOutInfo;
CellPngDecDataCtrlParam dCtrlParam;
CellPngDecInParam inParam;
CellPngDecOutParam outParam;
CtrlMallocArg MallocArg;
CtrlFreeArg FreeArg;
int ret_png = -1;
InParam.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_DISABLE;
InParam.ppuThreadPriority = 512;
InParam.spuThreadPriority = 200;
InParam.cbCtrlMallocFunc = png_malloc;
InParam.cbCtrlMallocArg = &MallocArg;
InParam.cbCtrlFreeFunc = png_free;
InParam.cbCtrlFreeArg = &FreeArg;
ret_png = ret = cellPngDecCreate(&mHandle, &InParam, &OutParam);
memset(data, 0xff, (DISPLAY_WIDTH * DISPLAY_HEIGHT * 4));
png_w = png_h = 0;
if (ret_png == CELL_OK) {
memset(&src, 0, sizeof(CellPngDecSrc));
src.srcSelect = CELL_PNGDEC_FILE;
src.fileName = name;
src.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_DISABLE;
ret_file = ret = cellPngDecOpen(mHandle, &sHandle, &src, &opnInfo);
if (ret == CELL_OK) {
ret = cellPngDecReadHeader(mHandle, sHandle, &info);
}
if (ret == CELL_OK) {
inParam.commandPtr = NULL;
inParam.outputMode = CELL_PNGDEC_TOP_TO_BOTTOM;
inParam.outputColorSpace = CELL_PNGDEC_RGBA;
inParam.outputBitDepth = 8;
inParam.outputPackFlag = CELL_PNGDEC_1BYTE_PER_1PIXEL;
if ((info.colorSpace == CELL_PNGDEC_GRAYSCALE_ALPHA)
|| (info.colorSpace == CELL_PNGDEC_RGBA)
|| (info.chunkInformation & 0x10))
inParam.outputAlphaSelect = CELL_PNGDEC_STREAM_ALPHA;
else
inParam.outputAlphaSelect = CELL_PNGDEC_FIX_ALPHA;
inParam.outputColorAlpha = 0xff;
ret = cellPngDecSetParameter(mHandle, sHandle, &inParam, &outParam);
}
if (ret == CELL_OK) {
dCtrlParam.outputBytesPerLine = DISPLAY_WIDTH * 4;
ret = cellPngDecDecodeData(mHandle, sHandle, data, &dCtrlParam, &dOutInfo);
//sys_timer_usleep(300);
if ((ret == CELL_OK)
&& (dOutInfo.status == CELL_PNGDEC_DEC_STATUS_FINISH)) {
png_w = outParam.outputWidth;
png_h = outParam.outputHeight;
ok = 0;
}
}
if (ret_file == 0)
ret = cellPngDecClose(mHandle, sHandle);
ret = cellPngDecDestroy(mHandle);
}
InParam.spuThreadEnable = CELL_PNGDEC_SPU_THREAD_DISABLE;
return ok;
}
/****************************************************/
/* syscalls */
/****************************************************/
/* psfreedom uses a generic syscall35 instead of syscall36 */
static uint32_t syscall35(const char *srcpath, const char *dstpath)
{
system_call_2(35, (uint32_t) srcpath, (uint32_t) dstpath);
return_to_user_prog(uint32_t);
}
// for some strange reasons syscall36 does not work as static
void syscall36(const char *path)
{
if (syscall35("/dev_bdvd", path) != 0) {
system_call_1(36, (uint32_t) path);
} else if (disc_less) {
syscall35("/app_home", path);
}
}
static void restorecall36(const char *path)
{
if (syscall35(path, NULL) != 0) {
system_call_1(36, (uint32_t) path);
}
}
/****************************************************/
/* UTILS */
/****************************************************/
#if 0 // Unused
static uint64_t peekq(uint64_t addr)
{
system_call_1(6, addr);
return_to_user_prog(uint64_t);
}
#endif
static void pokeq(uint64_t addr, uint64_t val)
{
system_call_2(7, addr, val);
}
static void fix_perm_recursive(const char *start_path)
{
int dir_fd;
uint64_t nread;
char f_name[CELL_FS_MAX_FS_FILE_NAME_LENGTH + 1];
CellFsDirent dir_ent;
CellFsErrno err;
if (cellFsOpendir(start_path, &dir_fd) == CELL_FS_SUCCEEDED) {
cellFsChmod(start_path, 0777);
while (1) {
err = cellFsReaddir(dir_fd, &dir_ent, &nread);
if (nread != 0) {
if (!strcmp(dir_ent.d_name, ".")
|| !strcmp(dir_ent.d_name, ".."))
continue;
sprintf(f_name, "%s/%s", start_path, dir_ent.d_name);
if (dir_ent.d_type == CELL_FS_TYPE_DIRECTORY) {
cellFsChmod(f_name, 0777);
fix_perm_recursive(f_name);
} else if (dir_ent.d_type == CELL_FS_TYPE_REGULAR) {
cellFsChmod(f_name, 0666);
}
} else {
break;
}
}
err = cellFsClosedir(dir_fd);
}
}
static void sort_entries(t_menu_list * list, int *max)
{
int n, m;
int fi = (*max);
for (n = 0; n < (fi - 1); n++)
for (m = n + 1; m < fi; m++) {
if ((strcasecmp(list[n].title, list[m].title) > 0 && ((list[n].flags | list[m].flags) & 2048) == 0)
|| ((list[m].flags & 2048) && n == 0)) {
t_menu_list swap;
swap = list[n];
list[n] = list[m];
list[m] = swap;
}
}
}
static void delete_entries(t_menu_list * list, int *max, u32 flag)
{
int n;
n = 0;
while (n < (*max)) {
if (list[n].flags & flag) {
if ((*max) > 1) {
list[n].flags = 0;
list[n] = list[(*max) - 1];
(*max)--;
} else {
if ((*max) == 1)
(*max)--;
break;
}
} else
n++;
}
}
static void fill_entries_from_device(char *path, t_menu_list * list, int *max, u32 flag, int sel)
{
DIR *dir;
char file[1024];
delete_entries(list, max, flag);
if ((*max) < 0)
*max = 0;
dir = opendir(path);
if (!dir)
return;
while (1) {
struct dirent *entry = readdir(dir);
if (!entry)
break;
if (entry->d_name[0] == '.')
continue;
if (!(entry->d_type & DT_DIR))
continue;
list[*max].flags = flag;
strncpy(list[*max].title, entry->d_name, 63);
list[*max].title[63] = 0;
sprintf(list[*max].path, "%s/%s", path, entry->d_name);
if (sel == 0) {
// read name in PARAM.SFO
sprintf(file, "%s/PS3_GAME/PARAM.SFO", list[*max].path);
parse_param_sfo(file, "TITLE", list[*max].title + 1 * (list[*max].title[0] == '_')); // move +1 with '_'
list[*max].title[63] = 0;
parse_param_sfo(file, "TITLE_ID", list[*max].title_id);
list[*max].title_id[63] = 0;
} else {
struct stat s;
sprintf(file, "%s/EBOOT.BIN", list[*max].path);
if (stat(file, &s) < 0)
continue;
}
(*max)++;
if (*max >= MAX_LIST)
break;
}
closedir(dir);
}
#ifndef WITHOUT_SAVE_STATUS
static void parse_ini(void)
{
FILE *fid;
fid = fopen(SETTINGS_FILE, "r");
if (!fid)
return;
while (fgets(filename, sizeof(filename), fid) != NULL) {
if (filename[strlen(filename) - 1] == '\n')
filename[strlen(filename) - 1] = '\0';
if (strncmp(filename, "patchmode = ", 12) == 0)
patchmode = strtoull(&filename[12], NULL, 10);
else if (strncmp(filename, "disc_less = ", 12) == 0)
disc_less = atoi(&filename[12]);
else if (strncmp(filename, "direct_boot = ", 14) == 0)
direct_boot = atoi(&filename[14]);
else if (strncmp(filename, "ftp_flags = ", 12) == 0)
ftp_flags = atoi(&filename[12]);
else if (strncmp(filename, "hdd_folder = ", 13) == 0)
strncpy(hdd_folder, &filename[13], sizeof(hdd_folder) - 1);
}
fclose(fid);
}
#endif
static void cleanup(void)
{
struct dirent *entry;
DIR *dir = opendir("/dev_hdd0/home");
unlink("/dev_hdd0/vsh/pushlist/patch.dat");
unlink("/dev_hdd0/vsh/pushlist/game.dat");
if (!dir)
return;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_name[0] == '.')
continue;
if (!(entry->d_type & DT_DIR))
continue;
sprintf(filename, "/dev_hdd0/home/%s/etc/boot_history.dat", entry->d_name);
unlink(filename);
}
closedir(dir);
}
static void update_game_folder(char *ebootbin
#ifndef WITHOUT_SAVE_STATUS
__attribute__ ((unused))
#endif
)
{
int ret, dir_fixed = 0;
char old_hdd_folder[64] = { 0, };
DIR *dir, *dir2;
strncpy(old_hdd_folder, hdd_folder, sizeof(hdd_folder));
dir = opendir("/dev_hdd0/game");
if (dir) {
while (1) {
struct dirent *entry = readdir(dir);
if (!entry)
break;
if (entry->d_name[0] == '.')
continue;
if (!(entry->d_type & DT_DIR))
continue;
sprintf(filename, "/dev_hdd0/game/%s/%s", entry->d_name, GAMES_DIR);
//sprintf(filename, "/dev_hdd0/GAMES");
dir2 = opendir(filename);
if (dir2) {
closedir(dir2);
dialog_ret = 0;
sprintf(filename, "%s /%s %s", text_wantuse[region], entry->d_name, text_toinstall[region]);
ret = cellMsgDialogOpen2(type_dialog_yes_no, filename, dialog_fun1, (void *) 0x0000aaaa, NULL);
wait_dialog();
if (dialog_ret == 1) {
strncpy(hdd_folder, entry->d_name, 64);
dir_fixed = 1;
break;
}
}
}
closedir(dir);
}
if (!dir_fixed) {
strcpy(hdd_folder, "./../."); // Don't change it to ".."
dir_fixed = 1;
// create the folder
sprintf(filename, "/dev_hdd0/game/%s/%s", hdd_folder, GAMES_DIR);
//sprintf(filename, "/dev_hdd0/GAMES");
mkdir(filename, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR);
dialog_ret = 0;
sprintf(filename, "/dev_hdd0/%s is the new folder for games", GAMES_DIR);
ret = cellMsgDialogOpen2(type_dialog_ok, filename, dialog_fun2, (void *) 0x0000aaab, NULL);
wait_dialog();
}
#ifdef WITHOUT_SAVE_STATUS
// modify EBOOT.BIN
if (dir_fixed && ebootbin) {
FILE *fp;
int n;
fp = fopen(ebootbin, "r+");
if (fp != NULL) {
int len;
char *mem = NULL;
fseek(fp, 0, SEEK_END);
len = ftell(fp);
mem = (char *) malloc(len + 16);
if (!mem) {
fclose(fp);
return;
}
fseek(fp, 0, SEEK_SET);
fread((void *) mem, len, 1, fp);
for (n = 0; n < (int) (len - strlen(old_hdd_folder)); n++) {
if (!memcmp(&mem[n], old_hdd_folder, strlen(old_hdd_folder))) {
strncpy(&mem[n], hdd_folder, 64);
fseek(fp, 0, SEEK_SET);
fwrite((void *) mem, len, 1, fp);
dialog_ret = 0;
sprintf(filename, "%s\n%s", text_eboot[region], text_launcher[region]);
ret = cellMsgDialogOpen2(type_dialog_ok, filename, dialog_fun2, (void *) 0x0000aaab, NULL);
wait_dialog();
break;
}
}
fclose(fp);
}
}
#endif
reset_game_list(1, 0);
}
static void quit(void)
{
if (mode_list == GAME) {
restorecall36((char *) "/app_home");
restorecall36((char *) "/dev_bdvd"); // restore bluray
} else {
restorecall36((char *) "/dev_usb000"); // restore
}
unload_modules();
sys_process_exit(1);
}
/*****************************************************/
/* CALLBACK */
/*****************************************************/
static void gfxSysutilCallback(uint64_t status, uint64_t param, void *userdata)
{
(void) param;
(void) userdata;
switch (status) {
case CELL_SYSUTIL_REQUEST_EXITGAME:
want_to_quit = true;
break;
case CELL_SYSUTIL_DRAWING_BEGIN:
case CELL_SYSUTIL_DRAWING_END:
break;
default:
printf("Graphics common: Unknown status received: 0x%llx\n", status);
}
}
static void reset_game_list(int force, int sel)
{
old_fi = -1;
counter_png = 0;
forcedevices = force;
game_sel = sel;
}
static void set_hermes_mode(uint64_t mode)
{
if (sys8_enable(0) > 0) {
sys8_perm_mode(mode);
} else {
pokeq(0x80000000000505d0ULL, mode == 0 ? mem_patched : mem_orig);
}
}
static void copy_from_bluray(void)
{
int ret;
char name[1024];
int curr_device = 0;
CellFsStat fstatus;
char id[16];
int n;
InputPad * pclIPad = InputPad::getSingle();
for (n = 0; n < 11; n++) {
dialog_ret = 0;
if ((fdevices >> n) & 1) {
if (n == 0)
sprintf(filename, "%s\n\n%s BDVD %s HDD0?", bluray_game, text_wantcopy[region], text_to[region]);
else
sprintf(filename, "%s\n\n%s BDVD %s USB00%c?", bluray_game, text_wantcopy[region], text_to[region],
47 + n);
ret = cellMsgDialogOpen2(type_dialog_yes_no, filename, dialog_fun1, (void *) 0x0000aaaa, NULL);
wait_dialog();
if (dialog_ret == 1) {
curr_device = n;
break;
} // exit
}
}
if (dialog_ret == 1) {
if (curr_device == 0)
sprintf(name, "/dev_hdd0");
else
sprintf(name, "/dev_usb00%c", 47 + curr_device);
if (cellFsStat(name, &fstatus) == CELL_FS_SUCCEEDED && !parse_ps3_disc((char *)
"/dev_bdvd/PS3_DISC.SFB", id)) {
// reset to update datas
reset_game_list(1 << curr_device, 0);
if (curr_device == 0) {
sprintf(name, "/dev_hdd0/game/%s/", hdd_folder);
mkdir(name, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR);
sprintf(name, "/dev_hdd0/game/%s/%s", hdd_folder, GAMES_DIR);
mkdir(name, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR);
sprintf(name, "/dev_hdd0/game/%s/%s/%s", hdd_folder, GAMES_DIR, id);
mkdir(name, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR);
} else {
sprintf(name, "/dev_usb00%c/%s", 47 + curr_device, GAMES_DIR);
mkdir(name, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR);
sprintf(name, "/dev_usb00%c/%s", 47 + curr_device, GAMES_DIR);
mkdir(name, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR);
sprintf(name, "/dev_usb00%c/%s/%s", 47 + curr_device, GAMES_DIR, id);
mkdir(name, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR);
}
time_start = time(NULL);
abort_copy = 0;
initConsole();
file_counter = 0;
pclIPad->clearPressed();
if (curr_device != 0)
copy_mode = 1; // break files >= 4GB
else
copy_mode = 0;
copy_is_split = 0;
my_game_copy((char *) "/dev_bdvd", (char *) name);
int seconds = (int) (time(NULL) - time_start);
int vflip = 0;
if (copy_is_split && !abort_copy) {
if (curr_device == 0) {
sprintf(filename, "/dev_hdd0/game/%s/%s/_%s", hdd_folder, GAMES_DIR, id);
} else {
sprintf(filename, "/dev_usb00%c/%s/_%s", 47 + curr_device, GAMES_DIR, id);
}
ret = rename(name, filename);
if (curr_device == 0)
sprintf(filename, "%s\n\nSplit game copied in HDD0 (non bootable)", id);
else
sprintf(filename, "%s\n\nSplit game copied in USB00%c (non bootable)", id, 47 + curr_device);
dialog_ret = 0;
ret = cellMsgDialogOpen2(type_dialog_ok, filename, dialog_fun2, (void *) 0x0000aaab, NULL);
wait_dialog();
}
while (1) {
if (abort_copy)
sprintf(string1, "Aborted!!! Time: %2.2i:%2.2i:%2.2i\n", seconds / 3600, (seconds / 60) % 60,
seconds % 60);
else {
sprintf(string1, "Done! Files Copied: %i Time: %2.2i:%2.2i:%2.2i Vol: %1.2f GB\n", file_counter,
seconds / 3600, (seconds / 60) % 60, seconds % 60, ((double)
global_device_bytes)
/ (1024.0 * 1024. * 1024.0));
}