Compare commits

...

6 Commits

Author SHA1 Message Date
Terkoiz
f49dfbdb01 Updated for SPT 3.9.0 2024-07-09 00:06:17 +03:00
ac56754db2 I am destroying any instances of GameObject.Find() to save the world (#5)
lgtm
Co-authored-by: Nympfonic <arys.steam@gmail.com>
Co-committed-by: Nympfonic <arys.steam@gmail.com>
2024-04-08 07:09:43 +00:00
Terkoiz
4839e050f8 Version bump for recompiled DLL targetting SPT 3.8.0 2024-03-18 18:29:14 +02:00
Terkoiz
183c640ea3 Version bump 2024-03-03 20:27:57 +02:00
Terkoiz
34e6c8fc06 Updated README 2024-03-03 17:43:39 +02:00
027893c1d6 Freecam Controls Toggle (#4)
Added option to toggle Freecam Controls using a new keybind (default: keypad period).

This allows users to easily switch to Freecam mode, move their camera to position, toggle camera controls, and move the player character. Great addition for efficient testing of weight painting and animations.

Reviewed-on: #4
Co-authored-by: GrooveypenguinX <grooveypenguinx@noreply.dev.sp-tarkov.com>
Co-committed-by: GrooveypenguinX <grooveypenguinx@noreply.dev.sp-tarkov.com>
2024-03-03 13:40:33 +00:00
9 changed files with 60 additions and 34 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ project/References/EFT_Managed/*
# Allow these files, despite the rules above
!project/References/EFT_Managed/.keep
!project/References/SPT/.keep
# ---> VisualStudio
## Ignore Visual Studio temporary files, build results, and

View File

@ -1,6 +1,6 @@
# Freecam
An SPT-AKI module mod that allows you to detach the camera and fly around freely in Escape From Tarkov.
A BepInEx plugin for SPT-AKI that allows you to detach the camera and fly around freely in Escape From Tarkov.
### Controls
@ -21,10 +21,9 @@ Alternatively, you can find the `com.terkoiz.freecam.cfg` file in your `BepInEx/
### Known issues
1. Your weapon doesn't turn invisible when you enter freecam mode
2. When teleporting to camera position, the camera rotation gets copied exactly, potentially causing the player model to tilt
3. Game version UI element is not hidden when toggling UI
4. When flying to distant parts of the map in freecam mode, LODs are not triggered (these seem to follow the player)
1. When teleporting to camera position, the camera rotation gets copied exactly, potentially causing the player model to tilt
2. Game version UI element is not hidden when toggling UI
3. When flying to distant parts of the map in freecam mode, LODs are not triggered (these seem to follow the player)
### How to build from source

View File

View File

@ -1,5 +1,5 @@
using System.Reflection;
using Aki.Reflection.Patching;
using SPT.Reflection.Patching;
using EFT.HealthSystem;
using HarmonyLib;
@ -11,7 +11,7 @@ namespace Terkoiz.Freecam
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(ActiveHealthController), "HandleFall");
return AccessTools.Method(typeof(ActiveHealthController), nameof(ActiveHealthController.HandleFall));
}
[PatchPrefix]

View File

@ -6,7 +6,7 @@ namespace Terkoiz.Freecam
/// <summary>
/// A simple free camera to be added to a Unity game object.
///
/// Full credit to Ashley Davis on GitHub for the inital code:
/// Full credit to Ashley Davis on GitHub for the initial code:
/// https://gist.github.com/ashleydavis/f025c03a9221bc840a2b
///
/// </summary>

View File

@ -13,7 +13,7 @@ namespace Terkoiz.Freecam
private GameObject _mainCamera;
private Freecam _freeCamScript;
private BattleUIScreen _playerUi;
private EftBattleUIScreen _playerUi;
private bool _uiHidden;
private GamePlayerOwner _gamePlayerOwner;
@ -24,14 +24,22 @@ namespace Terkoiz.Freecam
[UsedImplicitly]
public void Start()
{
// Find Main Camera
_mainCamera = GameObject.Find("FPS Camera");
// Get Main Camera
_mainCamera = GetLocalPlayerFromWorld().GetComponent<PlayerCameraController>().Camera.gameObject;
if (_mainCamera == null)
{
FreecamPlugin.Logger.LogError("Failed to locate main camera");
return;
}
// Get Player UI
_playerUi = Singleton<CommonUI>.Instance.EftBattleUIScreen;
if (_playerUi == null)
{
FreecamPlugin.Logger.LogError("Failed to locate player UI");
return;
}
// Add Freecam script to main camera in scene
_freeCamScript = _mainCamera.AddComponent<Freecam>();
if (_freeCamScript == null)
@ -60,6 +68,11 @@ namespace Terkoiz.Freecam
ToggleCamera();
}
if (FreecamPlugin.ToggleFreecamControls.Value.IsDown())
{
ToggleCameraControls();
}
if (FreecamPlugin.TeleportToCamera.Value.IsDown())
{
MovePlayerToCamera();
@ -119,18 +132,6 @@ namespace Terkoiz.Freecam
if (GetLocalPlayerFromWorld() == null)
return;
// If we don't have the UI Component cached, go look for it in the scene
if (_playerUi == null)
{
_playerUi = GameObject.Find("BattleUIScreen").GetComponent<BattleUIScreen>();
if (_playerUi == null)
{
FreecamPlugin.Logger.LogError("Failed to locate player UI");
return;
}
}
_playerUi.gameObject.SetActive(_uiHidden);
_uiHidden = !_uiHidden;
}
@ -196,6 +197,25 @@ namespace Terkoiz.Freecam
localPlayer.PointOfView = EPointOfView.FirstPerson;
}
/// <summary>
/// A helper method to toggle the Freecam Camera Controls
/// </summary>
private void ToggleCameraControls()
{
if (_freeCamScript.IsActive)
{
_freeCamScript.IsActive = false;
_gamePlayerOwner.enabled = true;
}
else
{
_freeCamScript.IsActive = true;
_gamePlayerOwner.enabled = false;
}
}
/// <summary>
/// Gets the current <see cref="Player"/> instance if it's available
/// </summary>
@ -216,7 +236,6 @@ namespace Terkoiz.Freecam
{
// Destroy FreeCamScript before FreeCamController if exists
Destroy(_freeCamScript);
Destroy(this);
}
}
}

View File

@ -1,5 +1,5 @@
using System.Reflection;
using Aki.Reflection.Patching;
using SPT.Reflection.Patching;
using Comfort.Common;
using EFT;
using HarmonyLib;
@ -10,19 +10,19 @@ namespace Terkoiz.Freecam
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GameWorld), "OnGameStarted");
return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted));
}
[PatchPostfix]
public static void PatchPostFix()
{
var gameworld = Singleton<GameWorld>.Instance;
var gameWorld = Singleton<GameWorld>.Instance;
if (gameworld == null)
if (gameWorld == null)
return;
// Add FreeCamController to GameWorld GameObject
gameworld.gameObject.AddComponent<FreecamController>();
// Add FreecamController to GameWorld GameObject
gameWorld.gameObject.AddComponent<FreecamController>();
}
}
}

View File

@ -7,7 +7,7 @@ using KeyboardShortcut = BepInEx.Configuration.KeyboardShortcut;
namespace Terkoiz.Freecam
{
[BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.4.0")]
[BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.4.4")]
public class FreecamPlugin : BaseUnityPlugin
{
internal new static ManualLogSource Logger { get; private set; }
@ -20,6 +20,7 @@ namespace Terkoiz.Freecam
// Keyboard shortcut config entries
private const string KeybindSectionName = "Keybinds";
internal static ConfigEntry<KeyboardShortcut> ToggleFreecamMode;
internal static ConfigEntry<KeyboardShortcut> ToggleFreecamControls;
internal static ConfigEntry<KeyboardShortcut> TeleportToCamera;
internal static ConfigEntry<KeyboardShortcut> ToggleUi;
@ -67,6 +68,12 @@ namespace Terkoiz.Freecam
new KeyboardShortcut(KeyCode.KeypadPlus),
"The keyboard shortcut that toggles Freecam");
ToggleFreecamControls = Config.Bind(
KeybindSectionName,
"Toggle Freecam Controls",
new KeyboardShortcut(KeyCode.KeypadPeriod),
"The keyboard shortcut that toggles Freecam Controls");
TeleportToCamera = Config.Bind(
KeybindSectionName,
"Teleport To Camera",

View File

@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<Version>1.4.0</Version>
<TargetFramework>net471</TargetFramework>
<Version>1.4.4</Version>
<Authors>Terkoiz, Kobrakon, CWX</Authors>
<RepositoryUrl>https://dev.sp-tarkov.com/Terkoiz/Freecam</RepositoryUrl>
<PackageLicenseExpression>NCSA</PackageLicenseExpression>
@ -16,7 +16,7 @@
<ItemGroup>
<Reference Include="Aki.Reflection">
<HintPath>..\References\EFT_Managed\Aki.Reflection.dll</HintPath>
<HintPath>..\References\SPT\spt-reflection.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp">