-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
60 lines (50 loc) · 1.64 KB
/
Copy pathmain.cpp
File metadata and controls
60 lines (50 loc) · 1.64 KB
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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdio>
#include <filesystem>
#include <cstdint>
#include <cstring> //linux g++ requires this
#include "Q2MD2.h"
#include "DKM.h"
#include "conv.h"
using namespace std;
namespace fs = filesystem;
int main(int argc, char* argv[]) {
if (argc < 2) {
cout << "No file provided. Please provide a Quake 2 MD2 model file." << endl;
return 1;
}
fs::path filePath(argv[1]);
string extension = filePath.extension().string();
for (auto& c : extension) c = tolower(c);
if (extension == ".md2") {
cout << "Processing MD2 file..." << endl;
fs::path outPath = filePath;
outPath.replace_extension(".dkm");
ifstream inFile(filePath, ios::binary);
if (!inFile.is_open()) {
cout << "Error: Could not open input file." << endl;
return 1;
}
char ident[4];
inFile.read(ident, 4);
int versionnum;
inFile.read(reinterpret_cast<char*>(&versionnum), sizeof(versionnum));
inFile.close();
if (memcmp(ident, "IDP2", 4) == 0 && versionnum == 8) {
cout << "Identified Quake 2 model file: " << string(ident, 4) << " and " << versionnum << endl;
WriteDKM(outPath, ConvertMD2toDKM(ParseQ2MD2(filePath)));
}
else {
cout << "Error: Invalid ident and version numbers: " << string(ident, 4) << " and " << versionnum << endl;
return 1;
}
}
else {
cout << "Unsupported file extension: " << filePath.extension() << endl;
}
return 0;
}