-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(input): 🔒 multi place builder patches
- Loading branch information
Showing
8 changed files
with
127 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
"input", | ||
"render", | ||
"ui", | ||
"player" | ||
"player", | ||
"game" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
plugin/src/camera/patch/builder/builder_reassemble_patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
plugin/src/camera/patch/builder/multi_place_builder_patch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |