Decompiled source of CameraON v1.0.3

StupidRepo.CameraON.dll

Decompiled 6 months ago
using System;
using System.Collections;
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.Logging;
using CameraON.Settings;
using ContentSettings.API.Attributes;
using ContentSettings.API.Settings;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MyceliumNetworking;
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("StupidRepo.CameraON")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0.2+97c1d22e2c56f9ec2ac24c9ccf30dae208d85061")]
[assembly: AssemblyProduct("CameraON")]
[assembly: AssemblyTitle("StupidRepo.CameraON")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
		{
		}
	}
}
namespace CameraON
{
	[ContentWarningPlugin("StupidRepo.CameraON", "1.0.2", false)]
	[BepInPlugin("StupidRepo.CameraON", "CameraON", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CameraON : BaseUnityPlugin
	{
		public static CameraON Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony Harmony { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			PatchAll();
			MyceliumNetwork.RegisterLobbyDataKey("CON_TimeOnFor");
			MyceliumNetwork.LobbyEntered += delegate
			{
				if (MyceliumNetwork.IsHost)
				{
					MyceliumNetwork.SetLobbyData("CON_TimeOnFor", (object)CameraONSettings.TimeOnFor);
				}
				else
				{
					TakeLobbyDataToConfig();
				}
			};
			MyceliumNetwork.LobbyDataUpdated += delegate
			{
				TakeLobbyDataToConfig();
			};
			Logger.LogInfo((object)"StupidRepo.CameraON v1.0.2 has loaded!");
		}

		private static void TakeLobbyDataToConfig()
		{
			if (!MyceliumNetwork.IsHost)
			{
				CameraONSettings.TimeOnFor = MyceliumNetwork.GetLobbyData<int>("CON_TimeOnFor");
			}
		}

		internal static void PatchAll()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			Logger.LogDebug((object)"Patching!");
			Harmony = new Harmony("StupidRepo.CameraON");
			Harmony.PatchAll(Assembly.GetExecutingAssembly());
			Logger.LogDebug((object)"Patched!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "StupidRepo.CameraON";

		public const string PLUGIN_NAME = "CameraON";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace CameraON.Settings
{
	public static class CameraONSettings
	{
		internal static int TimeOnFor = 4;
	}
	[SettingRegister("CameraON", null)]
	public class TimeOnForSetting : IntSetting, ICustomSetting, IExposedSetting
	{
		public override void ApplyValue()
		{
			if (!SteamManager.Initialized || !MyceliumNetwork.InLobby || MyceliumNetwork.IsHost)
			{
				CameraONSettings.TimeOnFor = ((IntSetting)this).Value;
			}
			if (SteamManager.Initialized && MyceliumNetwork.InLobby && MyceliumNetwork.IsHost)
			{
				MyceliumNetwork.SetLobbyData("CON_TimeOnFor", (object)((IntSetting)this).Value);
			}
		}

		protected override int GetDefaultValue()
		{
			return 4;
		}

		protected override (int, int) GetMinMaxValue()
		{
			return (0, 15);
		}

		public string GetDisplayName()
		{
			return "Time On For (seconds) (0 = always on)";
		}
	}
}
namespace CameraON.Patches
{
	[HarmonyPatch(typeof(RecordingsHandler))]
	public class RecordingsHandlerPatch
	{
		[HarmonyPatch(typeof(RecordingsHandler), "FindFreePlayer")]
		[HarmonyPrefix]
		private static bool FFPPatch(VideoCamera __instance, ref int __result)
		{
			return true;
		}
	}
	[HarmonyPatch(typeof(VideoCamera))]
	public class VideoCameraPatch
	{
		[HarmonyPatch(typeof(VideoCamera), "RestartRecordingDelayed")]
		[HarmonyPrefix]
		private static bool StopRecordingLog(VideoCamera __instance, ref IEnumerator __result)
		{
			CameraON.Logger.LogWarning((object)$"{((ItemInstanceBehaviour)__instance).isSimulatedByMe} <- is sim, {((ItemInstanceBehaviour)__instance).isHeldByMe} <- is held, {__instance.HasFilmLeft} <- has film!");
			if (__instance == null || !((ItemInstanceBehaviour)__instance).isSimulatedByMe || ((ItemInstanceBehaviour)__instance).isHeldByMe || !__instance.HasFilmLeft)
			{
				return true;
			}
			CameraON.Logger.LogWarning((object)"Not stopping recording!");
			__result = OurRestartCoroutine(__instance);
			return false;
		}

		private static IEnumerator OurRestartCoroutine(VideoCamera instance)
		{
			MethodInfo method = ((object)instance).GetType().GetMethod("RestartRecording", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo rieField = ((object)instance).GetType().GetField("m_recorderInfoEntry", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo idField = ((object)instance).GetType().GetField("m_instanceData", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo rUIField = ((object)instance).GetType().GetField("m_recordingUI", BindingFlags.Instance | BindingFlags.NonPublic);
			object rie = rieField?.GetValue(instance);
			object id = idField?.GetValue(instance);
			object rUI = rUIField?.GetValue(instance);
			if (rUIField == null || idField == null || rieField == null || method == null)
			{
				yield break;
			}
			yield return (object)new WaitForSeconds(0.25f);
			method.Invoke(instance, new object[1]);
			if (CameraONSettings.TimeOnFor != 0)
			{
				CameraON.Logger.LogWarning((object)$"Staying on for {CameraONSettings.TimeOnFor}sec!");
				yield return (object)new WaitForSeconds((float)CameraONSettings.TimeOnFor);
				if (((VideoInfoEntry)rie).isRecording)
				{
					RecordingsHandler.StopRecording((ItemInstanceData)id);
					((GameObject)rUI).gameObject.SetActive(false);
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}