using System;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zorro.Core;
[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("com.Bananegame.FreeCAM")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2")]
[assembly: AssemblyProduct("com.Bananegame.FreeCAM")]
[assembly: AssemblyTitle("FreeCAM")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.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 FreeCAM
{
public class FreeCamController : MonoBehaviour
{
private Vector3 velocity = Vector3.zero;
private Vector3 rotation = Vector3.zero;
private float moveSpeed;
private float mouseSensitivity;
public void Initialize()
{
moveSpeed = Plugin.MoveSpeed.Value;
mouseSensitivity = Plugin.MouseSensitivity.Value;
}
public void UpdateCamera(Transform cameraTransform, MainCamera mainCamera)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
moveSpeed = Plugin.MoveSpeed.Value;
mouseSensitivity = Plugin.MouseSensitivity.Value;
velocity = Vector3.zero;
rotation = Vector3.zero;
rotation.y = Input.GetAxis("Mouse X") * mouseSensitivity;
rotation.x = Input.GetAxis("Mouse Y") * mouseSensitivity;
float num = 1f;
if (Input.GetKey((KeyCode)304))
{
num = 3f;
}
if (Input.GetKey((KeyCode)100))
{
velocity.x = moveSpeed * num;
}
if (Input.GetKey((KeyCode)97))
{
velocity.x = (0f - moveSpeed) * num;
}
if (Input.GetKey((KeyCode)119))
{
velocity.z = moveSpeed * num;
}
if (Input.GetKey((KeyCode)115))
{
velocity.z = (0f - moveSpeed) * num;
}
if (Input.GetKey((KeyCode)32))
{
velocity.y = moveSpeed * num;
}
if (Input.GetKey((KeyCode)306))
{
velocity.y = (0f - moveSpeed) * num;
}
cameraTransform.Rotate(Vector3.up * rotation.y, (Space)0);
cameraTransform.Rotate(cameraTransform.right * (0f - rotation.x), (Space)0);
cameraTransform.Translate(Vector3.right * velocity.x, (Space)1);
cameraTransform.Translate(Vector3.forward * velocity.z, (Space)1);
cameraTransform.Translate(Vector3.up * velocity.y, (Space)0);
}
public void StopMovement()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
velocity = Vector3.zero;
rotation = Vector3.zero;
}
}
public class FreeCamManager : MonoBehaviour
{
private bool isFreeCamActive;
private bool isHudVisible;
private FreeCamController? freeCamController;
private List<GameObject> hudObjects = new List<GameObject>();
private List<bool> hudOriginalStates = new List<bool>();
private bool characterInputWasEnabled = true;
private FieldInfo? isGodCamField;
private readonly string[] hudCanvasNames = new string[4] { "Canvas_HUD", "DisplayCanvas", "Canvas_Names", "Binocs" };
private void Start()
{
Plugin.Log.LogInfo((object)"FreeCamManager Start() called");
InitializeReflection();
InitializeFreeCam();
}
private void InitializeReflection()
{
try
{
Type typeFromHandle = typeof(MainCameraMovement);
isGodCamField = typeFromHandle.GetField("isGodCam", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (isGodCamField == null)
{
Plugin.Log.LogError((object)"Could not find isGodCam field!");
}
else
{
Plugin.Log.LogInfo((object)"Reflection fields found successfully!");
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Error in InitializeReflection: " + ex.Message));
}
}
private void InitializeFreeCam()
{
try
{
MainCameraMovement instance = Singleton<MainCameraMovement>.Instance;
if ((Object)(object)instance == (Object)null)
{
Plugin.Log.LogWarning((object)"MainCameraMovement.Instance is null - retrying in Update");
return;
}
if ((Object)(object)freeCamController == (Object)null)
{
freeCamController = ((Component)this).gameObject.AddComponent<FreeCamController>();
freeCamController.Initialize();
Plugin.Log.LogInfo((object)"FreeCamController created!");
}
FindHUD();
}
catch (Exception ex)
{
Plugin.Log.LogError((object)("Error in InitializeFreeCam: " + ex.Message));
}
}
private void FindHUD()
{
hudObjects.Clear();
hudOriginalStates.Clear();
string[] array = hudCanvasNames;
foreach (string text in array)
{
GameObject val = GameObject.Find(text);
if ((Object)(object)val != (Object)null)
{
hudObjects.Add(val);
hudOriginalStates.Add(val.activeSelf);
Plugin.Log.LogInfo((object)$"Found HUD element: {text} (Active: {val.activeSelf})");
}
}
if (hudObjects.Count > 0)
{
Plugin.Log.LogInfo((object)$"Total HUD objects to manage: {hudObjects.Count}");
}
else
{
Plugin.Log.LogWarning((object)"No HUD objects found!");
}
}
private bool IsValidScene()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
if (name == "Airport" || name.StartsWith("Level_"))
{
return true;
}
return false;
}
private void Update()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)freeCamController == (Object)null)
{
InitializeFreeCam();
return;
}
if (!IsValidScene())
{
if (isFreeCamActive)
{
DisableFreeCam();
}
return;
}
if (Input.GetKeyDown(Plugin.FreeCamHotkey.Value))
{
ToggleFreeCam();
}
if (isFreeCamActive && Input.GetKeyDown((KeyCode)27))
{
DisableFreeCam();
}
if (isFreeCamActive && Input.GetKeyDown((KeyCode)104))
{
ToggleHUD();
}
if (isFreeCamActive && (Object)(object)freeCamController != (Object)null)
{
MainCamera instance = MainCamera.instance;
if ((Object)(object)instance != (Object)null)
{
freeCamController.UpdateCamera(((Component)this).transform, instance);
}
}
}
private void ToggleFreeCam()
{
if (isFreeCamActive)
{
DisableFreeCam();
}
else
{
EnableFreeCam();
}
}
private void ToggleHUD()
{
isHudVisible = !isHudVisible;
for (int i = 0; i < hudObjects.Count; i++)
{
if ((Object)(object)hudObjects[i] != (Object)null)
{
hudObjects[i].SetActive(isHudVisible);
}
}
Plugin.Log.LogInfo((object)("HUD " + (isHudVisible ? "shown" : "hidden")));
}
private void EnableFreeCam()
{
isFreeCamActive = true;
isHudVisible = false;
MainCameraMovement instance = Singleton<MainCameraMovement>.Instance;
if ((Object)(object)instance == (Object)null)
{
Plugin.Log.LogError((object)"Cannot enable FreeCam: MainCameraMovement.Instance is null");
return;
}
if (isGodCamField != null)
{
isGodCamField.SetValue(instance, true);
}
int num = 0;
for (int i = 0; i < hudObjects.Count; i++)
{
if ((Object)(object)hudObjects[i] != (Object)null && hudObjects[i].activeSelf)
{
hudObjects[i].SetActive(false);
num++;
}
}
Plugin.Log.LogInfo((object)$"Hidden {num} HUD elements");
if ((Object)(object)Character.localCharacter != (Object)null)
{
characterInputWasEnabled = ((Behaviour)Character.localCharacter.input).enabled;
((Behaviour)Character.localCharacter.input).enabled = false;
}
Cursor.visible = false;
Cursor.lockState = (CursorLockMode)1;
Plugin.Log.LogInfo((object)"FreeCam activated (Press H to toggle HUD)");
}
private void DisableFreeCam()
{
isFreeCamActive = false;
MainCameraMovement instance = Singleton<MainCameraMovement>.Instance;
if ((Object)(object)instance == (Object)null)
{
Plugin.Log.LogError((object)"Cannot disable FreeCam: MainCameraMovement.Instance is null");
return;
}
if (isGodCamField != null)
{
isGodCamField.SetValue(instance, false);
}
if ((Object)(object)freeCamController != (Object)null)
{
freeCamController.StopMovement();
}
int num = 0;
for (int i = 0; i < hudObjects.Count; i++)
{
if ((Object)(object)hudObjects[i] != (Object)null)
{
bool active = i >= hudOriginalStates.Count || hudOriginalStates[i];
hudObjects[i].SetActive(active);
num++;
}
}
Plugin.Log.LogInfo((object)$"Restored {num} HUD elements to original state");
if ((Object)(object)Character.localCharacter != (Object)null)
{
((Behaviour)Character.localCharacter.input).enabled = characterInputWasEnabled;
}
Cursor.visible = true;
Cursor.lockState = (CursorLockMode)0;
Plugin.Log.LogInfo((object)"FreeCam deactivated");
}
}
[BepInPlugin("com.Bananegame.FreeCAM", "FreeCAM", "0.0.2")]
public class Plugin : BaseUnityPlugin
{
private FreeCamManager freeCamManager;
public const string Id = "com.Bananegame.FreeCAM";
internal static ManualLogSource Log { get; private set; }
internal static ConfigEntry<KeyCode> FreeCamHotkey { get; private set; }
internal static ConfigEntry<float> MoveSpeed { get; private set; }
internal static ConfigEntry<float> MouseSensitivity { get; private set; }
public static string Name => "FreeCAM";
public static string Version => "0.0.2";
private void Awake()
{
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
FreeCamHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "FreeCamHotkey", (KeyCode)284, "Hotkey zum Aktivieren/Deaktivieren der FreeCam");
MoveSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("FreeCam Settings", "MoveSpeed", 0.05f, "Bewegungsgeschwindigkeit der FreeCam (Standard: 0.05)");
MouseSensitivity = ((BaseUnityPlugin)this).Config.Bind<float>("FreeCam Settings", "MouseSensitivity", 0.05f, "Mausempfindlichkeit der FreeCam (Standard: 0.05)");
Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
Log.LogInfo((object)$"FreeCam Hotkey: {FreeCamHotkey.Value}");
}
private void Start()
{
freeCamManager = ((Component)this).gameObject.AddComponent<FreeCamManager>();
Log.LogInfo((object)"FreeCamManager initialized!");
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}