Decompiled source of CustomVideoSaveLocation v1.0.10

Ramune.CustomVideoSaveLocation.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RamuneLib;
using RamuneLib.Utils;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Ramune.CustomVideoSaveLocation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Ramune.CustomVideoSaveLocation")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b9105445-d226-4386-9925-9cf910e664c3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace Ramune.CustomVideoSaveLocation
{
	[BepInPlugin("com.ramune.CustomVideoSaveLocation", "Custom Video Save Location", "1.0.0")]
	[BepInProcess("Content Warning.exe")]
	public class CustomVideoSaveLocation : BaseUnityPlugin
	{
		public static CustomVideoSaveLocation Instance;

		public static readonly Harmony harmony = new Harmony("com.ramune.CustomVideoSaveLocation");

		public const string GUID = "com.ramune.CustomVideoSaveLocation";

		public const string Name = "Custom Video Save Location";

		public const string Version = "1.0.0";

		public static ManualLogSource logger => ((BaseUnityPlugin)Instance).Logger;

		public static ConfigEntry<string> Path { get; set; }

		public void Awake()
		{
			Path = ((BaseUnityPlugin)this).Config.Bind<string>("VideoSaveFolderPath", "Path to the folder to save your videos to", "Desktop", "Example: 'C:\\Secrets\\Videos\\ContentWarning'. If it's set to \"Desktop\" it'll just use the default desktop saving, and if it's invalid it'll log an error and save it to the desktop location.");
			Initializer.Initialize(harmony, ((BaseUnityPlugin)this).Logger, "Custom Video Save Location", "1.0.0");
		}
	}
}
namespace Ramune.CustomVideoSaveLocation.Patches
{
	[HarmonyPatch(typeof(CameraRecording))]
	public static class CameraRecordingPatch
	{
		[HarmonyPatch("SaveToDesktop")]
		[HarmonyPrefix]
		public static bool SaveToDesktop(CameraRecording __instance, out string videoFileName)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			string sourceFileName = default(string);
			if (!RecordingsHandler.TryGetRecordingPath(__instance.videoHandle, ref sourceFileName))
			{
				videoFileName = string.Empty;
				return false;
			}
			videoFileName = "content_warning_" + GuidExtensions.ToShortString(__instance.videoHandle.id) + ".webm";
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
			string value = CustomVideoSaveLocation.Path.Value;
			if (value.ToLower() != "desktop" && Directory.Exists(value))
			{
				File.Copy(sourceFileName, Path.Combine(value, videoFileName));
				LoggerUtils.LogInfo("Saved '" + videoFileName + "' to '" + Path.Combine(value, videoFileName) + "'");
			}
			else
			{
				File.Copy(sourceFileName, Path.Combine(folderPath, videoFileName));
				LoggerUtils.LogWarning("Could not find folder at specified custom path '" + value + "', so the video was instead  saved '" + videoFileName + "' to '" + Path.Combine(value, videoFileName) + "'");
			}
			return true;
		}
	}
}
namespace RamuneLib
{
	public static class Initializer
	{
		public static void Initialize(Harmony harmony, ManualLogSource logger, string name, string version, bool patchAll = true)
		{
			Variables.harmony = harmony;
			Variables.logger = logger;
			string text = "======================= " + name + " (" + version + ") =======================";
			string message = new string('=', text.Length);
			LoggerUtils.LogInfo(text);
			if (patchAll)
			{
				LoggerUtils.LogInfo(">> Loading harmony patches for '" + name + " " + version + "'");
				harmony.PatchAll();
				LoggerUtils.LogInfo(">> Finished loading harmony patches for '" + name + " " + version + "'..");
			}
			LoggerUtils.LogInfo(message);
		}
	}
	public static class Variables
	{
		public static class Paths
		{
			public static string PluginFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

			public static string AssetsFolder => Path.Combine(PluginFolder, "Assets");
		}

		public static Harmony harmony { get; set; }

		public static ManualLogSource logger { get; set; }
	}
}
namespace RamuneLib.Utils
{
	public static class LoggerUtils
	{
		public static bool Debug;

		public static void LogInfo(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogInfo((object)message);
			}
		}

		public static void LogDebug(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogDebug((object)message);
			}
		}

		public static void LogWarning(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogWarning((object)message);
			}
		}

		public static void LogError(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogError((object)message);
			}
		}

		public static void LogFatal(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogFatal((object)message);
			}
		}
	}
}