diff --git a/Nodsoft.WowsReplaysUnpack.Console/Program.cs b/Nodsoft.WowsReplaysUnpack.Console/Program.cs index ef00174..d3dd6fd 100644 --- a/Nodsoft.WowsReplaysUnpack.Console/Program.cs +++ b/Nodsoft.WowsReplaysUnpack.Console/Program.cs @@ -50,12 +50,30 @@ // Console.WriteLine($"[{GetGroupString(msg)}] {msg.EntityId} : {msg.MessageContent}"); //} -Task[] tasks = { }; -for (int i = 0; i < 10; i++) +const int CYCLE = 20; +async Task syncTasks(bool sync) { - tasks.Append(Task.Run(() => replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay")))); + List unpackedReplays = new List(); + if (sync) + { + for (int i = 0; i < CYCLE; i++) + { + replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay")); + } + } + else + { + Parallel.ForEach(Enumerable.Range(0, CYCLE), (i) => + { + unpackedReplays.Add(replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay"))); + }); + } + return unpackedReplays.ToArray(); } -await Task.WhenAll(tasks); + +DateTime start = DateTime.Now; +await syncTasks(false); +Console.WriteLine(DateTime.Now - start); var goodReplay = replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("good.wowsreplay")); var alphaReplay = replayUnpacker.GetUnpacker().Unpack(_GetReplayFile("press_account_alpha.wowsreplay")); diff --git a/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs b/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs index d8f5ba6..da38623 100644 --- a/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs +++ b/Nodsoft.WowsReplaysUnpack/Services/ReplayUnpackerService.cs @@ -77,6 +77,7 @@ Seek to offset 4 in the replay file (skipping the magic number) byte[] signature = binaryReader.ReadBytes(4); int jsonBlockCount = binaryReader.ReadInt32(); + _semaphore.Release(); // Verify replay signature if (!signature.SequenceEqual(ReplaySignature)) { @@ -86,11 +87,13 @@ Seek to offset 4 in the replay file (skipping the magic number) // The first block is the arena info // Read it and create the unpacked replay model UnpackedReplay replay = _replayController.CreateUnpackedReplay(ReadJsonBlock(binaryReader)); + _semaphore.Wait(); ReadExtraJsonBlocks(replay, binaryReader, jsonBlockCount); MemoryStream decryptedStream = new(); Decrypt(binaryReader, decryptedStream); + _semaphore.Release(); // Initial stream and reader not used anymore binaryReader.Dispose(); @@ -101,6 +104,7 @@ Seek to offset 4 in the replay file (skipping the magic number) decryptedStream.Dispose(); + _semaphore.Wait(); foreach (NetworkPacketBase networkPacket in _replayDataParser.ParseNetworkPackets(replayDataStream, options)) { _replayController.HandleNetworkPacket(networkPacket, options);