using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalNetworkAPI;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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: AssemblyCompany("Index154.LockedInside")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+592937f632ffff54b93be689aa2d18f6b1408a2b")]
[assembly: AssemblyProduct("LockedInside")]
[assembly: AssemblyTitle("Index154.LockedInside")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 LockedInside
{
public class ConfigManager
{
internal ConfigEntry<int> lockedChance = null;
internal ConfigEntry<int> reverseChance = null;
internal ConfigEntry<string> customLockedChances = null;
internal ConfigEntry<string> customReverseChances = null;
internal Dictionary<string, int> customLockedChancesDict = null;
internal Dictionary<string, int> customReverseChancesDict = null;
internal ConfigEntry<bool> allowExitIfLastOneAlive = null;
internal void Setup(ConfigFile configFile)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Expected O, but got Unknown
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Expected O, but got Unknown
lockedChance = configFile.Bind<int>("General", "Chance for mod to trigger", 10, new ConfigDescription("Default percentage chance for the entrace to not allow exiting and fire exits to not allow entering for a given day", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
reverseChance = configFile.Bind<int>("General", "Chance for reverse door rolls", 25, new ConfigDescription("Default percentage chance for the main entrance and fire exits to \"swap roles\", making it so you have to enter through the exit and leave through the entrance instead. Can only trigger if the above chance has also been triggered", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
customLockedChances = configFile.Bind<string>("General", "Moons with custom trigger chance", "", new ConfigDescription("Comma-separated list of moon names and their custom trigger chances. Example: 'Dine:50,Adamance:0,Experimentation:100'. Modded moons should also work", (AcceptableValueBase)null, Array.Empty<object>()));
customReverseChances = configFile.Bind<string>("General", "Moons with custom reverse mode chance", "", new ConfigDescription("Comma-separated list of moons to get custom reverse mode chances. Example: 'Titan:5,Vow:25,March:90,Dine:15,Gratar:100'. Modded moons should also work", (AcceptableValueBase)null, Array.Empty<object>()));
allowExitIfLastOneAlive = configFile.Bind<bool>("General", "Allow exit if last one alive", false, "If true, the last player alive is always able to leave using any door");
customLockedChancesDict = StrToDict(customLockedChances.Value);
customReverseChancesDict = StrToDict(customReverseChances.Value);
static Dictionary<string, int> StrToDict(string list)
{
Dictionary<string, int> dictionary = new Dictionary<string, int>();
string[] array = list.ToLowerInvariant().Split(",");
foreach (string text in array)
{
string[] array2 = text.Split(":");
if (array2.Length > 1)
{
int num = 0;
try
{
num = int.Parse(array2[1]);
}
finally
{
if (num < 0)
{
num = 0;
}
if (num > 100)
{
num = 100;
}
if (!dictionary.ContainsKey(array2[0]))
{
dictionary.Add(array2[0], num);
}
}
}
}
return dictionary;
}
}
}
public static class ExitChecker
{
public static bool IsLastAlive()
{
int num = StartOfRound.Instance.allPlayerScripts.Count((PlayerControllerB playerScript) => !playerScript.isPlayerDead && playerScript.isPlayerControlled);
if (num > 1)
{
return false;
}
return true;
}
}
[BepInPlugin("Index154.LockedInside", "LockedInside", "1.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class LockedInside : BaseUnityPlugin
{
internal static ConfigManager configManager = null;
public static LethalNetworkVariable<bool> locked = new LethalNetworkVariable<bool>("LCLIlockedState");
public static LethalNetworkVariable<bool> reverseMode = new LethalNetworkVariable<bool>("LCLIreverseModeState");
public static LockedInside Instance { get; private set; } = null;
internal static ManualLogSource Logger { get; private set; } = null;
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
configManager = new ConfigManager();
configManager.Setup(((BaseUnityPlugin)this).Config);
Patch();
Logger.LogInfo((object)"Index154.LockedInside v1.2.0 has loaded!");
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("Index154.LockedInside");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Index154.LockedInside";
public const string PLUGIN_NAME = "LockedInside";
public const string PLUGIN_VERSION = "1.2.0";
}
}
namespace LockedInside.Patches
{
[HarmonyPatch(typeof(HUDManager))]
public class HUDManagerPatch
{
[HarmonyPatch("HoldInteractionFill")]
[HarmonyPostfix]
private static void DestroyEntranceExitAbility(ref bool __result)
{
if (!__result || !LockedInside.locked.Value)
{
return;
}
PlayerControllerB localPlayerController = HUDManager.Instance.playersManager.localPlayerController;
InteractTrigger hoveringOverTrigger = localPlayerController.hoveringOverTrigger;
if ((Object)(object)hoveringOverTrigger == (Object)null)
{
return;
}
EntranceTeleport component = ((Component)hoveringOverTrigger).gameObject.GetComponent<EntranceTeleport>();
if ((Object)(object)component == (Object)null)
{
return;
}
string text = "leave";
string text2 = "fire exit";
string text3 = "Passage restricted. ";
bool flag = false;
if (component.entranceId == 0)
{
if (component.isEntranceToBuilding)
{
text = "enter";
if (LockedInside.reverseMode.Value)
{
flag = true;
text3 = "PAss<ge rrestrc?! .Ex%Enter--";
text2 += "?.";
}
}
else
{
flag = true;
if (LockedInside.reverseMode.Value)
{
return;
}
}
}
else
{
text2 = "main entrance";
if (component.isEntranceToBuilding)
{
text = "enter";
flag = true;
if (LockedInside.reverseMode.Value)
{
return;
}
}
else if (LockedInside.reverseMode.Value)
{
flag = true;
text3 = "PAssa ge rrestrc?! .Ex%Enter--";
text2 += "?.";
}
}
if (!text.Equals("leave") || !ExitChecker.IsLastAlive() || !LockedInside.configManager.allowExitIfLastOneAlive.Value)
{
string text4 = text3 + "Please " + text + " using a designated " + text2;
if (flag)
{
__result = false;
hoveringOverTrigger.currentCooldownValue = 1f;
HUDManager.Instance.DisplayTip("Entrance control", text4, false, false, "LC_Tip1");
}
}
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatches
{
[HarmonyPostfix]
[HarmonyPatch("LoadNewLevel")]
public static void RollForLocking()
{
int value = LockedInside.configManager.lockedChance.Value;
int value2 = LockedInside.configManager.reverseChance.Value;
foreach (KeyValuePair<string, int> item in LockedInside.configManager.customLockedChancesDict)
{
if (item.Key != "" && ((Object)StartOfRound.Instance.currentLevel).name.ToLowerInvariant().Contains(item.Key))
{
value = item.Value;
}
}
foreach (KeyValuePair<string, int> item2 in LockedInside.configManager.customReverseChancesDict)
{
if (item2.Key != "" && ((Object)StartOfRound.Instance.currentLevel).name.ToLowerInvariant().Contains(item2.Key))
{
value2 = item2.Value;
}
}
LockedInside.Logger.LogDebug((object)("LevelName = " + ((Object)StartOfRound.Instance.currentLevel).name));
LockedInside.Logger.LogDebug((object)("LockChance = " + value));
LockedInside.Logger.LogDebug((object)("ReverseChance = " + value2));
int num = Random.Range(1, 101);
if (num <= value)
{
if (!((Object)StartOfRound.Instance.currentLevel).name.ToLowerInvariant().Contains("company"))
{
LockedInside.locked.Value = true;
int num2 = Random.Range(1, 101);
if (num2 <= value2)
{
LockedInside.reverseMode.Value = true;
HUDManager.Instance.AddTextToChatOnServer("<color=red>Entrance control systems are active and corrupted!</color>", -1);
}
else
{
LockedInside.reverseMode.Value = false;
HUDManager.Instance.AddTextToChatOnServer("<color=red>Entrance control systems are active!</color>", -1);
}
}
}
else
{
LockedInside.locked.Value = false;
HUDManager.Instance.AddTextToChatOnServer("<color=white>Entrance control systems are inactive</color>", -1);
}
}
}
}