using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 InfiniteGachaTokens
{
[BepInPlugin("com.earlj.supermarkettogether.infinitegachatokens", "Infinite Gacha Tokens", "1.0.2")]
public sealed class InfiniteGachaTokensPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(AchievementsManager), "LoadbufferValues")]
private static class LoadTokensPatch
{
private static void Postfix(AchievementsManager __instance)
{
if (!((Object)(object)__instance == (Object)null) && __instance.evtsTkns != null)
{
for (int i = 0; i < __instance.evtsTkns.Length; i++)
{
ShowVirtualToken(__instance, i);
}
}
}
}
[HarmonyPatch(typeof(AchievementsManager), "AddToken")]
private static class TokenDisplayPatch
{
private static void Postfix(AchievementsManager __instance, int __0)
{
ShowVirtualToken(__instance, __0);
}
}
[HarmonyPatch(typeof(AchievementsManager), "RequestGachaponSphere")]
private static class SpinPatch
{
private static void Prefix(AchievementsManager __instance, int __1, out int __state)
{
__state = -1;
if (!((Object)(object)__instance == (Object)null) && __instance.evtsTkns != null && __instance.tknsFields != null && __1 >= 0 && __1 < __instance.evtsTkns.Length && __1 < __instance.tknsFields.Length && !((Object)(object)__instance.tknsFields[__1] == (Object)null))
{
__state = __instance.evtsTkns[__1];
if (__instance.evtsTkns[__1] < 1)
{
__instance.AddToken(__1, 1 - __instance.evtsTkns[__1]);
}
}
}
private static void Postfix(AchievementsManager __instance, int __1, int __state)
{
if (__state >= 0 && !((Object)(object)__instance == (Object)null) && __instance.evtsTkns != null && __1 >= 0 && __1 < __instance.evtsTkns.Length)
{
int num = __state - __instance.evtsTkns[__1];
if (num != 0)
{
__instance.AddToken(__1, num);
}
ShowVirtualToken(__instance, __1);
}
}
}
[HarmonyPatch(typeof(AchievementsManager), "GetUnlockable")]
private static class SaveWonSkinPatch
{
private static void Prefix(AchievementsManager __instance, int __0, out bool __state)
{
__state = (Object)(object)__instance != (Object)null && __instance.unlockedArray != null && __0 >= 0 && __0 < __instance.unlockedArray.Length && __instance.unlockedArray[__0];
}
private static void Postfix(AchievementsManager __instance, int __0, bool __state)
{
if (!__state && (Object)(object)__instance != (Object)null && __instance.unlockedArray != null && __0 >= 0 && __0 < __instance.unlockedArray.Length && __instance.unlockedArray[__0])
{
try
{
SaveSkinsOnly(__instance);
}
catch (Exception ex)
{
Debug.LogError((object)("Infinite Gacha Tokens could not save the won skin: " + ex));
}
}
}
}
private Harmony harmony;
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
harmony = new Harmony("com.earlj.supermarkettogether.infinitegachatokens");
harmony.PatchAll(typeof(InfiniteGachaTokensPlugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Gacha tokens will remain available after every spin.");
}
private void OnDestroy()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static void ShowVirtualToken(AchievementsManager manager, int index)
{
if (!((Object)(object)manager == (Object)null) && manager.evtsTkns != null && manager.tknsFields != null && index >= 0 && index < manager.evtsTkns.Length && index < manager.tknsFields.Length && (Object)(object)manager.tknsFields[index] != (Object)null && manager.evtsTkns[index] < 1)
{
((TMP_Text)manager.tknsFields[index]).text = "x1";
}
}
private static void SaveSkinsOnly(AchievementsManager manager)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
string text = Application.persistentDataPath + "/buffervalues1.es3";
ES3Settings val = new ES3Settings((EncryptionType)1, "g#asojrtg@omos)^yq");
string text2 = Application.persistentDataPath + "/z_altbuffervalues1.es3";
if (ES3.FileExists(text2))
{
text = text2;
val = new ES3Settings((EncryptionType)0, "");
}
ES3.CacheFile(text, val);
ES3Settings val2 = new ES3Settings(text, new Enum[1] { (Enum)(object)(Location)4 });
ES3.Save<bool[]>("unlValues", manager.unlockedArray, text, val2);
ES3.StoreCachedFile(text, val);
}
}
}