@@ -30,7 +30,7 @@ using namespace PotatoAlert::ReplayParser;
30
30
namespace rp = PotatoAlert::ReplayParser;
31
31
using PotatoAlert::ReplayParser::ReplayResult;
32
32
33
- ReplayResult<Replay> Replay::FromFile (const fs::path& filePath, const fs ::path& scriptsPath )
33
+ ReplayResult<Replay> Replay::Read (const std::filesystem ::path& filePath )
34
34
{
35
35
PA_PROFILE_FUNCTION ();
36
36
@@ -165,13 +165,13 @@ ReplayResult<Replay> Replay::FromFile(const fs::path& filePath, const fs::path&
165
165
fileMapping.Close ();
166
166
file.Close ();
167
167
168
- const std::vector<Byte> decompressed = Zlib::Inflate (decrypted);
169
- if (decompressed .empty ())
168
+ replay. m_decompressed = Zlib::Inflate (decrypted);
169
+ if (replay. m_decompressed .empty ())
170
170
{
171
171
return PA_REPLAY_ERROR (" Failed to inflate decrypted replay data with zlib." );
172
172
}
173
173
174
- if (decompressed .size () != decompressedSize)
174
+ if (replay. m_decompressed .size () != decompressedSize)
175
175
{
176
176
return PA_REPLAY_ERROR (" Replay decompressed data != decompressedSize" );
177
177
}
@@ -180,28 +180,36 @@ ReplayResult<Replay> Replay::FromFile(const fs::path& filePath, const fs::path&
180
180
decrypted.clear ();
181
181
decrypted.shrink_to_fit ();
182
182
183
- PA_TRYA (replay.Specs , ParseScripts (scriptsPath));
183
+ return replay;
184
+ }
185
+
186
+ ReplayResult<void > Replay::ParsePackets (const std::filesystem::path& scriptsPath)
187
+ {
188
+ PA_TRYA (Specs, ParseScripts (scriptsPath));
184
189
185
- if (replay. Specs .empty ())
190
+ if (Specs.empty ())
186
191
{
187
192
return PA_REPLAY_ERROR (" Empty entity specs" );
188
193
}
189
194
190
- replay. m_packetParser .Specs = replay. Specs ;
195
+ m_packetParser.Specs = Specs;
191
196
192
- std::span out{ decompressed };
197
+ std::span< const Byte> out{ m_decompressed };
193
198
do {
194
- PA_TRY (packet, ParsePacket (out, replay. m_packetParser , replay. Meta .ClientVersionFromExe ));
195
- replay. Packets .emplace_back (std::move (packet));
199
+ PA_TRY (packet, ParsePacket (out, m_packetParser, Meta.ClientVersionFromExe ));
200
+ Packets.emplace_back (std::move (packet));
196
201
} while (!out.empty ());
197
202
198
- // sort the packets by game time
199
- // std::ranges::sort(replay.Packets, [](const PacketType& a, const PacketType& b)
200
- // {
201
- // const Packet& aPacket = std::visit([](const auto& x) -> const Packet& { return x; }, a);
202
- // const Packet& bPacket = std::visit([](const auto& x) -> const Packet& { return x; }, b);
203
- // return aPacket.Clock < bPacket.Clock;
204
- // });
203
+ // free memory of decompressed data
204
+ m_decompressed.clear ();
205
+ m_decompressed.shrink_to_fit ();
205
206
207
+ return {};
208
+ }
209
+
210
+ ReplayResult<Replay> Replay::FromFile (const fs::path& filePath, const fs::path& scriptsPath)
211
+ {
212
+ PA_TRY (replay, Read (filePath));
213
+ PA_TRYV (replay.ParsePackets (scriptsPath));
206
214
return replay;
207
215
}
0 commit comments