Skip to content

Commit

Permalink
Merge pull request #18 from Raicuparta/il2cpp-fixes-aaaaaaaa
Browse files Browse the repository at this point in the history
Il2cpp fixes aaaaaaaa
  • Loading branch information
Raicuparta authored Jun 16, 2024
2 parents 27800c6 + 05dc2ba commit 0621fe4
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 30 deletions.
6 changes: 6 additions & 0 deletions Uuvr/FollowTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace Uuvr;

public class FollowTarget: UuvrBehaviour
{
#if CPP
public FollowTarget(System.IntPtr pointer) : base(pointer)
{
}
#endif

public Transform? Target;
public Vector3 LocalPosition = Vector3.zero;
public Quaternion LocalRotation = Quaternion.identity;
Expand Down
22 changes: 18 additions & 4 deletions Uuvr/ModConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public enum UiPatchMode
public readonly ConfigEntry<int> VrCameraDepth;
public readonly ConfigEntry<int> VrUiLayerOverride;
public readonly ConfigEntry<bool> AlignCameraToHorizon;
public readonly ConfigEntry<Vector3> CameraPositionOffset;
public readonly ConfigEntry<float> CameraPositionOffsetX;
public readonly ConfigEntry<float> CameraPositionOffsetY;
public readonly ConfigEntry<float> CameraPositionOffsetZ;
public readonly ConfigEntry<bool> OverrideDepth;
public readonly ConfigEntry<bool> PhysicsMatchHeadsetRefreshRate;
public readonly ConfigEntry<UiPatchMode> PreferredUiPatchMode;
Expand Down Expand Up @@ -114,10 +116,22 @@ public ModConfiguration(ConfigFile config)
false,
"Prevents pitch and roll changes on the camera, allowing only yaw changes.");

CameraPositionOffset = config.Bind(
CameraPositionOffsetX = config.Bind(
"Camera",
"Camera Position Offset",
Vector3.zero,
"Camera Position Offset X",
0f,
"Changes position of tracked VR cameras");

CameraPositionOffsetY = config.Bind(
"Camera",
"Camera Position Offset Y",
0f,
"Changes position of tracked VR cameras");

CameraPositionOffsetZ = config.Bind(
"Camera",
"Camera Position Offset Z",
0f,
"Changes position of tracked VR cameras");

OverrideDepth = config.Bind(
Expand Down
26 changes: 19 additions & 7 deletions Uuvr/UuvrPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Reflection;
using BepInEx;
using HarmonyLib;
using Uuvr.VrCamera;
using Uuvr.VrUi;
using Uuvr.VrUi.PatchModes;

#if CPP
using BepInEx.IL2CPP;
Expand All @@ -26,6 +29,7 @@ public class UuvrPlugin
: BaseUnityPlugin
#endif
{
private static UuvrPlugin _instance;
public static string ModFolderPath { get; private set; }

#if CPP
Expand All @@ -34,23 +38,31 @@ public override void Load()
private void Awake()
#endif
{
ModFolderPath = Path.GetDirectoryName(Info.Location);
_instance = this;
ModFolderPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(UuvrPlugin)).Location);

new ModConfiguration(Config);
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());

#if CPP
ClassInjector.RegisterTypeInIl2Cpp<UuvrBehaviour>();
ClassInjector.RegisterTypeInIl2Cpp<VrCamera>();
ClassInjector.RegisterTypeInIl2Cpp<UuvrCore>();
ClassInjector.RegisterTypeInIl2Cpp<VrCamera.VrCamera>();
ClassInjector.RegisterTypeInIl2Cpp<VrCameraOffset>();
ClassInjector.RegisterTypeInIl2Cpp<VrCameraManager>();
ClassInjector.RegisterTypeInIl2Cpp<CanvasRedirect>();
ClassInjector.RegisterTypeInIl2Cpp<UiOverlayRenderMode>();
ClassInjector.RegisterTypeInIl2Cpp<VrUiCursor>();
ClassInjector.RegisterTypeInIl2Cpp<VrUiManager>();
ClassInjector.RegisterTypeInIl2Cpp<VrUiCanvas>();
ClassInjector.RegisterTypeInIl2Cpp<FollowTarget>();
// ClassInjector.RegisterTypeInIl2Cpp<UuvrInput>();
ClassInjector.RegisterTypeInIl2Cpp<UuvrPoseDriver>();
ClassInjector.RegisterTypeInIl2Cpp<UuvrBehaviour>();
ClassInjector.RegisterTypeInIl2Cpp<UuvrCore>();
// ClassInjector.RegisterTypeInIl2Cpp<AdditionalCameraData>();
ClassInjector.RegisterTypeInIl2Cpp<VrCameraManager>();
ClassInjector.RegisterTypeInIl2Cpp<VrUiPatchMode>();
ClassInjector.RegisterTypeInIl2Cpp<CanvasRedirectPatchMode>();
ClassInjector.RegisterTypeInIl2Cpp<ScreenMirrorPatchMode>();
#endif

UuvrCore.Create();

}
}
19 changes: 10 additions & 9 deletions Uuvr/VrCamera/VrCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ private void UpdateRelativeMatrix()
// TODO: reset camera matrices and everything else on disabling VR
}

private void SetUpForwardLine()
{
_forwardLine = new GameObject("VrCameraForwardLine").AddComponent<LineRenderer>();
_forwardLine.transform.SetParent(transform, false);
_forwardLine.useWorldSpace = false;
_forwardLine.SetPositions(new []{ Vector3.forward * 2f, Vector3.forward * 10f });
_forwardLine.startWidth = 0.1f;
_forwardLine.endWidth = 0f;
}
// TODO: add option for rendering original camera forward line.
// private void SetUpForwardLine()
// {
// _forwardLine = new GameObject("VrCameraForwardLine").AddComponent<LineRenderer>();
// _forwardLine.transform.SetParent(transform, false);
// _forwardLine.useWorldSpace = false;
// _forwardLine.SetPositions(new []{ Vector3.forward * 2f, Vector3.forward * 10f });
// _forwardLine.startWidth = 0.1f;
// _forwardLine.endWidth = 0f;
// }
}
7 changes: 6 additions & 1 deletion Uuvr/VrCamera/VrCameraOffset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ protected override void OnBeforeRender()
protected override void OnSettingChanged()
{
base.OnSettingChanged();
transform.localPosition = ModConfiguration.Instance.CameraPositionOffset.Value;
var config = ModConfiguration.Instance;

transform.localPosition = new Vector3(
config.CameraPositionOffsetX.Value,
config.CameraPositionOffsetY.Value,
config.CameraPositionOffsetZ.Value);
}

private void Update()
Expand Down
2 changes: 1 addition & 1 deletion Uuvr/VrUi/PatchModes/CanvasRedirect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Uuvr.VrUi.PatchModes;
public class CanvasRedirect: UuvrBehaviour
{
#if CPP
public VrUiCanvas(System.IntPtr pointer) : base(pointer)
public CanvasRedirect(System.IntPtr pointer) : base(pointer)
{
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Uuvr/VrUi/PatchModes/CanvasRedirectPatchMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Uuvr.VrUi.PatchModes;
public class CanvasRedirectPatchMode : VrUiPatchMode
{
#if CPP
public VrUiCanvasPatcher(System.IntPtr pointer) : base(pointer)
public CanvasRedirectPatchMode(System.IntPtr pointer) : base(pointer)
{
}
#endif
Expand Down
19 changes: 16 additions & 3 deletions Uuvr/VrUi/PatchModes/ScreenMirrorPatchMode.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System;
using System.Collections;
using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering;

#if MODERN
using Uuvr.VrCamera;
#endif

#if CPP
using BepInEx.IL2CPP.Utils;
#endif

namespace Uuvr.VrUi.PatchModes;

public class ScreenMirrorPatchMode: VrUiPatchMode
Expand All @@ -21,19 +26,20 @@ public ScreenMirrorPatchMode(System.IntPtr pointer) : base(pointer)
private Camera? _clearCamera;
private float _scale = 2f;
private RenderTexture _targetTexture;
private Coroutine _endOfFrameCoroutine;

protected override void OnEnable()
{
base.OnEnable();
SetXrMirror(false);
StartCoroutine(EndOfFrameCoroutine());
_endOfFrameCoroutine = this.StartCoroutine(EndOfFrameCoroutine());
}

protected override void OnDisable()
{
base.OnDisable();
SetXrMirror(true);
StopCoroutine(EndOfFrameCoroutine());
StopCoroutine(_endOfFrameCoroutine);
Reset();
}

Expand Down Expand Up @@ -71,10 +77,17 @@ public override void SetUpTargetTexture(RenderTexture targetTexture)
_targetTexture = targetTexture;

if (!enabled) return;
_commandBuffer = new CommandBuffer();
_commandBuffer = CreateCommandBuffer();
_commandBuffer.name = "UUVR UI";
_commandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, targetTexture);
}

private static CommandBuffer CreateCommandBuffer()
{
var commandBufferType = typeof(CommandBuffer);
var constructor = commandBufferType.GetConstructor(Type.EmptyTypes);
return (CommandBuffer)constructor.Invoke(null);
}

private void Reset()
{
Expand Down
6 changes: 6 additions & 0 deletions Uuvr/VrUi/PatchModes/VrUiPatchMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ namespace Uuvr.VrUi.PatchModes;

public abstract class VrUiPatchMode: UuvrBehaviour
{
#if CPP
protected VrUiPatchMode(System.IntPtr pointer) : base(pointer)
{
}
#endif

public abstract void SetUpTargetTexture(RenderTexture targetTexture);
}
6 changes: 6 additions & 0 deletions Uuvr/VrUi/UiOverlayRenderMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ namespace Uuvr.VrUi;

public class UiOverlayRenderMode: UuvrBehaviour
{
#if CPP
public UiOverlayRenderMode(System.IntPtr pointer) : base(pointer)
{
}
#endif

// Overlay camera that sees the UI quad where the captured UI is projected.
private Camera? _uiSceneCamera;

Expand Down
2 changes: 1 addition & 1 deletion Uuvr/VrUi/VrUiCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Uuvr.VrUi;
public class VrUiCursor: UuvrBehaviour
{
#if CPP
public VrUiCursor(IntPtr pointer) : base(pointer)
public VrUiCursor(System.IntPtr pointer) : base(pointer)
{
}
#endif
Expand Down
5 changes: 2 additions & 3 deletions Uuvr/VrUi/VrUiManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
Expand Down Expand Up @@ -74,7 +73,7 @@ private void SetUpUi()


_vrUiQuad = GameObject.CreatePrimitive(PrimitiveType.Quad);
Destroy(_vrUiQuad.GetComponent<Collider>());
Destroy(_vrUiQuad.GetComponent("Collider"));
_vrUiQuad.name = "VrUiQuad";
_vrUiQuad.transform.parent = _uiContainer.transform;
_vrUiQuad.transform.localPosition = Vector3.forward * 2f;
Expand Down

0 comments on commit 0621fe4

Please sign in to comment.