-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
71 lines (60 loc) · 2.26 KB
/
main.cpp
File metadata and controls
71 lines (60 loc) · 2.26 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
61
62
63
64
65
66
67
68
69
70
71
#include "lodepng.h"
#include "foart.h"
#include <iostream>
#include <filesystem>
#include <vector>
using namespace std;
void writePng(const std::string& filename, std::vector<ucolor>& pixels, unsigned width, unsigned height)
{
std::vector<unsigned char> image;
image.resize(width * height * 4);
for (size_t i = 0; i < width * height; i++)
{
image[i * 4] = pixels[i].r;
image[i * 4 + 1] = pixels[i].g;
image[i * 4 + 2] = pixels[i].b;
image[i * 4 + 3] = pixels[i].a;
}
unsigned error = lodepng::encode(filename + ".png", image, width, height);
if (error) std::cout << "encoder error " << error << ": " << lodepng_error_text(error) << std::endl;
}
bool decodeGraphics(filesystem::path& filename)
{
ByteReader* reader = new ByteReader;
reader->Reset(filename.string(), ByteReader::BigEndian);
file_t file;
file.read(reader);
if (file.check_num1 != 42) return false;
for (size_t currData = 0; currData < file.hdr.dirs; currData++)
{
for (size_t currFrame = 0; currFrame < file.hdr.frames_count; currFrame++)
{
frame_t* currFrame_ptr = &file.data[currData].frames[currFrame];
writePng(filename.parent_path().string() + "/" + filename.stem().string() + to_string(currData) + "_" + to_string(currFrame), currFrame_ptr->pixels, currFrame_ptr->width, currFrame_ptr->height);
}
}
return true;
}
void decodeOldGraphics(filesystem::path& filename)
{
ByteReader* reader = new ByteReader;
reader->Reset(filename.string(), ByteReader::BigEndian);
oldfile_t file;
file.read(reader);
if (file.width == 1196314761) return;
writePng(filename.parent_path().string() + "/" + filename.stem().string() + "_unbake", file.pixels, file.width, file.height);
}
int main(int argc, char* argv[])
{
if(argc < 2)
{
cout << "HELP:\nTo use this tool drag&drop needed Fonline Art file to program, or type file name as arg in console.\n\nABOUT:\nThe format has no name, but used in FOnline engine.\nThe author of format is Anton 'Cvet' Tsvetinsky.\nThe author of FoUnbaker is APAMk2. 2024.";
return 0;
}
filesystem::path filename = argv[1];
if (!decodeGraphics(filename))
{
decodeOldGraphics(filename);
}
return 0;
}