-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.cpp
167 lines (143 loc) · 3.8 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
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <cstdio>
#ifdef _WIN32
#include <windows.h>
#endif
#include <list>
#include <cmath>
#include <cstring>
#include <iomanip>
using namespace std;
//------------------------------
// .vol volume archive structs
//------------------------------
typedef struct
{
uint32_t unk1[3];
uint32_t numFiles;
uint32_t headerSz;
} volHeader;
typedef struct
{
uint32_t nameOffset;
uint32_t dataOffset1;
uint32_t dataOffset2;
uint32_t dataSz;
uint32_t unk;
} volEntry;
/*typedef struct
{
uint32_t unk[7];
uint32_t numDictEntries;
} list1;
FIBITMAP* imageFromPixels(uint8_t* imgData, uint32_t width, uint32_t height)
{
//FreeImage is broken here and you can't swap R/G/B channels upon creation. Do that manually
FIBITMAP* result = FreeImage_ConvertFromRawBits(imgData, width, height, ((((32 * width) + 31) / 32) * 4), 32, FI_RGBA_RED, FI_RGBA_GREEN, FI_RGBA_BLUE, true);
FIBITMAP* r = FreeImage_GetChannel(result, FICC_RED);
FIBITMAP* b = FreeImage_GetChannel(result, FICC_BLUE);
FreeImage_SetChannel(result, b, FICC_RED);
FreeImage_SetChannel(result, r, FICC_BLUE);
FreeImage_Unload(r);
FreeImage_Unload(b);
return result;
}*/
bool splitFiles(const char* cFilename)
{
uint8_t* fileData;
FILE* fh = fopen(cFilename, "rb");
if(fh == NULL)
{
cerr << "Unable to open input file " << cFilename << endl;
return false;
}
fseek(fh, 0, SEEK_END);
size_t fileSize = ftell(fh);
fseek(fh, 0, SEEK_SET);
fileData = (uint8_t*)malloc(fileSize);
size_t amt = fread(fileData, fileSize, 1, fh);
fclose(fh);
cout << "Splitting files from volume " << cFilename << endl;
//Figure out what we'll be naming the images
string sName = cFilename;
//First off, strip off filename extension
size_t namepos = sName.find(".vol");
if(namepos != string::npos)
sName.erase(namepos);
//Next, strip off any file path before it
namepos = sName.rfind('/');
if(namepos == string::npos)
namepos = sName.rfind('\\');
if(namepos != string::npos)
sName.erase(0, namepos+1);
//Create output folder
#ifdef _WIN32
CreateDirectory(TEXT(sName.c_str()), NULL);
#else
int result = system("mkdir -p output");
#endif
//grab header
volHeader vh;
memcpy(&vh, fileData, sizeof(volHeader));
//grab files
for(int i = 0; i < vh.numFiles; i++)
{
/*typedef struct
{
uint32_t nameOffset;
uint64_t dataOffset;
uint32_t dataSz;
uint32_t unk;
} volEntry;*/
volEntry ve;
memcpy(&ve, &fileData[vh.headerSz+4+i*sizeof(volEntry)], sizeof(volEntry));
cout << std::hex << ve.nameOffset << ", " << ve.dataOffset1 << ", " << ve.dataOffset2 << ", " << ve.dataSz << endl;
ostringstream oss;
oss << sName << "/" << (char*)(&fileData[ve.nameOffset]);
cout << "Saving " << oss.str() << endl;
FILE* f = fopen(oss.str().c_str(), "wb");
uint64_t dataOff = (uint64_t)ve.dataOffset1 | ((uint64_t)ve.dataOffset2 << 32);
fwrite(&fileData[dataOff], 1, ve.dataSz, f);
fclose(f);
}
//Grab data Header
//DataHeader dh;
//memcpy(&dh, fileData, sizeof(DataHeader));
//TODO
//int oSize = 0;
//byte* output = lzx_decompress(&fileData[dh.binData1Offset], &oSize);
//FILE* f = fopen("out.tmp", "wb");
//fwrite(output, oSize, 1, f);
//fclose(f);
//delete[] output;
return true;
}
int main(int argc, char** argv)
{
//FreeImage_Initialise();
list<string> sFilenames;
//Parse commandline
for(int i = 1; i < argc; i++)
{
string s = argv[i];
sFilenames.push_back(s);
}
//Decompress data files
int result = 0;
for(list<string>::iterator i = sFilenames.begin(); i != sFilenames.end(); i++)
{
if(!splitFiles((*i).c_str()))
result = 1;
}
//FreeImage_DeInitialise();
if(result) //Pause if we ran into trouble, to give users time to see/copy down any error message...
{
cout << "Press Enter to exit..." << endl;
cin.get();
}
return 0;
}