fork/slippc

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

Patrick CrainAdded documentation to replay.h; updated readme and changelog; minor tweaks to output of parser and analyzer, including original input filename; bumped parser and analyzer versions to 0.7.07d49c2f

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