fork/slippc
git clone https://git.julia.blue/fork/slippc
9683729
0.5.0
1#ifndef REPLAY_H_ 2#define REPLAY_H_ 3 4#include <iostream> 5#include <fstream> 6 7#include "enums.h" 8#include "util.h" 9 10// Replay File (.slp) Spec: https://github.com/project-slippi/project-slippi/wiki/Replay-File-Spec 11 12#define BYTE8 (b1 ,b2 ,b3 ,b4 ,b5 ,b6 ,b7 ,b8 ) (*((uint64_t*)(char[]){b1,b2,b3,b4,b5,b6,b7,b8})) 13#define BYTE4 (b1 ,b2 ,b3 ,b4 ) (*((uint32_t*)(char[]){b1,b2,b3,b4})) 14#define BYTE2 (b1 ,b2 ) (*((uint16_t*)(char[]){b1,b2})) 15 16const uint64_t SLP_HEADER = BYTE8 (0x7b ,0x55 ,0x03 ,0x72 ,0x61 ,0x77 ,0x5b ,0x24 );// {U.raw[$ 17 18const unsigned N_HEADER_BYTES = 15 ;//Header is always 15 bytes 19const unsigned MIN_EV_PAYLOAD_SIZE = 14 ;//Payloads, game start, pre frame, post frame, game end always defined 20const unsigned MIN_GAME_START_SIZE = 353 ;//Minimum size for game start event (necessary for all replays) 21const unsigned MIN_REPLAY_LENGTH = N_HEADER_BYTES + MIN_EV_PAYLOAD_SIZE + MIN_GAME_START_SIZE ; 22 23namespace slip { 24 25struct SlippiFrame { 26//Parser stuff 27bool alive = false;//For checking if this frame was actually set 28 29//Pre-frame stuff 30int32_t frame = 0 ; 31uint8_t player = 0 ; 32bool follower = false; 33uint32_t seed = 0 ; 34uint16_t action_pre = 0 ; 35float pos_x_pre = 0.0f ; 36float pos_y_pre = 0.0f ; 37float face_dir_pre = 0.0f ; 38float joy_x = 0.0f ; 39float joy_y = 0.0f ; 40float c_x = 0.0f ; 41float c_y = 0.0f ; 42float trigger = 0.0f ; 43uint32_t buttons = 0 ; 44float phys_l = 0.0f ; 45float phys_r = 0.0f ; 46uint8_t ucf_x = 0 ; 47float percent_pre = 0.0f ; 48 49//Post-frame stuff 50uint8_t char_id = 0 ; 51uint16_t action_post = 0 ; 52float pos_x_post = 0.0f ; 53float pos_y_post = 0.0f ; 54float face_dir_post = 0.0f ; 55float percent_post = 0.0f ; 56float shield = 0.0f ; 57uint8_t hit_with = 0 ; 58uint8_t combo = 0 ; 59uint8_t hurt_by = 0 ; 60uint8_t stocks = 0 ; 61float action_fc = 0.0f ; 62uint8_t flags_1 = 0 ; 63uint8_t flags_2 = 0 ; 64uint8_t flags_3 = 0 ; 65uint8_t flags_4 = 0 ; 66uint8_t flags_5 = 0 ; 67float hitstun = 0.0f ; 68bool airborne = false; 69uint16_t ground_id = 0 ; 70uint8_t jumps = 0 ; 71uint8_t l_cancel = 0 ; 72}; 73 74struct SlippiPlayer { 75uint8_t ext_char_id = 0 ; 76uint8_t player_type = 3 ;//empty 77uint8_t start_stocks = 0 ; 78uint8_t color = 0 ; 79uint8_t team_id = 0 ; 80uint8_t cpu_level = 0 ; 81uint32_t dash_back = 0 ; 82uint32_t shield_drop = 0 ; 83std ::string tag = ""; 84std ::string tag_code = ""; 85std ::string tag_css = ""; 86SlippiFrame * frame = nullptr; 87}; 88 89struct SlippiReplay { 90std ::string slippi_version = ""; 91std ::string parser_version = ""; 92std ::string game_start_raw = ""; 93std ::string metadata = ""; 94std ::string played_on = ""; 95std ::string start_time = ""; 96bool teams = false; 97uint16_t stage = 0 ; 98uint32_t seed = 0 ; 99bool pal = false; 100bool frozen = false; 101uint8_t end_type = 0 ; 102int8_t lras = 0 ; 103int32_t first_frame = LOAD_FRAME ; 104int32_t last_frame = 0 ; 105uint32_t frame_count = 0 ; 106uint8_t timer = 0 ; 107int8_t items = 0 ; 108bool sudden_death = false; 109SlippiPlayer player [8 ]; 110 111void setFrames (int32_t max_frames ); 112void cleanup (); 113std ::string replayAsJson (bool delta ); 114}; 115 116 117} 118 119#endif /* REPLAY_H_ */