diff --git a/project/References/Hollowed/Assembly-CSharp.dll b/project/References/Hollowed/Assembly-CSharp.dll deleted file mode 100644 index 29f3b29..0000000 Binary files a/project/References/Hollowed/Assembly-CSharp.dll and /dev/null differ diff --git a/project/Terkoiz.Freecam/FallDamagePatch.cs b/project/Terkoiz.Freecam/FallDamagePatch.cs new file mode 100644 index 0000000..ce57c82 --- /dev/null +++ b/project/Terkoiz.Freecam/FallDamagePatch.cs @@ -0,0 +1,44 @@ +using System.Reflection; +using Aki.Reflection.Patching; +using EFT.HealthSystem; +using HarmonyLib; + +namespace Terkoiz.Freecam +{ + public class FallDamagePatch : ModulePatch + { + internal static bool HasTeleported; + + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(ActiveHealthController), "HandleFall"); + } + + [PatchPrefix] + public static bool PatchPrefix(ActiveHealthController __instance, float height) + { + // WARNING: The 'HandleFall' method gets called every frame for every player and AI in a raid. Be very careful with logging or expensive operations in this prefix patch! + + // Check if it's our own player, or if a Player property even exists + if (__instance.Player?.IsAI ?? true) + { + return true; // Run original method + } + + // Global fall damage flag overrides everything + if (FreecamPlugin.GlobalDisableFallDamage.Value) + { + return false; // Prevent original method from running + } + + // If smart fall damage flag is enabled, check if we've recently teleported and if the fall height value was positive + if (FreecamPlugin.SmartDisableFallDamage.Value && HasTeleported && height > 0) + { + HasTeleported = false; + return false; // Prevent original method from running + } + + return true; // Run original method + } + } +} \ No newline at end of file diff --git a/project/Terkoiz.Freecam/FreecamController.cs b/project/Terkoiz.Freecam/FreecamController.cs index 7ba0668..ba884df 100644 --- a/project/Terkoiz.Freecam/FreecamController.cs +++ b/project/Terkoiz.Freecam/FreecamController.cs @@ -21,11 +21,6 @@ namespace Terkoiz.Freecam private Vector3? _lastPosition; private Quaternion? _lastRotation; - // TODO: - // Hide version number UI element - // Button to toggle between camera and player movement - // Independent FoV setting for Freecam mode (_mainCamera.GetComponent().fieldOfView = ...) - [UsedImplicitly] public void Start() { @@ -103,6 +98,9 @@ namespace Terkoiz.Freecam // Move the player to the camera's current position and switch to First Person mode if (_freeCamScript.IsActive) { + // Tell the fall damage patch that we just teleported. Used for the "smart" fall damage prevention feature + FallDamagePatch.HasTeleported = true; + // We grab the camera's position, but we subtract a bit off the Y axis, because the players coordinate origin is at the feet var position = new Vector3(_mainCamera.transform.position.x, _mainCamera.transform.position.y - 1.8f, _mainCamera.transform.position.z); localPlayer.gameObject.transform.SetPositionAndRotation(position, Quaternion.Euler(0, _mainCamera.transform.rotation.y, 0)); diff --git a/project/Terkoiz.Freecam/FreecamPatch.cs b/project/Terkoiz.Freecam/FreecamPatch.cs index 0311d0c..eae6a1a 100644 --- a/project/Terkoiz.Freecam/FreecamPatch.cs +++ b/project/Terkoiz.Freecam/FreecamPatch.cs @@ -2,6 +2,7 @@ using System.Reflection; using Aki.Reflection.Patching; using Comfort.Common; using EFT; +using HarmonyLib; namespace Terkoiz.Freecam { @@ -9,7 +10,7 @@ namespace Terkoiz.Freecam { protected override MethodBase GetTargetMethod() { - return typeof(GameWorld).GetMethod("OnGameStarted", BindingFlags.Public | BindingFlags.Instance); + return AccessTools.Method(typeof(GameWorld), "OnGameStarted"); } [PatchPostfix] diff --git a/project/Terkoiz.Freecam/FreecamPlugin.cs b/project/Terkoiz.Freecam/FreecamPlugin.cs index 0db2acd..68e5867 100644 --- a/project/Terkoiz.Freecam/FreecamPlugin.cs +++ b/project/Terkoiz.Freecam/FreecamPlugin.cs @@ -7,11 +7,16 @@ using KeyboardShortcut = BepInEx.Configuration.KeyboardShortcut; namespace Terkoiz.Freecam { - [BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.3.2")] + [BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.4.0")] public class FreecamPlugin : BaseUnityPlugin { internal new static ManualLogSource Logger { get; private set; } + // Fall damage config entries + private const string FallDamageSectionName = "Fall Damage"; + internal static ConfigEntry GlobalDisableFallDamage; + internal static ConfigEntry SmartDisableFallDamage; + // Keyboard shortcut config entries private const string KeybindSectionName = "Keybinds"; internal static ConfigEntry ToggleFreecamMode; @@ -19,7 +24,7 @@ namespace Terkoiz.Freecam internal static ConfigEntry ToggleUi; // Camera settings config entries - private const string CameraSettingsSectionName = "CameraSettings"; + private const string CameraSettingsSectionName = "Camera Settings"; internal static ConfigEntry CameraMoveSpeed; internal static ConfigEntry CameraFastMoveSpeed; internal static ConfigEntry CameraLookSensitivity; @@ -39,31 +44,44 @@ namespace Terkoiz.Freecam InitConfiguration(); new FreecamPatch().Enable(); + new FallDamagePatch().Enable(); } private void InitConfiguration() { + 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."); + ToggleFreecamMode = Config.Bind( KeybindSectionName, - "ToggleCamera", + "Toggle Freecam", new KeyboardShortcut(KeyCode.KeypadPlus), "The keyboard shortcut that toggles Freecam"); TeleportToCamera = Config.Bind( KeybindSectionName, - "TeleportToCamera", + "Teleport To Camera", new KeyboardShortcut(KeyCode.KeypadEnter), "The keyboard shortcut that teleports the player to camera position"); ToggleUi = Config.Bind( KeybindSectionName, - "ToggleUi", + "Toggle UI", new KeyboardShortcut(KeyCode.KeypadMultiply), "The keyboard shortcut that toggles the game UI"); CameraMoveSpeed = Config.Bind( CameraSettingsSectionName, - "CameraMoveSpeed", + "Camera Speed", 10f, new ConfigDescription( "The speed at which the camera will move normally", @@ -71,7 +89,7 @@ namespace Terkoiz.Freecam CameraFastMoveSpeed = Config.Bind( CameraSettingsSectionName, - "CameraFastMoveSpeed", + "Camera Sprint Speed", 100f, new ConfigDescription( "The speed at which the camera will move when the Shift key is held down", @@ -79,7 +97,7 @@ namespace Terkoiz.Freecam CameraLookSensitivity = Config.Bind( CameraSettingsSectionName, - "CameraLookSensitivity", + "Camera Mouse Sensitivity", 3f, new ConfigDescription( "Camera free look mouse sensitivity", @@ -87,7 +105,7 @@ namespace Terkoiz.Freecam CameraZoomSpeed = Config.Bind( CameraSettingsSectionName, - "CameraMousewheelZoomSpeed", + "Camera Zoom Speed", 10f, new ConfigDescription( "Amount to zoom the camera when using the mouse wheel", @@ -95,30 +113,30 @@ namespace Terkoiz.Freecam CameraFastZoomSpeed = Config.Bind( CameraSettingsSectionName, - "CameraMousewheelFastZoomSpeed", + "Camera Zoom Sprint Speed", 50f, new ConfigDescription( "Amount to zoom the camera when using the mouse wheel while holding Shift", new AcceptableValueRange(0.01f, 1000f))); - + CameraHeightMovement = Config.Bind( TogglesSectionName, - "CameraHeightMovementKeys", + "Camera Height Movement Keys", 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, - "CameraMousewheelZoom", + "Camera Mousewheel Zoom", true, "Enables or disables camera movement on mousewheel scroll. Just in case you find it annoying and want that disabled."); CameraRememberLastPosition = Config.Bind( TogglesSectionName, - "CameraRememberLastPosition", + "Remember Last Camera Position", false, - "If enabled, returning to Freecam mode will put the camera to it's last position which was saved when exiting Freecam mode."); + "If enabled, returning to Freecam mode will put the camera to it's last position which is saved when exiting Freecam mode."); } } } diff --git a/project/Terkoiz.Freecam/Terkoiz.Freecam.csproj b/project/Terkoiz.Freecam/Terkoiz.Freecam.csproj index 78891a0..9914470 100644 --- a/project/Terkoiz.Freecam/Terkoiz.Freecam.csproj +++ b/project/Terkoiz.Freecam/Terkoiz.Freecam.csproj @@ -1,8 +1,8 @@ - + net472 - 1.3.2 + 1.4.0 Terkoiz, Kobrakon, CWX https://dev.sp-tarkov.com/Terkoiz/Freecam NCSA @@ -20,7 +20,7 @@ False - ..\References\Hollowed\Assembly-CSharp.dll + ..\References\EFT_Managed\Assembly-CSharp.dll False