using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("WaterAudioFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WaterAudioFix")]
[assembly: AssemblyTitle("WaterAudioFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace WaterAudioFix
{
[BepInPlugin("com.jai.wateraudiofix", "Water Audio Fix", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <LoadFixedAudio>d__5 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
private Stream <stream>5__2;
private string <tempPath>5__3;
private UnityWebRequest <www>5__4;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadFixedAudio>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if ((uint)(num - -5) <= 2u || num == 1)
{
try
{
if ((uint)(num - -5) <= 1u || num == 1)
{
try
{
if (num == -5 || num == 1)
{
try
{
}
finally
{
<>m__Finally3();
}
}
}
finally
{
<>m__Finally2();
}
}
}
finally
{
<>m__Finally1();
}
}
<stream>5__2 = null;
<tempPath>5__3 = null;
<www>5__4 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Invalid comparison between Unknown and I4
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
bool result;
try
{
switch (<>1__state)
{
default:
result = false;
break;
case 0:
{
<>1__state = -1;
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = "WaterAudioFix.audio.sfx_river ambience.ogg";
Log.LogInfo((object)"Loading fixed audio...");
<stream>5__2 = executingAssembly.GetManifestResourceStream(text);
<>1__state = -3;
if (<stream>5__2 == null)
{
Log.LogError((object)("Could not find resource: " + text));
result = false;
<>m__Finally1();
break;
}
<tempPath>5__3 = Path.Combine(Path.GetTempPath(), "sfx_river ambience.ogg");
<>1__state = -4;
using (FileStream destination = File.Create(<tempPath>5__3))
{
<stream>5__2.CopyTo(destination);
}
<www>5__4 = UnityWebRequestMultimedia.GetAudioClip("file://" + <tempPath>5__3, (AudioType)14);
<>1__state = -5;
((DownloadHandlerAudioClip)<www>5__4.downloadHandler).streamAudio = false;
<>2__current = <www>5__4.SendWebRequest();
<>1__state = 1;
result = true;
break;
}
case 1:
<>1__state = -5;
if ((int)<www>5__4.result == 1)
{
FixedWaterClip = DownloadHandlerAudioClip.GetContent(<www>5__4);
((Object)FixedWaterClip).name = "sfx_river ambience";
Log.LogInfo((object)$"Fixed audio loaded! Length: {FixedWaterClip.length}s");
}
<>m__Finally3();
<www>5__4 = null;
<>m__Finally2();
<tempPath>5__3 = null;
<>m__Finally1();
<stream>5__2 = null;
result = false;
break;
}
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
return result;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<stream>5__2 != null)
{
((IDisposable)<stream>5__2).Dispose();
}
}
private void <>m__Finally2()
{
<>1__state = -3;
if (File.Exists(<tempPath>5__3))
{
try
{
File.Delete(<tempPath>5__3);
}
catch
{
}
}
}
private void <>m__Finally3()
{
<>1__state = -4;
if (<www>5__4 != null)
{
((IDisposable)<www>5__4).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <ReplaceRiverSound>d__4 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ReplaceRiverSound>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForEndOfFrame();
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
try
{
AudioSource[] array = Resources.FindObjectsOfTypeAll<AudioSource>();
foreach (AudioSource val in array)
{
if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && ((Object)((Component)val).gameObject).name == "RiverSound" && (Object)(object)val.clip != (Object)null)
{
Log.LogInfo((object)("Found RiverSound! Current clip: " + ((Object)val.clip).name));
bool isPlaying = val.isPlaying;
float time = val.time;
val.clip = FixedWaterClip;
if (isPlaying)
{
val.time = time;
val.Play();
}
Log.LogInfo((object)"Successfully replaced river sound!");
}
}
}
catch (Exception arg)
{
Log.LogError((object)$"Error replacing river sound: {arg}");
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
internal static ManualLogSource Log;
internal static AudioClip FixedWaterClip;
private void Awake()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
Log.LogInfo((object)"Water Audio Fix loading...");
((MonoBehaviour)this).StartCoroutine(LoadFixedAudio());
new Harmony("com.jai.wateraudiofix").PatchAll();
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (((Scene)(ref scene)).name == "Island" && (Object)(object)FixedWaterClip != (Object)null)
{
((MonoBehaviour)this).StartCoroutine(ReplaceRiverSound());
}
}
[IteratorStateMachine(typeof(<ReplaceRiverSound>d__4))]
private IEnumerator ReplaceRiverSound()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ReplaceRiverSound>d__4(0);
}
[IteratorStateMachine(typeof(<LoadFixedAudio>d__5))]
private IEnumerator LoadFixedAudio()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadFixedAudio>d__5(0);
}
}
[HarmonyPatch]
public static class AudioSourcePatches
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPrefix]
public static void AudioSource_set_clip_Prefix(AudioSource __instance, ref AudioClip value)
{
try
{
if ((Object)(object)value != (Object)null && ((Object)value).name == "sfx_river ambience" && (Object)(object)Plugin.FixedWaterClip != (Object)null)
{
value = Plugin.FixedWaterClip;
}
}
catch
{
}
}
}
}