using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FreeCammer.Scripts;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("FreeCammer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FreeCammer")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a9c64b17-f023-4fda-931b-d9b7e62bad35")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace FreeCammer
{
[BepInPlugin("grug.lethalcompany.freecammer", "Free Cammer", "0.1.2.2")]
public class MyCammer : BaseUnityPlugin
{
public const string modGUID = "grug.lethalcompany.freecammer";
public const string modName = "Free Cammer";
public const string modVersion = "0.1.2.2";
public static ConfigEntry<string> enterCam;
public static ConfigEntry<bool> fpsCam;
public static ConfigEntry<int> mouseButton;
public static ConfigEntry<bool> fullbrightMethod;
public static ConfigEntry<string> camControls;
public static ConfigEntry<string> intensityControls;
public static ConfigEntry<string> showCursorBind;
public static ConfigEntry<bool> tapOrHold;
public static ConfigEntry<KeyCode> dummy;
private static GameObject cammerHolder;
private readonly Harmony harmony = new Harmony("grug.lethalcompany.freecammer");
public static ManualLogSource mls;
private static MyCammer instance;
public void Awake()
{
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Expected O, but got Unknown
mouseButton = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Mouse button", 1, "Button used to turn camera if not using FPS cam for freecam.");
fullbrightMethod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Full bright method", true, "True for directional light, false for a flashlight-sort of method.");
enterCam = ((BaseUnityPlugin)this).Config.Bind<string>("Keybinds", "Camera Activation", "Z", "The key used to enter the camera(google a list of keycodes if you want a specific key)");
fpsCam = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "First person Freecammer", true, "Whether or not rotating requires you to hold right click");
tapOrHold = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hold to increase brightness", false, "Set to true for holding the key down in order to increase brightness");
showCursorBind = ((BaseUnityPlugin)this).Config.Bind<string>("Keybinds", "Key to show cursor", "X", "Pressing this key while in freecam will show your cursor");
camControls = ((BaseUnityPlugin)this).Config.Bind<string>("Keybinds", "WASD controls for camera", "U H J K", "Format the 4 keys you wish to use as the default, and it should work. If not, double check the spelling. Check the bottom of the config for options!");
intensityControls = ((BaseUnityPlugin)this).Config.Bind<string>("Keybinds", "Keys to increase light brightness", "Comma Period", "The keys used to increase and decrease light brightness!");
dummy = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("List of Keys", "", (KeyCode)0, "List of keycodes you can use. Triple check when typing it to ensure no bugs.");
if (!Enum.TryParse<KeyCode>(enterCam.Value, out KeyCode _))
{
enterCam.Value = "Z";
}
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
mls = ((BaseUnityPlugin)this).Logger;
mls.LogInfo((object)"Cammer loaded.");
if ((Object)(object)cammerHolder == (Object)null)
{
cammerHolder = new GameObject("cammerHolder");
Object.DontDestroyOnLoad((Object)(object)cammerHolder);
((Object)cammerHolder).hideFlags = (HideFlags)61;
cammerHolder.AddComponent<CammerScript>();
}
if ((Object)(object)cammerHolder != (Object)null)
{
mls.LogInfo((object)"Cammer not null");
if ((Object)(object)cammerHolder.GetComponent<CammerScript>() != (Object)null)
{
mls.LogInfo((object)"CammerScript not null");
}
}
harmony.PatchAll();
}
}
}
namespace FreeCammer.Scripts
{
internal class CammerScript : MonoBehaviour
{
public static CammerScript instance;
public bool inCammer = false;
public float speed = 10f;
public float intensity = 50f;
public float speedMult = 0.5f;
public Camera cammer;
public AudioListener ears;
public Light light;
public PlayerControllerB me;
public GameObject lightHolder;
private GameObject myarms;
private Renderer myhead;
public LODGroup lodgroup;
public GameObject lod1;
public GameObject lod2;
public GameObject lod3;
public Volume volume;
public Fog fog;
private bool killme;
public List<string> keyList = MyCammer.camControls.Value.Split(new char[1] { ' ' }).ToList();
public List<string> intensKeyList = MyCammer.intensityControls.Value.Split(new char[1] { ' ' }).ToList();
public int beforeCamLayerVal;
public Camera beforeCamCamera;
private Vector3 rotateValue;
public void Awake()
{
MyCammer.mls.LogInfo((object)"Script Active");
instance = this;
}
public unsafe void Update()
{
//IL_0310: Unknown result type (might be due to invalid IL or missing references)
//IL_031a: Expected O, but got Unknown
//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
//IL_0466: Unknown result type (might be due to invalid IL or missing references)
//IL_0470: Unknown result type (might be due to invalid IL or missing references)
//IL_0475: Unknown result type (might be due to invalid IL or missing references)
//IL_0486: Unknown result type (might be due to invalid IL or missing references)
//IL_048c: Unknown result type (might be due to invalid IL or missing references)
//IL_0491: Unknown result type (might be due to invalid IL or missing references)
//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_050d: Unknown result type (might be due to invalid IL or missing references)
//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
//IL_052a: Unknown result type (might be due to invalid IL or missing references)
//IL_0556: Unknown result type (might be due to invalid IL or missing references)
//IL_0565: Unknown result type (might be due to invalid IL or missing references)
//IL_0708: Unknown result type (might be due to invalid IL or missing references)
//IL_076d: Unknown result type (might be due to invalid IL or missing references)
//IL_0725: Unknown result type (might be due to invalid IL or missing references)
//IL_0735: Unknown result type (might be due to invalid IL or missing references)
//IL_0740: Unknown result type (might be due to invalid IL or missing references)
//IL_074a: Unknown result type (might be due to invalid IL or missing references)
//IL_074f: Unknown result type (might be due to invalid IL or missing references)
//IL_07d2: Unknown result type (might be due to invalid IL or missing references)
//IL_078a: Unknown result type (might be due to invalid IL or missing references)
//IL_079a: Unknown result type (might be due to invalid IL or missing references)
//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
//IL_07af: Unknown result type (might be due to invalid IL or missing references)
//IL_07b4: Unknown result type (might be due to invalid IL or missing references)
//IL_0837: Unknown result type (might be due to invalid IL or missing references)
//IL_07ef: Unknown result type (might be due to invalid IL or missing references)
//IL_07ff: Unknown result type (might be due to invalid IL or missing references)
//IL_080a: Unknown result type (might be due to invalid IL or missing references)
//IL_0814: Unknown result type (might be due to invalid IL or missing references)
//IL_0819: Unknown result type (might be due to invalid IL or missing references)
//IL_0854: Unknown result type (might be due to invalid IL or missing references)
//IL_0864: Unknown result type (might be due to invalid IL or missing references)
//IL_086f: Unknown result type (might be due to invalid IL or missing references)
//IL_0879: Unknown result type (might be due to invalid IL or missing references)
//IL_087e: Unknown result type (might be due to invalid IL or missing references)
//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0617: Unknown result type (might be due to invalid IL or missing references)
//IL_08d0: Unknown result type (might be due to invalid IL or missing references)
//IL_0668: Unknown result type (might be due to invalid IL or missing references)
//IL_0693: Unknown result type (might be due to invalid IL or missing references)
//IL_0971: Unknown result type (might be due to invalid IL or missing references)
//IL_0918: Unknown result type (might be due to invalid IL or missing references)
//IL_09ca: Unknown result type (might be due to invalid IL or missing references)
//IL_099b: Unknown result type (might be due to invalid IL or missing references)
//IL_09a1: Invalid comparison between Unknown and I4
//IL_0a14: Unknown result type (might be due to invalid IL or missing references)
//IL_0a5a: Unknown result type (might be due to invalid IL or missing references)
//IL_0aa0: Unknown result type (might be due to invalid IL or missing references)
//IL_0ae3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)volume == (Object)null)
{
foreach (Volume item in Object.FindObjectsOfType<Volume>().ToList())
{
if (((Object)((Component)item).gameObject).name == "VolumeMain")
{
volume = item;
}
}
if ((Object)(object)fog == (Object)null && (Object)(object)volume != (Object)null)
{
volume.sharedProfile.TryGet<Fog>(ref fog);
}
}
if ((Object)(object)me == (Object)null)
{
PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
foreach (PlayerControllerB val in array)
{
if (!((NetworkBehaviour)val).IsOwner)
{
continue;
}
me = val;
myarms = ((Component)me.cameraContainerTransform.parent.GetChild(1)).gameObject;
myhead = GameObject.Find("Systems/Rendering/PlayerHUDHelmetModel/ScavengerHelmet").GetComponent<Renderer>();
if (!Object.op_Implicit((Object)(object)((Component)me).GetComponentInChildren<LODGroup>()))
{
continue;
}
lodgroup = ((Component)me).GetComponentInChildren<LODGroup>();
LOD[] lODs = lodgroup.GetLODs();
foreach (LOD val2 in lODs)
{
Renderer[] renderers = val2.renderers;
foreach (Renderer val3 in renderers)
{
if (((Object)((Component)val3).gameObject).name == "LOD1")
{
lod1 = ((Component)val3).gameObject;
}
if (((Object)((Component)val3).gameObject).name == "LOD2")
{
lod2 = ((Component)val3).gameObject;
}
if (((Object)((Component)val3).gameObject).name == "LOD3")
{
lod3 = ((Component)val3).gameObject;
}
}
}
}
}
if ((Object)(object)cammer == (Object)null)
{
cammer = ((Component)this).gameObject.AddComponent<Camera>();
((Behaviour)cammer).enabled = false;
if ((Object)(object)((Component)this).gameObject.GetComponent<Camera>() != (Object)null)
{
MyCammer.mls.LogInfo((object)"Cammer Added!");
cammer.cullingMask = 557520895;
}
if ((Object)(object)ears == (Object)null)
{
MyCammer.mls.LogInfo((object)"ears spawned");
ears = ((Component)this).gameObject.AddComponent<AudioListener>();
((Behaviour)ears).enabled = false;
}
}
if ((Object)(object)lightHolder == (Object)null)
{
lightHolder = new GameObject("lightermfer");
((Object)lightHolder).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)lightHolder);
light = lightHolder.AddComponent<Light>();
lightHolder.AddComponent<HDAdditionalLightData>();
((Component)light).gameObject.GetComponent<HDAdditionalLightData>().intensity = intensity;
light.intensity = intensity;
if (MyCammer.fullbrightMethod.Value)
{
light.type = (LightType)1;
}
else
{
light.type = (LightType)2;
light.range = 10000f;
light.intensity = intensity;
((Component)light).gameObject.GetComponent<HDAdditionalLightData>().range = 10000f;
}
lightHolder.SetActive(false);
MyCammer.mls.LogInfo((object)"Light spawned");
}
if (UnityInput.Current.GetMouseButton(MyCammer.mouseButton.Value) || MyCammer.fpsCam.Value)
{
rotateValue = new Vector3(*(float*)((InputControl<float>)(object)((Vector2Control)((Pointer)Mouse.current).delta).y).value, *(float*)((InputControl<float>)(object)((Vector2Control)((Pointer)Mouse.current).delta).x).value * -1f) * 0.1f;
((Component)this).transform.eulerAngles = ((Component)this).transform.eulerAngles - rotateValue;
}
if (((Component)this).transform.eulerAngles.x + 5f >= 89f && ((Component)this).transform.localEulerAngles.x < 270f)
{
((Component)this).transform.eulerAngles = new Vector3(84f, ((Component)this).transform.eulerAngles.y, 0f);
}
if (((Component)this).transform.eulerAngles.x - 5f <= 271f && ((Component)this).transform.localEulerAngles.x > 90f)
{
((Component)this).transform.eulerAngles = new Vector3(276f, ((Component)this).transform.eulerAngles.y, 0f);
}
if (UnityInput.Current.GetKeyDown(MyCammer.enterCam.Value))
{
if (!inCammer)
{
beforeCamCamera = StartOfRound.Instance.activeCamera;
}
if ((Object)(object)me != (Object)null && !me.isPlayerDead)
{
((Component)cammer).transform.position = ((Component)me.gameplayCamera).transform.position;
((Component)cammer).transform.rotation = ((Component)me.gameplayCamera).transform.rotation;
}
else if ((Object)(object)me != (Object)null && me.isPlayerDead)
{
((Component)cammer).transform.position = ((Component)me.playersManager.spectateCamera).transform.position;
((Component)cammer).transform.rotation = ((Component)me.playersManager.spectateCamera).transform.rotation;
}
((Behaviour)cammer).enabled = !((Behaviour)cammer).enabled;
inCammer = !inCammer;
if ((Object)(object)lightHolder != (Object)null)
{
lightHolder.SetActive(inCammer);
}
ChangeStates();
}
if (UnityInput.Current.GetKey(isKeyValid(keyList[0])))
{
Transform transform = ((Component)cammer).transform;
transform.position += ((Component)cammer).transform.forward * speed * Time.deltaTime;
}
if (UnityInput.Current.GetKey(isKeyValid(keyList[2])))
{
Transform transform2 = ((Component)cammer).transform;
transform2.position -= ((Component)cammer).transform.forward * speed * Time.deltaTime;
}
if (UnityInput.Current.GetKey(isKeyValid(keyList[1])))
{
Transform transform3 = ((Component)cammer).transform;
transform3.position -= ((Component)cammer).transform.right * speed * Time.deltaTime;
}
if (UnityInput.Current.GetKey(isKeyValid(keyList[3])))
{
Transform transform4 = ((Component)cammer).transform;
transform4.position += ((Component)cammer).transform.right * speed * Time.deltaTime;
}
if ((Object)(object)light != (Object)null && (Object)(object)cammer != (Object)null && MyCammer.fullbrightMethod.Value)
{
((Component)light).transform.localEulerAngles = ((Component)cammer).transform.localEulerAngles;
}
else if ((Object)(object)light != (Object)null && (Object)(object)cammer != (Object)null)
{
((Component)light).transform.position = ((Component)cammer).transform.position;
}
if ((Object)(object)light != (Object)null)
{
light.intensity = intensity;
lightHolder.GetComponent<HDAdditionalLightData>().intensity = intensity;
}
if (UnityInput.Current.GetKeyDown(isKeyValid(MyCammer.showCursorBind.Value)) && inCammer)
{
Cursor.visible = !Cursor.visible;
if ((int)Cursor.lockState == 1)
{
Cursor.lockState = (CursorLockMode)2;
}
else
{
Cursor.lockState = (CursorLockMode)1;
}
}
speed += UnityInput.Current.mouseScrollDelta.y * speedMult;
if (speed <= 0f)
{
speed = 5f;
}
if (UnityInput.Current.GetKeyDown(isKeyValid(intensKeyList[0])) && !MyCammer.tapOrHold.Value)
{
intensity += 10f;
}
if (UnityInput.Current.GetKeyDown(isKeyValid(intensKeyList[1])) && !MyCammer.tapOrHold.Value)
{
intensity -= 10f;
}
if (UnityInput.Current.GetKey(isKeyValid(intensKeyList[0])) && MyCammer.tapOrHold.Value)
{
intensity += 1f;
}
if (UnityInput.Current.GetKey(isKeyValid(intensKeyList[1])) && MyCammer.tapOrHold.Value)
{
intensity -= 1f;
}
if (intensity <= 0f)
{
intensity = 0f;
}
if ((Object)(object)lod1 != (Object)null)
{
SkinnedMeshRenderer val4 = default(SkinnedMeshRenderer);
if (lod1.TryGetComponent<SkinnedMeshRenderer>(ref val4))
{
((Renderer)val4).shadowCastingMode = (ShadowCastingMode)((inCammer || (Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)me.gameplayCamera) ? 1 : 3);
}
if (UnityInput.Current.GetKeyDown((KeyCode)103))
{
MyCammer.mls.LogInfo((object)(inCammer || (Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)me.gameplayCamera));
MyCammer.mls.LogInfo((object)StartOfRound.Instance.activeCamera);
MyCammer.mls.LogInfo((object)me.gameplayCamera);
}
lod1.layer = ((!inCammer && !((Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)me.gameplayCamera)) ? 5 : 0);
}
}
public void ChangeStates()
{
beforeCamLayerVal = lod1.layer;
((Behaviour)me.activeAudioListener).enabled = !inCammer;
((Behaviour)ears).enabled = inCammer;
myarms.SetActive(!inCammer);
if (!MyCammer.fpsCam.Value)
{
Cursor.visible = inCammer;
}
myhead.forceRenderingOff = inCammer;
if ((Object)(object)lodgroup != (Object)null)
{
lodgroup.enabled = !inCammer;
lod1.layer = ((!inCammer) ? beforeCamLayerVal : 0);
lod2.SetActive(false);
lod3.SetActive(false);
}
if (inCammer && (Object)(object)me != (Object)null && !MyCammer.fpsCam.Value)
{
Cursor.lockState = (CursorLockMode)2;
}
else if ((Object)(object)me != (Object)null && !me.quickMenuManager.isMenuOpen)
{
Cursor.lockState = (CursorLockMode)1;
}
if (inCammer)
{
StartOfRound.Instance.activeCamera = cammer;
StartOfRound.Instance.localPlayerController.playerActions.Disable();
}
else
{
StartOfRound.Instance.activeCamera = beforeCamCamera;
StartOfRound.Instance.localPlayerController.playerActions.Enable();
}
if ((Object)(object)volume != (Object)null)
{
((VolumeComponent)fog).active = !inCammer;
((VolumeParameter)fog.enabled).overrideState = !inCammer;
((VolumeParameter<bool>)(object)fog.enabled).value = !inCammer;
}
}
public KeyCode isKeyValid(string keyBrug)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (Enum.TryParse<KeyCode>(keyBrug.ToString(), out KeyCode result))
{
return result;
}
return (KeyCode)0;
}
public void OnGUI()
{
if (!inCammer || !Cursor.visible)
{
return;
}
if (GUILayout.Button("Show/Hide Fog", Array.Empty<GUILayoutOption>()))
{
((VolumeComponent)fog).active = !((VolumeComponent)fog).active;
((VolumeParameter)fog.enabled).overrideState = !((VolumeParameter)fog.enabled).overrideState;
((VolumeParameter<bool>)(object)fog.enabled).value = !((VolumeParameter<bool>)(object)fog.enabled).value;
}
if (GUILayout.Button("Reset Speed", Array.Empty<GUILayoutOption>()))
{
speed = 10f;
}
if (GUILayout.Button("Reset Light", Array.Empty<GUILayoutOption>()))
{
intensity = 50f;
}
if (killme)
{
if (GUILayout.Button("Player turns", Array.Empty<GUILayoutOption>()))
{
StartOfRound.Instance.localPlayerController.playerActions.Enable();
killme = false;
}
}
else if (GUILayout.Button("Player freezes", Array.Empty<GUILayoutOption>()))
{
StartOfRound.Instance.localPlayerController.playerActions.Disable();
killme = true;
}
}
}
}
namespace FreeCammer.Patches
{
internal class CanPerformScanPatch
{
[HarmonyPatch(typeof(HUDManager), "CanPlayerScan")]
private class HUDManager_CanPlayerScan
{
public static bool Prefix(ref bool __result)
{
if (CammerScript.instance.inCammer)
{
__result = false;
return false;
}
return true;
}
}
}
}