Skip to content

Commit

Permalink
fix(input): 🔒 multi place builder patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira committed Dec 15, 2023
1 parent e4610bb commit e628f70
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 84 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"input",
"render",
"ui",
"player"
"player",
"game"
]
}
}
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ While the mod is in a playable state, it is still in early development. Some fea
- Button prompts are not for VR controllers.
- Haptics are played on both controllers by the game. One improvement would be to play them on the hand that is actually holding the tool.
- Use and interact buttons are mapped to the same button. This might cause issues when interacting with objects.
- The manual crank button is not mapped to a button on the controller.
- Machine info not visible when targeting with hand.
- Crafting queue not visible.
- The game is locked to 60fps when running in windowed mode. This is based on the refresh rate of your monitor. To unlock the framerate, switch to fullscreen mode. (For now)
- Menus are a little jittery

=== Cool stuff to try
- Tobii eye tracking for dynamic foveated rendering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Plugin.Input;
using UnityEngine;

namespace TechtonicaVR.VRCamera.Patch;
namespace TechtonicaVR.VRCamera.Patch.Builder;

[HarmonyPatch]
public class BuilderRaycastPatch
Expand Down
34 changes: 34 additions & 0 deletions plugin/src/camera/patch/builder/builder_reassemble_patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using HarmonyLib;
using TechtonicaVR.Util.Patch;

namespace TechtonicaVR.VRCamera.Patch.Builder;

[HarmonyPatch]
public class BuilderReassemblePatch
{
private const int EXPECTED_PATCH_COUNT = 12;



[HarmonyPatch(typeof(FloorBuilder), nameof(FloorBuilder.Reassemble))]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> ReassembleTranspiler(IEnumerable<CodeInstruction> instructions)
{
return Transpile.reassemblePatch<FloorBuilder>(instructions);
}

[HarmonyPatch(typeof(ResearchCoreBuilder), nameof(ResearchCoreBuilder.Reassemble))]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> ResearchCoreReassembleTranspiler(IEnumerable<CodeInstruction> instructions)
{
return Transpile.reassemblePatch<ResearchCoreBuilder>(instructions);
}

[HarmonyPatch(typeof(StairsBuilder), nameof(StairsBuilder.Reassemble))]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> StairsBuilderTranspiler(IEnumerable<CodeInstruction> instructions)
{
return Transpile.reassemblePatch<StairsBuilder>(instructions);
}
}
16 changes: 16 additions & 0 deletions plugin/src/camera/patch/builder/conveyor_builder_patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using HarmonyLib;
using TechtonicaVR.Util.Patch;

namespace TechtonicaVR.VRCamera.Patch.Builder;

[HarmonyPatch]
class ConveyorBuilderPatch
{
[HarmonyPatch(typeof(ConveyorBuilder), nameof(ConveyorBuilder.GetTargetEndPt))]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> ReassembleTranspiler(IEnumerable<CodeInstruction> instructions)
{
return Transpile.reassemblePatch<ConveyorBuilder>(instructions, 5);
}
}
16 changes: 16 additions & 0 deletions plugin/src/camera/patch/builder/multi_place_builder_patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using HarmonyLib;
using TechtonicaVR.Util.Patch;

namespace TechtonicaVR.VRCamera.Patch.Builder;

[HarmonyPatch]
class MultiPlaceBuilderPatch
{
[HarmonyPatch(typeof(MultiPlaceBuilder), nameof(MultiPlaceBuilder.Reassemble))]
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> ReassembleTranspiler(IEnumerable<CodeInstruction> instructions)
{
return Transpile.reassemblePatch<MultiPlaceBuilder>(instructions, 25);
}
}
80 changes: 0 additions & 80 deletions plugin/src/camera/patch/builder_reassemble_patch.cs

This file was deleted.

56 changes: 56 additions & 0 deletions plugin/src/util/patch/Transpile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using HarmonyLib;
using Plugin.Input;
using UnityEngine;

namespace TechtonicaVR.Util.Patch;

public class Transpile
{
public static MethodInfo getTransformMethod = typeof(Component).GetMethod("get_transform");
public static MethodInfo getForwardMethod = typeof(Transform).GetMethod("get_forward");

public static MethodInfo getTransformPatchMethod = typeof(Transpile).GetMethod(nameof(patchedGetTransform));
public static MethodInfo getForwardPatchMethod = typeof(Transpile).GetMethod(nameof(PatchedGetForward));

public static IEnumerable<CodeInstruction> reassemblePatch<T>(IEnumerable<CodeInstruction> instructions, int expectedPatchCount = 12)
{
var patchCnt = 0;
foreach (var instruction in instructions)
{
if (instruction.Calls(getTransformMethod))
{
yield return new CodeInstruction(OpCodes.Pop);
yield return new CodeInstruction(OpCodes.Call, getTransformPatchMethod);
patchCnt++;
}
else if (instruction.Calls(getForwardMethod))
{
yield return new CodeInstruction(OpCodes.Pop);
yield return new CodeInstruction(OpCodes.Call, getForwardPatchMethod);
patchCnt++;
}
else
{
yield return instruction;
}
}

if (patchCnt != expectedPatchCount)
{
Plugin.Logger.LogError($"[{typeof(T)}]: Patch count mismatch: {patchCnt} != {expectedPatchCount}");
}
}

public static Transform patchedGetTransform()
{
return SteamVRInputMapper.rightHandObject.transform;
}

public static Vector3 PatchedGetForward()
{
return -SteamVRInputMapper.rightHandObject.transform.up;
}
}

0 comments on commit e628f70

Please sign in to comment.