-
Notifications
You must be signed in to change notification settings - Fork 0
/
slywaldumper.c
128 lines (107 loc) · 2.69 KB
/
slywaldumper.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#define SECTOR_SIZE 2048
/*
Sector lookup tables:
If value is -1 extracting that builds wal is not supported.
*/
const int32_t startSectors[3][3] = {
// Sly 1
{
12345, // PAL
12345, // NTSC-U
12345 // NTSC-J
},
// Sly 2
{
3232, // PAL
-1, // NTSC-U
-1 // NTSC-J
},
// Sly3
{
3232, // PAL
-1, // NTSC-U
-1 // NTSC-J
},
};
const int32_t endSectors[3][3] = {
// Sly 1
{
1427632, // PAL
1368306, // NTSC-U
955136 // NTSC-J
},
// Sly 2
{
-1, // PAL
-1, // NTSC-U
-1 // NTSC-J
},
// Sly 3
{
2135015, // PAL
-1, // NTSC-U
-1 // NTSC-J
}
};
int getGameRegion(const char *regionName) {
if(strcmp(regionName, "pal") == 0) {
return 0;
}
else if(strcmp(regionName, "ntsc-u") == 0) {
return 1;
}
else if(strcmp(regionName, "ntsc-j") == 0) {
return 2;
}
else {
return 0;
}
}
int main(int argc, char *argv[]) {
printf("SlyWalDumper v1.0\n");
printf("Made by: 545u\n");
printf("https://github.com/545u\n\n");
if(argc == 5) {
int gameRegion = getGameRegion(argv[3]);
int gameNumber = argv[4][0] - '0';
if((strcmp(argv[3], "pal") != 0) && (strcmp(argv[3], "ntsc-u") != 0) && (strcmp(argv[3], "ntsc-j") != 0)) {
printf("Error: Invalid or unsupported region!\n");
return EXIT_FAILURE;
}
uint32_t startSector = startSectors[gameNumber - 1][gameRegion];
uint32_t endSector = endSectors[gameNumber - 1][gameRegion];
if((gameNumber > 3 || gameNumber < 1) || startSector == -1 || endSector == -1) {
printf("Error: Invalid or unsupported game!\n");
return EXIT_FAILURE;
}
FILE *slyIso = fopen(argv[1], "rb");
FILE *slyWal = fopen(argv[2], "wb");
fseek(slyIso, startSector * SECTOR_SIZE, SEEK_SET);
printf("Copying sectors to %s\n", argv[2]);
uint8_t sectorData[SECTOR_SIZE];
for(int i = 0; i < endSector - startSector + 1; i++) {
fread(§orData, SECTOR_SIZE, 1, slyIso);
fwrite(§orData, SECTOR_SIZE, 1, slyWal);
}
printf("Done!\n");
fclose(slyWal);
fclose(slyIso);
}
else {
printf("Usage:\n");
printf(" %s [Sly Cooper PS2 Iso] [Output Wal Filename] [Game Region] [Game Number]\n\n", argv[0]);
printf("Regions:\n");
printf(" pal, ntsc-u, ntsc-j\n\n");
printf("Supported builds:\n");
printf(" Sly 1 (PAL, NTSC-U, NTSC-J)\n");
printf(" Sly 3 (PAL)\n\n");
printf("Example Usage:\n");
printf(" %s Sly1_PAL.iso SLY1.WAL pal 1\n", argv[0]);
printf(" %s Sly3_NTSC-U.iso SLY3.WAL ntsc-u 3\n", argv[0]);
}
return EXIT_SUCCESS;
}