From 364f313e79ecfabb8ac217540b48a2773996f3ba Mon Sep 17 00:00:00 2001 From: notGreg Date: Thu, 8 Sep 2022 21:29:16 +0200 Subject: [PATCH] Add project files. --- CameraResolutionScale.sln | 25 ++++++ .../CameraResolutionScale.csproj | 71 ++++++++++++++++ CameraResolutionScale/Plugin.cs | 83 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ CameraResolutionScale/Utils.cs | 21 +++++ 5 files changed, 236 insertions(+) create mode 100644 CameraResolutionScale.sln create mode 100644 CameraResolutionScale/CameraResolutionScale.csproj create mode 100644 CameraResolutionScale/Plugin.cs create mode 100644 CameraResolutionScale/Properties/AssemblyInfo.cs create mode 100644 CameraResolutionScale/Utils.cs diff --git a/CameraResolutionScale.sln b/CameraResolutionScale.sln new file mode 100644 index 0000000..4952ffb --- /dev/null +++ b/CameraResolutionScale.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32825.248 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CameraResolutionScale", "CameraResolutionScale\CameraResolutionScale.csproj", "{41D9C9BC-1D1B-4A90-8543-DD303712A766}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {41D9C9BC-1D1B-4A90-8543-DD303712A766}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {41D9C9BC-1D1B-4A90-8543-DD303712A766}.Debug|Any CPU.Build.0 = Debug|Any CPU + {41D9C9BC-1D1B-4A90-8543-DD303712A766}.Release|Any CPU.ActiveCfg = Release|Any CPU + {41D9C9BC-1D1B-4A90-8543-DD303712A766}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D4D1124D-EE96-4A87-9DC9-879ED5AC1122} + EndGlobalSection +EndGlobal diff --git a/CameraResolutionScale/CameraResolutionScale.csproj b/CameraResolutionScale/CameraResolutionScale.csproj new file mode 100644 index 0000000..6065dcf --- /dev/null +++ b/CameraResolutionScale/CameraResolutionScale.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {41D9C9BC-1D1B-4A90-8543-DD303712A766} + Library + Properties + CameraResolutionScale + CameraResolutionScale + v4.8 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + E:\SPT-AKI\SPT-AKI 3.2.1\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll + + + E:\SPT-AKI\SPT-AKI 3.2.1\BepInEx\core\BepInEx.dll + + + E:\SPT-AKI\SPT-AKI 3.2.1\EscapeFromTarkov_Data\Managed\Comfort.dll + + + False + E:\SPT-AKI\SPT-AKI 3.2.1\EscapeFromTarkov_Data\Managed\ItemComponent.Types.dll + + + + + + + + + + + E:\SPT-AKI\SPT-AKI 3.2.1\EscapeFromTarkov_Data\Managed\Unity.Postprocessing.Runtime.dll + + + E:\SPT-AKI\SPT-AKI 3.2.1\EscapeFromTarkov_Data\Managed\UnityEngine.dll + + + E:\SPT-AKI\SPT-AKI 3.2.1\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll + + + + + + + + + \ No newline at end of file diff --git a/CameraResolutionScale/Plugin.cs b/CameraResolutionScale/Plugin.cs new file mode 100644 index 0000000..37164b1 --- /dev/null +++ b/CameraResolutionScale/Plugin.cs @@ -0,0 +1,83 @@ +using BepInEx; +using BepInEx.Configuration; +using EFT; +using UnityEngine; +using Comfort.Common; + + +namespace CameraResolutionScale +{ + [BepInPlugin("com.notGreg.cameraScaleControl", "notGreg's Camera Resolution Settings", "1.0.0")] + public class Plugin : BaseUnityPlugin + { + ConfigEntry cameraResolutionScale; + ConfigEntry scopeCameraResolutionScale; + + void Awake() + { + cameraResolutionScale = Config.Bind("General", "Main camera scale %", 50, new ConfigDescription("Main camera resulution scae", new AcceptableValueRange(10,200))); + scopeCameraResolutionScale = Config.Bind("General", "Scope camera scale %", 33, new ConfigDescription("Scope camera resulution scae", new AcceptableValueRange(10, 200))); + } + + Rect defaultMainCameraRect; + float rectScale; + bool setupDone = false; + + + Camera scopeCamera = null; + + bool isAiming = false; + + Utils utils = new Utils(); + void Update() + { + if (!utils.gameIsReady()) + + { + return; + } + if (Camera.allCamerasCount < 1) return; + if (Camera.main == null || Camera.main.isActiveAndEnabled == false) + { + setupDone = false; + return; + } + + + + var handsController = ((Singleton.Instance.RegisteredPlayers[0].HandsController)); + isAiming = handsController.IsAiming; + + + + if (isAiming) + { + if (Camera.main == null || Camera.allCamerasCount <= 1) return; + + if (!setupDone) + { + Logger.LogInfo("Storing default Camera.main.rect"); + defaultMainCameraRect = Camera.main.rect; + rectScale = defaultMainCameraRect.width; + Logger.LogInfo($"Rect: {defaultMainCameraRect}"); + setupDone = true; + } + + if (scopeCamera == null) scopeCamera = Camera.allCameras[1]; + + scopeCamera.GetComponent().OpticCameraToMainCameraResolutionRatio = (float)(scopeCameraResolutionScale.Value / 100f); + float scale = (float)cameraResolutionScale.Value / 100f; + Camera.main.rect = new Rect(0, 0, rectScale * scale, rectScale * scale); + //Logger.LogInfo($"Updating render resolutions: Main Camera: {cameraResolutionScale.Value}% Scope Camera: {scopeCameraResolutionScale.Value}%"); + + return; + } + + if (Camera.main.rect != defaultMainCameraRect && setupDone) + { + Logger.LogInfo("Restoring default render resolution"); + Camera.main.rect = defaultMainCameraRect; + } + } + } +} diff --git a/CameraResolutionScale/Properties/AssemblyInfo.cs b/CameraResolutionScale/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..80b6a60 --- /dev/null +++ b/CameraResolutionScale/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CameraResolutionScale")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CameraResolutionScale")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("41d9c9bc-1d1b-4a90-8543-dd303712a766")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CameraResolutionScale/Utils.cs b/CameraResolutionScale/Utils.cs new file mode 100644 index 0000000..e38b4d9 --- /dev/null +++ b/CameraResolutionScale/Utils.cs @@ -0,0 +1,21 @@ +using Comfort.Common; +using EFT; + +namespace CameraResolutionScale +{ + public class Utils + { + public bool gameIsReady() + { + var gameWorld = Singleton.Instance; + var sessionResultPanel = Singleton.Instance; + + if (gameWorld == null + || gameWorld.AllPlayers == null + || gameWorld.AllPlayers.Count <= 0 + || sessionResultPanel != null) + { return false; } + return true; + } + } +}