using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MrokNadchodzi")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MrokNadchodzi")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dd95be33-0b92-4e5b-ae6e-4febf59ebf12")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("czekoloczek.peak.mroknadchodzi", "Mrok Nadchodzi", "1.0.3")]
public class PeakMod : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <LoadAudio>d__2 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public PeakMod <>4__this;
private WWW <www>5__2;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadAudio>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<www>5__2 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
try
{
int num = <>1__state;
PeakMod peakMod = <>4__this;
switch (num)
{
default:
return false;
case 0:
{
<>1__state = -1;
string text = "file://" + Paths.PluginPath + "/Czekoloczek-Mrok_Nadchodzi/replacement.ogg";
<www>5__2 = new WWW(text);
<>1__state = -3;
<>2__current = <www>5__2;
<>1__state = 1;
return true;
}
case 1:
<>1__state = -3;
peakMod.replacementClip = <www>5__2.GetAudioClip(false, false, (AudioType)14);
<>m__Finally1();
<www>5__2 = null;
return false;
}
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
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 (<www>5__2 != null)
{
((IDisposable)<www>5__2).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <ReplaceAudio>d__4 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public PeakMod <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ReplaceAudio>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
int num = <>1__state;
PeakMod peakMod = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(1f);
<>1__state = 1;
return true;
case 1:
{
<>1__state = -1;
GameObject val = GameObject.Find("GAME/GUIManager/Canvas_HUD/TheFogRises/SFX");
if ((Object)(object)val != (Object)null && (Object)(object)peakMod.replacementClip != (Object)null)
{
AudioSource component = val.GetComponent<AudioSource>();
if ((Object)(object)component != (Object)null)
{
component.clip = peakMod.replacementClip;
((BaseUnityPlugin)peakMod).Logger.LogInfo((object)"Dźwięk został podmieniony.");
}
}
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();
}
}
private AudioClip replacementClip;
private void Awake()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"Mrok nadchodzi was loaded!");
new Harmony("com.czekoloczek.peakmod.mroknadchodzi").PatchAll();
SceneManager.sceneLoaded += OnSceneLoaded;
((MonoBehaviour)this).StartCoroutine(LoadAudio());
}
[IteratorStateMachine(typeof(<LoadAudio>d__2))]
private IEnumerator LoadAudio()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadAudio>d__2(0)
{
<>4__this = this
};
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (Regex.IsMatch(((Scene)(ref scene)).name, "^Level_\\d+$"))
{
((MonoBehaviour)this).StartCoroutine(ReplaceAudio());
}
}
[IteratorStateMachine(typeof(<ReplaceAudio>d__4))]
private IEnumerator ReplaceAudio()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ReplaceAudio>d__4(0)
{
<>4__this = this
};
}
}
[HarmonyPatch]
public static class LocalizedText_RefreshText_Patch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.TypeByName("LocalizedText"), "RefreshText", (Type[])null, (Type[])null);
}
private static void Postfix(object __instance)
{
Component val = (Component)((__instance is Component) ? __instance : null);
if ((Object)(object)val != (Object)null && (Object)(object)val.gameObject != (Object)null && val.gameObject.transform.GetHierarchyPath().EndsWith("GAME/GUIManager/Canvas_HUD/TheFogRises/Fog"))
{
TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
if ((Object)(object)component != (Object)null)
{
((TMP_Text)component).text = "MROK NADCHODZI...";
}
}
}
}
public static class TransformExtensions
{
public static string GetHierarchyPath(this Transform transform)
{
string text = ((Object)transform).name;
while ((Object)(object)transform.parent != (Object)null)
{
transform = transform.parent;
text = ((Object)transform).name + "/" + text;
}
return text;
}
public static string GetHierarchyPath(this GameObject go)
{
return go.transform.GetHierarchyPath();
}
}