fork/slippc
git clone https://git.julia.blue/fork/slippc
7d49c2f
0.7.1
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 12const unsigned MAX_ITEMS = 1024 ;//Max number of items to output 13const int32_t MAX_ITEM_LIFE = 1024 ;//Max number of frames to track an item 14 15namespace slip { 16 17struct SlippiFrame { 18//Parser stuff 19bool alive = false;//For checking if this frame was actually set 20 21//Pre-frame stuff 22int32_t frame = 0 ;//In-game frame number corresponding to this SlippiFrame (starts at -123) 23uint8_t player = 0 ;//Port id of the player (0 = Port 1, 1 = Port 2, etc.) 24bool follower = false;//Whether this player is a follower (e.g., 2nd climber) 25uint32_t seed = 0 ;//RNG seed at the beginning of the frame 26uint16_t action_pre = 0 ;//Action state at the beginning of the frame 27float pos_x_pre = 0.0f ;//X position at the beginning of the frame 28float pos_y_pre = 0.0f ;//Y position at the beginning of the frame 29float face_dir_pre = 0.0f ;//Facing direction at the beginning of the frame (-1 = left, +1 = right) 30float joy_x = 0.0f ;//Joystick X position 31float joy_y = 0.0f ;//Joystick Y position 32float c_x = 0.0f ;//C stick X position 33float c_y = 0.0f ;//C stick Y position 34float trigger = 0.0f ;//Analog trigger position (max of L or R) 35uint16_t buttons = 0 ;//Physical buttons pressed 36float phys_l = 0.0f ;//Physical L analog value (0-1) 37float phys_r = 0.0f ;//Physical R analog value (0-1) 38uint8_t ucf_x = 0 ;//Raw UCF value 39float percent_pre = 0.0f ;//Percent / damage at the beginning of the frame 40 41//Post-frame stuff 42uint8_t char_id = 0 ;//Internal character ID 43uint16_t action_post = 0 ;//Action state at the end of the frame 44float pos_x_post = 0.0f ;//X position at the end of the frame 45float pos_y_post = 0.0f ;//Y position at the end of the frame 46float face_dir_post = 0.0f ;//Facing direction at the end of the frame (-1 = left, +1 = right) 47float percent_post = 0.0f ;//Percent / damage at the end of the frame 48float shield = 0.0f ;//Shield health (0-60) 49uint8_t hit_with = 0 ;//Move ID of this player's last move that connected with an opponent 50uint8_t combo = 0 ;//In-game combo counter 51uint8_t hurt_by = 0 ;//Payer ID of the last opponent that hit this player 52uint8_t stocks = 0 ;//Number of stocks remaining 53float action_fc = 0.0f ;//Action state frame counter 54uint8_t flags_1 = 0 ;//Player state bit flags 1 55uint8_t flags_2 = 0 ;//Player state bit flags 2 56uint8_t flags_3 = 0 ;//Player state bit flags 3 57uint8_t flags_4 = 0 ;//Player state bit flags 4 58uint8_t flags_5 = 0 ;//Player state bit flags 5 59float hitstun = 0.0f ;//Hitstun remaining, among other things 60bool airborne = false;//Whether the player is airborne 61uint16_t ground_id = 0 ;//ID of the last ground the character stood on 62uint8_t jumps = 0 ;//Number of jumps remaining 63uint8_t l_cancel = 0 ;//L-cancel status (0 = N/A, 1 = success, 2 = failure) 64uint8_t hurtbox = 0 ;//Hurtbox state (0 = vulnerable, 1 = invulnerable, 2 = intangible) 65float self_air_x = 0 ;//Self-induced aerial X-velocity 66float self_air_y = 0 ;//Self-induced aerial Y-velocity 67float attack_x = 0 ;//Attack-induced X-velocity 68float attack_y = 0 ;//Attack-induced Y-velocity 69float self_grd_x = 0 ;//Self-induced grounded X-velocity 70float hitlag = 0 ;//Number of hitlag frames remaining 71}; 72 73struct SlippiItemFrame { 74int32_t frame = 0 ;//In-game frame number corresponding to this SlippiItemFrame 75uint8_t state = 0 ;//Item state (undocumented) 76float face_dir = 0 ;//Item facing direction (-1 = left, +1 = right) 77float xvel = 0 ;//Item X-velocity 78float yvel = 0 ;//Item Y-velocity 79float xpos = 0 ;//Item X-position 80float ypos = 0 ;//Item Y-position 81uint16_t damage = 0 ;//Item damage taken 82float expire = 0 ;//Number of frames until item expires 83uint8_t flags_1 = 0 ;//Item state flags 1 84uint8_t flags_2 = 0 ;//Item state flags 2 85uint8_t flags_3 = 0 ;//Item state flags 3 86uint8_t flags_4 = 0 ;//Item state flags 4 87int8_t owner = 0 ;//Port ID of player that owns the item (-1 = unowned) 88}; 89 90struct SlippiItem { 91uint16_t type = 0 ;//Type of item this is 92uint32_t spawn_id = MAX_ITEMS +1 ;//ID of this item 93uint32_t num_frames = 0 ;//Number of frames this item was active 94SlippiItemFrame * frame = nullptr;//Pointer to array of data for item's individual frames 95}; 96 97struct SlippiPlayer { 98uint8_t ext_char_id = 0 ;//External character ID 99uint8_t player_type = 3 ;//0 = human, 1 = CPU, 2 = demo, 3 = empty 100uint8_t start_stocks = 0 ;//Starting stocks for this player 101uint8_t end_stocks = 0 ;//Ending stocks for this player 102uint8_t color = 0 ;//Costume / color index 103uint8_t team_id = 0 ;//Team index (0 = red, 1 = blue, 2 = green) 104uint8_t cpu_level = 0 ;//CPU level for this player (only applicable for CPU players) 105uint32_t dash_back = 0 ;//Type of dash-back fix enabled (0 = off, 1 = UCF, 2 = Arduino) 106uint32_t shield_drop = 0 ;//Type of shield drop fix enabled (0 = off, 1 = UCF, 2 = Arduino) 107uint8_t shade = 0 ;//Player costume shade (0 = normal, 1 = light, 2 = dark) 108uint8_t handicap = 0 ;//Player handicap setting 109float offense = 0 ;//Knockback multiplier when hitting another player 110float defense = 0 ;//Knockback multiplier when getting hit by another player 111float scale = 0 ;//Character's model scale 112bool stamina = false;//Whether this character has a stamina bar 113bool silent = false;//Whether this character is silent (no sound effects???) 114bool low_gravity = false;//Whether this character has low gravity (bunny hood???) 115bool invisible = false;//Whether this character is invisible 116bool black_stock = false;//Whether this character has black stock icons 117bool metal = false;//Whether this character is metal 118bool warp_in = false;//Whether this character should warp in when spawning 119bool rumble = false;//Whether this player has rumble enabled 120std ::string tag = "";//Player display tag grabbed from metadata 121std ::string tag_code = "";//Player connect code 122std ::string tag_css = "";//Player tag entered on character select screen 123SlippiFrame * frame = nullptr;//Pointer to array of data for player's individual frames 124}; 125 126struct SlippiReplay { 127uint32_t slippi_version_raw = 0 ;//Raw Slippi version number 128std ::string slippi_version = "";//String representation of Slippi version number 129std ::string parser_version = "";//SlippC parser version number 130std ::string original_file = "";//Name of the input file used to generate this replay 131std ::string game_start_raw = "";//Base64-encoded game start block data 132std ::string metadata = "";//JSON metadata stored in the Slippi Replay 133std ::string played_on = "";//Platform this replay was played on (dolphin, console, or network) 134std ::string start_time = "";//Timestamp for when this game was played 135int8_t winner_id = -1 ;//Port ID of the game's winner 136bool teams = false;//Whether this was a teams match 137uint16_t stage = 0 ;//Stage ID for this game 138uint32_t seed = 0 ;//Starting RNG seed 139bool pal = false;//Whether this was played on the PAL version of Melee 140bool frozen_stadium = false;//Whether Pokemon Stadium is frozen or not 141uint8_t scene_min = 0 ;//Minor scene number 142uint8_t scene_maj = 0 ;//Major scene number 143uint8_t end_type = 0 ;//Game end type (1 = TIME!, 2 = GAME!, 7 = No Contest) 144int8_t lras = -1 ;//Port ID of player who initiated LRAStart 145int32_t first_frame = LOAD_FRAME ;//Index of first frame of the game (always -123) 146int32_t last_frame = 0 ;//Index of the last frame of the game 147uint32_t frame_count = 0 ;//Total number of frames the game lasted (always == last_frame+123) 148uint8_t timer = 0 ;//Number of minutes the timer started at 149int8_t items_on = 0 ;//Item spawn rate (-1 = disabled, 0 = very low, 1 = low, etc.) 150int8_t sd_score = 0 ;//How many points a player loses for SDing 151uint8_t timer_behav = 0 ;//Timer behavior (0 = off, 2 = count down, 3 = count up) 152uint8_t ui_chars = 0 ;//Number of UI slots for characters on the in-game HUD (usually 4) 153uint8_t game_mode = 0 ;//Game mode (0 = time, 1 = stock, 2 = coin, 3 = bonus) 154bool friendly_fire = false;//Whether friendly fire is enabled 155bool demo_mode = false;//Whether we are in the title screen or BTT dmeo 156bool classic_adv = false;//Whether we are in classic or adventure mode 157bool hrc_event = false;//Whether we are in HRC or some other event 158bool allstar_wait1 = false;//Whether we are in the all-star wait area 159bool allstar_game1 = false;//Same as above??? 160bool allstar_wait2 = false;//Whether we are in an all-star game 161bool allstar_game2 = false;//Same as above??? 162bool single_button = false;//Whether we are in single button mode 163bool pause_timer = false;//Whether the timer continues to count down when game is paused 164bool pause_nohud = false;//Whether the HUD is shown when game is paused 165bool pause_lras = false;//Whether LRAS is enabled when game is paused 166bool pause_off = false;//Whether pause is disabld 167bool pause_zretry = false;//Whether we can press Z to retry when game is paused 168bool pause_analog = false;//Whether the analog stick is shown when game is paused 169bool pause_score = false;//Whether the score is shown when game is paused 170uint8_t items1 = 0 ;//Item enabled / disabled bitfield 1 171uint8_t items2 = 0 ;//Item enabled / disabled bitfield 2 172uint8_t items3 = 0 ;//Item enabled / disabled bitfield 3 173uint8_t items4 = 0 ;//Item enabled / disabled bitfield 4 174uint8_t items5 = 0 ;//Item enabled / disabled bitfield 5 175bool sudden_death = false;//Whether bombs start dropping after 20 seconds 176uint32_t num_items = 0 ;//Number of distinct item IDs encountered during the game 177SlippiPlayer player [8 ]= {0 };//Array of SlippiPlayers (1 main + follower for each port) 178SlippiItem item [MAX_ITEMS ]= {0 };//Array of SlippiItems (can track up to MAX_ITEMS per game) 179 180void setFrames (int32_t max_frames ); 181void cleanup (); 182std ::string replayAsJson (bool delta ); 183}; 184 185 186} 187 188#endif /* REPLAY_H_ */