Skip to content

Commit

Permalink
Fix demo repair
Browse files Browse the repository at this point in the history
  • Loading branch information
NeKzor committed Apr 1, 2024
1 parent 8df33f0 commit b06734f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/server/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,22 @@ export const repairDemo = (buffer: Uint8Array): Uint8Array => {
.setOptions({ packets: true })
.parse(buffer);

const isSvcSetPause = (packet: NetMessages.NetMessage) => packet instanceof NetMessages.SvcSetPause;

let paused = false;

demo.messages = demo.messages!.filter((message) => {
if (message instanceof Messages.Packet) {
const pausePacket = message.findPacket<NetMessages.SvcSetPause>(isSvcSetPause);
if (pausePacket) {
paused = pausePacket.paused!;
let pausePacketCount = 0;

for (const packet of message.packets!) {
if (packet instanceof NetMessages.SvcSetPause) {
paused = packet.paused!;
pausePacketCount += 1;
}
}

// Drop the whole message during a pause but only if there aren't any other packets.
const dropMessage = paused && (!pausePacketCount || message.packets!.length <= pausePacketCount);
return !dropMessage;
}

return !paused;
Expand Down

0 comments on commit b06734f

Please sign in to comment.