Decompiled source of Video Converter v1.1.2

BepInEx/plugins/Video Converter.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using On;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Video Converter")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0d24d8e2b4b6bd136446cd9eebcf3429aac85c9a")]
[assembly: AssemblyProduct("Video Converter")]
[assembly: AssemblyTitle("Video Converter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Video_Converter
{
	public static class Converter
	{
		public static void Init()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			ManualLogSource? logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)"Converter initialized");
			}
			CameraRecording.SaveToDesktop += new hook_SaveToDesktop(SaveToDesktop);
		}

		private static bool SaveToDesktop(orig_SaveToDesktop orig, CameraRecording self, out string videoFileName)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			ManualLogSource? logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)"Beginning conversion process");
			}
			bool result = orig.Invoke(self, ref videoFileName);
			string ffmpegPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content Warning_Data\\StreamingAssets\\FFmpegOut\\Windows\\ffmpeg.exe");
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
			string inputFilePath;
			if (Chainloader.PluginInfos.ContainsKey("com.ramune.CustomVideoSaveLocation"))
			{
				string text = Path.Combine(Paths.ConfigPath, "com.ramune.CustomVideoSaveLocation.cfg");
				ConfigFile val = new ConfigFile(text, true);
				ConfigDefinition val2 = new ConfigDefinition("VideoSaveFolderPath", "Path to the folder to save your videos to");
				string value = val.Bind<string>(val2, "Desktop", (ConfigDescription)null).Value;
				if (value != "Desktop" && value != null)
				{
					inputFilePath = Path.Combine(value, videoFileName ?? "");
					ManualLogSource? logger2 = Plugin.Logger;
					if (logger2 != null)
					{
						logger2.LogInfo((object)"Custom path detected");
					}
				}
				else
				{
					inputFilePath = Path.Combine(folderPath, videoFileName);
					ManualLogSource? logger3 = Plugin.Logger;
					if (logger3 != null)
					{
						logger3.LogInfo((object)"Custom path not detected, using desktop");
					}
				}
			}
			else
			{
				inputFilePath = Path.Combine(folderPath, videoFileName);
			}
			string outputFilePath = Path.ChangeExtension(inputFilePath, ".mp4");
			string arguments = "-i \"" + inputFilePath + "\" \"" + outputFilePath + "\"";
			string videoFileNameString = videoFileName;
			if (!File.Exists(outputFilePath))
			{
				Thread thread = new Thread((ThreadStart)delegate
				{
					ConvertVideo(outputFilePath, 30, ffmpegPath, arguments, inputFilePath, videoFileNameString);
				});
				thread.Start();
			}
			else
			{
				File.Delete(inputFilePath);
			}
			return result;
		}

		private static void ConvertVideo(string outputFilePath, int timeoutInSeconds, string ffmpegPath, string arguments, string inputFilePath, string videoFileName)
		{
			ManualLogSource? logger = Plugin.Logger;
			if (logger != null)
			{
				logger.LogInfo((object)"Beginning coroutine");
			}
			int num = 0;
			ProcessStartInfo startInfo = new ProcessStartInfo
			{
				FileName = ffmpegPath,
				Arguments = arguments,
				UseShellExecute = false,
				RedirectStandardOutput = true,
				CreateNoWindow = true
			};
			using (Process process = new Process())
			{
				process.StartInfo = startInfo;
				process.Start();
				process.StandardOutput.ReadToEnd();
				process.WaitForExit();
			}
			if (File.Exists(outputFilePath))
			{
				ManualLogSource? logger2 = Plugin.Logger;
				if (logger2 != null)
				{
					logger2.LogInfo((object)"Conversion successful deleting WEBM");
				}
				File.Delete(inputFilePath);
				if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), videoFileName)))
				{
					ManualLogSource? logger3 = Plugin.Logger;
					if (logger3 != null)
					{
						logger3.LogInfo((object)"Deleting WEBM that wasn't cleaned up by CustomVideoSaveLocation");
					}
					File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), videoFileName));
				}
			}
			else if (num >= timeoutInSeconds)
			{
				ManualLogSource? logger4 = Plugin.Logger;
				if (logger4 != null)
				{
					logger4.LogError((object)"Conversion timed out");
				}
			}
			else
			{
				ManualLogSource? logger5 = Plugin.Logger;
				if (logger5 != null)
				{
					logger5.LogError((object)"Conversion Failed");
				}
			}
		}
	}
	[BepInPlugin("breadsoup.Video_Converter", "Video Converter", "1.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private const string ModGuid = "breadsoup.Video_Converter";

		private const string ModName = "Video Converter";

		private const string ModVersion = "1.1.2";

		private const bool Devmode = false;

		internal static ManualLogSource? Logger { get; private set; }

		private void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Converter.Init();
			SurfaceNetworkHandler.RPCM_StartGame += new hook_RPCM_StartGame(RPCM_StartGame);
		}

		private void RPCM_StartGame(orig_RPCM_StartGame orig, SurfaceNetworkHandler self)
		{
			bool flag = false;
			orig.Invoke(self);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}