Skip to content

Instantly share code, notes, and snippets.

@fdeitylink
Last active August 31, 2016 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdeitylink/910b42351bacb08ca726 to your computer and use it in GitHub Desktop.
Save fdeitylink/910b42351bacb08ca726 to your computer and use it in GitHub Desktop.
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