From 735b375f234ecaf9a8a30f3fa54f0679c476aed8 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 6 Oct 2022 00:28:50 -0700 Subject: [PATCH] add a silly little patch --- QSB/GetAttachedOWRigidbodyPatch.cs | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 QSB/GetAttachedOWRigidbodyPatch.cs diff --git a/QSB/GetAttachedOWRigidbodyPatch.cs b/QSB/GetAttachedOWRigidbodyPatch.cs new file mode 100644 index 00000000..7ee82ab1 --- /dev/null +++ b/QSB/GetAttachedOWRigidbodyPatch.cs @@ -0,0 +1,43 @@ +using HarmonyLib; +using QSB.Patches; +using UnityEngine; + +namespace QSB; + +/// +/// TODO: TEST THIS. see if things horribly break. this could be huge. +/// +[HarmonyPatch(typeof(OWExtensions))] +public class GetAttachedOWRigidbodyPatch : QSBPatch +{ + public override QSBPatchTypes Type => QSBPatchTypes.OnModStart; + + [HarmonyPrefix] + [HarmonyPatch(nameof(OWExtensions.GetAttachedOWRigidbody), typeof(GameObject), typeof(bool))] + private static bool GetAttachedOWRigidbody(GameObject obj, bool ignoreThisTransform, out OWRigidbody __result) + { + OWRigidbody owrigidbody = null; + var transform = obj.transform; + if (ignoreThisTransform) + { + transform = obj.transform.parent; + } + while (owrigidbody == null) + { + owrigidbody = transform.GetComponent(); + /* + if (owrigidbody != null && !owrigidbody.gameObject.activeInHierarchy) + { + owrigidbody = null; + } + */ + if ((transform == obj.transform.root && owrigidbody == null) || owrigidbody != null) + { + break; + } + transform = transform.parent; + } + __result = owrigidbody; + return false; + } +}