Decompiled source of FilmIncreaser v1.0.0

FilmIncreaser/FilmIncreaser.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("river")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Increase the amount of film in the camera (in seconds)!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FilmIncreaser")]
[assembly: AssemblyTitle("FilmIncreaser")]
[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 FilmIncreaser
{
	[BepInPlugin("com.river.filmincreaser", "Film Increaser", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static ConfigEntry<float> _maxFilmLength;

		internal static ManualLogSource Log;

		private static readonly string[] MaxTimeNames = new string[7] { "maxTime", "maxRecordingTime", "maxFilm", "recordingLength", "m_MaxTime", "videoLength", "maxSeconds" };

		private static readonly string[] CurrentTimeNames = new string[6] { "timeLeft", "currentFilm", "filmLeft", "recordingTimeLeft", "m_TimeLeft", "secondsLeft" };

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			_maxFilmLength = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxFilmLength", 90f, "The maximum length of the film in seconds. Default is 300 (5 minutes). Game default is 90.");
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			Log.LogInfo((object)$"Plugin FilmIncreaser is loaded with MaxFilmLength: {_maxFilmLength.Value}");
		}

		[HarmonyPatch(typeof(VideoCamera), "Start")]
		[HarmonyPrefix]
		private static void CaptureState(VideoCamera __instance, out float[] __state)
		{
			__state = null;
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			Traverse val = Traverse.Create((object)__instance);
			object value = val.Field("m_recorderInfoEntry").GetValue();
			if (value == null)
			{
				return;
			}
			Traverse val2 = Traverse.Create(value);
			float num = -1f;
			float num2 = -1f;
			string[] currentTimeNames = CurrentTimeNames;
			foreach (string text in currentTimeNames)
			{
				if (val2.Field(text).FieldExists())
				{
					num = val2.Field(text).GetValue<float>();
					break;
				}
			}
			string[] maxTimeNames = MaxTimeNames;
			foreach (string text2 in maxTimeNames)
			{
				if (val2.Field(text2).FieldExists())
				{
					num2 = val2.Field(text2).GetValue<float>();
					break;
				}
			}
			if (num != -1f && num2 != -1f)
			{
				__state = new float[2] { num, num2 };
			}
		}

		[HarmonyPatch(typeof(VideoCamera), "Start")]
		[HarmonyPostfix]
		private static void ForceMaxTime(VideoCamera __instance, float[] __state)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			Traverse val = Traverse.Create((object)__instance);
			object value = val.Field("m_recorderInfoEntry").GetValue();
			if (value == null)
			{
				return;
			}
			Traverse val2 = Traverse.Create(value);
			string[] maxTimeNames = MaxTimeNames;
			foreach (string text in maxTimeNames)
			{
				if (val2.Field(text).FieldExists())
				{
					val2.Field(text).SetValue((object)_maxFilmLength.Value);
				}
			}
			float num = _maxFilmLength.Value;
			if (__state != null && __state.Length == 2)
			{
				float num2 = __state[0];
				float num3 = __state[1];
				num = (Mathf.Approximately(num3, _maxFilmLength.Value) ? num2 : ((!Mathf.Approximately(num2, num3)) ? num2 : _maxFilmLength.Value));
			}
			string[] currentTimeNames = CurrentTimeNames;
			foreach (string text2 in currentTimeNames)
			{
				if (val2.Field(text2).FieldExists())
				{
					val2.Field(text2).SetValue((object)num);
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FilmIncreaser";

		public const string PLUGIN_NAME = "FilmIncreaser";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}