Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzo committed Jul 24, 2024
1 parent a31d469 commit 371e435
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
1 change: 1 addition & 0 deletions changesets/Boneworks_LootDropBugfix_Minor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added back the fix to stop destructibles being destroyed before level start.
2 changes: 1 addition & 1 deletion projects/Boneworks/LootDropBugfix/Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</Target>

<PropertyGroup>
<CopyIntoGameAfterBuild>true</CopyIntoGameAfterBuild>
<!-- <CopyIntoGameAfterBuild>true</CopyIntoGameAfterBuild> -->

<ProjectGuid>{EAE1410F-B5CF-47D6-8764-2FCAEE822C9D}</ProjectGuid>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
7 changes: 7 additions & 0 deletions projects/Boneworks/LootDropBugfix/restart.bat
Original file line number Diff line number Diff line change
@@ -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"
75 changes: 72 additions & 3 deletions projects/Boneworks/LootDropBugfix/src/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,6 +14,7 @@ public class Mod : MelonMod {

private MelonPreferences_Entry<bool> _prefEnabled;
private AmmoDebugger _ammoDebugger;
private bool _isLoading = false;

public Mod() { Instance = this; }

Expand All @@ -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) {
Expand Down Expand Up @@ -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<RigManager>().Teleport(
new Vector3(-20.1f, 19.0f, -64.6f), Vector3.right);
};
timer.AutoReset = false;
timer.Enabled = true;
}
}
#endif
}

0 comments on commit 371e435

Please sign in to comment.