using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using PimDeWitte.UnityMainThreadDispatcher;
using UnityEngine;
using Zorro.Core;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LastDayLostCameraFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d4f775179351899668666ca7c3f179597c655911")]
[assembly: AssemblyProduct("LastDayLostCameraFix")]
[assembly: AssemblyTitle("LastDayLostCameraFix")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 PimDeWitte.UnityMainThreadDispatcher
{
public class UnityMainThreadDispatcher : MonoBehaviour
{
private static readonly Queue<Action> _executionQueue = new Queue<Action>();
private static UnityMainThreadDispatcher _instance = null;
public void Update()
{
lock (_executionQueue)
{
while (_executionQueue.Count > 0)
{
_executionQueue.Dequeue()();
}
}
}
public void Enqueue(IEnumerator action)
{
IEnumerator action2 = action;
lock (_executionQueue)
{
_executionQueue.Enqueue(delegate
{
((MonoBehaviour)this).StartCoroutine(action2);
});
}
}
public void Enqueue(Action action)
{
Enqueue(ActionWrapper(action));
}
public Task EnqueueAsync(Action action)
{
Action action2 = action;
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
Enqueue(ActionWrapper(WrappedAction));
return tcs.Task;
void WrappedAction()
{
try
{
action2();
tcs.TrySetResult(result: true);
}
catch (Exception exception)
{
tcs.TrySetException(exception);
}
}
}
private IEnumerator ActionWrapper(Action a)
{
a();
yield return null;
}
public static bool Exists()
{
return (Object)(object)_instance != (Object)null;
}
public static UnityMainThreadDispatcher Instance()
{
if (!Exists())
{
throw new Exception("UnityMainThreadDispatcher could not find the UnityMainThreadDispatcher object. Please ensure you have added the MainThreadExecutor Prefab to your scene.");
}
return _instance;
}
private void Awake()
{
if ((Object)(object)_instance == (Object)null)
{
_instance = this;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
}
private void OnDestroy()
{
_instance = null;
}
}
}
namespace LastDayLostCameraFix
{
[ContentWarningPlugin("LastDayLostCameraFix", "3.0", false)]
public class LastDayLostCameraFix
{
[HarmonyPatch(typeof(SurfaceNetworkHandler), "InitSurface")]
public static class Patch_InitSurface
{
[HarmonyPrefix]
private static bool Prefix(SurfaceNetworkHandler __instance)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Invalid comparison between Unknown and I4
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Expected O, but got Unknown
try
{
DebugCW.Log("Patch 'InitSurface' called");
if (!UnityMainThreadDispatcher.Exists())
{
DebugCW.LogWarning("'UnityMainThreadDispatcher' not found...");
GameObject val = new GameObject("UnityMainThreadDispatcher");
val.AddComponent<UnityMainThreadDispatcher>();
DebugCW.Log("'UnityMainThreadDispatcher' created and added to the scene");
}
Debug.Log((object)"Initializing Surface");
__instance.m_View = ((Component)__instance).GetComponent<PhotonView>();
__instance.m_SteamLobby = MainMenuHandler.SteamLobbyHandler;
if (SurfaceNetworkHandler.RoomStats == null)
{
SurfaceNetworkHandler.RoomStats = new RoomStatsHolder(__instance, SingletonAsset<BigNumbers>.Instance.StartMoney, BigNumbers.GetQuota(0), 3);
if (PhotonNetwork.IsMasterClient)
{
PhotonNetwork.CurrentRoom.IsOpen = true;
PhotonNetwork.CurrentRoom.IsVisible = true;
PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new InviteFriendsObjective());
__instance.CheckSave();
}
else
{
((MonoBehaviourPunCallbacks)__instance).OnRoomPropertiesUpdate(((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties);
}
if (SurfaceNetworkHandler.RoomStats.CurrentDay <= 1)
{
__instance.firstDay = true;
string localizedString = LocalizationKeys.GetLocalizedString((Keys)0);
HelmetText.Instance.SetHelmetText(localizedString, 3f);
Debug.Log((object)"NEW RUN!");
if (PhotonNetwork.IsMasterClient)
{
__instance.SpawnSurfacePickups();
}
}
else if (PhotonNetwork.IsMasterClient)
{
__instance.m_VideoCameraSpawner.SpawnMe(true);
}
if (__instance.m_SteamLobby != null)
{
__instance.m_SteamLobby.OpenLobby();
}
SpawnHandler.Instance.SpawnLocalPlayer((Spawns)1);
}
else
{
Debug.Log((object)"Should do next day here but waiting for upload?");
if ((int)TimeOfDayHandler.TimeOfDay == 10)
{
RichPresenceHandler.SetPresenceState((RichPresenceState)3);
if (PhotonNetwork.IsMasterClient)
{
CheckCameraOnMasterClient(__instance);
}
if (!Player.justDied && !__instance.m_FailedQuota)
{
SpawnHandler.Instance.SpawnLocalPlayer((Spawns)3);
}
}
}
if (!__instance.m_FailedQuota)
{
__instance.ShopHandler.InitShopHandler();
}
return false;
}
catch (Exception exception)
{
DebugCW.LogException(exception);
if (Harmony.HasAnyPatches(harmony.Id))
{
DebugCW.Log("Patch disabled");
harmony.UnpatchSelf();
}
HelmetText.Instance.SetHelmetText("Patch '" + Assembly.GetExecutingAssembly().GetName().Name + "' - Disabled!\nPlease report the error to the mod developer.\n", 3f);
return true;
}
}
}
private static readonly Harmony harmony;
static LastDayLostCameraFix()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Expected O, but got Unknown
harmony = new Harmony("com.artkopt.LastDayLostCameraFix");
DebugCW.Log("The 'LastDayLostCameraFix' mod has been launched");
ApplyPatches();
}
public static void ApplyPatches()
{
try
{
DebugCW.Log("Attempting to apply patches");
if (!Harmony.HasAnyPatches(harmony.Id))
{
harmony.PatchAll();
DebugCW.Log("Patches applied successfully");
}
}
catch (Exception exception)
{
DebugCW.LogException(exception);
DebugCW.LogError("Failed to apply patches. Mod may not work correctly.");
}
}
public static void CheckCameraOnMasterClient(SurfaceNetworkHandler __instance)
{
DebugCW.Log("Waiting for the camera to appear...");
UnityMainThreadDispatcher.Instance().Enqueue(CheckCameraOnMasterClientCoroutine(__instance));
}
private static IEnumerator CheckCameraOnMasterClientCoroutine(SurfaceNetworkHandler __instance)
{
float maxWaitTime = 1f;
float elapsedTime = 0f;
while (!__instance.CheckIfCameraIsPresent(true) && elapsedTime < maxWaitTime)
{
DebugCW.Log($"Waiting... {elapsedTime}s");
yield return (object)new WaitForSeconds(0.2f);
elapsedTime += 0.2f;
if (elapsedTime >= maxWaitTime)
{
DebugCW.LogWarning("Camera not found...");
break;
}
}
UnityMainThreadDispatcher.Instance().Enqueue(CheckIfCameraIsPresentCoroutine(__instance));
}
public static IEnumerator CheckIfCameraIsPresentCoroutine(SurfaceNetworkHandler __instance)
{
SurfaceNetworkHandler.ReturnedFromLostWorldWithCamera = __instance.CheckIfCameraIsPresent(true);
if (!SurfaceNetworkHandler.ReturnedFromLostWorldWithCamera)
{
SurfaceNetworkHandler.RoomStats.ResetCameraUpgrades();
if (PhotonNetwork.IsMasterClient)
{
PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new GoToBedFailedObjective());
if (SurfaceNetworkHandler.RoomStats.IsQuotaDay && !SurfaceNetworkHandler.RoomStats.CalculateIfReachedQuota())
{
__instance.NextDay();
}
}
}
else if (PhotonNetwork.IsMasterClient)
{
PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new ExtractVideoObjective());
}
if (!__instance.m_FailedQuota)
{
__instance.CheckForHospitalBill();
}
yield return null;
}
}
public class DebugCW
{
public static void Log(string message)
{
Debug.Log((object)$"[{DateTime.Now}] [{(object)(LogType)3}] [MOD] {message}");
}
public static void LogWarning(string message)
{
Debug.LogWarning((object)$"[{DateTime.Now}] [{(object)(LogType)2}] [MOD] {message}");
}
public static void LogError(string message)
{
Debug.LogError((object)$"[{DateTime.Now}] [{(object)(LogType)0}] [MOD] {message}");
}
public static void LogException(Exception exception)
{
Debug.LogError((object)$"[{DateTime.Now}] [{(object)(LogType)0}] [MOD] Exception: {exception.Message}");
Debug.LogException(exception);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
internal IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}