fork/slippc

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

Patrick CrainUpdated parser to decode tags properly and record CPU levels; updated parser version to 0.2.0d3d6f97

0.4.0
3.6 KiB118 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
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
27  bool     alive         = false;  //For checking if this frame was actually set
28
29  //Pre-frame stuff
30  int32_t  frame         = 0;
31  uint8_t  player        = 0;
32  bool     follower      = false;
33  uint32_t seed          = 0;
34  uint16_t action_pre    = 0;
35  float    pos_x_pre     = 0.0f;
36  float    pos_y_pre     = 0.0f;
37  float    face_dir_pre  = 0.0f;
38  float    joy_x         = 0.0f;
39  float    joy_y         = 0.0f;
40  float    c_x           = 0.0f;
41  float    c_y           = 0.0f;
42  float    trigger       = 0.0f;
43  uint32_t buttons       = 0;
44  float    phys_l        = 0.0f;
45  float    phys_r        = 0.0f;
46  uint8_t  ucf_x         = 0;
47  float    percent_pre   = 0.0f;
48
49  //Post-frame stuff
50  uint8_t  char_id       = 0;
51  uint16_t action_post   = 0;
52  float    pos_x_post    = 0.0f;
53  float    pos_y_post    = 0.0f;
54  float    face_dir_post = 0.0f;
55  float    percent_post  = 0.0f;
56  float    shield        = 0.0f;
57  uint8_t  hit_with      = 0;
58  uint8_t  combo         = 0;
59  uint8_t  hurt_by       = 0;
60  uint8_t  stocks        = 0;
61  float    action_fc     = 0.0f;
62  uint8_t  flags_1       = 0;
63  uint8_t  flags_2       = 0;
64  uint8_t  flags_3       = 0;
65  uint8_t  flags_4       = 0;
66  uint8_t  flags_5       = 0;
67  float    hitstun       = 0.0f;
68  bool     airborne      = false;
69  uint16_t ground_id     = 0;
70  uint8_t  jumps         = 0;
71  uint8_t  l_cancel      = 0;
72};
73
74struct SlippiPlayer {
75  uint8_t      ext_char_id  = 0;
76  uint8_t      player_type  = 3;  //empty
77  uint8_t      start_stocks = 0;
78  uint8_t      color        = 0;
79  uint8_t      team_id      = 0;
80  uint8_t      cpu_level    = 0;
81  uint32_t     dash_back    = 0;
82  uint32_t     shield_drop  = 0;
83  std::string  tag          = "";
84  std::string  tag_css      = "";
85  SlippiFrame* frame        =  nullptr;
86};
87
88struct SlippiReplay {
89  std::string     slippi_version = "";
90  std::string     parser_version = "";
91  std::string     game_start_raw = "";
92  std::string     metadata       = "";
93  std::string     played_on      = "";
94  std::string     start_time     = "";
95  bool            teams          = false;
96  uint16_t        stage          = 0;
97  uint32_t        seed           = 0;
98  bool            pal            = false;
99  bool            frozen         = false;
100  uint8_t         end_type       = 0;
101  int8_t          lras           = 0;
102  int32_t         first_frame    = LOAD_FRAME;
103  int32_t         last_frame     = 0;
104  uint32_t        frame_count    = 0;
105  uint8_t         timer          = 0;
106  int8_t          items          = 0;
107  bool            sudden_death   = false;
108  SlippiPlayer    player[8];
109
110  void setFrames(int32_t max_frames);
111  void cleanup();
112  std::string replayAsJson(bool delta);
113};
114
115
116}
117
118#endif /* REPLAY_H_ */