fork/slippc

git clone https://git.julia.blue/fork/slippc

Patrick Crainadded ability to parse and analyze partially corrupt files; added punish stock info to analysis json output7fcd71c

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