using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using Imazen.WebP; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("ValheimEventClips.Encoder")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("ValheimEventClips.Encoder")] [assembly: AssemblyTitle("ValheimEventClips.Encoder")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } internal static class Program { public static int Main(string[] args) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Expected O, but got Unknown string text = null; try { if (args.Length == 2 && args[0] == "--verify") { AnimDecoder val = new AnimDecoder(File.ReadAllBytes(args[1]), false); try { int num = 0; int num2 = 0; while (val.HasMoreFrames()) { AnimFrame nextFrame = val.GetNextFrame(); num++; num2 += nextFrame.DurationMs; } Console.WriteLine("frames={0} width={1} height={2} decoder_duration_ms={3:F0}", num, val.Info.Width, val.Info.Height, num2); } finally { ((IDisposable)val)?.Dispose(); } return 0; } if (args.Length != 1) { throw new ArgumentException("Expected output WebP path"); } Stopwatch stopwatch = Stopwatch.StartNew(); using (BinaryReader binaryReader = new BinaryReader(Console.OpenStandardInput())) { if (binaryReader.ReadInt32() != 826492246) { throw new InvalidDataException("Bad VEC1 header"); } int num3 = binaryReader.ReadInt32(); int num4 = binaryReader.ReadInt32(); int num5 = binaryReader.ReadInt32(); int num6 = binaryReader.ReadInt32(); bool flag = binaryReader.ReadBoolean(); if (num3 < 16 || num3 > 1920 || num4 < 16 || num4 > 1080 || num5 < 1 || num5 > 1800 || num6 < 1 || num6 > 100) { throw new InvalidDataException("Invalid capture dimensions/count/quality"); } int num7 = checked(num3 * num4 * 4); if ((long)num7 * (long)num5 > 268435456) { throw new InvalidDataException("Clip exceeds encoder's 256 MiB raw-frame limit"); } byte[] array = new byte[num7]; WebPEncoderConfig val2 = new WebPEncoderConfig().SetQuality((float)num6).SetMethod(3).SetMultiThreaded(false); AnimEncoder val3 = new AnimEncoder(num3, num4, 0, 0u, false, false); try { int num8 = 0; int num9 = 0; Stopwatch stopwatch2 = Stopwatch.StartNew(); for (int i = 0; i < num5; i++) { int num10 = binaryReader.ReadInt32(); if (num10 < 1 || num10 > 60000 || (num8 += num10) > 60000) { throw new InvalidDataException("Invalid frame timing"); } int num11; for (int j = 0; j < num7; j += num11) { num11 = binaryReader.Read(array, j, num7 - j); if (num11 == 0) { throw new EndOfStreamException("Incomplete frame"); } } if (flag) { int num12 = num3 * 4; for (int k = 0; k < num4 / 2; k++) { for (int l = 0; l < num12; l++) { int num13 = k * num12 + l; int num14 = (num4 - k - 1) * num12 + l; byte b = array[num13]; array[num13] = array[num14]; array[num14] = b; } } } val3.AddFrame(array, num3 * 4, (WebPPixelFormat)1, num8 - num10, val2); num9 = num10; } string fullPath = Path.GetFullPath(args[0]); Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); text = fullPath + ".partial"; FieldInfo? field = typeof(AnimEncoder).GetField("_lastDuration", BindingFlags.Instance | BindingFlags.NonPublic); if (field == null) { throw new MissingFieldException("Pinned animation duration contract changed"); } field.SetValue(val3, num9); File.WriteAllBytes(text, val3.Assemble()); stopwatch2.Stop(); File.Move(text, fullPath); text = null; Console.WriteLine("frames={0} duration_ms={1} elapsed_ms={2} encode_ms={3} bytes={4} helper_peak_mib={5:F1}", num5, num8, stopwatch.ElapsedMilliseconds, stopwatch2.ElapsedMilliseconds, new FileInfo(fullPath).Length, (double)Process.GetCurrentProcess().PeakWorkingSet64 / 1048576.0); } finally { ((IDisposable)val3)?.Dispose(); } } return 0; } catch (Exception ex) { Console.Error.WriteLine(ex.GetType().Name + ": " + ex.Message); return 1; } finally { if (text != null) { try { File.Delete(text); } catch { } } } } }