From c60ce8d615bee40729e8d87bcced6874ee35198c Mon Sep 17 00:00:00 2001 From: Govorunb Date: Sat, 20 Apr 2024 07:17:17 +1000 Subject: [PATCH] fix sea monkey fumo positioning --- .../Components/SeaMonkeyHeldItemOverrides.cs | 27 +++++++++++ ...onkeyHeldItemOverridesPatches.BelowZero.cs | 28 +++++++++++ .../Mod/Evil Fumo/Evil Fumo item.prefab | 47 ++++++++++++++----- .../Mod/Neurofumo/Neurofumo item.prefab | 21 +++++++++ .../Components/SeaMonkeyHeldItemOverrides.cs | 32 +++++++++++++ .../SeaMonkeyHeldItemOverrides.cs.meta | 11 +++++ 6 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs create mode 100644 SCHIZO/Items/Components/SeaMonkeyHeldItemOverridesPatches.BelowZero.cs create mode 100644 Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs create mode 100644 Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs.meta diff --git a/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs b/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs new file mode 100644 index 00000000..73bb80e3 --- /dev/null +++ b/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs @@ -0,0 +1,27 @@ +using UnityEngine; + +namespace SCHIZO.Items.Components; + +partial class SeaMonkeyHeldItemOverrides +{ + private Vector3 _savedLocalPos; + private Quaternion _savedLocalRot; + public void OnPickedUp() + { + if (!enabled) return; + + _savedLocalPos = overrideTransform.localPosition; + _savedLocalRot = overrideTransform.localRotation; + + overrideTransform.localPosition = localPosition; + overrideTransform.localEulerAngles = localRotation; + } + + public void OnDropped() + { + if (!enabled) return; + + overrideTransform.localPosition = _savedLocalPos; + overrideTransform.localRotation = _savedLocalRot; + } +} diff --git a/SCHIZO/Items/Components/SeaMonkeyHeldItemOverridesPatches.BelowZero.cs b/SCHIZO/Items/Components/SeaMonkeyHeldItemOverridesPatches.BelowZero.cs new file mode 100644 index 00000000..1df7cb36 --- /dev/null +++ b/SCHIZO/Items/Components/SeaMonkeyHeldItemOverridesPatches.BelowZero.cs @@ -0,0 +1,28 @@ +using HarmonyLib; + +namespace SCHIZO.Items.Components; +[HarmonyPatch] +public static class SeaMonkeyHeldItemOverridesPatches +{ + [HarmonyPatch(typeof(SeaMonkeyHeldItem), nameof(SeaMonkeyHeldItem.Hold), [typeof(Pickupable), typeof(bool)])] + [HarmonyPostfix] + public static void OnHold(Pickupable pickupable) + { + if (!pickupable) return; + SeaMonkeyHeldItemOverrides overrideComponent = pickupable.GetComponent(); + if (!overrideComponent) return; + + overrideComponent.OnPickedUp(); + } + + [HarmonyPatch(typeof(SeaMonkeyHeldItem), nameof(SeaMonkeyHeldItem.Drop))] + [HarmonyPrefix] + public static void OnDrop(SeaMonkeyHeldItem __instance) + { + if (!__instance.item) return; + SeaMonkeyHeldItemOverrides overrideComponent = __instance.item.GetComponent(); + if (!overrideComponent) return; + + overrideComponent.OnDropped(); + } +} diff --git a/Unity/Assets/Mod/Evil Fumo/Evil Fumo item.prefab b/Unity/Assets/Mod/Evil Fumo/Evil Fumo item.prefab index 1ba4ba5b..e56112c9 100644 --- a/Unity/Assets/Mod/Evil Fumo/Evil Fumo item.prefab +++ b/Unity/Assets/Mod/Evil Fumo/Evil Fumo item.prefab @@ -1,18 +1,5 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: ---- !u!65 &4332142020512149085 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 3050323588128677620} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Size: {x: 4.0000005, y: 4.3434496, z: 3.2994847} - m_Center: {x: -0, y: 2.1420708, z: -0.17539322} --- !u!1 &4427810026626581335 GameObject: m_ObjectHideFlags: 0 @@ -177,6 +164,21 @@ MonoBehaviour: m_EditorClassIdentifier: propModel: {fileID: 853428788585080163} viewModel: {fileID: 7656616662938203038} +--- !u!114 &7732719034029743030 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5958827312421353464} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: def191360849e4c4eb0083d03d029b81, type: 3} + m_Name: + m_EditorClassIdentifier: + overrideTransform: {fileID: 4242091266149702868} + localPosition: {x: 0, y: 0, z: 0} + localRotation: {x: -40, y: 0, z: 30} --- !u!114 &5518736193718426385 MonoBehaviour: m_ObjectHideFlags: 0 @@ -197,6 +199,19 @@ MonoBehaviour: _fabricatorMesh: {fileID: 4300000, guid: f02dbf41adbb6c14c8b2eb4704e4fd18, type: 2} _fabricatorPrefab: {fileID: 4931248133309480, guid: 18b270460e531e34ca5ebc989dccd026, type: 3} +--- !u!65 &4332142020512149085 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3050323588128677620} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 4.0000005, y: 4.3434496, z: 3.2994847} + m_Center: {x: -0, y: 2.1420708, z: -0.17539322} --- !u!1001 &8219148621552729296 PrefabInstance: m_ObjectHideFlags: 0 @@ -339,6 +354,12 @@ GameObject: type: 3} m_PrefabInstance: {fileID: 8219148621552729296} m_PrefabAsset: {fileID: 0} +--- !u!4 &4242091266149702868 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 5246314888156504068, guid: 494d51939a4d56f47a65310c2d52e286, + type: 3} + m_PrefabInstance: {fileID: 8219148621552729296} + m_PrefabAsset: {fileID: 0} --- !u!1 &2059160104811668376 stripped GameObject: m_CorrespondingSourceObject: {fileID: 7963440748852813640, guid: 494d51939a4d56f47a65310c2d52e286, diff --git a/Unity/Assets/Mod/Neurofumo/Neurofumo item.prefab b/Unity/Assets/Mod/Neurofumo/Neurofumo item.prefab index 0c5d69fa..8fa04d77 100644 --- a/Unity/Assets/Mod/Neurofumo/Neurofumo item.prefab +++ b/Unity/Assets/Mod/Neurofumo/Neurofumo item.prefab @@ -58,6 +58,21 @@ MonoBehaviour: underwaterDrag: 0.5 handleWind: 0 windScalar: 1 +--- !u!114 &4318481871196627161 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 5527787040625736568} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: def191360849e4c4eb0083d03d029b81, type: 3} + m_Name: + m_EditorClassIdentifier: + overrideTransform: {fileID: 6978155363206644661} + localPosition: {x: 0, y: 0, z: 0} + localRotation: {x: 0, y: 0, z: 0} --- !u!114 &5550508841886641735 MonoBehaviour: m_ObjectHideFlags: 0 @@ -266,6 +281,12 @@ GameObject: type: 3} m_PrefabInstance: {fileID: 5020507161881458003} m_PrefabAsset: {fileID: 0} +--- !u!4 &6978155363206644661 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 2700769981969528550, guid: 5a15aed96d8d1b84592bfbe203825ee4, + type: 3} + m_PrefabInstance: {fileID: 5020507161881458003} + m_PrefabAsset: {fileID: 0} --- !u!1 &3170597382691848538 stripped GameObject: m_CorrespondingSourceObject: {fileID: 7614554720012481545, guid: 5a15aed96d8d1b84592bfbe203825ee4, diff --git a/Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs b/Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs new file mode 100644 index 00000000..8c278873 --- /dev/null +++ b/Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs @@ -0,0 +1,32 @@ +#if UNITY_EDITOR +using SCHIZO.Interop.Subnautica.Enums; +#endif +using TriInspector; +using UnityEngine; + +namespace SCHIZO.Items.Components +{ + [AddComponentMenu("SCHIZO/Sea Monkey Held Item Overrides")] + public sealed partial class SeaMonkeyHeldItemOverrides : MonoBehaviour + { + [InfoBox("When a sea monkey grabs this object, temporarily set the target transform's local position and rotation.\n" + + "Use this to fix misaligned items.")] + public Transform overrideTransform; + public Vector3 localPosition; + public Vector3 localRotation; + +#if UNITY_EDITOR + private void OnValidate() + { + if (!enabled) return; + + Component ecoTarget = GetComponent("EcoTarget"); + EcoTargetType_All type = (EcoTargetType_All)HarmonyLib.AccessTools.Field(ecoTarget.GetType(), "type").GetValue(ecoTarget); + if (type != EcoTargetType_All.Shiny) + Debug.LogWarning("Sea monkeys only steal Shiny items, so these overrides are useless"); + } + private void OnDisable() {} + private void OnEnable() {} +#endif + } +} diff --git a/Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs.meta b/Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs.meta new file mode 100644 index 00000000..048167de --- /dev/null +++ b/Unity/Assets/Scripts/SCHIZO/Items/Components/SeaMonkeyHeldItemOverrides.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: def191360849e4c4eb0083d03d029b81 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: