Created
June 2, 2016 19:53
-
-
Save YaLTeR/95e0ae1e0ffffc09b5bf1c61f8ad4f8d to your computer and use it in GitHub Desktop.
HLSDemo version of Listdemo from DemTools.
This file contains hidden or 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 <algorithm> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <cstring> | |
#include <boost/nowide/args.hpp> | |
#include <boost/nowide/iostream.hpp> | |
#include "DemoFile.hpp" | |
namespace nowide = boost::nowide; | |
void usage() | |
{ | |
nowide::cout << "Usage:" | |
"\n\tListdemo <path to demo.dem>" | |
"\n\t- Shows information about the demo." | |
<< std::endl; | |
} | |
template<size_t N> | |
inline bool any_matches(const char* pattern, const char* const (&samples)[N]) | |
{ | |
for (size_t i = 0; i < N; ++i) { | |
if (!std::strcmp(pattern, samples[i])) | |
return true; | |
} | |
return false; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
nowide::args a(argc, argv); | |
if (argc != 2) { | |
usage(); | |
nowide::cin.get(); | |
return 1; | |
} | |
try { | |
DemoFile demo(argv[1], false); | |
nowide::cout << "Reading " << argv[1] << "...\n\n"; | |
nowide::cout << "Demo protocol: " << demo.header.demoProtocol << '\n'; | |
nowide::cout << "Net protocol: " << demo.header.netProtocol << '\n'; | |
nowide::cout << "Map name: " << demo.header.mapName << '\n'; | |
nowide::cout << "Game directory: " << demo.header.gameDir << "\n\n"; | |
size_t i = 0; | |
for (const auto& entry : demo.directoryEntries) { | |
++i; | |
if (entry.type == 0) { | |
// Don't print the start segment, no useful info. | |
continue; | |
} | |
nowide::cout << i << ":\n"; | |
nowide::cout << "\tType: " << (entry.type ? "normal" : "start") << " segment\n"; | |
nowide::cout << "\tTime (full): " << entry.playbackTime << "s\n"; | |
nowide::cout << "\tFrames: " << entry.frameCount << '\n'; | |
} | |
nowide::cout << "\nReading frames...\n\n"; | |
demo.ReadFrames(); | |
i = 0; | |
for (const auto& entry : demo.directoryEntries) { | |
++i; | |
if (entry.type == 0) { | |
// Don't print the start segment, no useful info. | |
continue; | |
} | |
nowide::cout << i << ":\n"; | |
bool found = false; | |
for (const auto& frame : entry.frames) { | |
if (frame->type == DemoFrameType::CONSOLE_COMMAND) { | |
auto f = reinterpret_cast<ConsoleCommandFrame*>(frame.get()); | |
if (f->command.find("#SAVE#") != f->command.npos) { | |
found = true; | |
nowide::cout << "Found a save flag at " << f->time << "!\n"; | |
} | |
} | |
} | |
if (!found) | |
nowide::cout << "Found no save flags.\n"; | |
nowide::cout << "\n"; | |
} | |
} catch (const std::exception& ex) { | |
nowide::cout << "Error: " << ex.what() << std::endl; | |
} | |
nowide::cin.get(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment