Files
wc3re/objdecode.cc

74 lines
1.5 KiB
C++

#include <cstdio>
#include <cstring>
#include <cerrno>
#include <cstdint>
#include <memory>
#include <limits>
#include <unistd.h>
#include "common.hh"
#include "util.hh"
#include "TreFile.hh"
#include "IffFile.hh"
#include "ObjDecoder.hh"
#include "PaletteDecoder.hh"
#include "render/Renderer.hh"
#include "game/GSShowObject.hh"
void usage(char *argv0) {
fprintf(stderr, "Usage: %s [-h] [-ppalt] resource-path\n", argv0);
fprintf(stderr, "\tAttempt to decode the object stored in the resource\n");
fprintf(stderr, "\t-p palt\tUse palette \"palt\"");
fprintf(stderr, "\t-h\tPrint this help\n");
}
int main(int argc, char *argv[]) {
std::string inPath, paltFile = "tmp/1DC61F50";
{
int opt;
while ((opt = getopt(argc, argv, "hp:")) != -1) {
switch (opt) {
case 'h':
usage(argv[0]);
return 0;
case 'p':
paltFile = optarg;
break;
default:
usage(argv[0]);
return 1;
}
}
if (optind != argc-1) {
usage(argv[0]);
return 1;
}
inPath = argv[optind];
}
try {
PaletteDecoder palt{paltFile};
auto obj = std::make_unique<ObjDecoder>(inPath);
render::Renderer renderer;
renderer.pushGS(std::make_unique<game::GSShowObject>(renderer, *obj, palt));
renderer.run();
} catch (POSIXException &ex) {
fflush(stdout);
fprintf(stderr, "%s\n", ex.toString().c_str());
return 2;
} catch (Exception &ex) {
fflush(stdout);
fprintf(stderr, "%s\n", ex.toString().c_str());
return 3;
}
return 0;
}