Skip to content

Commit

Permalink
Merge branch 'main' into uuh
Browse files Browse the repository at this point in the history
  • Loading branch information
w1n7er87 committed Nov 28, 2023
2 parents 2d639a1 + 5b3764b commit 09e3cab
Show file tree
Hide file tree
Showing 11 changed files with 417 additions and 443 deletions.
Binary file modified Install/BelowZero/BepInEx/plugins/Nautilus/Nautilus.dll
Binary file not shown.
202 changes: 182 additions & 20 deletions Install/BelowZero/BepInEx/plugins/Nautilus/Nautilus.xml

Large diffs are not rendered by default.

Binary file modified Install/Subnautica/BepInEx/plugins/Nautilus/Nautilus.dll
Binary file not shown.
205 changes: 186 additions & 19 deletions Install/Subnautica/BepInEx/plugins/Nautilus/Nautilus.xml

Large diffs are not rendered by default.

117 changes: 18 additions & 99 deletions SCHIZO/Jukebox/NetStreamCompatPatches.BelowZero.cs
Original file line number Diff line number Diff line change
@@ -1,60 +1,36 @@
using System.Collections;
using FMOD;
using FMOD.Studio;
using HarmonyLib;
using UWE;
using BZJukebox = Jukebox;

namespace SCHIZO.Jukebox;

[HarmonyPatch]
public static class NetStreamCompatPatches
{
// the code in this class is dedicated to stopping FMOD/UWE from pausing or seeking the stream
// netstreams don't support it and WILL break

internal static bool UpdateStream(BZJukebox jukebox, CustomJukeboxTrack track)
{
bool CanContinue()
{
if (!track.IsSoundValid(out OPENSTATE state)) return false;
// fix error spam
if (state == OPENSTATE.ERROR) return false;

// can't pause streams
if (jukebox._paused) return false;

// manually stop playback instead of letting FMOD pause due to attenuation
if (BZJukebox.instance && BZJukebox.instance.GetSoundPosition(out _, out float minDistance, out _)
&& minDistance > BZJukebox.maxDistance)
return false;

return true;
}

jukebox._length = 0;
if (!CanContinue())
{
jukebox.StopInternal();
return false;
}
return true;
}

[HarmonyPatch(typeof(BZJukebox), nameof(BZJukebox.SetSnapshotState))]
// netstreams don't support seeking and will commit ERR_INVALID_HANDLE if anything tries to seek them
// this check *might* be a bit heavy to do on every single call but... meh
[HarmonyPatch(typeof(Channel), nameof(Channel.setPosition))]
[HarmonyPrefix]
public static bool DontMuteBecauseItPauses(BZJukebox __instance, EventInstance snapshot, ref bool state, bool value)
public static bool DontSeekNetStreams(Channel __instance)
{
if (!__instance.IsPlayingStream(out _)) return true;
if (!BZJukebox._main || __instance.handle != BZJukebox._main._channel.handle) return true;

return snapshot.handle != __instance.snapshotMute.handle;
return !BZJukebox._main.IsPlayingStream(out _);
}

[HarmonyPatch(typeof(BZJukebox), nameof(BZJukebox.volume), MethodType.Setter)]
[HarmonyPrefix]
public static void PreventZeroVolumePause(ref float value)
internal static bool UpdateStream(BZJukebox jukebox, CustomJukeboxTrack track)
{
if (value == 0) value = 0.001f;
// prevents the sound/channel from turning "virtual"
// when sounds become inaudible, they turn "virtual" and get paused;
// when they become audible again, FMOD seeks them forward - and we can't seek streams
jukebox._channel.setPriority(0);
jukebox._length = 0; // hide it, it's meaningless on streams

// prevent console spam on error
bool canContinue = track.IsSoundValid(out OPENSTATE state) && state != OPENSTATE.ERROR;
if (!canContinue)
jukebox.StopInternal();
return canContinue;
}

[HarmonyPatch(typeof(JukeboxInstance), nameof(JukeboxInstance.UpdateUI))]
Expand All @@ -75,61 +51,4 @@ public static void AdjustUIForHttpStreams(JukeboxInstance __instance)
__instance.SetLabel(isPlaying && hasInfo ? info.label : track.trackLabel);
}
}

[HarmonyPatch(typeof(JukeboxInstance), nameof(JukeboxInstance.OnButtonPlayPause))]
[HarmonyPrefix]
public static bool DisablePauseButtonForHttpStreams(JukeboxInstance __instance)
{
if (!__instance.IsPlayingStream(out _)) return true;
// isControlling essentially means "started playback on this jukebox"
// if it's false, we're definitely not pausing
if (!__instance.isControlling) return true;

// not pause, but stop... it was lie! but the player never know.........
BZJukebox.Stop();
return false;
}

[HarmonyPatch(typeof(IngameMenu), nameof(IngameMenu.OnDeselect))]
[HarmonyPostfix]
public static void AwfulAwfulPauseMenuHack()
{
// just... please pretend this isn't here
// note: the proper solution to this is to download and buffer the netstream ourselves. however comma

if (BZJukebox.main && BZJukebox.main.IsPlayingStream(out _) && BZJukebox.instance)
{
JukeboxInstance instance = BZJukebox.instance;
BZJukebox.Stop();
CoroutineHost.StartCoroutine(Bad(instance));
}

return;

static IEnumerator Bad(JukeboxInstance instance)
{
BZJukebox.main.Release();
yield return null;
BZJukebox.Play(instance);
}
}

[HarmonyPatch(typeof(BZJukebox), nameof(BZJukebox.PlayInternal))]
public static class PreventSeekingSameFileIfStream
{
[HarmonyPrefix]
public static void Prefix(out uint __state)
{
__state = BZJukebox.main._position;
}

[HarmonyPostfix]
public static void Postfix(BZJukebox __instance, uint __state)
{
if (!__instance.IsPlayingStream(out _)) return;

__instance._position = __state;
__instance._positionDirty = false;
}
}
}
15 changes: 12 additions & 3 deletions SCHIZO/Jukebox/TruckersFMUnlockSignal.BelowZero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ public void OnDestroy()

public void OnTrackUnlocked(TrackId trackId)
{
if (!enabled) return;

if (trackId == track)
{
Destroy(gameObject);
return;
DestroySignal();
enabled = false;
}

if (signal) return;
if (customOnly && !CustomJukeboxTrack.TryGetCustomTrack(trackId, out CustomJukeboxTrack _)) return;

Expand All @@ -61,10 +64,16 @@ private void CreateSignal()
signal.pos = track.diskSpawnLocation.position;
}

private void DestroySignal()
{
if (signal) Destroy(signal.gameObject);
}

private void Reset()
{
unlockedTracks = 0;
if (signal) Destroy(signal.gameObject);
enabled = true;
DestroySignal();
}

[HarmonyPatch(typeof(BZJukebox), nameof(BZJukebox.OnUnlock))]
Expand Down
Loading

0 comments on commit 09e3cab

Please sign in to comment.