Skip to content

Instantly share code, notes, and snippets.

@YaLTeR
Created October 30, 2015 18:28
Show Gist options
  • Save YaLTeR/c40e8ff9fd83804cef70 to your computer and use it in GitHub Desktop.
Save YaLTeR/c40e8ff9fd83804cef70 to your computer and use it in GitHub Desktop.
#include <chrono>
#include <cstdio>
#include <cstring>
#include <boost/nowide/args.hpp>
#include <boost/nowide/iostream.hpp>
#include <boost/nowide/fstream.hpp>
#include "DemoFile.hpp"
namespace nowide = boost::nowide;
void usage()
{
nowide::cerr << "Usage:"
"\n\tDemoPrint <path to demo.dem>"
<< std::endl;
}
int main(int argc, char *argv[])
{
nowide::args a(argc, argv);
if (argc != 2) {
usage();
return 1;
}
try {
DemoFile demo(argv[1]);
demo.ReadFrames();
std::ofstream o(std::string{ argv[1] } + ".txt", std::ios::trunc);
if (!o) {
std::cerr << "Error: Could not open the output file.\n";
char c;
nowide::cin.getline(&c, 1);
return 2;
}
o.setf(std::ios::fixed);
o.precision(8);
o << "origin[0] origin[1] origin[2] velocity[0] velocity[1] velocity[2] angles[0] angles[1] angles[2] weapon buttons frametime" << std::endl;
// Some of the incorrect or malicious frames were filtered out on the demo reading stage.
// Check the ones that got through.
for (auto& entry : demo.directoryEntries) {
for (auto& frame : entry.frames) {
if (frame->type < DemoFrameType::DEMO_START || frame->type > DemoFrameType::DEMO_BUFFER) {
auto f = reinterpret_cast<NetMsgFrame*>(frame.get());
o << f->DemoInfo.RefParams.vieworg[0] << " " << f->DemoInfo.RefParams.vieworg[1] << " " << f->DemoInfo.RefParams.vieworg[2] << " "
<< f->DemoInfo.RefParams.simvel[0] << " " << f->DemoInfo.RefParams.simvel[1] << " " << f->DemoInfo.RefParams.simvel[2] << " "
<< f->DemoInfo.RefParams.viewangles[0] << " " << f->DemoInfo.RefParams.viewangles[1] << " " << f->DemoInfo.RefParams.viewangles[2] << " "
<< static_cast<int32_t>(f->DemoInfo.UserCmd.weaponselect) << " "
<< f->DemoInfo.UserCmd.buttons << " "
<< f->DemoInfo.RefParams.frametime
<< std::endl;
}
}
}
} catch (const std::exception& ex) {
nowide::cerr << "Error: " << ex.what() << std::endl;
char c;
nowide::cin.getline(&c, 1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment