From 371e43517e939ed1812052bb977eabedffca6116 Mon Sep 17 00:00:00 2001 From: jakzo Date: Wed, 24 Jul 2024 12:40:24 +1000 Subject: [PATCH] fix --- changesets/Boneworks_LootDropBugfix_Minor.md | 1 + .../Boneworks/LootDropBugfix/Project.csproj | 2 +- projects/Boneworks/LootDropBugfix/restart.bat | 7 ++ projects/Boneworks/LootDropBugfix/src/Mod.cs | 75 ++++++++++++++++++- 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 changesets/Boneworks_LootDropBugfix_Minor.md create mode 100644 projects/Boneworks/LootDropBugfix/restart.bat diff --git a/changesets/Boneworks_LootDropBugfix_Minor.md b/changesets/Boneworks_LootDropBugfix_Minor.md new file mode 100644 index 0000000..df27bcd --- /dev/null +++ b/changesets/Boneworks_LootDropBugfix_Minor.md @@ -0,0 +1 @@ +Added back the fix to stop destructibles being destroyed before level start. diff --git a/projects/Boneworks/LootDropBugfix/Project.csproj b/projects/Boneworks/LootDropBugfix/Project.csproj index 2ae651b..c8ead29 100644 --- a/projects/Boneworks/LootDropBugfix/Project.csproj +++ b/projects/Boneworks/LootDropBugfix/Project.csproj @@ -6,7 +6,7 @@ - true + {EAE1410F-B5CF-47D6-8764-2FCAEE822C9D} true diff --git a/projects/Boneworks/LootDropBugfix/restart.bat b/projects/Boneworks/LootDropBugfix/restart.bat new file mode 100644 index 0000000..245c7ef --- /dev/null +++ b/projects/Boneworks/LootDropBugfix/restart.bat @@ -0,0 +1,7 @@ +@echo off + +taskkill /F /IM BONEWORKS.exe +dotnet build +@REM timeout /T 2 /NOBREAK > NUL +cd /d "C:\Program Files (x86)\Steam\steamapps\common\BONEWORKS\BONEWORKS" +start "" "BONEWORKS.exe" diff --git a/projects/Boneworks/LootDropBugfix/src/Mod.cs b/projects/Boneworks/LootDropBugfix/src/Mod.cs index 902d4e3..cfa1fdc 100644 --- a/projects/Boneworks/LootDropBugfix/src/Mod.cs +++ b/projects/Boneworks/LootDropBugfix/src/Mod.cs @@ -2,7 +2,10 @@ using HarmonyLib; using UnityEngine; using StressLevelZero.Data; -using System.Linq; +using Valve.VR; +using StressLevelZero.Props; +using StressLevelZero.Utilities; +using StressLevelZero.Rig; namespace Sst.LootDropBugfix; @@ -11,6 +14,7 @@ public class Mod : MelonMod { private MelonPreferences_Entry _prefEnabled; private AmmoDebugger _ammoDebugger; + private bool _isLoading = false; public Mod() { Instance = this; } @@ -21,8 +25,18 @@ public override void OnApplicationStart() { _ammoDebugger = new AmmoDebugger(prefCategory); } - public override void OnSceneWasInitialized(int buildIndex, string sceneName) { - _ammoDebugger.OnLevelStart(); + // TODO: Find way which works in Oculus too + [HarmonyPatch(typeof(CVRCompositor), nameof(CVRCompositor.FadeGrid))] + class CVRCompositor_FadeGrid_Patch { + [HarmonyPrefix()] + internal static void Prefix(bool bFadeIn) { + if (bFadeIn) { + Instance._isLoading = true; + } else { + Instance._isLoading = false; + Instance._ammoDebugger.OnLevelStart(); + } + } } public static SpawnableObject GetLootItemFixed(LootTableData lootTable) { @@ -57,4 +71,59 @@ internal static void Postfix(LootTableData __instance, Instance._ammoDebugger.OnGetLootItem(__instance, __result); } } + + // Fixes missing bonebox in runoff + // name = dest_Crate_Lite_1m Boneworks (2) + // save item uuid = 13cc9af0-32e7-44a1-a91c-ba2ae3bc1717 + // spawnable title = Capsule Omni Turret + // spawnable uuid = af0d2c47-f9c9-4323-be80-48ff071eeb37 + [HarmonyPatch(typeof(ObjectDestructable), + nameof(ObjectDestructable.TakeDamage))] + class ObjectDestructable_TakeDamage_Patch { + [HarmonyPrefix()] + internal static void Prefix(ObjectDestructable __instance, float damage, + ref float __state) { + if (!Instance._isLoading) + return; + if (damage > __instance._health) + Dbg.Log( + $"Item would have broken but is indestructible before load: {__instance.name}"); + __state = __instance._health; + __instance._health = float.PositiveInfinity; + } + + [HarmonyFinalizer()] + internal static void Finalizer(ObjectDestructable __instance, + float __state) { + if (!Instance._isLoading) + return; + __instance._health = __state; + } + } + +// RUNOFF BONEBOX TESTING +#if DEBUG + public override void OnSceneWasInitialized(int buildIndex, string sceneName) { + if (buildIndex == 1) { + Dbg.Log("Menu loaded"); + var timer = new System.Timers.Timer(2000); + timer.Elapsed += (x, y) => { + Dbg.Log("Loading runoff"); + BoneworksSceneManager.LoadScene("Runoff"); + }; + timer.AutoReset = false; + timer.Enabled = true; + } else if (buildIndex == 6) { + Dbg.Log("Runoff loaded"); + var timer = new System.Timers.Timer(1000); + timer.Elapsed += (x, y) => { + Dbg.Log("Teleporting"); + GameObject.FindObjectOfType().Teleport( + new Vector3(-20.1f, 19.0f, -64.6f), Vector3.right); + }; + timer.AutoReset = false; + timer.Enabled = true; + } + } +#endif }