Skip to content

Commit 8860305

Browse files
committed
split replayparser replay analysis
1 parent 2300662 commit 8860305

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

ReplayParser/include/ReplayParser/ReplayParser.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ class PA_API Replay
357357
std::vector<PacketType> Packets;
358358
std::vector<EntitySpec> Specs;
359359

360+
static ReplayResult<Replay> Read(const std::filesystem::path& filePath);
361+
ReplayResult<void> ParsePackets(const std::filesystem::path& scriptsPath);
362+
360363
static ReplayResult<Replay> FromFile(const std::filesystem::path& filePath, const std::filesystem::path& scriptsPath);
361364
[[nodiscard]] ReplayResult<ReplaySummary> Analyze() const;
362365

@@ -368,6 +371,7 @@ class PA_API Replay
368371

369372
private:
370373
PacketParser m_packetParser;
374+
std::vector<Byte> m_decompressed;
371375
};
372376

373377
} // namespace PotatoAlert::ReplayParser

ReplayParser/src/ReplayParser.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using namespace PotatoAlert::ReplayParser;
3030
namespace rp = PotatoAlert::ReplayParser;
3131
using PotatoAlert::ReplayParser::ReplayResult;
3232

33-
ReplayResult<Replay> Replay::FromFile(const fs::path& filePath, const fs::path& scriptsPath)
33+
ReplayResult<Replay> Replay::Read(const std::filesystem::path& filePath)
3434
{
3535
PA_PROFILE_FUNCTION();
3636

@@ -165,13 +165,13 @@ ReplayResult<Replay> Replay::FromFile(const fs::path& filePath, const fs::path&
165165
fileMapping.Close();
166166
file.Close();
167167

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())
170170
{
171171
return PA_REPLAY_ERROR("Failed to inflate decrypted replay data with zlib.");
172172
}
173173

174-
if (decompressed.size() != decompressedSize)
174+
if (replay.m_decompressed.size() != decompressedSize)
175175
{
176176
return PA_REPLAY_ERROR("Replay decompressed data != decompressedSize");
177177
}
@@ -180,28 +180,36 @@ ReplayResult<Replay> Replay::FromFile(const fs::path& filePath, const fs::path&
180180
decrypted.clear();
181181
decrypted.shrink_to_fit();
182182

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));
184189

185-
if (replay.Specs.empty())
190+
if (Specs.empty())
186191
{
187192
return PA_REPLAY_ERROR("Empty entity specs");
188193
}
189194

190-
replay.m_packetParser.Specs = replay.Specs;
195+
m_packetParser.Specs = Specs;
191196

192-
std::span out{ decompressed };
197+
std::span<const Byte> out{ m_decompressed };
193198
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));
196201
} while (!out.empty());
197202

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();
205206

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));
206214
return replay;
207215
}

0 commit comments

Comments
 (0)