fork/slippc
git clone https://git.julia.blue/fork/slippc
bf6fd60
bench
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 71uint32_t anim_index = 0 ;//Animation index (used for Wait) 72}; 73 74struct SlippiItemFrame { 75int32_t frame = 0 ;//In-game frame number corresponding to this SlippiItemFrame 76uint8_t state = 0 ;//Item state (undocumented) 77float face_dir = 0 ;//Item facing direction (-1 = left, +1 = right) 78float xvel = 0 ;//Item X-velocity 79float yvel = 0 ;//Item Y-velocity 80float xpos = 0 ;//Item X-position 81float ypos = 0 ;//Item Y-position 82uint16_t damage = 0 ;//Item damage taken 83float expire = 0 ;//Number of frames until item expires 84uint8_t flags_1 = 0 ;//Item state flags 1 85uint8_t flags_2 = 0 ;//Item state flags 2 86uint8_t flags_3 = 0 ;//Item state flags 3 87uint8_t flags_4 = 0 ;//Item state flags 4 88int8_t owner = 0 ;//Port ID of player that owns the item (-1 = unowned) 89}; 90 91struct SlippiItem { 92uint16_t type = 0 ;//Type of item this is 93uint32_t spawn_id = MAX_ITEMS +1 ;//ID of this item 94uint32_t num_frames = 0 ;//Number of frames this item was active 95SlippiItemFrame * frame = nullptr;//Pointer to array of data for item's individual frames 96}; 97 98struct SlippiPlayer { 99uint8_t ext_char_id = 0 ;//External character ID 100uint8_t player_type = 3 ;//0 = human, 1 = CPU, 2 = demo, 3 = empty 101uint8_t start_stocks = 0 ;//Starting stocks for this player 102uint8_t end_stocks = 0 ;//Ending stocks for this player 103uint8_t color = 0 ;//Costume / color index 104uint8_t team_id = 0 ;//Team index (0 = red, 1 = blue, 2 = green) 105uint8_t cpu_level = 0 ;//CPU level for this player (only applicable for CPU players) 106uint32_t dash_back = 0 ;//Type of dash-back fix enabled (0 = off, 1 = UCF, 2 = Arduino) 107uint32_t shield_drop = 0 ;//Type of shield drop fix enabled (0 = off, 1 = UCF, 2 = Arduino) 108uint8_t shade = 0 ;//Player costume shade (0 = normal, 1 = light, 2 = dark) 109uint8_t handicap = 0 ;//Player handicap setting 110float offense = 0 ;//Knockback multiplier when hitting another player 111float defense = 0 ;//Knockback multiplier when getting hit by another player 112float scale = 0 ;//Character's model scale 113bool stamina = false;//Whether this character has a stamina bar 114bool silent = false;//Whether this character is silent (no sound effects???) 115bool low_gravity = false;//Whether this character has low gravity (bunny hood???) 116bool invisible = false;//Whether this character is invisible 117bool black_stock = false;//Whether this character has black stock icons 118bool metal = false;//Whether this character is metal 119bool warp_in = false;//Whether this character should warp in when spawning 120bool rumble = false;//Whether this player has rumble enabled 121std ::string tag = "";//Player display tag grabbed from metadata 122std ::string tag_code = "";//Player connect code (as of 3.9.0, in both game start block and metadata) 123std ::string tag_css = "";//Player tag entered on character select screen 124std ::string disp_name = "";//Display name used on Slippi Online 125std ::string slippi_uid = "";//Firebase UID of Slippi player 126SlippiFrame * frame = nullptr;//Pointer to array of data for player's individual frames 127}; 128 129struct SlippiReplay { 130unsigned errors = 0 ;//Number of errors that occurred during parsing 131uint32_t slippi_version_raw = 0 ;//Raw Slippi version number 132std ::string slippi_version = "";//String representation of Slippi version number 133std ::string parser_version = "";//SlippC parser version number 134std ::string original_file = "";//Name of the input file used to generate this replay 135std ::string game_start_raw = "";//Base64-encoded game start block data 136std ::string metadata = "";//JSON metadata stored in the Slippi Replay 137std ::string played_on = "";//Platform this replay was played on (dolphin, console, or network) 138std ::string start_time = "";//Timestamp for when this game was played 139std ::string match_id = "";//An ID consisting of the mode and time the match started (e.g. mode.unranked-2022-12-20T06:52:39.18-0). Max 50 characters + null terminator 140int8_t winner_id = -1 ;//Port ID of the game's winner 141bool teams = false;//Whether this was a teams match 142uint16_t stage = 0 ;//Stage ID for this game 143uint32_t seed = 0 ;//Starting RNG seed 144uint32_t game_number = 0 ;//For the given Match ID, starts at 1 145uint32_t tiebreaker_number = 0 ;//For the given Game Number, will be 0 if not a tiebreak game 146bool pal = false;//Whether this was played on the PAL version of Melee 147bool frozen_stadium = false;//Whether Pokemon Stadium is frozen or not 148uint8_t scene_min = 0 ;//Minor scene number 149uint8_t scene_maj = 0 ;//Major scene number 150uint8_t end_type = 0 ;//Game end type (1 = TIME!, 2 = GAME!, 7 = No Contest) 151int8_t lras = -1 ;//Port ID of player who initiated LRAStart 152int32_t first_frame = LOAD_FRAME ;//Index of first frame of the game (always -123) 153int32_t last_frame = 0 ;//Index of the last frame of the game 154uint32_t frame_count = 0 ;//Total number of frames the game lasted (always == last_frame+123) 155uint8_t timer = 0 ;//Number of minutes the timer started at 156int8_t items_on = 0 ;//Item spawn rate (-1 = disabled, 0 = very low, 1 = low, etc.) 157int8_t sd_score = 0 ;//How many points a player loses for SDing 158uint8_t timer_behav = 0 ;//Timer behavior (0 = off, 2 = count down, 3 = count up) 159uint8_t ui_chars = 0 ;//Number of UI slots for characters on the in-game HUD (usually 4) 160uint8_t game_mode = 0 ;//Game mode (0 = time, 1 = stock, 2 = coin, 3 = bonus) 161bool friendly_fire = false;//Whether friendly fire is enabled 162bool demo_mode = false;//Whether we are in the title screen or BTT dmeo 163bool classic_adv = false;//Whether we are in classic or adventure mode 164bool hrc_event = false;//Whether we are in HRC or some other event 165bool allstar_wait1 = false;//Whether we are in the all-star wait area 166bool allstar_game1 = false;//Same as above??? 167bool allstar_wait2 = false;//Whether we are in an all-star game 168bool allstar_game2 = false;//Same as above??? 169bool single_button = false;//Whether we are in single button mode 170bool pause_timer = false;//Whether the timer continues to count down when game is paused 171bool pause_nohud = false;//Whether the HUD is shown when game is paused 172bool pause_lras = false;//Whether LRAS is enabled when game is paused 173bool pause_off = false;//Whether pause is disabld 174bool pause_zretry = false;//Whether we can press Z to retry when game is paused 175bool pause_analog = false;//Whether the analog stick is shown when game is paused 176bool pause_score = false;//Whether the score is shown when game is paused 177uint8_t items1 = 0 ;//Item enabled / disabled bitfield 1 178uint8_t items2 = 0 ;//Item enabled / disabled bitfield 2 179uint8_t items3 = 0 ;//Item enabled / disabled bitfield 3 180uint8_t items4 = 0 ;//Item enabled / disabled bitfield 4 181uint8_t items5 = 0 ;//Item enabled / disabled bitfield 5 182bool sudden_death = false;//Whether bombs start dropping after 20 seconds 183uint32_t num_items = 0 ;//Number of distinct item IDs encountered during the game 184uint8_t language = 0 ;//Language option (0 = Japanese, 1 = English) 185SlippiPlayer player [8 ]= {};//Array of SlippiPlayers (1 main + follower for each port) 186SlippiItem item [MAX_ITEMS ]= {};//Array of SlippiItems (can track up to MAX_ITEMS per game) 187 188void setFrames (int32_t max_frames ); 189void cleanup (); 190std ::string replayAsJson (bool delta ); 191}; 192 193 194} 195 196#endif /* REPLAY_H_ */