mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
push
This commit is contained in:
parent
dc577c3a2f
commit
a468487850
24 changed files with 484 additions and 121 deletions
182
ThirdPerson/CameraLogic.cs
Normal file
182
ThirdPerson/CameraLogic.cs
Normal file
|
@ -0,0 +1,182 @@
|
|||
using ABI_RC.Core.Base;
|
||||
using ABI_RC.Core.Player;
|
||||
using ABI_RC.Core.Util.Object_Behaviour;
|
||||
using Aura2API;
|
||||
using BeautifyEffect;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AzureSky;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
namespace ThirdPerson;
|
||||
|
||||
internal static class CameraLogic
|
||||
{
|
||||
private static float _dist;
|
||||
private static GameObject _ourCam;
|
||||
private static GameObject _desktopCam;
|
||||
private static CameraFovClone _cameraFovClone;
|
||||
|
||||
internal static CameraLocation CurrentLocation = CameraLocation.Default;
|
||||
|
||||
internal enum CameraLocation
|
||||
{
|
||||
Default,
|
||||
FrontView,
|
||||
RightSide,
|
||||
LeftSide
|
||||
}
|
||||
|
||||
private static bool _state;
|
||||
internal static bool State
|
||||
{
|
||||
get => _state;
|
||||
set
|
||||
{
|
||||
_state = value;
|
||||
_ourCam.SetActive(_state);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool _setupPostProcessing;
|
||||
private static readonly FieldInfo _ppResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_Resources", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
private static readonly FieldInfo _ppOldResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_OldResources", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
internal static IEnumerator SetupCamera()
|
||||
{
|
||||
yield return new WaitUntil(() => PlayerSetup.Instance);
|
||||
|
||||
_ourCam = new GameObject("ThirdPersonCameraObj") { };
|
||||
_ourCam.AddComponent<Camera>();
|
||||
|
||||
_cameraFovClone = _ourCam.AddComponent<CameraFovClone>();
|
||||
|
||||
_desktopCam = PlayerSetup.Instance.desktopCamera;
|
||||
_cameraFovClone.targetCamera = _desktopCam.GetComponent<Camera>();
|
||||
|
||||
_ourCam.transform.SetParent(_desktopCam.transform);
|
||||
|
||||
RelocateCam(CameraLocation.Default);
|
||||
|
||||
_ourCam.gameObject.SetActive(false);
|
||||
|
||||
ThirdPerson.Logger.Msg("Finished setting up third person camera.");
|
||||
}
|
||||
|
||||
internal static void CopyFromPlayerCam()
|
||||
{
|
||||
Camera ourCamComponent = _ourCam.GetComponent<Camera>();
|
||||
Camera playerCamComponent = _desktopCam.GetComponent<Camera>();
|
||||
if (ourCamComponent == null || playerCamComponent == null) return;
|
||||
ThirdPerson.Logger.Msg("Copying active camera settings & components.");
|
||||
|
||||
//steal basic settings
|
||||
ourCamComponent.farClipPlane = playerCamComponent.farClipPlane;
|
||||
ourCamComponent.nearClipPlane = playerCamComponent.nearClipPlane;
|
||||
ourCamComponent.cullingMask = playerCamComponent.cullingMask;
|
||||
ourCamComponent.depthTextureMode = playerCamComponent.depthTextureMode;
|
||||
|
||||
//steal post processing if added
|
||||
PostProcessLayer ppLayerPlayerCam = playerCamComponent.GetComponent<PostProcessLayer>();
|
||||
PostProcessLayer ppLayerThirdPerson = ourCamComponent.AddComponentIfMissing<PostProcessLayer>();
|
||||
if (ppLayerPlayerCam != null && ppLayerThirdPerson != null)
|
||||
{
|
||||
ppLayerThirdPerson.enabled = ppLayerPlayerCam.enabled;
|
||||
ppLayerThirdPerson.volumeLayer = ppLayerPlayerCam.volumeLayer;
|
||||
//need to copy these via reflection, otherwise post processing will error
|
||||
if (!_setupPostProcessing)
|
||||
{
|
||||
_setupPostProcessing = true;
|
||||
PostProcessResources resources = (PostProcessResources)_ppResourcesFieldInfo.GetValue(ppLayerPlayerCam);
|
||||
PostProcessResources oldResources = (PostProcessResources)_ppOldResourcesFieldInfo.GetValue(ppLayerPlayerCam);
|
||||
_ppResourcesFieldInfo.SetValue(ppLayerThirdPerson, resources);
|
||||
_ppResourcesFieldInfo.SetValue(ppLayerThirdPerson, oldResources);
|
||||
}
|
||||
}
|
||||
|
||||
//what even is this aura camera stuff
|
||||
AuraCamera auraPlayerCam = playerCamComponent.GetComponent<AuraCamera>();
|
||||
AuraCamera auraThirdPerson = ourCamComponent.AddComponentIfMissing<AuraCamera>();
|
||||
if (auraPlayerCam != null && auraThirdPerson != null)
|
||||
{
|
||||
auraThirdPerson.enabled = auraPlayerCam.enabled;
|
||||
auraThirdPerson.frustumSettings = auraPlayerCam.frustumSettings;
|
||||
}
|
||||
else
|
||||
{
|
||||
auraThirdPerson.enabled = false;
|
||||
}
|
||||
|
||||
//flare layer thing? the sun :_:_:_:_:_:
|
||||
FlareLayer flarePlayerCam = playerCamComponent.GetComponent<FlareLayer>();
|
||||
FlareLayer flareThirdPerson = ourCamComponent.AddComponentIfMissing<FlareLayer>();
|
||||
if (flarePlayerCam != null && flareThirdPerson != null)
|
||||
{
|
||||
flareThirdPerson.enabled = flarePlayerCam.enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
flareThirdPerson.enabled = false;
|
||||
}
|
||||
|
||||
//and now what the fuck is fog scattering
|
||||
AzureFogScattering azureFogPlayerCam = playerCamComponent.GetComponent<AzureFogScattering>();
|
||||
AzureFogScattering azureFogThirdPerson = ourCamComponent.AddComponentIfMissing<AzureFogScattering>();
|
||||
if (azureFogPlayerCam != null && azureFogThirdPerson != null)
|
||||
{
|
||||
azureFogThirdPerson.fogScatteringMaterial = azureFogPlayerCam.fogScatteringMaterial;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.Destroy(ourCamComponent.GetComponent<AzureFogScattering>());
|
||||
}
|
||||
|
||||
//why is there so many thingsssssssss
|
||||
Beautify beautifyPlayerCam = playerCamComponent.GetComponent<Beautify>();
|
||||
Beautify beautifyThirdPerson = ourCamComponent.AddComponentIfMissing<Beautify>();
|
||||
if (beautifyPlayerCam != null && beautifyThirdPerson != null)
|
||||
{
|
||||
beautifyThirdPerson.quality = beautifyPlayerCam.quality;
|
||||
beautifyThirdPerson.profile = beautifyPlayerCam.profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.Destroy(ourCamComponent.gameObject.GetComponent<Beautify>());
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RelocateCam(CameraLocation location, bool resetDist = false)
|
||||
{
|
||||
_ourCam.transform.rotation = _desktopCam.transform.rotation;
|
||||
if (resetDist) ResetDist();
|
||||
switch (location)
|
||||
{
|
||||
case CameraLocation.FrontView:
|
||||
_ourCam.transform.localPosition = new Vector3(0, 0.015f, 0.55f + _dist);
|
||||
_ourCam.transform.localRotation = new Quaternion(0, 180, 0, 0);
|
||||
CurrentLocation = CameraLocation.FrontView;
|
||||
break;
|
||||
case CameraLocation.RightSide:
|
||||
_ourCam.transform.localPosition = new Vector3(0.3f, 0.015f, -0.55f + _dist);
|
||||
_ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0);
|
||||
CurrentLocation = CameraLocation.RightSide;
|
||||
break;
|
||||
case CameraLocation.LeftSide:
|
||||
_ourCam.transform.localPosition = new Vector3(-0.3f, 0.015f, -0.55f + _dist);
|
||||
_ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0);
|
||||
CurrentLocation = CameraLocation.LeftSide;
|
||||
break;
|
||||
case CameraLocation.Default:
|
||||
default:
|
||||
_ourCam.transform.localPosition = new Vector3(0, 0.015f, -0.55f + _dist);
|
||||
_ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0);
|
||||
CurrentLocation = CameraLocation.Default;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ResetDist() => _dist = 0;
|
||||
internal static void IncrementDist() { _dist += 0.25f; RelocateCam(CurrentLocation); }
|
||||
internal static void DecrementDist() { _dist -= 0.25f; RelocateCam(CurrentLocation); }
|
||||
}
|
27
ThirdPerson/Patches.cs
Normal file
27
ThirdPerson/Patches.cs
Normal file
|
@ -0,0 +1,27 @@
|
|||
using ABI.CCK.Components;
|
||||
using ABI_RC.Core.InteractionSystem;
|
||||
using ABI_RC.Core.Player;
|
||||
using MelonLoader;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using static ThirdPerson.CameraLogic;
|
||||
|
||||
namespace ThirdPerson;
|
||||
|
||||
internal static class Patches
|
||||
{
|
||||
internal static void Apply(HarmonyLib.Harmony harmony)
|
||||
{
|
||||
harmony.Patch(
|
||||
typeof(CVRWorld).GetMethod("SetDefaultCamValues", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod()
|
||||
);
|
||||
harmony.Patch(
|
||||
typeof(CVRWorld).GetMethod("CopyRefCamValues", BindingFlags.NonPublic | BindingFlags.Instance),
|
||||
postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod()
|
||||
);
|
||||
}
|
||||
|
||||
//Copy camera settings & postprocessing components
|
||||
private static void OnWorldStart() => CopyFromPlayerCam();
|
||||
}
|
48
ThirdPerson/ThirdPerson.cs
Normal file
48
ThirdPerson/ThirdPerson.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using MelonLoader;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using static ThirdPerson.CameraLogic;
|
||||
using BuildInfo = ThirdPerson.BuildInfo;
|
||||
|
||||
[assembly: AssemblyCopyright("Created by " + BuildInfo.Author)]
|
||||
[assembly: MelonInfo(typeof(ThirdPerson.ThirdPerson), BuildInfo.Name, BuildInfo.Version, BuildInfo.Author)]
|
||||
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
|
||||
[assembly: MelonColor(ConsoleColor.DarkMagenta)]
|
||||
|
||||
namespace ThirdPerson;
|
||||
|
||||
public static class BuildInfo
|
||||
{
|
||||
public const string Name = "ThirdPerson";
|
||||
public const string Author = "Davi & NotAKidoS";
|
||||
public const string Version = "1.0.1";
|
||||
}
|
||||
|
||||
public class ThirdPerson : MelonMod
|
||||
{
|
||||
internal static MelonLogger.Instance Logger;
|
||||
|
||||
public override void OnInitializeMelon()
|
||||
{
|
||||
Logger = LoggerInstance;
|
||||
|
||||
MelonCoroutines.Start(SetupCamera());
|
||||
|
||||
Patches.Apply(HarmonyInstance);
|
||||
}
|
||||
|
||||
public override void OnUpdate()
|
||||
{
|
||||
if (State)
|
||||
{
|
||||
if (Input.GetAxis("Mouse ScrollWheel") > 0f) IncrementDist();
|
||||
else if (Input.GetAxis("Mouse ScrollWheel") < 0f) DecrementDist();
|
||||
}
|
||||
|
||||
if (!Input.GetKey(KeyCode.LeftControl)) return;
|
||||
if (Input.GetKeyDown(KeyCode.T)) State = !State;
|
||||
if (!State || !Input.GetKeyDown(KeyCode.Y)) return;
|
||||
RelocateCam((CameraLocation)(((int)CurrentLocation + 1) % Enum.GetValues(typeof(CameraLocation)).Length), true);
|
||||
}
|
||||
}
|
54
ThirdPerson/ThirdPerson.csproj
Normal file
54
ThirdPerson/ThirdPerson.csproj
Normal file
|
@ -0,0 +1,54 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<CVRReferences>true</CVRReferences>
|
||||
<CopyToMods>true</CopyToMods>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
||||
<Version>1.0.0</Version>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony">
|
||||
<HintPath>..\_ManagedLibs\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>..\_ManagedLibs\Assembly-CSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp-firstpass">
|
||||
<HintPath>..\_ManagedLibs\Assembly-CSharp-firstpass.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Aura2_Core">
|
||||
<HintPath>..\_ManagedLibs\Aura2_Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Cohtml.Runtime">
|
||||
<HintPath>..\_ManagedLibs\Cohtml.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MelonLoader">
|
||||
<HintPath>..\_ManagedLibs\MelonLoader.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Unity.Postprocessing.Runtime">
|
||||
<HintPath>..\_ManagedLibs\Unity.Postprocessing.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AnimationModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.AnimationModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AssetBundleModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.AssetBundleModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.InputLegacyModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.InputLegacyModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule">
|
||||
<HintPath>..\_ManagedLibs\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="Deploy" AfterTargets="Build">
|
||||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" />
|
||||
<Message Text="Copied $(TargetPath) to C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" Importance="high" />
|
||||
</Target>
|
||||
</Project>
|
25
ThirdPerson/ThirdPerson.sln
Normal file
25
ThirdPerson/ThirdPerson.sln
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.2.32630.192
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ThirdPerson", "ThirdPerson.csproj", "{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B44A1184-3AC9-4ABD-8603-6B13ECDA5CA9}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
22
ThirdPerson/format.json
Normal file
22
ThirdPerson/format.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
[
|
||||
{
|
||||
"_id": 16,
|
||||
"name": "ThirdPerson",
|
||||
"modversion": "1.0.1",
|
||||
"gameversion": "2022r170",
|
||||
"loaderversion": "0.5.7",
|
||||
"modtype": "Mod",
|
||||
"author": "Davi & NotAKidoS",
|
||||
"description": "Allows you to go into third person view by pressing Ctrl + T to toggle and Ctrl + Y to change the mode",
|
||||
"searchtags": [
|
||||
"third person view",
|
||||
"3rd person",
|
||||
"third person"
|
||||
],
|
||||
"requirements": [],
|
||||
"downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/tag/r2/ThirdPerson.dll",
|
||||
"sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/",
|
||||
"changelog": "- Made thirdperson camera parent to Desktop camera instead of active camera.\n- Copy postprocessing settings from player camera on world start.\n - This fixed HUD rendering twice in thirdperson due to game update.\n- Added CameraFovClone component to copy zoom from desktop camera.\n- Removed logic that disabled thirdperson when opening a menu, as Game UI renders on top anyways.",
|
||||
"embedcolor": "F61961"
|
||||
}
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue