using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CoinWin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CoinWin")]
[assembly: AssemblyTitle("CoinWin")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 CoinWin
{
[MycoMod(/*Could not decode attribute arguments.*/)]
[BepInPlugin("coinin.coinwin", "CoinWin", "1.2.0")]
public sealed class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(CoinflipColin), "DoCoinflipCoroutine")]
private static class CoinflipColinWinPatch
{
private static void Prefix(ref bool heads)
{
if (heads != headResult)
{
Log.LogDebug((object)$"Forced Coinflip Colin result from {heads} to {headResult}.");
}
heads = headResult;
}
}
[HarmonyPatch(typeof(CoinflipColin), "CollectUpgrades")]
private static class CoinflipColinReusePatch
{
private static void Postfix(ref bool ___canInteract, ref UpgradeInstance ___selectedUpgrade)
{
___canInteract = true;
___selectedUpgrade = null;
}
}
private const string PluginGuid = "coinin.coinwin";
private const string PluginName = "CoinWin";
private const string PluginVersion = "1.2.0";
internal static ManualLogSource Log = null;
private static bool headResult = true;
private Harmony? harmony;
private OuroGearWindow? currentWindow;
private Button? headButton;
private void Awake()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
harmony = new Harmony("coinin.coinwin");
harmony.PatchAll(typeof(Plugin).Assembly);
Log.LogInfo((object)"CoinWin loaded. Coinflip Colin will always win and can be reused.");
}
private void Update()
{
if (!CanUseWindow(out OuroGearWindow window))
{
DestroyHeadButton();
return;
}
if ((Object)(object)currentWindow == (Object)(object)window && (Object)(object)headButton != (Object)null)
{
SetHeadButtonText();
return;
}
DestroyHeadButton();
if (!TryFindCloseButton(window, out Button closeButton))
{
Log.LogWarning((object)"Could not find OuroGearWindow Close button.");
}
else
{
CreateHeadButton(window, closeButton);
}
}
private void OnDestroy()
{
DestroyHeadButton();
Harmony? obj = harmony;
if (obj != null)
{
obj.UnpatchSelf();
}
harmony = null;
}
private void CreateHeadButton(OuroGearWindow window, Button closeButton)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Expected O, but got Unknown
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Expected O, but got Unknown
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Expected O, but got Unknown
Button val = Object.Instantiate<Button>(closeButton, ((Component)closeButton).transform.parent);
((Object)val).name = "CoinWinHeadButton";
((Component)val).transform.SetSiblingIndex(((Component)closeButton).transform.GetSiblingIndex() + 1);
RectTransform val2 = (RectTransform)((Component)val).transform;
RectTransform val3 = (RectTransform)((Component)closeButton).transform;
val2.anchorMin = val3.anchorMin;
val2.anchorMax = val3.anchorMax;
val2.pivot = val3.pivot;
val2.sizeDelta = val3.sizeDelta;
Vector2 anchoredPosition = val3.anchoredPosition;
Rect rect = val3.rect;
val2.anchoredPosition = anchoredPosition + new Vector2(0f, ((Rect)(ref rect)).height + 25f);
val.OnClickDown = new UnityEvent();
val.OnClickUp = new UnityEvent();
val.OnClickUp.AddListener((UnityAction)delegate
{
headResult = !headResult;
SetHeadButtonText();
Log.LogInfo((object)$"Coinflip Colin head result set to {headResult}.");
});
currentWindow = window;
headButton = val;
SetHeadButtonText();
}
private void SetHeadButtonText()
{
if ((Object)(object)headButton != (Object)null)
{
SetButtonText(headButton, $"HEAD: {headResult}");
}
}
private static void SetButtonText(Button button, string text)
{
TMP_Text[] componentsInChildren = ((Component)button).GetComponentsInChildren<TMP_Text>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
componentsInChildren[i].text = text;
}
Text[] componentsInChildren2 = ((Component)button).GetComponentsInChildren<Text>(true);
for (int j = 0; j < componentsInChildren2.Length; j++)
{
componentsInChildren2[j].text = text;
}
}
private void DestroyHeadButton()
{
if ((Object)(object)headButton != (Object)null)
{
Object.Destroy((Object)(object)((Component)headButton).gameObject);
headButton = null;
}
currentWindow = null;
}
private static bool TryFindCloseButton(OuroGearWindow window, out Button closeButton)
{
Button[] componentsInChildren = ((Component)window).GetComponentsInChildren<Button>(true);
foreach (Button val in componentsInChildren)
{
int persistentEventCount = ((UnityEventBase)val.OnClickUp).GetPersistentEventCount();
for (int j = 0; j < persistentEventCount; j++)
{
if (((UnityEventBase)val.OnClickUp).GetPersistentTarget(j) == (Object)(object)window && ((UnityEventBase)val.OnClickUp).GetPersistentMethodName(j) == "CloseMenu")
{
closeButton = val;
return true;
}
}
}
foreach (Button val2 in componentsInChildren)
{
if (IsNamedLikeCloseButton(((Component)val2).transform))
{
closeButton = val2;
return true;
}
}
foreach (Button val3 in componentsInChildren)
{
if (HasCloseText(val3))
{
closeButton = val3;
return true;
}
}
closeButton = null;
return false;
}
private static bool IsNamedLikeCloseButton(Transform transform)
{
Transform val = transform;
while ((Object)(object)val != (Object)null)
{
if (((Object)val).name.IndexOf("close", StringComparison.OrdinalIgnoreCase) >= 0)
{
return true;
}
val = val.parent;
}
return false;
}
private static bool HasCloseText(Button button)
{
TMP_Text[] componentsInChildren = ((Component)button).GetComponentsInChildren<TMP_Text>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (IsCloseLabel(componentsInChildren[i].text))
{
return true;
}
}
Text[] componentsInChildren2 = ((Component)button).GetComponentsInChildren<Text>(true);
for (int j = 0; j < componentsInChildren2.Length; j++)
{
if (IsCloseLabel(componentsInChildren2[j].text))
{
return true;
}
}
return false;
}
private static bool IsCloseLabel(string text)
{
return string.Equals(text?.Trim(), "close", StringComparison.OrdinalIgnoreCase);
}
private static bool CanUseWindow(out OuroGearWindow window)
{
window = null;
if ((Object)(object)Menu.Instance == (Object)null || !Menu.Instance.IsOpen || (Object)(object)Menu.Instance.WindowSystem == (Object)null)
{
return false;
}
Window top = Menu.Instance.WindowSystem.GetTop();
OuroGearWindow val = (OuroGearWindow)(object)((top is OuroGearWindow) ? top : null);
if (val == null)
{
return false;
}
window = val;
return true;
}
}
}