public static void Post_Update(ZSteamSocket __instance, float dt) { return; CompStats cs; if (!CompStatsMan.compStats.TryGetValue(__instance, out cs)) { cs = new CompStats(); CompStatsMan.compStats.Add(__instance, cs); } if (cs.timeElapsed >= 5f) { ZLog.Log(String.Concat(new[] { $"Data sent\n" + $"Uncompressed: {cs.dataSent}\n" + $"Deflate: {cs.dataSentCompressed} | Ratio {((cs.dataSentCompressed > 0 && cs.dataSent > 0) ? ((float)cs.dataSentCompressed / (float)cs.dataSent * 100f) : 0f)}\n", $"ZStd 3: {cs.dataSentZstd} | Ratio {((cs.dataSentZstd> 0 && cs.dataSent > 0) ? ((float)cs.dataSentZstd / (float)cs.dataSent * 100f) : 0f)}\n", $"ZStd 1: {cs.dataSentZstdSlow} | Ratio {((cs.dataSentZstdSlow> 0 && cs.dataSent > 0) ? ((float)cs.dataSentZstdSlow / (float)cs.dataSent * 100f) : 0f)} " //$"ZStd Dict: {cs.dataSentZstdStream} | Ratio {((cs.dataSentZstdStream> 0 && cs.dataSent > 0) ? ((float)cs.dataSentZstdStream / (float)cs.dataSent * 100f) : 0f)} " })); cs.dataSent = 0L; cs.dataSentCompressed = 0L; cs.dataSentZstd = 0L; cs.dataSentZstdStream = 0L; cs.dataSentZstdSlow = 0L; cs.timeElapsed = 0f; } cs.timeElapsed += dt; }
public static byte[] ProcessForCompression(byte[] data, ZSteamSocket socket) { return(compressor.Wrap(data)); byte[] dataClone = data.ToArray(); //buffer.Add(dataClone); /*using (var stream = new FileStream("C:\\Users\\jayess\\code\\ValheimCompressionDictData.dat", FileMode.Append)) * { * stream.Write(data, 0, data.Length); * }*/ CompStats cs; if (!CompStatsMan.compStats.TryGetValue(socket, out cs)) { cs = new CompStats(); CompStatsMan.compStats.Add(socket, cs); } cs.dataSent += dataClone.Length; MemoryStream output = new MemoryStream(); using (DeflateStream dstream = new DeflateStream(output, CompressionLevel.Optimal)) { dstream.Write(dataClone.ToArray(), 0, dataClone.Length); } cs.dataSentCompressed += output.ToArray().Length; cs.dataSentZstd += CompressionMan.compressor.Wrap(data.ToArray()).Length; //cs.dataSentZstdSlow += CompressionMan.slowCompressor.Wrap(data.ToArray()).Length; //using (var compressor = new Compressor(new CompressionOptions(File.ReadAllBytes("C:\\Users\\jayess\\code\\ValheimCompressionDict.dat")))) //{ // cs.dataSentZstdStream += compressor.Wrap(data.ToArray()).Length; //} }