using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ConfigureMap.Patches;
using HarmonyLib;
using MyceliumNetworking;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ConfigureMap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConfigureMap")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("AC2268FA-9265-4023-8633-3084B9FA0298")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ConfigureMap
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("MerQury.ConfigureMap", "Configure Map", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource Log;
public static PluginInfo info;
public static uint modId = 2552354125u;
public static Plugin instance;
public static PluginConfig Config { get; private set; }
private void Awake()
{
instance = this;
info = ((BaseUnityPlugin)this).Info;
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"ConfigureMap Plugin loaded");
MyceliumNetwork.RegisterNetworkObject((object)UI.networkObject, modId, 0);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Registerd in MyceliumNetwork");
Harmony.CreateAndPatchAll(typeof(RoomStatsHolderPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(SurfaceNetworkHandlerPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(CursorHandlerPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(MainMenuHandlerPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(SteamLobbyHandlerPatch), (string)null);
Config = new PluginConfig(((BaseUnityPlugin)this).Config);
}
}
public enum MapEnum
{
Ship = 2,
Mines = 1,
Factory = 0
}
public class PluginConfig
{
public ConfigEntry<MapEnum> Map;
public ConfigEntry<bool> GraphicMode;
public PluginConfig(ConfigFile config)
{
Map = config.Bind<MapEnum>("General", "Map", MapEnum.Ship, "Default Map, not used in graphic mode");
GraphicMode = config.Bind<bool>("General", "GraphicMode", true, "Graphic mode requires everyone to have the mod, without it host-only");
}
}
public class ResourceLoader
{
public static Sprite LoadEmbeddedImage(string relativePath)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
string directoryName = Path.GetDirectoryName(Plugin.info.Location);
string path = Path.Combine(directoryName, relativePath);
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(2, 2);
ImageConversion.LoadImage(val, array);
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
}
}
public class UI
{
private static GameObject window = null;
private static Action<GameObject> onMapSelected = null;
public static UI networkObject = new UI();
public static void CreateMapSelectionWindow(Action<GameObject> onMapSelected = null)
{
MyceliumNetwork.RegisterNetworkObject((object)Plugin.instance, Plugin.modId, 0);
Plugin.Log.LogInfo((object)$"isHost: {MyceliumNetwork.IsHost}, inLobby: {MyceliumNetwork.InLobby}");
if (!SteamLobbyHandlerPatch.InLobby)
{
UI.onMapSelected = null;
CreateMapSelectionWindowHost(onMapSelected);
}
else if (!SteamLobbyHandlerPatch.IsHost)
{
window = CreateMapSelectionWindowClient();
UI.onMapSelected = onMapSelected;
}
else
{
CreateMapSelectionWindowHost(onMapSelected);
}
}
[CustomRPC]
public void RPC_OnMapSelected(int selectedMap)
{
Plugin.Config.Map.Value = (MapEnum)selectedMap;
Plugin.Log.LogInfo((object)$"RPC_OnMapSelected: {Plugin.Config.Map.Value}");
onMapSelected?.Invoke(window);
}
private static GameObject CreateMapSelectionWindowClient()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Expected O, but got Unknown
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("MapSelectionWindow");
Canvas val2 = val.AddComponent<Canvas>();
val2.renderMode = (RenderMode)0;
val.AddComponent<CanvasScaler>();
val.AddComponent<GraphicRaycaster>();
GameObject val3 = new GameObject("cm_panel");
val3.transform.SetParent(val.transform);
RectTransform val4 = val3.AddComponent<RectTransform>();
val4.anchoredPosition = Vector2.zero;
val4.anchorMax = new Vector2(0.5f, 0.7f);
val4.anchorMin = new Vector2(0.5f, 0.7f);
val4.sizeDelta = new Vector2(500f, 200f);
Image val5 = val3.AddComponent<Image>();
((Graphic)val5).color = new Color(0.1f, 0.1f, 0.1f, 0.6f);
VerticalLayoutGroup val6 = val3.AddComponent<VerticalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)val6).childForceExpandWidth = false;
((HorizontalOrVerticalLayoutGroup)val6).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)val6).childControlHeight = false;
((HorizontalOrVerticalLayoutGroup)val6).childControlWidth = false;
((LayoutGroup)val6).childAlignment = (TextAnchor)4;
GameObject val7 = new GameObject("cm_text");
val7.transform.SetParent(val3.transform);
RectTransform val8 = val7.AddComponent<RectTransform>();
val8.sizeDelta = new Vector2(500f, 50f);
Text val9 = val7.AddComponent<Text>();
val9.text = "Wait until host selecting map...";
? val10 = val9;
Object builtinResource = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
((Text)val10).font = (Font)(object)((builtinResource is Font) ? builtinResource : null);
val9.alignment = (TextAnchor)4;
return val;
}
private static void CreateMapSelectionWindowHost(Action<GameObject> onMapSelected = null)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Expected O, but got Unknown
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a1: Expected O, but got Unknown
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
GameObject canvasParent = new GameObject("MapSelectionWindow");
Canvas val = canvasParent.AddComponent<Canvas>();
val.renderMode = (RenderMode)0;
canvasParent.AddComponent<CanvasScaler>();
canvasParent.AddComponent<GraphicRaycaster>();
GameObject val2 = new GameObject("cm_panel");
val2.transform.SetParent(canvasParent.transform);
RectTransform val3 = val2.AddComponent<RectTransform>();
val3.anchoredPosition = Vector2.zero;
val3.anchorMax = new Vector2(0.5f, 0.7f);
val3.anchorMin = new Vector2(0.5f, 0.7f);
val3.sizeDelta = new Vector2(500f, 200f);
Image val4 = val2.AddComponent<Image>();
((Graphic)val4).color = new Color(0.1f, 0.1f, 0.1f, 0.6f);
VerticalLayoutGroup val5 = val2.AddComponent<VerticalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)val5).childForceExpandWidth = false;
((HorizontalOrVerticalLayoutGroup)val5).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)val5).childControlHeight = false;
((HorizontalOrVerticalLayoutGroup)val5).childControlWidth = false;
GameObject val6 = new GameObject("cm_text");
val6.transform.SetParent(val2.transform);
RectTransform val7 = val6.AddComponent<RectTransform>();
val7.sizeDelta = new Vector2(500f, 50f);
Text val8 = val6.AddComponent<Text>();
val8.text = "Choose map!";
? val9 = val8;
Object builtinResource = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
((Text)val9).font = (Font)(object)((builtinResource is Font) ? builtinResource : null);
val8.alignment = (TextAnchor)4;
GameObject val10 = new GameObject("cm_buttons");
val10.transform.SetParent(val2.transform);
RectTransform val11 = val10.AddComponent<RectTransform>();
val11.sizeDelta = new Vector2(500f, 150f);
HorizontalLayoutGroup val12 = val10.AddComponent<HorizontalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)val12).childForceExpandWidth = false;
((HorizontalOrVerticalLayoutGroup)val12).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)val12).childControlHeight = false;
((HorizontalOrVerticalLayoutGroup)val12).childControlWidth = false;
((LayoutGroup)val12).childAlignment = (TextAnchor)4;
((HorizontalOrVerticalLayoutGroup)val12).spacing = 8f;
CreateMapButton("Ship", val10, delegate
{
Plugin.Config.Map.Value = MapEnum.Ship;
if (SteamLobbyHandlerPatch.InLobby)
{
MyceliumNetwork.RPC(Plugin.modId, "RPC_OnMapSelected", (ReliableType)1, new object[1] { 2 });
}
onMapSelected?.Invoke(canvasParent);
});
CreateMapButton("Factory", val10, delegate
{
Plugin.Config.Map.Value = MapEnum.Factory;
if (SteamLobbyHandlerPatch.InLobby)
{
MyceliumNetwork.RPC(Plugin.modId, "RPC_OnMapSelected", (ReliableType)1, new object[1] { 0 });
}
onMapSelected?.Invoke(canvasParent);
});
CreateMapButton("Mines", val10, delegate
{
Plugin.Config.Map.Value = MapEnum.Mines;
if (SteamLobbyHandlerPatch.InLobby)
{
MyceliumNetwork.RPC(Plugin.modId, "RPC_OnMapSelected", (ReliableType)1, new object[1] { 1 });
}
onMapSelected?.Invoke(canvasParent);
});
CreateMapButton("Random", val10, delegate
{
Array values = Enum.GetValues(typeof(MapEnum));
if (SteamLobbyHandlerPatch.InLobby)
{
MyceliumNetwork.RPC(Plugin.modId, "RPC_OnMapSelected", (ReliableType)1, new object[1] { (int)values.GetValue(Random.Range(0, values.Length)) });
}
Plugin.Config.Map.Value = (MapEnum)values.GetValue(Random.Range(0, values.Length));
onMapSelected?.Invoke(canvasParent);
});
}
private static void CreateMapButton(string mapName, GameObject parent, Action onClick = null)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Expected O, but got Unknown
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Expected O, but got Unknown
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("cm_button_" + mapName);
val.transform.SetParent(parent.transform);
RectTransform val2 = val.AddComponent<RectTransform>();
val2.sizeDelta = new Vector2(115f, 140f);
Image i = val.AddComponent<Image>();
((Graphic)i).color = new Color(0f, 0f, 0f, 0f);
PointerHandler pointerHandler = val.AddComponent<PointerHandler>();
pointerHandler.onEnter = delegate
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
((Graphic)i).color = new Color(1f, 1f, 1f, 0.05f);
};
pointerHandler.onExit = delegate
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
((Graphic)i).color = new Color(0f, 0f, 0f, 0f);
};
pointerHandler.onClick = onClick;
VerticalLayoutGroup val3 = val.AddComponent<VerticalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)val3).childForceExpandWidth = false;
((HorizontalOrVerticalLayoutGroup)val3).childForceExpandHeight = false;
((HorizontalOrVerticalLayoutGroup)val3).childControlHeight = false;
((HorizontalOrVerticalLayoutGroup)val3).childControlWidth = false;
GameObject val4 = new GameObject("cm_button_" + mapName + "_img");
val4.transform.SetParent(val.transform);
RectTransform val5 = val4.AddComponent<RectTransform>();
val5.sizeDelta = new Vector2(115f, 115f);
Image val6 = val4.AddComponent<Image>();
val6.sprite = ResourceLoader.LoadEmbeddedImage(mapName.ToLower() + ".png");
GameObject val7 = new GameObject("cm_button_" + mapName + "_text");
val7.transform.SetParent(val.transform);
RectTransform val8 = val7.AddComponent<RectTransform>();
val8.sizeDelta = new Vector2(115f, 25f);
Text val9 = val7.AddComponent<Text>();
val9.text = mapName;
val9.alignment = (TextAnchor)4;
? val10 = val9;
Object builtinResource = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
((Text)val10).font = (Font)(object)((builtinResource is Font) ? builtinResource : null);
}
}
internal class PointerHandler : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerClickHandler
{
public Action onEnter = null;
public Action onExit = null;
public Action onClick = null;
public void OnPointerEnter(PointerEventData eventData)
{
onEnter?.Invoke();
}
public void OnPointerExit(PointerEventData eventData)
{
onExit?.Invoke();
}
public void OnPointerClick(PointerEventData eventData)
{
onClick?.Invoke();
}
}
}
namespace ConfigureMap.Patches
{
public class Common
{
public static object InvokeMethod<T>(T instance, string methodName, object[] args)
{
try
{
return typeof(T).GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(instance, args);
}
catch (NullReferenceException)
{
LogNRE(typeof(T), methodName, "InvokeMethod");
throw;
}
}
public static R GetField<T, R>(T instance, string fieldName)
{
try
{
return (R)(typeof(T).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(instance));
}
catch (NullReferenceException)
{
LogNRE(typeof(T), fieldName, "GetField");
throw;
}
}
public static void SetField<T>(T instance, string fieldName, object value)
{
try
{
typeof(T).GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(instance, value);
}
catch (NullReferenceException)
{
LogNRE(typeof(T), fieldName, "SetField");
throw;
}
}
public static void SetStaticProperty(Type type, string fieldName, object value)
{
try
{
type.GetProperty(fieldName, BindingFlags.Static | BindingFlags.Public)?.SetValue(null, value);
}
catch (NullReferenceException)
{
LogNRE(type, fieldName, "SetField");
throw;
}
}
public static void SetStaticField(Type type, string fieldName, object value)
{
try
{
type.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic)?.SetValue(null, value);
}
catch (NullReferenceException)
{
LogNRE(type, fieldName, "SetField");
throw;
}
}
private static void LogNRE(Type type, string subjectName, string methodName)
{
Plugin.Log.LogError((object)("NRE on " + type.Name + "." + subjectName + " in " + methodName));
}
}
[HarmonyPatch(typeof(CursorHandler))]
public class CursorHandlerPatch
{
public static bool MouseShouldBeFree;
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static bool UpdatePatch(CursorHandler __instance)
{
if (MouseShouldBeFree)
{
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = true;
return false;
}
return true;
}
}
public class MainMenuHandlerPatch
{
private static MainMenuHandler MainMenuHandlerInstance;
[HarmonyPatch(typeof(MainMenuHandler), "Host")]
[HarmonyPrefix]
private static bool HostPatch(MainMenuHandler __instance, int saveIndex)
{
if (!Plugin.Config.GraphicMode.Value)
{
return true;
}
Save val = SaveSystem.SavesOnFile[saveIndex];
if (val != null)
{
return true;
}
MainMenuLoadingPage loadingPage = ((UIPageHandler)__instance.UIHandler).TransistionToPage<MainMenuLoadingPage>();
loadingPage.SetText("");
UI.CreateMapSelectionWindow(delegate(GameObject window)
{
Object.Destroy((Object)(object)window);
string localizedString = LocalizationKeys.GetLocalizedString((Keys)133);
loadingPage.SetText(localizedString);
FieldInfo field = typeof(MainMenuHandler).GetField("m_Hosting", BindingFlags.Instance | BindingFlags.NonPublic);
if (!(bool)field.GetValue(__instance))
{
SaveSystem.SelectCurrentSave(saveIndex);
MainMenuHandlerInstance = __instance;
MainMenuHandler.SteamLobbyHandler.HostMatch((Action<ulong>)onSteamHosted, true);
field.SetValue(__instance, true);
}
});
return false;
}
private static void onSteamHosted(ulong steamId)
{
MethodInfo method = typeof(MainMenuHandler).GetMethod("OnSteamHosted", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(MainMenuHandlerInstance, new object[1] { steamId });
}
}
[HarmonyPatch(typeof(RoomStatsHolder))]
public class RoomStatsHolderPatch
{
[HarmonyPatch("NewMapToPlay")]
[HarmonyPostfix]
private static void NewMapToPlayPatch(RoomStatsHolder __instance)
{
__instance.LevelToPlay = (int)Plugin.Config.Map.Value;
}
}
[HarmonyPatch(typeof(SteamLobbyHandler))]
public class SteamLobbyHandlerPatch
{
public static bool InLobby;
public static bool IsHost;
[HarmonyPatch("HostMatch")]
[HarmonyPostfix]
private static void HostMatchPostfix()
{
InLobby = true;
IsHost = true;
}
[HarmonyPatch("JoinLobby")]
[HarmonyPostfix]
private static void JoinLobbyPostfix()
{
InLobby = true;
IsHost = false;
}
[HarmonyPatch("LeaveLobby")]
[HarmonyPostfix]
private static void LeaveLobbyPostfix()
{
InLobby = false;
IsHost = false;
}
}
[HarmonyPatch(typeof(SurfaceNetworkHandler))]
public class SurfaceNetworkHandlerPatch
{
private static bool MouseShouldBeFree;
private static bool QuotaFailed;
[HarmonyPatch("OnSlept")]
[HarmonyPrefix]
public static bool OnSleptPatch(SurfaceNetworkHandler __instance)
{
if (!Plugin.Config.GraphicMode.Value)
{
return true;
}
if (SurfaceNetworkHandler.RoomStats == null)
{
return true;
}
if (SurfaceNetworkHandler.RoomStats.GetDaysLeft() > 0)
{
return true;
}
if (!SurfaceNetworkHandler.RoomStats.CalculateIfReachedQuota())
{
return true;
}
Time.timeScale = 0f;
CursorHandlerPatch.MouseShouldBeFree = true;
UI.CreateMapSelectionWindow(delegate(GameObject window)
{
Object.Destroy((Object)(object)window);
CursorHandlerPatch.MouseShouldBeFree = false;
Time.timeScale = 1f;
OnSlept(__instance);
});
return false;
}
[HarmonyPatch("InitSurface")]
[HarmonyPrefix]
public static bool InitSurface_Patch(SurfaceNetworkHandler __instance)
{
if (!Plugin.Config.GraphicMode.Value)
{
return true;
}
if (QuotaFailed)
{
Time.timeScale = 0f;
CursorHandlerPatch.MouseShouldBeFree = true;
UI.CreateMapSelectionWindow(delegate(GameObject window)
{
Object.Destroy((Object)(object)window);
CursorHandlerPatch.MouseShouldBeFree = false;
Time.timeScale = 1f;
InitSurface(__instance);
});
QuotaFailed = false;
return false;
}
return true;
}
[HarmonyPatch("RPC_QuotaFailed")]
[HarmonyPostfix]
public static void RPC_QuotaFailed_Patch()
{
QuotaFailed = true;
}
private static void InitSurface(SurfaceNetworkHandler __instance)
{
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Invalid comparison between Unknown and I4
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_0249: Unknown result type (might be due to invalid IL or missing references)
//IL_0253: Expected O, but got Unknown
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Expected O, but got Unknown
Common.SetField<SurfaceNetworkHandler>(__instance, "m_View", ((Component)__instance).GetComponent<PhotonView>());
Common.SetField<SurfaceNetworkHandler>(__instance, "m_SteamLobby", MainMenuHandler.SteamLobbyHandler);
if (SurfaceNetworkHandler.RoomStats == null)
{
Common.SetStaticProperty(typeof(SurfaceNetworkHandler), "RoomStats", (object)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());
Common.InvokeMethod<SurfaceNetworkHandler>(__instance, "CheckSave", null);
}
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)
{
Common.InvokeMethod<SurfaceNetworkHandler>(__instance, "SpawnSurfacePickups", null);
}
}
else if (PhotonNetwork.IsMasterClient)
{
Common.GetField<SurfaceNetworkHandler, PickupSpawner>(__instance, "m_VideoCameraSpawner").SpawnMe(true);
}
if (Common.GetField<SurfaceNetworkHandler, SteamLobbyHandler>(__instance, "m_SteamLobby") != null)
{
Common.GetField<SurfaceNetworkHandler, SteamLobbyHandler>(__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)
{
Common.SetStaticProperty(typeof(SurfaceNetworkHandler), "ReturnedFromLostWorldWithCamera", Common.InvokeMethod<SurfaceNetworkHandler>(__instance, "CheckIfCameraIsPresent", new object[1] { true }));
if (!SurfaceNetworkHandler.ReturnedFromLostWorldWithCamera)
{
SurfaceNetworkHandler.RoomStats.ResetCameraUpgrades();
if (PhotonNetwork.IsMasterClient)
{
PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new GoToBedFailedObjective());
if (SurfaceNetworkHandler.RoomStats.IsQuotaDay && !SurfaceNetworkHandler.RoomStats.CalculateIfReachedQuota())
{
Common.InvokeMethod<SurfaceNetworkHandler>(__instance, "NextDay", null);
}
}
}
else if (PhotonNetwork.IsMasterClient)
{
PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new ExtractVideoObjective());
}
if (!Common.GetField<SurfaceNetworkHandler, bool>(__instance, "m_FailedQuota"))
{
Common.InvokeMethod<SurfaceNetworkHandler>(__instance, "CheckForHospitalBill", null);
}
}
if (!Player.justDied && !Common.GetField<SurfaceNetworkHandler, bool>(__instance, "m_FailedQuota"))
{
SpawnHandler.Instance.SpawnLocalPlayer((Spawns)3);
}
}
}
if (!Common.GetField<SurfaceNetworkHandler, bool>(__instance, "m_FailedQuota"))
{
__instance.ShopHandler.InitShopHandler();
}
}
[HarmonyPatch("RPCA_Sleep")]
[HarmonyPrefix]
public static bool RPCA_SleepPatch(SurfaceNetworkHandler __instance)
{
Common.SetField<SurfaceNetworkHandler>(__instance, "m_RequestedSleep", false);
SurfaceNetworkHandler.ResetReturningFromLostWorld();
Object.FindObjectOfType<ShopHandler>().InitShopScreen();
Common.InvokeMethod<SurfaceNetworkHandler>(__instance, "OnSlept", null);
return false;
}
private static void OnSlept(SurfaceNetworkHandler instance)
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected O, but got Unknown
Action action = Player.localPlayer.WakeUp;
if (PhotonNetwork.IsMasterClient)
{
Common.InvokeMethod<SurfaceNetworkHandler>(instance, "NextDay", null);
if (SurfaceNetworkHandler.RoomStats.Money >= 20)
{
PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new BuyEquipmentObjective());
}
else
{
PhotonGameLobbyHandler.Instance.SetCurrentObjective((Objective)new EnterDiveBellDay2Objective());
}
int daysLocaleKey = -1;
if (SurfaceNetworkHandler.RoomStats != null)
{
int daysLeft = SurfaceNetworkHandler.RoomStats.GetDaysLeft();
if (daysLeft == 0)
{
daysLocaleKey = 63;
}
else
{
daysLocaleKey = 62;
}
if (!(bool)Common.InvokeMethod<SurfaceNetworkHandler>(instance, "CheckIfCameraIsPresent", new object[1] { false }))
{
Common.GetField<SurfaceNetworkHandler, PickupSpawner>(instance, "m_VideoCameraSpawner").SpawnMe(true);
}
Common.SetField<SurfaceNetworkHandler>(instance, "ReturnedFromLostWorldWithCamera", true);
action = (Action)Delegate.Combine(action, (Action)delegate
{
Common.GetField<SurfaceNetworkHandler, PhotonView>(instance, "m_View").RPC("RPCA_HelmetText", (RpcTarget)0, new object[2] { daysLocaleKey, daysLeft });
});
}
RetrievableResourceSingleton<TransitionHandler>.Instance.FadeOut(action, 0f);
}
RetrievableResourceSingleton<TransitionHandler>.Instance.FadeOut(action, 0f);
}
}
}