forked from soneek/3DSUSoundArchiveTool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGRP.h
127 lines (120 loc) · 3.43 KB
/
GRP.h
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
typedef struct {
u32 id;
u32 offset;
u32 fileId;
string name;
string outfolder;
u32 groupBank;
bool bankExists;
u32 groupWarc;
u32 sectionCount;
u32 infoOffset;
u32 infoSize;
u32 fileOffset;
u32 fileSize;
u32 infxOffset;
u32 infxSize;
u32 fileCount;
u32 tempId;
void processGroup(FILE * &csar) {
fseek(csar, files[fileId].fileOffset, SEEK_SET);
// printf("Checking group at %X\n", ftell(csar));
typeHeader = ReadBE(csar, 32);
if (typeHeader != 0x43475250)
printf("Group might be external, because it isn't here.\n");
else {
// printf("Found group\n");
fseek(csar, 0xC, SEEK_CUR);
sectionCount = ReadLE(csar, 16);
fseek(csar, 2, SEEK_CUR);
for (j = 0; j < (int)sectionCount; j++) {
// printf("%X\n", ftell(sar));
tempHeader = ReadLE(csar, 16);
fseek(csar, 2, SEEK_CUR);
if (tempHeader == 0x7800) {
// Found INFO pointer
infoOffset = ReadLE(csar, 32) + files[fileId].fileOffset;
// printf("INFO section at %X\n", infoOffset);
infoSize = ReadLE(csar, 32);
}
else if (tempHeader == 0x7801) {
// Found FILE pointer
fileOffset = ReadLE(csar, 32) + files[fileId].fileOffset;
fileSize = ReadLE(csar, 32);
}
else if (tempHeader == 0x7802) {
// Found INFX pointer
infxOffset = ReadLE(csar, 32) + files[fileId].fileOffset;
infxSize = ReadLE(csar, 32);
}
else {
printf("Unrecognized section pointer\n");
fclose(csar);
exit(1);
}
}
// Reading INFO section
fseek(csar, infoOffset + 8, SEEK_SET);
fileCount = ReadLE(csar, 32);
printf("%d files for this group\n", fileCount);
bankExists = false;
for (m = 0; m < (int)fileCount; m++) {
fseek(csar, infoOffset + 12 + m * 8, SEEK_SET);
tempHeader = ReadLE(csar, 16);
fseek(csar, 2, SEEK_CUR);
if (tempHeader != 0x7900)
continue;
else {
printf("Iteration %d - Currently at %X\n", m, ftell(csar));
tempOffset = ReadLE(csar, 32) + infoOffset + 8;
fseek(csar, tempOffset, SEEK_SET);
printf("Now at %X\n", ftell(csar));
tempId = ReadLE(csar, 32);
printf("Found file %d\n", tempId);
tempHeader = ReadLE(csar, 16);
fseek(csar, 2, SEEK_CUR);
if (tempHeader != 0x1F00)
continue;
else {
files[tempId].fileOffset = ReadLE(csar, 32) + fileOffset + 8;
fseek(csar, files[tempId].fileOffset, SEEK_SET);
if (files[tempId].type == "bcwar") {
warcs[files[tempId].id].processWarc(csar);
}
else
continue;
}
}
}
// Looping through again, but this time focusing on banks
for (m = 0; m < (int)fileCount; m++) {
fseek(csar, infoOffset + 12 + m * 8, SEEK_SET);
tempHeader = ReadLE(csar, 16);
fseek(csar, 2, SEEK_CUR);
if (tempHeader != 0x7900)
continue;
else {
printf("Iteration %d - Currently at %X\n", m, ftell(csar));
tempOffset = ReadLE(csar, 32) + infoOffset + 8;
fseek(csar, tempOffset, SEEK_SET);
printf("Now at %X\n", ftell(csar));
tempId = ReadLE(csar, 32);
printf("Found file %d\n", tempId);
tempHeader = ReadLE(csar, 16);
fseek(csar, 2, SEEK_CUR);
if (tempHeader != 0x1F00)
continue;
else {
files[tempId].fileOffset = ReadLE(csar, 32) + fileOffset + 8;
fseek(csar, files[tempId].fileOffset, SEEK_SET);
if (files[tempId].type == "bcbnk") {
banks[files[tempId].id].processBank(csar);;
}
else
continue;
}
}
}
}
}
} group;