using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
[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("RestoreMapper")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Restore the unused mapper item in the shop")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2+91e4078ed553595a15a6b4db9e57d7885f6789fc")]
[assembly: AssemblyProduct("RestoreMapper")]
[assembly: AssemblyTitle("RestoreMapper")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.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 RestoreMapper
{
internal static class LobbyCompatibility
{
internal static void Init()
{
PluginHelper.RegisterPlugin("butterystancakes.lethalcompany.restoremapper", Version.Parse("1.2.2"), (CompatibilityLevel)2, (VersionStrictness)0);
}
}
[BepInPlugin("butterystancakes.lethalcompany.restoremapper", "Restore Mapper", "1.2.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal const string PLUGIN_GUID = "butterystancakes.lethalcompany.restoremapper";
internal const string PLUGIN_NAME = "Restore Mapper";
internal const string PLUGIN_VERSION = "1.2.2";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> configLowQuality;
private const string GUID_LOBBY_COMPATIBILITY = "BMX.LobbyCompatibility";
private void Awake()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
if (Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility"))
{
Logger.LogInfo((object)"CROSS-COMPATIBILITY - Lobby Compatibility detected");
LobbyCompatibility.Init();
}
configLowQuality = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "Low Quality", false, "Decreases the resolution of the mapper image (to match the radar camera) and disables film grain.\nThis will reduce memory usage and might also reduce lag spikes when activating the device.");
new Harmony("butterystancakes.lethalcompany.restoremapper").PatchAll();
Logger.LogInfo((object)"Restore Mapper v1.2.2 loaded");
}
}
[HarmonyPatch]
internal class RestoreMapperPatches
{
private static Texture scanline;
[HarmonyPatch(typeof(Terminal), "Awake")]
[HarmonyPostfix]
private static void TerminalPostAwake(Terminal __instance)
{
TerminalKeyword? obj = ((IEnumerable<TerminalKeyword>)__instance.terminalNodes?.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword keyword) => ((Object)keyword).name == "Buy"));
TerminalNode val = ((IEnumerable<CompatibleNoun>)obj?.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)delegate(CompatibleNoun compatibleNoun)
{
TerminalKeyword noun2 = compatibleNoun.noun;
return ((noun2 != null) ? ((Object)noun2).name : null) == "Mapper";
}).result;
CompatibleNoun val2 = ((IEnumerable<CompatibleNoun>)val?.terminalOptions).FirstOrDefault((Func<CompatibleNoun, bool>)delegate(CompatibleNoun compatibleNoun)
{
TerminalKeyword noun = compatibleNoun.noun;
return ((noun != null) ? ((Object)noun).name : null) == "Confirm";
});
List<Item> list = StartOfRound.Instance?.allItemsList?.itemsList;
Item val3 = list?.FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "MapDevice"));
if ((Object)(object)obj == (Object)null || (Object)(object)val == (Object)null || val2 == null || list == null || (Object)(object)val3 == (Object)null)
{
Plugin.Logger.LogError((object)"Encountered an error while caching essential references. Loading will be skipped.");
return;
}
__instance.buyableItemsList = CollectionExtensions.AddItem<Item>((IEnumerable<Item>)__instance.buyableItemsList, val3).ToArray();
val.buyItemIndex = __instance.buyableItemsList.Length - 1;
val2.result.buyItemIndex = val.buyItemIndex;
Plugin.Logger.LogDebug((object)"Assigned IDs");
val3.creditsWorth = 150;
Plugin.Logger.LogDebug((object)"Assigned price");
Item val4 = ((IEnumerable<Item>)list).FirstOrDefault((Func<Item, bool>)((Item item) => ((Object)item).name == "ProFlashlight"));
if ((Object)(object)val4 != (Object)null)
{
val3.grabSFX = val4.grabSFX;
val3.dropSFX = val4.dropSFX;
val3.pocketSFX = val4.pocketSFX;
Plugin.Logger.LogDebug((object)"Assigned SFX");
}
else
{
Plugin.Logger.LogWarning((object)"Couldn't find pro-flashlight item. Sound effects will be missing.");
}
try
{
AssetBundle val5 = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "restoremapper"));
val3.itemIcon = val5.LoadAsset<Sprite>("MapperIcon");
scanline = val5.LoadAsset<Texture>("scanline");
val5.Unload(false);
Plugin.Logger.LogDebug((object)"Assigned special icon");
}
catch
{
Plugin.Logger.LogWarning((object)"Encountered some error loading asset bundle. Inventory icon will be incorrect.");
Item val6 = list?.FirstOrDefault((Func<Item, bool>)delegate(Item item)
{
Sprite itemIcon = item.itemIcon;
return ((itemIcon != null) ? ((Object)itemIcon).name : null) == "caticontest";
});
if ((Object)(object)val6 != (Object)null)
{
val3.itemIcon = val6.itemIcon;
}
}
}
[HarmonyPatch(typeof(MapDevice), "Start")]
[HarmonyPrefix]
private static bool MapDevicePreStart(MapDevice __instance)
{
if ((Object)(object)__instance.mapCamera != (Object)null)
{
Plugin.Logger.LogWarning((object)$"Mapper #{((Object)__instance).GetInstanceID()} tried to call Start() more than once, this is dangerous and would've caused a memory leak");
return false;
}
return true;
}
[HarmonyPatch(typeof(MapDevice), "Start")]
[HarmonyPostfix]
private static void MapDevicePostStart(MapDevice __instance)
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Expected O, but got Unknown
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
if (!((Component)__instance.mapCamera).CompareTag("MapCamera"))
{
return;
}
RenderTexture targetTexture = __instance.mapCamera.targetTexture;
__instance.mapCamera = Object.Instantiate<GameObject>(((Component)__instance.mapCamera).gameObject, ((Component)__instance.mapCamera).transform.parent).GetComponent<Camera>();
((Component)__instance.mapCamera).tag = "Untagged";
__instance.mapCamera.targetTexture = new RenderTexture(Plugin.configLowQuality.Value ? ((Texture)targetTexture).width : 655, Plugin.configLowQuality.Value ? ((Texture)targetTexture).height : 455, targetTexture.depth, targetTexture.format);
Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} cam&tex cloned");
__instance.mapAnimatorTransition = ((Component)__instance.mapCamera).GetComponentInChildren<Animator>();
((Component)__instance.mapAnimatorTransition).transform.localPosition = new Vector3(0f, 0f, -0.95f);
__instance.mapLight = ((Component)__instance.mapCamera).GetComponentInChildren<Light>();
((Component)__instance.mapCamera).gameObject.SetActive(false);
((Behaviour)__instance.mapCamera).enabled = true;
((Behaviour)__instance.mapLight).enabled = false;
Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} light setup");
MeshRenderer componentInChildren = ((Component)__instance).GetComponentInChildren<MeshRenderer>();
Material[] materials = ((Renderer)componentInChildren).materials;
((IEnumerable<Material>)materials).FirstOrDefault((Func<Material, bool>)((Material mat) => ((Object)mat).name.StartsWith("MapScreen"))).mainTexture = (Texture)(object)__instance.mapCamera.targetTexture;
((Renderer)componentInChildren).materials = materials;
Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} screen retex'd");
if (!Plugin.configLowQuality.Value)
{
Volume componentInChildren2 = ((Component)__instance.mapCamera).GetComponentInChildren<Volume>();
VolumeProfile val = ((componentInChildren2 != null) ? componentInChildren2.profile : null);
FilmGrain val2 = default(FilmGrain);
val.TryGet<FilmGrain>(ref val2);
if ((Object)(object)val2 == (Object)null)
{
val2 = val.Add<FilmGrain>(false);
}
((VolumeParameter<FilmGrainLookup>)(object)val2.type).Override((FilmGrainLookup)10);
((VolumeParameter<Texture>)(object)val2.texture).Override(scanline);
((VolumeParameter<float>)(object)val2.intensity).Override(1f);
((VolumeParameter<float>)(object)val2.response).Override(1f);
}
}
[HarmonyPatch(typeof(MapDevice), "ItemActivate")]
[HarmonyPrefix]
private static bool MapDeviceItemActivate(MapDevice __instance, Coroutine ___pingMapCoroutine)
{
if ((Object)(object)((GrabbableObject)__instance).playerHeldBy == (Object)null || ((Component)__instance.mapCamera).CompareTag("MapCamera"))
{
return true;
}
if (___pingMapCoroutine != null)
{
((MonoBehaviour)__instance).StopCoroutine(___pingMapCoroutine);
}
((MonoBehaviour)__instance).StartCoroutine(pingMapSystem(__instance, ((GrabbableObject)__instance).playerHeldBy));
return false;
}
[HarmonyPatch(typeof(NetworkBehaviour), "OnDestroy")]
[HarmonyPostfix]
private static void NetworkBehaviourPostOnDestroy(NetworkBehaviour __instance)
{
MapDevice val = (MapDevice)(object)((__instance is MapDevice) ? __instance : null);
if (val != null && (Object)(object)val.mapCamera != (Object)null && !((Component)val.mapCamera).CompareTag("MapCamera"))
{
if (val.mapCamera.targetTexture.IsCreated())
{
val.mapCamera.targetTexture.Release();
}
Object.Destroy((Object)(object)val.mapCamera.targetTexture);
Object.Destroy((Object)(object)((Component)val.mapCamera).gameObject);
Plugin.Logger.LogDebug((object)$"Mapper #{((Object)__instance).GetInstanceID()} cleaned up");
}
}
[HarmonyPatch(typeof(GrabbableObject), "UseItemBatteries")]
[HarmonyPrefix]
private static bool GrabbableObjectPreUseItemBatteries(GrabbableObject __instance)
{
if (__instance is MapDevice)
{
if (!StartOfRound.Instance.mapScreen.overrideCameraForOtherUse)
{
if (!((Object)(object)__instance.playerHeldBy == (Object)null))
{
if (__instance.playerHeldBy.isInHangarShipRoom || __instance.playerHeldBy.isInElevator)
{
return !((Behaviour)StartOfRound.Instance.mapScreen.cam).enabled;
}
return true;
}
return true;
}
return false;
}
return true;
}
private static IEnumerator pingMapSystem(MapDevice mapDevice, PlayerControllerB playerHeldBy)
{
((Component)mapDevice.mapCamera).gameObject.SetActive(true);
if ((Object)(object)playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController && ((!GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom && !GameNetworkManager.Instance.localPlayerController.isInElevator) || !((Behaviour)StartOfRound.Instance.mapScreen.cam).enabled))
{
mapDevice.mapAnimatorTransition.SetTrigger("Transition");
((Component)StartOfRound.Instance.mapScreenPlayerName).gameObject.SetActive(false);
}
yield return (object)new WaitForSeconds(0.035f);
Vector3 position = ((Component)playerHeldBy).transform.position;
position.y += 3.636f;
((Component)mapDevice.mapCamera).transform.position = position;
yield return (object)new WaitForSeconds(0.2f);
((Behaviour)mapDevice.mapLight).enabled = playerHeldBy.isInsideFactory || ((Component)playerHeldBy).transform.position.y < -80f;
mapDevice.mapCamera.Render();
((Behaviour)mapDevice.mapLight).enabled = false;
((Component)mapDevice.mapCamera).gameObject.SetActive(false);
((Component)StartOfRound.Instance.mapScreenPlayerName).gameObject.SetActive(true);
}
[HarmonyPatch(typeof(StartOfRound), "SwitchMapMonitorPurpose")]
[HarmonyPostfix]
private static void PostSwitchMapMonitorPurpose(bool displayInfo)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (!displayInfo)
{
return;
}
MapDevice[] array = Object.FindObjectsByType<MapDevice>((FindObjectsSortMode)0);
foreach (MapDevice val in array)
{
if ((Object)(object)val.mapCamera != (Object)null && !((Component)val.mapCamera).CompareTag("MapCamera"))
{
RenderTexture active = RenderTexture.active;
RenderTexture.active = val.mapCamera.targetTexture;
GL.Clear(true, true, Color.clear);
RenderTexture.active = active;
}
}
}
[HarmonyPatch(typeof(MapDevice), "EquipItem")]
[HarmonyPostfix]
private static void MapDevicePostEquipItem(MapDevice __instance)
{
((GrabbableObject)__instance).playerHeldBy.equippedUsableItemQE = false;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "RestoreMapper";
public const string PLUGIN_NAME = "RestoreMapper";
public const string PLUGIN_VERSION = "1.2.2";
}
}