using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using FishNet.Connection;
using FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[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 FairerSlots
{
[BepInPlugin("welffi.howtofish.fairerslots", "Fairer Slots", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
public const string Guid = "welffi.howtofish.fairerslots";
public const string Name = "Fairer Slots";
public const string Version = "1.0.2";
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("welffi.howtofish.fairerslots").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Fairer Slots 1.0.2 loaded - the drip machine will reroll duplicate skins for you.");
}
}
[HarmonyPatch(typeof(SlotMachine), "Roll")]
internal static class SlotMachine_Roll_FairerSlots
{
private const int MaxRerollAttempts = 30;
private static void Prefix(Player roller, byte[] itemIDs, byte[] itemSkins, byte rolled)
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)roller == (Object)null || ((NetworkBehaviour)roller).Owner == (NetworkConnection)null || !((NetworkBehaviour)roller).Owner.IsLocalClient)
{
return;
}
byte b = itemIDs[rolled];
byte b2 = itemSkins[rolled];
if (!IsAlreadyUnlocked(b, b2))
{
return;
}
ItemSkin val = ((b == byte.MaxValue) ? BoatManager.Boat.SkinPreset : GameInfo.IDToItem(b).SkinPreset).Skins[b2];
Rarity rarity = ((ItemSkin)(ref val)).Rarity;
List<Item> list = new List<Item>(SlotMachine.AvailableItems);
if (!SlotMachine.ExcludeBoat)
{
list.Add(null);
}
for (int i = 0; i < 30; i++)
{
Item val2 = list[Random.Range(0, list.Count)];
byte randomSkinIndex = (Object.op_Implicit((Object)(object)val2) ? val2.SkinPreset : BoatManager.Boat.SkinPreset).GetRandomSkinIndex(rarity);
byte b3 = (Object.op_Implicit((Object)(object)val2) ? val2.ID : byte.MaxValue);
if (!IsAlreadyUnlocked(b3, randomSkinIndex))
{
itemIDs[rolled] = b3;
itemSkins[rolled] = randomSkinIndex;
break;
}
}
}
private static bool IsAlreadyUnlocked(byte itemID, byte skinIndex)
{
LocalSaveObject value = Traverse.Create(typeof(SaveManager)).Field("_curLocalSave").GetValue<LocalSaveObject>();
if (value == null)
{
return false;
}
if (itemID == byte.MaxValue)
{
if (value.UnlockedBoatSkins != null)
{
return value.UnlockedBoatSkins.Contains(skinIndex);
}
return false;
}
if (value.UnlockedItemSkins == null)
{
return false;
}
foreach (SavedItemSkin unlockedItemSkin in value.UnlockedItemSkins)
{
if (unlockedItemSkin.ID == itemID)
{
return unlockedItemSkin.SkinsUnlocked != null && unlockedItemSkin.SkinsUnlocked.Contains(skinIndex);
}
}
return false;
}
}
}