2022-02-20 00:39:32 +02:00
using BepInEx ;
using BepInEx.Configuration ;
2022-06-03 14:28:35 +03:00
using BepInEx.Logging ;
2023-02-18 21:35:18 +00:00
using JetBrains.Annotations ;
2022-02-20 00:39:32 +02:00
using UnityEngine ;
2023-02-18 20:23:20 +00:00
using KeyboardShortcut = BepInEx . Configuration . KeyboardShortcut ;
2022-02-20 00:39:32 +02:00
namespace Terkoiz.Freecam
{
2024-07-09 00:06:17 +03:00
[BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.4.4")]
2022-02-20 00:39:32 +02:00
public class FreecamPlugin : BaseUnityPlugin
{
2022-06-03 14:28:35 +03:00
internal new static ManualLogSource Logger { get ; private set ; }
2024-03-02 18:40:51 +02:00
// Fall damage config entries
private const string FallDamageSectionName = "Fall Damage" ;
internal static ConfigEntry < bool > GlobalDisableFallDamage ;
internal static ConfigEntry < bool > SmartDisableFallDamage ;
2022-02-20 00:39:32 +02:00
// Keyboard shortcut config entries
private const string KeybindSectionName = "Keybinds" ;
internal static ConfigEntry < KeyboardShortcut > ToggleFreecamMode ;
2024-03-03 13:40:33 +00:00
internal static ConfigEntry < KeyboardShortcut > ToggleFreecamControls ;
2022-02-20 00:39:32 +02:00
internal static ConfigEntry < KeyboardShortcut > TeleportToCamera ;
internal static ConfigEntry < KeyboardShortcut > ToggleUi ;
// Camera settings config entries
2024-03-02 18:40:51 +02:00
private const string CameraSettingsSectionName = "Camera Settings" ;
2022-02-20 00:39:32 +02:00
internal static ConfigEntry < float > CameraMoveSpeed ;
internal static ConfigEntry < float > CameraFastMoveSpeed ;
internal static ConfigEntry < float > CameraLookSensitivity ;
internal static ConfigEntry < float > CameraZoomSpeed ;
internal static ConfigEntry < float > CameraFastZoomSpeed ;
2023-02-21 22:26:52 +02:00
// General toggles
2022-06-03 14:28:35 +03:00
private const string TogglesSectionName = "Toggles" ;
internal static ConfigEntry < bool > CameraHeightMovement ;
internal static ConfigEntry < bool > CameraMousewheelZoom ;
internal static ConfigEntry < bool > CameraRememberLastPosition ;
2023-03-04 11:26:11 +02:00
2023-02-18 21:35:18 +00:00
[UsedImplicitly]
2022-06-03 14:28:35 +03:00
internal void Start ( )
2022-02-20 00:39:32 +02:00
{
2022-06-03 14:28:35 +03:00
Logger = base . Logger ;
2022-02-20 00:39:32 +02:00
InitConfiguration ( ) ;
2023-02-21 22:26:52 +02:00
new FreecamPatch ( ) . Enable ( ) ;
2024-03-02 18:40:51 +02:00
new FallDamagePatch ( ) . Enable ( ) ;
2022-02-20 00:39:32 +02:00
}
private void InitConfiguration ( )
{
2024-03-02 18:40:51 +02:00
GlobalDisableFallDamage = Config . Bind (
FallDamageSectionName ,
"Globally Disable Fall Damage" ,
false ,
"Completely disables fall damage. This is the safest option for using freecam. Will fully override the 'Smart Fall Damage Prevention' setting." ) ;
SmartDisableFallDamage = Config . Bind (
FallDamageSectionName ,
"Smart Fall Damage Prevention" ,
true ,
"Fall damage will only be disabled after using teleport, until your player lands. Less cheat-y way to save yourself from fall damage, but might sometimes be unreliable." ) ;
2022-02-20 00:39:32 +02:00
ToggleFreecamMode = Config . Bind (
KeybindSectionName ,
2024-03-02 18:40:51 +02:00
"Toggle Freecam" ,
2022-02-20 00:39:32 +02:00
new KeyboardShortcut ( KeyCode . KeypadPlus ) ,
"The keyboard shortcut that toggles Freecam" ) ;
2024-03-03 13:40:33 +00:00
ToggleFreecamControls = Config . Bind (
KeybindSectionName ,
"Toggle Freecam Controls" ,
new KeyboardShortcut ( KeyCode . KeypadPeriod ) ,
"The keyboard shortcut that toggles Freecam Controls" ) ;
2022-02-20 00:39:32 +02:00
TeleportToCamera = Config . Bind (
KeybindSectionName ,
2024-03-02 18:40:51 +02:00
"Teleport To Camera" ,
2022-02-20 00:39:32 +02:00
new KeyboardShortcut ( KeyCode . KeypadEnter ) ,
"The keyboard shortcut that teleports the player to camera position" ) ;
ToggleUi = Config . Bind (
KeybindSectionName ,
2024-03-02 18:40:51 +02:00
"Toggle UI" ,
2022-02-20 00:39:32 +02:00
new KeyboardShortcut ( KeyCode . KeypadMultiply ) ,
"The keyboard shortcut that toggles the game UI" ) ;
CameraMoveSpeed = Config . Bind (
CameraSettingsSectionName ,
2024-03-02 18:40:51 +02:00
"Camera Speed" ,
2022-02-20 00:39:32 +02:00
10f ,
new ConfigDescription (
"The speed at which the camera will move normally" ,
new AcceptableValueRange < float > ( 0.01f , 100f ) ) ) ;
CameraFastMoveSpeed = Config . Bind (
CameraSettingsSectionName ,
2024-03-02 18:40:51 +02:00
"Camera Sprint Speed" ,
2022-02-20 00:39:32 +02:00
100f ,
new ConfigDescription (
"The speed at which the camera will move when the Shift key is held down" ,
new AcceptableValueRange < float > ( 0.01f , 1000f ) ) ) ;
CameraLookSensitivity = Config . Bind (
CameraSettingsSectionName ,
2024-03-02 18:40:51 +02:00
"Camera Mouse Sensitivity" ,
2022-02-20 00:39:32 +02:00
3f ,
new ConfigDescription (
"Camera free look mouse sensitivity" ,
new AcceptableValueRange < float > ( 0.1f , 10f ) ) ) ;
CameraZoomSpeed = Config . Bind (
CameraSettingsSectionName ,
2024-03-02 18:40:51 +02:00
"Camera Zoom Speed" ,
2022-02-20 00:39:32 +02:00
10f ,
new ConfigDescription (
"Amount to zoom the camera when using the mouse wheel" ,
new AcceptableValueRange < float > ( 0.01f , 100f ) ) ) ;
CameraFastZoomSpeed = Config . Bind (
CameraSettingsSectionName ,
2024-03-02 18:40:51 +02:00
"Camera Zoom Sprint Speed" ,
2022-02-20 00:39:32 +02:00
50f ,
new ConfigDescription (
"Amount to zoom the camera when using the mouse wheel while holding Shift" ,
new AcceptableValueRange < float > ( 0.01f , 1000f ) ) ) ;
2024-03-02 18:40:51 +02:00
2022-06-03 14:28:35 +03:00
CameraHeightMovement = Config . Bind (
TogglesSectionName ,
2024-03-02 18:40:51 +02:00
"Camera Height Movement Keys" ,
2022-06-03 14:28:35 +03:00
true ,
"Enables or disables the camera height movement keys, which default to Q, E, R, F." +
" \nUseful to disable if you want to let your character lean in Freecam mode" ) ;
CameraMousewheelZoom = Config . Bind (
TogglesSectionName ,
2024-03-02 18:40:51 +02:00
"Camera Mousewheel Zoom" ,
2022-06-03 14:28:35 +03:00
true ,
2023-02-21 22:26:52 +02:00
"Enables or disables camera movement on mousewheel scroll. Just in case you find it annoying and want that disabled." ) ;
2022-06-03 14:28:35 +03:00
CameraRememberLastPosition = Config . Bind (
TogglesSectionName ,
2024-03-02 18:40:51 +02:00
"Remember Last Camera Position" ,
2022-06-03 14:28:35 +03:00
false ,
2024-03-02 18:40:51 +02:00
"If enabled, returning to Freecam mode will put the camera to it's last position which is saved when exiting Freecam mode." ) ;
2022-02-20 00:39:32 +02:00
}
}
}