Skip to content

Commit d016052

Browse files
committed
Add VR Red Dot Sight
1 parent d70e2f0 commit d016052

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed

TABGVR/AssetBundle.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Reflection;
2+
using UnityEngine;
3+
4+
namespace TABGVR;
5+
6+
public static class AssetBundle
7+
{
8+
public static void Load()
9+
{
10+
using var bundle0Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TABGVR.Assets.vr0.tabgvrasset");
11+
Bundle0 = UnityEngine.AssetBundle.LoadFromStream(bundle0Stream);
12+
}
13+
14+
public static UnityEngine.AssetBundle Bundle0;
15+
}

TABGVR/Assets/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
You may notice there's no source code here, only a binary file. This is a Unity AssetBundle containing scope shaders and
2+
modifications. I cannot legally distribute the source code of this Unity project as it contains copyrighted assets from
3+
TABG. You can decompile it if you really want though. There is no executables in this file since AssetBundles don't
4+
support that as a security measure, so there isn't any undocumented source code that would give you a virus or anything.

TABGVR/Assets/vr0.tabgvrasset

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:08d474beb202002567c2560bab98196e437d6da5cec91f5b65b34dce2a26e459
3+
size 11097

TABGVR/Input/VRControls.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ private void Start()
4949
interactionHandler.canNotPickUpAction = () => currentPickup = null;
5050

5151
inputHandler.enabled = false;
52+
inputHandler.cameraMovement.ADS = true;
5253

5354
menuTransitions = InventoryUI.instance.gameObject.GetComponent<MenuTransitions>();
5455
mapHandler = InventoryUI.instance.gameObject.GetComponentInChildren<MapHandler>();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using HarmonyLib;
2+
using TABGVR.PatchAttributes;
3+
using TABGVR.Scopes;
4+
using UnityEngine;
5+
6+
namespace TABGVR.Patches.Scopes;
7+
8+
[HarmonyPatch(typeof(RedDot))]
9+
[VRPatch, FlatscreenPatch]
10+
public static class RedDotPatch
11+
{
12+
[HarmonyPatch(nameof(RedDot.Start))]
13+
[HarmonyPostfix]
14+
public static void Start(RedDot __instance)
15+
{
16+
__instance.dotTransform.gameObject.SetActive(true);
17+
__instance.enabled = false;
18+
__instance.gameObject.AddComponent<VRRedDot>();
19+
}
20+
}

TABGVR/Plugin.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class Plugin : BaseUnityPlugin
2929

3030
private void Awake()
3131
{
32+
AssetBundle.Load();
33+
3234
SnapTurnEnabled = Config.Bind("Input", "SnapTurn", true, "Use snap turn instead of smooth turn.");
3335
AskOnStartup = Config.Bind("Input", "AskOnStartup", true, "Ask to use VR mode on startup.");
3436
VREnabled = Config.Bind("Input", "VREnabled", true,

TABGVR/Scopes/VRRedDot.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using Unity.XR.CoreUtils;
3+
using UnityEngine;
4+
5+
namespace TABGVR.Scopes;
6+
7+
public class VRRedDot : MonoBehaviour
8+
{
9+
private RedDot redDot;
10+
private bool success;
11+
private const float Multiplier = 1 / (0.4f * 3.5f * 0.12f * 0.7f);
12+
13+
private void Start()
14+
{
15+
redDot = GetComponent<RedDot>();
16+
17+
var lens = transform.Find("GameObject").Find("Model").Find("W_RedDot").Find("W_RedDot_Glass").gameObject;
18+
lens.SetActive(true); // enable lens glass
19+
20+
Debug.Log(1);
21+
var glassMaterial = AssetBundle.Bundle0.LoadAsset<Material>("Assets/TABGVR/Scopes/RedDot/Glass.mat");
22+
Debug.Log(2);
23+
var redDotMaterial = AssetBundle.Bundle0.LoadAsset<Material>("Assets/TABGVR/Scopes/RedDot/RedDot.mat");
24+
25+
Debug.Log(3);
26+
lens.GetComponent<MeshRenderer>().material = glassMaterial;
27+
Debug.Log(3);
28+
redDot.dotTransform.GetComponent<MeshRenderer>().material = redDotMaterial;
29+
}
30+
31+
private void Update()
32+
{
33+
// this method just bruteforces the positioning until it doesn't error :|
34+
if (success) return;
35+
36+
try
37+
{
38+
// ReSharper disable once Unity.PerformanceCriticalCodeInvocation
39+
var shootPosition = redDot.camMove.weaponHandler.m_holding.heldObject.rig.GetComponent<Gun>()
40+
.shootPositions;
41+
42+
redDot.dotTransform.localPosition =
43+
Vector3.forward * (redDot.transform.InverseTransformPoint(shootPosition[0].position).z * Multiplier);
44+
45+
redDot.dotTransform.localScale = Vector3.one * (0.006f * redDot.dotTransform.localPosition.z);
46+
47+
success = true;
48+
}
49+
catch
50+
{
51+
// ignored
52+
}
53+
}
54+
}

TABGVR/TABGVR.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
<Reference Include="$(GameReferences)\Unity.XR.OpenXR.dll" Publicize="true"/>
4646
</ItemGroup>
4747

48+
<!-- Embedded Assets -->
49+
<ItemGroup>
50+
<EmbeddedResource Include="Assets/*.tabgvrasset" />
51+
</ItemGroup>
52+
4853
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
4954
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all"/>
5055
</ItemGroup>

0 commit comments

Comments
 (0)