Create a gist now

Instantly share code, notes, and snippets.

@FDeityLink /pxe.cpp
Last active Aug 31, 2016

What would you like to do?
Reads and prints out contents of a Cave Story PXE file
#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