Updated Freecam to support the new BepInEx plugin loader for SPT-AKI

This commit is contained in:
Martynas Gestautas 2022-02-20 00:39:32 +02:00
parent 0c801c48c3
commit a4424ecd09
12 changed files with 152 additions and 138 deletions

View File

@ -4,30 +4,31 @@ An SPT-AKI module mod that allows you to detach the camera and fly around freely
### Controls ### Controls
For now, the keybinds are non-configurable (unless you change it in code and build from source). The default controls are as follows:
- Keypad Plus - toggle free camera mode - Keypad Plus - toggle free camera mode
- Keypad Enter - teleport player to camera position - Keypad Enter - teleport player to camera position
- Keypad Multiply - toggle UI - Keypad Multiply - toggle UI
If you need to change them, press F12 in-game and expand the `Freecam #.#.#` section and configure your keybinds there.
Alternatively, you can find the `com.terkoiz.freecam.cfg` file in your `BepInEx/config/` folder after you've started up the game at least once with Freecam installed, and change the keybinds there.
### How to install ### How to install
1. Download the latest release here: [link](https://dev.sp-tarkov.com/Terkoiz/Freecam/releases) -OR- build from source (instructions below) 1. Download the latest release here: [link](https://dev.sp-tarkov.com/Terkoiz/Freecam/releases) -OR- build from source (instructions below)
2. Simply drop the folder `Terkoiz-Freecam` into your SPT-AKI `user/mods/` directory. 2. Simply extract the zip file contents into your root SPT-AKI folder (where EscapeFromTarkov.exe is).
3. Your `BepInEx/plugins` folder should now contain a `Terkoiz.Freecam.dll` file inside.
### Known issues ### Known issues
1. Your weapon doesn't turn invisible when you enter freecam mode 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 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 3. Game version UI element is not hidden when toggling UI
4. None of the camera settings (speed, senstivity, etc.) are user-configurable 4. When flying to distant parts of the map in freecam mode, LODs are not triggered (these seem to follow the player)
5. 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 ### How to build from source
1. Download/clone this repository 1. Download/clone this repository
2. Download/clone the `SPT-AKI/Modules` repository: [link](https://dev.sp-tarkov.com/SPT-AKI/Modules) 2. Re-import dependencies. I recommend you do this from the SPT-AKI/Modules project's `Shared/Managed` folder, if you have the Modules project fully setup.
3. Move the contents of the `project` folder over to the SPT-AKI Modules `project` folder 3. Rebuild the project in the Release configuration.
4. Add the `Terkoiz.Freecam` project to the SPT-AKI Modules solution 4. Grab the `Terkoiz.Freecam.dll` file from the `bin/Release` folder and use it wherever. Refer to the "How to install" section if you need help here.
5. Build modules - `Terkoiz.Freecam.dll` should appear under `Build/EscapeFromTarkov_Data/Managed` in the SPT-AKI Modules directory
6. Copy the .dll into the `mod/Terkoiz-Freecam` folder and rename to `module.dll`
7. That's it, you have a working release of this mod! Follow the `How to install` instructions on how to get the mod into your game

View File

@ -1,31 +0,0 @@
Copyright (c) 2021 Martynas Gestautas. All rights reserved.
Developed by: SPT-Aki
Martynas Gestautas
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal with the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.
* Neither the names of Martynas Gestautas, SPT-Aki nor the names of its
contributors may be used to endorse or promote products derived from
this Software without specific prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
THE SOFTWARE.

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +0,0 @@
{
"name": "Freecam",
"author": "Terkoiz",
"version": "1.0.1",
"license": "NCSA Open Source",
"dependencies": {}
}

View File

@ -11,31 +11,6 @@ namespace Terkoiz.Freecam
/// </summary> /// </summary>
public class Freecam : MonoBehaviour public class Freecam : MonoBehaviour
{ {
/// <summary>
/// Normal speed of camera movement.
/// </summary>
public float MovementSpeed = 10f;
/// <summary>
/// Speed of camera movement when shift is held down.
/// </summary>
public float FastMovementSpeed = 100f;
/// <summary>
/// Sensitivity for free look.
/// </summary>
public float FreeLookSensitivity = 3f;
/// <summary>
/// Amount to zoom the camera when using the mouse wheel.
/// </summary>
public float ZoomSensitivity = 10f;
/// <summary>
/// Amount to zoom the camera when using the mouse wheel (fast mode).
/// </summary>
public float FastZoomSensitivity = 50f;
public bool IsActive = false; public bool IsActive = false;
void Update() void Update()
@ -44,9 +19,9 @@ namespace Terkoiz.Freecam
{ {
return; return;
} }
var fastMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); var fastMode = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
var movementSpeed = fastMode ? FastMovementSpeed : MovementSpeed; var movementSpeed = fastMode ? FreecamPlugin.CameraFastMoveSpeed.Value : FreecamPlugin.CameraMoveSpeed.Value;
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{ {
@ -88,14 +63,14 @@ namespace Terkoiz.Freecam
transform.position += (-Vector3.up * movementSpeed * Time.deltaTime); transform.position += (-Vector3.up * movementSpeed * Time.deltaTime);
} }
float newRotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * FreeLookSensitivity; float newRotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * FreecamPlugin.CameraLookSensitivity.Value;
float newRotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * FreeLookSensitivity; float newRotationY = transform.localEulerAngles.x - Input.GetAxis("Mouse Y") * FreecamPlugin.CameraLookSensitivity.Value;
transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f); transform.localEulerAngles = new Vector3(newRotationY, newRotationX, 0f);
float axis = Input.GetAxis("Mouse ScrollWheel"); float axis = Input.GetAxis("Mouse ScrollWheel");
if (axis != 0) if (axis != 0)
{ {
var zoomSensitivity = fastMode ? FastZoomSensitivity : ZoomSensitivity; var zoomSensitivity = fastMode ? FreecamPlugin.CameraFastZoomSpeed.Value : FreecamPlugin.CameraZoomSpeed.Value;
transform.position += transform.forward * axis * zoomSensitivity; transform.position += transform.forward * axis * zoomSensitivity;
} }
} }

View File

@ -13,30 +13,24 @@ namespace Terkoiz.Freecam
private BattleUIScreen playerUi; private BattleUIScreen playerUi;
private bool uiHidden; private bool uiHidden;
// TODO:
// Menu for adjusting settings
// Config file for default settings
// Configurable keybinds
// TODO MAYBE: // TODO MAYBE:
// Hide player weapon // Hide player weapon
// Hide version number UI element // Hide version number UI element
// FreeCam controller support (camera could be smoother with an analog stick, apparently) // FreeCam controller support (camera could be smoother with an analog stick, apparently)
// Adjusting speed/sensitivity without a menu (Ctrl+ScrollWheel for example)
public void Update() public void Update()
{ {
if (Input.GetKeyDown(KeyCode.KeypadMultiply)) if (FreecamPlugin.ToggleUi.Value.IsDown())
{ {
ToggleUi(); ToggleUi();
} }
if (Input.GetKeyDown(KeyCode.KeypadPlus)) if (FreecamPlugin.ToggleFreecamMode.Value.IsDown())
{ {
ToggleCamera(); ToggleCamera();
} }
if (Input.GetKeyDown(KeyCode.KeypadEnter)) if (FreecamPlugin.TeleportToCamera.Value.IsDown())
{ {
MovePlayerToCamera(); MovePlayerToCamera();
} }

View File

@ -0,0 +1,98 @@
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
namespace Terkoiz.Freecam
{
[BepInPlugin("com.terkoiz.freecam", "Terkoiz.Freecam", "1.1.0")]
public class FreecamPlugin : BaseUnityPlugin
{
private static GameObject HookObject;
// Keyboard shortcut config entries
private const string KeybindSectionName = "Keybinds";
internal static ConfigEntry<KeyboardShortcut> ToggleFreecamMode;
internal static ConfigEntry<KeyboardShortcut> TeleportToCamera;
internal static ConfigEntry<KeyboardShortcut> ToggleUi;
// Camera settings config entries
private const string CameraSettingsSectionName = "CameraSettings";
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;
private void Awake()
{
Logger.LogError("Loading Freecam...");
InitConfiguration();
HookObject = new GameObject();
HookObject.AddComponent<FreecamController>();
Object.DontDestroyOnLoad(HookObject);
}
private void InitConfiguration()
{
ToggleFreecamMode = Config.Bind(
KeybindSectionName,
"ToggleCamera",
new KeyboardShortcut(KeyCode.KeypadPlus),
"The keyboard shortcut that toggles Freecam");
TeleportToCamera = Config.Bind(
KeybindSectionName,
"TeleportToCamera",
new KeyboardShortcut(KeyCode.KeypadEnter),
"The keyboard shortcut that teleports the player to camera position");
ToggleUi = Config.Bind(
KeybindSectionName,
"ToggleUi",
new KeyboardShortcut(KeyCode.KeypadMultiply),
"The keyboard shortcut that toggles the game UI");
CameraMoveSpeed = Config.Bind(
CameraSettingsSectionName,
"CameraMoveSpeed",
10f,
new ConfigDescription(
"The speed at which the camera will move normally",
new AcceptableValueRange<float>(0.01f, 100f)));
CameraFastMoveSpeed = Config.Bind(
CameraSettingsSectionName,
"CameraFastMoveSpeed",
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,
"CameraLookSensitivity",
3f,
new ConfigDescription(
"Camera free look mouse sensitivity",
new AcceptableValueRange<float>(0.1f, 10f)));
CameraZoomSpeed = Config.Bind(
CameraSettingsSectionName,
"CameraMousewheelZoomSpeed",
10f,
new ConfigDescription(
"Amount to zoom the camera when using the mouse wheel",
new AcceptableValueRange<float>(0.01f, 100f)));
CameraFastZoomSpeed = Config.Bind(
CameraSettingsSectionName,
"CameraMousewheelFastZoomSpeed",
50f,
new ConfigDescription(
"Amount to zoom the camera when using the mouse wheel while holding Shift",
new AcceptableValueRange<float>(0.01f, 1000f)));
}
}
}

View File

@ -1,17 +0,0 @@
using UnityEngine;
namespace Terkoiz.Freecam
{
public class Program
{
private static GameObject HookObject;
static void Main(string[] args)
{
Debug.LogError("Terkoiz.Freecam: Loading...");
HookObject = new GameObject();
HookObject.AddComponent<FreecamController>();
Object.DontDestroyOnLoad(HookObject);
}
}
}

View File

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Terkoiz.Freecam</RootNamespace> <RootNamespace>Terkoiz.Freecam</RootNamespace>
<AssemblyName>Terkoiz.Freecam</AssemblyName> <AssemblyName>Terkoiz.Freecam</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
@ -32,62 +32,48 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<SignAssembly>true</SignAssembly> <SignAssembly>false</SignAssembly>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile> <AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\Shared\References\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp"> <Reference Include="Assembly-CSharp">
<HintPath>..\Shared\References\Assembly-CSharp.dll</HintPath> <HintPath>..\Shared\Hollowed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="ItemComponent.Types"> <Reference Include="BepInEx, Version=5.4.17.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\Shared\References\ItemComponent.Types.dll</HintPath> <HintPath>..\packages\BepInEx.BaseLib.5.4.17\lib\net35\BepInEx.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="Comfort"> <Reference Include="Comfort">
<HintPath>..\Shared\References\Comfort.dll</HintPath> <HintPath>..\Shared\Managed\Comfort.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="ItemComponent.Types">
<SpecificVersion>False</SpecificVersion> <HintPath>..\Shared\Managed\ItemComponent.Types.dll</HintPath>
<HintPath>..\Shared\References\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="UnityEngine"> <Reference Include="UnityEngine">
<HintPath>..\Shared\References\UnityEngine.dll</HintPath> <HintPath>..\Shared\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="UnityEngine.CoreModule"> <Reference Include="UnityEngine.CoreModule">
<HintPath>..\Shared\References\UnityEngine.CoreModule.dll</HintPath> <HintPath>..\Shared\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="UnityEngine.PhysicsModule"> <Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\Shared\References\UnityEngine.PhysicsModule.dll</HintPath> <HintPath>..\Shared\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
<Private>False</Private> </Reference>
<Reference Include="UnityEngine.UIModule">
<HintPath>..\Shared\Managed\UnityEngine.UIModule.dll</HintPath>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Freecam.cs" /> <Compile Include="Freecam.cs" />
<Compile Include="FreecamController.cs" /> <Compile Include="FreecamController.cs" />
<Compile Include="Program.cs" /> <Compile Include="FreecamPlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Aki.Common\Aki.Common.csproj"> <None Include="app.config" />
<Project>{7584f43a-5937-417e-abf4-c5f680f300fb}</Project> <None Include="packages.config" />
<Name>Aki.Common</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="key.snk" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Mono.Cecil" publicKeyToken="50cebf1cceb9d05e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.11.4.0" newVersion="0.11.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BepInEx.BaseLib" version="5.4.17" targetFramework="net472" />
</packages>