using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FreeCamera")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreeCamera")]
[assembly: AssemblyTitle("FreeCamera")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FreeCamera;
[BepInPlugin("Free.Camera", "Free.Camera", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <WaitAndRegister>d__5 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public Plugin <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WaitAndRegister>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
int num = <>1__state;
Plugin plugin = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(5f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
plugin.RegisterFreeCamera();
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static ManualLogSource Log;
private readonly Harmony harmony = new Harmony("Free.Camera");
public static ConfigEntry<int> CameraPrice;
public static ConfigEntry<float> FilmLength;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
CameraPrice = ((BaseUnityPlugin)this).Config.Bind<int>("General", "CameraPrice", 0, "Price of the camera in the shop (default: 0 for free)");
FilmLength = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FilmLength", 120f, "Maximum film length in seconds (default: 120, vanilla: 90)");
((BaseUnityPlugin)this).Logger.LogInfo((object)"FreeCamera loading...");
harmony.PatchAll();
((MonoBehaviour)this).StartCoroutine(WaitAndRegister());
}
[IteratorStateMachine(typeof(<WaitAndRegister>d__5))]
private IEnumerator WaitAndRegister()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WaitAndRegister>d__5(0)
{
<>4__this = this
};
}
private void RegisterFreeCamera()
{
Item[] array = Resources.FindObjectsOfTypeAll<Item>();
foreach (Item val in array)
{
if (((Object)val).name == "Camera")
{
val.price = CameraPrice.Value;
val.purchasable = true;
Log.LogInfo((object)$"Set Camera price to {CameraPrice.Value}!");
return;
}
}
Log.LogWarning((object)"Could not find Camera item!");
}
}
[HarmonyPatch(typeof(VideoCamera))]
public class VideoCameraPatches
{
[CompilerGenerated]
private sealed class <JustRestartAndKeepGoing>d__1 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public VideoCamera instance;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <JustRestartAndKeepGoing>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(0.25f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
typeof(VideoCamera).GetMethod("RestartRecording", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(instance, new object[1]);
Plugin.Log.LogInfo((object)"Camera dropped - recording continues indefinitely!");
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[HarmonyPatch("RestartRecordingDelayed")]
[HarmonyPrefix]
private static bool SkipRestartRecordingDelayed(VideoCamera __instance, ref IEnumerator __result)
{
__result = JustRestartAndKeepGoing(__instance);
return false;
}
[IteratorStateMachine(typeof(<JustRestartAndKeepGoing>d__1))]
private static IEnumerator JustRestartAndKeepGoing(VideoCamera instance)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <JustRestartAndKeepGoing>d__1(0)
{
instance = instance
};
}
}
[HarmonyPatch(typeof(VideoCamera), "ConfigItem")]
public class FilmLengthPatch
{
[HarmonyPostfix]
private static void Postfix(VideoCamera __instance)
{
object obj = typeof(VideoCamera).GetField("m_recorderInfoEntry", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
if (obj != null)
{
FieldInfo field = obj.GetType().GetField("maxTime");
FieldInfo field2 = obj.GetType().GetField("timeLeft");
float num = (float)field?.GetValue(obj);
float num2 = (float)field2?.GetValue(obj);
if (num <= 90f)
{
float num3 = num2 / num;
field?.SetValue(obj, Plugin.FilmLength.Value);
field2?.SetValue(obj, Plugin.FilmLength.Value * num3);
Plugin.Log.LogInfo((object)$"Film length set to {Plugin.FilmLength.Value} seconds!");
}
}
}
}