using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[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("PeakPauseMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeakPauseMod")]
[assembly: AssemblyTitle("PeakPauseMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[HarmonyPatch(typeof(EndScreen), "EndSequenceRoutine")]
public class EndscreenPatch
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static UnityAction <>9__0_1;
public static UnityAction <>9__0_2;
internal void <Postfix>b__0_1()
{
Process.Start("https://www.instagram.com/codeburstdev");
}
internal void <Postfix>b__0_2()
{
Process.Start("https://www.gofundme.com/f/worldhopper-startup");
}
}
private static void Postfix()
{
//IL_0248: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Expected O, but got Unknown
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Expected O, but got Unknown
//IL_0300: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Expected O, but got Unknown
string path = Path.Combine(Paths.PluginPath, "CodeBurst-MultiplayerPause/seendonationcanvas");
if (File.Exists(path))
{
return;
}
AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Paths.PluginPath, "CodeBurst-MultiplayerPause/multiplayerpausedonationcanvas"));
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"[PeakPauseMod] Donation Canvas bundle niet gevonden.");
return;
}
GameObject val2 = val.LoadAsset<GameObject>("MultiplayerPauseDonationCanvas");
if ((Object)(object)val2 == (Object)null)
{
Debug.LogError((object)"[PeakPauseMod] Donation Canvas prefab niet gevonden in bundle.");
return;
}
GameObject canvasInstance = Object.Instantiate<GameObject>(val2);
Object.DontDestroyOnLoad((Object)(object)canvasInstance);
GameObject val3 = GameObject.Find("GAME/GUIManager/Canvas_End/Panel/Margin/SCOUTING_REPORT");
if ((Object)(object)val3 != (Object)null)
{
TextMeshProUGUI component = val3.GetComponent<TextMeshProUGUI>();
if ((Object)(object)component != (Object)null)
{
TextMeshProUGUI[] componentsInChildren = canvasInstance.GetComponentsInChildren<TextMeshProUGUI>(true);
foreach (TextMeshProUGUI obj in componentsInChildren)
{
((TMP_Text)obj).font = ((TMP_Text)component).font;
((TMP_Text)obj).fontSharedMaterial = ((TMP_Text)component).fontSharedMaterial;
((TMP_Text)obj).fontMaterial = ((TMP_Text)component).fontMaterial;
}
Debug.Log((object)"[PeakPauseMod] Font & materiaal gekopieerd van SCOUTING_REPORT.");
}
else
{
Debug.LogWarning((object)"[PeakPauseMod] SCOUTING_REPORT heeft geen TextMeshProUGUI component.");
}
}
else
{
Debug.LogWarning((object)"[PeakPauseMod] Kon SCOUTING_REPORT object niet vinden.");
}
Renderer[] componentsInChildren2 = canvasInstance.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val4 in componentsInChildren2)
{
Material[] sharedMaterials = val4.sharedMaterials;
for (int j = 0; j < sharedMaterials.Length; j++)
{
if (!((Object)(object)sharedMaterials[j] == (Object)null) && !((Object)(object)sharedMaterials[j].shader == (Object)null))
{
string name = ((Object)sharedMaterials[j].shader).name;
Shader val5 = Shader.Find(name);
if ((Object)(object)val5 != (Object)null)
{
sharedMaterials[j].shader = val5;
}
else
{
Debug.LogWarning((object)("Shader " + name + " not found!"));
}
}
}
val4.materials = sharedMaterials;
}
GameObject canvasEnd = GameObject.Find("GAME/GUIManager/Canvas_End");
if ((Object)(object)canvasEnd != (Object)null)
{
canvasEnd.SetActive(false);
}
else
{
Debug.LogWarning((object)"[PeakPauseMod] Canvas_End niet gevonden.");
}
Transform val6 = canvasInstance.transform.Find("Panel/Close");
if ((Object)(object)val6 != (Object)null)
{
Button component2 = ((Component)val6).GetComponent<Button>();
if ((Object)(object)component2 != (Object)null)
{
((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
{
if ((Object)(object)canvasEnd != (Object)null)
{
canvasEnd.SetActive(true);
}
Object.Destroy((Object)(object)canvasInstance);
});
}
}
Transform val7 = canvasInstance.transform.Find("Panel/Insta");
if ((Object)(object)val7 != (Object)null)
{
Button component3 = ((Component)val7).GetComponent<Button>();
if ((Object)(object)component3 != (Object)null)
{
ButtonClickedEvent onClick = component3.onClick;
object obj2 = <>c.<>9__0_1;
if (obj2 == null)
{
UnityAction val8 = delegate
{
Process.Start("https://www.instagram.com/codeburstdev");
};
<>c.<>9__0_1 = val8;
obj2 = (object)val8;
}
((UnityEvent)onClick).AddListener((UnityAction)obj2);
}
}
Transform val9 = canvasInstance.transform.Find("Panel/GoFundMe");
if ((Object)(object)val9 != (Object)null)
{
Button component4 = ((Component)val9).GetComponent<Button>();
if ((Object)(object)component4 != (Object)null)
{
ButtonClickedEvent onClick2 = component4.onClick;
object obj3 = <>c.<>9__0_2;
if (obj3 == null)
{
UnityAction val10 = delegate
{
Process.Start("https://www.gofundme.com/f/worldhopper-startup");
};
<>c.<>9__0_2 = val10;
obj3 = (object)val10;
}
((UnityEvent)onClick2).AddListener((UnityAction)obj3);
}
}
try
{
File.WriteAllText(path, "seen");
}
catch (Exception value)
{
Debug.LogError((object)$"[PeakPauseMod] Kon markerbestand niet aanmaken: {value}");
}
}
}
[BepInPlugin("com.codeburst.pausemod", "Pause Mod", "1.0.6")]
public class PauseMod : BaseUnityPlugin
{
private static bool isPaused;
private static GameObject fogSphere;
private static GameObject snowStorm;
private static float[] originalMovementForces;
private static GameObject pauseUiInstance;
private static AssetBundle pauseUiBundle;
private static AssetBundle dontationCanvasBundle;
private static PhotonView photonView;
private void Start()
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Expected O, but got Unknown
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
try
{
pauseUiBundle = AssetBundle.LoadFromFile(Path.Combine(Paths.PluginPath, "CodeBurst-MultiplayerPause/multiplayerpausepopup"));
if ((Object)(object)pauseUiBundle == (Object)null)
{
Debug.LogError((object)"PauseMod: Failed to load asset bundle!");
}
else
{
Debug.Log((object)"PauseMod: Asset bundle loaded.");
}
if ((Object)(object)dontationCanvasBundle == (Object)null)
{
Debug.LogError((object)"PauseMod: Failed to load donation asset bundle!");
}
else
{
Debug.Log((object)"PauseMod: Donation Asset bundle loaded.");
}
}
catch (Exception value)
{
Debug.LogError((object)$"PauseMod: Error loading asset bundle: {value}");
}
GameObject val = new GameObject("PauseMod_NetworkSync");
Object.DontDestroyOnLoad((Object)val);
photonView = val.AddComponent<PhotonView>();
val.AddComponent<PauseNetworkReceiver>();
photonView.ViewID = 9999;
new Harmony("com.codeburst.pausemod").PatchAll();
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)112))
{
if (!PhotonNetwork.IsMasterClient)
{
Debug.Log((object)"PauseMod: Only the host can toggle pause.");
return;
}
isPaused = !isPaused;
Debug.Log((object)$"PauseMod: Host toggled pause: {isPaused}");
photonView.RPC("RPC_SetPaused", (RpcTarget)0, new object[1] { isPaused });
}
}
public static void ApplyPauseState(bool pause)
{
isPaused = pause;
Debug.Log((object)"PauseMod: Applying pause state...");
try
{
foreach (MonoBehaviour item in from x in Object.FindObjectsOfType<MonoBehaviour>()
where ((object)x).GetType().Name == "MainCameraMovement"
select x)
{
if ((Object)(object)item != (Object)null)
{
((Behaviour)item).enabled = !pause;
}
}
}
catch (Exception value)
{
Debug.LogError((object)$"PauseMod: Error with CharacterVineClimbing: {value}");
}
try
{
CharacterAfflictions[] array = Object.FindObjectsByType<CharacterAfflictions>((FindObjectsSortMode)0);
foreach (CharacterAfflictions val in array)
{
if ((Object)(object)val != (Object)null)
{
((Behaviour)val).enabled = !pause;
}
}
}
catch (Exception value2)
{
Debug.LogError((object)$"PauseMod: Error with CharacterAfflictions: {value2}");
}
try
{
CharacterClimbing[] array2 = Object.FindObjectsByType<CharacterClimbing>((FindObjectsSortMode)0);
foreach (CharacterClimbing val2 in array2)
{
if ((Object)(object)val2 != (Object)null)
{
((Behaviour)val2).enabled = !pause;
}
}
}
catch (Exception value3)
{
Debug.LogError((object)$"PauseMod: Error with CharacterClimbing: {value3}");
}
try
{
CharacterRopeHandling[] array3 = Object.FindObjectsByType<CharacterRopeHandling>((FindObjectsSortMode)0);
foreach (CharacterRopeHandling val3 in array3)
{
if ((Object)(object)val3 != (Object)null)
{
((Behaviour)val3).enabled = !pause;
}
}
}
catch (Exception value4)
{
Debug.LogError((object)$"PauseMod: Error with CharacterRopeHandling: {value4}");
}
try
{
CharacterVineClimbing[] array4 = Object.FindObjectsByType<CharacterVineClimbing>((FindObjectsSortMode)0);
foreach (CharacterVineClimbing val4 in array4)
{
if ((Object)(object)val4 != (Object)null)
{
((Behaviour)val4).enabled = !pause;
}
}
}
catch (Exception value5)
{
Debug.LogError((object)$"PauseMod: Error with CharacterVineClimbing: {value5}");
}
try
{
CharacterMovement[] array5 = Object.FindObjectsByType<CharacterMovement>((FindObjectsSortMode)0);
if (originalMovementForces == null || originalMovementForces.Length != array5.Length)
{
originalMovementForces = new float[array5.Length];
}
for (int j = 0; j < array5.Length; j++)
{
CharacterMovement val5 = array5[j];
if (!((Object)(object)val5 == (Object)null))
{
if (pause)
{
originalMovementForces[j] = val5.movementForce;
val5.movementForce = 0f;
}
else
{
val5.movementForce = originalMovementForces[j];
}
}
}
}
catch (Exception value6)
{
Debug.LogError((object)$"PauseMod: Error with CharacterMovement: {value6}");
}
try
{
foreach (GameObject item2 in from go in Object.FindObjectsOfType<GameObject>()
where ((Object)go).name.Contains("Scout")
select go)
{
Transform val6 = item2.transform.Find("Armature");
Transform val7 = item2.transform.Find("SFX");
if ((Object)(object)val6 != (Object)null)
{
((Component)val6).gameObject.SetActive(!pause);
}
if ((Object)(object)val7 != (Object)null)
{
((Component)val7).gameObject.SetActive(!pause);
}
}
}
catch (Exception value7)
{
Debug.LogError((object)$"PauseMod: Error toggling Scout Armature/SFX: {value7}");
}
try
{
foreach (MonoBehaviour item3 in from x in Object.FindObjectsOfType<MonoBehaviour>()
where ((object)x).GetType().Name == "OrbFogHandler"
select x)
{
if ((Object)(object)item3 != (Object)null)
{
((Behaviour)item3).enabled = !pause;
}
}
}
catch (Exception value8)
{
Debug.LogError((object)$"PauseMod: Error with CharacterVineClimbing: {value8}");
}
try
{
WindChillZone[] array6 = Object.FindObjectsByType<WindChillZone>((FindObjectsSortMode)0);
foreach (WindChillZone val8 in array6)
{
if ((Object)(object)val8 != (Object)null)
{
((Behaviour)val8).enabled = !pause;
}
}
}
catch (Exception value9)
{
Debug.LogError((object)$"PauseMod: Error with CharacterRopeHandling: {value9}");
}
try
{
GameObject val9 = GameObject.Find("LavaField");
if ((Object)(object)val9 != (Object)null)
{
Transform val10 = val9.transform.Find("River");
if ((Object)(object)val10 != (Object)null)
{
Animator component = ((Component)val10).GetComponent<Animator>();
if ((Object)(object)component != (Object)null)
{
((Behaviour)component).enabled = !pause;
Debug.Log((object)"Animator on LavaField/River effected by pause.");
}
else
{
Debug.LogWarning((object)"Animator component not found on River.");
}
}
else
{
Debug.LogWarning((object)"Child 'River' not found under LavaField.");
}
}
else
{
Debug.LogWarning((object)"GameObject 'LavaField' not found.");
}
}
catch (Exception ex)
{
Debug.LogError((object)("Error disabling LavaField River Animator: " + ex));
}
try
{
GameObject val11 = GameObject.Find("LavaField");
if ((Object)(object)val11 != (Object)null)
{
Transform val12 = val11.transform.Find("River");
if ((Object)(object)val12 != (Object)null)
{
Animator component2 = ((Component)val12).GetComponent<Animator>();
if ((Object)(object)component2 != (Object)null)
{
((Behaviour)component2).enabled = false;
Debug.Log((object)"Animator on LavaField/River disabled.");
}
else
{
Debug.LogWarning((object)"Animator component not found on River.");
}
}
else
{
Debug.LogWarning((object)"Child 'River' not found under LavaField.");
}
}
else
{
Debug.LogWarning((object)"GameObject 'LavaField' not found.");
}
}
catch (Exception ex2)
{
Debug.LogError((object)("Error disabling LavaField River Animator: " + ex2));
}
try
{
if (pause)
{
if ((Object)(object)pauseUiBundle != (Object)null && (Object)(object)pauseUiInstance == (Object)null)
{
GameObject val13 = pauseUiBundle.LoadAsset<GameObject>("PauseNoticeUI");
if ((Object)(object)val13 != (Object)null)
{
pauseUiInstance = Object.Instantiate<GameObject>(val13);
Object.DontDestroyOnLoad((Object)(object)pauseUiInstance);
}
}
}
else if ((Object)(object)pauseUiInstance != (Object)null)
{
Object.Destroy((Object)(object)pauseUiInstance);
pauseUiInstance = null;
}
}
catch (Exception value10)
{
Debug.LogError((object)$"PauseMod: Error with pause UI: {value10}");
}
}
}
public class PauseNetworkReceiver : MonoBehaviourPun
{
[PunRPC]
public void RPC_SetPaused(bool pause)
{
Debug.Log((object)$"PauseNetworkReceiver: RPC_SetPaused({pause}) received.");
PauseMod.ApplyPauseState(pause);
}
}