From 7124834232d9a6ad9b4571c399685d62d878979e Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Wed, 15 Jun 2022 11:53:19 -0400 Subject: [PATCH] debugging Awake failure --- NewHorizons/Builder/Props/QuantumBuilder.cs | 17 +++++---- NewHorizons/Patches/AudioSignalPatches.cs | 2 +- ...TemporaryDebugOnlyPatchesDeleteBeforePR.cs | 38 +++++++++++++++++++ 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 NewHorizons/Patches/TemporaryDebugOnlyPatchesDeleteBeforePR.cs diff --git a/NewHorizons/Builder/Props/QuantumBuilder.cs b/NewHorizons/Builder/Props/QuantumBuilder.cs index 0d8dfbc8..b3c16e0e 100644 --- a/NewHorizons/Builder/Props/QuantumBuilder.cs +++ b/NewHorizons/Builder/Props/QuantumBuilder.cs @@ -1,3 +1,4 @@ +using HarmonyLib; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using OWML.Common; @@ -55,14 +56,14 @@ namespace NewHorizons.Builder.Props quantumObject._socketRoot = groupRoot; quantumObject._socketList = sockets; - if (prop.GetComponentInChildren() != null) continue; + if (prop.GetComponentInChildren() != null) continue; var boxBounds = GetBoundsOfSelfAndChildMeshes(prop); var boxShape = prop.AddComponent(); boxShape.center = boxBounds.center; boxShape.extents = boxBounds.size; - prop.AddComponent(); + prop.AddComponent(); } } @@ -81,14 +82,14 @@ namespace NewHorizons.Builder.Props var state = prop.AddComponent(); states.Add(state); - if (prop.GetComponentInChildren() != null) continue; + if (prop.GetComponentInChildren() != null) continue; var boxBounds = GetBoundsOfSelfAndChildMeshes(prop); var boxShape = prop.AddComponent(); boxShape.center = boxBounds.center; boxShape.extents = boxBounds.size; - prop.AddComponent(); + prop.AddComponent(); } if (quantumGroup.hasEmptyState) @@ -105,7 +106,7 @@ namespace NewHorizons.Builder.Props boxShape.center = boxBounds.center; boxShape.extents = boxBounds.size; - empty.AddComponent(); + empty.AddComponent(); } var multiState = groupRoot.AddComponent(); @@ -124,16 +125,16 @@ namespace NewHorizons.Builder.Props var shuffle = shuffleParent.AddComponent(); shuffle._shuffledObjects = propsInGroup.Select(p => p.transform).ToArray(); + shuffle.Awake(); // this doesn't get called on its own for some reason - var boxBounds = GetBoundsOfSelfAndChildMeshes(shuffleParent); + var boxBounds = GetBoundsOfSelfAndChildMeshes(shuffleParent); // TODO: add a box shape to each prop instead of to the parent var boxShape = shuffleParent.AddComponent(); boxShape.center = boxBounds.center; boxShape.extents = boxBounds.size; - shuffleParent.AddComponent(); + shuffleParent.AddComponent(); } - public static Bounds GetBoundsOfSelfAndChildMeshes(GameObject g) { var meshFilters = g.GetComponentsInChildren(); diff --git a/NewHorizons/Patches/AudioSignalPatches.cs b/NewHorizons/Patches/AudioSignalPatches.cs index 10fb8640..803bcd41 100644 --- a/NewHorizons/Patches/AudioSignalPatches.cs +++ b/NewHorizons/Patches/AudioSignalPatches.cs @@ -1,4 +1,4 @@ -using HarmonyLib; +using HarmonyLib; using NewHorizons.Builder.Props; using NewHorizons.Components; using NewHorizons.External; diff --git a/NewHorizons/Patches/TemporaryDebugOnlyPatchesDeleteBeforePR.cs b/NewHorizons/Patches/TemporaryDebugOnlyPatchesDeleteBeforePR.cs new file mode 100644 index 00000000..564aa3fe --- /dev/null +++ b/NewHorizons/Patches/TemporaryDebugOnlyPatchesDeleteBeforePR.cs @@ -0,0 +1,38 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public static class TemporaryDebugOnlyPatchesDeleteBeforePR + { + // This is some dark magic + // this creates a method called base_DropItem that basically just calls OWItem.PickUpItem whenever it (VisionTorchItemPatches.base_PickUpItem) is called + [HarmonyReversePatch] + [HarmonyPatch(typeof(QuantumObject), nameof(QuantumObject.Awake))] + private static void base_Awake(QuantumObject __instance) { } + + + // Make the vision torch droppable. In the base game you can only drop it if you're in the dream world. + [HarmonyPrefix] + [HarmonyPatch(typeof(QuantumShuffleObject), nameof(QuantumShuffleObject.Awake))] + public static bool QuantumShuffleObject_Awake(QuantumShuffleObject __instance) + { + base_Awake(__instance); + __instance._indexList = new List(__instance._shuffledObjects.Length); + __instance._localPositions = new Vector3[__instance._shuffledObjects.Length]; + for (int i = 0; i < __instance._shuffledObjects.Length; i++) + { + __instance._localPositions[i] = __instance._shuffledObjects[i].localPosition; + } + + return false; + } + } + +}