fork/slippc
git clone https://git.julia.blue/fork/slippc
46ef8c0
testing
1#ifndef PARSER_H_ 2#define PARSER_H_ 3 4#include <iostream> 5#include <fstream> 6#include <sstream> 7#include <regex> 8 9#include "util.h" 10#include "replay.h" 11#include "analyzer.h" 12#include "schema.h" 13#include "compressor.h" 14 15// Replay File (.slp) Spec: https://github.com/project-slippi/slippi-wiki/blob/master/SPEC.md 16 17namespace slip { 18 19class Parser { 20private : 21int _debug ;//Current debug level 22SlippiReplay _replay ;//Internal struct for replay being parsed 23uint16_t _payload_sizes [256 ]= {0 };//Size of payload for each event 24std ::string _slippi_version ;//String representation of the Slippi version of the replay 25uint8_t _slippi_maj = 0 ;//Major version number of replay being parsed 26uint8_t _slippi_min = 0 ;//Minor version number of replay being parsed 27uint8_t _slippi_rev = 0 ;//Revision number of replay being parsed 28int32_t _max_frames = 0 ;//Maximum number of frames that there will be in the replay file 29bool _game_end_found = false;//Whether we've found the game end event 30bool _is_encoded = false;//Whether this file is encoded by the compressor 31 32char * _rb = nullptr ;//Read buffer 33unsigned _bp ;//Current position in buffer 34uint32_t _length_raw ;//Remaining length of raw payload 35uint32_t _length_raw_start ;//Total length of raw payload 36uint32_t _file_size ;//Total size of the replay file on disk 37bool _parse ();//Internal main parsing funnction 38bool _parseHeader (); 39bool _parseEventDescriptions (); 40bool _parseEvents (); 41bool _parseGameStart (); 42bool _parsePreFrame (); 43bool _parsePostFrame (); 44bool _parseGameEnd (); 45bool _parseItemUpdate (); 46bool _parseMetadata (); 47void _cleanup ();//Cleanup replay data 48public : 49Parser (int debug_level ); //Instantiate the parser (possibly in debug mode) 50~ Parser (); //Destroy the parser 51bool load ( const char * replayfilename); //Load a replay file 52Analysis * analyze (); //Analyze the loaded replay file 53std :: string asJson ( bool delta); //Convert the parsed replay structure to a JSON 54void save ( const char * outfilename, bool delta); //Save a replay file 55 56//Getter function for exposing read-only access to underlying replay 57inline const SlippiReplay * replay () const { 58return & _replay; 59}; 60 61//Estimate the maximum number of frames stored in the file 62// -> Assumes only two people are alive for the whole match / one ice climber 63inline int32_t getMaxNumFrames () { 64//Get the base size for the file 65unsigned base_size = 0 ; 66base_size += _payload_sizes[Event:: EV_PAYLOADS ]; //One meta event 67base_size += _payload_sizes[Event:: GAME_START ]; //One start event 68base_size += _payload_sizes[Event:: GAME_END ]; //One end event 69 70unsigned num_players = 2 ; 71 72unsigned frame_size = num_players * ( 73_payload_sizes[Event:: PRE_FRAME ] + 74_payload_sizes[Event:: POST_FRAME ] 75); 76 77if (_length_raw_start < base_size) { 78return 0 ; //There's a problem 79} 80 81// std::cerr << "((" << _length_raw_start << "-" << base_size << ")/" << frame_size << ")-123" << std::endl; 82int32_t maxframes = ((_length_raw_start - base_size)/frame_size) + LOAD_FRAME ; 83return maxframes + 1 ; //TODO: the above doesn't compute an exact number sometimes and we need the +1; figure out why 84} 85}; 86 87} 88 89#endif /* PARSER_H_ */