Last active
August 31, 2016 00:17
-
-
Save fdeitylink/910b42351bacb08ca726 to your computer and use it in GitHub Desktop.
Reads and prints out contents of a Cave Story PXE file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <cstdint> | |
#include <cstring> | |
int main(const int argc, const char* argv[]) { | |
using namespace std; | |
if (argc <= 1) { | |
cerr << "No file provided" << endl; | |
return 1; | |
} | |
ifstream ifs(argv[1], ifstream::binary); | |
if (!ifs) { | |
cerr << "Failed to open file \"" << argv[1] << "\"" << endl; | |
return 1; | |
} | |
char* header = new char[4]; | |
ifs.read(header, 4); | |
if (strcmp(header, "PXE") != 0) { | |
cerr << "ERROR: Incorrect header" << endl; | |
return 1; | |
} | |
delete[] header; | |
uint32_t entityCount; | |
ifs.read((char*)&entityCount, sizeof(entityCount)); | |
uint16_t data; | |
const char* elements[] = {"x: ", "y: ", "flag number: ", "event number: ", "type: ", "flags: "}; | |
for (unsigned int i = 0; i < entityCount; ++i) { | |
for (int j = 0; j < 6; ++j) { | |
ifs.read((char*)&data, sizeof(data)); | |
cout << elements[j] << data << endl; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment