From 2cf5e80412896bd10c4975f1835a6f9ad03aa901 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Sat, 26 Dec 2020 12:31:16 -0500 Subject: [PATCH] Add fix for restricted resource placement circumvention --- CLre/Fixes/ExclusionImprovement.cs | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 CLre/Fixes/ExclusionImprovement.cs diff --git a/CLre/Fixes/ExclusionImprovement.cs b/CLre/Fixes/ExclusionImprovement.cs new file mode 100644 index 0000000..5ca1956 --- /dev/null +++ b/CLre/Fixes/ExclusionImprovement.cs @@ -0,0 +1,52 @@ +using System.Globalization; +using System.Reflection; +using HarmonyLib; +using UnityEngine; + +namespace CLre.Fixes +{ + [Bugfix(name = "ExclusionImprovement", + description = "Sync exclusion zone collision check with visual location", + more = "https://trello.com/c/Ue4yIqWQ/11-placing-material-in-restricted-areas", + component = BugfixType.HarmonyPatch, id = 2)] + [HarmonyPatch] + class ExclusionZoneCollisionEngine_TestExclusionZoneCollision_Patch + { + [HarmonyPrefix] + public static void BeforeMethodCall(ref Vector3 structurePosition, ref bool __result) + { + if (ResourcePlacementPreviewEngine_GetLerpPosition_Patch.quantizedPosition != Vector3.zero) + { + structurePosition = ResourcePlacementPreviewEngine_GetLerpPosition_Patch.quantizedPosition; + } + } + + [HarmonyTargetMethod] + public static MethodBase Target() + { + return AccessTools.Method("Game.Building.ExclusionZone.ExclusionZoneCollisionEngine:TestExclusionZoneCollision"); + } + } + + [Bugfix(name = "ExclusionImprovement", + description = "Sync exclusion zone collision check with visual location", + more = "https://trello.com/c/Ue4yIqWQ/11-placing-material-in-restricted-areas", + component = BugfixType.HarmonyPatch, id = 2)] + [HarmonyPatch] + class ResourcePlacementPreviewEngine_GetLerpPosition_Patch + { + internal static Vector3 quantizedPosition = Vector3.zero; + + [HarmonyPrefix] + public static void BeforeMethodCall(ref Vector3 voxelWorldPos, ref Vector3 __result) + { + quantizedPosition = voxelWorldPos; + } + + [HarmonyTargetMethod] + public static MethodBase Target() + { + return AccessTools.Method("Game.Handhelds.ResourcePlacementPreviewEngine:GetLerpPosition"); + } + } +} \ No newline at end of file