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
|
#include "qda.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Load headers for each image
//Returns: 0 = file not found | 1 = success | 2 = Invalid file
int initQDA()
{
int result = 0;
FILE* f;
char fullPath[80];
#ifdef _SDL
strcpy(fullPath, "data/");
#else
strcpy(fullPath, "");
#endif
#ifdef _3DS
strcat(fullPath, "romfs:/");
#endif
strcat(fullPath, "bmp.qda");
if ( (f = fopen(fullPath, "rb")) ) {
result = 1;
//Read header data into memory
int allHeadersSize = 0x1F5C;
unsigned char* QDAFile = (unsigned char*)malloc(allHeadersSize);
fread(QDAFile, allHeadersSize, 1, f);
//Check if QDA file is valid
{
if (QDAFile[4] == 0x51 && QDAFile[5] == 0x44 && QDAFile[6] == 0x41 && QDAFile[7] == 0x30) {
//Load headers separately
{
int numofsheets = 29;
int headerSize = 0x10C;
int i;
for (i = 0; i < numofsheets; i++) {
//memcpy(&headers[i], &QDAFile[0x100 + (i * headerSize)], sizeof(QDAHeader));
int offset = 256 + (i * headerSize);
memcpy(&headers[i].offset, &QDAFile[offset], 4);
memcpy(&headers[i].size, &QDAFile[offset + 4], 4);
memcpy(&headers[i].bytes, &QDAFile[offset + 8], 4);
memcpy(&headers[i].fileName, &QDAFile[offset + 12], 0x100);
}
}
}else{
result = 2;
}
}
//Cleanup
free(QDAFile);
}
fclose(f);
return result;
}
|