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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[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: AssemblyCompany("TheASMRsonist")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("R.EA.P.O")]
[assembly: AssemblyTitle("R.EA.P.O")]
[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 R.EA.P.O
{
[HarmonyPatch]
public static class DoorPatch
{
[CompilerGenerated]
private sealed class <ClearProcessedDoor>d__9 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PhysGrabHinge door;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ClearProcessedDoor>d__9(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(0.75f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if ((Object)(object)door != (Object)null)
{
_processedDoors.Remove(door);
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static float _lastInteractionTime;
private const float InteractionCooldown = 0.5f;
private static readonly HashSet<PhysGrabHinge> _processedDoors = new HashSet<PhysGrabHinge>();
private static bool _isDoorLocked = false;
private static readonly Dictionary<PhysGrabHinge, bool> _originalDoorStates = new Dictionary<PhysGrabHinge, bool>();
[RuntimeInitializeOnLoadMethod(/*Could not decode attribute arguments.*/)]
private static void OnSubsystemRegistration()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (!(((Scene)(ref scene)).name == "Lobby") && !(((Scene)(ref scene)).name == "Shop"))
{
R_EA_P_O.ResetMoney();
_isDoorLocked = false;
_processedDoors.Clear();
_originalDoorStates.Clear();
R_EA_P_O.Logger.LogInfo((object)$"Level loaded: {((Scene)(ref scene)).name}, money reset to {R_EA_P_O.CurrentMoney}, and reset door locking state");
}
}
private static void LockAllDoors()
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
if (_isDoorLocked)
{
return;
}
PhysGrabHinge[] array = Object.FindObjectsOfType<PhysGrabHinge>();
PhysGrabHinge[] array2 = array;
foreach (PhysGrabHinge val in array2)
{
if (!((Object)(object)val == (Object)null))
{
if (!_originalDoorStates.ContainsKey(val))
{
_originalDoorStates[val] = ((Behaviour)val).enabled;
}
((Behaviour)val).enabled = false;
Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
if ((Object)(object)component != (Object)null)
{
component.isKinematic = true;
component.velocity = Vector3.zero;
component.angularVelocity = Vector3.zero;
}
}
}
_isDoorLocked = true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PhysGrabHinge), "OpenImpulse")]
[HarmonyPatch(typeof(PhysGrabHinge), "OpenImpulseRPC")]
public static bool BeforeDoorUpdate(PhysGrabHinge __instance)
{
try
{
if (_processedDoors.Contains(__instance))
{
return true;
}
PlayerController instance = PlayerController.instance;
if ((Object)(object)instance == (Object)null)
{
R_EA_P_O.Logger.LogWarning((object)"Player instance not found.");
return true;
}
if (!((Component)instance).CompareTag("Player"))
{
return true;
}
if (R_EA_P_O.CurrentMoney <= 0)
{
if (!_isDoorLocked)
{
R_EA_P_O.Logger.LogInfo((object)"No more money, doors have been locked.");
LockAllDoors();
}
return false;
}
if (Time.time - _lastInteractionTime < 0.5f)
{
return true;
}
int level = 1;
int scaledCost = R_EA_P_O.GetScaledCost(R_EA_P_O.DoorCostBase.Value, level);
bool flag = Random.value <= R_EA_P_O.DoorCostChance.Value;
R_EA_P_O.Logger.LogInfo((object)$"Door interaction - Cost: {scaledCost}, Should charge: {flag}, Current money: {R_EA_P_O.CurrentMoney}");
if (flag && scaledCost > 0)
{
if (!R_EA_P_O.TryDeductMoney(scaledCost))
{
R_EA_P_O.Logger.LogInfo((object)"Not enough money.");
_processedDoors.Add(__instance);
((MonoBehaviour)R_EA_P_O.Instance).StartCoroutine(ClearProcessedDoor(__instance));
return false;
}
R_EA_P_O.Logger.LogInfo((object)$"Deducted {scaledCost} credits. Remaining: {R_EA_P_O.CurrentMoney}");
_processedDoors.Add(__instance);
((MonoBehaviour)R_EA_P_O.Instance).StartCoroutine(ClearProcessedDoor(__instance));
_lastInteractionTime = Time.time;
}
return true;
}
catch (Exception arg)
{
R_EA_P_O.Logger.LogError((object)$"Error in door interaction: {arg}");
return true;
}
}
[IteratorStateMachine(typeof(<ClearProcessedDoor>d__9))]
private static IEnumerator ClearProcessedDoor(PhysGrabHinge door)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ClearProcessedDoor>d__9(0)
{
door = door
};
}
}
[HarmonyPatch(typeof(PlayerController))]
internal static class ExamplePlayerControllerPatch
{
[HarmonyPrefix]
[HarmonyPatch("Start")]
private static void Start_Prefix(PlayerController __instance)
{
R_EA_P_O.Logger.LogDebug((object)$"{__instance} Start Prefix");
}
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void Start_Postfix(PlayerController __instance)
{
R_EA_P_O.Logger.LogDebug((object)$"{__instance} Start Postfix");
}
}
public class MoneyDisplay : MonoBehaviour
{
private static TextMeshProUGUI moneyText;
private static GameObject canvasObject;
private static MoneyDisplay instance;
private static bool isInitialized;
public static void Initialize()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (!isInitialized)
{
GameObject val = new GameObject("MoneyDisplay");
Object.DontDestroyOnLoad((Object)(object)val);
instance = val.AddComponent<MoneyDisplay>();
instance.SetupDisplay();
isInitialized = true;
}
}
private void SetupDisplay()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
canvasObject = new GameObject("MoneyDisplayCanvas");
Canvas val = canvasObject.AddComponent<Canvas>();
val.renderMode = (RenderMode)0;
val.sortingOrder = 1000;
Object.DontDestroyOnLoad((Object)(object)canvasObject);
GameObject val2 = new GameObject("MoneyText");
val2.transform.SetParent(((Component)val).transform, false);
moneyText = val2.AddComponent<TextMeshProUGUI>();
((TMP_Text)moneyText).fontSize = 28f;
((Graphic)moneyText).color = Color.yellow;
((TMP_Text)moneyText).fontStyle = (FontStyles)1;
((TMP_Text)moneyText).alignment = (TextAlignmentOptions)257;
((TMP_Text)moneyText).enableWordWrapping = false;
((TMP_Text)moneyText).overflowMode = (TextOverflowModes)0;
RectTransform rectTransform = ((TMP_Text)moneyText).rectTransform;
rectTransform.anchorMin = new Vector2(0f, 1f);
rectTransform.anchorMax = new Vector2(0f, 1f);
rectTransform.pivot = new Vector2(0f, 1f);
rectTransform.anchoredPosition = new Vector2(20f, -20f);
rectTransform.sizeDelta = new Vector2(300f, 50f);
Outline val3 = val2.AddComponent<Outline>();
((Shadow)val3).effectColor = Color.black;
((Shadow)val3).effectDistance = new Vector2(2f, -2f);
UpdateMoneyDisplay();
}
private void Update()
{
UpdateMoneyDisplay();
}
private static void UpdateMoneyDisplay()
{
if ((Object)(object)moneyText != (Object)null && (Object)(object)R_EA_P_O.Instance != (Object)null)
{
((TMP_Text)moneyText).text = $"Credit card: ${R_EA_P_O.CurrentMoney}";
}
}
}
[BepInPlugin("TheASMRsonist.R.EA.P.O", "R_EA_P_O", "1.0")]
public class R_EA_P_O : BaseUnityPlugin
{
public static ConfigEntry<int> StarterMoney;
public static ConfigEntry<float> DoorCostChance;
public static ConfigEntry<int> DoorCostBase;
public static ConfigEntry<bool> ScaleCostsWithLevel;
public static ConfigEntry<float> CostScaleFactor;
private static bool _isInitialized;
internal static R_EA_P_O Instance { get; private set; }
internal static ManualLogSource Logger => Instance._logger;
private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;
internal Harmony? Harmony { get; set; }
public static int CurrentMoney { get; private set; }
private void Awake()
{
Instance = this;
InitializeConfig();
CurrentMoney = StarterMoney.Value;
_isInitialized = true;
((Component)this).gameObject.transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Patch();
Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
Logger.LogInfo((object)$"Starter money: {StarterMoney.Value}");
}
private void InitializeConfig()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
StarterMoney = ((BaseUnityPlugin)this).Config.Bind<int>("General", "StarterMoney", 1000, "Amount of money you start with per round. Round restart required.");
DoorCostChance = ((BaseUnityPlugin)this).Config.Bind<float>("Door", "CostChance", 1f, new ConfigDescription("Chance to lose money when opening a door (0 meaning 0%, 1 meaning 100%)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
DoorCostBase = ((BaseUnityPlugin)this).Config.Bind<int>("Door", "BaseCost", 10, new ConfigDescription("Base amount of money lost when opening a door", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
ScaleCostsWithLevel = ((BaseUnityPlugin)this).Config.Bind<bool>("Scaling", "Enabled", true, "Should door costs scale with level?");
CostScaleFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "Factor", 1.5f, new ConfigDescription("If ScaleCostsWithLevel is true, value entered here will be the scale.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
}
internal void Patch()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0026: Expected O, but got Unknown
if (Harmony == null)
{
Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
Harmony val2 = val;
Harmony = val;
}
Harmony.PatchAll();
}
internal void Unpatch()
{
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public static bool CanAffordCost(int cost)
{
return CurrentMoney >= cost;
}
public static bool TryDeductMoney(int amount)
{
if (!_isInitialized)
{
return true;
}
if (amount <= 0)
{
return true;
}
if (CurrentMoney >= amount)
{
CurrentMoney -= amount;
return true;
}
return false;
}
public static int GetScaledCost(int baseCost, int level = 1)
{
if (!ScaleCostsWithLevel.Value || level <= 1)
{
return baseCost;
}
return Mathf.RoundToInt((float)baseCost * Mathf.Pow(CostScaleFactor.Value, (float)(level - 1)));
}
public static void ResetMoney()
{
CurrentMoney = StarterMoney.Value;
}
private void Update()
{
MoneyDisplay.Initialize();
}
}
}