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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
[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("LCCinematicFreecam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LCCinematicFreecam")]
[assembly: AssemblyTitle("LCCinematicFreecam")]
[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 LCCinematicFreecam
{
public static class Logger
{
private static ManualLogSource logSource;
public static void SetSource(ManualLogSource Logger)
{
logSource = Logger;
}
public static void Log(object message)
{
logSource.LogInfo(message);
}
public static void LogInfo(object message)
{
logSource.LogInfo(message);
}
public static void LogWarning(object message)
{
logSource.LogWarning(message);
}
public static void LogError(object message)
{
logSource.LogError(message);
}
public static void LogDebug(object message)
{
logSource.LogDebug(message);
}
}
[BepInPlugin("io.daxcess.lccinematicfreecam", "LCCinematicFreecam", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public const string PLUGIN_GUID = "io.daxcess.lccinematicfreecam";
public const string PLUGIN_NAME = "LCCinematicFreecam";
public const string PLUGIN_VERSION = "1.0.0";
private void Awake()
{
Logger.SetSource(((BaseUnityPlugin)this).Logger);
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Inserted patches for LCCinematicFreecam");
}
}
[HarmonyPatch]
internal static class MainPatches
{
private static GameObject helmetObject;
private static SkinnedMeshRenderer playerRenderer;
private static Transform playerAudioListener;
private static Transform mainCamera;
private static Transform freeCamera;
private static Camera cinematicCamera;
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
private static void OnGameEntered(StartOfRound __instance)
{
((MonoBehaviour)__instance).StartCoroutine(SetupFreecam());
}
[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
[HarmonyPostfix]
private static void OnGameLeft()
{
IngamePlayerSettings.Instance.playerInput.actions.FindAction("SetFreeCamera", false).performed -= SetFreeCamera_performed;
}
[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
[HarmonyPostfix]
private static void OnPlayerDeath(PlayerControllerB __instance)
{
if (((NetworkBehaviour)__instance).IsOwner && __instance.isFreeCamera)
{
DisableFreecam();
}
}
private static IEnumerator SetupFreecam()
{
Logger.LogInfo("Setting up free camera");
yield return (object)new WaitUntil((Func<bool>)(() => (Object)(object)StartOfRound.Instance.localPlayerController != (Object)null));
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
helmetObject = ((Component)GameObject.Find("Systems").transform.Find("Rendering/PlayerHUDHelmetModel")).gameObject;
playerRenderer = ((Component)((Component)localPlayerController).transform.Find("ScavengerModel/LOD1")).GetComponent<SkinnedMeshRenderer>();
playerAudioListener = ((Component)localPlayerController).transform.Find("ScavengerModel/metarig/CameraContainer/MainCamera/PlayerAudioListener");
mainCamera = ((Component)localPlayerController).transform.Find("ScavengerModel/metarig/CameraContainer/MainCamera");
freeCamera = GameObject.Find("FreeCameraCinematic").transform;
cinematicCamera = StartOfRound.Instance.freeCinematicCamera;
IngamePlayerSettings.Instance.playerInput.actions.FindAction("SetFreeCamera", false).performed += SetFreeCamera_performed;
}
private static void SetFreeCamera_performed(CallbackContext obj)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
Logger.LogDebug("Freecamera keybind pressed");
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
typeof(PlayerControllerB).GetMethod("SetFreeCamera_performed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(localPlayerController, new object[1] { obj });
if (localPlayerController.isFreeCamera)
{
DisableFreecam();
}
else if (!localPlayerController.isPlayerDead)
{
EnableFreecam();
}
}
private static void EnableFreecam()
{
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
Logger.Log("Enabling freecam");
localPlayerController.isFreeCamera = true;
StartOfRound.Instance.SwitchCamera(cinematicCamera);
cinematicCamera.cullingMask = 557520895;
helmetObject.SetActive(false);
((Renderer)localPlayerController.thisPlayerModelArms).enabled = false;
((Renderer)playerRenderer).shadowCastingMode = (ShadowCastingMode)1;
playerAudioListener.SetParent(freeCamera, false);
HUDManager.Instance.HideHUD(true);
}
private static void DisableFreecam()
{
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
Logger.Log($"Disabling freecam (Dead: {localPlayerController.isPlayerDead})");
localPlayerController.isFreeCamera = false;
((Behaviour)StartOfRound.Instance.freeCinematicCamera).enabled = false;
StartOfRound.Instance.SwitchCamera(localPlayerController.isPlayerDead ? StartOfRound.Instance.spectateCamera : localPlayerController.gameplayCamera);
helmetObject.SetActive(true);
((Renderer)localPlayerController.thisPlayerModelArms).enabled = true;
((Renderer)playerRenderer).shadowCastingMode = (ShadowCastingMode)3;
playerAudioListener.SetParent(mainCamera, false);
HUDManager.Instance.HideHUD(localPlayerController.isPlayerDead);
}
}
}