Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //GRP Eater
- //(C) 2015 Alex Craik
- //A little project I made because who needs PTCUtilities?
- #include <iostream>
- #include <fstream>
- bool nopalette;
- char grp[49152];
- char col[256*3];
- char bin[49152];
- int j;
- int i;
- int v;
- int u;
- int y;
- int x;
- using namespace std;
- int main(int argc, char* argv[]) {
- //initial startup routines
- //cout messages, argument processing, errors and whatnot
- cout << "GRP Eater\n(C) 2015 Alex Craik\n";
- if (argc == 1) {
- cout << "Creates PNG images of GRP files.\n";
- cout << "Accepts COL files as palettes (optional argument).\n";
- cout << "Usage: grpeat InGRPFile [InCOLFile] OutPNGFile\n";
- return 10;
- }
- if (argc == 2) {
- cout << "Error 11\nNo output file specified.\n";
- return 11;
- }
- char* ingrp = argv[1];
- char* incol;
- char* outpng;
- if (argc == 3) {
- outpng = argv[2];
- nopalette = true;
- } else {
- incol = argv[2];
- outpng = argv[3];
- }
- fstream color;
- if (nopalette) {
- color.open("DEFLTCOL.PTC", ios::in | ios::binary);
- if (!color.is_open()) {
- cout << "Error 21\nWhere's DEFLTCOL.PTC? Did you delete it? I put it there for a reason, you know.\n";
- return 21;
- }
- } else {
- color.open(incol, ios::in | ios::binary);
- if (!color.is_open()) {
- cout << "Error 22\nCould not open given COL file.\n";
- return 22;
- }
- }
- char four_bytes[5];
- four_bytes[4] = '\0';
- char colbytes[2];
- char col_filename[8];
- char md5_hash[16];
- char type_string[13];
- type_string[12] = '\0';
- //data integrity check on COL
- color.seekg(0);
- color.read(four_bytes, 4);
- if (strcmp(four_bytes, "PX01")) {
- cout << "Error 30\nCOL file is of wrong type or damaged.\n";
- cout << four_bytes;
- return 30;
- }
- color.read(four_bytes, 4);
- if (strcmp(four_bytes, "\x00\x00\x02\x0C")) {
- cout << "Error 30\nCOL file is of wrong type or damaged.\n";
- cout << four_bytes;
- return 30;
- }
- color.read(four_bytes, 4);
- if (strcmp(four_bytes, "\x05\x00\x00\x00")) {
- cout << "Error 30\nCOL file is of wrong type or damaged.\n";
- cout << four_bytes;
- return 30;
- }
- color.read(col_filename, 8); //because why not, I might use it as metadata
- color.read(md5_hash, 16); //won't be doing md5 checks yet
- color.read(type_string, 12);
- if (strcmp(type_string, "PETC0100RCOL")) {
- cout << "Error 30\nCOL file is of wrong type or damaged.\n";
- return 30;
- }
- //get the colors
- char red;
- char green;
- char blue;
- for (i = 0; i < 256; i++) {
- color.read(colbytes, 2);
- red = colbytes[0] & 0x1f;
- green = ((colbytes[0] & 0xe0) << 3) | ((colbytes[1] & 0x80) >> 2) | (colbytes[1] & 0x02); //finagle with this until colors come out right
- blue = colbytes[1] & 0x7c;
- //right-shift to get the 8-bit equivalents
- col[i * 3] = red << 3;
- col[i * 3 + 1] = green << 2;
- col[i * 3 + 2] = blue << 3;
- }
- color.close();
- fstream input;
- input.open(ingrp, ios::in | ios::binary);
- if (!input.is_open()) {
- cout << "Error 20\nCould not open given GRP file.\n";
- return 20;
- }
- //data integrity check on GRP
- //do it later, just get to the meat-and-potatoes
- input.seekg(48);
- input.read(grp, 49152); //the whole GRP
- int counter;
- //now we eat the GRP data and turn it into something useable
- //GRP has a crazy structure so I'm only doing this out of convenience
- for (j = 0; j < 3; j++) {
- for (i = 0; i < 4; i++) {
- for (v = 0; v < 8; v++) {
- for (u = 0; u < 8; u++) {
- for (y = 0; y < 8; y++) {
- for (x = 0; x < 8; x++) {
- bin[x + (y * 8) + (u * 64) + (v * 512) + (i * 4096) + (j * 16384)] = grp[counter];
- counter++;
- }
- }
- }
- }
- }
- }
- input.close();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement