private EulerContainer GetEulerContainer(string path) { using (var english = File.Open(path, FileMode.Open)) { return(CompressionUtils.Decompress <EulerContainer>(english)); } }
public Block GetBlockByHash(Hash hash) { if (hash == Hash.Null) { return(null); } var blockMap = new StorageMap(BlockHashMapTag, this.Storage); if (blockMap.ContainsKey <Hash>(hash)) { var bytes = blockMap.Get <Hash, byte[]>(hash); bytes = CompressionUtils.Decompress(bytes); var block = Block.Unserialize(bytes); if (block.Hash != hash) { throw new ChainException("data corruption on block: " + hash); } return(block); } return(null); }
protected override void WriteDataToStream(Stream stream, SharedExtractParams extractParams, bool decompress) { var reader = extractParams.Reader; uint len = this.Compressed ? this.Size : this.RealSize; reader.BaseStream.Seek((long)this.Offset, SeekOrigin.Begin); // Reset at start since value might still be in used for a bit after this.BytesWritten = 0; if (!decompress || !this.Compressed) { StreamUtils.WriteSectionToStream(reader.BaseStream, len, stream, bytesWritten => this.BytesWritten = bytesWritten); } else { CompressionUtils.Decompress(reader.BaseStream, len, stream, bytesWritten => this.BytesWritten = bytesWritten, extractParams); } }
private void WriteChunks(Stream stream, SharedExtractParams extractParams, bool decompress) { var reader = extractParams.Reader; for (int i = 0; i < (numChunks - 1); i++) { reader.BaseStream.Seek((long)this.Chunks[i].offset, SeekOrigin.Begin); if (!decompress) { ulong prev = this.BytesWritten; StreamUtils.WriteSectionToStream(reader.BaseStream, Math.Max(Chunks[i].packSz, Chunks[i].fullSz), // Lazy hack, only one should be set when not compressed stream, bytesWritten => this.BytesWritten = prev + bytesWritten); } else { ulong prev = this.BytesWritten; CompressionUtils.Decompress(reader.BaseStream, this.Chunks[i].packSz, stream, bytesWritten => this.BytesWritten = prev + bytesWritten, extractParams); } } }
private static EulerContainer GetEulerContainer(string path) { using (var file = File.Open(path, FileMode.Open)) { return(CompressionUtils.Decompress <EulerContainer>(file)); } }
protected override void WriteDataToStream(Stream stream, SharedExtractParams extractParams, bool decompress) { var reader = extractParams.Reader; reader.BaseStream.Seek((long)this.Offset, SeekOrigin.Begin); // Reset at start since value might still be in used for a bit after this.BytesWritten = 0; if (!decompress) { StreamUtils.WriteSectionToStream(reader.BaseStream, Math.Max(this.Size, this.RealSize), // Lazy hack, only one should be set when not compressed stream, bytesWritten => this.BytesWritten = bytesWritten); } else { this.WriteHeader(stream); try { CompressionUtils.Decompress(reader.BaseStream, this.Size, stream, bytesWritten => this.BytesWritten = bytesWritten, extractParams); } catch (Exception ex) { throw new Exception($"Couldn't decompress zlib texture data. Size: {this.Size}, RealSize: {this.RealSize}", ex); } } this.WriteChunks(stream, extractParams, decompress); }
public override object ConvertFromStorageType(object value) { if (value != null) { byte[] decompressedValue = CompressionUtils.Decompress(new MemoryStream((byte[])value)).ToArray(); if (decompressedValue != null) { return(System.Text.Encoding.UTF8.GetString(decompressedValue)); } } return(null); }
public void CompressTest() { var testClass = new TestClass { IntProperty = 100, StringProperty = "Test" }; var compressed = CompressionUtils.Compress(testClass); var obj = CompressionUtils.Decompress <TestClass>(compressed); Assert.AreEqual(testClass.IntProperty, obj.IntProperty); Assert.AreEqual(testClass.StringProperty, obj.StringProperty); }
public override object ConvertFromStorageType(object value) { if (value != null && !(value is byte[])) { throw new ArgumentException(); } if (value == null || ((byte[])value).Length == 0) { return(value); } return(new ImageConverter().ConvertFrom( CompressionUtils.Decompress(new MemoryStream((byte[])value)).ToArray())); }
private List <Security> LoadSecuritiesFromCache() { try { using (StreamReader reader = new StreamReader(SecuritiesCachePath)) { string data = CompressionUtils.Decompress(reader.ReadToEnd()); List <Security> list = JsonConvert.DeserializeObject <List <Security> >(data); return(list != null && list.Count != 0 ? list : LoadSecuritiesFromQuik()); } } catch (Exception e) { SendLogMessage(e.ToString(), LogMessageType.Error); return(LoadSecuritiesFromQuik()); } }
public void CreateCompressedBufferedMessageSet() { string testMessage = "TestMessage"; Message message = new Message(Encoding.UTF8.GetBytes(testMessage)); BufferedMessageSet bms = new BufferedMessageSet(CompressionCodecs.DefaultCompressionCodec, new List <Message>() { message }); foreach (var bmsMessage in bms.Messages) { Assert.AreNotEqual(bmsMessage.Payload, message.Payload); var decompressedBms = CompressionUtils.Decompress(bmsMessage); foreach (var decompressedMessage in decompressedBms.Messages) { Assert.AreEqual(message.ToString(), decompressedMessage.ToString()); } } }
public void CompressAndDecompressMessageUsingSnappyCompressionCodec() { var messageBytes = new byte[] { 1, 2, 3, 4, 5 }; var message = new Message(messageBytes, CompressionCodecs.SnappyCompressionCodec); Message compressedMsg = CompressionUtils.Compress(new List <Message>() { message }, CompressionCodecs.SnappyCompressionCodec, 0); var decompressed = CompressionUtils.Decompress(compressedMsg, 0); int i = 0; foreach (var decompressedMessage in decompressed.Messages) { i++; message.Payload.SequenceEqual(decompressedMessage.Payload).Should().BeTrue(); } Assert.AreEqual(1, i); }
public void ActualDataSerializationTest() { var language = new Language { LocalizationName = "RU-ru", FontFamilyNames = new List <string>() { "SomeFont" }, Chars = new List <Symbol> { new Symbol { Chr = 'Б', Codes = new HashSet <SymbolCode>( new[] { new SymbolCode(10, new EulerMonomap2D(EulerValue)) }) } } }; var eulerContainer = new EulerContainer() { Languages = new List <Language>() { language }, SpecialChars = new List <Symbol>() { new Symbol() { Chr = 'Ж' } } }; using (var compressed = CompressionUtils.Compress(eulerContainer)) { CompressionUtils.Decompress <EulerContainer>(compressed); } }
public void CompressAndDecompressMessageUsingDefaultCompressionCodec() { byte[] messageBytes = new byte[] { 1, 2, 3, 4, 5 }; Message message = new Message(messageBytes, CompressionCodecs.DefaultCompressionCodec); Message compressedMsg = CompressionUtils.Compress(new List <Message>() { message }); var decompressed = CompressionUtils.Decompress(compressedMsg); int i = 0; foreach (var decompressedMessage in decompressed.Messages) { i++; Assert.AreEqual(message.Payload, decompressedMessage.Payload); } Assert.AreEqual(1, i); }
protected override void WriteDataToStream(Stream stream, SharedExtractParams extractParams, bool decompress) { var bw = new BinaryWriter(stream); var reader = extractParams.Reader; // Reset at start since value might still be in used for a bit after this.BytesWritten = 0; if (decompress && GenerateTextureHeader) { this.WriteHeader(bw); } for (int i = 0; i < numChunks; i++) { bool isCompressed = this.Chunks[i].packSz != 0; ulong prev = this.BytesWritten; reader.BaseStream.Seek((long)this.Chunks[i].offset, SeekOrigin.Begin); if (!decompress || !isCompressed) { StreamUtils.WriteSectionToStream(reader.BaseStream, Chunks[i].fullSz, stream, bytesWritten => this.BytesWritten = prev + bytesWritten); } else { CompressionUtils.Decompress(reader.BaseStream, this.Chunks[i].packSz, stream, bytesWritten => this.BytesWritten = prev + bytesWritten, extractParams); } } if (dataSizePosition > -1) { bw.WriteAt(dataSizePosition, (uint)bw.BaseStream.Length - 164); } }
public Transaction GetTransactionByHash(Hash hash) { var txMap = new StorageMap(TransactionHashMapTag, this.Storage); if (txMap.ContainsKey <Hash>(hash)) { var bytes = txMap.Get <Hash, byte[]>(hash); bytes = CompressionUtils.Decompress(bytes); var tx = Transaction.Unserialize(bytes); if (tx.Hash != hash) { throw new ChainException("data corruption on transaction: " + hash); } return(tx); } return(null); }
public void CompressAndDecompress3MessagesUsingDefaultCompressionCodec() { byte[] messageBytes = new byte[] { 1, 2, 3, 4, 5 }; Message message1 = new Message(messageBytes, CompressionCodecs.DefaultCompressionCodec); Message message2 = new Message(messageBytes, CompressionCodecs.DefaultCompressionCodec); Message message3 = new Message(messageBytes, CompressionCodecs.DefaultCompressionCodec); Message compressedMsg = CompressionUtils.Compress(new List <Message>() { message1, message2, message3 }, 0); var decompressed = CompressionUtils.Decompress(compressedMsg, 0); int i = 0; foreach (var decompressedMessage in decompressed.Messages) { i++; message1.Payload.SequenceEqual(decompressedMessage.Payload).Should().BeTrue(); } Assert.AreEqual(3, i); }
protected override void Client_PacketReceived(Packet packet) { base.Client_PacketReceived(packet); if (packet.Type == PacketType.PlaySong) { PlaySong playSong = packet.SpecificPacket as PlaySong; var desiredLevel = SongUtils.masterLevelList.First(x => x.levelID == playSong.GameplayParameters.Beatmap.LevelId); var desiredCharacteristic = desiredLevel.previewDifficultyBeatmapSets.FirstOrDefault(x => x.beatmapCharacteristic.serializedName == playSong.GameplayParameters.Beatmap.Characteristic.SerializedName).beatmapCharacteristic ?? desiredLevel.previewDifficultyBeatmapSets.First().beatmapCharacteristic; var desiredDifficulty = (BeatmapDifficulty)playSong.GameplayParameters.Beatmap.Difficulty; var playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().First().playerData; var playerSettings = playerData.playerSpecificSettings; //Override defaults if we have forced options enabled if (playSong.GameplayParameters.PlayerSettings.Options != PlayerOptions.None) { playerSettings = new PlayerSpecificSettings( playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.StaticLights), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.LeftHanded), playSong.GameplayParameters.PlayerSettings.PlayerHeight, playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AutoPlayerHeight), playSong.GameplayParameters.PlayerSettings.SfxVolume, playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.ReduceDebris), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.NoHud), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.NoFailEffects), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AdvancedHud), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AutoRestart), playSong.GameplayParameters.PlayerSettings.SaberTrailIntensity, playSong.GameplayParameters.PlayerSettings.NoteJumpStartBeatOffset, playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.HideNoteSpawnEffect), playSong.GameplayParameters.PlayerSettings.Options.HasFlag(PlayerOptions.AdaptiveSfx) ); } var songSpeed = GameplayModifiers.SongSpeed.Normal; if (playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.SlowSong)) { songSpeed = GameplayModifiers.SongSpeed.Slower; } if (playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.FastSong)) { songSpeed = GameplayModifiers.SongSpeed.Faster; } var gameplayModifiers = new GameplayModifiers( playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.DemoNoFail), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.DemoNoObstacles), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.BatteryEnergy) ? GameplayModifiers.EnergyType.Battery : GameplayModifiers.EnergyType.Bar, playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoFail), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.InstaFail), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.FailOnClash), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoObstacles) ? GameplayModifiers.EnabledObstacleType.NoObstacles : GameplayModifiers.EnabledObstacleType.All, playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoBombs), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.FastNotes), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.StrictAngles), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.DisappearingArrows), songSpeed, playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.NoArrows), playSong.GameplayParameters.GameplayModifiers.Options.HasFlag(GameOptions.GhostNotes) ); var colorScheme = playerData.colorSchemesSettings.overrideDefaultColors ? playerData.colorSchemesSettings.GetSelectedColorScheme() : null; //Disable score submission if nofail is on. This is specifically for Hidden Sabers, though it may stay longer if (playSong.DisableScoresaberSubmission) { BS_Utils.Gameplay.ScoreSubmission.DisableSubmission(SharedConstructs.Name); } if (playSong.ShowNormalNotesOnStream) { var customNotes = IPA.Loader.PluginManager.GetPluginFromId("CustomNotes"); if (customNotes != null) { EnableHMDOnly(); } } PlaySong?.Invoke(desiredLevel, desiredCharacteristic, desiredDifficulty, gameplayModifiers, playerSettings, playerData.overrideEnvironmentSettings, colorScheme, playSong.FloatingScoreboard, playSong.StreamSync, playSong.DisablePause, playSong.DisableFail); } else if (packet.Type == PacketType.Command) { Command command = packet.SpecificPacket as Command; if (command.CommandType == Command.CommandTypes.ReturnToMenu) { if (SyncHandler.Instance != null) { ScreenOverlay.Instance.Clear(); } if ((Self as Player).PlayState == Player.PlayStates.InGame) { PlayerUtils.ReturnToMenu(); } } else if (command.CommandType == Command.CommandTypes.ScreenOverlay_ShowPng) { ScreenOverlay.Instance.ShowPng(); } else if (command.CommandType == Command.CommandTypes.DelayTest_Finish) { UnityMainThreadDispatcher.Instance().Enqueue(() => { ScreenOverlay.Instance.Clear(); SyncHandler.Instance.Resume(); SyncHandler.Destroy(); }); } } else if (packet.Type == PacketType.LoadSong) { LoadSong loadSong = packet.SpecificPacket as LoadSong; Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { //Send updated download status (Self as Player).DownloadState = Player.DownloadStates.Downloaded; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); //Notify any listeners of the client that a song has been loaded LoadedSong?.Invoke(loadedLevel); }; if (OstHelper.IsOst(loadSong.LevelId)) { SongLoaded?.Invoke(SongUtils.masterLevelList.First(x => x.levelID == loadSong.LevelId) as BeatmapLevelSO); } else { if (SongUtils.masterLevelList.Any(x => x.levelID == loadSong.LevelId)) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { Action <string, bool> loadSongAction = (hash, succeeded) => { if (succeeded) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { (Self as Player).DownloadState = Player.DownloadStates.DownloadError; var playerUpdated = new Event(); playerUpdated.Type = Event.EventType.PlayerUpdated; playerUpdated.ChangedObject = Self; Send(new Packet(playerUpdated)); } }; (Self as Player).DownloadState = Player.DownloadStates.Downloading; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); SongDownloader.DownloadSong(loadSong.LevelId, songDownloaded: loadSongAction, downloadProgressChanged: (hash, progress) => Logger.Debug($"DOWNLOAD PROGRESS ({hash}): {progress}"), customHostUrl: loadSong.CustomHostUrl); } } } else if (packet.Type == PacketType.File) { File file = packet.SpecificPacket as File; if (file.Intent == File.Intentions.SetPngToShowWhenTriggered) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); } else if (file.Intent == File.Intentions.ShowPngImmediately) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); ScreenOverlay.Instance.ShowPng(); } Send(packet.From, new Packet(new Acknowledgement() { PacketId = packet.Id, Type = Acknowledgement.AcknowledgementType.FileDownloaded })); } }
protected override void Client_PacketRecieved(Packet packet) { base.Client_PacketRecieved(packet); if (packet.Type == PacketType.PlaySong) { PlaySong playSong = packet.SpecificPacket as PlaySong; var desiredLevel = SongUtils.masterLevelList.First(x => x.levelID == playSong.Beatmap.LevelId); var desiredCharacteristic = desiredLevel.previewDifficultyBeatmapSets.FirstOrDefault(x => x.beatmapCharacteristic.serializedName == playSong.Beatmap.Characteristic.SerializedName).beatmapCharacteristic ?? desiredLevel.previewDifficultyBeatmapSets.First().beatmapCharacteristic; var desiredDifficulty = (BeatmapDifficulty)playSong.Beatmap.Difficulty; var playerData = Resources.FindObjectsOfTypeAll <PlayerDataModel>().First().playerData; var playerSettings = playerData.playerSpecificSettings; //Override defaults if we have forced options enabled if (playSong.PlayerSettings.Options != PlayerOptions.None) { playerSettings = new PlayerSpecificSettings(); playerSettings.leftHanded = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.LeftHanded); playerSettings.staticLights = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.StaticLights); playerSettings.noTextsAndHuds = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.NoHud); playerSettings.advancedHud = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.AdvancedHud); playerSettings.reduceDebris = playSong.PlayerSettings.Options.HasFlag(PlayerOptions.ReduceDebris); } var gameplayModifiers = new GameplayModifiers(); gameplayModifiers.batteryEnergy = playSong.GameplayModifiers.Options.HasFlag(GameOptions.BatteryEnergy); gameplayModifiers.disappearingArrows = playSong.GameplayModifiers.Options.HasFlag(GameOptions.DisappearingArrows); gameplayModifiers.failOnSaberClash = playSong.GameplayModifiers.Options.HasFlag(GameOptions.FailOnClash); gameplayModifiers.fastNotes = playSong.GameplayModifiers.Options.HasFlag(GameOptions.FastNotes); gameplayModifiers.ghostNotes = playSong.GameplayModifiers.Options.HasFlag(GameOptions.GhostNotes); gameplayModifiers.instaFail = playSong.GameplayModifiers.Options.HasFlag(GameOptions.InstaFail); gameplayModifiers.noBombs = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoBombs); gameplayModifiers.noFail = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoFail); gameplayModifiers.noObstacles = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoObstacles); gameplayModifiers.noArrows = playSong.GameplayModifiers.Options.HasFlag(GameOptions.NoArrows); if (playSong.GameplayModifiers.Options.HasFlag(GameOptions.SlowSong)) { gameplayModifiers.songSpeed = GameplayModifiers.SongSpeed.Slower; } if (playSong.GameplayModifiers.Options.HasFlag(GameOptions.FastSong)) { gameplayModifiers.songSpeed = GameplayModifiers.SongSpeed.Faster; } var colorScheme = playerData.colorSchemesSettings.overrideDefaultColors ? playerData.colorSchemesSettings.GetSelectedColorScheme() : null; PlaySong?.Invoke(desiredLevel, desiredCharacteristic, desiredDifficulty, gameplayModifiers, playerSettings, playerData.overrideEnvironmentSettings, colorScheme, playSong.FloatingScoreboard, playSong.StreamSync, playSong.DisablePause, playSong.DisableFail); } else if (packet.Type == PacketType.Command) { Command command = packet.SpecificPacket as Command; if (command.CommandType == Command.CommandTypes.ReturnToMenu) { if (SyncHandler.Instance != null) { ScreenOverlay.Instance.Clear(); } if ((Self as Player).PlayState == Player.PlayStates.InGame) { PlayerUtils.ReturnToMenu(); } } else if (command.CommandType == Command.CommandTypes.ScreenOverlay_ShowPng) { ScreenOverlay.Instance.ShowPng(); } else if (command.CommandType == Command.CommandTypes.DelayTest_Finish) { UnityMainThreadDispatcher.Instance().Enqueue(() => { ScreenOverlay.Instance.Clear(); SyncHandler.Instance.Resume(); SyncHandler.Destroy(); }); } } else if (packet.Type == PacketType.LoadSong) { LoadSong loadSong = packet.SpecificPacket as LoadSong; Action <IBeatmapLevel> SongLoaded = (loadedLevel) => { //Send updated download status (Self as Player).DownloadState = Player.DownloadStates.Downloaded; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); //Notify any listeners of the client that a song has been loaded LoadedSong?.Invoke(loadedLevel); Logger.Debug($"SENT DOWNLOADED SIGNAL {(playerUpdate.ChangedObject as Player).DownloadState}"); }; if (OstHelper.IsOst(loadSong.LevelId)) { SongLoaded?.Invoke(SongUtils.masterLevelList.First(x => x.levelID == loadSong.LevelId) as BeatmapLevelSO); } else { if (SongUtils.masterLevelList.Any(x => x.levelID == loadSong.LevelId)) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { Action <bool> loadSongAction = (succeeded) => { if (succeeded) { SongUtils.LoadSong(loadSong.LevelId, SongLoaded); } else { (Self as Player).DownloadState = Player.DownloadStates.DownloadError; var playerUpdated = new Event(); playerUpdated.Type = Event.EventType.PlayerUpdated; playerUpdated.ChangedObject = Self; Send(new Packet(playerUpdated)); Logger.Debug($"SENT DOWNLOADED SIGNAL {(playerUpdated.ChangedObject as Player).DownloadState}"); } }; (Self as Player).DownloadState = Player.DownloadStates.Downloading; var playerUpdate = new Event(); playerUpdate.Type = Event.EventType.PlayerUpdated; playerUpdate.ChangedObject = Self; Send(new Packet(playerUpdate)); Logger.Debug($"SENT DOWNLOAD SIGNAL {(playerUpdate.ChangedObject as Player).DownloadState}"); SongDownloader.DownloadSong(loadSong.LevelId, songDownloaded: loadSongAction, downloadProgressChanged: (progress) => Logger.Debug($"DOWNLOAD PROGRESS: {progress}")); } } } else if (packet.Type == PacketType.File) { File file = packet.SpecificPacket as File; if (file.Intention == File.Intentions.SetPngToShowWhenTriggered) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); } else if (file.Intention == File.Intentions.ShowPngImmediately) { var pngBytes = file.Compressed ? CompressionUtils.Decompress(file.Data) : file.Data; ScreenOverlay.Instance.SetPngBytes(pngBytes); ScreenOverlay.Instance.ShowPng(); } Send(packet.From, new Packet(new Acknowledgement() { PacketId = packet.Id, Type = Acknowledgement.AcknowledgementType.FileDownloaded })); } }
protected override void WriteDataToStream(Stream stream, SharedExtractParams extractParams, bool decompress) { var reader = extractParams.Reader; decompress = decompress && this.Compressed; reader.BaseStream.Position = (long)Offset; // Reset at start since value might still be in used for a bit after this.BytesWritten = 0; if (this.Archive.Type == ArchiveTypes.BSA_SE) { // Separate Skyrim Special Edition extraction ulong filesz = this.Size & 0x3fffffff; if (this.Archive.ContainsFileNameBlobs) { int len = reader.ReadByte(); filesz -= (ulong)len + 1; reader.BaseStream.Seek((long)this.Offset + 1 + len, SeekOrigin.Begin); } uint filesize = (uint)filesz; if (this.Size > 0 && this.Compressed) { filesize = reader.ReadUInt32(); filesz -= 4; } if (!decompress) { StreamUtils.WriteSectionToStream(reader.BaseStream, filesz, stream, bytesWritten => this.BytesWritten = bytesWritten); } else { CompressionUtils.DecompressLZ4(reader.BaseStream, (uint)filesz, stream, bytesWritten => this.BytesWritten = bytesWritten); } } else { // Skip ahead if (this.Archive.ContainsFileNameBlobs) { reader.BaseStream.Position += reader.ReadByte() + 1; } if (!decompress) { StreamUtils.WriteSectionToStream(reader.BaseStream, this.Size, stream, bytesWritten => this.BytesWritten = bytesWritten); } else { if (this.Compressed) { reader.ReadUInt32(); // Skip } CompressionUtils.Decompress(reader.BaseStream, this.Size - 4, stream, bytesWriten => this.BytesWritten = bytesWriten, extractParams); } } }