using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCCutscene.Patches;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCCutscene")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCCutscene")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ab36879c-13c9-4bbe-ad1f-d5d9f31d2b8b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public enum EndPosition
{
Camera,
Custom
}
public enum SceneType
{
Cutscene,
QuickScene
}
public enum Transition
{
Fade,
FadeIn,
FadeOut,
Instant
}
namespace LCCutscene
{
public class Content
{
public static AssetBundle MainAssets;
public static void TryLoadAssets()
{
if ((Object)(object)MainAssets == (Object)null)
{
MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "cutsceneasset"));
Plugin.mls.LogInfo((object)"Loaded asset bundle!");
}
}
}
public class Cutscene
{
public Transform CameraTransform { get; private set; }
public float Time { get; private set; }
public Transition TransitionIn { get; set; } = Transition.Fade;
public Transition TransitionOut { get; set; } = Transition.Fade;
public float TransitionInSpeed { get; set; } = 1f;
public float TransitionOutSpeed { get; set; } = 1f;
public bool AllowPlayerDeath { get; set; } = false;
public bool AllowPlayerMovement { get; set; } = false;
public Cutscene(Transform cameraTransform, float time)
{
CameraTransform = cameraTransform;
Time = time;
}
}
public class CutsceneManager : MonoBehaviour
{
private Volume fadeVolume;
private bool inTransition;
private bool OutTransition;
private float transitionTime = 0f;
private SceneType? sceneType = null;
private Cutscene currentCutscene;
private float currentSceneTime = 0f;
private bool initialized = false;
public static CutsceneManager Instance { get; private set; }
public Camera CutsceneCamera { get; private set; }
public bool cutscenePlaying { get; private set; } = false;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
else
{
Object.Destroy((Object)(object)((Component)this).gameObject);
}
}
private void Start()
{
Init();
}
private void Init()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
if (!initialized)
{
if (!Object.op_Implicit((Object)(object)fadeVolume))
{
GameObject val = new GameObject("Fade Volume");
fadeVolume = val.AddComponent<Volume>();
fadeVolume.profile = Content.MainAssets.LoadAsset<VolumeProfile>("Assets/Cutscene/fade.asset");
fadeVolume.isGlobal = true;
fadeVolume.weight = 0f;
fadeVolume.sharedProfile = Content.MainAssets.LoadAsset<VolumeProfile>("Assets/Cutscene/fade.asset");
}
CutsceneCamera = new GameObject("Cutscene_Camera").AddComponent<Camera>();
((Component)CutsceneCamera).gameObject.tag = "MainCamera";
CutsceneCamera.cullingMask = 557520895;
((Behaviour)CutsceneCamera).enabled = false;
initialized = true;
Plugin.mls.LogInfo((object)"Cutscene Manager initialized!");
}
else
{
Plugin.mls.LogWarning((object)"Tried to initialize Cutscene Manager when already initialized!");
}
}
private void Update()
{
//IL_056a: Unknown result type (might be due to invalid IL or missing references)
//IL_058b: Unknown result type (might be due to invalid IL or missing references)
if (inTransition)
{
if (currentCutscene.TransitionIn == Transition.Fade)
{
if (transitionTime < 1f)
{
fadeVolume.weight = Mathf.Lerp(0f, 1f, transitionTime);
transitionTime += Time.deltaTime * currentCutscene.TransitionInSpeed;
}
else if (transitionTime >= 1f && transitionTime < 2f)
{
fadeVolume.weight = Mathf.Lerp(1f, 0f, transitionTime - 1f);
transitionTime += Time.deltaTime * currentCutscene.TransitionInSpeed;
}
else if (transitionTime >= 2f && !OutTransition)
{
inTransition = false;
transitionTime = 0f;
}
}
else if (currentCutscene.TransitionIn == Transition.FadeIn)
{
if (transitionTime < 1f)
{
fadeVolume.weight = Mathf.Lerp(0f, 1f, transitionTime);
transitionTime += Time.deltaTime * currentCutscene.TransitionInSpeed;
}
else if (transitionTime >= 1f)
{
inTransition = false;
transitionTime = 0f;
}
}
else if (currentCutscene.TransitionIn == Transition.FadeOut)
{
if (transitionTime < 1f)
{
fadeVolume.weight = Mathf.Lerp(1f, 0f, transitionTime);
transitionTime += Time.deltaTime * currentCutscene.TransitionInSpeed;
}
else if (transitionTime >= 1f)
{
inTransition = false;
transitionTime = 0f;
}
}
}
else if (OutTransition)
{
if (currentCutscene.TransitionOut == Transition.Fade)
{
if (transitionTime < 1f)
{
fadeVolume.weight = Mathf.Lerp(0f, 1f, transitionTime);
transitionTime += Time.deltaTime * currentCutscene.TransitionOutSpeed;
}
else if (transitionTime >= 1f && transitionTime < 2f)
{
fadeVolume.weight = Mathf.Lerp(1f, 0f, transitionTime - 1f);
transitionTime += Time.deltaTime * currentCutscene.TransitionOutSpeed;
}
else if (transitionTime >= 2f)
{
OutTransition = false;
transitionTime = 0f;
}
}
else if (currentCutscene.TransitionOut == Transition.FadeIn)
{
if (transitionTime < 1f)
{
fadeVolume.weight = Mathf.Lerp(0f, 1f, transitionTime);
transitionTime += Time.deltaTime * currentCutscene.TransitionOutSpeed;
}
else if (transitionTime >= 1f)
{
OutTransition = false;
transitionTime = 0f;
}
}
else if (currentCutscene.TransitionOut == Transition.FadeOut)
{
if (transitionTime < 1f)
{
fadeVolume.weight = Mathf.Lerp(1f, 0f, transitionTime);
transitionTime += Time.deltaTime * currentCutscene.TransitionOutSpeed;
}
else if (transitionTime >= 1f)
{
OutTransition = false;
transitionTime = 0f;
}
}
}
else
{
fadeVolume.weight = 0f;
}
if (cutscenePlaying && sceneType == SceneType.Cutscene && currentCutscene != null)
{
if (((Behaviour)StartOfRound.Instance.localPlayerController.gameplayCamera).enabled)
{
((Behaviour)StartOfRound.Instance.localPlayerController.gameplayCamera).enabled = false;
}
if (!((Behaviour)CutsceneCamera).enabled)
{
((Behaviour)CutsceneCamera).enabled = true;
}
((Component)CutsceneCamera).transform.position = currentCutscene.CameraTransform.position;
((Component)CutsceneCamera).transform.rotation = currentCutscene.CameraTransform.rotation;
currentSceneTime += Time.deltaTime;
}
}
public void PlayScene(Cutscene cutscene)
{
if (!Object.op_Implicit((Object)(object)cutscene.CameraTransform) || (Object)(object)cutscene.CameraTransform == (Object)null)
{
Plugin.mls.LogError((object)$"Camera is {cutscene.CameraTransform}! Cutscene aborted.");
}
else if (!Object.op_Implicit((Object)(object)StartOfRound.Instance.localPlayerController) || (Object)(object)StartOfRound.Instance.localPlayerController == (Object)null)
{
Plugin.mls.LogError((object)$"Player is {StartOfRound.Instance.localPlayerController}! Cutscene aborted.");
}
else if (cutscene.Time <= 0f)
{
Plugin.mls.LogError((object)"Cutscene time can't be 0 or lower! Cutscene aborted.");
}
else if (cutscenePlaying)
{
Plugin.mls.LogError((object)"A cutscene is already playing! Cutscene aborted.");
}
else
{
((MonoBehaviour)this).StartCoroutine(DoCutscene(cutscene));
}
}
private IEnumerator DoCutscene(Cutscene cutscene)
{
currentCutscene = cutscene;
currentSceneTime = 0f;
sceneType = SceneType.Cutscene;
if (cutscene.TransitionIn != Transition.Instant)
{
inTransition = true;
}
if (cutscene.TransitionIn == Transition.Fade || cutscene.TransitionIn == Transition.FadeIn)
{
yield return (object)new WaitForSeconds(1f / cutscene.TransitionInSpeed);
}
cutscenePlaying = true;
StartOfRound.Instance.allowLocalPlayerDeath = cutscene.AllowPlayerDeath;
if (!cutscene.AllowPlayerMovement)
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Move", false).Disable();
}
if (!cutscene.AllowPlayerMovement)
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Jump", false).Disable();
}
if (!cutscene.AllowPlayerMovement)
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Look", false).Disable();
}
if (cutscene.TransitionOut != Transition.Instant && cutscene.TransitionOut != Transition.FadeOut)
{
yield return (object)new WaitForSeconds(cutscene.Time - 1f / cutscene.TransitionOutSpeed);
OutTransition = true;
yield return (object)new WaitForSeconds(1f / cutscene.TransitionOutSpeed);
}
else
{
yield return (object)new WaitForSeconds(cutscene.Time);
}
if (((Behaviour)CutsceneCamera).enabled)
{
((Behaviour)CutsceneCamera).enabled = false;
}
if (!((Behaviour)StartOfRound.Instance.localPlayerController.gameplayCamera).enabled)
{
((Behaviour)StartOfRound.Instance.localPlayerController.gameplayCamera).enabled = true;
}
cutscenePlaying = false;
sceneType = null;
if (!StartOfRound.Instance.allowLocalPlayerDeath)
{
StartOfRound.Instance.allowLocalPlayerDeath = true;
}
if (!cutscene.AllowPlayerMovement)
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Move", false).Enable();
}
if (!cutscene.AllowPlayerMovement)
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Jump", false).Enable();
}
if (!cutscene.AllowPlayerMovement)
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("Look", false).Enable();
}
}
}
[BepInPlugin("Chaos.LCCutscene", "LCCutscene", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private const string modGUID = "Chaos.LCCutscene";
private const string modName = "LCCutscene";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("Chaos.LCCutscene");
public static Plugin Instance;
public static ManualLogSource mls;
public static ConfigFile config;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = ((BaseUnityPlugin)this).Logger;
Content.TryLoadAssets();
harmony.PatchAll(typeof(StartOfRoundPatch));
mls.LogInfo((object)"LCCutscene started.");
}
}
public class QuickScene
{
public Camera CameraCutscene { get; private set; }
public PlayerControllerB Player { get; private set; }
public float Time { get; private set; }
public EndPosition EndPosition { get; set; } = EndPosition.Camera;
public QuickScene(PlayerControllerB player, Camera cameraCutscene, float time)
{
CameraCutscene = cameraCutscene;
Player = player;
Time = time;
}
}
}
namespace LCCutscene.Patches
{
[HarmonyPatch(typeof(StartOfRound))]
public class StartOfRoundPatch
{
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPrefix]
private static void Awake(ref StartOfRound __instance)
{
CutsceneManager component = ((Component)__instance).gameObject.GetComponent<CutsceneManager>();
if (!Object.op_Implicit((Object)(object)component))
{
((Component)__instance).gameObject.AddComponent<CutsceneManager>();
}
}
}
}